From efd4dd687ff7b0dbb1ef47b66b3903ccf450106b Mon Sep 17 00:00:00 2001 From: Karim TAAM Date: Thu, 28 Apr 2022 17:10:00 +0200 Subject: [PATCH 1/2] fix Signed-off-by: Karim TAAM --- .../eth/sync/snapsync/SnapWorldDownloadState.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapWorldDownloadState.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapWorldDownloadState.java index 2a28bffbf0a..a5c810f5cf4 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapWorldDownloadState.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapWorldDownloadState.java @@ -189,13 +189,8 @@ public synchronized void reloadHeal() { worldStateStorage.clearFlatDatabase(); pendingTrieNodeRequests.clearInternalQueues(); pendingCodeRequests.clearInternalQueue(); - enqueueRequest( - createAccountTrieNodeDataRequest( - snapSyncState.getPivotBlockHeader().orElseThrow().getStateRoot(), - Bytes.EMPTY, - inconsistentAccounts)); - requestComplete(true); - notifyTaskAvailable(); + snapSyncState.setHealStatus(false); + checkCompletion(snapSyncState.getPivotBlockHeader().orElseThrow()); } @Override From 1b1cbf035be61c8bd0eda66d61cc590c44747c44 Mon Sep 17 00:00:00 2001 From: Karim TAAM Date: Fri, 29 Apr 2022 12:12:27 +0200 Subject: [PATCH 2/2] add test Signed-off-by: Karim TAAM --- .../snapsync/SnapWorldDownloadStateTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapWorldDownloadStateTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapWorldDownloadStateTest.java index b0c5d14957e..010d49c8126 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapWorldDownloadStateTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapWorldDownloadStateTest.java @@ -18,6 +18,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -236,4 +237,21 @@ public void shouldCancelOutstandingTasksWhenFutureIsCancelled() { verify(worldStateDownloadProcess).abort(); assertThat(downloadState.isDownloading()).isFalse(); } + + @Test + public void shouldRestartHealWhenNewPivotBlock() { + when(snapSyncState.getPivotBlockHeader()).thenReturn(Optional.of(mock(BlockHeader.class))); + when(snapSyncState.isHealInProgress()).thenReturn(false); + assertThat(downloadState.pendingTrieNodeRequests.isEmpty()).isTrue(); + // start heal + downloadState.checkCompletion(header); + verify(snapSyncState).setHealStatus(true); + assertThat(downloadState.pendingTrieNodeRequests.isEmpty()).isFalse(); + // reload the heal + downloadState.reloadHeal(); + verify(snapSyncState).setHealStatus(false); + spy(downloadState.pendingTrieNodeRequests).clearInternalQueues(); + spy(downloadState).checkCompletion(header); + assertThat(downloadState.pendingTrieNodeRequests.isEmpty()).isFalse(); + } }