Skip to content

Commit

Permalink
Use BONSAI for the execution engine BesuNode in ATs
Browse files Browse the repository at this point in the history
Affects tests extending AbstractJsonRpcTest
Signed-off-by: Simon Dudley <[email protected]>
  • Loading branch information
siladu committed Oct 17, 2023
1 parent 6d100f3 commit b8a164d
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration;
import org.hyperledger.besu.ethereum.p2p.rlpx.connections.netty.TLSConfiguration;
import org.hyperledger.besu.ethereum.permissioning.PermissioningConfiguration;
import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.pki.config.PkiKeyStoreConfiguration;
import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition;
Expand Down Expand Up @@ -128,6 +129,7 @@ public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable
private Optional<PkiKeyStoreConfiguration> pkiKeyStoreConfiguration = Optional.empty();
private final boolean isStrictTxReplayProtectionEnabled;
private final Map<String, String> environment;
private final DataStorageFormat dataStorageFormat;

public BesuNode(
final String name,
Expand Down Expand Up @@ -161,7 +163,8 @@ public BesuNode(
final Optional<KeyPair> keyPair,
final Optional<PkiKeyStoreConfiguration> pkiKeyStoreConfiguration,
final boolean isStrictTxReplayProtectionEnabled,
final Map<String, String> environment)
final Map<String, String> environment,
final DataStorageFormat dataStorageFormat)
throws IOException {
this.homeDirectory = dataPath.orElseGet(BesuNode::createTmpDataDirectory);
this.isStrictTxReplayProtectionEnabled = isStrictTxReplayProtectionEnabled;
Expand Down Expand Up @@ -219,6 +222,7 @@ public BesuNode(
privacyParameters.ifPresent(this::setPrivacyParameters);
this.pkiKeyStoreConfiguration = pkiKeyStoreConfiguration;
this.environment = environment;
this.dataStorageFormat = dataStorageFormat;
LOG.info("Created BesuNode {}", this);
}

Expand Down Expand Up @@ -751,6 +755,7 @@ public String toString() {
.add("p2pEnabled", p2pEnabled)
.add("discoveryEnabled", discoveryEnabled)
.add("privacyEnabled", privacyParameters.isEnabled())
.add("dataStorageFormat", dataStorageFormat)
.toString();
}

Expand Down Expand Up @@ -806,4 +811,8 @@ public void setExitCode(final int exitValue) {
public Map<String, String> getEnvironment() {
return environment;
}

public DataStorageFormat getDataStorageFormat() {
return dataStorageFormat;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.ipc.JsonRpcIpcConfiguration;
import org.hyperledger.besu.ethereum.p2p.rlpx.connections.netty.TLSConfiguration;
import org.hyperledger.besu.ethereum.permissioning.PermissioningConfiguration;
import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.plugin.services.metrics.MetricCategory;
import org.hyperledger.besu.tests.acceptance.dsl.StaticNodesUtils;
Expand Down Expand Up @@ -78,6 +79,11 @@ public void startNode(final BesuNode node) {
params.add("--data-path");
params.add(dataDir.toAbsolutePath().toString());

if (DataStorageFormat.BONSAI.equals(node.getDataStorageFormat())) {
params.add("--data-storage-format");
params.add("BONSAI");
}

if (node.isDevMode()) {
params.add("--network");
params.add("DEV");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
import org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl;
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProvider;
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProviderBuilder;
import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration;
import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat;
import org.hyperledger.besu.ethereum.worldstate.ImmutableDataStorageConfiguration;
import org.hyperledger.besu.evm.internal.EvmConfiguration;
import org.hyperledger.besu.metrics.MetricsSystemFactory;
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
Expand Down Expand Up @@ -143,7 +146,8 @@ public void startNode(final BesuNode node) {
final SecurityModuleServiceImpl securityModuleService = new SecurityModuleServiceImpl();
final Path dataDir = node.homeDirectory();
final BesuConfiguration commonPluginConfiguration =
new BesuConfigurationImpl(dataDir, dataDir.resolve(DATABASE_PATH));
new BesuConfigurationImpl(
dataDir, dataDir.resolve(DATABASE_PATH), DataStorageFormat.BONSAI.getDatabaseVersion());
final BesuPluginContextImpl besuPluginContext =
besuPluginContextMap.computeIfAbsent(
node,
Expand Down Expand Up @@ -190,6 +194,15 @@ public void startNode(final BesuNode node) {

final PluginTransactionValidatorFactory pluginTransactionValidatorFactory =
getPluginTransactionValidatorFactory(besuPluginContext);

final DataStorageConfiguration dataStorageConfiguration =
DataStorageFormat.BONSAI.equals(node.getDataStorageFormat())
? ImmutableDataStorageConfiguration.builder()
.dataStorageFormat(DataStorageFormat.BONSAI)
.bonsaiMaxLayersToLoad(DataStorageConfiguration.DEFAULT_BONSAI_MAX_LAYERS_TO_LOAD)
.build()
: DataStorageConfiguration.DEFAULT_CONFIG;

builder
.synchronizerConfiguration(new SynchronizerConfiguration.Builder().build())
.dataDirectory(node.homeDirectory())
Expand All @@ -207,6 +220,7 @@ public void startNode(final BesuNode node) {
node.getPkiKeyStoreConfiguration()
.map(pkiConfig -> new PkiBlockCreationConfigurationProvider().load(pkiConfig)))
.evmConfiguration(EvmConfiguration.DEFAULT)
.dataStorageConfiguration(dataStorageConfiguration)
.maxPeers(maxPeers)
.lowerBoundPeers(maxPeers)
.maxRemotelyInitiatedPeers(15)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration;
import org.hyperledger.besu.ethereum.p2p.rlpx.connections.netty.TLSConfiguration;
import org.hyperledger.besu.ethereum.permissioning.PermissioningConfiguration;
import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.pki.config.PkiKeyStoreConfiguration;
import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.genesis.GenesisConfigurationProvider;
Expand Down Expand Up @@ -67,6 +68,7 @@ public class BesuNodeConfiguration {
private final Optional<PkiKeyStoreConfiguration> pkiKeyStoreConfiguration;
private final boolean strictTxReplayProtectionEnabled;
private final Map<String, String> environment;
private final DataStorageFormat dataStorageFormat;

BesuNodeConfiguration(
final String name,
Expand Down Expand Up @@ -100,7 +102,8 @@ public class BesuNodeConfiguration {
final Optional<KeyPair> keyPair,
final Optional<PkiKeyStoreConfiguration> pkiKeyStoreConfiguration,
final boolean strictTxReplayProtectionEnabled,
final Map<String, String> environment) {
final Map<String, String> environment,
final DataStorageFormat dataStorageFormat) {
this.name = name;
this.miningParameters = miningParameters;
this.jsonRpcConfiguration = jsonRpcConfiguration;
Expand Down Expand Up @@ -133,6 +136,7 @@ public class BesuNodeConfiguration {
this.pkiKeyStoreConfiguration = pkiKeyStoreConfiguration;
this.strictTxReplayProtectionEnabled = strictTxReplayProtectionEnabled;
this.environment = environment;
this.dataStorageFormat = dataStorageFormat;
}

public String getName() {
Expand Down Expand Up @@ -262,4 +266,8 @@ public boolean isStrictTxReplayProtectionEnabled() {
public Map<String, String> getEnvironment() {
return environment;
}

public DataStorageFormat getDataStorageFormat() {
return dataStorageFormat;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration;
import org.hyperledger.besu.ethereum.p2p.rlpx.connections.netty.TLSConfiguration;
import org.hyperledger.besu.ethereum.permissioning.PermissioningConfiguration;
import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.pki.config.PkiKeyStoreConfiguration;
import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.genesis.GenesisConfigurationProvider;
Expand Down Expand Up @@ -90,6 +91,7 @@ public class BesuNodeConfigurationBuilder {
private Optional<PkiKeyStoreConfiguration> pkiKeyStoreConfiguration = Optional.empty();
private Boolean strictTxReplayProtectionEnabled = false;
private Map<String, String> environment = new HashMap<>();
private DataStorageFormat dataStorageFormat = DataStorageFormat.FOREST;

public BesuNodeConfigurationBuilder() {
// Check connections more frequently during acceptance tests to cut down on
Expand Down Expand Up @@ -494,6 +496,11 @@ public BesuNodeConfigurationBuilder environment(final Map<String, String> enviro
return this;
}

public BesuNodeConfigurationBuilder dataStorageFormat(final DataStorageFormat dataStorageFormat) {
this.dataStorageFormat = dataStorageFormat;
return this;
}

public BesuNodeConfiguration build() {
return new BesuNodeConfiguration(
name,
Expand Down Expand Up @@ -527,6 +534,7 @@ public BesuNodeConfiguration build() {
keyPair,
pkiKeyStoreConfiguration,
strictTxReplayProtectionEnabled,
environment);
environment,
dataStorageFormat);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.permissioning.LocalPermissioningConfiguration;
import org.hyperledger.besu.ethereum.permissioning.PermissioningConfiguration;
import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat;
import org.hyperledger.besu.pki.keystore.KeyStoreWrapper;
import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode;
import org.hyperledger.besu.tests.acceptance.dsl.node.Node;
Expand Down Expand Up @@ -89,7 +90,8 @@ public BesuNode create(final BesuNodeConfiguration config) throws IOException {
config.getKeyPair(),
config.getPkiKeyStoreConfiguration(),
config.isStrictTxReplayProtectionEnabled(),
config.getEnvironment());
config.getEnvironment(),
config.getDataStorageFormat());
}

public BesuNode createMinerNode(
Expand Down Expand Up @@ -549,6 +551,7 @@ public BesuNode createExecutionEngineGenesisNode(final String name, final String
.jsonRpcTxPool()
.engineRpcEnabled(true)
.jsonRpcDebug()
.dataStorageFormat(DataStorageFormat.BONSAI)
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ public PrivacyNode(
Optional.empty(),
Optional.empty(),
besuConfig.isStrictTxReplayProtectionEnabled(),
besuConfig.getEnvironment());
besuConfig.getEnvironment(),
besuConfig.getDataStorageFormat());
}

public void testEnclaveConnection(final List<PrivacyNode> otherNodes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.services;

import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat;
import org.hyperledger.besu.plugin.services.BesuConfiguration;

import java.nio.file.Path;
Expand All @@ -23,6 +24,7 @@ public class BesuConfigurationImpl implements BesuConfiguration {

private final Path storagePath;
private final Path dataPath;
private final int databaseVersion;

/**
* BesuConfigurationImpl Constructor.
Expand All @@ -33,6 +35,14 @@ public class BesuConfigurationImpl implements BesuConfiguration {
public BesuConfigurationImpl(final Path dataPath, final Path storagePath) {
this.dataPath = dataPath;
this.storagePath = storagePath;
this.databaseVersion = DataStorageFormat.FOREST.getDatabaseVersion();
}

public BesuConfigurationImpl(
final Path dataPath, final Path storagePath, final int databaseVersion) {
this.dataPath = dataPath;
this.storagePath = storagePath;
this.databaseVersion = databaseVersion;
}

@Override
Expand All @@ -44,4 +54,9 @@ public Path getStoragePath() {
public Path getDataPath() {
return dataPath;
}

@Override
public int getDatabaseVersion() {
return databaseVersion;
}
}
2 changes: 1 addition & 1 deletion plugin-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Calculated : ${currentHash}
tasks.register('checkAPIChanges', FileStateChecker) {
description = "Checks that the API for the Plugin-API project does not change without deliberate thought"
files = sourceSets.main.allJava.files
knownHash = 'j6NRklFHlG35Pq/t6t/oJBrT8DbYOyruGq3cJNh4ENw='
knownHash = '+qJXjI2n0ZVY1jwmQ7bY+7yfYJvzj59g0BCcV22DbSI='
}
check.dependsOn('checkAPIChanges')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
*/
package org.hyperledger.besu.plugin.services;

import org.hyperledger.besu.plugin.Unstable;

import java.nio.file.Path;

/** Generally useful configuration provided by Besu. */
Expand All @@ -40,8 +38,5 @@ public interface BesuConfiguration extends BesuService {
*
* @return Database version.
*/
@Unstable
default int getDatabaseVersion() {
return 1;
}
int getDatabaseVersion();
}

0 comments on commit b8a164d

Please sign in to comment.