Skip to content

Commit

Permalink
Create new DiffBasedWorldStateConfig when copying bonsai archive worl…
Browse files Browse the repository at this point in the history
…d state, and freeze it

Signed-off-by: Matthew Whitehead <[email protected]>
  • Loading branch information
matthew1001 committed Aug 20, 2024
1 parent a49e8b6 commit de5109a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,14 @@ public Optional<MutableWorldState> getMutable(
var contextSafeCopy =
((BonsaiWorldStateKeyValueStorage) worldStateKeyValueStorage).getContextSafeCopy();
contextSafeCopy.getFlatDbStrategy().updateBlockContext(blockHeader);
return Optional.of(
BonsaiWorldState worldState =
new BonsaiWorldState(
this, contextSafeCopy, evmConfiguration, this.defaultWorldStateConfig));
this,
contextSafeCopy,
evmConfiguration,
new DiffBasedWorldStateConfig(defaultWorldStateConfig));
worldState.freeze();
return Optional.of(worldState);
}

final BlockHeader chainHeadBlockHeader = blockchain.getChainHeadHeader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.CODE_STORAGE;
import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.TRIE_BRANCH_STORAGE;
import static org.hyperledger.besu.ethereum.trie.diffbased.common.storage.DiffBasedWorldStateKeyValueStorage.WORLD_ROOT_HASH_KEY;

import org.hyperledger.besu.ethereum.bonsai.BonsaiContext;
import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.flat.ArchiveCodeStorageStrategy;
Expand Down Expand Up @@ -79,13 +78,14 @@ public void loadFlatDbStrategy(final SegmentedKeyValueStorage composedWorldState

@VisibleForTesting
FlatDbMode deriveFlatDbStrategy(final SegmentedKeyValueStorage composedWorldStateStorage) {
final FlatDbMode requestedFlatDbMode =
dataStorageConfiguration.getUnstable().getBonsaiFullFlatDbEnabled()
? FlatDbMode.FULL
: FlatDbMode.PARTIAL;
// final FlatDbMode requestedFlatDbMode =
// dataStorageConfiguration.getUnstable().getBonsaiFullFlatDbEnabled()
// ? FlatDbMode.FULL
// : FlatDbMode.PARTIAL;

final var existingTrieData =
composedWorldStateStorage.get(TRIE_BRANCH_STORAGE, WORLD_ROOT_HASH_KEY).isPresent();
// TODO: commented out for archive testing
// final var existingTrieData =
// composedWorldStateStorage.get(TRIE_BRANCH_STORAGE, WORLD_ROOT_HASH_KEY).isPresent();

var flatDbMode =
FlatDbMode.fromVersion(
Expand All @@ -99,10 +99,10 @@ FlatDbMode deriveFlatDbStrategy(final SegmentedKeyValueStorage composedWorldStat
// and default to the storage config otherwise

// TODO: temporarily hard code ARCHIVE mode for testing
var flatDbModeVal =
existingTrieData
? FlatDbMode.ARCHIVE.getVersion()
: requestedFlatDbMode.getVersion();
var flatDbModeVal = FlatDbMode.ARCHIVE.getVersion();
// existingTrieData
// ? FlatDbMode.ARCHIVE.getVersion()
// : requestedFlatDbMode.getVersion();
// persist this config in the db
var setDbModeTx = composedWorldStateStorage.startTransaction();
setDbModeTx.put(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public void persist(final BlockHeader blockHeader) {

boolean success = false;

this.worldStateKeyValueStorage.getFlatDbStrategy().updateBlockContext(blockHeader);
final DiffBasedWorldStateKeyValueStorage.Updater stateUpdater =
worldStateKeyValueStorage.updater();
Runnable saveTrieLog = () -> {};
Expand Down

0 comments on commit de5109a

Please sign in to comment.