From 9bf542732b1bc85ff00d576a13cb5914517a78e0 Mon Sep 17 00:00:00 2001 From: MASDXI <31649128+MASDXI@users.noreply.github.com> Date: Thu, 14 Mar 2024 16:40:05 +0700 Subject: [PATCH] Change`txpool_beusPendingTransactions`:`numResults` from a required parameter to an optional parameter (#6708) Signed-off-by: MASDXI --- CHANGELOG.md | 1 + .../TxPoolBesuPendingTransactions.java | 8 +++-- .../TxPoolBesuPendingTransactionsTest.java | 32 ++++++++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33d5d447852..6ef8654d9f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ ### Deprecations ### Additions and Improvements +- `txpool_besuPendingTransactions`change parameter `numResults` to optional parameter [#6708](https://github.com/hyperledger/besu/pull/6708) - Extend `Blockchain` service [#6592](https://github.com/hyperledger/besu/pull/6592) - Add bft-style blockperiodseconds transitions to Clique [#6596](https://github.com/hyperledger/besu/pull/6596) - Add createemptyblocks transitions to Clique [#6608](https://github.com/hyperledger/besu/pull/6608) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactions.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactions.java index 067daa7a11e..c1d224e1f14 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactions.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactions.java @@ -23,6 +23,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.transaction.pool.PendingTransactionFilter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.transaction.pool.PendingTransactionFilter.Filter; import org.hyperledger.besu.ethereum.core.Transaction; +import org.hyperledger.besu.ethereum.eth.transactions.PendingTransaction; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import java.util.Collection; @@ -49,7 +50,10 @@ public String getName() { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final Integer limit = requestContext.getRequiredParameter(0, Integer.class); + final Collection pendingTransactions = + transactionPool.getPendingTransactions(); + final Integer limit = + requestContext.getOptionalParameter(0, Integer.class).orElse(pendingTransactions.size()); final List filters = requestContext .getOptionalParameter(1, PendingTransactionsParams.class) @@ -57,7 +61,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { .orElse(Collections.emptyList()); final Collection pendingTransactionsFiltered = - pendingTransactionFilter.reduce(transactionPool.getPendingTransactions(), filters, limit); + pendingTransactionFilter.reduce(pendingTransactions, filters, limit); return new JsonRpcSuccessResponse( requestContext.getRequest().getId(), diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactionsTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactionsTest.java index 738cae30970..1eef04fb93a 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactionsTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactionsTest.java @@ -70,7 +70,7 @@ public void shouldReturnPendingTransactions() { final JsonRpcRequestContext request = new JsonRpcRequestContext( new JsonRpcRequest( - JSON_RPC_VERSION, TXPOOL_PENDING_TRANSACTIONS_METHOD, new Object[] {100})); + JSON_RPC_VERSION, TXPOOL_PENDING_TRANSACTIONS_METHOD, new Object[] {})); final JsonRpcSuccessResponse actualResponse = (JsonRpcSuccessResponse) method.response(request); final Set result = @@ -120,6 +120,36 @@ public void shouldReturnPendingTransactionsWithLimit() { @Test public void shouldReturnPendingTransactionsWithFilter() { + final Map fromFilter = new HashMap<>(); + fromFilter.put( + "eq", listTrx.stream().findAny().get().getTransaction().getSender().toHexString()); + + final JsonRpcRequestContext request = + new JsonRpcRequestContext( + new JsonRpcRequest( + JSON_RPC_VERSION, + TXPOOL_PENDING_TRANSACTIONS_METHOD, + new Object[] { + null, + new PendingTransactionsParams( + fromFilter, + new HashMap<>(), + new HashMap<>(), + new HashMap<>(), + new HashMap<>(), + new HashMap<>()) + })); + + final JsonRpcSuccessResponse actualResponse = (JsonRpcSuccessResponse) method.response(request); + + final Set result = + (Set) actualResponse.getResult(); + assertThat(result.size()).isEqualTo(1); + } + + @Test + public void shouldReturnPendingTransactionsWithLimitAndFilter() { + final Map fromFilter = new HashMap<>(); fromFilter.put( "eq", listTrx.stream().findAny().get().getTransaction().getSender().toHexString());