Reload flat db strategy on clear (#5619)

* reload flat db strategy on clear

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>

---------

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
pull/5620/head
matkt 1 year ago committed by GitHub
parent 50ea7268ee
commit 0c4b1d9966
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/BonsaiWorldStateKeyValueStorage.java
  2. 18
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateKeyValueStorageTest.java

@ -87,7 +87,7 @@ public class BonsaiWorldStateKeyValueStorage implements WorldStateStorage, AutoC
this.trieLogStorage =
provider.getStorageBySegmentIdentifier(KeyValueSegmentIdentifier.TRIE_LOG_STORAGE);
this.metricsSystem = metricsSystem;
initFlatDbStrategy();
loadFlatDbStrategy();
}
public BonsaiWorldStateKeyValueStorage(
@ -109,7 +109,7 @@ public class BonsaiWorldStateKeyValueStorage implements WorldStateStorage, AutoC
this.metricsSystem = metricsSystem;
}
public void initFlatDbStrategy() {
public void loadFlatDbStrategy() {
this.flatDbMode =
FlatDbMode.fromVersion(
trieBranchStorage
@ -275,14 +275,14 @@ public class BonsaiWorldStateKeyValueStorage implements WorldStateStorage, AutoC
final KeyValueStorageTransaction transaction = trieBranchStorage.startTransaction();
transaction.put(FLAT_DB_MODE, FlatDbMode.FULL.getVersion().toArrayUnsafe());
transaction.commit();
initFlatDbStrategy(); // force reload of flat db reader strategy
loadFlatDbStrategy(); // force reload of flat db reader strategy
}
public void downgradeToPartialFlatDbMode() {
final KeyValueStorageTransaction transaction = trieBranchStorage.startTransaction();
transaction.put(FLAT_DB_MODE, FlatDbMode.PARTIAL.getVersion().toArrayUnsafe());
transaction.commit();
initFlatDbStrategy(); // force reload of flat db reader strategy
loadFlatDbStrategy(); // force reload of flat db reader strategy
}
@Override
@ -291,7 +291,7 @@ public class BonsaiWorldStateKeyValueStorage implements WorldStateStorage, AutoC
getFlatDbReaderStrategy().clearAll(accountStorage, storageStorage, codeStorage);
trieBranchStorage.clear();
trieLogStorage.clear();
flatDbReaderStrategy = null; // force reload of flat db reader strategy
loadFlatDbStrategy(); // force reload of flat db reader strategy
}
@Override

@ -335,6 +335,24 @@ public class BonsaiWorldStateKeyValueStorageTest {
storage.clearFlatDatabase();
}
@Test
public void clear_reloadFlatDbStrategy() {
final BonsaiWorldStateKeyValueStorage storage = spy(emptyStorage());
// save world state root hash
final BonsaiWorldStateKeyValueStorage.BonsaiUpdater updater = storage.updater();
updater.putAccountInfoState(Hash.ZERO, Bytes32.random()).commit();
assertThat(storage.getAccount(Hash.ZERO)).isNotEmpty();
// clear
storage.clear();
assertThat(storage.getFlatDbReaderStrategy()).isNotNull();
assertThat(storage.getAccount(Hash.ZERO)).isEmpty();
}
@Test
public void reconcilesNonConflictingUpdaters() {
final Hash accountHashA = Hash.hash(Address.fromHexString("0x1"));

Loading…
Cancel
Save