Skip to content

Commit

Permalink
reset cache after heal (hyperledger#5266)
Browse files Browse the repository at this point in the history
* reset cache after heal

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
  • Loading branch information
matkt authored and elenduuche committed Aug 16, 2023
1 parent b07083e commit 9220bb8
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,11 @@ public TrieLogManager getTrieLogManager() {
}

@Override
public void setArchiveStateUnSafe(final BlockHeader blockHeader) {
persistedState.setArchiveStateUnSafe(blockHeader);
public void resetArchiveStateTo(final BlockHeader blockHeader) {
persistedState.resetWorldStateTo(blockHeader);
this.trieLogManager.reset();
this.trieLogManager.addCachedLayer(
blockHeader, persistedState.worldStateRootHash, persistedState);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ public Optional<BonsaiWorldState> getHeadWorldState(
});
}

@Override
public void reset() {
this.cachedWorldStatesByHash.clear();
}

@Override
public void onClearStorage() {
this.cachedWorldStatesByHash.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@ Optional<BonsaiWorldState> getHeadWorldState(

long getMaxLayersToLoad();

void reset();

Optional<TrieLogLayer> getTrieLogLayer(final Hash blockHash);
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ public Optional<Bytes> getCode(@Nonnull final Address address, final Hash codeHa
return worldStateStorage.getCode(codeHash, Hash.hash(address));
}

public void setArchiveStateUnSafe(final BlockHeader blockHeader) {
/**
* Reset the worldState to this block header
*
* @param blockHeader block to use
*/
public void resetWorldStateTo(final BlockHeader blockHeader) {
worldStateBlockHash = Hash.fromPlugin(blockHeader.getBlockHash());
worldStateRootHash = Hash.fromPlugin(blockHeader.getStateRoot());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public MutableWorldState getMutable() {
}

@Override
public void setArchiveStateUnSafe(final BlockHeader blockHeader) {
public void resetArchiveStateTo(final BlockHeader blockHeader) {
// ignore for forest
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ public interface WorldStateArchive extends Closeable {

MutableWorldState getMutable();

void setArchiveStateUnSafe(BlockHeader blockHeader);
/**
* Resetting the archive cache and adding the new pivot as the only entry
*
* @param blockHeader new pivot block header
*/
void resetArchiveStateTo(BlockHeader blockHeader);

Optional<Bytes> getNodeData(Hash hash);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ private CompletableFuture<Void> handleSyncResult(final FastSyncState result) {
result
.getPivotBlockHeader()
.ifPresent(
blockHeader ->
protocolContext.getWorldStateArchive().setArchiveStateUnSafe(blockHeader));
blockHeader -> protocolContext.getWorldStateArchive().resetArchiveStateTo(blockHeader));
LOG.info(
"Sync completed successfully with pivot block {}",
result.getPivotBlockNumber().getAsLong());
Expand Down

0 comments on commit 9220bb8

Please sign in to comment.