Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changetxpool_beusPendingTransactions:numResults from a required parameter to an optional parameter #6708

Merged
merged 16 commits into from
Mar 14, 2024
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
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 =
MASDXI marked this conversation as resolved.
Show resolved Hide resolved
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
Loading