Skip to content
/ besu Public
forked from hyperledger/besu

Commit

Permalink
Changetxpool_beusPendingTransactions:numResults from a required p…
Browse files Browse the repository at this point in the history
…arameter to an optional parameter (hyperledger#6708)

Signed-off-by: MASDXI <[email protected]>
Signed-off-by: amsmota <[email protected]>
  • Loading branch information
MASDXI authored and amsmota committed Apr 16, 2024
1 parent 9ab60db commit bdbd53c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -49,15 +50,18 @@ public String getName() {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {

final Integer limit = requestContext.getRequiredParameter(0, Integer.class);
final Collection<PendingTransaction> pendingTransactions =
transactionPool.getPendingTransactions();
final Integer limit =
requestContext.getOptionalParameter(0, Integer.class).orElse(pendingTransactions.size());
final List<Filter> filters =
requestContext
.getOptionalParameter(1, PendingTransactionsParams.class)
.map(PendingTransactionsParams::filters)
.orElse(Collections.emptyList());

final Collection<Transaction> pendingTransactionsFiltered =
pendingTransactionFilter.reduce(transactionPool.getPendingTransactions(), filters, limit);
pendingTransactionFilter.reduce(pendingTransactions, filters, limit);

return new JsonRpcSuccessResponse(
requestContext.getRequest().getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TransactionPendingResult> result =
Expand Down Expand Up @@ -120,6 +120,36 @@ public void shouldReturnPendingTransactionsWithLimit() {
@Test
public void shouldReturnPendingTransactionsWithFilter() {

final Map<String, String> 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<TransactionPendingResult> result =
(Set<TransactionPendingResult>) actualResponse.getResult();
assertThat(result.size()).isEqualTo(1);
}

@Test
public void shouldReturnPendingTransactionsWithLimitAndFilter() {

final Map<String, String> fromFilter = new HashMap<>();
fromFilter.put(
"eq", listTrx.stream().findAny().get().getTransaction().getSender().toHexString());
Expand Down

0 comments on commit bdbd53c

Please sign in to comment.