From 0896e31de71514287c6bceaa7fc3ec6355b7cc31 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Mon, 7 Oct 2024 09:12:03 +1100 Subject: [PATCH] 7311: Rework PeerTaskExecutor retry system to be 0-based Signed-off-by: Matilda Clerke --- .../eth/manager/peertask/PeerTaskExecutor.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java index d4b3f603d1..1d56c61a7e 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java @@ -34,9 +34,9 @@ import java.util.concurrent.TimeoutException; /** Manages the execution of PeerTasks, respecting their PeerTaskRetryBehavior */ public class PeerTaskExecutor { - public static final int RETRIES_WITH_SAME_PEER = 3; - public static final int RETRIES_WITH_OTHER_PEER = 3; - public static final int NO_RETRIES = 1; + public static final int RETRIES_WITH_SAME_PEER = 2; + public static final int RETRIES_WITH_OTHER_PEER = 2; + public static final int NO_RETRIES = 0; private final PeerSelector peerSelector; private final PeerTaskRequestSender requestSender; private final EthScheduler ethScheduler; @@ -61,7 +61,7 @@ public class PeerTaskExecutor { public PeerTaskExecutorResult execute(final PeerTask peerTask) { PeerTaskExecutorResult executorResult; - int triesRemaining = + int retriesRemaining = peerTask.getPeerTaskRetryBehaviors().contains(PeerTaskRetryBehavior.RETRY_WITH_OTHER_PEERS) ? RETRIES_WITH_OTHER_PEER : NO_RETRIES; @@ -81,7 +81,7 @@ public class PeerTaskExecutor { new PeerTaskExecutorResult<>( Optional.empty(), PeerTaskExecutorResponseCode.NO_PEER_AVAILABLE); } - } while (--triesRemaining > 0 + } while (retriesRemaining-- > 0 && executorResult.responseCode() != PeerTaskExecutorResponseCode.SUCCESS); return executorResult; @@ -96,7 +96,7 @@ public class PeerTaskExecutor { final PeerTask peerTask, final EthPeer peer) { MessageData requestMessageData = peerTask.getRequestMessage(); PeerTaskExecutorResult executorResult; - int triesRemaining = + int retriesRemaining = peerTask.getPeerTaskRetryBehaviors().contains(PeerTaskRetryBehavior.RETRY_WITH_SAME_PEER) ? RETRIES_WITH_SAME_PEER : NO_RETRIES; @@ -136,7 +136,7 @@ public class PeerTaskExecutor { new PeerTaskExecutorResult<>( Optional.empty(), PeerTaskExecutorResponseCode.INTERNAL_SERVER_ERROR); } - } while (--triesRemaining > 0 + } while (retriesRemaining-- > 0 && executorResult.responseCode() != PeerTaskExecutorResponseCode.SUCCESS && executorResult.responseCode() != PeerTaskExecutorResponseCode.PEER_DISCONNECTED && sleepBetweenRetries());