From beb4e3baa32b7a918e84343b1ef08b098698ce3d Mon Sep 17 00:00:00 2001 From: matkt Date: Tue, 3 May 2022 08:58:32 +0200 Subject: [PATCH] fix nullpointer on snapsync (#3773) Signed-off-by: Karim TAAM --- .../sync/snapsync/SnapWorldDownloadState.java | 9 ++------- .../snapsync/SnapWorldDownloadStateTest.java | 18 ++++++++++++++++++ 2 files changed, 20 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 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(); + } }