diff --git a/CHANGELOG.md b/CHANGELOG.md index a74da30fd6..01d329274d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ - Adds `storage rocksdb x-stats` subcommand [#6540](https://github.com/hyperledger/besu/pull/6540) - New `eth_blobBaseFee`JSON-RPC method [#6581](https://github.com/hyperledger/besu/pull/6581) - Upgrade reference tests to version 13.1 [#6574](https://github.com/hyperledger/besu/pull/6574) +- Extend `BesuConfiguration` service [#6584](https://github.com/hyperledger/besu/pull/6584) ### Bug fixes - Fix the way an advertised host configured with `--p2p-host` is treated when communicating with the originator of a PING packet [#6225](https://github.com/hyperledger/besu/pull/6225) diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java index ba00ac8f22..ec9d7b1173 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java @@ -33,6 +33,7 @@ import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfigurati 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.DataStorageConfiguration; import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; import org.hyperledger.besu.pki.config.PkiKeyStoreConfiguration; import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; @@ -109,6 +110,7 @@ public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable private final WebSocketConfiguration webSocketConfiguration; private final JsonRpcIpcConfiguration jsonRpcIpcConfiguration; private final MetricsConfiguration metricsConfiguration; + private final DataStorageConfiguration dataStorageConfiguration; private Optional permissioningConfiguration; private final ApiConfiguration apiConfiguration; private final GenesisConfigurationProvider genesisConfigProvider; @@ -145,6 +147,7 @@ public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable final MetricsConfiguration metricsConfiguration, final Optional permissioningConfiguration, final ApiConfiguration apiConfiguration, + final DataStorageConfiguration dataStorageConfiguration, final Optional keyfilePath, final boolean devMode, final NetworkName network, @@ -195,6 +198,7 @@ public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable this.metricsConfiguration = metricsConfiguration; this.permissioningConfiguration = permissioningConfiguration; this.apiConfiguration = apiConfiguration; + this.dataStorageConfiguration = dataStorageConfiguration; this.genesisConfigProvider = genesisConfigProvider; this.devMode = devMode; this.network = network; @@ -690,6 +694,10 @@ public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable this.privacyParameters = privacyParameters; } + public DataStorageConfiguration getDataStorageConfiguration() { + return dataStorageConfiguration; + } + public boolean isDevMode() { return devMode; } diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java index 1cfacc15c4..bd94a4a345 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java @@ -145,8 +145,12 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner { final StorageServiceImpl storageService = new StorageServiceImpl(); final SecurityModuleServiceImpl securityModuleService = new SecurityModuleServiceImpl(); final Path dataDir = node.homeDirectory(); - final BesuConfiguration commonPluginConfiguration = - new BesuConfigurationImpl(dataDir, dataDir.resolve(DATABASE_PATH)); + final BesuConfigurationImpl commonPluginConfiguration = new BesuConfigurationImpl(); + commonPluginConfiguration.init( + dataDir, + dataDir.resolve(DATABASE_PATH), + node.getDataStorageConfiguration(), + node.getMiningParameters()); final BesuPluginContextImpl besuPluginContext = besuPluginContextMap.computeIfAbsent( node, diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfiguration.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfiguration.java index 0c0d66be6a..d1e398f721 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfiguration.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfiguration.java @@ -26,6 +26,7 @@ import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfigurati 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.DataStorageConfiguration; 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; @@ -48,6 +49,7 @@ public class BesuNodeConfiguration { private final MetricsConfiguration metricsConfiguration; private final Optional permissioningConfiguration; private final ApiConfiguration apiConfiguration; + private final DataStorageConfiguration dataStorageConfiguration; private final Optional keyFilePath; private final boolean devMode; private final GenesisConfigurationProvider genesisConfigProvider; @@ -84,6 +86,7 @@ public class BesuNodeConfiguration { final MetricsConfiguration metricsConfiguration, final Optional permissioningConfiguration, final ApiConfiguration apiConfiguration, + final DataStorageConfiguration dataStorageConfiguration, final Optional keyFilePath, final boolean devMode, final NetworkName network, @@ -117,6 +120,7 @@ public class BesuNodeConfiguration { this.metricsConfiguration = metricsConfiguration; this.permissioningConfiguration = permissioningConfiguration; this.apiConfiguration = apiConfiguration; + this.dataStorageConfiguration = dataStorageConfiguration; this.keyFilePath = keyFilePath; this.dataPath = dataPath; this.devMode = devMode; @@ -183,6 +187,10 @@ public class BesuNodeConfiguration { return apiConfiguration; } + public DataStorageConfiguration getDataStorageConfiguration() { + return dataStorageConfiguration; + } + public Optional getKeyFilePath() { return keyFilePath; } diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfigurationBuilder.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfigurationBuilder.java index c20e7ec6d1..1a9a16f36f 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfigurationBuilder.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfigurationBuilder.java @@ -39,6 +39,7 @@ import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfigurati 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.DataStorageConfiguration; 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; @@ -73,6 +74,8 @@ public class BesuNodeConfigurationBuilder { private MetricsConfiguration metricsConfiguration = MetricsConfiguration.builder().build(); private Optional permissioningConfiguration = Optional.empty(); private ApiConfiguration apiConfiguration = ImmutableApiConfiguration.builder().build(); + private DataStorageConfiguration dataStorageConfiguration = + DataStorageConfiguration.DEFAULT_FOREST_CONFIG; private String keyFilePath = null; private boolean devMode = true; private GenesisConfigurationProvider genesisConfigProvider = ignore -> Optional.empty(); @@ -506,6 +509,12 @@ public class BesuNodeConfigurationBuilder { return this; } + public BesuNodeConfigurationBuilder dataStorageConfiguration( + final DataStorageConfiguration dataStorageConfiguration) { + this.dataStorageConfiguration = dataStorageConfiguration; + return this; + } + public BesuNodeConfiguration build() { return new BesuNodeConfiguration( name, @@ -519,6 +528,7 @@ public class BesuNodeConfigurationBuilder { metricsConfiguration, permissioningConfiguration, apiConfiguration, + dataStorageConfiguration, Optional.ofNullable(keyFilePath), devMode, network, diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeFactory.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeFactory.java index ed26587812..65d257fbfb 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeFactory.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeFactory.java @@ -72,6 +72,7 @@ public class BesuNodeFactory { config.getMetricsConfiguration(), config.getPermissioningConfiguration(), config.getApiConfiguration(), + config.getDataStorageConfiguration(), config.getKeyFilePath(), config.isDevMode(), config.getNetwork(), diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/privacy/PrivacyNode.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/privacy/PrivacyNode.java index 4ec4396d6b..1c0df5ace6 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/privacy/PrivacyNode.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/privacy/PrivacyNode.java @@ -76,6 +76,7 @@ public class PrivacyNode implements AutoCloseable { private final boolean isFlexiblePrivacyEnabled; private final boolean isMultitenancyEnabled; private final boolean isPrivacyPluginEnabled; + private final BesuNodeConfiguration besuConfig; public PrivacyNode( final PrivacyNodeConfiguration privacyConfiguration, @@ -89,7 +90,7 @@ public class PrivacyNode implements AutoCloseable { selectEnclave(enclaveType, enclaveDir, config, privacyConfiguration, containerNetwork); this.vertx = vertx; - final BesuNodeConfiguration besuConfig = config; + this.besuConfig = config; isFlexiblePrivacyEnabled = privacyConfiguration.isFlexiblePrivacyGroupEnabled(); isMultitenancyEnabled = privacyConfiguration.isMultitenancyEnabled(); @@ -108,6 +109,7 @@ public class PrivacyNode implements AutoCloseable { besuConfig.getMetricsConfiguration(), besuConfig.getPermissioningConfiguration(), besuConfig.getApiConfiguration(), + besuConfig.getDataStorageConfiguration(), besuConfig.getKeyFilePath(), besuConfig.isDevMode(), besuConfig.getNetwork(), @@ -272,6 +274,8 @@ public class PrivacyNode implements AutoCloseable { private PrivacyStorageProvider createKeyValueStorageProvider( final Path dataLocation, final Path dbLocation) { + final var besuConfiguration = new BesuConfigurationImpl(); + besuConfiguration.init(dataLocation, dbLocation, null, besuConfig.getMiningParameters()); return new PrivacyKeyValueStorageProviderBuilder() .withStorageFactory( new RocksDBKeyValuePrivacyStorageFactory( @@ -284,7 +288,7 @@ public class PrivacyNode implements AutoCloseable { DEFAULT_IS_HIGH_SPEC), Arrays.asList(KeyValueSegmentIdentifier.values()), RocksDBMetricsFactory.PRIVATE_ROCKS_DB_METRICS))) - .withCommonConfiguration(new BesuConfigurationImpl(dataLocation, dbLocation)) + .withCommonConfiguration(besuConfiguration) .withMetricsSystem(new NoOpMetricsSystem()) .build(); } diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index 656abc5b03..73c8c6ae19 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -138,6 +138,7 @@ import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProvider; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProviderBuilder; import org.hyperledger.besu.ethereum.trie.forest.pruner.PrunerConfiguration; +import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat; import org.hyperledger.besu.evm.precompile.AbstractAltBnPrecompiledContract; import org.hyperledger.besu.evm.precompile.BigIntegerModularExponentiationPrecompiledContract; @@ -173,6 +174,7 @@ import org.hyperledger.besu.plugin.services.storage.PrivacyKeyValueStorageFactor import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBPlugin; import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory; import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidatorFactory; +import org.hyperledger.besu.services.BesuConfigurationImpl; import org.hyperledger.besu.services.BesuEventsImpl; import org.hyperledger.besu.services.BesuPluginContextImpl; import org.hyperledger.besu.services.BlockchainServiceImpl; @@ -893,9 +895,10 @@ public class BesuCommand implements DefaultCommandValues, Runnable { private MetricsConfiguration metricsConfiguration; private Optional permissioningConfiguration; private Optional p2pTLSConfiguration; + private DataStorageConfiguration dataStorageConfiguration; private Collection staticNodes; private BesuController besuController; - private BesuConfiguration pluginCommonConfiguration; + private BesuConfigurationImpl pluginCommonConfiguration; private MiningParameters miningParameters; private BesuComponent besuComponent; @@ -1000,7 +1003,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable { this.securityModuleService = securityModuleService; this.permissioningService = permissioningService; this.privacyPluginService = privacyPluginService; - pluginCommonConfiguration = new BesuCommandConfigurationService(); + this.pluginCommonConfiguration = new BesuConfigurationImpl(); besuPluginContext.addService(BesuConfiguration.class, pluginCommonConfiguration); this.pkiBlockCreationConfigProvider = pkiBlockCreationConfigProvider; this.rpcEndpointServiceImpl = rpcEndpointServiceImpl; @@ -1076,7 +1079,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable { validateOptions(); configure(); configureNativeLibs(); - besuController = initController(); + besuController = buildController(); besuPluginContext.beforeExternalServices(); @@ -1098,7 +1101,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable { } @VisibleForTesting - void setBesuConfiguration(final BesuConfiguration pluginCommonConfiguration) { + void setBesuConfiguration(final BesuConfigurationImpl pluginCommonConfiguration) { this.pluginCommonConfiguration = pluginCommonConfiguration; } @@ -1674,6 +1677,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable { unstableIpcOptions.getIpcPath(), unstableIpcOptions.getRpcIpcApis()); apiConfiguration = apiConfigurationOptions.apiConfiguration(getMiningParameters()); + dataStorageConfiguration = getDataStorageConfiguration(); // hostsWhitelist is a hidden option. If it is specified, add the list to hostAllowlist if (!hostsWhitelist.isEmpty()) { // if allowlist == default values, remove the default values @@ -1736,10 +1740,6 @@ public class BesuCommand implements DefaultCommandValues, Runnable { } } - private BesuController initController() { - return buildController(); - } - /** * Builds BesuController * @@ -1761,6 +1761,11 @@ public class BesuCommand implements DefaultCommandValues, Runnable { * @return instance of BesuControllerBuilder */ public BesuControllerBuilder getControllerBuilder() { + pluginCommonConfiguration.init( + dataDir(), + dataDir().resolve(DATABASE_PATH), + getDataStorageConfiguration(), + getMiningParameters()); final KeyValueStorageProvider storageProvider = keyValueStorageProvider(keyValueStorageName); return controllerBuilderFactory .fromEthNetworkConfig( @@ -1771,6 +1776,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable { .transactionSelectorFactory(getTransactionSelectorFactory()) .pluginTransactionValidatorFactory(getPluginTransactionValidatorFactory()) .dataDirectory(dataDir()) + .dataStorageConfiguration(getDataStorageConfiguration()) .miningParameters(getMiningParameters()) .transactionPoolConfiguration(buildTransactionPoolConfiguration()) .nodeKey(new NodeKey(securityModule())) @@ -1792,7 +1798,6 @@ public class BesuCommand implements DefaultCommandValues, Runnable { .requiredBlocks(requiredBlocks) .reorgLoggingThreshold(reorgLoggingThreshold) .evmConfiguration(unstableEvmOptions.toDomainObject()) - .dataStorageConfiguration(dataStorageOptions.toDomainObject()) .maxPeers(p2PDiscoveryOptionGroup.maxPeers) .maxRemotelyInitiatedPeers(maxRemoteInitiatedPeers) .randomPeerPriority(p2PDiscoveryOptionGroup.randomPeerPriority) @@ -2127,6 +2132,13 @@ public class BesuCommand implements DefaultCommandValues, Runnable { return miningParameters; } + private DataStorageConfiguration getDataStorageConfiguration() { + if (dataStorageConfiguration == null) { + dataStorageConfiguration = dataStorageOptions.toDomainObject(); + } + return dataStorageConfiguration; + } + private OptionalInt getGenesisBlockPeriodSeconds( final GenesisConfigOptions genesisConfigOptions) { if (genesisConfigOptions.isClique()) { @@ -2538,24 +2550,6 @@ public class BesuCommand implements DefaultCommandValues, Runnable { return loggingLevelOption.getLogLevel(); } - private class BesuCommandConfigurationService implements BesuConfiguration { - - @Override - public Path getStoragePath() { - return dataDir().resolve(DATABASE_PATH); - } - - @Override - public Path getDataPath() { - return dataDir(); - } - - @Override - public int getDatabaseVersion() { - return dataStorageOptions.toDomainObject().getDataStorageFormat().getDatabaseVersion(); - } - } - private void instantiateSignatureAlgorithmFactory() { if (SignatureAlgorithmFactory.isInstanceSet()) { return; @@ -2714,12 +2708,11 @@ public class BesuCommand implements DefaultCommandValues, Runnable { builder.setHighSpecEnabled(); } - if (dataStorageOptions.toDomainObject().getUnstable().getBonsaiLimitTrieLogsEnabled()) { + if (getDataStorageConfiguration().getUnstable().getBonsaiLimitTrieLogsEnabled()) { builder.setLimitTrieLogsEnabled(); - builder.setTrieLogRetentionLimit( - dataStorageOptions.toDomainObject().getBonsaiMaxLayersToLoad()); + builder.setTrieLogRetentionLimit(getDataStorageConfiguration().getBonsaiMaxLayersToLoad()); builder.setTrieLogsPruningWindowSize( - dataStorageOptions.toDomainObject().getUnstable().getBonsaiTrieLogPruningWindowSize()); + getDataStorageConfiguration().getUnstable().getBonsaiTrieLogPruningWindowSize()); } builder.setTxPoolImplementation(buildTransactionPoolConfiguration().getTxPoolImplementation()); diff --git a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java index 7110a8d88a..1213bd76ba 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java @@ -576,6 +576,7 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides checkNotNull(gasLimitCalculator, "Missing gas limit calculator"); checkNotNull(evmConfiguration, "Missing evm config"); checkNotNull(networkingConfiguration, "Missing network configuration"); + checkNotNull(dataStorageConfiguration, "Missing data storage configuration"); prepForBuild(); final ProtocolSchedule protocolSchedule = createProtocolSchedule(); diff --git a/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java b/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java index a297411552..ae907e0a38 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java @@ -14,25 +14,37 @@ */ package org.hyperledger.besu.services; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; import org.hyperledger.besu.plugin.services.BesuConfiguration; import java.nio.file.Path; /** A concrete implementation of BesuConfiguration which is used in Besu plugin framework. */ public class BesuConfigurationImpl implements BesuConfiguration { - - private final Path storagePath; - private final Path dataPath; + private Path storagePath; + private Path dataPath; + private DataStorageConfiguration dataStorageConfiguration; + private MiningParameters miningParameters; /** - * BesuConfigurationImpl Constructor. + * Post creation initialization * * @param dataPath The Path representing data folder * @param storagePath The path representing storage folder + * @param dataStorageConfiguration The data storage configuration + * @param miningParameters The mining parameters */ - public BesuConfigurationImpl(final Path dataPath, final Path storagePath) { + public void init( + final Path dataPath, + final Path storagePath, + final DataStorageConfiguration dataStorageConfiguration, + final MiningParameters miningParameters) { this.dataPath = dataPath; this.storagePath = storagePath; + this.dataStorageConfiguration = dataStorageConfiguration; + this.miningParameters = miningParameters; } @Override @@ -44,4 +56,14 @@ public class BesuConfigurationImpl implements BesuConfiguration { public Path getDataPath() { return dataPath; } + + @Override + public int getDatabaseVersion() { + return dataStorageConfiguration.getDataStorageFormat().getDatabaseVersion(); + } + + @Override + public Wei getMinGasPrice() { + return miningParameters.getMinTransactionGasPrice(); + } } diff --git a/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java b/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java index 038dcdedd1..44730b43ee 100644 --- a/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java +++ b/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java @@ -41,6 +41,7 @@ import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration; import org.hyperledger.besu.ethereum.privacy.storage.PrivacyStorageProvider; import org.hyperledger.besu.ethereum.privacy.storage.keyvalue.PrivacyKeyValueStorageProviderBuilder; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier; +import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.precompile.PrecompiledContract; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -97,11 +98,15 @@ public class PrivacyTest { private BesuController setUpControllerWithPrivacyEnabled(final boolean flexibleEnabled) throws IOException, URISyntaxException { final Path dbDir = Files.createTempDirectory(dataDir, "database"); + final var miningParameters = MiningParameters.newDefault(); + final var dataStorageConfiguration = DataStorageConfiguration.DEFAULT_FOREST_CONFIG; final PrivacyParameters privacyParameters = new PrivacyParameters.Builder() .setEnabled(true) .setEnclaveUrl(new URI("http://127.0.0.1:8000")) - .setStorageProvider(createKeyValueStorageProvider(dataDir, dbDir)) + .setStorageProvider( + createKeyValueStorageProvider( + dataDir, dbDir, dataStorageConfiguration, miningParameters)) .setEnclaveFactory(new EnclaveFactory(vertx)) .setFlexiblePrivacyGroupsEnabled(flexibleEnabled) .build(); @@ -111,7 +116,8 @@ public class PrivacyTest { .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .storageProvider(new InMemoryKeyValueStorageProvider()) .networkId(BigInteger.ONE) - .miningParameters(MiningParameters.newDefault()) + .miningParameters(miningParameters) + .dataStorageConfiguration(dataStorageConfiguration) .nodeKey(NodeKeyUtils.generate()) .metricsSystem(new NoOpMetricsSystem()) .dataDirectory(dataDir) @@ -125,7 +131,12 @@ public class PrivacyTest { } private PrivacyStorageProvider createKeyValueStorageProvider( - final Path dataDir, final Path dbDir) { + final Path dataDir, + final Path dbDir, + final DataStorageConfiguration dataStorageConfiguration, + final MiningParameters miningParameters) { + final var besuConfiguration = new BesuConfigurationImpl(); + besuConfiguration.init(dataDir, dbDir, dataStorageConfiguration, miningParameters); return new PrivacyKeyValueStorageProviderBuilder() .withStorageFactory( new RocksDBKeyValuePrivacyStorageFactory( @@ -138,7 +149,7 @@ public class PrivacyTest { DEFAULT_IS_HIGH_SPEC), Arrays.asList(KeyValueSegmentIdentifier.values()), RocksDBMetricsFactory.PRIVATE_ROCKS_DB_METRICS))) - .withCommonConfiguration(new BesuConfigurationImpl(dataDir, dbDir)) + .withCommonConfiguration(besuConfiguration) .withMetricsSystem(new NoOpMetricsSystem()) .build(); } diff --git a/besu/src/test/java/org/hyperledger/besu/RunnerTest.java b/besu/src/test/java/org/hyperledger/besu/RunnerTest.java index 241e18ce09..d624064e5c 100644 --- a/besu/src/test/java/org/hyperledger/besu/RunnerTest.java +++ b/besu/src/test/java/org/hyperledger/besu/RunnerTest.java @@ -164,12 +164,13 @@ public final class RunnerTest { final Path dataDirAhead = Files.createTempDirectory(temp, "db-ahead"); final Path dbAhead = dataDirAhead.resolve("database"); final int blockCount = 500; - final NodeKey aheadDbNodeKey = NodeKeyUtils.createFrom(KeyPairUtil.loadKeyPair(dbAhead)); + final NodeKey aheadDbNodeKey = NodeKeyUtils.createFrom(KeyPairUtil.loadKeyPair(dataDirAhead)); final NodeKey behindDbNodeKey = NodeKeyUtils.generate(); final SynchronizerConfiguration syncConfigAhead = SynchronizerConfiguration.builder().syncMode(SyncMode.FULL).build(); final ObservableMetricsSystem noOpMetricsSystem = new NoOpMetricsSystem(); - + final var miningParameters = MiningParameters.newDefault(); + final var dataStorageConfiguration = DataStorageConfiguration.DEFAULT_FOREST_CONFIG; // Setup Runner with blocks final BesuController controllerAhead = getController( @@ -177,7 +178,8 @@ public final class RunnerTest { syncConfigAhead, dataDirAhead, aheadDbNodeKey, - createKeyValueStorageProvider(dataDirAhead, dbAhead), + createKeyValueStorageProvider( + dataDirAhead, dbAhead, dataStorageConfiguration, miningParameters), noOpMetricsSystem); setupState( blockCount, controllerAhead.getProtocolSchedule(), controllerAhead.getProtocolContext()); @@ -376,7 +378,13 @@ public final class RunnerTest { return GenesisConfigFile.fromConfig(jsonNode); } - private StorageProvider createKeyValueStorageProvider(final Path dataDir, final Path dbDir) { + private StorageProvider createKeyValueStorageProvider( + final Path dataDir, + final Path dbDir, + final DataStorageConfiguration dataStorageConfiguration, + final MiningParameters miningParameters) { + final var besuConfiguration = new BesuConfigurationImpl(); + besuConfiguration.init(dataDir, dbDir, dataStorageConfiguration, miningParameters); return new KeyValueStorageProviderBuilder() .withStorageFactory( new RocksDBKeyValueStorageFactory( @@ -388,7 +396,7 @@ public final class RunnerTest { DEFAULT_IS_HIGH_SPEC), Arrays.asList(KeyValueSegmentIdentifier.values()), RocksDBMetricsFactory.PUBLIC_ROCKS_DB_METRICS)) - .withCommonConfiguration(new BesuConfigurationImpl(dataDir, dbDir)) + .withCommonConfiguration(besuConfiguration) .withMetricsSystem(new NoOpMetricsSystem()) .build(); } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java b/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java index 915eefcd24..34c9d44e0f 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java @@ -75,13 +75,13 @@ import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; import org.hyperledger.besu.pki.config.PkiKeyStoreConfiguration; -import org.hyperledger.besu.plugin.services.BesuConfiguration; import org.hyperledger.besu.plugin.services.PicoCLIOptions; import org.hyperledger.besu.plugin.services.StorageService; import org.hyperledger.besu.plugin.services.securitymodule.SecurityModule; import org.hyperledger.besu.plugin.services.storage.KeyValueStorageFactory; import org.hyperledger.besu.plugin.services.storage.PrivacyKeyValueStorageFactory; import org.hyperledger.besu.plugin.services.storage.SegmentIdentifier; +import org.hyperledger.besu.services.BesuConfigurationImpl; import org.hyperledger.besu.services.BesuPluginContextImpl; import org.hyperledger.besu.services.PermissioningServiceImpl; import org.hyperledger.besu.services.PluginTransactionValidatorServiceImpl; @@ -207,7 +207,7 @@ public abstract class CommandTestAbstract { @Mock protected StorageServiceImpl storageService; @Mock protected SecurityModuleServiceImpl securityModuleService; @Mock protected SecurityModule securityModule; - @Mock protected BesuConfiguration commonPluginConfiguration; + @Mock protected BesuConfigurationImpl commonPluginConfiguration; @Mock protected KeyValueStorageFactory rocksDBStorageFactory; @Mock protected PrivacyKeyValueStorageFactory rocksDBSPrivacyStorageFactory; @Mock protected PicoCLIOptions cliOptions; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/AbstractIsolationTests.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/AbstractIsolationTests.java index 53e7947850..983414d1c6 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/AbstractIsolationTests.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/AbstractIsolationTests.java @@ -205,6 +205,11 @@ public abstract class AbstractIsolationTests { public int getDatabaseVersion() { return 2; } + + @Override + public Wei getMinGasPrice() { + return MiningParameters.newDefault().getMinTransactionGasPrice(); + } }) .withMetricsSystem(new NoOpMetricsSystem()) .build(); diff --git a/ethereum/eth/src/jmh/java/org/hyperledger/besu/ethereum/eth/sync/worldstate/WorldStateDownloaderBenchmark.java b/ethereum/eth/src/jmh/java/org/hyperledger/besu/ethereum/eth/sync/worldstate/WorldStateDownloaderBenchmark.java index 71ba9b3ece..fb7f36038a 100644 --- a/ethereum/eth/src/jmh/java/org/hyperledger/besu/ethereum/eth/sync/worldstate/WorldStateDownloaderBenchmark.java +++ b/ethereum/eth/src/jmh/java/org/hyperledger/besu/ethereum/eth/sync/worldstate/WorldStateDownloaderBenchmark.java @@ -24,6 +24,7 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; +import org.hyperledger.besu.ethereum.core.MiningParameters; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; @@ -160,6 +161,9 @@ public class WorldStateDownloaderBenchmark { } private StorageProvider createKeyValueStorageProvider(final Path dataDir, final Path dbDir) { + final var besuConfiguration = new BesuConfigurationImpl(); + besuConfiguration.init( + dataDir, dbDir, DataStorageConfiguration.DEFAULT_CONFIG, MiningParameters.newDefault()); return new KeyValueStorageProviderBuilder() .withStorageFactory( new RocksDBKeyValueStorageFactory( @@ -171,7 +175,7 @@ public class WorldStateDownloaderBenchmark { DEFAULT_IS_HIGH_SPEC), Arrays.asList(KeyValueSegmentIdentifier.values()), RocksDBMetricsFactory.PUBLIC_ROCKS_DB_METRICS)) - .withCommonConfiguration(new BesuConfigurationImpl(dataDir, dbDir)) + .withCommonConfiguration(besuConfiguration) .withMetricsSystem(new NoOpMetricsSystem()) .build(); } diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommandOptionsModule.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommandOptionsModule.java index b8df5fa4a9..9ef1036ee4 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommandOptionsModule.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommandOptionsModule.java @@ -88,7 +88,9 @@ public class EvmToolCommandOptionsModule { @Provides @Singleton BesuConfiguration provideBesuConfiguration() { - return new BesuConfigurationImpl(dataPath, dataPath.resolve(BesuController.DATABASE_PATH)); + final var besuConfiguration = new BesuConfigurationImpl(); + besuConfiguration.init(dataPath, dataPath.resolve(BesuController.DATABASE_PATH), null, null); + return besuConfiguration; } @Option( diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index ade07493c0..9184bb5706 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -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 = '3+WNtdl1idY70N/MwVBbopU2ZWyWiu12YV1qaYXprZ8=' + knownHash = 'f6P3+XG9GjPYEg7zrXHlujoE2/4axgd+EjKGDDJVVp8=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BesuConfiguration.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BesuConfiguration.java index 9f830162ec..bf1b1ab58e 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BesuConfiguration.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BesuConfiguration.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.plugin.services; +import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.plugin.Unstable; import java.nio.file.Path; @@ -41,7 +42,13 @@ public interface BesuConfiguration extends BesuService { * @return Database version. */ @Unstable - default int getDatabaseVersion() { - return 1; - } + int getDatabaseVersion(); + + /** + * The runtime value of the min gas price + * + * @return min gas price in wei + */ + @Unstable + Wei getMinGasPrice(); }