Skip to content

Commit

Permalink
Remove a BonsaiWorldStateProvider constructor
Browse files Browse the repository at this point in the history
Was only used for supporting test code and can instead reuse static factory from InMemoryKeyValueStorageProvider
Signed-off-by: Simon Dudley <[email protected]>
  • Loading branch information
siladu committed Oct 24, 2023
1 parent 840b3c8 commit ec6f52b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@
import org.hyperledger.besu.ethereum.proof.WorldStateProof;
import org.hyperledger.besu.ethereum.proof.WorldStateProofProvider;
import org.hyperledger.besu.ethereum.rlp.RLP;
import org.hyperledger.besu.ethereum.storage.StorageProvider;
import org.hyperledger.besu.ethereum.trie.MerkleTrieException;
import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie;
import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat;
import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.evm.worldstate.WorldState;
Expand Down Expand Up @@ -69,24 +67,6 @@ public class BonsaiWorldStateProvider implements WorldStateArchive {
private final BonsaiWorldStateKeyValueStorage worldStateStorage;
private final CachedMerkleTrieLoader cachedMerkleTrieLoader;

public BonsaiWorldStateProvider(
final StorageProvider provider,
final Blockchain blockchain,
final CachedMerkleTrieLoader cachedMerkleTrieLoader,
final ObservableMetricsSystem metricsSystem,
final BesuContext pluginContext,
final TrieLogPruner trieLogPruner) {
this(
(BonsaiWorldStateKeyValueStorage)
provider.createWorldStateStorage(DataStorageFormat.BONSAI),
blockchain,
Optional.empty(),
cachedMerkleTrieLoader,
metricsSystem,
pluginContext,
trieLogPruner);
}

public BonsaiWorldStateProvider(
final BonsaiWorldStateKeyValueStorage worldStateStorage,
final Blockchain blockchain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.hyperledger.besu.ethereum.bonsai.BonsaiWorldStateProvider;
import org.hyperledger.besu.ethereum.bonsai.cache.CachedMerkleTrieLoader;
import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogPruner;
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.chain.DefaultBlockchain;
Expand All @@ -36,6 +37,8 @@
import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage;
import org.hyperledger.besu.services.kvstore.SegmentedInMemoryKeyValueStorage;

import java.util.Optional;

public class InMemoryKeyValueStorageProvider extends KeyValueStorageProvider {

public InMemoryKeyValueStorageProvider() {
Expand Down Expand Up @@ -87,8 +90,10 @@ public static BonsaiWorldStateProvider createBonsaiInMemoryWorldStateArchive(
final CachedMerkleTrieLoader cachedMerkleTrieLoader =
new CachedMerkleTrieLoader(new NoOpMetricsSystem());
return new BonsaiWorldStateProvider(
inMemoryKeyValueStorageProvider,
(BonsaiWorldStateKeyValueStorage)
inMemoryKeyValueStorageProvider.createWorldStateStorage(DataStorageFormat.BONSAI),
blockchain,
Optional.empty(),
cachedMerkleTrieLoader,
new NoOpMetricsSystem(),
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.bonsai.BonsaiWorldStateProvider;
import org.hyperledger.besu.ethereum.bonsai.cache.CachedMerkleTrieLoader;
import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogPruner;
import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldState;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
Expand Down Expand Up @@ -83,19 +81,10 @@ public class BlockImportExceptionHandlingTest {
private final WorldStateStorage worldStateStorage =
new BonsaiWorldStateKeyValueStorage(storageProvider, new NoOpMetricsSystem());

private CachedMerkleTrieLoader cachedMerkleTrieLoader;

private final WorldStateArchive worldStateArchive =
// contains a BonsaiWorldState which we need to spy on.
// do we need to also test with a DefaultWorldStateArchive?
spy(
new BonsaiWorldStateProvider(
storageProvider,
blockchain,
cachedMerkleTrieLoader,
new NoOpMetricsSystem(),
null,
TrieLogPruner.noOpTrieLogPruner()));
spy(InMemoryKeyValueStorageProvider.createBonsaiInMemoryWorldStateArchive(blockchain));

private final BonsaiWorldState persisted =
spy(
Expand All @@ -115,7 +104,6 @@ public void setup() {
mainnetBlockValidator =
new MainnetBlockValidator(
blockHeaderValidator, blockBodyValidator, blockProcessor, badBlockManager);
cachedMerkleTrieLoader = new CachedMerkleTrieLoader(new NoOpMetricsSystem());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.bonsai.cache.CachedMerkleTrieLoader;
import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogFactoryImpl;
import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogLayer;
import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogPruner;
import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldState;
import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldStateUpdateAccumulator;
import org.hyperledger.besu.ethereum.chain.Blockchain;
Expand Down Expand Up @@ -129,16 +127,7 @@ class LogRollingTests {
@BeforeEach
void createStorage() {
provider = new InMemoryKeyValueStorageProvider();
final CachedMerkleTrieLoader cachedMerkleTrieLoader =
new CachedMerkleTrieLoader(new NoOpMetricsSystem());
archive =
new BonsaiWorldStateProvider(
provider,
blockchain,
cachedMerkleTrieLoader,
new NoOpMetricsSystem(),
null,
TrieLogPruner.noOpTrieLogPruner());
archive = InMemoryKeyValueStorageProvider.createBonsaiInMemoryWorldStateArchive(blockchain);
accountStorage =
provider.getStorageBySegmentIdentifier(KeyValueSegmentIdentifier.ACCOUNT_INFO_STATE);
codeStorage = provider.getStorageBySegmentIdentifier(KeyValueSegmentIdentifier.CODE_STORAGE);
Expand All @@ -150,16 +139,8 @@ void createStorage() {
provider.getStorageBySegmentIdentifier(KeyValueSegmentIdentifier.TRIE_LOG_STORAGE);

secondProvider = new InMemoryKeyValueStorageProvider();
final CachedMerkleTrieLoader secondOptimizedMerkleTrieLoader =
new CachedMerkleTrieLoader(new NoOpMetricsSystem());
secondArchive =
new BonsaiWorldStateProvider(
secondProvider,
blockchain,
secondOptimizedMerkleTrieLoader,
new NoOpMetricsSystem(),
null,
TrieLogPruner.noOpTrieLogPruner());
InMemoryKeyValueStorageProvider.createBonsaiInMemoryWorldStateArchive(blockchain);
secondAccountStorage =
secondProvider.getStorageBySegmentIdentifier(KeyValueSegmentIdentifier.ACCOUNT_INFO_STATE);
secondCodeStorage =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.CODE_STORAGE;
import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.TRIE_BRANCH_STORAGE;

import org.hyperledger.besu.ethereum.bonsai.cache.CachedMerkleTrieLoader;
import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogFactoryImpl;
import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogLayer;
import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogPruner;
import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldState;
import org.hyperledger.besu.ethereum.bonsai.worldview.BonsaiWorldStateUpdateAccumulator;
import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider;
Expand All @@ -52,16 +50,8 @@ public static void main(final String[] arg) throws IOException {
new RollingFileReader((i, c) -> Path.of(String.format(arg[0] + "-%04d.rdat", i)), false);

final InMemoryKeyValueStorageProvider provider = new InMemoryKeyValueStorageProvider();
final CachedMerkleTrieLoader cachedMerkleTrieLoader =
new CachedMerkleTrieLoader(new NoOpMetricsSystem());
final BonsaiWorldStateProvider archive =
new BonsaiWorldStateProvider(
provider,
null,
cachedMerkleTrieLoader,
new NoOpMetricsSystem(),
null,
TrieLogPruner.noOpTrieLogPruner());
InMemoryKeyValueStorageProvider.createBonsaiInMemoryWorldStateArchive(null);
final BonsaiWorldState bonsaiState =
new BonsaiWorldState(
archive, new BonsaiWorldStateKeyValueStorage(provider, new NoOpMetricsSystem()));
Expand Down

0 comments on commit ec6f52b

Please sign in to comment.