Skip to content

Commit

Permalink
refactor a bit and a few test tweaks
Browse files Browse the repository at this point in the history
Signed-off-by: garyschulte <[email protected]>
  • Loading branch information
garyschulte committed Oct 24, 2024
1 parent 757b592 commit 6f04716
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public void bonsaiTrieLogPruningLimitLegacyOption() {
internalTestSuccess(
dataStorageConfiguration ->
assertThat(dataStorageConfiguration.getBonsaiTrieLogPruningWindowSize()).isEqualTo(600),
"--Xbonsai-limit-trie-logs-enabled",
"--Xbonsai-trie-logs-pruning-window-size",
"--bonsai-limit-trie-logs-enabled",
"--bonsai-trie-logs-pruning-window-size",
"600");
}

Expand Down
3 changes: 2 additions & 1 deletion besu/src/test/resources/everything_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ bonsai-historical-block-limit=512
bonsai-limit-trie-logs-enabled=true
bonsai-trie-logs-pruning-window-size=100_000
receipt-compaction-enabled=true
hash-preimage-storage-enabled=true

# feature flags
Xsecp256k1-native-enabled=false
Expand Down Expand Up @@ -248,4 +249,4 @@ Xevm-jumpdest-cache-weight-kb=32000
# plugins
Xplugins-external-enabled=true
plugins=["none"]
plugin-continue-on-error=false
plugin-continue-on-error=false
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private void updateTheAccounts(
final BonsaiAccount updatedAccount = bonsaiValue.getUpdated();
try {
if (updatedAccount == null) {
final Hash addressHash = preImageProxy.hashAndSaveAddressPreImage(accountKey);
final Hash addressHash = getPreImageProxy().hashAndSaveAddressPreImage(accountKey);
accountTrie.remove(addressHash);
maybeStateUpdater.ifPresent(
bonsaiUpdater -> bonsaiUpdater.removeAccountInfoState(addressHash));
Expand All @@ -202,7 +202,7 @@ private void updateTheAccounts(
maybeStateUpdater.ifPresent(
bonsaiUpdater ->
bonsaiUpdater.putAccountInfoState(
preImageProxy.hashAndSaveAddressPreImage(accountKey), accountValue));
getPreImageProxy().hashAndSaveAddressPreImage(accountKey), accountValue));
accountTrie.put(addressHash, accountValue);
}
} catch (MerkleTrieException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.hyperledger.besu.datatypes.StorageSlotKey;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.BonsaiAccount;
import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.CachingPreImageStorage;
import org.hyperledger.besu.ethereum.trie.diffbased.common.DiffBasedValue;
import org.hyperledger.besu.ethereum.trie.diffbased.common.worldview.DiffBasedWorldView;
import org.hyperledger.besu.ethereum.trie.diffbased.common.worldview.accumulator.DiffBasedWorldStateUpdateAccumulator;
Expand Down Expand Up @@ -95,9 +94,4 @@ protected void assertCloseEnoughForDiffing(
final BonsaiAccount source, final AccountValue account, final String context) {
BonsaiAccount.assertCloseEnoughForDiffing(source, account, context);
}

@Override
public CachingPreImageStorage getPreImageProxy() {
return world.getPreImageProxy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public abstract class DiffBasedWorldStateKeyValueStorage
LoggerFactory.getLogger(DiffBasedWorldStateKeyValueStorage.class);

// TODO: config this based on dataStorageConfiguration, use real storage where appropriate
protected final CachingPreImageStorage preImageProxy =
// currently hard-coded to Unbounded preimage store so ref/spec tests pass
private static final CachingPreImageStorage preImageProxy =
new CachingPreImageStorage.UnboundedPreImageStorage();

// 0x776f726c64526f6f74
Expand Down Expand Up @@ -109,6 +110,10 @@ public SegmentedKeyValueStorage getComposedWorldStateStorage() {
return composedWorldStateStorage;
}

public CachingPreImageStorage getPreImageProxy() {
return preImageProxy;
}

public KeyValueStorage getTrieLogStorage() {
return trieLogStorage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ public abstract class DiffBasedWorldState

private static final Logger LOG = LoggerFactory.getLogger(DiffBasedWorldState.class);

// TODO: where the shit to initialize you? just use unbounded for now to ensure ref tests pass
protected static final CachingPreImageStorage preImageProxy =
new CachingPreImageStorage.UnboundedPreImageStorage(); // CachingOnlyPreImageStorage();

protected DiffBasedWorldStateKeyValueStorage worldStateKeyValueStorage;
protected final DiffBasedCachedWorldStorageManager cachedWorldStorageManager;
protected final TrieLogManager trieLogManager;
Expand Down Expand Up @@ -124,7 +120,7 @@ private boolean isPersisted(final WorldStateKeyValueStorage worldStateKeyValueSt

@Override
public CachingPreImageStorage getPreImageProxy() {
return preImageProxy;
return worldStateKeyValueStorage.getPreImageProxy();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.rlp.RLP;
import org.hyperledger.besu.ethereum.trie.MerkleTrieException;
import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.CachingPreImageStorage;
import org.hyperledger.besu.ethereum.trie.diffbased.common.DiffBasedAccount;
import org.hyperledger.besu.ethereum.trie.diffbased.common.DiffBasedValue;
import org.hyperledger.besu.ethereum.trie.diffbased.common.storage.DiffBasedWorldStateKeyValueStorage;
Expand Down Expand Up @@ -614,6 +615,11 @@ public DiffBasedWorldStateKeyValueStorage getWorldStateStorage() {
return wrappedWorldView().getWorldStateStorage();
}

@Override
public CachingPreImageStorage getPreImageProxy() {
return wrappedWorldView().getPreImageProxy();
}

public void rollForward(final TrieLog layer) {
layer
.getAccountChanges()
Expand Down Expand Up @@ -881,7 +887,7 @@ public void reset() {

protected Hash hashAndSaveAccountPreImage(final Address address) {
// default to using address static hash cache:
return address.addressHash();
return getPreImageProxy().hashAndSaveAddressPreImage(address);
}

public abstract DiffBasedWorldStateUpdateAccumulator<ACCOUNT> copy();
Expand Down

0 comments on commit 6f04716

Please sign in to comment.