Skip to content

Commit

Permalink
fix bonsai bug during fastsync - mark the worldtsate as missing (#3712)
Browse files Browse the repository at this point in the history
Fix a bug that caused the worldstate to be missing during a fastsync and prevented it from completing properly

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
  • Loading branch information
matkt authored Apr 10, 2022
1 parent f27fd8d commit 009c246
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ public Updater putAccountInfoState(final Hash accountHash, final Bytes accountVa
public WorldStateStorage.Updater saveWorldState(
final Bytes blockHash, final Bytes32 nodeHash, final Bytes node) {
trieBranchStorageTransaction.put(Bytes.EMPTY.toArrayUnsafe(), node.toArrayUnsafe());
trieBranchStorageTransaction.put(WORLD_ROOT_HASH_KEY, nodeHash.toArrayUnsafe());
trieBranchStorageTransaction.put(WORLD_BLOCK_HASH_KEY, blockHash.toArrayUnsafe());
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,24 @@ public void isWorldStateAvailable_StateAvailableByRootHash() {
.isTrue();
}

@Test
public void isWorldStateAvailable_afterCallingSaveWorldstate() {

final BonsaiWorldStateKeyValueStorage storage = emptyStorage();
final BonsaiWorldStateKeyValueStorage.Updater updater = storage.updater();

final Bytes blockHash = Bytes32.fromHexString("0x01");
final Bytes32 nodeHashKey = Bytes32.fromHexString("0x02");
final Bytes nodeValue = Bytes32.fromHexString("0x03");

assertThat(storage.isWorldStateAvailable(Bytes32.wrap(nodeHashKey), Hash.EMPTY)).isFalse();

updater.saveWorldState(blockHash, nodeHashKey, nodeValue);
updater.commit();

assertThat(storage.isWorldStateAvailable(Bytes32.wrap(nodeHashKey), Hash.EMPTY)).isTrue();
}

private BonsaiWorldStateKeyValueStorage emptyStorage() {
return new BonsaiWorldStateKeyValueStorage(new InMemoryKeyValueStorageProvider());
}
Expand Down

0 comments on commit 009c246

Please sign in to comment.