|
|
|
@ -37,8 +37,8 @@ import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStatePreimageKeyValue |
|
|
|
|
import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.cache.BonsaiCachedMerkleTrieLoader; |
|
|
|
|
import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.cache.BonsaiNoOpCachedWorldStorageManager; |
|
|
|
|
import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; |
|
|
|
|
import org.hyperledger.besu.ethereum.trie.diffbased.common.trielog.NoOpTrieLogManager; |
|
|
|
|
import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.worldview.BonsaiWorldState; |
|
|
|
|
import org.hyperledger.besu.ethereum.trie.diffbased.common.trielog.NoOpTrieLogManager; |
|
|
|
|
import org.hyperledger.besu.ethereum.trie.diffbased.verkle.cache.VerkleNoOpCachedWorldStorageManager; |
|
|
|
|
import org.hyperledger.besu.ethereum.trie.diffbased.verkle.storage.VerkleWorldStateKeyValueStorage; |
|
|
|
|
import org.hyperledger.besu.ethereum.trie.diffbased.verkle.worldview.VerkleWorldState; |
|
|
|
@ -51,6 +51,7 @@ import org.hyperledger.besu.evm.log.LogsBloomFilter; |
|
|
|
|
import org.hyperledger.besu.evm.worldstate.WorldUpdater; |
|
|
|
|
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; |
|
|
|
|
import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; |
|
|
|
|
import org.hyperledger.besu.services.kvstore.SegmentedInMemoryKeyValueStorage; |
|
|
|
|
|
|
|
|
|
import java.math.BigInteger; |
|
|
|
|
import java.util.HashMap; |
|
|
|
@ -66,7 +67,6 @@ import com.google.common.base.MoreObjects; |
|
|
|
|
import org.apache.tuweni.bytes.Bytes; |
|
|
|
|
import org.apache.tuweni.bytes.Bytes32; |
|
|
|
|
import org.apache.tuweni.units.bigints.UInt256; |
|
|
|
|
import org.hyperledger.besu.services.kvstore.SegmentedInMemoryKeyValueStorage; |
|
|
|
|
|
|
|
|
|
public final class GenesisState { |
|
|
|
|
|
|
|
|
@ -87,9 +87,9 @@ public final class GenesisState { |
|
|
|
|
* @return A new {@link GenesisState}. |
|
|
|
|
*/ |
|
|
|
|
public static GenesisState fromJson( |
|
|
|
|
final DataStorageFormat dataStorageFormat, |
|
|
|
|
final String json, |
|
|
|
|
final ProtocolSchedule protocolSchedule) { |
|
|
|
|
final DataStorageFormat dataStorageFormat, |
|
|
|
|
final String json, |
|
|
|
|
final ProtocolSchedule protocolSchedule) { |
|
|
|
|
return fromConfig(dataStorageFormat, GenesisConfigFile.fromConfig(json), protocolSchedule); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -105,13 +105,15 @@ public final class GenesisState { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Construct a {@link GenesisState} from a JSON object with FOREST as a default data storage format. |
|
|
|
|
* Construct a {@link GenesisState} from a JSON object with FOREST as a default data storage |
|
|
|
|
* format. |
|
|
|
|
* |
|
|
|
|
* @param config A {@link GenesisConfigFile} describing the genesis block. |
|
|
|
|
* @param protocolSchedule A protocol Schedule associated with |
|
|
|
|
*/ |
|
|
|
|
public static GenesisState fromConfig( |
|
|
|
|
final GenesisConfigFile config, final ProtocolSchedule protocolSchedule) { |
|
|
|
|
return fromConfig(DataStorageFormat.FOREST, config, protocolSchedule); |
|
|
|
|
final GenesisConfigFile config, final ProtocolSchedule protocolSchedule) { |
|
|
|
|
return fromConfig(DataStorageFormat.FOREST, config, protocolSchedule); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* Construct a {@link GenesisState} from a JSON object. |
|
|
|
@ -122,17 +124,17 @@ public final class GenesisState { |
|
|
|
|
* @return A new {@link GenesisState}. |
|
|
|
|
*/ |
|
|
|
|
public static GenesisState fromConfig( |
|
|
|
|
final DataStorageFormat dataStorageFormat, |
|
|
|
|
final GenesisConfigFile config, |
|
|
|
|
final ProtocolSchedule protocolSchedule) { |
|
|
|
|
final DataStorageFormat dataStorageFormat, |
|
|
|
|
final GenesisConfigFile config, |
|
|
|
|
final ProtocolSchedule protocolSchedule) { |
|
|
|
|
final List<GenesisAccount> genesisAccounts = parseAllocations(config).toList(); |
|
|
|
|
final Block block = |
|
|
|
|
new Block( |
|
|
|
|
buildHeader( |
|
|
|
|
config, |
|
|
|
|
calculateGenesisStateHash(dataStorageFormat, genesisAccounts), |
|
|
|
|
protocolSchedule), |
|
|
|
|
buildBody(config)); |
|
|
|
|
new Block( |
|
|
|
|
buildHeader( |
|
|
|
|
config, |
|
|
|
|
calculateGenesisStateHash(dataStorageFormat, genesisAccounts), |
|
|
|
|
protocolSchedule), |
|
|
|
|
buildBody(config)); |
|
|
|
|
return new GenesisState(block, genesisAccounts); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -176,7 +178,7 @@ public final class GenesisState { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static Hash calculateGenesisStateHash( |
|
|
|
|
final DataStorageFormat dataStorageFormat, final List<GenesisAccount> genesisAccounts) { |
|
|
|
|
final DataStorageFormat dataStorageFormat, final List<GenesisAccount> genesisAccounts) { |
|
|
|
|
final MutableWorldState worldState = loadWorldState(dataStorageFormat); |
|
|
|
|
writeAccountsTo(worldState, genesisAccounts, null); |
|
|
|
|
return worldState.rootHash(); |
|
|
|
@ -186,40 +188,40 @@ public final class GenesisState { |
|
|
|
|
switch (dataStorageFormat) { |
|
|
|
|
case BONSAI -> { |
|
|
|
|
final BonsaiCachedMerkleTrieLoader cachedMerkleTrieLoader = |
|
|
|
|
new BonsaiCachedMerkleTrieLoader(new NoOpMetricsSystem()); |
|
|
|
|
new BonsaiCachedMerkleTrieLoader(new NoOpMetricsSystem()); |
|
|
|
|
final BonsaiWorldStateKeyValueStorage bonsaiWorldStateKeyValueStorage = |
|
|
|
|
new BonsaiWorldStateKeyValueStorage( |
|
|
|
|
new KeyValueStorageProvider( |
|
|
|
|
segmentIdentifiers -> new SegmentedInMemoryKeyValueStorage(), |
|
|
|
|
new InMemoryKeyValueStorage(), |
|
|
|
|
new NoOpMetricsSystem()), |
|
|
|
|
new NoOpMetricsSystem()); |
|
|
|
|
new BonsaiWorldStateKeyValueStorage( |
|
|
|
|
new KeyValueStorageProvider( |
|
|
|
|
segmentIdentifiers -> new SegmentedInMemoryKeyValueStorage(), |
|
|
|
|
new InMemoryKeyValueStorage(), |
|
|
|
|
new NoOpMetricsSystem()), |
|
|
|
|
new NoOpMetricsSystem()); |
|
|
|
|
return new BonsaiWorldState( |
|
|
|
|
bonsaiWorldStateKeyValueStorage, |
|
|
|
|
cachedMerkleTrieLoader, |
|
|
|
|
new BonsaiNoOpCachedWorldStorageManager(bonsaiWorldStateKeyValueStorage), |
|
|
|
|
new NoOpTrieLogManager(), |
|
|
|
|
EvmConfiguration.DEFAULT); |
|
|
|
|
bonsaiWorldStateKeyValueStorage, |
|
|
|
|
cachedMerkleTrieLoader, |
|
|
|
|
new BonsaiNoOpCachedWorldStorageManager(bonsaiWorldStateKeyValueStorage), |
|
|
|
|
new NoOpTrieLogManager(), |
|
|
|
|
EvmConfiguration.DEFAULT); |
|
|
|
|
} |
|
|
|
|
case VERKLE -> { |
|
|
|
|
final VerkleWorldStateKeyValueStorage verkleWorldStateKeyValueStorage = |
|
|
|
|
new VerkleWorldStateKeyValueStorage( |
|
|
|
|
new KeyValueStorageProvider( |
|
|
|
|
segmentIdentifiers -> new SegmentedInMemoryKeyValueStorage(), |
|
|
|
|
new InMemoryKeyValueStorage(), |
|
|
|
|
new NoOpMetricsSystem()), |
|
|
|
|
new NoOpMetricsSystem()); |
|
|
|
|
new VerkleWorldStateKeyValueStorage( |
|
|
|
|
new KeyValueStorageProvider( |
|
|
|
|
segmentIdentifiers -> new SegmentedInMemoryKeyValueStorage(), |
|
|
|
|
new InMemoryKeyValueStorage(), |
|
|
|
|
new NoOpMetricsSystem()), |
|
|
|
|
new NoOpMetricsSystem()); |
|
|
|
|
return new VerkleWorldState( |
|
|
|
|
verkleWorldStateKeyValueStorage, |
|
|
|
|
new VerkleNoOpCachedWorldStorageManager(verkleWorldStateKeyValueStorage), |
|
|
|
|
new NoOpTrieLogManager(), |
|
|
|
|
EvmConfiguration.DEFAULT); |
|
|
|
|
verkleWorldStateKeyValueStorage, |
|
|
|
|
new VerkleNoOpCachedWorldStorageManager(verkleWorldStateKeyValueStorage), |
|
|
|
|
new NoOpTrieLogManager(), |
|
|
|
|
EvmConfiguration.DEFAULT); |
|
|
|
|
} |
|
|
|
|
default -> { |
|
|
|
|
final ForestWorldStateKeyValueStorage stateStorage = |
|
|
|
|
new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); |
|
|
|
|
new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage()); |
|
|
|
|
final WorldStatePreimageKeyValueStorage preimageStorage = |
|
|
|
|
new WorldStatePreimageKeyValueStorage(new InMemoryKeyValueStorage()); |
|
|
|
|
new WorldStatePreimageKeyValueStorage(new InMemoryKeyValueStorage()); |
|
|
|
|
return new ForestMutableWorldState(stateStorage, preimageStorage, EvmConfiguration.DEFAULT); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|