@ -18,8 +18,13 @@ import static org.hyperledger.besu.controller.BesuController.DATABASE_PATH;
import org.hyperledger.besu.Runner ;
import org.hyperledger.besu.Runner ;
import org.hyperledger.besu.RunnerBuilder ;
import org.hyperledger.besu.RunnerBuilder ;
import org.hyperledger.besu.chainexport.RlpBlockExporter ;
import org.hyperledger.besu.chainimport.JsonBlockImporter ;
import org.hyperledger.besu.chainimport.RlpBlockImporter ;
import org.hyperledger.besu.cli.BesuCommand ;
import org.hyperledger.besu.cli.config.EthNetworkConfig ;
import org.hyperledger.besu.cli.config.EthNetworkConfig ;
import org.hyperledger.besu.cli.config.NetworkName ;
import org.hyperledger.besu.cli.config.NetworkName ;
import org.hyperledger.besu.components.BesuComponent ;
import org.hyperledger.besu.config.GenesisConfigFile ;
import org.hyperledger.besu.config.GenesisConfigFile ;
import org.hyperledger.besu.controller.BesuController ;
import org.hyperledger.besu.controller.BesuController ;
import org.hyperledger.besu.controller.BesuControllerBuilder ;
import org.hyperledger.besu.controller.BesuControllerBuilder ;
@ -31,23 +36,28 @@ import org.hyperledger.besu.ethereum.api.ApiConfiguration;
import org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration ;
import org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration ;
import org.hyperledger.besu.ethereum.api.jsonrpc.InProcessRpcConfiguration ;
import org.hyperledger.besu.ethereum.api.jsonrpc.InProcessRpcConfiguration ;
import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters ;
import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters ;
import org.hyperledger.besu.ethereum.core.MiningParameters ;
import org.hyperledger.besu.ethereum.core.plugins.PluginConfiguration ;
import org.hyperledger.besu.ethereum.core.plugins.PluginConfiguration ;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration ;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration ;
import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration ;
import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration ;
import org.hyperledger.besu.ethereum.eth.transactions.BlobCacheModule ;
import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration ;
import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration ;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration ;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration ;
import org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl ;
import org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl ;
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProvider ;
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProvider ;
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProviderBuilder ;
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProviderBuilder ;
import org.hyperledger.besu.ethereum.transaction.TransactionSimulator ;
import org.hyperledger.besu.ethereum.transaction.TransactionSimulator ;
import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.cache.BonsaiCachedMerkleTrieLoaderModule ;
import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration ;
import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration ;
import org.hyperledger.besu.evm.internal.EvmConfiguration ;
import org.hyperledger.besu.evm.internal.EvmConfiguration ;
import org.hyperledger.besu.metrics.MetricsSystemFactory ;
import org.hyperledger.besu.metrics.MetricsSystemModule ;
import org.hyperledger.besu.metrics.ObservableMetricsSystem ;
import org.hyperledger.besu.metrics.ObservableMetricsSystem ;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration ;
import org.hyperledger.besu.plugin.data.EnodeURL ;
import org.hyperledger.besu.plugin.data.EnodeURL ;
import org.hyperledger.besu.plugin.services.BesuConfiguration ;
import org.hyperledger.besu.plugin.services.BesuConfiguration ;
import org.hyperledger.besu.plugin.services.BesuEvents ;
import org.hyperledger.besu.plugin.services.BesuEvents ;
import org.hyperledger.besu.plugin.services.BlockchainService ;
import org.hyperledger.besu.plugin.services.BlockchainService ;
import org.hyperledger.besu.plugin.services.MetricsSystem ;
import org.hyperledger.besu.plugin.services.PermissioningService ;
import org.hyperledger.besu.plugin.services.PermissioningService ;
import org.hyperledger.besu.plugin.services.PicoCLIOptions ;
import org.hyperledger.besu.plugin.services.PicoCLIOptions ;
import org.hyperledger.besu.plugin.services.PrivacyPluginService ;
import org.hyperledger.besu.plugin.services.PrivacyPluginService ;
@ -71,17 +81,27 @@ import org.hyperledger.besu.services.StorageServiceImpl;
import org.hyperledger.besu.services.TransactionPoolValidatorServiceImpl ;
import org.hyperledger.besu.services.TransactionPoolValidatorServiceImpl ;
import org.hyperledger.besu.services.TransactionSelectionServiceImpl ;
import org.hyperledger.besu.services.TransactionSelectionServiceImpl ;
import org.hyperledger.besu.services.TransactionSimulationServiceImpl ;
import org.hyperledger.besu.services.TransactionSimulationServiceImpl ;
import org.hyperledger.besu.services.kvstore.InMemoryStoragePlugin ;
import java.io.File ;
import java.io.File ;
import java.io.IOException ;
import java.nio.file.Files ;
import java.nio.file.Path ;
import java.nio.file.Path ;
import java.time.Clock ;
import java.time.Clock ;
import java.util.HashMap ;
import java.util.HashMap ;
import java.util.HashSet ;
import java.util.HashSet ;
import java.util.List ;
import java.util.List ;
import java.util.Map ;
import java.util.Map ;
import java.util.Optional ;
import java.util.concurrent.ConcurrentHashMap ;
import java.util.concurrent.ConcurrentHashMap ;
import java.util.stream.Collectors ;
import java.util.stream.Collectors ;
import javax.inject.Inject ;
import javax.inject.Named ;
import javax.inject.Singleton ;
import dagger.Component ;
import dagger.Module ;
import dagger.Provides ;
import io.opentelemetry.api.GlobalOpenTelemetry ;
import io.opentelemetry.api.GlobalOpenTelemetry ;
import io.vertx.core.Vertx ;
import io.vertx.core.Vertx ;
import org.slf4j.Logger ;
import org.slf4j.Logger ;
@ -97,59 +117,6 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
private final Map < Node , BesuPluginContextImpl > besuPluginContextMap = new ConcurrentHashMap < > ( ) ;
private final Map < Node , BesuPluginContextImpl > besuPluginContextMap = new ConcurrentHashMap < > ( ) ;
private BesuPluginContextImpl buildPluginContext (
final BesuNode node ,
final StorageServiceImpl storageService ,
final SecurityModuleServiceImpl securityModuleService ,
final TransactionSimulationServiceImpl transactionSimulationServiceImpl ,
final TransactionSelectionServiceImpl transactionSelectionServiceImpl ,
final TransactionPoolValidatorServiceImpl transactionPoolValidatorServiceImpl ,
final BlockchainServiceImpl blockchainServiceImpl ,
final RpcEndpointServiceImpl rpcEndpointServiceImpl ,
final BesuConfiguration commonPluginConfiguration ,
final PermissioningServiceImpl permissioningService ) {
final CommandLine commandLine = new CommandLine ( CommandSpec . create ( ) ) ;
final BesuPluginContextImpl besuPluginContext = new BesuPluginContextImpl ( ) ;
besuPluginContext . addService ( StorageService . class , storageService ) ;
besuPluginContext . addService ( SecurityModuleService . class , securityModuleService ) ;
besuPluginContext . addService ( PicoCLIOptions . class , new PicoCLIOptionsImpl ( commandLine ) ) ;
besuPluginContext . addService ( RpcEndpointService . class , rpcEndpointServiceImpl ) ;
besuPluginContext . addService (
TransactionSelectionService . class , transactionSelectionServiceImpl ) ;
besuPluginContext . addService (
TransactionPoolValidatorService . class , transactionPoolValidatorServiceImpl ) ;
besuPluginContext . addService (
TransactionSimulationService . class , transactionSimulationServiceImpl ) ;
besuPluginContext . addService ( BlockchainService . class , blockchainServiceImpl ) ;
besuPluginContext . addService ( BesuConfiguration . class , commonPluginConfiguration ) ;
final Path pluginsPath ;
final String pluginDir = System . getProperty ( "besu.plugins.dir" ) ;
if ( pluginDir = = null | | pluginDir . isEmpty ( ) ) {
pluginsPath = node . homeDirectory ( ) . resolve ( "plugins" ) ;
final File pluginsDirFile = pluginsPath . toFile ( ) ;
if ( ! pluginsDirFile . isDirectory ( ) ) {
pluginsDirFile . mkdirs ( ) ;
pluginsDirFile . deleteOnExit ( ) ;
}
System . setProperty ( "besu.plugins.dir" , pluginsPath . toString ( ) ) ;
} else {
pluginsPath = Path . of ( pluginDir ) ;
}
besuPluginContext . addService ( BesuConfiguration . class , commonPluginConfiguration ) ;
besuPluginContext . addService ( PermissioningService . class , permissioningService ) ;
besuPluginContext . addService ( PrivacyPluginService . class , new PrivacyPluginServiceImpl ( ) ) ;
besuPluginContext . registerPlugins ( new PluginConfiguration ( pluginsPath ) ) ;
commandLine . parseArgs ( node . getConfiguration ( ) . getExtraCLIOptions ( ) . toArray ( new String [ 0 ] ) ) ;
// register built-in plugins
new RocksDBPlugin ( ) . register ( besuPluginContext ) ;
return besuPluginContext ;
}
@Override
@Override
public void startNode ( final BesuNode node ) {
public void startNode ( final BesuNode node ) {
@ -162,8 +129,9 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
throw new UnsupportedOperationException ( "commands are not supported with thread runner" ) ;
throw new UnsupportedOperationException ( "commands are not supported with thread runner" ) ;
}
}
final StorageServiceImpl storageService = new StorageServiceImpl ( ) ;
AcceptanceTestBesuComponent component =
final SecurityModuleServiceImpl securityModuleService = new SecurityModuleServiceImpl ( ) ;
DaggerThreadBesuNodeRunner_AcceptanceTestBesuComponent . create ( ) ;
final TransactionSimulationServiceImpl transactionSimulationServiceImpl =
final TransactionSimulationServiceImpl transactionSimulationServiceImpl =
new TransactionSimulationServiceImpl ( ) ;
new TransactionSimulationServiceImpl ( ) ;
final TransactionSelectionServiceImpl transactionSelectionServiceImpl =
final TransactionSelectionServiceImpl transactionSelectionServiceImpl =
@ -186,49 +154,22 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
. withMiningParameters ( miningParameters ) ;
. withMiningParameters ( miningParameters ) ;
final BesuPluginContextImpl besuPluginContext =
final BesuPluginContextImpl besuPluginContext =
besuPluginContextMap . computeIfAbsent (
besuPluginContextMap . computeIfAbsent ( node , n - > component . getBesuPluginContext ( ) ) ;
node ,
n - >
buildPluginContext (
node ,
storageService ,
securityModuleService ,
transactionSimulationServiceImpl ,
transactionSelectionServiceImpl ,
transactionPoolValidatorServiceImpl ,
blockchainServiceImpl ,
rpcEndpointServiceImpl ,
commonPluginConfiguration ,
permissioningService ) ) ;
GlobalOpenTelemetry . resetForTest ( ) ;
GlobalOpenTelemetry . resetForTest ( ) ;
final ObservableMetricsSystem metricsSystem =
final ObservableMetricsSystem metricsSystem = component . getObservableMetricsSystem ( ) ;
MetricsSystemFactory . create ( node . getMetricsConfiguration ( ) ) ;
final List < EnodeURL > bootnodes =
final List < EnodeURL > bootnodes =
node . getConfiguration ( ) . getBootnodes ( ) . stream ( )
node . getConfiguration ( ) . getBootnodes ( ) . stream ( )
. map ( EnodeURLImpl : : fromURI )
. map ( EnodeURLImpl : : fromURI )
. collect ( Collectors . toList ( ) ) ;
. collect ( Collectors . toList ( ) ) ;
final NetworkName network = node . getNetwork ( ) = = null ? NetworkName . DEV : node . getNetwork ( ) ;
final EthNetworkConfig . Builder networkConfigBuilder =
final EthNetworkConfig . Builder networkConfigBuilder = component . ethNetworkConfigBuilder ( ) ;
new EthNetworkConfig . Builder ( EthNetworkConfig . getNetworkConfig ( network ) )
networkConfigBuilder . setBootNodes ( bootnodes ) ;
. setBootNodes ( bootnodes ) ;
node . getConfiguration ( )
node . getConfiguration ( )
. getGenesisConfig ( )
. getGenesisConfig ( )
. map ( GenesisConfigFile : : fromConfig )
. map ( GenesisConfigFile : : fromConfig )
. ifPresent ( networkConfigBuilder : : setGenesisConfigFile ) ;
. ifPresent ( networkConfigBuilder : : setGenesisConfigFile ) ;
final EthNetworkConfig ethNetworkConfig = networkConfigBuilder . build ( ) ;
final EthNetworkConfig ethNetworkConfig = networkConfigBuilder . build ( ) ;
final SynchronizerConfiguration synchronizerConfiguration =
new SynchronizerConfiguration . Builder ( ) . build ( ) ;
final BesuControllerBuilder builder =
new BesuController . Builder ( )
. fromEthNetworkConfig ( ethNetworkConfig , synchronizerConfiguration . getSyncMode ( ) ) ;
final KeyValueStorageProvider storageProvider =
new KeyValueStorageProviderBuilder ( )
. withStorageFactory ( storageService . getByName ( "rocksdb" ) . get ( ) )
. withCommonConfiguration ( commonPluginConfiguration )
. withMetricsSystem ( metricsSystem )
. build ( ) ;
final TransactionPoolConfiguration txPoolConfig =
final TransactionPoolConfiguration txPoolConfig =
ImmutableTransactionPoolConfiguration . builder ( )
ImmutableTransactionPoolConfiguration . builder ( )
@ -237,35 +178,20 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
. transactionPoolValidatorService ( transactionPoolValidatorServiceImpl )
. transactionPoolValidatorService ( transactionPoolValidatorServiceImpl )
. build ( ) ;
. build ( ) ;
final BesuControllerBuilder builder = component . besuControllerBuilder ( ) ;
builder . isRevertReasonEnabled ( node . isRevertReasonEnabled ( ) ) ;
builder . networkConfiguration ( node . getNetworkingConfiguration ( ) ) ;
builder . transactionPoolConfiguration ( txPoolConfig ) ;
builder . dataDirectory ( dataDir ) ;
builder . nodeKey ( new NodeKey ( new KeyPairSecurityModule ( KeyPairUtil . loadKeyPair ( dataDir ) ) ) ) ;
builder . privacyParameters ( node . getPrivacyParameters ( ) ) ;
final InProcessRpcConfiguration inProcessRpcConfiguration = node . inProcessRpcConfiguration ( ) ;
final InProcessRpcConfiguration inProcessRpcConfiguration = node . inProcessRpcConfiguration ( ) ;
final int maxPeers = 25 ;
builder
. synchronizerConfiguration ( new SynchronizerConfiguration . Builder ( ) . build ( ) )
. dataDirectory ( node . homeDirectory ( ) )
. miningParameters ( miningParameters )
. privacyParameters ( node . getPrivacyParameters ( ) )
. nodeKey ( new NodeKey ( new KeyPairSecurityModule ( KeyPairUtil . loadKeyPair ( dataDir ) ) ) )
. metricsSystem ( metricsSystem )
. transactionPoolConfiguration ( txPoolConfig )
. dataStorageConfiguration ( DataStorageConfiguration . DEFAULT_FOREST_CONFIG )
. ethProtocolConfiguration ( EthProtocolConfiguration . defaultConfig ( ) )
. clock ( Clock . systemUTC ( ) )
. isRevertReasonEnabled ( node . isRevertReasonEnabled ( ) )
. storageProvider ( storageProvider )
. gasLimitCalculator ( GasLimitCalculator . constant ( ) )
. evmConfiguration ( EvmConfiguration . DEFAULT )
. maxPeers ( maxPeers )
. maxRemotelyInitiatedPeers ( 15 )
. networkConfiguration ( node . getNetworkingConfiguration ( ) )
. randomPeerPriority ( false ) ;
node . getGenesisConfig ( )
node . getGenesisConfig ( )
. map ( GenesisConfigFile : : fromConfig )
. map ( GenesisConfigFile : : fromConfig )
. ifPresent ( builder : : genesisConfigFile ) ;
. ifPresent ( builder : : genesisConfigFile ) ;
final BesuController besuController = builder . build ( ) ;
final BesuController besuController = component . besuController ( ) ;
initTransactionSimulationService (
initTransactionSimulationService (
transactionSimulationServiceImpl , besuController , node . getApiConfiguration ( ) ) ;
transactionSimulationServiceImpl , besuController , node . getApiConfiguration ( ) ) ;
@ -299,11 +225,10 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
. collect ( Collectors . toList ( ) ) )
. collect ( Collectors . toList ( ) ) )
. besuPluginContext ( besuPluginContext )
. besuPluginContext ( besuPluginContext )
. autoLogBloomCaching ( false )
. autoLogBloomCaching ( false )
. storageProvider ( storageProvider )
. storageProvider ( be suController . getS torageProvider( ) )
. rpcEndpointService ( rpcEndpointServiceImpl )
. rpcEndpointService ( rpcEndpointServiceImpl )
. inProcessRpcConfiguration ( inProcessRpcConfiguration ) ;
. inProcessRpcConfiguration ( inProcessRpcConfiguration ) ;
node . engineRpcConfiguration ( ) . ifPresent ( runnerBuilder : : engineJsonRpcConfiguration ) ;
node . engineRpcConfiguration ( ) . ifPresent ( runnerBuilder : : engineJsonRpcConfiguration ) ;
besuPluginContext . beforeExternalServices ( ) ;
besuPluginContext . beforeExternalServices ( ) ;
final Runner runner = runnerBuilder . build ( ) ;
final Runner runner = runnerBuilder . build ( ) ;
@ -396,4 +321,229 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
public String getConsoleContents ( ) {
public String getConsoleContents ( ) {
throw new RuntimeException ( "Console contents can only be captured in process execution" ) ;
throw new RuntimeException ( "Console contents can only be captured in process execution" ) ;
}
}
@Module
@SuppressWarnings ( "CloseableProvides" )
static class BesuControllerModule {
@Provides
@Singleton
public SynchronizerConfiguration provideSynchronizationConfiguration ( ) {
final SynchronizerConfiguration synchronizerConfiguration =
SynchronizerConfiguration . builder ( ) . build ( ) ;
return synchronizerConfiguration ;
}
@Singleton
@Provides
public BesuControllerBuilder provideBesuControllerBuilder (
final EthNetworkConfig ethNetworkConfig ,
final SynchronizerConfiguration synchronizerConfiguration ) {
final BesuControllerBuilder builder =
new BesuController . Builder ( )
. fromEthNetworkConfig ( ethNetworkConfig , synchronizerConfiguration . getSyncMode ( ) ) ;
return builder ;
}
@Provides
public BesuController provideBesuController (
final SynchronizerConfiguration synchronizerConfiguration ,
final BesuControllerBuilder builder ,
final ObservableMetricsSystem metricsSystem ,
final KeyValueStorageProvider storageProvider ,
final MiningParameters miningParameters ) {
builder
. synchronizerConfiguration ( synchronizerConfiguration )
. metricsSystem ( metricsSystem )
. dataStorageConfiguration ( DataStorageConfiguration . DEFAULT_FOREST_CONFIG )
. ethProtocolConfiguration ( EthProtocolConfiguration . defaultConfig ( ) )
. clock ( Clock . systemUTC ( ) )
. storageProvider ( storageProvider )
. gasLimitCalculator ( GasLimitCalculator . constant ( ) )
. evmConfiguration ( EvmConfiguration . DEFAULT )
. maxPeers ( 25 )
. maxRemotelyInitiatedPeers ( 15 )
. miningParameters ( miningParameters )
. randomPeerPriority ( false )
. besuComponent ( null ) ;
return builder . build ( ) ;
}
@Provides
@Singleton
public EthNetworkConfig . Builder provideEthNetworkConfigBuilder ( ) {
final EthNetworkConfig . Builder networkConfigBuilder =
new EthNetworkConfig . Builder ( EthNetworkConfig . getNetworkConfig ( NetworkName . DEV ) ) ;
return networkConfigBuilder ;
}
@Provides
public EthNetworkConfig provideEthNetworkConfig (
final EthNetworkConfig . Builder networkConfigBuilder ) {
final EthNetworkConfig ethNetworkConfig = networkConfigBuilder . build ( ) ;
return ethNetworkConfig ;
}
@Provides
@Named ( "besuPluginContext" )
public BesuPluginContextImpl providePluginContext (
final StorageServiceImpl storageService ,
final SecurityModuleServiceImpl securityModuleService ,
final TransactionSimulationServiceImpl transactionSimulationServiceImpl ,
final TransactionSelectionServiceImpl transactionSelectionServiceImpl ,
final TransactionPoolValidatorServiceImpl transactionPoolValidatorServiceImpl ,
final BlockchainServiceImpl blockchainServiceImpl ,
final RpcEndpointServiceImpl rpcEndpointServiceImpl ,
final BesuConfiguration commonPluginConfiguration ,
final PermissioningServiceImpl permissioningService ) {
final CommandLine commandLine = new CommandLine ( CommandSpec . create ( ) ) ;
final BesuPluginContextImpl besuPluginContext = new BesuPluginContextImpl ( ) ;
besuPluginContext . addService ( StorageService . class , storageService ) ;
besuPluginContext . addService ( SecurityModuleService . class , securityModuleService ) ;
besuPluginContext . addService ( PicoCLIOptions . class , new PicoCLIOptionsImpl ( commandLine ) ) ;
besuPluginContext . addService ( RpcEndpointService . class , rpcEndpointServiceImpl ) ;
besuPluginContext . addService (
TransactionSelectionService . class , transactionSelectionServiceImpl ) ;
besuPluginContext . addService (
TransactionPoolValidatorService . class , transactionPoolValidatorServiceImpl ) ;
besuPluginContext . addService (
TransactionSimulationService . class , transactionSimulationServiceImpl ) ;
besuPluginContext . addService ( BlockchainService . class , blockchainServiceImpl ) ;
besuPluginContext . addService ( BesuConfiguration . class , commonPluginConfiguration ) ;
final Path pluginsPath ;
final String pluginDir = System . getProperty ( "besu.plugins.dir" ) ;
if ( pluginDir = = null | | pluginDir . isEmpty ( ) ) {
// pluginsPath = node.homeDirectory().resolve("plugins");
pluginsPath = commonPluginConfiguration . getDataPath ( ) . resolve ( "plugins" ) ;
final File pluginsDirFile = pluginsPath . toFile ( ) ;
if ( ! pluginsDirFile . isDirectory ( ) ) {
pluginsDirFile . mkdirs ( ) ;
pluginsDirFile . deleteOnExit ( ) ;
}
System . setProperty ( "besu.plugins.dir" , pluginsPath . toString ( ) ) ;
} else {
pluginsPath = Path . of ( pluginDir ) ;
}
besuPluginContext . addService ( BesuConfiguration . class , commonPluginConfiguration ) ;
besuPluginContext . addService ( PermissioningService . class , permissioningService ) ;
besuPluginContext . addService ( PrivacyPluginService . class , new PrivacyPluginServiceImpl ( ) ) ;
besuPluginContext . registerPlugins ( new PluginConfiguration ( pluginsPath ) ) ;
// register built-in plugins
new RocksDBPlugin ( ) . register ( besuPluginContext ) ;
return besuPluginContext ;
}
@Provides
public KeyValueStorageProvider provideKeyValueStorageProvider (
final BesuConfiguration commonPluginConfiguration , final MetricsSystem metricsSystem ) {
final StorageServiceImpl storageService = new StorageServiceImpl ( ) ;
storageService . registerKeyValueStorage (
new InMemoryStoragePlugin . InMemoryKeyValueStorageFactory ( "memory" ) ) ;
final KeyValueStorageProvider storageProvider =
new KeyValueStorageProviderBuilder ( )
. withStorageFactory ( storageService . getByName ( "memory" ) . get ( ) )
. withCommonConfiguration ( commonPluginConfiguration )
. withMetricsSystem ( metricsSystem )
. build ( ) ;
return storageProvider ;
}
@Provides
public MiningParameters provideMiningParameters (
final TransactionSelectionServiceImpl transactionSelectionServiceImpl ) {
final var miningParameters =
ImmutableMiningParameters . builder ( )
. transactionSelectionService ( transactionSelectionServiceImpl )
. build ( ) ;
return miningParameters ;
}
@Provides
Path provideDataDir ( ) {
try {
return Files . createTempDirectory ( "acctest" ) ;
} catch ( final IOException e ) {
throw new RuntimeException ( "Unable to create temporary data directory" , e ) ;
}
}
@Provides
@Inject
BesuConfiguration provideBesuConfiguration ( final Path dataDir ) {
final BesuConfigurationImpl commonPluginConfiguration = new BesuConfigurationImpl ( ) ;
commonPluginConfiguration . init (
dataDir , dataDir . resolve ( DATABASE_PATH ) , DataStorageConfiguration . DEFAULT_FOREST_CONFIG ) ;
return commonPluginConfiguration ;
}
@Provides
TransactionPoolConfiguration provideTransactionPoolConfiguration (
final BesuNode node ,
final TransactionPoolValidatorServiceImpl transactionPoolValidatorServiceImpl ) {
return ImmutableTransactionPoolConfiguration . builder ( )
. from ( node . getTransactionPoolConfiguration ( ) )
. strictTransactionReplayProtectionEnabled ( node . isStrictTxReplayProtectionEnabled ( ) )
. transactionPoolValidatorService ( transactionPoolValidatorServiceImpl )
. build ( ) ;
}
}
@Module
static class MockBesuCommandModule {
@Provides
BesuCommand provideBesuCommand ( final AcceptanceTestBesuComponent component ) {
final BesuCommand besuCommand =
new BesuCommand (
component ,
RlpBlockImporter : : new ,
JsonBlockImporter : : new ,
RlpBlockExporter : : new ,
new RunnerBuilder ( ) ,
new BesuController . Builder ( ) ,
Optional . ofNullable ( component . getBesuPluginContext ( ) ) . orElse ( null ) ,
System . getenv ( ) ) ;
besuCommand . toCommandLine ( ) ;
return besuCommand ;
}
@Provides
@Singleton
MetricsConfiguration provideMetricsConfiguration ( ) {
return MetricsConfiguration . builder ( ) . build ( ) ;
}
@Provides
@Named ( "besuCommandLogger" )
@Singleton
Logger provideBesuCommandLogger ( ) {
return LoggerFactory . getLogger ( MockBesuCommandModule . class ) ;
}
}
@Singleton
@Component (
modules = {
ThreadBesuNodeRunner . BesuControllerModule . class ,
ThreadBesuNodeRunner . MockBesuCommandModule . class ,
BonsaiCachedMerkleTrieLoaderModule . class ,
MetricsSystemModule . class ,
BlobCacheModule . class
} )
public interface AcceptanceTestBesuComponent extends BesuComponent {
BesuController besuController ( ) ;
BesuControllerBuilder besuControllerBuilder ( ) ; // TODO: needing this sucks
EthNetworkConfig . Builder ethNetworkConfigBuilder ( ) ;
}
}
}