Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d459de9
Mostly There
shemnon Sep 12, 2023
0e99d78
merge
shemnon Sep 13, 2023
59164b4
Merge branch 'main' of github.com:hyperledger/besu into journaled-wor…
shemnon Sep 18, 2023
0f33d7f
Merge branch 'main' of github.com:hyperledger/besu into journaled-wor…
shemnon Sep 19, 2023
2aa8bc4
spotless
shemnon Sep 21, 2023
5880090
Merge remote-tracking branch 'upstream/main' into journaled-world-state
shemnon Sep 24, 2023
b430ee9
javadoc
shemnon Sep 25, 2023
36fbab5
Merge branch 'main' of github.com:hyperledger/besu into journaled-wor…
shemnon Oct 2, 2023
98a06e8
merge
shemnon Oct 9, 2023
4d3ccff
Merge branch 'main' of github.com:hyperledger/besu into journaled-wor…
shemnon Oct 10, 2023
01b793f
Wire in stacked vs journaled updater
shemnon Oct 11, 2023
00defce
cleanup and expose to evmtool
shemnon Oct 13, 2023
830ab3d
expose worldstate status on startup
shemnon Oct 13, 2023
a3ba879
fix original value retrieval
shemnon Oct 14, 2023
91c1909
Merge branch 'main' into journaled-world-state
shemnon Oct 16, 2023
414bbdc
Merge branch 'main' into journaled-world-state
shemnon Oct 25, 2023
fae36d4
add in hedges against state tests for journaled mode
shemnon Oct 25, 2023
a37fd7b
Use 5723 fork demarcations.
shemnon Oct 26, 2023
86815f6
merge
shemnon Oct 26, 2023
9493c70
review comments
shemnon Oct 30, 2023
27c6a00
Merge branch 'main' of github.com:hyperledger/besu into journaled-wor…
shemnon Oct 30, 2023
6ada1ef
Merge branch 'main' into journaled-world-state
shemnon Oct 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.hyperledger.besu.cli.options.CLIOptions;
import org.hyperledger.besu.evm.internal.EvmConfiguration;

import java.util.Arrays;
import java.util.List;

import picocli.CommandLine;
Expand All @@ -29,6 +28,9 @@ public class EvmOptions implements CLIOptions<EvmConfiguration> {
/** The constant JUMPDEST_CACHE_WEIGHT. */
public static final String JUMPDEST_CACHE_WEIGHT = "--Xevm-jumpdest-cache-weight-kb";

/** The constant WORLDSTATE_UPDATE_MODE. */
public static final String WORLDSTATE_UPDATE_MODE = "--Xevm-worldstate-update-mode";

/**
* Create evm options.
*
Expand All @@ -51,13 +53,24 @@ public static EvmOptions create() {
private Long jumpDestCacheWeightKilobytes =
32_000L; // 10k contracts, (25k max contract size / 8 bit) + 32byte hash

@CommandLine.Option(
names = {WORLDSTATE_UPDATE_MODE},
description = "How to handle worldstate updates within a transaction",
fallbackValue = "STACKED",
defaultValue = "STACKED",
hidden = true,
arity = "1")
private EvmConfiguration.WorldUpdaterMode worldstateUpdateMode =
EvmConfiguration.WorldUpdaterMode
.STACKED; // Stacked Updater. Years of battle tested correctness.

@Override
public EvmConfiguration toDomainObject() {
return new EvmConfiguration(jumpDestCacheWeightKilobytes);
return new EvmConfiguration(jumpDestCacheWeightKilobytes, worldstateUpdateMode);
}

@Override
public List<String> getCLIOptions() {
return Arrays.asList(JUMPDEST_CACHE_WEIGHT);
return List.of(JUMPDEST_CACHE_WEIGHT, WORLDSTATE_UPDATE_MODE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,60 +129,83 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides

/** The Sync config. */
protected SynchronizerConfiguration syncConfig;

/** The Ethereum wire protocol configuration. */
protected EthProtocolConfiguration ethereumWireProtocolConfiguration;

/** The Transaction pool configuration. */
protected TransactionPoolConfiguration transactionPoolConfiguration;

/** The Network id. */
protected BigInteger networkId;

/** The Mining parameters. */
protected MiningParameters miningParameters;

/** The Metrics system. */
protected ObservableMetricsSystem metricsSystem;

/** The Privacy parameters. */
protected PrivacyParameters privacyParameters;

/** The Pki block creation configuration. */
protected Optional<PkiBlockCreationConfiguration> pkiBlockCreationConfiguration =
Optional.empty();

/** The Data directory. */
protected Path dataDirectory;

/** The Clock. */
protected Clock clock;

/** The Node key. */
protected NodeKey nodeKey;

/** The Is revert reason enabled. */
protected boolean isRevertReasonEnabled;

/** The Gas limit calculator. */
GasLimitCalculator gasLimitCalculator;

/** The Storage provider. */
protected StorageProvider storageProvider;

/** The Is pruning enabled. */
protected boolean isPruningEnabled;

/** The Pruner configuration. */
protected PrunerConfiguration prunerConfiguration;

/** The Required blocks. */
protected Map<Long, Hash> requiredBlocks = Collections.emptyMap();

/** The Reorg logging threshold. */
protected long reorgLoggingThreshold;

/** The Data storage configuration. */
protected DataStorageConfiguration dataStorageConfiguration =
DataStorageConfiguration.DEFAULT_CONFIG;

/** The Message permissioning providers. */
protected List<NodeMessagePermissioningProvider> messagePermissioningProviders =
Collections.emptyList();

/** The Evm configuration. */
protected EvmConfiguration evmConfiguration;

/** The Max peers. */
protected int maxPeers;

private int peerLowerBound;
private int maxRemotelyInitiatedPeers;

/** The Chain pruner configuration. */
protected ChainPrunerConfiguration chainPrunerConfiguration = ChainPrunerConfiguration.DEFAULT;

private NetworkingConfiguration networkingConfiguration;
private Boolean randomPeerPriority;
private Optional<TransactionSelectorFactory> transactionSelectorFactory = Optional.empty();

/** the Dagger configured context that can provide dependencies */
protected Optional<BesuComponent> besuComponent = Optional.empty();

Expand Down Expand Up @@ -618,10 +641,7 @@ public BesuController build() {
if (chainPrunerConfiguration.getChainPruningEnabled()) {
protocolContext
.safeConsensusContext(MergeContext.class)
.ifPresent(
mergeContext -> {
mergeContext.setIsChainPruningEnabled(true);
});
.ifPresent(mergeContext -> mergeContext.setIsChainPruningEnabled(true));
final ChainDataPruner chainDataPruner = createChainPruner(blockchainStorage);
blockchain.observeBlockAdded(chainDataPruner);
LOG.info(
Expand Down Expand Up @@ -762,7 +782,6 @@ public BesuController build() {

final SubProtocolConfiguration subProtocolConfiguration =
createSubProtocolConfiguration(ethProtocolManager, maybeSnapProtocolManager);
;

final JsonRpcMethods additionalJsonRpcMethodFactory =
createAdditionalJsonRpcMethodFactory(protocolContext);
Expand Down Expand Up @@ -817,24 +836,21 @@ protected Synchronizer createSynchronizer(
final EthProtocolManager ethProtocolManager,
final PivotBlockSelector pivotBlockSelector) {

final DefaultSynchronizer toUse =
new DefaultSynchronizer(
syncConfig,
protocolSchedule,
protocolContext,
worldStateStorage,
ethProtocolManager.getBlockBroadcaster(),
maybePruner,
ethContext,
syncState,
dataDirectory,
storageProvider,
clock,
metricsSystem,
getFullSyncTerminationCondition(protocolContext.getBlockchain()),
pivotBlockSelector);

return toUse;
return new DefaultSynchronizer(
syncConfig,
protocolSchedule,
protocolContext,
worldStateStorage,
ethProtocolManager.getBlockBroadcaster(),
maybePruner,
ethContext,
syncState,
dataDirectory,
storageProvider,
clock,
metricsSystem,
getFullSyncTerminationCondition(protocolContext.getBlockchain()),
pivotBlockSelector);
}

private PivotBlockSelector createPivotSelector(
Expand Down Expand Up @@ -916,9 +932,8 @@ protected SubProtocolConfiguration createSubProtocolConfiguration(
final SubProtocolConfiguration subProtocolConfiguration =
new SubProtocolConfiguration().withSubProtocol(EthProtocol.get(), ethProtocolManager);
maybeSnapProtocolManager.ifPresent(
snapProtocolManager -> {
subProtocolConfiguration.withSubProtocol(SnapProtocol.get(), snapProtocolManager);
});
snapProtocolManager ->
subProtocolConfiguration.withSubProtocol(SnapProtocol.get(), snapProtocolManager));
return subProtocolConfiguration;
}

Expand Down Expand Up @@ -1057,22 +1072,21 @@ WorldStateArchive createWorldStateArchive(
final WorldStateStorage worldStateStorage,
final Blockchain blockchain,
final CachedMerkleTrieLoader cachedMerkleTrieLoader) {
switch (dataStorageConfiguration.getDataStorageFormat()) {
case BONSAI:
return new BonsaiWorldStateProvider(
(BonsaiWorldStateKeyValueStorage) worldStateStorage,
blockchain,
Optional.of(dataStorageConfiguration.getBonsaiMaxLayersToLoad()),
cachedMerkleTrieLoader,
metricsSystem,
besuComponent.map(BesuComponent::getBesuPluginContext).orElse(null));

case FOREST:
default:
return switch (dataStorageConfiguration.getDataStorageFormat()) {
case BONSAI -> new BonsaiWorldStateProvider(
(BonsaiWorldStateKeyValueStorage) worldStateStorage,
blockchain,
Optional.of(dataStorageConfiguration.getBonsaiMaxLayersToLoad()),
cachedMerkleTrieLoader,
metricsSystem,
besuComponent.map(BesuComponent::getBesuPluginContext).orElse(null),
evmConfiguration);
default -> {
final WorldStatePreimageStorage preimageStorage =
storageProvider.createWorldStatePreimageStorage();
return new DefaultWorldStateArchive(worldStateStorage, preimageStorage);
}
yield new DefaultWorldStateArchive(worldStateStorage, preimageStorage, evmConfiguration);
}
};
}

private ChainDataPruner createChainPruner(final BlockchainStorage blockchainStorage) {
Expand Down
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ allprojects {
options.encoding = 'UTF-8'
}

// IntelliJ workaround to allow repeated debugging of unchanged code
tasks.withType(JavaExec) {
if (it.name.contains(".")) {
outputs.upToDateWhen { false }
}
}

/*
* Pass some system properties provided on the gradle command line to test executions for
* convenience.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
import org.hyperledger.besu.ethereum.vm.DebugOperationTracer;
import org.hyperledger.besu.evm.worldstate.StackedUpdater;
import org.hyperledger.besu.evm.worldstate.WorldUpdater;
import org.hyperledger.besu.metrics.BesuMetricCategory;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
Expand Down Expand Up @@ -208,8 +207,8 @@ public WorldUpdater getNextUpdater() {
// if we have no prior updater, it must be the first TX, so use the block's initial state
if (updater == null) {
updater = worldState.updater();
} else if (updater instanceof StackedUpdater) {
((StackedUpdater) updater).markTransactionBoundary();
} else {
updater.markTransactionBoundary();
}
updater = updater.updater();
return updater;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult;
import org.hyperledger.besu.ethereum.vm.CachingBlockHashLookup;
import org.hyperledger.besu.ethereum.vm.DebugOperationTracer;
import org.hyperledger.besu.evm.worldstate.StackedUpdater;
import org.hyperledger.besu.evm.worldstate.WorldUpdater;

import java.util.List;
Expand Down Expand Up @@ -58,8 +57,8 @@ private BlockReplay.TransactionAction<TransactionTrace> prepareReplayAction(
// if we have no prior updater, it must be the first TX, so use the block's initial state
if (chainedUpdater == null) {
chainedUpdater = mutableWorldState.updater();
} else if (chainedUpdater instanceof StackedUpdater<?, ?> stackedUpdater) {
stackedUpdater.markTransactionBoundary();
} else {
chainedUpdater.markTransactionBoundary();
}
// create an updater for just this tx
chainedUpdater = chainedUpdater.updater();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.hyperledger.besu.ethereum.vm.DebugOperationTracer;
import org.hyperledger.besu.evm.tracing.OperationTracer;
import org.hyperledger.besu.evm.tracing.StandardJsonTracer;
import org.hyperledger.besu.evm.worldstate.StackedUpdater;
import org.hyperledger.besu.evm.worldstate.WorldUpdater;

import java.io.File;
Expand Down Expand Up @@ -123,7 +122,7 @@ public List<String> traceTransactionToFile(
.map(parent -> calculateExcessBlobGasForParent(protocolSpec, parent))
.orElse(BlobGas.ZERO));
for (int i = 0; i < body.getTransactions().size(); i++) {
((StackedUpdater<?, ?>) stackedUpdater).markTransactionBoundary();
stackedUpdater.markTransactionBoundary();
final Transaction transaction = body.getTransactions().get(i);
if (selectedHash.isEmpty()
|| selectedHash.filter(isEqual(transaction.getHash())).isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.TracingUtils;
import org.hyperledger.besu.ethereum.debug.TraceFrame;
import org.hyperledger.besu.evm.account.Account;
import org.hyperledger.besu.evm.worldstate.UpdateTrackingAccount;
import org.hyperledger.besu.evm.account.MutableAccount;
import org.hyperledger.besu.evm.worldstate.WorldUpdater;

import java.util.Collections;
Expand All @@ -39,7 +39,7 @@ public class StateDiffGenerator {

public Stream<Trace> generateStateDiff(final TransactionTrace transactionTrace) {
final List<TraceFrame> traceFrames = transactionTrace.getTraceFrames();
if (traceFrames.size() < 1) {
if (traceFrames.isEmpty()) {
return Stream.empty();
}

Expand All @@ -60,9 +60,7 @@ public Stream<Trace> generateStateDiff(final TransactionTrace transactionTrace)
// calculate storage diff
final Map<String, DiffNode> storageDiff = new TreeMap<>();
for (final Map.Entry<UInt256, UInt256> entry :
((UpdateTrackingAccount<?>) updatedAccount)
.getUpdatedStorage()
.entrySet()) { // FIXME cast
((MutableAccount) updatedAccount).getUpdatedStorage().entrySet()) { // FIXME cast
final UInt256 newValue = entry.getValue();
if (rootAccount == null) {
if (!UInt256.ZERO.equals(newValue)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.hyperledger.besu.ethereum.trie.MerkleTrie;
import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie;
import org.hyperledger.besu.ethereum.worldstate.Pruner.PruningPhase;
import org.hyperledger.besu.evm.internal.EvmConfiguration;
import org.hyperledger.besu.evm.worldstate.WorldState;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage;
Expand Down Expand Up @@ -59,7 +60,9 @@ public class PrunerIntegrationTest {
private final WorldStateStorage worldStateStorage = new WorldStateKeyValueStorage(stateStorage);
private final WorldStateArchive worldStateArchive =
new DefaultWorldStateArchive(
worldStateStorage, new WorldStatePreimageKeyValueStorage(new InMemoryKeyValueStorage()));
worldStateStorage,
new WorldStatePreimageKeyValueStorage(new InMemoryKeyValueStorage()),
EvmConfiguration.DEFAULT);
private final InMemoryKeyValueStorage markStorage = new InMemoryKeyValueStorage();
private final Block genesisBlock = gen.genesisBlock();
private final MutableBlockchain blockchain = createInMemoryBlockchain(genesisBlock);
Expand Down Expand Up @@ -226,7 +229,7 @@ private Set<Bytes> collectWorldStateNodes(final Hash stateRootHash, final Set<By
private void collectTrieNodes(final MerkleTrie<Bytes32, Bytes> trie, final Set<Bytes> collector) {
final Bytes32 rootHash = trie.getRootHash();
trie.visitAll(
(node) -> {
node -> {
if (node.isReferencedByHash() || node.getHash().equals(rootHash)) {
collector.add(node.getEncodedBytes());
}
Expand Down
Loading