From a7b10dbeceabca9c4ba0c09fc2658c9c765dbbc9 Mon Sep 17 00:00:00 2001 From: Jason Frame Date: Thu, 4 Apr 2024 17:33:35 +1000 Subject: [PATCH] Bws internal error fix (#6806) Signed-off-by: Jason Frame --- .../merge/blockcreation/MergeCoordinator.java | 4 ---- .../eth/sync/backwardsync/BackwardSyncContext.java | 12 ++++++++---- .../sync/backwardsync/BackwardSyncContextTest.java | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java index 512d2dc21f..e0b0559795 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java @@ -501,10 +501,6 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene .addArgument(maybeHeadHeader.get()::toLogString) .log(); } else { - LOG.atDebug() - .setMessage("Appending new head block hash {} to backward sync") - .addArgument(headHash::toHexString) - .log(); backwardSyncContext.maybeUpdateTargetHeight(headHash); backwardSyncContext .syncBackwardsUntil(headHash) diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContext.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContext.java index 1c1382e06b..273dd56c78 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContext.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContext.java @@ -125,11 +125,15 @@ public class BackwardSyncContext { } public synchronized CompletableFuture syncBackwardsUntil(final Hash newBlockHash) { - if (!isTrusted(newBlockHash)) { - backwardChain.addNewHash(newBlockHash); - } - if (isReady()) { + if (!isTrusted(newBlockHash)) { + LOG.atDebug() + .setMessage("Appending new head block hash {} to backward sync") + .addArgument(newBlockHash::toHexString) + .log(); + backwardChain.addNewHash(newBlockHash); + } + final Status status = getOrStartSyncSession(); backwardChain .getBlock(newBlockHash) diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContextTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContextTest.java index 532400c20d..ce4640ae93 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContextTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContextTest.java @@ -231,6 +231,20 @@ public class BackwardSyncContextTest { assertThat(localBlockchain.getChainHeadBlock()).isEqualTo(remoteBlockchain.getChainHeadBlock()); } + @Test + public void shouldNotSyncUntilHashWhenNotInSync() { + doReturn(false).when(context).isReady(); + final Hash hash = getBlockByNumber(REMOTE_HEIGHT).getHash(); + final CompletableFuture future = context.syncBackwardsUntil(hash); + + respondUntilFutureIsDone(future); + + assertThatThrownBy(future::get) + .isInstanceOf(ExecutionException.class) + .hasMessageContaining("Backward sync is not ready"); + assertThat(backwardChain.getFirstHashToAppend()).isEmpty(); + } + @Test public void shouldSyncUntilRemoteBranch() throws Exception {