Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
### Repository Migration
- The Besu repository has moved from `hyperledger/besu` to `besu-eth/besu`. GitHub automatically redirects all existing links from the old location.

### Repository Migration
- The Besu repository has moved from `hyperledger/besu` to `besu-eth/besu`. GitHub automatically redirects all existing links from the old location.

### Breaking Changes
- Clique consensus has been removed. Besu can no longer start or mine on pure Clique networks. Syncing networks that started as Clique and have since transitioned to PoS via `terminalTotalDifficulty` (e.g. Linea Mainnet) are still supported. [#9852](https://github.com/hyperledger/besu/pull/9852)
- Deprecated `--min-block-occupancy-ratio` for removal and make it noop. That option, that is ignored on PoS networks, is related to the deprecated PoW, and allowed to broadcast a mined block as soon as it reached a satisfying fill threshold. The option is still recognized, but it has no effect and will be completely removed in a future release. [#10036](https://github.com/besu-eth/besu/pull/10036)
Expand Down Expand Up @@ -58,6 +55,7 @@ are provided with different values, using input as per the execution-apis spec i
- Add blockTimestamp to transaction RPC results [#9887](https://github.com/hyperledger/besu/pull/9887)
- Add `txpool_status` RPC method [#10002](https://github.com/hyperledger/besu/pull/10002)
- Add `txpool_contentFrom` JSON-RPC method [#10111](https://github.com/besu-eth/besu/pull/10111)
- Add `txpool_content` JSON-RPC method [#10120](https://github.com/besu-eth/besu/pull/10120)
- Add maxUsedGas field to eth_simulateV1 results [#10066](https://github.com/besu-eth/besu/pull/10066)

### Performance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public enum RpcMethod {
TX_POOL_BESU_PENDING_TRANSACTIONS("txpool_besuPendingTransactions"),
TX_POOL_STATUS("txpool_status"),
TX_POOL_CONTENT_FROM("txpool_contentFrom"),
TX_POOL_CONTENT("txpool_content"),
WEB3_CLIENT_VERSION("web3_clientVersion"),
WEB3_SHA3("web3_sha3"),
PLUGINS_RELOAD_CONFIG("plugins_reloadPluginConfig"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright contributors to Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;

import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionPendingResult;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionPoolContentResult;
import org.hyperledger.besu.ethereum.eth.transactions.PendingTransaction;
import org.hyperledger.besu.ethereum.eth.transactions.SenderPendingTransactionsData;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.SequencedMap;
import java.util.stream.Collectors;

public class TxPoolContent implements JsonRpcMethod {

private final TransactionPool transactionPool;

public TxPoolContent(final TransactionPool transactionPool) {
this.transactionPool = transactionPool;
}

@Override
public String getName() {
return RpcMethod.TX_POOL_CONTENT.getMethodName();
}

@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), content());
}

private TransactionPoolContentResult content() {
final Map<Address, SenderPendingTransactionsData> pendingTransactionsBySender =
transactionPool.getPendingTransactionsBySender();

final Map<String, SequencedMap<String, TransactionPendingResult>> pending = new HashMap<>();
final Map<String, SequencedMap<String, TransactionPendingResult>> queued = new HashMap<>();

pendingTransactionsBySender.forEach(
(sender, pendingTransactionsData) -> {
final List<PendingTransaction> pendingTransactions =
pendingTransactionsData.pendingTransactions();
long expectedNonce = pendingTransactionsData.nonce();
int idx = 0;
while (idx < pendingTransactions.size()
&& expectedNonce == pendingTransactions.get(idx).getNonce()) {
++expectedNonce;
++idx;
}

final SequencedMap<String, TransactionPendingResult> pendingByNonce =
pendingTransactions.subList(0, idx).stream()
.map(PendingTransaction::getTransaction)
.collect(
Collectors.toMap(
tx -> Long.toString(tx.getNonce()),
TransactionPendingResult::new,
(a, b) -> a,
LinkedHashMap::new));

final SequencedMap<String, TransactionPendingResult> queuedByNonce =
pendingTransactions.subList(idx, pendingTransactions.size()).stream()
.map(PendingTransaction::getTransaction)
.collect(
Collectors.toMap(
tx -> Long.toString(tx.getNonce()),
TransactionPendingResult::new,
(a, b) -> a,
LinkedHashMap::new));

if (!pendingByNonce.isEmpty()) {
pending.put(sender.toString(), pendingByNonce);
}
if (!queuedByNonce.isEmpty()) {
queued.put(sender.toString(), queuedByNonce);
}
});
return new TransactionPoolContentResult(pending, queued);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright contributors to Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results;

import java.util.Map;
import java.util.SequencedMap;

import com.fasterxml.jackson.annotation.JsonGetter;

public class TransactionPoolContentResult {

private final Map<String, SequencedMap<String, TransactionPendingResult>> pending;
private final Map<String, SequencedMap<String, TransactionPendingResult>> queued;

public TransactionPoolContentResult(
final Map<String, SequencedMap<String, TransactionPendingResult>> pending,
final Map<String, SequencedMap<String, TransactionPendingResult>> queued) {
this.pending = pending;
this.queued = queued;
}

@JsonGetter(value = "pending")
public Map<String, SequencedMap<String, TransactionPendingResult>> getPending() {
return pending;
}

@JsonGetter(value = "queued")
public Map<String, SequencedMap<String, TransactionPendingResult>> getQueued() {
return queued;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.TxPoolBesuPendingTransactions;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.TxPoolBesuStatistics;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.TxPoolBesuTransactions;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.TxPoolContent;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.TxPoolContentFrom;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.TxPoolStatus;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
Expand All @@ -45,6 +46,7 @@ protected Map<String, JsonRpcMethod> create() {
new TxPoolBesuPendingTransactions(transactionPool),
new TxPoolBesuStatistics(transactionPool),
new TxPoolStatus(transactionPool),
new TxPoolContentFrom(transactionPool));
new TxPoolContentFrom(transactionPool),
new TxPoolContent(transactionPool));
}
}
Loading
Loading