Skip to content

Commit

Permalink
Extend BesuConfiguration service (hyperledger#6584)
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
  • Loading branch information
fab-10 authored and suraneti committed Feb 24, 2024
1 parent 7ee3288 commit 015eb33
Show file tree
Hide file tree
Showing 18 changed files with 146 additions and 57 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,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.DataStorageConfiguration;
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 @@ -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> permissioningConfiguration;
private final ApiConfiguration apiConfiguration;
private final GenesisConfigurationProvider genesisConfigProvider;
Expand Down Expand Up @@ -145,6 +147,7 @@ public BesuNode(
final MetricsConfiguration metricsConfiguration,
final Optional<PermissioningConfiguration> permissioningConfiguration,
final ApiConfiguration apiConfiguration,
final DataStorageConfiguration dataStorageConfiguration,
final Optional<String> keyfilePath,
final boolean devMode,
final NetworkName network,
Expand Down Expand Up @@ -195,6 +198,7 @@ public BesuNode(
this.metricsConfiguration = metricsConfiguration;
this.permissioningConfiguration = permissioningConfiguration;
this.apiConfiguration = apiConfiguration;
this.dataStorageConfiguration = dataStorageConfiguration;
this.genesisConfigProvider = genesisConfigProvider;
this.devMode = devMode;
this.network = network;
Expand Down Expand Up @@ -690,6 +694,10 @@ public void setPrivacyParameters(final PrivacyParameters privacyParameters) {
this.privacyParameters = privacyParameters;
}

public DataStorageConfiguration getDataStorageConfiguration() {
return dataStorageConfiguration;
}

public boolean isDevMode() {
return devMode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,12 @@ public void startNode(final BesuNode node) {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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.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;
Expand All @@ -48,6 +49,7 @@ public class BesuNodeConfiguration {
private final MetricsConfiguration metricsConfiguration;
private final Optional<PermissioningConfiguration> permissioningConfiguration;
private final ApiConfiguration apiConfiguration;
private final DataStorageConfiguration dataStorageConfiguration;
private final Optional<String> keyFilePath;
private final boolean devMode;
private final GenesisConfigurationProvider genesisConfigProvider;
Expand Down Expand Up @@ -84,6 +86,7 @@ public class BesuNodeConfiguration {
final MetricsConfiguration metricsConfiguration,
final Optional<PermissioningConfiguration> permissioningConfiguration,
final ApiConfiguration apiConfiguration,
final DataStorageConfiguration dataStorageConfiguration,
final Optional<String> keyFilePath,
final boolean devMode,
final NetworkName network,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -183,6 +187,10 @@ public ApiConfiguration getApiConfiguration() {
return apiConfiguration;
}

public DataStorageConfiguration getDataStorageConfiguration() {
return dataStorageConfiguration;
}

public Optional<String> getKeyFilePath() {
return keyFilePath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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.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;
Expand Down Expand Up @@ -73,6 +74,8 @@ public class BesuNodeConfigurationBuilder {
private MetricsConfiguration metricsConfiguration = MetricsConfiguration.builder().build();
private Optional<PermissioningConfiguration> 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();
Expand Down Expand Up @@ -506,6 +509,12 @@ public BesuNodeConfigurationBuilder apiConfiguration(final ApiConfiguration apiC
return this;
}

public BesuNodeConfigurationBuilder dataStorageConfiguration(
final DataStorageConfiguration dataStorageConfiguration) {
this.dataStorageConfiguration = dataStorageConfiguration;
return this;
}

public BesuNodeConfiguration build() {
return new BesuNodeConfiguration(
name,
Expand All @@ -519,6 +528,7 @@ public BesuNodeConfiguration build() {
metricsConfiguration,
permissioningConfiguration,
apiConfiguration,
dataStorageConfiguration,
Optional.ofNullable(keyFilePath),
devMode,
network,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public BesuNode create(final BesuNodeConfiguration config) throws IOException {
config.getMetricsConfiguration(),
config.getPermissioningConfiguration(),
config.getApiConfiguration(),
config.getDataStorageConfiguration(),
config.getKeyFilePath(),
config.isDevMode(),
config.getNetwork(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -89,7 +90,7 @@ public PrivacyNode(
selectEnclave(enclaveType, enclaveDir, config, privacyConfiguration, containerNetwork);
this.vertx = vertx;

final BesuNodeConfiguration besuConfig = config;
this.besuConfig = config;

isFlexiblePrivacyEnabled = privacyConfiguration.isFlexiblePrivacyGroupEnabled();
isMultitenancyEnabled = privacyConfiguration.isMultitenancyEnabled();
Expand All @@ -108,6 +109,7 @@ public PrivacyNode(
besuConfig.getMetricsConfiguration(),
besuConfig.getPermissioningConfiguration(),
besuConfig.getApiConfiguration(),
besuConfig.getDataStorageConfiguration(),
besuConfig.getKeyFilePath(),
besuConfig.isDevMode(),
besuConfig.getNetwork(),
Expand Down Expand Up @@ -272,6 +274,8 @@ public NodeConfiguration getConfiguration() {

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(
Expand All @@ -284,7 +288,7 @@ private PrivacyStorageProvider createKeyValueStorageProvider(
DEFAULT_IS_HIGH_SPEC),
Arrays.asList(KeyValueSegmentIdentifier.values()),
RocksDBMetricsFactory.PRIVATE_ROCKS_DB_METRICS)))
.withCommonConfiguration(new BesuConfigurationImpl(dataLocation, dbLocation))
.withCommonConfiguration(besuConfiguration)
.withMetricsSystem(new NoOpMetricsSystem())
.build();
}
Expand Down
55 changes: 24 additions & 31 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
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;
Expand Down Expand Up @@ -173,6 +174,7 @@
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;
Expand Down Expand Up @@ -893,9 +895,10 @@ static class MetricsOptionGroup {
private MetricsConfiguration metricsConfiguration;
private Optional<PermissioningConfiguration> permissioningConfiguration;
private Optional<TLSConfiguration> p2pTLSConfiguration;
private DataStorageConfiguration dataStorageConfiguration;
private Collection<EnodeURL> staticNodes;
private BesuController besuController;
private BesuConfiguration pluginCommonConfiguration;
private BesuConfigurationImpl pluginCommonConfiguration;
private MiningParameters miningParameters;

private BesuComponent besuComponent;
Expand Down Expand Up @@ -1000,7 +1003,7 @@ protected BesuCommand(
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;
Expand Down Expand Up @@ -1076,7 +1079,7 @@ public void run() {
validateOptions();
configure();
configureNativeLibs();
besuController = initController();
besuController = buildController();

besuPluginContext.beforeExternalServices();

Expand All @@ -1098,7 +1101,7 @@ public void run() {
}

@VisibleForTesting
void setBesuConfiguration(final BesuConfiguration pluginCommonConfiguration) {
void setBesuConfiguration(final BesuConfigurationImpl pluginCommonConfiguration) {
this.pluginCommonConfiguration = pluginCommonConfiguration;
}

Expand Down Expand Up @@ -1674,6 +1677,7 @@ private void configure() throws Exception {
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
Expand Down Expand Up @@ -1736,10 +1740,6 @@ private void ensureAllNodesAreInAllowlist(
}
}

private BesuController initController() {
return buildController();
}

/**
* Builds BesuController
*
Expand All @@ -1761,6 +1761,11 @@ public BesuController buildController() {
* @return instance of BesuControllerBuilder
*/
public BesuControllerBuilder getControllerBuilder() {
pluginCommonConfiguration.init(
dataDir(),
dataDir().resolve(DATABASE_PATH),
getDataStorageConfiguration(),
getMiningParameters());
final KeyValueStorageProvider storageProvider = keyValueStorageProvider(keyValueStorageName);
return controllerBuilderFactory
.fromEthNetworkConfig(
Expand All @@ -1771,6 +1776,7 @@ public BesuControllerBuilder getControllerBuilder() {
.transactionSelectorFactory(getTransactionSelectorFactory())
.pluginTransactionValidatorFactory(getPluginTransactionValidatorFactory())
.dataDirectory(dataDir())
.dataStorageConfiguration(getDataStorageConfiguration())
.miningParameters(getMiningParameters())
.transactionPoolConfiguration(buildTransactionPoolConfiguration())
.nodeKey(new NodeKey(securityModule()))
Expand All @@ -1792,7 +1798,6 @@ public BesuControllerBuilder getControllerBuilder() {
.requiredBlocks(requiredBlocks)
.reorgLoggingThreshold(reorgLoggingThreshold)
.evmConfiguration(unstableEvmOptions.toDomainObject())
.dataStorageConfiguration(dataStorageOptions.toDomainObject())
.maxPeers(p2PDiscoveryOptionGroup.maxPeers)
.maxRemotelyInitiatedPeers(maxRemoteInitiatedPeers)
.randomPeerPriority(p2PDiscoveryOptionGroup.randomPeerPriority)
Expand Down Expand Up @@ -2127,6 +2132,13 @@ private MiningParameters getMiningParameters() {
return miningParameters;
}

private DataStorageConfiguration getDataStorageConfiguration() {
if (dataStorageConfiguration == null) {
dataStorageConfiguration = dataStorageOptions.toDomainObject();
}
return dataStorageConfiguration;
}

private OptionalInt getGenesisBlockPeriodSeconds(
final GenesisConfigOptions genesisConfigOptions) {
if (genesisConfigOptions.isClique()) {
Expand Down Expand Up @@ -2538,24 +2550,6 @@ String getLogLevel() {
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;
Expand Down Expand Up @@ -2714,12 +2708,11 @@ private String generateConfigurationOverview() {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ public BesuController build() {
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();
Expand Down
Loading

0 comments on commit 015eb33

Please # to comment.