Skip to content

Commit

Permalink
Merge branch 'main' into zkbesu
Browse files Browse the repository at this point in the history
# Conflicts:
#	acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java
  • Loading branch information
fab-10 committed Mar 12, 2024
2 parents 0c41e6a + 8dba298 commit 349fd98
Show file tree
Hide file tree
Showing 137 changed files with 2,746 additions and 1,603 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
- RocksDB database metadata refactoring [#6555](https://github.com/hyperledger/besu/pull/6555)
- Make layered txpool aware of minGasPrice and minPriorityFeePerGas dynamic options [#6611](https://github.com/hyperledger/besu/pull/6611)
- Update commons-compress to 1.26.0 [#6648](https://github.com/hyperledger/besu/pull/6648)
- Update Vert.x to 4.5.4 [#6666](https://github.com/hyperledger/besu/pull/6666)
- Add blob transaction support to `eth_call` [#6661](https://github.com/hyperledger/besu/pull/6661)
- Add blobs to `eth_feeHistory` [#6679](https://github.com/hyperledger/besu/pull/6679)
- Refactor and extend `TransactionPoolValidatorService` [#6636](https://github.com/hyperledger/besu/pull/6636)
- Transaction call object to accept both `input` and `data` field simultaneously if they are set to equal values [#6702](https://github.com/hyperledger/besu/pull/6702)

### Bug fixes
- Make block transaction selection max time aware of PoA transitions [#6676](https://github.com/hyperledger/besu/pull/6676)
- Don't enable the BFT mining coordinator when running sub commands such as `blocks export` [#6675](https://github.com/hyperledger/besu/pull/6675)

### Download Links

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
import org.hyperledger.besu.plugin.services.BesuConfiguration;
import org.hyperledger.besu.plugin.services.BesuEvents;
import org.hyperledger.besu.plugin.services.BlockchainService;
import org.hyperledger.besu.plugin.services.PermissioningService;
import org.hyperledger.besu.plugin.services.PicoCLIOptions;
import org.hyperledger.besu.plugin.services.PrivacyPluginService;
import org.hyperledger.besu.plugin.services.RpcEndpointService;
import org.hyperledger.besu.plugin.services.SecurityModuleService;
import org.hyperledger.besu.plugin.services.StorageService;
Expand All @@ -61,6 +63,7 @@
import org.hyperledger.besu.services.BlockchainServiceImpl;
import org.hyperledger.besu.services.PermissioningServiceImpl;
import org.hyperledger.besu.services.PicoCLIOptionsImpl;
import org.hyperledger.besu.services.PrivacyPluginServiceImpl;
import org.hyperledger.besu.services.RpcEndpointServiceImpl;
import org.hyperledger.besu.services.SecurityModuleServiceImpl;
import org.hyperledger.besu.services.StorageServiceImpl;
Expand Down Expand Up @@ -132,12 +135,16 @@ private BesuPluginContextImpl buildPluginContext(
} else {
pluginsPath = Path.of(pluginDir);
}
besuPluginContext.registerPlugins(pluginsPath);

besuPluginContext.addService(BesuConfiguration.class, commonPluginConfiguration);
besuPluginContext.addService(PermissioningService.class, new PermissioningServiceImpl());
besuPluginContext.addService(PrivacyPluginService.class, new PrivacyPluginServiceImpl());

besuPluginContext.registerPlugins(pluginsPath);
commandLine.parseArgs(node.getConfiguration().getExtraCLIOptions().toArray(new String[0]));

// register built-in plugins
new RocksDBPlugin().register(besuPluginContext);

return besuPluginContext;
}

Expand Down
4 changes: 2 additions & 2 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2166,10 +2166,10 @@ private TransactionPoolConfiguration buildTransactionPoolConfiguration() {

private MiningParameters getMiningParameters() {
if (miningParameters == null) {
miningOptions.setGenesisBlockPeriodSeconds(
getGenesisBlockPeriodSeconds(getActualGenesisConfigOptions()));
miningOptions.setTransactionSelectionService(transactionSelectionServiceImpl);
miningParameters = miningOptions.toDomainObject();
getGenesisBlockPeriodSeconds(getActualGenesisConfigOptions())
.ifPresent(miningParameters::setBlockPeriodSeconds);
initMiningParametersMetrics(miningParameters);
}
return miningParameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.hyperledger.besu.util.number.PositiveNumber;

import java.util.List;
import java.util.OptionalInt;

import org.apache.tuweni.bytes.Bytes;
import org.slf4j.Logger;
Expand Down Expand Up @@ -191,7 +190,6 @@ static class Unstable {
DEFAULT_POS_BLOCK_CREATION_REPETITION_MIN_DURATION;
}

private OptionalInt maybeGenesisBlockPeriodSeconds;
private TransactionSelectionService transactionSelectionService;

private MiningOptions() {}
Expand All @@ -205,16 +203,6 @@ public static MiningOptions create() {
return new MiningOptions();
}

/**
* Set the optional genesis block period per seconds
*
* @param genesisBlockPeriodSeconds if the network is PoA then the block period in seconds
* specified in the genesis file, otherwise empty.
*/
public void setGenesisBlockPeriodSeconds(final OptionalInt genesisBlockPeriodSeconds) {
maybeGenesisBlockPeriodSeconds = genesisBlockPeriodSeconds;
}

/**
* Set the transaction selection service
*
Expand Down Expand Up @@ -312,7 +300,6 @@ public void validate(

static MiningOptions fromConfig(final MiningParameters miningParameters) {
final MiningOptions miningOptions = MiningOptions.create();
miningOptions.setGenesisBlockPeriodSeconds(miningParameters.getGenesisBlockPeriodSeconds());
miningOptions.setTransactionSelectionService(miningParameters.getTransactionSelectionService());
miningOptions.isMiningEnabled = miningParameters.isMiningEnabled();
miningOptions.iStratumMiningEnabled = miningParameters.isStratumMiningEnabled();
Expand Down Expand Up @@ -348,9 +335,6 @@ static MiningOptions fromConfig(final MiningParameters miningParameters) {

@Override
public MiningParameters toDomainObject() {
checkNotNull(
maybeGenesisBlockPeriodSeconds,
"genesisBlockPeriodSeconds must be set before using this object");
checkNotNull(
transactionSelectionService,
"transactionSelectionService must be set before using this object");
Expand All @@ -371,7 +355,6 @@ public MiningParameters toDomainObject() {
}

return ImmutableMiningParameters.builder()
.genesisBlockPeriodSeconds(maybeGenesisBlockPeriodSeconds)
.transactionSelectionService(transactionSelectionService)
.mutableInitValues(updatableInitValuesBuilder.build())
.isStratumMiningEnabled(iStratumMiningEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive;
import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage;
import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;

import java.io.File;
Expand Down Expand Up @@ -81,15 +81,19 @@ public void run() {

final BesuController besuController = createBesuController();
final MutableBlockchain blockchain = besuController.getProtocolContext().getBlockchain();
final WorldStateStorage worldStateStorage =
final ForestWorldStateKeyValueStorage forestWorldStateKeyValueStorage =
((ForestWorldStateArchive) besuController.getProtocolContext().getWorldStateArchive())
.getWorldStateStorage();
final EthScheduler scheduler = new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem());
try {
final long targetBlock = Math.min(blockchain.getChainHeadBlockNumber(), this.block);
final StateBackupService backup =
new StateBackupService(
BesuInfo.version(), blockchain, backupDir.toPath(), scheduler, worldStateStorage);
BesuInfo.version(),
blockchain,
backupDir.toPath(),
scheduler,
forestWorldStateKeyValueStorage);
final BackupStatus status = backup.requestBackup(targetBlock, compress, Optional.empty());

final double refValue = Math.pow(2, 256) / 100.0d;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
import org.hyperledger.besu.ethereum.trie.PersistVisitor;
import org.hyperledger.besu.ethereum.trie.RestoreVisitor;
import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive;
import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue;
import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage;
import org.hyperledger.besu.util.io.RollingFileReader;

import java.io.IOException;
Expand Down Expand Up @@ -83,7 +83,7 @@ public class RestoreState implements Runnable {
private long trieNodeCount;
private boolean compressed;
private BesuController besuController;
private WorldStateStorage.Updater updater;
private ForestWorldStateKeyValueStorage.Updater updater;

private Path accountFileName(final int fileNumber, final boolean compressed) {
return StateBackupService.accountFileName(backupDir, targetBlock, fileNumber, compressed);
Expand Down Expand Up @@ -249,10 +249,10 @@ private void newWorldStateUpdater() {
if (updater != null) {
updater.commit();
}
final WorldStateStorage worldStateStorage =
final ForestWorldStateKeyValueStorage worldStateKeyValueStorage =
((ForestWorldStateArchive) besuController.getProtocolContext().getWorldStateArchive())
.getWorldStateStorage();
updater = worldStateStorage.updater();
updater = worldStateKeyValueStorage.updater();
}

private void maybeCommitUpdater() {
Expand All @@ -263,20 +263,20 @@ private void maybeCommitUpdater() {

private void updateCode(final Bytes code) {
maybeCommitUpdater();
updater.putCode(null, code);
updater.putCode(code);
}

private void updateAccountState(final Bytes32 key, final Bytes value) {
maybeCommitUpdater();
// restore by path not supported
updater.putAccountStateTrieNode(null, key, value);
updater.putAccountStateTrieNode(key, value);
trieNodeCount++;
}

private void updateAccountStorage(final Bytes32 key, final Bytes value) {
maybeCommitUpdater();
// restore by path not supported
updater.putAccountStorageTrieNode(null, null, key, value);
updater.putAccountStorageTrieNode(key, value);
trieNodeCount++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@
import org.hyperledger.besu.ethereum.trie.forest.pruner.PrunerConfiguration;
import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.ethereum.worldstate.WorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.worldstate.WorldStatePreimageStorage;
import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage;
import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator;
import org.hyperledger.besu.evm.internal.EvmConfiguration;
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
import org.hyperledger.besu.plugin.services.MetricsSystem;
Expand Down Expand Up @@ -559,8 +560,8 @@ public BesuController build() {

final VariablesStorage variablesStorage = storageProvider.createVariablesStorage();

final WorldStateStorage worldStateStorage =
storageProvider.createWorldStateStorage(dataStorageConfiguration);
final WorldStateStorageCoordinator worldStateStorageCoordinator =
storageProvider.createWorldStateStorageCoordinator(dataStorageConfiguration);

final BlockchainStorage blockchainStorage =
storageProvider.createBlockchainStorage(protocolSchedule, variablesStorage);
Expand All @@ -580,7 +581,7 @@ public BesuController build() {
.orElseGet(() -> new CachedMerkleTrieLoader(metricsSystem));

final WorldStateArchive worldStateArchive =
createWorldStateArchive(worldStateStorage, blockchain, cachedMerkleTrieLoader);
createWorldStateArchive(worldStateStorageCoordinator, blockchain, cachedMerkleTrieLoader);

if (blockchain.getChainHeadBlockNumber() < 1) {
genesisState.writeStateTo(worldStateArchive.getMutable());
Expand Down Expand Up @@ -707,7 +708,7 @@ public BesuController build() {
final Synchronizer synchronizer =
createSynchronizer(
protocolSchedule,
worldStateStorage,
worldStateStorageCoordinator,
protocolContext,
maybePruner,
ethContext,
Expand Down Expand Up @@ -739,8 +740,10 @@ public BesuController build() {
&& DataStorageFormat.BONSAI.equals(dataStorageConfiguration.getDataStorageFormat())) {
final TrieLogManager trieLogManager =
((BonsaiWorldStateProvider) worldStateArchive).getTrieLogManager();
final BonsaiWorldStateKeyValueStorage worldStateKeyValueStorage =
worldStateStorageCoordinator.getStrategy(BonsaiWorldStateKeyValueStorage.class);
final TrieLogPruner trieLogPruner =
createTrieLogPruner(worldStateStorage, blockchain, scheduler);
createTrieLogPruner(worldStateKeyValueStorage, blockchain, scheduler);
trieLogManager.subscribe(trieLogPruner);
}

Expand Down Expand Up @@ -773,7 +776,7 @@ public BesuController build() {
}

private TrieLogPruner createTrieLogPruner(
final WorldStateStorage worldStateStorage,
final WorldStateKeyValueStorage worldStateStorage,
final Blockchain blockchain,
final EthScheduler scheduler) {
final GenesisConfigOptions genesisConfigOptions = configOptionsSupplier.get();
Expand All @@ -796,7 +799,7 @@ private TrieLogPruner createTrieLogPruner(
* Create synchronizer synchronizer.
*
* @param protocolSchedule the protocol schedule
* @param worldStateStorage the world state storage
* @param worldStateStorageCoordinator the world state storage
* @param protocolContext the protocol context
* @param maybePruner the maybe pruner
* @param ethContext the eth context
Expand All @@ -807,7 +810,7 @@ private TrieLogPruner createTrieLogPruner(
*/
protected Synchronizer createSynchronizer(
final ProtocolSchedule protocolSchedule,
final WorldStateStorage worldStateStorage,
final WorldStateStorageCoordinator worldStateStorageCoordinator,
final ProtocolContext protocolContext,
final Optional<Pruner> maybePruner,
final EthContext ethContext,
Expand All @@ -819,7 +822,7 @@ protected Synchronizer createSynchronizer(
syncConfig,
protocolSchedule,
protocolContext,
worldStateStorage,
worldStateStorageCoordinator,
ethProtocolManager.getBlockBroadcaster(),
maybePruner,
ethContext,
Expand Down Expand Up @@ -1042,21 +1045,26 @@ private Optional<SnapProtocolManager> createSnapProtocolManager(
}

WorldStateArchive createWorldStateArchive(
final WorldStateStorage worldStateStorage,
final WorldStateStorageCoordinator worldStateStorageCoordinator,
final Blockchain blockchain,
final CachedMerkleTrieLoader cachedMerkleTrieLoader) {
return switch (dataStorageConfiguration.getDataStorageFormat()) {
case BONSAI -> new BonsaiWorldStateProvider(
(BonsaiWorldStateKeyValueStorage) worldStateStorage,
blockchain,
Optional.of(dataStorageConfiguration.getBonsaiMaxLayersToLoad()),
cachedMerkleTrieLoader,
besuComponent.map(BesuComponent::getBesuPluginContext).orElse(null),
evmConfiguration);
case BONSAI -> {
final BonsaiWorldStateKeyValueStorage worldStateKeyValueStorage =
worldStateStorageCoordinator.getStrategy(BonsaiWorldStateKeyValueStorage.class);
yield new BonsaiWorldStateProvider(
worldStateKeyValueStorage,
blockchain,
Optional.of(dataStorageConfiguration.getBonsaiMaxLayersToLoad()),
cachedMerkleTrieLoader,
besuComponent.map(BesuComponent::getBesuPluginContext).orElse(null),
evmConfiguration);
}
case FOREST -> {
final WorldStatePreimageStorage preimageStorage =
storageProvider.createWorldStatePreimageStorage();
yield new ForestWorldStateArchive(worldStateStorage, preimageStorage, evmConfiguration);
yield new ForestWorldStateArchive(
worldStateStorageCoordinator, preimageStorage, evmConfiguration);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ protected MiningCoordinator createMiningCoordinator(
miningExecutor,
syncState,
new CliqueMiningTracker(localAddress, protocolContext));

// Update the next block period in seconds according to the transition schedule
protocolContext
.getBlockchain()
.observeBlockAdded(
o ->
miningParameters.setBlockPeriodSeconds(
forksSchedule
.getFork(o.getBlock().getHeader().getNumber() + 1)
.getValue()
.getBlockPeriodSeconds()));

miningCoordinator.addMinedBlockObserver(ethProtocolManager);

// Clique mining is implicitly enabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,19 @@ protected MiningCoordinator createMiningCoordinator(
blockchain,
bftEventQueue);

// Update the next block period in seconds according to the transition schedule
protocolContext
.getBlockchain()
.observeBlockAdded(
o ->
miningParameters.setBlockPeriodSeconds(
forksSchedule
.getFork(o.getBlock().getHeader().getNumber() + 1)
.getValue()
.getBlockPeriodSeconds()));

if (syncState.isInitialSyncPhaseDone()) {
LOG.info("Starting IBFT mining coordinator");
ibftMiningCoordinator.enable();
ibftMiningCoordinator.start();
} else {
LOG.info("IBFT mining coordinator not starting while initial sync in progress");
}

syncState.subscribeCompletionReached(
Expand Down
Loading

0 comments on commit 349fd98

Please sign in to comment.