Skip to content

Commit

Permalink
fix nullpointer on snapsync (#3773)
Browse files Browse the repository at this point in the history
Signed-off-by: Karim TAAM <[email protected]>
  • Loading branch information
matkt committed May 3, 2022
1 parent a154034 commit beb4e3b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
}

0 comments on commit beb4e3b

Please sign in to comment.