From 7beee1f9c1ff94c04196b38007c70e7ce9709a07 Mon Sep 17 00:00:00 2001 From: Suyash Nayan Date: Sun, 22 Oct 2023 14:58:29 +0530 Subject: [PATCH] Optimize GetPooledTransactionsFromPeerTask with HashSet Switch from using a List to a HashSet for transaction hashes in GetPooledTransactionsFromPeerTask to improve performance. Signed-off-by: Suyash Nayan --- .../task/GetPooledTransactionsFromPeerTask.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetPooledTransactionsFromPeerTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetPooledTransactionsFromPeerTask.java index ca3c90af5f1..06151ba68c8 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetPooledTransactionsFromPeerTask.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetPooledTransactionsFromPeerTask.java @@ -27,8 +27,10 @@ import org.hyperledger.besu.plugin.services.MetricsSystem; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Optional; +import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,12 +40,12 @@ public class GetPooledTransactionsFromPeerTask extends AbstractPeerRequestTask hashes; + private final Set hashes; private GetPooledTransactionsFromPeerTask( final EthContext ethContext, final List hashes, final MetricsSystem metricsSystem) { super(ethContext, EthPV65.GET_POOLED_TRANSACTIONS, metricsSystem); - this.hashes = List.copyOf(hashes); + this.hashes = new HashSet<>(hashes); } public static GetPooledTransactionsFromPeerTask forHashes( @@ -51,7 +53,7 @@ public static GetPooledTransactionsFromPeerTask forHashes( return new GetPooledTransactionsFromPeerTask(ethContext, hashes, metricsSystem); } - public List getTransactionHashes() { + public Set getTransactionHashes() { return hashes; } @@ -60,7 +62,7 @@ protected PendingPeerRequest sendRequest() { return sendRequestToPeer( peer -> { LOG.debug("Requesting {} transaction pool entries from peer {}.", hashes.size(), peer); - return peer.getPooledTransactions(hashes); + return peer.getPooledTransactions(new ArrayList<>(hashes)); }, 0); }