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 ba00ac8f22f..c822ce899ce 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.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 BesuNode( 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 BesuNode( this.metricsConfiguration = metricsConfiguration; this.permissioningConfiguration = permissioningConfiguration; this.apiConfiguration = apiConfiguration; + this.dataStorageConfiguration = dataStorageConfiguration; this.genesisConfigProvider = genesisConfigProvider; this.devMode = devMode; this.network = network; @@ -432,6 +436,7 @@ public NodeRequests nodeRequests() { nodeRequests = new NodeRequests( + web3jService, new JsonRpc2_0Web3j(web3jService, 2000, Async.defaultExecutorService()), new CliqueRequestFactory(web3jService), new BftRequestFactory(web3jService, bftType), @@ -690,6 +695,10 @@ public void setPrivacyParameters(final PrivacyParameters privacyParameters) { 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 a29a7b0ee60..7dee09bad78 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 @@ -28,6 +28,7 @@ import org.hyperledger.besu.cryptoservices.KeyPairSecurityModule; import org.hyperledger.besu.cryptoservices.NodeKey; import org.hyperledger.besu.ethereum.GasLimitCalculator; +import org.hyperledger.besu.ethereum.api.ApiConfiguration; import org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; @@ -36,24 +37,26 @@ 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.transaction.TransactionSimulator; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.MetricsSystemFactory; import org.hyperledger.besu.metrics.ObservableMetricsSystem; import org.hyperledger.besu.plugin.data.EnodeURL; import org.hyperledger.besu.plugin.services.BesuConfiguration; import org.hyperledger.besu.plugin.services.BesuEvents; +import org.hyperledger.besu.plugin.services.BlockchainService; import org.hyperledger.besu.plugin.services.PicoCLIOptions; import org.hyperledger.besu.plugin.services.PluginTransactionValidatorService; import org.hyperledger.besu.plugin.services.RpcEndpointService; import org.hyperledger.besu.plugin.services.SecurityModuleService; import org.hyperledger.besu.plugin.services.StorageService; import org.hyperledger.besu.plugin.services.TransactionSelectionService; +import org.hyperledger.besu.plugin.services.TransactionSimulationService; 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; import org.hyperledger.besu.services.PermissioningServiceImpl; import org.hyperledger.besu.services.PicoCLIOptionsImpl; import org.hyperledger.besu.services.PluginTransactionValidatorServiceImpl; @@ -61,6 +64,7 @@ import org.hyperledger.besu.services.SecurityModuleServiceImpl; import org.hyperledger.besu.services.StorageServiceImpl; import org.hyperledger.besu.services.TransactionSelectionServiceImpl; +import org.hyperledger.besu.services.TransactionSimulationServiceImpl; import java.io.File; import java.nio.file.Path; @@ -70,7 +74,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; @@ -93,17 +96,27 @@ private BesuPluginContextImpl buildPluginContext( final BesuNode node, final StorageServiceImpl storageService, final SecurityModuleServiceImpl securityModuleService, + final TransactionSimulationServiceImpl transactionSimulationServiceImpl, + final PluginTransactionValidatorServiceImpl transactionValidatorServiceImpl, + final TransactionSelectionServiceImpl transactionSelectionServiceImpl, + final BlockchainServiceImpl blockchainServiceImpl, + final RpcEndpointServiceImpl rpcEndpointServiceImpl, final BesuConfiguration commonPluginConfiguration) { 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, new RpcEndpointServiceImpl()); + besuPluginContext.addService(RpcEndpointService.class, rpcEndpointServiceImpl); besuPluginContext.addService( - TransactionSelectionService.class, new TransactionSelectionServiceImpl()); + TransactionSelectionService.class, transactionSelectionServiceImpl); besuPluginContext.addService( - PluginTransactionValidatorService.class, new PluginTransactionValidatorServiceImpl()); + PluginTransactionValidatorService.class, transactionValidatorServiceImpl); + 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()) { @@ -120,9 +133,6 @@ private BesuPluginContextImpl buildPluginContext( besuPluginContext.registerPlugins(pluginsPath); commandLine.parseArgs(node.getConfiguration().getExtraCLIOptions().toArray(new String[0])); - - besuPluginContext.addService(BesuConfiguration.class, commonPluginConfiguration); - // register built-in plugins new RocksDBPlugin().register(besuPluginContext); @@ -143,15 +153,35 @@ public void startNode(final BesuNode node) { final StorageServiceImpl storageService = new StorageServiceImpl(); final SecurityModuleServiceImpl securityModuleService = new SecurityModuleServiceImpl(); + final TransactionSimulationServiceImpl transactionSimulationServiceImpl = + new TransactionSimulationServiceImpl(); + final TransactionSelectionServiceImpl transactionSelectionServiceImpl = + new TransactionSelectionServiceImpl(); + final PluginTransactionValidatorServiceImpl transactionValidatorServiceImpl = + new PluginTransactionValidatorServiceImpl(); + final BlockchainServiceImpl blockchainServiceImpl = new BlockchainServiceImpl(); + final RpcEndpointServiceImpl rpcEndpointServiceImpl = new RpcEndpointServiceImpl(); 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, n -> buildPluginContext( - node, storageService, securityModuleService, commonPluginConfiguration)); + node, + storageService, + securityModuleService, + transactionSimulationServiceImpl, + transactionValidatorServiceImpl, + transactionSelectionServiceImpl, + blockchainServiceImpl, + rpcEndpointServiceImpl, + commonPluginConfiguration)); GlobalOpenTelemetry.resetForTest(); final ObservableMetricsSystem metricsSystem = @@ -188,11 +218,11 @@ public void startNode(final BesuNode node) { final int maxPeers = 25; - final Optional transactionSelectorFactory = - getTransactionSelectorFactory(besuPluginContext); + final TransactionSelectionService transactionSelectorService = + getTransactionSelectorService(besuPluginContext); - final PluginTransactionValidatorFactory pluginTransactionValidatorFactory = - getPluginTransactionValidatorFactory(besuPluginContext); + final PluginTransactionValidatorService pluginTransactionValidatorService = + getPluginTransactionValidatorService(besuPluginContext); builder .synchronizerConfiguration(new SynchronizerConfiguration.Builder().build()) .dataDirectory(node.homeDirectory()) @@ -214,8 +244,8 @@ public void startNode(final BesuNode node) { .maxRemotelyInitiatedPeers(15) .networkConfiguration(node.getNetworkingConfiguration()) .randomPeerPriority(false) - .transactionSelectorFactory(transactionSelectorFactory) - .pluginTransactionValidatorFactory(pluginTransactionValidatorFactory); + .transactionSelectorService(transactionSelectorService) + .pluginTransactionValidatorService(pluginTransactionValidatorService); node.getGenesisConfig() .map(GenesisConfigFile::fromConfig) @@ -223,6 +253,10 @@ public void startNode(final BesuNode node) { final BesuController besuController = builder.build(); + initTransactionSimulationService( + transactionSimulationServiceImpl, besuController, node.getApiConfiguration()); + initBlockchainService(blockchainServiceImpl, besuController); + final RunnerBuilder runnerBuilder = new RunnerBuilder(); runnerBuilder.permissioningConfiguration(node.getPermissioningConfiguration()); runnerBuilder.apiConfiguration(node.getApiConfiguration()); @@ -252,7 +286,7 @@ public void startNode(final BesuNode node) { .besuPluginContext(new BesuPluginContextImpl()) .autoLogBloomCaching(false) .storageProvider(storageProvider) - .rpcEndpointService(new RpcEndpointServiceImpl()); + .rpcEndpointService(rpcEndpointServiceImpl); node.engineRpcConfiguration().ifPresent(runnerBuilder::engineJsonRpcConfiguration); final Runner runner = runnerBuilder.build(); @@ -276,6 +310,25 @@ public void startNode(final BesuNode node) { MDC.remove("node"); } + private void initBlockchainService( + final BlockchainServiceImpl blockchainServiceImpl, final BesuController besuController) { + blockchainServiceImpl.init( + besuController.getProtocolContext(), besuController.getProtocolSchedule()); + } + + private void initTransactionSimulationService( + final TransactionSimulationServiceImpl transactionSimulationService, + final BesuController besuController, + final ApiConfiguration apiConfiguration) { + transactionSimulationService.init( + besuController.getProtocolContext().getBlockchain(), + new TransactionSimulator( + besuController.getProtocolContext().getBlockchain(), + besuController.getProtocolContext().getWorldStateArchive(), + besuController.getProtocolSchedule(), + apiConfiguration.getGasCap())); + } + @Override public void stopNode(final BesuNode node) { final BesuPluginContextImpl pluginContext = besuPluginContextMap.remove(node); @@ -326,17 +379,15 @@ public String getConsoleContents() { throw new RuntimeException("Console contents can only be captured in process execution"); } - private Optional getTransactionSelectorFactory( + private TransactionSelectionService getTransactionSelectorService( final BesuPluginContextImpl besuPluginContext) { - final Optional txSelectionService = - besuPluginContext.getService(TransactionSelectionService.class); - return txSelectionService.isPresent() ? txSelectionService.get().get() : Optional.empty(); + return besuPluginContext.getService(TransactionSelectionService.class).orElseThrow(); } - private PluginTransactionValidatorFactory getPluginTransactionValidatorFactory( + private PluginTransactionValidatorService getPluginTransactionValidatorService( final BesuPluginContextImpl besuPluginContext) { - final Optional txValidatorService = - besuPluginContext.getService(PluginTransactionValidatorService.class); - return txValidatorService.map(PluginTransactionValidatorService::get).orElse(null); + return besuPluginContext + .getService(org.hyperledger.besu.plugin.services.PluginTransactionValidatorService.class) + .orElseThrow(); } } 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 0c0d66be6a8..d1e398f7215 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.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 ApiConfiguration getApiConfiguration() { 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 c20e7ec6d11..77d9477228f 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.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_CONFIG; private String keyFilePath = null; private boolean devMode = true; private GenesisConfigurationProvider genesisConfigProvider = ignore -> Optional.empty(); @@ -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, @@ -519,6 +528,7 @@ public BesuNodeConfiguration build() { 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 ed26587812c..ff6dc2ac9b1 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 @@ -49,6 +49,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.Set; import java.util.function.UnaryOperator; import io.vertx.core.Vertx; @@ -72,6 +73,7 @@ public BesuNode create(final BesuNodeConfiguration config) throws IOException { config.getMetricsConfiguration(), config.getPermissioningConfiguration(), config.getApiConfiguration(), + config.getDataStorageConfiguration(), config.getKeyFilePath(), config.isDevMode(), config.getNetwork(), @@ -375,17 +377,27 @@ public BesuNode createCliqueNode(final String name) throws IOException { public BesuNode createCliqueNode(final String name, final CliqueOptions cliqueOptions) throws IOException { - return createCliqueNodeWithExtraCliOptions(name, cliqueOptions, List.of()); + return createCliqueNodeWithExtraCliOptionsAndRpcApis(name, cliqueOptions, List.of()); } - public BesuNode createCliqueNodeWithExtraCliOptions( + public BesuNode createCliqueNodeWithExtraCliOptionsAndRpcApis( final String name, final CliqueOptions cliqueOptions, final List extraCliOptions) throws IOException { + return createCliqueNodeWithExtraCliOptionsAndRpcApis( + name, cliqueOptions, extraCliOptions, Set.of()); + } + + public BesuNode createCliqueNodeWithExtraCliOptionsAndRpcApis( + final String name, + final CliqueOptions cliqueOptions, + final List extraCliOptions, + final Set extraRpcApis) + throws IOException { return create( new BesuNodeConfigurationBuilder() .name(name) .miningEnabled() - .jsonRpcConfiguration(node.createJsonRpcWithCliqueEnabledConfig()) + .jsonRpcConfiguration(node.createJsonRpcWithCliqueEnabledConfig(extraRpcApis)) .webSocketConfiguration(node.createWebSocketEnabledConfig()) .devMode(false) .jsonRpcTxPool() @@ -583,7 +595,7 @@ public BesuNode createCliqueNodeWithValidators(final String name, final String.. new BesuNodeConfigurationBuilder() .name(name) .miningEnabled() - .jsonRpcConfiguration(node.createJsonRpcWithCliqueEnabledConfig()) + .jsonRpcConfiguration(node.createJsonRpcWithCliqueEnabledConfig(Set.of())) .webSocketConfiguration(node.createWebSocketEnabledConfig()) .jsonRpcTxPool() .devMode(false) diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/NodeConfigurationFactory.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/NodeConfigurationFactory.java index f2682993f8a..219d15d1adf 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/NodeConfigurationFactory.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/NodeConfigurationFactory.java @@ -30,8 +30,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.HashSet; import java.util.List; import java.util.Optional; +import java.util.Set; public class NodeConfigurationFactory { @@ -44,8 +46,10 @@ public Optional createGenesisConfigForValidators( return genesisConfigProvider.create(nodes); } - public JsonRpcConfiguration createJsonRpcWithCliqueEnabledConfig() { - return createJsonRpcWithRpcApiEnabledConfig(CLIQUE.name()); + public JsonRpcConfiguration createJsonRpcWithCliqueEnabledConfig(final Set extraRpcApis) { + final var enabledApis = new HashSet<>(extraRpcApis); + enabledApis.add(CLIQUE.name()); + return createJsonRpcWithRpcApiEnabledConfig(enabledApis.toArray(String[]::new)); } public JsonRpcConfiguration createJsonRpcWithIbft2EnabledConfig(final boolean minerEnabled) { 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 4ec4396d6b5..1c0df5ace6d 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 PrivacyNode( 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 PrivacyNode( besuConfig.getMetricsConfiguration(), besuConfig.getPermissioningConfiguration(), besuConfig.getApiConfiguration(), + besuConfig.getDataStorageConfiguration(), besuConfig.getKeyFilePath(), besuConfig.isDevMode(), besuConfig.getNetwork(), @@ -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( @@ -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(); } diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/NodeRequests.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/NodeRequests.java index 4741e397ddc..1151100065b 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/NodeRequests.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/NodeRequests.java @@ -27,10 +27,11 @@ import java.util.Optional; import org.web3j.protocol.Web3j; +import org.web3j.protocol.Web3jService; import org.web3j.protocol.websocket.WebSocketService; public class NodeRequests { - + private final Web3jService web3jService; private final Web3j netEth; private final CliqueRequestFactory clique; private final BftRequestFactory bft; @@ -44,6 +45,7 @@ public class NodeRequests { private final TxPoolRequestFactory txPool; public NodeRequests( + final Web3jService web3jService, final Web3j netEth, final CliqueRequestFactory clique, final BftRequestFactory bft, @@ -55,6 +57,7 @@ public NodeRequests( final TxPoolRequestFactory txPool, final Optional websocketService, final LoginRequestFactory login) { + this.web3jService = web3jService; this.netEth = netEth; this.clique = clique; this.bft = bft; @@ -116,4 +119,8 @@ public void shutdown() { netEth.shutdown(); websocketService.ifPresent(WebSocketService::close); } + + public Web3jService getWeb3jService() { + return web3jService; + } } diff --git a/besu/build.gradle b/besu/build.gradle index 0b31c4a43c2..85c17e7ff35 100644 --- a/besu/build.gradle +++ b/besu/build.gradle @@ -28,6 +28,8 @@ jar { } dependencies { + api project(':datatypes') + api 'org.slf4j:slf4j-api' implementation project(':config') 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 db4a733f9fe..43473206333 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -137,7 +137,9 @@ 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.transaction.TransactionSimulator; 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; @@ -165,14 +167,14 @@ import org.hyperledger.besu.plugin.services.StorageService; import org.hyperledger.besu.plugin.services.TraceService; import org.hyperledger.besu.plugin.services.TransactionSelectionService; +import org.hyperledger.besu.plugin.services.TransactionSimulationService; import org.hyperledger.besu.plugin.services.exception.StorageException; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.MetricCategoryRegistry; import org.hyperledger.besu.plugin.services.securitymodule.SecurityModule; import org.hyperledger.besu.plugin.services.storage.PrivacyKeyValueStorageFactory; 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; @@ -185,6 +187,7 @@ import org.hyperledger.besu.services.StorageServiceImpl; import org.hyperledger.besu.services.TraceServiceImpl; import org.hyperledger.besu.services.TransactionSelectionServiceImpl; +import org.hyperledger.besu.services.TransactionSimulationServiceImpl; import org.hyperledger.besu.services.kvstore.InMemoryStoragePlugin; import org.hyperledger.besu.util.InvalidConfigurationException; import org.hyperledger.besu.util.LogConfigurator; @@ -232,7 +235,6 @@ import io.vertx.core.metrics.MetricsOptions; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.units.bigints.UInt256; -import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import picocli.AutoComplete; import picocli.CommandLine; @@ -365,6 +367,8 @@ public class BesuCommand implements DefaultCommandValues, Runnable { private final TransactionSelectionServiceImpl transactionSelectionServiceImpl; private final PluginTransactionValidatorServiceImpl transactionValidatorServiceImpl; + private final TransactionSimulationServiceImpl transactionSimulationServiceImpl; + private final BlockchainServiceImpl blockchainServiceImpl; static class P2PDiscoveryOptionGroup { @@ -889,9 +893,10 @@ static class MetricsOptionGroup { 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; @@ -942,7 +947,9 @@ public BesuCommand( new PkiBlockCreationConfigurationProvider(), new RpcEndpointServiceImpl(), new TransactionSelectionServiceImpl(), - new PluginTransactionValidatorServiceImpl()); + new PluginTransactionValidatorServiceImpl(), + new TransactionSimulationServiceImpl(), + new BlockchainServiceImpl()); } /** @@ -964,6 +971,8 @@ public BesuCommand( * @param rpcEndpointServiceImpl instance of RpcEndpointServiceImpl * @param transactionSelectionServiceImpl instance of TransactionSelectionServiceImpl * @param transactionValidatorServiceImpl instance of TransactionValidatorServiceImpl + * @param transactionSimulationServiceImpl instance of TransactionSimulationServiceImpl + * @param blockchainServiceImpl instance of BlockchainServiceImpl */ @VisibleForTesting protected BesuCommand( @@ -982,7 +991,9 @@ protected BesuCommand( final PkiBlockCreationConfigurationProvider pkiBlockCreationConfigProvider, final RpcEndpointServiceImpl rpcEndpointServiceImpl, final TransactionSelectionServiceImpl transactionSelectionServiceImpl, - final PluginTransactionValidatorServiceImpl transactionValidatorServiceImpl) { + final PluginTransactionValidatorServiceImpl transactionValidatorServiceImpl, + final TransactionSimulationServiceImpl transactionSimulationServiceImpl, + final BlockchainServiceImpl blockchainServiceImpl) { this.besuComponent = besuComponent; this.logger = besuComponent.getBesuCommandLogger(); this.rlpBlockImporter = rlpBlockImporter; @@ -996,12 +1007,14 @@ 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; this.transactionSelectionServiceImpl = transactionSelectionServiceImpl; this.transactionValidatorServiceImpl = transactionValidatorServiceImpl; + this.transactionSimulationServiceImpl = transactionSimulationServiceImpl; + this.blockchainServiceImpl = blockchainServiceImpl; } /** @@ -1069,7 +1082,7 @@ public void run() { validateOptions(); configure(); configureNativeLibs(); - besuController = initController(); + besuController = buildController(); besuPluginContext.beforeExternalServices(); @@ -1091,7 +1104,7 @@ public void run() { } @VisibleForTesting - void setBesuConfiguration(final BesuConfiguration pluginCommonConfiguration) { + void setBesuConfiguration(final BesuConfigurationImpl pluginCommonConfiguration) { this.pluginCommonConfiguration = pluginCommonConfiguration; } @@ -1184,6 +1197,9 @@ private void preparePlugins() { TransactionSelectionService.class, transactionSelectionServiceImpl); besuPluginContext.addService( PluginTransactionValidatorService.class, transactionValidatorServiceImpl); + besuPluginContext.addService( + TransactionSimulationService.class, transactionSimulationServiceImpl); + besuPluginContext.addService(BlockchainService.class, blockchainServiceImpl); // register built-in plugins rocksDBPlugin = new RocksDBPlugin(); @@ -1264,6 +1280,16 @@ private Runner buildRunner() { } private void startPlugins() { + blockchainServiceImpl.init( + besuController.getProtocolContext(), besuController.getProtocolSchedule()); + transactionSimulationServiceImpl.init( + besuController.getProtocolContext().getBlockchain(), + new TransactionSimulator( + besuController.getProtocolContext().getBlockchain(), + besuController.getProtocolContext().getWorldStateArchive(), + besuController.getProtocolSchedule(), + apiConfiguration.getGasCap())); + besuPluginContext.addService( BesuEvents.class, new BesuEventsImpl( @@ -1273,10 +1299,6 @@ private void startPlugins() { besuController.getSyncState())); besuPluginContext.addService(MetricsSystem.class, getMetricsSystem()); - besuPluginContext.addService( - BlockchainService.class, - new BlockchainServiceImpl(besuController.getProtocolContext().getBlockchain())); - besuPluginContext.addService( TraceService.class, new TraceServiceImpl( @@ -1667,6 +1689,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 @@ -1729,10 +1752,6 @@ private void ensureAllNodesAreInAllowlist( } } - private BesuController initController() { - return buildController(); - } - /** * Builds BesuController * @@ -1754,6 +1773,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( @@ -1761,9 +1785,10 @@ public BesuControllerBuilder getControllerBuilder() { .synchronizerConfiguration(buildSyncConfig()) .ethProtocolConfiguration(unstableEthProtocolOptions.toDomainObject()) .networkConfiguration(unstableNetworkingOptions.toDomainObject()) - .transactionSelectorFactory(getTransactionSelectorFactory()) - .pluginTransactionValidatorFactory(getPluginTransactionValidatorFactory()) + .transactionSelectorService(getTransactionSelectorService()) + .pluginTransactionValidatorService(getPluginTransactionValidatorService()) .dataDirectory(dataDir()) + .dataStorageConfiguration(getDataStorageConfiguration()) .miningParameters(getMiningParameters()) .transactionPoolConfiguration(buildTransactionPoolConfiguration()) .nodeKey(new NodeKey(securityModule())) @@ -1785,7 +1810,6 @@ public BesuControllerBuilder getControllerBuilder() { .requiredBlocks(requiredBlocks) .reorgLoggingThreshold(reorgLoggingThreshold) .evmConfiguration(unstableEvmOptions.toDomainObject()) - .dataStorageConfiguration(dataStorageOptions.toDomainObject()) .maxPeers(p2PDiscoveryOptionGroup.maxPeers) .maxRemotelyInitiatedPeers(maxRemoteInitiatedPeers) .randomPeerPriority(p2PDiscoveryOptionGroup.randomPeerPriority) @@ -1793,17 +1817,12 @@ public BesuControllerBuilder getControllerBuilder() { .cacheLastBlocks(numberOfblocksToCache); } - @NotNull - private Optional getTransactionSelectorFactory() { - final Optional txSelectionService = - besuPluginContext.getService(TransactionSelectionService.class); - return txSelectionService.isPresent() ? txSelectionService.get().get() : Optional.empty(); + private TransactionSelectionService getTransactionSelectorService() { + return besuPluginContext.getService(TransactionSelectionService.class).orElseThrow(); } - private PluginTransactionValidatorFactory getPluginTransactionValidatorFactory() { - final Optional txSValidatorService = - besuPluginContext.getService(PluginTransactionValidatorService.class); - return txSValidatorService.map(PluginTransactionValidatorService::get).orElse(null); + private PluginTransactionValidatorService getPluginTransactionValidatorService() { + return besuPluginContext.getService(PluginTransactionValidatorService.class).orElseThrow(); } private JsonRpcConfiguration createEngineJsonRpcConfiguration( @@ -2120,6 +2139,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()) { @@ -2531,24 +2557,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; @@ -2707,12 +2715,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()); diff --git a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommand.java index ea8bfab8d14..d373091cd9f 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommand.java @@ -34,6 +34,7 @@ import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; import org.hyperledger.besu.metrics.MetricsService; import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; @@ -258,6 +259,7 @@ private BesuController createController() { // set to mainnet genesis block so validation rules won't reject it. .clock(Clock.fixed(Instant.ofEpochSecond(startTime), ZoneOffset.UTC)) .miningParameters(getMiningParameters()) + .dataStorageConfiguration(DataStorageConfiguration.DEFAULT_CONFIG) .build(); } catch (final Exception e) { throw new ExecutionException(parentCommand.spec.commandLine(), e.getMessage(), e); @@ -376,6 +378,7 @@ private BesuController createBesuController() { .parentCommand .getControllerBuilder() .miningParameters(MiningParameters.newDefault()) + .dataStorageConfiguration(DataStorageConfiguration.DEFAULT_CONFIG) .build(); } 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 539c3d62ab2..03c2db422a4 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java @@ -97,9 +97,9 @@ import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.ObservableMetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem; +import org.hyperledger.besu.plugin.services.PluginTransactionValidatorService; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; import org.hyperledger.besu.plugin.services.permissioning.NodeMessagePermissioningProvider; -import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory; -import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidatorFactory; import java.io.Closeable; import java.math.BigInteger; @@ -184,11 +184,11 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides private NetworkingConfiguration networkingConfiguration; private Boolean randomPeerPriority; - private Optional transactionSelectorFactory = Optional.empty(); + private TransactionSelectionService transactionSelectorService; /** the Dagger configured context that can provide dependencies */ protected Optional besuComponent = Optional.empty(); - private PluginTransactionValidatorFactory pluginTransactionValidatorFactory; + private PluginTransactionValidatorService pluginTransactionValidatorService; private int numberOfBlocksToCache = 0; @@ -532,26 +532,26 @@ public BesuControllerBuilder randomPeerPriority(final Boolean randomPeerPriority } /** - * sets the transactionSelectorFactory in the builder + * sets the transactionSelectionService in the builder * - * @param transactionSelectorFactory the optional transaction selector factory + * @param transactionSelectionService the transaction selector service * @return the besu controller builder */ - public BesuControllerBuilder transactionSelectorFactory( - final Optional transactionSelectorFactory) { - this.transactionSelectorFactory = transactionSelectorFactory; + public BesuControllerBuilder transactionSelectorService( + final TransactionSelectionService transactionSelectionService) { + this.transactionSelectorService = transactionSelectionService; return this; } /** - * sets the pluginTransactionValidatorFactory + * sets the pluginTransactionValidatorService * - * @param pluginTransactionValidatorFactory factory that creates plugin transaction Validators + * @param pluginTransactionValidatorService factory that creates plugin transaction Validators * @return the besu controller builder */ - public BesuControllerBuilder pluginTransactionValidatorFactory( - final PluginTransactionValidatorFactory pluginTransactionValidatorFactory) { - this.pluginTransactionValidatorFactory = pluginTransactionValidatorFactory; + public BesuControllerBuilder pluginTransactionValidatorService( + final PluginTransactionValidatorService pluginTransactionValidatorService) { + this.pluginTransactionValidatorService = pluginTransactionValidatorService; return this; } @@ -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(); @@ -618,7 +619,7 @@ public BesuController build() { worldStateArchive, protocolSchedule, this::createConsensusContext, - transactionSelectorFactory); + transactionSelectorService); validateContext(protocolContext); if (chainPrunerConfiguration.getChainPruningEnabled()) { @@ -712,7 +713,7 @@ public BesuController build() { metricsSystem, syncState, transactionPoolConfiguration, - pluginTransactionValidatorFactory, + pluginTransactionValidatorService, besuComponent.map(BesuComponent::getBlobCache).orElse(new BlobCache())); final List peerValidators = createPeerValidators(protocolSchedule); @@ -1054,7 +1055,7 @@ protected EthProtocolManager createEthProtocolManager( * @param worldStateArchive the world state archive * @param protocolSchedule the protocol schedule * @param consensusContextFactory the consensus context factory - * @param transactionSelectorFactory optional transaction selector factory + * @param transactionSelectionService optional transaction selector factory * @return the protocol context */ protected ProtocolContext createProtocolContext( @@ -1062,13 +1063,13 @@ protected ProtocolContext createProtocolContext( final WorldStateArchive worldStateArchive, final ProtocolSchedule protocolSchedule, final ConsensusContextFactory consensusContextFactory, - final Optional transactionSelectorFactory) { + final TransactionSelectionService transactionSelectionService) { return ProtocolContext.init( blockchain, worldStateArchive, protocolSchedule, consensusContextFactory, - transactionSelectorFactory); + transactionSelectionService); } private Optional createSnapProtocolManager( diff --git a/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java index 1d9356f5c76..daf736d5669 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java @@ -61,8 +61,8 @@ import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.ObservableMetricsSystem; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; import org.hyperledger.besu.plugin.services.permissioning.NodeMessagePermissioningProvider; -import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory; import java.math.BigInteger; import java.nio.file.Path; @@ -176,13 +176,13 @@ protected ProtocolContext createProtocolContext( final WorldStateArchive worldStateArchive, final ProtocolSchedule protocolSchedule, final ConsensusContextFactory consensusContextFactory, - final Optional transactionSelectorFactory) { + final TransactionSelectionService transactionSelectionService) { return MigratingProtocolContext.init( blockchain, worldStateArchive, protocolSchedule, consensusContextFactory, - transactionSelectorFactory); + transactionSelectionService); } @Override diff --git a/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java index 65aadd46c63..e62cc737594 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java @@ -59,8 +59,8 @@ import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.ObservableMetricsSystem; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; import org.hyperledger.besu.plugin.services.permissioning.NodeMessagePermissioningProvider; -import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory; import java.math.BigInteger; import java.nio.file.Path; @@ -190,14 +190,14 @@ protected ProtocolContext createProtocolContext( final WorldStateArchive worldStateArchive, final ProtocolSchedule protocolSchedule, final ConsensusContextFactory consensusContextFactory, - final Optional transactionSelectorFactory) { + final TransactionSelectionService transactionSelectionService) { final ProtocolContext protocolContext = super.createProtocolContext( blockchain, worldStateArchive, protocolSchedule, consensusContextFactory, - transactionSelectorFactory); + transactionSelectionService); transitionProtocolSchedule.setProtocolContext(protocolContext); return protocolContext; } 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 a2974115522..ae907e0a381 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 Path getStoragePath() { 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/main/java/org/hyperledger/besu/services/BlockchainServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/BlockchainServiceImpl.java index a3b37a6665a..aa1c6a2128b 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/BlockchainServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/BlockchainServiceImpl.java @@ -15,8 +15,13 @@ package org.hyperledger.besu.services; -import org.hyperledger.besu.ethereum.chain.Blockchain; +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockBody; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket; +import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket; import org.hyperledger.besu.plugin.Unstable; import org.hyperledger.besu.plugin.data.BlockContext; import org.hyperledger.besu.plugin.data.BlockHeader; @@ -29,15 +34,21 @@ @Unstable public class BlockchainServiceImpl implements BlockchainService { - private final Blockchain blockchain; + private ProtocolContext protocolContext; + private ProtocolSchedule protocolSchedule; + + /** Create a new instance */ + public BlockchainServiceImpl() {} /** * Instantiates a new Blockchain service. * - * @param blockchain the blockchain + * @param protocolContext the protocol context + * @param protocolSchedule the protocol schedule */ - public BlockchainServiceImpl(final Blockchain blockchain) { - this.blockchain = blockchain; + public void init(final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule) { + this.protocolContext = protocolContext; + this.protocolSchedule = protocolSchedule; } /** @@ -48,11 +59,39 @@ public BlockchainServiceImpl(final Blockchain blockchain) { */ @Override public Optional getBlockByNumber(final long number) { - return blockchain + return protocolContext + .getBlockchain() .getBlockByNumber(number) .map(block -> blockContext(block::getHeader, block::getBody)); } + @Override + public Hash getChainHeadHash() { + return protocolContext.getBlockchain().getChainHeadHash(); + } + + @Override + public BlockHeader getChainHeadHeader() { + return protocolContext.getBlockchain().getChainHeadHeader(); + } + + @Override + public Optional getNextBlockBaseFee() { + final var chainHeadHeader = protocolContext.getBlockchain().getChainHeadHeader(); + final var protocolSpec = + protocolSchedule.getForNextBlockHeader(chainHeadHeader, System.currentTimeMillis()); + return Optional.of(protocolSpec.getFeeMarket()) + .filter(FeeMarket::implementsBaseFee) + .map(BaseFeeMarket.class::cast) + .map( + feeMarket -> + feeMarket.computeBaseFee( + chainHeadHeader.getNumber() + 1, + chainHeadHeader.getBaseFee().orElse(Wei.ZERO), + chainHeadHeader.getGasUsed(), + feeMarket.targetGasUsed(chainHeadHeader))); + } + private static BlockContext blockContext( final Supplier blockHeaderSupplier, final Supplier blockBodySupplier) { diff --git a/besu/src/main/java/org/hyperledger/besu/services/TransactionSimulationServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/TransactionSimulationServiceImpl.java new file mode 100644 index 00000000000..cf652fb5417 --- /dev/null +++ b/besu/src/main/java/org/hyperledger/besu/services/TransactionSimulationServiceImpl.java @@ -0,0 +1,73 @@ +/* + * Copyright Hyperledger Besu Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.services; + +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.ethereum.chain.Blockchain; +import org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams; +import org.hyperledger.besu.ethereum.transaction.CallParameter; +import org.hyperledger.besu.ethereum.transaction.TransactionSimulator; +import org.hyperledger.besu.evm.tracing.OperationTracer; +import org.hyperledger.besu.plugin.Unstable; +import org.hyperledger.besu.plugin.data.TransactionSimulationResult; +import org.hyperledger.besu.plugin.services.TransactionSimulationService; + +import java.util.Optional; + +/** TransactionSimulationServiceImpl */ +@Unstable +public class TransactionSimulationServiceImpl implements TransactionSimulationService { + private Blockchain blockchain; + private TransactionSimulator transactionSimulator; + + /** Create an instance to be configured */ + public TransactionSimulationServiceImpl() {} + + /** + * Configure the plugin + * + * @param blockchain the blockchain + * @param transactionSimulator transaction simulator + */ + public void init(final Blockchain blockchain, final TransactionSimulator transactionSimulator) { + this.blockchain = blockchain; + this.transactionSimulator = transactionSimulator; + } + + @Override + public Optional simulate( + final Transaction transaction, final Hash blockHash, final OperationTracer operationTracer) { + + final CallParameter callParameter = CallParameter.fromTransaction(transaction); + + final var blockHeader = + blockchain + .getBlockHeader(blockHash) + .or(() -> blockchain.getBlockHeaderSafe(blockHash)) + .orElseThrow( + () -> + new IllegalStateException( + "Block header not yet present for chain head hash: " + blockHash)); + + return transactionSimulator + .process( + callParameter, + TransactionValidationParams.transactionSimulator(), + operationTracer, + blockHeader) + .map(res -> new TransactionSimulationResult(transaction, res.result())); + } +} diff --git a/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java b/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java index 038dcdedd1f..2f5e9653b9a 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.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 void flexibleEnabledPrivacy() throws IOException, URISyntaxException { 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_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 @@ private BesuController setUpControllerWithPrivacyEnabled(final boolean flexibleE .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 @@ private BesuController setUpControllerWithPrivacyEnabled(final boolean flexibleE } 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 @@ private PrivacyStorageProvider createKeyValueStorageProvider( 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 c9e16baeecc..e9446537e25 100644 --- a/besu/src/test/java/org/hyperledger/besu/RunnerTest.java +++ b/besu/src/test/java/org/hyperledger/besu/RunnerTest.java @@ -57,6 +57,7 @@ import org.hyperledger.besu.ethereum.storage.StorageProvider; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProviderBuilder; +import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.ObservableMetricsSystem; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -168,7 +169,8 @@ private void syncFromGenesis(final SyncMode mode, final GenesisConfigFile genesi final SynchronizerConfiguration syncConfigAhead = SynchronizerConfiguration.builder().syncMode(SyncMode.FULL).build(); final ObservableMetricsSystem noOpMetricsSystem = new NoOpMetricsSystem(); - + final var miningParameters = MiningParameters.newDefault(); + final var dataStorageConfiguration = DataStorageConfiguration.DEFAULT_CONFIG; // Setup Runner with blocks final BesuController controllerAhead = getController( @@ -176,8 +178,10 @@ private void syncFromGenesis(final SyncMode mode, final GenesisConfigFile genesi syncConfigAhead, dataDirAhead, aheadDbNodeKey, - createKeyValueStorageProvider(dataDirAhead, dbAhead), - noOpMetricsSystem); + createKeyValueStorageProvider( + dataDirAhead, dbAhead, dataStorageConfiguration, miningParameters), + noOpMetricsSystem, + miningParameters); setupState( blockCount, controllerAhead.getProtocolSchedule(), controllerAhead.getProtocolContext()); @@ -232,7 +236,8 @@ private void syncFromGenesis(final SyncMode mode, final GenesisConfigFile genesi dataDirBehind, behindDbNodeKey, new InMemoryKeyValueStorageProvider(), - noOpMetricsSystem); + noOpMetricsSystem, + miningParameters); final EnodeURL aheadEnode = runnerAhead.getLocalEnode().get(); final EthNetworkConfig behindEthNetworkConfiguration = @@ -375,7 +380,13 @@ private GenesisConfigFile getFastSyncGenesis() { 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( @@ -387,7 +398,7 @@ private StorageProvider createKeyValueStorageProvider(final Path dataDir, final DEFAULT_IS_HIGH_SPEC), Arrays.asList(KeyValueSegmentIdentifier.values()), RocksDBMetricsFactory.PUBLIC_ROCKS_DB_METRICS)) - .withCommonConfiguration(new BesuConfigurationImpl(dataDir, dbDir)) + .withCommonConfiguration(besuConfiguration) .withMetricsSystem(new NoOpMetricsSystem()) .build(); } @@ -443,14 +454,15 @@ private BesuController getController( final Path dataDir, final NodeKey nodeKey, final StorageProvider storageProvider, - final ObservableMetricsSystem metricsSystem) { + final ObservableMetricsSystem metricsSystem, + final MiningParameters miningParameters) { return new MainnetBesuControllerBuilder() .genesisConfigFile(genesisConfig) .synchronizerConfiguration(syncConfig) .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .dataDirectory(dataDir) .networkId(NETWORK_ID) - .miningParameters(MiningParameters.newDefault()) + .miningParameters(miningParameters) .nodeKey(nodeKey) .storageProvider(storageProvider) .metricsSystem(metricsSystem) diff --git a/besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java b/besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java index 4b59491dc18..4af5c8c0dde 100644 --- a/besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java +++ b/besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java @@ -41,6 +41,8 @@ import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; +import org.hyperledger.besu.services.PluginTransactionValidatorServiceImpl; +import org.hyperledger.besu.services.TransactionSelectionServiceImpl; import org.hyperledger.besu.testutil.TestClock; import java.io.IOException; @@ -457,6 +459,8 @@ protected BesuController createController(final GenesisConfigFile genesisConfigF .gasLimitCalculator(GasLimitCalculator.constant()) .evmConfiguration(EvmConfiguration.DEFAULT) .networkConfiguration(NetworkingConfiguration.create()) + .pluginTransactionValidatorService(new PluginTransactionValidatorServiceImpl()) + .transactionSelectorService(new TransactionSelectionServiceImpl()) .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 915eefcd249..7da69f5daa1 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java @@ -75,14 +75,17 @@ 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.PluginTransactionValidatorService; import org.hyperledger.besu.plugin.services.StorageService; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; 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.BlockchainServiceImpl; import org.hyperledger.besu.services.PermissioningServiceImpl; import org.hyperledger.besu.services.PluginTransactionValidatorServiceImpl; import org.hyperledger.besu.services.PrivacyPluginServiceImpl; @@ -90,6 +93,7 @@ import org.hyperledger.besu.services.SecurityModuleServiceImpl; import org.hyperledger.besu.services.StorageServiceImpl; import org.hyperledger.besu.services.TransactionSelectionServiceImpl; +import org.hyperledger.besu.services.TransactionSimulationServiceImpl; import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; import java.io.ByteArrayOutputStream; @@ -205,9 +209,11 @@ public abstract class CommandTestAbstract { @Mock protected JsonBlockImporter jsonBlockImporter; @Mock protected RlpBlockImporter rlpBlockImporter; @Mock protected StorageServiceImpl storageService; + @Mock protected TransactionSelectionServiceImpl txSelectionService; + @Mock protected PluginTransactionValidatorServiceImpl txValidatorService; @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; @@ -290,8 +296,8 @@ public void initMocks() throws Exception { when(mockControllerBuilder.maxPeers(anyInt())).thenReturn(mockControllerBuilder); when(mockControllerBuilder.maxRemotelyInitiatedPeers(anyInt())) .thenReturn(mockControllerBuilder); - when(mockControllerBuilder.transactionSelectorFactory(any())).thenReturn(mockControllerBuilder); - when(mockControllerBuilder.pluginTransactionValidatorFactory(any())) + when(mockControllerBuilder.transactionSelectorService(any())).thenReturn(mockControllerBuilder); + when(mockControllerBuilder.pluginTransactionValidatorService(any())) .thenReturn(mockControllerBuilder); when(mockControllerBuilder.besuComponent(any(BesuComponent.class))) .thenReturn(mockControllerBuilder); @@ -377,6 +383,12 @@ public void initMocks() throws Exception { lenient() .when(mockBesuPluginContext.getService(StorageService.class)) .thenReturn(Optional.of(storageService)); + lenient() + .when(mockBesuPluginContext.getService(TransactionSelectionService.class)) + .thenReturn(Optional.of(txSelectionService)); + lenient() + .when(mockBesuPluginContext.getService(PluginTransactionValidatorService.class)) + .thenReturn(Optional.of(txValidatorService)); lenient() .doReturn(mockPkiBlockCreationConfiguration) @@ -564,7 +576,9 @@ public static class TestBesuCommand extends BesuCommand { pkiBlockCreationConfigProvider, rpcEndpointServiceImpl, new TransactionSelectionServiceImpl(), - new PluginTransactionValidatorServiceImpl()); + new PluginTransactionValidatorServiceImpl(), + new TransactionSimulationServiceImpl(), + new BlockchainServiceImpl()); } @Override diff --git a/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java b/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java index 93cf830faf1..2f1b18eab13 100644 --- a/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java +++ b/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java @@ -130,6 +130,9 @@ public void setUp() { when(mockEthContext.getScheduler()).thenReturn(new DeterministicEthScheduler()); lenient().when(mockEthPeers.streamAvailablePeers()).thenAnswer(z -> Stream.empty()); when(mockProtocolContext.getBlockchain()).thenReturn(blockchain); + lenient() + .when(mockProtocolContext.getTransactionSelectionService()) + .thenReturn(new TransactionSelectionServiceImpl()); lenient().when(mockProtocolContext.getWorldStateArchive()).thenReturn(mockWorldStateArchive); lenient().when(mockProtocolSchedule.getByBlockHeader(any())).thenReturn(mockProtocolSpec); lenient() @@ -163,7 +166,7 @@ public void setUp() { new NoOpMetricsSystem(), syncState, txPoolConfig, - null, + new PluginTransactionValidatorServiceImpl(), new BlobCache()); serviceImpl = new BesuEventsImpl(blockchain, blockBroadcaster, transactionPool, syncState); diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculatorTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculatorTest.java index 6f9c5c53e0e..f7d10174d42 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculatorTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculatorTest.java @@ -28,10 +28,10 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Util; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; import java.math.BigInteger; import java.util.List; -import java.util.Optional; import com.google.common.collect.Lists; import org.junit.jupiter.api.BeforeEach; @@ -58,7 +58,8 @@ public void setup() { when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); - cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext, Optional.empty()); + cliqueProtocolContext = + new ProtocolContext(null, null, cliqueContext, mock(TransactionSelectionService.class)); blockHeaderBuilder = new BlockHeaderTestFixture(); } diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/NodeCanProduceNextBlockTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/NodeCanProduceNextBlockTest.java index 486c1840fc9..6a22ad152fa 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/NodeCanProduceNextBlockTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/NodeCanProduceNextBlockTest.java @@ -35,9 +35,9 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Util; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; import java.util.List; -import java.util.Optional; import com.google.common.collect.Lists; import org.junit.jupiter.api.BeforeEach; @@ -80,7 +80,9 @@ public void networkWithOneValidatorIsAllowedToCreateConsecutiveBlocks() { final ValidatorProvider validatorProvider = mock(ValidatorProvider.class); when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); - cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext, Optional.empty()); + cliqueProtocolContext = + new ProtocolContext( + blockChain, null, cliqueContext, mock(TransactionSelectionService.class)); headerBuilder.number(1).parentHash(genesisBlock.getHash()); final Block block_1 = createEmptyBlock(proposerKeyPair); @@ -104,7 +106,9 @@ public void networkWithTwoValidatorsIsAllowedToProduceBlockIfNotPreviousBlockPro final ValidatorProvider validatorProvider = mock(ValidatorProvider.class); when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); - cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext, Optional.empty()); + cliqueProtocolContext = + new ProtocolContext( + blockChain, null, cliqueContext, mock(TransactionSelectionService.class)); headerBuilder.number(1).parentHash(genesisBlock.getHash()); final Block block_1 = createEmptyBlock(proposerKeyPair); @@ -137,7 +141,9 @@ public void networkWithTwoValidatorsIsNotAllowedToProduceBlockIfIsPreviousBlockP final ValidatorProvider validatorProvider = mock(ValidatorProvider.class); when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); - cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext, Optional.empty()); + cliqueProtocolContext = + new ProtocolContext( + blockChain, null, cliqueContext, mock(TransactionSelectionService.class)); headerBuilder.parentHash(genesisBlock.getHash()).number(1); final Block block_1 = createEmptyBlock(proposerKeyPair); @@ -166,7 +172,9 @@ public void withThreeValidatorsMustHaveOneBlockBetweenSignings() { final ValidatorProvider validatorProvider = mock(ValidatorProvider.class); when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); - cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext, Optional.empty()); + cliqueProtocolContext = + new ProtocolContext( + blockChain, null, cliqueContext, mock(TransactionSelectionService.class)); headerBuilder.parentHash(genesisBlock.getHash()).number(1); final Block block_1 = createEmptyBlock(proposerKeyPair); @@ -210,7 +218,9 @@ public void signerIsValidIfInsufficientBlocksExistInHistory() { final ValidatorProvider validatorProvider = mock(ValidatorProvider.class); when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); - cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext, Optional.empty()); + cliqueProtocolContext = + new ProtocolContext( + blockChain, null, cliqueContext, mock(TransactionSelectionService.class)); headerBuilder.parentHash(genesisBlock.getHash()).number(1); final Block block_1 = createEmptyBlock(otherNodeKeyPair); @@ -238,7 +248,9 @@ public void exceptionIsThrownIfOnAnOrphanedChain() { final ValidatorProvider validatorProvider = mock(ValidatorProvider.class); when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); - cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext, Optional.empty()); + cliqueProtocolContext = + new ProtocolContext( + blockChain, null, cliqueContext, mock(TransactionSelectionService.class)); headerBuilder.parentHash(Hash.ZERO).number(3); final BlockHeader parentHeader = @@ -261,7 +273,9 @@ public void nonValidatorIsNotAllowedToCreateABlock() { final ValidatorProvider validatorProvider = mock(ValidatorProvider.class); when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); - cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext, Optional.empty()); + cliqueProtocolContext = + new ProtocolContext( + blockChain, null, cliqueContext, mock(TransactionSelectionService.class)); headerBuilder.parentHash(Hash.ZERO).number(3); final BlockHeader parentHeader = headerBuilder.buildHeader(); diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java index 645a1ca9482..aca69e94d99 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java @@ -64,6 +64,8 @@ import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; +import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory; import org.hyperledger.besu.testutil.DeterministicEthScheduler; import org.hyperledger.besu.testutil.TestClock; @@ -117,7 +119,20 @@ public void setup() { GenesisState.fromConfig(GenesisConfigFile.mainnet(), protocolSchedule).getBlock(); blockchain = createInMemoryBlockchain(genesis); protocolContext = - new ProtocolContext(blockchain, stateArchive, cliqueContext, Optional.empty()); + new ProtocolContext( + blockchain, + stateArchive, + cliqueContext, + new TransactionSelectionService() { + @Override + public Optional get() { + return Optional.empty(); + } + + @Override + public void registerTransactionSelectorFactory( + final PluginTransactionSelectorFactory transactionSelectorFactory) {} + }); epochManager = new EpochManager(10); // Add a block above the genesis diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockMinerTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockMinerTest.java index ed1cfced5e3..03e56127b9d 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockMinerTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockMinerTest.java @@ -45,6 +45,7 @@ import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; import org.hyperledger.besu.util.Subscribers; import java.math.BigInteger; @@ -70,7 +71,7 @@ void doesNotMineBlockIfNoTransactionsWhenEmptyBlocksNotAllowed() throws Interrup final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, null); final ProtocolContext protocolContext = - new ProtocolContext(null, null, cliqueContext, Optional.empty()); + new ProtocolContext(null, null, cliqueContext, mock(TransactionSelectionService.class)); final CliqueBlockCreator blockCreator = mock(CliqueBlockCreator.class); final Function blockCreatorSupplier = @@ -125,7 +126,7 @@ void minesBlockIfHasTransactionsWhenEmptyBlocksNotAllowed() throws InterruptedEx final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, null); final ProtocolContext protocolContext = - new ProtocolContext(null, null, cliqueContext, Optional.empty()); + new ProtocolContext(null, null, cliqueContext, mock(TransactionSelectionService.class)); final CliqueBlockCreator blockCreator = mock(CliqueBlockCreator.class); final Function blockCreatorSupplier = diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java index 090d2b52c5a..cb341d4df39 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java @@ -52,6 +52,7 @@ import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; import org.hyperledger.besu.testutil.DeterministicEthScheduler; import org.hyperledger.besu.testutil.TestClock; @@ -94,7 +95,8 @@ public void setup() { when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); - cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext, Optional.empty()); + cliqueProtocolContext = + new ProtocolContext(null, null, cliqueContext, mock(TransactionSelectionService.class)); cliqueProtocolSchedule = CliqueProtocolSchedule.create( GENESIS_CONFIG_OPTIONS, proposerNodeKey, false, EvmConfiguration.DEFAULT); diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java index 7f7daf4eeab..996295d3357 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java @@ -32,9 +32,9 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Util; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; import java.util.List; -import java.util.Optional; import com.google.common.collect.Lists; import org.junit.jupiter.api.BeforeEach; @@ -58,7 +58,8 @@ public void setup() { when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); - cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext, Optional.empty()); + cliqueProtocolContext = + new ProtocolContext(null, null, cliqueContext, mock(TransactionSelectionService.class)); blockHeaderBuilder = new BlockHeaderTestFixture(); } diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueExtraDataValidationRuleTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueExtraDataValidationRuleTest.java index 72043c9cb9a..7d2dc560d89 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueExtraDataValidationRuleTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueExtraDataValidationRuleTest.java @@ -33,9 +33,9 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Util; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; import java.util.List; -import java.util.Optional; import com.google.common.collect.Lists; import org.apache.tuweni.bytes.Bytes; @@ -62,7 +62,8 @@ public void setup() { when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); - cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext, Optional.empty()); + cliqueProtocolContext = + new ProtocolContext(null, null, cliqueContext, mock(TransactionSelectionService.class)); } @Test diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingProtocolContext.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingProtocolContext.java index 32099e23fdf..f532aee6ae7 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingProtocolContext.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingProtocolContext.java @@ -20,9 +20,7 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; -import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory; - -import java.util.Optional; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; /** The Migrating protocol context. */ public class MigratingProtocolContext extends ProtocolContext { @@ -35,14 +33,14 @@ public class MigratingProtocolContext extends ProtocolContext { * @param blockchain the blockchain * @param worldStateArchive the world state archive * @param consensusContextSchedule the consensus context schedule - * @param transactionSelectorFactory the optional transaction selector factory + * @param transactionSelectorService the optional transaction selector service */ public MigratingProtocolContext( final MutableBlockchain blockchain, final WorldStateArchive worldStateArchive, final ForksSchedule consensusContextSchedule, - final Optional transactionSelectorFactory) { - super(blockchain, worldStateArchive, null, transactionSelectorFactory); + final TransactionSelectionService transactionSelectorService) { + super(blockchain, worldStateArchive, null, transactionSelectorService); this.consensusContextSchedule = consensusContextSchedule; } @@ -53,7 +51,7 @@ public MigratingProtocolContext( * @param worldStateArchive the world state archive * @param protocolSchedule the protocol schedule * @param consensusContextFactory the consensus context factory - * @param transactionSelectorFactory the optional transaction selector factory + * @param transactionSelectorService the optional transaction selector service * @return the protocol context */ public static ProtocolContext init( @@ -61,7 +59,7 @@ public static ProtocolContext init( final WorldStateArchive worldStateArchive, final ProtocolSchedule protocolSchedule, final ConsensusContextFactory consensusContextFactory, - final Optional transactionSelectorFactory) { + final TransactionSelectionService transactionSelectorService) { final ConsensusContext consensusContext = consensusContextFactory.create(blockchain, worldStateArchive, protocolSchedule); final MigratingContext migratingContext = consensusContext.as(MigratingContext.class); @@ -69,7 +67,7 @@ public static ProtocolContext init( blockchain, worldStateArchive, migratingContext.getConsensusContextSchedule(), - transactionSelectorFactory); + transactionSelectorService); } @Override diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java index c675219c352..b8566e2d683 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java @@ -23,7 +23,6 @@ import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import java.util.List; -import java.util.Optional; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -44,8 +43,7 @@ public void returnsContextForSpecificChainHeight() { final ForksSchedule contextSchedule = new ForksSchedule<>(List.of(new ForkSpec<>(0L, context1), new ForkSpec<>(10L, context2))); final MigratingProtocolContext migratingProtocolContext = - new MigratingProtocolContext( - blockchain, worldStateArchive, contextSchedule, Optional.empty()); + new MigratingProtocolContext(blockchain, worldStateArchive, contextSchedule, null); assertThat(migratingProtocolContext.getConsensusContext(ConsensusContext.class)) .isSameAs(context1); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java index e8d7ee79e98..275c2f56bd5 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java @@ -16,6 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.consensus.common.bft.BftContextBuilder.setupContextWithValidators; +import static org.mockito.Mockito.mock; import org.hyperledger.besu.cryptoservices.NodeKey; import org.hyperledger.besu.cryptoservices.NodeKeyUtils; @@ -25,9 +26,9 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Util; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; import java.util.List; -import java.util.Optional; import com.google.common.collect.Lists; import org.junit.jupiter.api.Test; @@ -51,7 +52,11 @@ public void proposerInValidatorListPassesValidation() { final List
validators = Lists.newArrayList(proposerAddress); final ProtocolContext context = - new ProtocolContext(null, null, setupContextWithValidators(validators), Optional.empty()); + new ProtocolContext( + null, + null, + setupContextWithValidators(validators), + mock(TransactionSelectionService.class)); final BftCoinbaseValidationRule coinbaseValidationRule = new BftCoinbaseValidationRule(); @@ -71,7 +76,11 @@ public void proposerNotInValidatorListFailsValidation() { final List
validators = Lists.newArrayList(otherValidatorNodeAddress); final ProtocolContext context = - new ProtocolContext(null, null, setupContextWithValidators(validators), Optional.empty()); + new ProtocolContext( + null, + null, + setupContextWithValidators(validators), + mock(TransactionSelectionService.class)); final BftCoinbaseValidationRule coinbaseValidationRule = new BftCoinbaseValidationRule(); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java index facc4ee2e3a..7256511c285 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java @@ -30,10 +30,10 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Util; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; import java.util.Collections; import java.util.List; -import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -58,7 +58,8 @@ public void correctlyConstructedHeaderPassesValidation() { .collect(Collectors.toList()); final BftContext bftContext = setupContextWithValidators(committerAddresses); - final ProtocolContext context = new ProtocolContext(null, null, bftContext, Optional.empty()); + final ProtocolContext context = + new ProtocolContext(null, null, bftContext, mock(TransactionSelectionService.class)); when(bftContext.getBlockInterface().getCommitters(any())).thenReturn(committerAddresses); assertThat(commitSealsValidationRule.validate(blockHeader, null, context)).isTrue(); @@ -72,7 +73,8 @@ public void insufficientCommitSealsFailsValidation() { final List
validators = singletonList(committerAddress); final BftContext bftContext = setupContextWithValidators(validators); - final ProtocolContext context = new ProtocolContext(null, null, bftContext, Optional.empty()); + final ProtocolContext context = + new ProtocolContext(null, null, bftContext, mock(TransactionSelectionService.class)); when(bftContext.getBlockInterface().getCommitters(any())).thenReturn(emptyList()); assertThat(commitSealsValidationRule.validate(blockHeader, null, context)).isFalse(); @@ -89,7 +91,8 @@ public void committerNotInValidatorListFailsValidation() { final NodeKey nonValidatorNodeKey = NodeKeyUtils.generate(); final BftContext bftContext = setupContextWithValidators(validators); - final ProtocolContext context = new ProtocolContext(null, null, bftContext, Optional.empty()); + final ProtocolContext context = + new ProtocolContext(null, null, bftContext, mock(TransactionSelectionService.class)); when(bftContext.getBlockInterface().getCommitters(any())) .thenReturn(singletonList(Util.publicKeyToAddress(nonValidatorNodeKey.getPublicKey()))); @@ -136,7 +139,8 @@ public void headerContainsDuplicateSealsFailsValidation() { final List
validators = singletonList(committerAddress); final BftContext bftContext = setupContextWithValidators(validators); - final ProtocolContext context = new ProtocolContext(null, null, bftContext, Optional.empty()); + final ProtocolContext context = + new ProtocolContext(null, null, bftContext, mock(TransactionSelectionService.class)); when(bftContext.getBlockInterface().getCommitters(any())) .thenReturn(List.of(committerAddress, committerAddress)); @@ -155,7 +159,8 @@ private boolean subExecution(final int validatorCount, final int committerCount) Collections.sort(validators); final BftContext bftContext = setupContextWithValidators(validators); - final ProtocolContext context = new ProtocolContext(null, null, bftContext, Optional.empty()); + final ProtocolContext context = + new ProtocolContext(null, null, bftContext, mock(TransactionSelectionService.class)); when(bftContext.getBlockInterface().getCommitters(any())) .thenReturn(validators.subList(0, committerCount)); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java index 690dc26f155..2c8286614d0 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java @@ -26,7 +26,6 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import java.util.List; -import java.util.Optional; import com.google.common.collect.Lists; import org.junit.jupiter.api.Test; @@ -46,7 +45,7 @@ public void correctlyConstructedHeaderPassesValidation() { final ProtocolContext context = new ProtocolContext( - null, null, setupContextWithBftExtraData(validators, bftExtraData), Optional.empty()); + null, null, setupContextWithBftExtraData(validators, bftExtraData), null); when(bftExtraData.getValidators()).thenReturn(validators); assertThat(validatorsValidationRule.validate(blockHeader, null, context)).isTrue(); @@ -61,7 +60,7 @@ public void validatorsInNonAscendingOrderFailValidation() { final ProtocolContext context = new ProtocolContext( - null, null, setupContextWithBftExtraData(validators, bftExtraData), Optional.empty()); + null, null, setupContextWithBftExtraData(validators, bftExtraData), null); when(bftExtraData.getValidators()).thenReturn(Lists.reverse(validators)); assertThat(validatorsValidationRule.validate(blockHeader, null, context)).isFalse(); @@ -79,10 +78,7 @@ public void mismatchingReportedValidatorsVsLocallyStoredListFailsValidation() { final ProtocolContext context = new ProtocolContext( - null, - null, - setupContextWithBftExtraData(storedValidators, bftExtraData), - Optional.empty()); + null, null, setupContextWithBftExtraData(storedValidators, bftExtraData), null); when(bftExtraData.getValidators()).thenReturn(Lists.reverse(reportedValidators)); assertThat(validatorsValidationRule.validate(blockHeader, null, context)).isFalse(); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java index 5b9252df567..84f704aacb2 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java @@ -23,8 +23,7 @@ import org.hyperledger.besu.consensus.common.bft.BftExtraData; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockHeader; - -import java.util.Optional; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Test; @@ -47,7 +46,10 @@ public boolean headerWithVanityDataOfSize(final int extraDataSize) { final ProtocolContext context = new ProtocolContext( - null, null, setupContextWithBftExtraData(emptyList(), extraData), Optional.empty()); + null, + null, + setupContextWithBftExtraData(emptyList(), extraData), + mock(TransactionSelectionService.class)); return validationRule.validate(blockHeader, null, context); } } diff --git a/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java b/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java index ce06496d547..0da87d3de6c 100644 --- a/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java +++ b/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java @@ -344,7 +344,7 @@ private static ControllerAndState createControllerAndFinalState( blockChain, worldStateArchive, new BftContext(validatorProvider, epochManager, blockInterface), - Optional.empty()); + null); final TransactionPoolConfiguration poolConf = ImmutableTransactionPoolConfiguration.builder().txPoolMaxSize(1).build(); diff --git a/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/tests/round/IbftRoundIntegrationTest.java b/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/tests/round/IbftRoundIntegrationTest.java index 8bc3cd7e02d..fd9c1d2ca58 100644 --- a/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/tests/round/IbftRoundIntegrationTest.java +++ b/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/tests/round/IbftRoundIntegrationTest.java @@ -126,7 +126,7 @@ public void setup() { blockChain, worldStateArchive, setupContextWithBftExtraDataEncoder(emptyList(), bftExtraDataEncoder), - Optional.empty()); + null); } @Test diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftBlockHeaderValidationRulesetFactoryTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftBlockHeaderValidationRulesetFactoryTest.java index e02ad9236c8..87c8ba68021 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftBlockHeaderValidationRulesetFactoryTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftBlockHeaderValidationRulesetFactoryTest.java @@ -51,7 +51,7 @@ private ProtocolContext protocolContext(final Collection
validators) { null, null, setupContextWithBftExtraDataEncoder(validators, new IbftExtraDataCodec()), - Optional.empty()); + null); } @Test diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java index 472dccbd5e5..98041810271 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java @@ -47,7 +47,6 @@ import java.math.BigInteger; import java.util.Collection; import java.util.List; -import java.util.Optional; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -121,6 +120,6 @@ private ProtocolContext protocolContext(final Collection
validators) { null, null, setupContextWithBftExtraDataEncoder(BftContext.class, validators, bftExtraDataCodec), - Optional.empty()); + null); } } diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/blockcreation/BftBlockCreatorTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/blockcreation/BftBlockCreatorTest.java index 3e884139f50..5b1a437ccf2 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/blockcreation/BftBlockCreatorTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/blockcreation/BftBlockCreatorTest.java @@ -59,6 +59,8 @@ import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; +import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory; import org.hyperledger.besu.testutil.DeterministicEthScheduler; import org.hyperledger.besu.testutil.TestClock; @@ -124,7 +126,16 @@ public BlockHeaderValidator.Builder createBlockHeaderRuleset( blockchain, createInMemoryWorldStateArchive(), setupContextWithBftExtraDataEncoder(initialValidatorList, bftExtraDataEncoder), - Optional.empty()); + new TransactionSelectionService() { + @Override + public Optional get() { + return Optional.empty(); + } + + @Override + public void registerTransactionSelectorFactory( + final PluginTransactionSelectorFactory transactionSelectorFactory) {} + }); final TransactionPoolConfiguration poolConf = ImmutableTransactionPoolConfiguration.builder().txPoolMaxSize(1).build(); diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java index e0d9f90c10f..0eb381496ef 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java @@ -76,6 +76,7 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecAdapters; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; import org.hyperledger.besu.evm.internal.EvmConfiguration; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; import org.hyperledger.besu.util.Subscribers; import java.math.BigInteger; @@ -168,7 +169,10 @@ public void setup() { protocolContext = new ProtocolContext( - blockchain, null, setupContextWithValidators(validators), Optional.empty()); + blockchain, + null, + setupContextWithValidators(validators), + mock(TransactionSelectionService.class)); final ProtocolScheduleBuilder protocolScheduleBuilder = new ProtocolScheduleBuilder( diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftRoundTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftRoundTest.java index 39f774c57d8..d4dfa3aeadc 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftRoundTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftRoundTest.java @@ -112,7 +112,7 @@ public void setup() { blockChain, worldStateArchive, setupContextWithBftExtraDataEncoder(emptyList(), new IbftExtraDataCodec()), - Optional.empty()); + null); lenient().when(messageValidator.validateProposal(any())).thenReturn(true); lenient().when(messageValidator.validatePrepare(any())).thenReturn(true); diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/validation/MessageValidatorTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/validation/MessageValidatorTest.java index b13df3439dd..9e99684f4cf 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/validation/MessageValidatorTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/validation/MessageValidatorTest.java @@ -101,10 +101,7 @@ public void setup() { protocolContext = new ProtocolContext( - mock(MutableBlockchain.class), - mock(WorldStateArchive.class), - mockBftCtx, - Optional.empty()); + mock(MutableBlockchain.class), mock(WorldStateArchive.class), mockBftCtx, null); lenient() .when(protocolSchedule.getByBlockNumberOrTimestamp(anyLong(), anyLong())) diff --git a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java index 16a147c70e5..c4e0926f87a 100644 --- a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java +++ b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java @@ -77,6 +77,8 @@ import org.hyperledger.besu.ethereum.trie.MerkleTrieException; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.metrics.StubMetricsSystem; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; +import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory; import org.hyperledger.besu.testutil.TestClock; import org.hyperledger.besu.util.number.Fraction; @@ -201,7 +203,20 @@ public void setUp() { .getByBlockHeader(any(BlockHeader.class)); protocolContext = - new ProtocolContext(blockchain, worldStateArchive, mergeContext, Optional.empty()); + new ProtocolContext( + blockchain, + worldStateArchive, + mergeContext, + new TransactionSelectionService() { + @Override + public Optional get() { + return Optional.empty(); + } + + @Override + public void registerTransactionSelectorFactory( + final PluginTransactionSelectorFactory transactionSelectorFactory) {} + }); var mutable = worldStateArchive.getMutable(); genesisState.writeStateTo(mutable); mutable.persist(null); diff --git a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeReorgTest.java b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeReorgTest.java index 1b2bd2bffd2..6dca8f47d09 100644 --- a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeReorgTest.java +++ b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeReorgTest.java @@ -43,6 +43,7 @@ import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket; import org.hyperledger.besu.ethereum.mainnet.feemarket.LondonFeeMarket; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; import org.hyperledger.besu.testutil.DeterministicEthScheduler; import org.hyperledger.besu.util.LogConfigurator; @@ -75,7 +76,8 @@ public class MergeReorgTest implements MergeGenesisConfigHelper { private final MutableBlockchain blockchain = createInMemoryBlockchain(genesisState.getBlock()); private final EthScheduler ethScheduler = new DeterministicEthScheduler(); private final ProtocolContext protocolContext = - new ProtocolContext(blockchain, worldStateArchive, mergeContext, Optional.empty()); + new ProtocolContext( + blockchain, worldStateArchive, mergeContext, mock(TransactionSelectionService.class)); private final Address coinbase = genesisAllocations(getPowGenesisConfigFile()).findFirst().get(); private final BlockHeaderTestFixture headerGenerator = new BlockHeaderTestFixture(); diff --git a/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java b/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java index 1ab82e91d14..46986dfc880 100644 --- a/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java +++ b/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java @@ -441,7 +441,7 @@ private static ControllerAndState createControllerAndFinalState( blockChain, worldStateArchive, new QbftContext(validatorProvider, epochManager, blockInterface, Optional.empty()), - Optional.empty()); + null); final TransactionPoolConfiguration poolConf = ImmutableTransactionPoolConfiguration.builder().txPoolMaxSize(1).build(); diff --git a/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/test/round/QbftRoundIntegrationTest.java b/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/test/round/QbftRoundIntegrationTest.java index 21e7e070974..f89fef55c30 100644 --- a/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/test/round/QbftRoundIntegrationTest.java +++ b/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/test/round/QbftRoundIntegrationTest.java @@ -57,7 +57,6 @@ import org.hyperledger.besu.util.Subscribers; import java.math.BigInteger; -import java.util.Optional; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.BeforeEach; @@ -130,7 +129,7 @@ public void setup() { worldStateArchive, setupContextWithBftExtraDataEncoder( QbftContext.class, emptyList(), qbftExtraDataEncoder), - Optional.empty()); + null); } @Test diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/validator/ValidatorContractController.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/validator/ValidatorContractController.java index a7b705e4a9d..e6786a92ef1 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/validator/ValidatorContractController.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/validator/ValidatorContractController.java @@ -107,7 +107,7 @@ private List decodeResult( if (result.isSuccessful()) { final List decodedList = FunctionReturnDecoder.decode( - result.getResult().getOutput().toHexString(), function.getOutputParameters()); + result.result().getOutput().toHexString(), function.getOutputParameters()); if (decodedList.isEmpty()) { throw new IllegalStateException( diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftBlockHeaderValidationRulesetFactoryTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftBlockHeaderValidationRulesetFactoryTest.java index 641e23db6fa..55a9b9fe442 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftBlockHeaderValidationRulesetFactoryTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftBlockHeaderValidationRulesetFactoryTest.java @@ -46,7 +46,7 @@ private ProtocolContext protocolContext(final Collection
validators) { null, setupContextWithBftExtraDataEncoder( QbftContext.class, validators, new QbftExtraDataCodec()), - Optional.empty()); + null); } @Test diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleTest.java index 31114a9889d..871551e37f3 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleTest.java @@ -58,7 +58,7 @@ private ProtocolContext protocolContext(final Collection
validators) { null, setupContextWithBftExtraDataEncoder( QbftContext.class, validators, new QbftExtraDataCodec()), - Optional.empty()); + null); } @Test diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/headervalidationrules/QbftValidatorsValidationRuleTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/headervalidationrules/QbftValidatorsValidationRuleTest.java index b006ccd3be0..2030f961386 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/headervalidationrules/QbftValidatorsValidationRuleTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/headervalidationrules/QbftValidatorsValidationRuleTest.java @@ -47,7 +47,7 @@ public void validationPassesIfValidatorsAndVoteAreEmpty() { null, null, setupContextWithBftExtraData(QbftContext.class, Collections.emptyList(), bftExtraData), - Optional.empty()); + null); when(bftExtraData.getValidators()).thenReturn(Collections.emptyList()); when(bftExtraData.getVote()).thenReturn(Optional.empty()); assertThat(qbftValidatorsValidationRule.validate(blockHeader, null, context)).isTrue(); @@ -66,7 +66,7 @@ public void validationIsDelegatedWhenConstructorFlagIsFalse() { null, null, setupContextWithBftExtraData(QbftContext.class, validators, bftExtraData), - Optional.empty()); + null); when(bftExtraData.getValidators()).thenReturn(validators); assertThat(qbftValidatorsValidationRule.validate(blockHeader, null, context)).isTrue(); } @@ -84,7 +84,7 @@ public void validationFailsIfValidatorsAreNotEmpty() { null, null, setupContextWithBftExtraData(QbftContext.class, validators, bftExtraData), - Optional.empty()); + null); when(bftExtraData.getValidators()).thenReturn(validators); assertThat(qbftValidatorsValidationRule.validate(blockHeader, null, context)).isFalse(); } @@ -98,7 +98,7 @@ public void validationFailsIfVoteIsPresent() { null, null, setupContextWithBftExtraData(QbftContext.class, Collections.emptyList(), bftExtraData), - Optional.empty()); + null); when(bftExtraData.getValidators()).thenReturn(Collections.emptyList()); when(bftExtraData.getVote()).thenReturn(Optional.of(mock(Vote.class))); assertThat(qbftValidatorsValidationRule.validate(blockHeader, null, context)).isFalse(); diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java index 0ec9f36ee3e..a96d8ffa2a8 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java @@ -168,7 +168,7 @@ public void setup() { null, setupContextWithBftExtraDataEncoder( QbftContext.class, validators, new QbftExtraDataCodec()), - Optional.empty()); + null); final ProtocolScheduleBuilder protocolScheduleBuilder = new ProtocolScheduleBuilder( diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftRoundTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftRoundTest.java index b17895e2032..58adf57f98e 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftRoundTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftRoundTest.java @@ -122,7 +122,7 @@ public void setup() { worldStateArchive, setupContextWithBftExtraDataEncoder( QbftContext.class, emptyList(), new QbftExtraDataCodec()), - Optional.empty()); + null); when(messageValidator.validateProposal(any())).thenReturn(true); when(messageValidator.validatePrepare(any())).thenReturn(true); diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidatorTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidatorTest.java index fb8b67393d6..9468b3ef10a 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidatorTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidatorTest.java @@ -18,6 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.consensus.common.bft.BftContextBuilder.setupContextWithBftExtraDataEncoder; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; @@ -48,6 +49,7 @@ import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.pki.cms.CmsValidator; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; import java.util.Collections; import java.util.List; @@ -87,7 +89,7 @@ public void setup() { blockChain, worldStateArchive, setupContextWithBftExtraDataEncoder(QbftContext.class, emptyList(), bftExtraDataCodec), - Optional.empty()); + null); } @Test @@ -240,7 +242,8 @@ public void validationForCmsFailsWhenCmsFailsValidation() { setupContextWithBftExtraDataEncoder(QbftContext.class, emptyList(), pkiQbftExtraDataCodec); final Bytes cms = Bytes.fromHexStringLenient("0x1"); final ProtocolContext protocolContext = - new ProtocolContext(blockChain, worldStateArchive, qbftContext, Optional.empty()); + new ProtocolContext( + blockChain, worldStateArchive, qbftContext, mock(TransactionSelectionService.class)); final ProposalPayloadValidator payloadValidator = new ProposalPayloadValidator( @@ -275,7 +278,8 @@ public void validationForCmsPassesWhenCmsIsValid() { setupContextWithBftExtraDataEncoder(QbftContext.class, emptyList(), pkiQbftExtraDataCodec); final Bytes cms = Bytes.fromHexStringLenient("0x1"); final ProtocolContext protocolContext = - new ProtocolContext(blockChain, worldStateArchive, qbftContext, Optional.empty()); + new ProtocolContext( + blockChain, worldStateArchive, qbftContext, mock(TransactionSelectionService.class)); final ProposalPayloadValidator payloadValidator = new ProposalPayloadValidator( diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalValidatorTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalValidatorTest.java index 96bb80313db..386ef1d34de 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalValidatorTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalValidatorTest.java @@ -103,7 +103,7 @@ public void setup() { worldStateArchive, setupContextWithBftExtraDataEncoder( QbftContext.class, emptyList(), bftExtraDataEncoder), - Optional.empty()); + null); // typically tests require the blockValidation to be successful when(blockValidator.validateAndProcessBlock( diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/RoundChangeMessageValidatorTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/RoundChangeMessageValidatorTest.java index b6804ad9f31..359efa00d34 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/RoundChangeMessageValidatorTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/RoundChangeMessageValidatorTest.java @@ -85,7 +85,7 @@ public void setup() { worldStateArchive, setupContextWithBftExtraDataEncoder( QbftContext.class, emptyList(), bftExtraDataEncoder), - Optional.empty()); + null); lenient().when(protocolSchedule.getByBlockHeader(any())).thenReturn(protocolSpec); diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java index f7573d266ba..88f21d255a0 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java @@ -47,6 +47,8 @@ import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; import org.hyperledger.besu.nat.NatService; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; +import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory; import java.math.BigInteger; import java.nio.file.Path; @@ -78,7 +80,21 @@ public JsonRpcTestMethodsFactory(final BlockchainImporter importer) { this.blockchain = createInMemoryBlockchain(importer.getGenesisBlock()); this.stateArchive = createInMemoryWorldStateArchive(); this.importer.getGenesisState().writeStateTo(stateArchive.getMutable()); - this.context = new ProtocolContext(blockchain, stateArchive, null, Optional.empty()); + this.context = + new ProtocolContext( + blockchain, + stateArchive, + null, + new TransactionSelectionService() { + @Override + public Optional get() { + return Optional.empty(); + } + + @Override + public void registerTransactionSelectorFactory( + PluginTransactionSelectorFactory transactionSelectorFactory) {} + }); final ProtocolSchedule protocolSchedule = importer.getProtocolSchedule(); this.synchronizer = mock(Synchronizer.class); diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByNumberLatestDesyncIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByNumberLatestDesyncIntegrationTest.java index 6d723844a2d..b68b28ca778 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByNumberLatestDesyncIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByNumberLatestDesyncIntegrationTest.java @@ -40,6 +40,8 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.plugin.data.SyncStatus; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; +import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory; import org.hyperledger.besu.testutil.BlockTestUtil; import java.util.Optional; @@ -67,7 +69,21 @@ public static void setUpOnce() throws Exception { InMemoryKeyValueStorageProvider.createInMemoryBlockchain(importer.getGenesisBlock()); WorldStateArchive state = InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive(); importer.getGenesisState().writeStateTo(state.getMutable()); - ProtocolContext context = new ProtocolContext(chain, state, null, Optional.empty()); + ProtocolContext context = + new ProtocolContext( + chain, + state, + null, + new TransactionSelectionService() { + @Override + public Optional get() { + return Optional.empty(); + } + + @Override + public void registerTransactionSelectorFactory( + PluginTransactionSelectorFactory transactionSelectorFactory) {} + }); for (final Block block : importer.getBlocks()) { final ProtocolSchedule protocolSchedule = importer.getProtocolSchedule(); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractEstimateGas.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractEstimateGas.java index b3de5094c8f..0f9b1b7be14 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractEstimateGas.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractEstimateGas.java @@ -90,7 +90,7 @@ protected long processEstimateGas( Math.pow(SUB_CALL_REMAINING_GAS_RATIO, operationTracer.getMaxDepth()); // and minimum gas remaining is necessary for some operation (additionalStipend) final long gasStipend = operationTracer.getStipendNeeded(); - final long gasUsedByTransaction = result.getResult().getEstimateGasUsedByTransaction(); + final long gasUsedByTransaction = result.result().getEstimateGasUsedByTransaction(); return ((long) ((gasUsedByTransaction + gasStipend) * subCallMultiplier)); } @@ -123,7 +123,7 @@ protected JsonRpcErrorResponse errorResponse( JsonRpcErrorConverter.convertTransactionInvalidReason( validationResult.getInvalidReason())); } else { - final TransactionProcessingResult resultTrx = result.getResult(); + final TransactionProcessingResult resultTrx = result.result(); if (resultTrx != null && resultTrx.getRevertReason().isPresent()) { return errorResponse( request, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceCall.java index d133aa77524..27852a89023 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceCall.java @@ -83,7 +83,7 @@ protected PreCloseStateHandler getSimulatorResultHandler( final TransactionTrace transactionTrace = new TransactionTrace( - result.getTransaction(), result.getResult(), tracer.getTraceFrames()); + result.transaction(), result.result(), tracer.getTraceFrames()); return new DebugTraceTransactionResult(transactionTrace); }); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java index 569563ca932..698685f7457 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java @@ -117,7 +117,7 @@ private JsonRpcErrorResponse errorResponse( JsonRpcErrorConverter.convertTransactionInvalidReason( validationResult.getInvalidReason())); } else { - final TransactionProcessingResult resultTrx = result.getResult(); + final TransactionProcessingResult resultTrx = result.result(); if (resultTrx != null && resultTrx.getRevertReason().isPresent()) { return errorResponse( request, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java index 9a382d6441b..c0631bf44cb 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java @@ -85,7 +85,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { return errorResponse(requestContext, gasUsed.get()); } - var low = gasUsed.get().getResult().getEstimateGasUsedByTransaction(); + var low = gasUsed.get().result().getEstimateGasUsedByTransaction(); var lowResult = executeSimulation( blockHeader, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCall.java index 724f3f780f9..a5971681d97 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCall.java @@ -73,7 +73,7 @@ protected PreCloseStateHandler getSimulatorResultHandler( final TransactionTrace transactionTrace = new TransactionTrace( - result.getTransaction(), result.getResult(), tracer.getTraceFrames()); + result.transaction(), result.result(), tracer.getTraceFrames()); final Block block = blockchainQueriesSupplier.get().getBlockchain().getChainHeadBlock(); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java index 4ee9ff04e33..87886cc419e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java @@ -169,7 +169,7 @@ private JsonNode getSingleCallResult( final TransactionTrace transactionTrace = new TransactionTrace( - simulatorResult.getTransaction(), simulatorResult.getResult(), tracer.getTraceFrames()); + simulatorResult.transaction(), simulatorResult.result(), tracer.getTraceFrames()); final Block block = blockchainQueriesSupplier.get().getBlockchain().getChainHeadBlock(); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceRawTransaction.java index 8d1f8f6506e..2fed211bece 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceRawTransaction.java @@ -101,7 +101,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { result -> { final TransactionTrace transactionTrace = new TransactionTrace( - result.getTransaction(), result.getResult(), tracer.getTraceFrames()); + result.transaction(), result.result(), tracer.getTraceFrames()); final Optional maybeBlock = blockchainQueriesSupplier .get() diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java index 20b77eed839..f386c35c36a 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.api.graphql; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.hyperledger.besu.datatypes.TransactionType; @@ -36,6 +37,7 @@ import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason; import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat; import org.hyperledger.besu.plugin.data.SyncStatus; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; import java.nio.file.Path; import java.util.Collections; @@ -108,7 +110,10 @@ public void setupTest() throws Exception { final MutableBlockchain blockchain = blockchainSetupUtil.getBlockchain(); ProtocolContext context = new ProtocolContext( - blockchain, blockchainSetupUtil.getWorldArchive(), null, Optional.empty()); + blockchain, + blockchainSetupUtil.getWorldArchive(), + null, + mock(TransactionSelectionService.class)); final BlockchainQueries blockchainQueries = new BlockchainQueries( context.getBlockchain(), diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java index 00c5af2f94c..55eebc0acca 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java @@ -197,7 +197,7 @@ public void shouldReturnBasicExecutionRevertErrorWithoutReason() { final TransactionSimulatorResult result = mock(TransactionSimulatorResult.class); when(result.isSuccessful()).thenReturn(false); when(result.getValidationResult()).thenReturn(ValidationResult.valid()); - when(result.getResult()).thenReturn(processingResult); + when(result.result()).thenReturn(processingResult); verify(transactionSimulator).process(any(), any(), any(), mapperCaptor.capture(), any()); assertThat(mapperCaptor.getValue().apply(mock(MutableWorldState.class), Optional.of(result))) .isEqualTo(Optional.of(expectedResponse)); @@ -236,7 +236,7 @@ public void shouldReturnExecutionRevertErrorWithABIParseError() { final TransactionSimulatorResult result = mock(TransactionSimulatorResult.class); when(result.isSuccessful()).thenReturn(false); when(result.getValidationResult()).thenReturn(ValidationResult.valid()); - when(result.getResult()).thenReturn(processingResult); + when(result.result()).thenReturn(processingResult); verify(transactionSimulator).process(any(), any(), any(), mapperCaptor.capture(), any()); assertThat(mapperCaptor.getValue().apply(mock(MutableWorldState.class), Optional.of(result))) .isEqualTo(Optional.of(expectedResponse)); @@ -277,7 +277,7 @@ public void shouldReturnExecutionRevertErrorWithParsedABI() { final TransactionSimulatorResult result = mock(TransactionSimulatorResult.class); when(result.isSuccessful()).thenReturn(false); when(result.getValidationResult()).thenReturn(ValidationResult.valid()); - when(result.getResult()).thenReturn(processingResult); + when(result.result()).thenReturn(processingResult); verify(transactionSimulator).process(any(), any(), any(), mapperCaptor.capture(), any()); System.out.println(result); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCreateAccessListTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCreateAccessListTest.java index 674617b4b57..72af329661d 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCreateAccessListTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCreateAccessListTest.java @@ -300,7 +300,7 @@ private void mockTransactionSimulatorResult( when(mockResult.getEstimateGasUsedByTransaction()).thenReturn(estimateGas); when(mockResult.getRevertReason()) .thenReturn(isReverted ? Optional.of(Bytes.of(0)) : Optional.empty()); - when(mockTxSimResult.getResult()).thenReturn(mockResult); + when(mockTxSimResult.result()).thenReturn(mockResult); when(mockTxSimResult.isSuccessful()).thenReturn(isSuccessful); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java index 44b3bb9ba04..ec9831b8c1b 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java @@ -451,7 +451,7 @@ private TransactionSimulatorResult getMockTransactionSimulatorResult( when(mockResult.getEstimateGasUsedByTransaction()).thenReturn(estimateGas); when(mockResult.getRevertReason()).thenReturn(revertReason); - when(mockTxSimResult.getResult()).thenReturn(mockResult); + when(mockTxSimResult.result()).thenReturn(mockResult); when(mockTxSimResult.isSuccessful()).thenReturn(isSuccessful); return mockTxSimResult; } diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java index deac72bc5da..aa22101a71c 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java @@ -193,7 +193,8 @@ protected BlockCreationResult createBlock( final PluginTransactionSelector pluginTransactionSelector = protocolContext - .getTransactionSelectorFactory() + .getTransactionSelectionService() + .get() .map(PluginTransactionSelectorFactory::create) .orElseGet(() -> AllAcceptingTransactionSelector.INSTANCE); diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java index 953fdeb7f42..304c1f737f4 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java @@ -78,6 +78,8 @@ import org.hyperledger.besu.evm.log.Log; import org.hyperledger.besu.evm.log.LogTopic; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; +import org.hyperledger.besu.plugin.services.PluginTransactionValidatorService; +import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidatorFactory; import org.hyperledger.besu.testutil.DeterministicEthScheduler; import java.math.BigInteger; @@ -385,7 +387,16 @@ private AbstractBlockCreator createBlockCreator( ethContext, new TransactionPoolMetrics(new NoOpMetricsSystem()), poolConf, - null); + new PluginTransactionValidatorService() { + @Override + public PluginTransactionValidatorFactory get() { + return null; + } + + @Override + public void registerTransactionValidatorFactory( + final PluginTransactionValidatorFactory transactionValidatorFactory) {} + }); transactionPool.setEnabled(); final MiningParameters miningParameters = diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockMinerTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockMinerTest.java index 681991ee75c..3a0af7737d2 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockMinerTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockMinerTest.java @@ -56,7 +56,7 @@ public void blockCreatedIsAddedToBlockChain() throws InterruptedException { new Block( headerBuilder.buildHeader(), new BlockBody(Lists.newArrayList(), Lists.newArrayList())); - final ProtocolContext protocolContext = new ProtocolContext(null, null, null, Optional.empty()); + final ProtocolContext protocolContext = new ProtocolContext(null, null, null, null); final PoWBlockCreator blockCreator = mock(PoWBlockCreator.class); final Function blockCreatorSupplier = @@ -97,7 +97,7 @@ public void failureToImportDoesNotTriggerObservers() throws InterruptedException new Block( headerBuilder.buildHeader(), new BlockBody(Lists.newArrayList(), Lists.newArrayList())); - final ProtocolContext protocolContext = new ProtocolContext(null, null, null, Optional.empty()); + final ProtocolContext protocolContext = new ProtocolContext(null, null, null, null); final PoWBlockCreator blockCreator = mock(PoWBlockCreator.class); final Function blockCreatorSupplier = @@ -142,7 +142,7 @@ public void blockValidationFailureBeforeImportDoesNotImportBlock() throws Interr new Block( headerBuilder.buildHeader(), new BlockBody(Lists.newArrayList(), Lists.newArrayList())); - final ProtocolContext protocolContext = new ProtocolContext(null, null, null, Optional.empty()); + final ProtocolContext protocolContext = new ProtocolContext(null, null, null, null); final PoWBlockCreator blockCreator = mock(PoWBlockCreator.class); final Function blockCreatorSupplier = diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LegacyFeeMarketBlockTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LegacyFeeMarketBlockTransactionSelectorTest.java index fdda1b7f4d2..229526013e7 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LegacyFeeMarketBlockTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LegacyFeeMarketBlockTransactionSelectorTest.java @@ -34,6 +34,8 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder; import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecAdapters; import org.hyperledger.besu.evm.internal.EvmConfiguration; +import org.hyperledger.besu.plugin.services.PluginTransactionValidatorService; +import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidatorFactory; import org.hyperledger.besu.testutil.TestClock; import org.hyperledger.besu.util.number.Fraction; @@ -89,7 +91,16 @@ protected TransactionPool createTransactionPool() { ethContext, new TransactionPoolMetrics(metricsSystem), poolConf, - null); + new PluginTransactionValidatorService() { + @Override + public PluginTransactionValidatorFactory get() { + return null; + } + + @Override + public void registerTransactionValidatorFactory( + final PluginTransactionValidatorFactory transactionValidatorFactory) {} + }); transactionPool.setEnabled(); return transactionPool; } diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java index eb1a98cbd76..bb4c2c0b992 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java @@ -43,6 +43,8 @@ import org.hyperledger.besu.ethereum.mainnet.ValidationResult; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.plugin.data.TransactionSelectionResult; +import org.hyperledger.besu.plugin.services.PluginTransactionValidatorService; +import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidatorFactory; import org.hyperledger.besu.testutil.TestClock; import org.hyperledger.besu.util.number.Fraction; @@ -97,7 +99,16 @@ protected TransactionPool createTransactionPool() { ethContext, new TransactionPoolMetrics(metricsSystem), poolConf, - null); + new PluginTransactionValidatorService() { + @Override + public PluginTransactionValidatorFactory get() { + return null; + } + + @Override + public void registerTransactionValidatorFactory( + final PluginTransactionValidatorFactory transactionValidatorFactory) {} + }); transactionPool.setEnabled(); return transactionPool; } diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java index 3e50328dd43..62dfd771f47 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java @@ -54,6 +54,8 @@ import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem; +import org.hyperledger.besu.plugin.services.PluginTransactionValidatorService; +import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidatorFactory; import org.hyperledger.besu.testutil.TestClock; import org.hyperledger.besu.util.Subscribers; @@ -334,7 +336,16 @@ private TransactionPool createTransactionPool( ethContext, new TransactionPoolMetrics(metricsSystem), poolConf, - null); + new PluginTransactionValidatorService() { + @Override + public PluginTransactionValidatorFactory get() { + return null; + } + + @Override + public void registerTransactionValidatorFactory( + final PluginTransactionValidatorFactory transactionValidatorFactory) {} + }); transactionPool.setEnabled(); return transactionPool; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java index 745c5640689..39eb8008587 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java @@ -18,7 +18,7 @@ import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; -import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; import java.util.Optional; @@ -31,27 +31,20 @@ public class ProtocolContext { private final MutableBlockchain blockchain; private final WorldStateArchive worldStateArchive; private final ConsensusContext consensusContext; - private final Optional transactionSelectorFactory; + private final TransactionSelectionService transactionSelectionService; private Optional synchronizer; - public ProtocolContext( - final MutableBlockchain blockchain, - final WorldStateArchive worldStateArchive, - final ConsensusContext consensusContext) { - this(blockchain, worldStateArchive, consensusContext, Optional.empty()); - } - public ProtocolContext( final MutableBlockchain blockchain, final WorldStateArchive worldStateArchive, final ConsensusContext consensusContext, - final Optional transactionSelectorFactory) { + final TransactionSelectionService transactionSelectionService) { this.blockchain = blockchain; this.worldStateArchive = worldStateArchive; this.consensusContext = consensusContext; this.synchronizer = Optional.empty(); - this.transactionSelectorFactory = transactionSelectorFactory; + this.transactionSelectionService = transactionSelectionService; } public static ProtocolContext init( @@ -59,12 +52,12 @@ public static ProtocolContext init( final WorldStateArchive worldStateArchive, final ProtocolSchedule protocolSchedule, final ConsensusContextFactory consensusContextFactory, - final Optional transactionSelectorFactory) { + final TransactionSelectionService transactionSelectionService) { return new ProtocolContext( blockchain, worldStateArchive, consensusContextFactory.create(blockchain, worldStateArchive, protocolSchedule), - transactionSelectorFactory); + transactionSelectionService); } public Optional getSynchronizer() { @@ -93,7 +86,7 @@ public Optional safeConsensusContext(final Class .map(klass::cast); } - public Optional getTransactionSelectorFactory() { - return transactionSelectorFactory; + public TransactionSelectionService getTransactionSelectionService() { + return transactionSelectionService; } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/processing/TransactionProcessingResult.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/processing/TransactionProcessingResult.java index c053e1107b9..e77062a7ddd 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/processing/TransactionProcessingResult.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/processing/TransactionProcessingResult.java @@ -204,4 +204,31 @@ public ValidationResult getValidationResult() { public Optional getRevertReason() { return revertReason; } + + @Override + public Optional getInvalidReason() { + return (validationResult.isValid() + ? Optional.empty() + : Optional.of(validationResult.getErrorMessage())); + } + + @Override + public String toString() { + return "TransactionProcessingResult{" + + "status=" + + status + + ", estimateGasUsedByTransaction=" + + estimateGasUsedByTransaction + + ", gasRemaining=" + + gasRemaining + + ", logs=" + + logs + + ", output=" + + output + + ", validationResult=" + + validationResult + + ", revertReason=" + + revertReason + + '}'; + } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/CallParameter.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/CallParameter.java index 433be4673a3..4b3abbcc498 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/CallParameter.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/CallParameter.java @@ -16,8 +16,8 @@ import org.hyperledger.besu.datatypes.AccessListEntry; import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.core.Transaction; import java.util.List; import java.util.Objects; @@ -146,14 +146,38 @@ public int hashCode() { from, to, gasLimit, gasPrice, maxPriorityFeePerGas, maxFeePerGas, value, payload); } + @Override + public String toString() { + return "CallParameter{" + + "from=" + + from + + ", to=" + + to + + ", gasLimit=" + + gasLimit + + ", maxPriorityFeePerGas=" + + maxPriorityFeePerGas + + ", maxFeePerGas=" + + maxFeePerGas + + ", gasPrice=" + + gasPrice + + ", value=" + + value + + ", payloadSize=" + + (payload == null ? "null" : payload.size()) + + ", accessListSize=" + + accessList.map(List::size) + + '}'; + } + public static CallParameter fromTransaction(final Transaction tx) { return new CallParameter( tx.getSender(), - tx.getTo().orElseGet(() -> null), + tx.getTo().orElse(null), tx.getGasLimit(), - Wei.fromQuantity(tx.getGasPrice().orElseGet(() -> Wei.ZERO)), - Optional.of(Wei.fromQuantity(tx.getMaxPriorityFeePerGas().orElseGet(() -> Wei.ZERO))), - tx.getMaxFeePerGas(), + tx.getGasPrice().map(Wei::fromQuantity).orElse(Wei.ZERO), + tx.getMaxPriorityFeePerGas().map(Wei::fromQuantity), + tx.getMaxFeePerGas().map(Wei::fromQuantity), Wei.fromQuantity(tx.getValue()), tx.getPayload(), tx.getAccessList()); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java index 3b94f888179..a36262db0bc 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java @@ -106,7 +106,21 @@ public Optional process( header); } + public Optional process( + final CallParameter callParams, + final TransactionValidationParams transactionValidationParams, + final OperationTracer operationTracer, + final BlockHeader blockHeader) { + return process( + callParams, + transactionValidationParams, + operationTracer, + (mutableWorldState, transactionSimulatorResult) -> transactionSimulatorResult, + blockHeader); + } + public Optional processAtHead(final CallParameter callParams) { + final var chainHeadHash = blockchain.getChainHeadHash(); return process( callParams, ImmutableTransactionValidationParams.builder() @@ -115,7 +129,10 @@ public Optional processAtHead(final CallParameter ca .build(), OperationTracer.NO_TRACING, (mutableWorldState, transactionSimulatorResult) -> transactionSimulatorResult, - blockchain.getChainHeadHeader()); + blockchain + .getBlockHeader(chainHeadHash) + .or(() -> blockchain.getBlockHeaderSafe(chainHeadHash)) + .orElse(null)); } /** diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorResult.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorResult.java index 0627ca14fd2..853bc4611a3 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorResult.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorResult.java @@ -18,22 +18,10 @@ import org.hyperledger.besu.ethereum.mainnet.ValidationResult; import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; -import java.util.Objects; - -import com.google.common.annotations.VisibleForTesting; import org.apache.tuweni.bytes.Bytes; -public class TransactionSimulatorResult { - - private final Transaction transaction; - private final TransactionProcessingResult result; - - @VisibleForTesting - public TransactionSimulatorResult( - final Transaction transaction, final TransactionProcessingResult result) { - this.transaction = transaction; - this.result = result; - } +public record TransactionSimulatorResult( + Transaction transaction, TransactionProcessingResult result) { public boolean isSuccessful() { return result.isSuccessful(); @@ -54,40 +42,4 @@ public Bytes getOutput() { public ValidationResult getValidationResult() { return result.getValidationResult(); } - - public TransactionProcessingResult getResult() { - return result; - } - - public Transaction getTransaction() { - return transaction; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - final TransactionSimulatorResult that = (TransactionSimulatorResult) o; - return Objects.equals(transaction, that.transaction) && Objects.equals(result, that.result); - } - - @Override - public int hashCode() { - return Objects.hash(transaction, result); - } - - @Override - public String toString() { - return "TransactionSimulatorResult{" - + "transaction=" - + transaction - + ", " - + "result=" - + result - + "}"; - } } diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java index 5e43198e25e..e8c0334a5b2 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java @@ -49,7 +49,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Optional; import com.google.common.io.Resources; @@ -156,7 +155,7 @@ public C as(final Class klass) { return null; } }, - Optional.empty()); + null); } private static BlockchainSetupUtil create( diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java index bd3b77798ff..6e9708ed0c3 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java @@ -31,7 +31,9 @@ import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; import org.hyperledger.besu.plugin.services.storage.KeyValueStorage; +import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory; import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; import java.math.BigInteger; @@ -69,7 +71,21 @@ private ExecutionContextTestFixture( 0); this.stateArchive = createInMemoryWorldStateArchive(); this.protocolSchedule = protocolSchedule; - this.protocolContext = new ProtocolContext(blockchain, stateArchive, null, Optional.empty()); + this.protocolContext = + new ProtocolContext( + blockchain, + stateArchive, + null, + new TransactionSelectionService() { + @Override + public Optional get() { + return Optional.empty(); + } + + @Override + public void registerTransactionSelectorFactory( + final PluginTransactionSelectorFactory transactionSelectorFactory) {} + }); genesisState.writeStateTo(stateArchive.getMutable()); } 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 a9d36e29e21..731e2c6cdf9 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 @@ -73,9 +73,13 @@ import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.BesuConfiguration; +import org.hyperledger.besu.plugin.services.PluginTransactionValidatorService; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBKeyValueStorageFactory; import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBMetricsFactory; import org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBFactoryConfiguration; +import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory; +import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidatorFactory; import org.hyperledger.besu.testutil.DeterministicEthScheduler; import java.nio.file.Path; @@ -165,7 +169,21 @@ public void createStorage() { EvmConfiguration.DEFAULT); var ws = archive.getMutable(); genesisState.writeStateTo(ws); - protocolContext = new ProtocolContext(blockchain, archive, null, Optional.empty()); + protocolContext = + new ProtocolContext( + blockchain, + archive, + null, + new TransactionSelectionService() { + @Override + public Optional get() { + return Optional.empty(); + } + + @Override + public void registerTransactionSelectorFactory( + final PluginTransactionSelectorFactory transactionSelectorFactory) {} + }); ethContext = mock(EthContext.class, RETURNS_DEEP_STUBS); when(ethContext.getEthPeers().subscribeConnect(any())).thenReturn(1L); transactionPool = @@ -177,7 +195,16 @@ public void createStorage() { ethContext, txPoolMetrics, poolConfiguration, - null); + new PluginTransactionValidatorService() { + @Override + public PluginTransactionValidatorFactory get() { + return null; + } + + @Override + public void registerTransactionValidatorFactory( + final PluginTransactionValidatorFactory transactionValidatorFactory) {} + }); transactionPool.setEnabled(); } @@ -212,6 +239,11 @@ public Path getDataPath() { 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 71ba9b3ece0..fb7f36038a0 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.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 Optional downloadWorldState() { } 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 @@ private StorageProvider createKeyValueStorageProvider(final Path dataDir, final 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/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java index a3d164105d0..a91a21c3f56 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java @@ -42,8 +42,7 @@ import org.hyperledger.besu.ethereum.trie.MerkleTrieException; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.fluent.SimpleAccount; -import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidator; -import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidatorFactory; +import org.hyperledger.besu.plugin.services.PluginTransactionValidatorService; import org.hyperledger.besu.util.Subscribers; import java.io.BufferedReader; @@ -92,7 +91,7 @@ public class TransactionPool implements BlockAddedObserver { private static final Logger LOG = LoggerFactory.getLogger(TransactionPool.class); private static final Logger LOG_FOR_REPLAY = LoggerFactory.getLogger("LOG_FOR_REPLAY"); private final Supplier pendingTransactionsSupplier; - private final PluginTransactionValidator pluginTransactionValidator; + private final PluginTransactionValidatorService pluginTransactionValidatorService; private volatile PendingTransactions pendingTransactions; private final ProtocolSchedule protocolSchedule; private final ProtocolContext protocolContext; @@ -116,7 +115,7 @@ public TransactionPool( final EthContext ethContext, final TransactionPoolMetrics metrics, final TransactionPoolConfiguration configuration, - final PluginTransactionValidatorFactory pluginTransactionValidatorFactory) { + final PluginTransactionValidatorService pluginTransactionValidatorService) { this.pendingTransactionsSupplier = pendingTransactionsSupplier; this.protocolSchedule = protocolSchedule; this.protocolContext = protocolContext; @@ -124,10 +123,7 @@ public TransactionPool( this.transactionBroadcaster = transactionBroadcaster; this.metrics = metrics; this.configuration = configuration; - this.pluginTransactionValidator = - pluginTransactionValidatorFactory == null - ? null - : pluginTransactionValidatorFactory.create(); + this.pluginTransactionValidatorService = pluginTransactionValidatorService; this.blockAddedEventOrderedProcessor = ethContext.getScheduler().createOrderedProcessor(this::processBlockAddedEvent); initLogForReplay(); @@ -441,9 +437,9 @@ && strictReplayProtectionShouldBeEnforcedLocally(chainHeadBlockHeader) } // Call the transaction validator plugin if one is available - if (pluginTransactionValidator != null) { + if (pluginTransactionValidatorService.get() != null) { final Optional maybeError = - pluginTransactionValidator.validateTransaction(transaction); + pluginTransactionValidatorService.get().create().validateTransaction(transaction); if (maybeError.isPresent()) { return ValidationResultAndAccount.invalid( TransactionInvalidReason.PLUGIN_TX_VALIDATOR, maybeError.get()); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactory.java index 253d37a4758..85e20884bf8 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactory.java @@ -35,7 +35,7 @@ import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket; import org.hyperledger.besu.plugin.services.BesuEvents; import org.hyperledger.besu.plugin.services.MetricsSystem; -import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidatorFactory; +import org.hyperledger.besu.plugin.services.PluginTransactionValidatorService; import java.time.Clock; import java.util.function.BiFunction; @@ -54,7 +54,7 @@ public static TransactionPool createTransactionPool( final MetricsSystem metricsSystem, final SyncState syncState, final TransactionPoolConfiguration transactionPoolConfiguration, - final PluginTransactionValidatorFactory pluginTransactionValidatorFactory, + final PluginTransactionValidatorService pluginTransactionValidatorService, final BlobCache blobCache) { final TransactionPoolMetrics metrics = new TransactionPoolMetrics(metricsSystem); @@ -77,7 +77,7 @@ public static TransactionPool createTransactionPool( transactionTracker, transactionsMessageSender, newPooledTransactionHashesMessageSender, - pluginTransactionValidatorFactory, + pluginTransactionValidatorService, blobCache); } @@ -92,7 +92,7 @@ static TransactionPool createTransactionPool( final PeerTransactionTracker transactionTracker, final TransactionsMessageSender transactionsMessageSender, final NewPooledTransactionHashesMessageSender newPooledTransactionHashesMessageSender, - final PluginTransactionValidatorFactory pluginTransactionValidatorFactory, + final PluginTransactionValidatorService pluginTransactionValidatorService, final BlobCache blobCache) { final TransactionPool transactionPool = @@ -115,7 +115,7 @@ static TransactionPool createTransactionPool( ethContext, metrics, transactionPoolConfiguration, - pluginTransactionValidatorFactory); + pluginTransactionValidatorService); final TransactionsMessageHandler transactionsMessageHandler = new TransactionsMessageHandler( diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java index 1a80d2f742d..18d186255d7 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java @@ -75,6 +75,7 @@ import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem; +import org.hyperledger.besu.plugin.services.PluginTransactionValidatorService; import org.hyperledger.besu.testutil.TestClock; import java.math.BigInteger; @@ -1117,7 +1118,7 @@ public void transactionMessagesGoToTheCorrectExecutor() { metricsSystem, new SyncState(blockchain, ethManager.ethContext().getEthPeers()), TransactionPoolConfiguration.DEFAULT, - null, + mock(PluginTransactionValidatorService.class), new BlobCache()) .setEnabled(); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/AbstractMessageTaskTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/AbstractMessageTaskTest.java index 868030334c8..da17f48f24c 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/AbstractMessageTaskTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/AbstractMessageTaskTest.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.ethereum.eth.manager.ethtaskutils; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import org.hyperledger.besu.crypto.KeyPair; @@ -45,6 +46,7 @@ import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem; +import org.hyperledger.besu.plugin.services.PluginTransactionValidatorService; import org.hyperledger.besu.testutil.DeterministicEthScheduler; import org.hyperledger.besu.testutil.TestClock; @@ -135,7 +137,7 @@ public void setupTest() { metricsSystem, syncState, TransactionPoolConfiguration.DEFAULT, - null, + mock(PluginTransactionValidatorService.class), new BlobCache()); transactionPool.setEnabled(); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/AbstractBlockPropagationManagerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/AbstractBlockPropagationManagerTest.java index f36958b2fb1..1283c4c01a8 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/AbstractBlockPropagationManagerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/AbstractBlockPropagationManagerTest.java @@ -65,7 +65,6 @@ import java.util.Collections; import java.util.List; -import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.function.Supplier; @@ -106,7 +105,7 @@ protected void setup(final DataStorageFormat dataStorageFormat) { blockchain, tempProtocolContext.getWorldStateArchive(), tempProtocolContext.getConsensusContext(ConsensusContext.class), - Optional.empty()); + null); ethProtocolManager = EthProtocolManagerTestUtil.create( protocolSchedule, diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java index 790e17998a3..be35b3d93f2 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java @@ -38,7 +38,6 @@ import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; -import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.stream.Stream; @@ -76,7 +75,7 @@ public void setup(final DataStorageFormat storageFormat) { final ProtocolSchedule protocolSchedule = ProtocolScheduleFixture.MAINNET; final ProtocolContext protocolContext = - new ProtocolContext(localBlockchain, localWorldState, null, Optional.empty()); + new ProtocolContext(localBlockchain, localWorldState, null, null); ethProtocolManager = EthProtocolManagerTestUtil.create( protocolSchedule, diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java index 3eddd2bae24..5d287a39598 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java @@ -43,7 +43,6 @@ import java.io.IOException; import java.util.List; -import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; @@ -150,7 +149,7 @@ public void searchesAgainstNetwork(final int headerRequestSize, final int common final EthContext ethContext = ethProtocolManager.ethContext(); final ProtocolContext protocolContext = - new ProtocolContext(localBlockchain, worldStateArchive, null, Optional.empty()); + new ProtocolContext(localBlockchain, worldStateArchive, null, null); final EthTask task = DetermineCommonAncestorTask.create( diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java index ca183d57af0..15b9866c67b 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java @@ -54,7 +54,6 @@ import org.hyperledger.besu.util.ExceptionUtils; import java.util.List; -import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicReference; @@ -87,8 +86,7 @@ public void setup() { mock(TransactionPool.class), EthProtocolConfiguration.defaultConfig()); ethContext = ethProtocolManager.ethContext(); - protocolContext = - new ProtocolContext(localBlockchain, worldStateArchive, null, Optional.empty()); + protocolContext = new ProtocolContext(localBlockchain, worldStateArchive, null, null); } @Test diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTest.java index c34b4f0906d..cbc84646f97 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTest.java @@ -86,6 +86,7 @@ import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem; +import org.hyperledger.besu.plugin.services.PluginTransactionValidatorService; import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidator; import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidatorFactory; import org.hyperledger.besu.util.number.Percentage; @@ -255,12 +256,12 @@ protected TransactionPool createTransactionPool() { protected TransactionPool createTransactionPool( final Consumer configConsumer) { - return createTransactionPool(configConsumer, null); + return createTransactionPool(configConsumer, mock(PluginTransactionValidatorService.class)); } private TransactionPool createTransactionPool( final Consumer configConsumer, - final PluginTransactionValidatorFactory pluginTransactionValidatorFactory) { + final PluginTransactionValidatorService pluginTransactionValidatorService) { final ImmutableTransactionPoolConfiguration.Builder configBuilder = ImmutableTransactionPoolConfiguration.builder(); configConsumer.accept(configBuilder); @@ -285,7 +286,7 @@ private TransactionPool createTransactionPool( ethContext, new TransactionPoolMetrics(metricsSystem), poolConfig, - pluginTransactionValidatorFactory); + pluginTransactionValidatorService); txPool.setEnabled(); return txPool; } @@ -788,11 +789,11 @@ public void shouldAcceptRemoteTransactionEvenIfFeeCapExceeded(final boolean hasP @ParameterizedTest @ValueSource(booleans = {true, false}) public void transactionNotRejectedByPluginShouldBeAdded(final boolean noLocalPriority) { - final PluginTransactionValidatorFactory pluginTransactionValidatorFactory = - getPluginTransactionValidatorFactoryReturning(null); // null -> not rejecting !! + final PluginTransactionValidatorService pluginTransactionValidatorService = + getPluginTransactionValidatorServiceReturning(null); // null -> not rejecting !! this.transactionPool = createTransactionPool( - b -> b.noLocalPriority(noLocalPriority), pluginTransactionValidatorFactory); + b -> b.noLocalPriority(noLocalPriority), pluginTransactionValidatorService); givenTransactionIsValid(transaction0); @@ -802,11 +803,11 @@ public void transactionNotRejectedByPluginShouldBeAdded(final boolean noLocalPri @ParameterizedTest @ValueSource(booleans = {true, false}) public void transactionRejectedByPluginShouldNotBeAdded(final boolean noLocalPriority) { - final PluginTransactionValidatorFactory pluginTransactionValidatorFactory = - getPluginTransactionValidatorFactoryReturning("false"); + final PluginTransactionValidatorService pluginTransactionValidatorService = + getPluginTransactionValidatorServiceReturning("false"); this.transactionPool = createTransactionPool( - b -> b.noLocalPriority(noLocalPriority), pluginTransactionValidatorFactory); + b -> b.noLocalPriority(noLocalPriority), pluginTransactionValidatorService); givenTransactionIsValid(transaction0); @@ -816,9 +817,9 @@ public void transactionRejectedByPluginShouldNotBeAdded(final boolean noLocalPri @Test public void remoteTransactionRejectedByPluginShouldNotBeAdded() { - final PluginTransactionValidatorFactory pluginTransactionValidatorFactory = - getPluginTransactionValidatorFactoryReturning("false"); - this.transactionPool = createTransactionPool(b -> {}, pluginTransactionValidatorFactory); + final PluginTransactionValidatorService pluginTransactionValidatorService = + getPluginTransactionValidatorServiceReturning("false"); + this.transactionPool = createTransactionPool(b -> {}, pluginTransactionValidatorService); givenTransactionIsValid(transaction0); @@ -1264,11 +1265,20 @@ public void addRemoteTransactionsShouldAllowDuplicates() { .containsExactlyInAnyOrder(transaction1, transaction2a, transaction3); } - private static PluginTransactionValidatorFactory getPluginTransactionValidatorFactoryReturning( + private static PluginTransactionValidatorService getPluginTransactionValidatorServiceReturning( final String errorMessage) { final PluginTransactionValidator pluginTransactionValidator = transaction -> Optional.ofNullable(errorMessage); - return () -> pluginTransactionValidator; + return new PluginTransactionValidatorService() { + @Override + public PluginTransactionValidatorFactory get() { + return () -> pluginTransactionValidator; + } + + @Override + public void registerTransactionValidatorFactory( + final PluginTransactionValidatorFactory transactionValidatorFactory) {} + }; } @SuppressWarnings("unused") diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java index c02e2d78934..1e4116eb955 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java @@ -60,6 +60,8 @@ import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.data.EnodeURL; import org.hyperledger.besu.plugin.services.MetricsSystem; +import org.hyperledger.besu.plugin.services.PluginTransactionValidatorService; +import org.hyperledger.besu.plugin.services.TransactionSelectionService; import org.hyperledger.besu.plugin.services.permissioning.NodeMessagePermissioningProvider; import org.hyperledger.besu.testutil.TestClock; @@ -121,7 +123,8 @@ public TestNode( final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); genesisState.writeStateTo(worldStateArchive.getMutable()); final ProtocolContext protocolContext = - new ProtocolContext(blockchain, worldStateArchive, null, Optional.empty()); + new ProtocolContext( + blockchain, worldStateArchive, null, mock(TransactionSelectionService.class)); final SyncState syncState = mock(SyncState.class); final SynchronizerConfiguration syncConfig = mock(SynchronizerConfiguration.class); @@ -161,7 +164,7 @@ public boolean isMessagePermitted(final EnodeURL destinationEnode, final int cod metricsSystem, syncState, TransactionPoolConfiguration.DEFAULT, - null, + mock(PluginTransactionValidatorService.class), new BlobCache()); final EthProtocolManager ethProtocolManager = diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactoryTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactoryTest.java index 79d88a82d21..81e1361ae05 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactoryTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactoryTest.java @@ -51,6 +51,7 @@ import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; +import org.hyperledger.besu.plugin.services.PluginTransactionValidatorService; import org.hyperledger.besu.plugin.services.permissioning.NodeMessagePermissioningProvider; import org.hyperledger.besu.testutil.TestClock; @@ -356,7 +357,7 @@ private TransactionPool createTransactionPool( .txMessageKeepAliveSeconds(1) .build()) .build(), - null, + mock(PluginTransactionValidatorService.class), new BlobCache()); txPool.setEnabled(); 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 b8df5fa4a95..9ef1036ee40 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 @@ String provideKeyValueStorageName() { @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/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/NodeSmartContractPermissioningController.java b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/NodeSmartContractPermissioningController.java index 5f619ee3f80..a034f049da0 100644 --- a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/NodeSmartContractPermissioningController.java +++ b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/NodeSmartContractPermissioningController.java @@ -71,7 +71,7 @@ boolean checkSmartContractRules(final EnodeURL sourceEnode, final EnodeURL desti transactionSimulator.processAtHead(callParams); if (result.isPresent()) { - switch (result.get().getResult().getStatus()) { + switch (result.get().result().getStatus()) { case INVALID: throw new IllegalStateException("Permissioning transaction found to be Invalid"); case FAILED: diff --git a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/NodeSmartContractV2PermissioningController.java b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/NodeSmartContractV2PermissioningController.java index ca114d17955..ae78a4ab85a 100644 --- a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/NodeSmartContractV2PermissioningController.java +++ b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/NodeSmartContractV2PermissioningController.java @@ -114,7 +114,7 @@ private Bytes createPayload(final EnodeURL enodeUrl) { } private boolean parseResult(final TransactionSimulatorResult result) { - switch (result.getResult().getStatus()) { + switch (result.result().getStatus()) { case INVALID: throw new IllegalStateException("Invalid node permissioning smart contract call"); case FAILED: diff --git a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/TransactionSmartContractPermissioningController.java b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/TransactionSmartContractPermissioningController.java index f8ee921668f..dd42727af85 100644 --- a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/TransactionSmartContractPermissioningController.java +++ b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/TransactionSmartContractPermissioningController.java @@ -134,7 +134,7 @@ public boolean isPermitted(final Transaction transaction) { transactionSimulator.processAtHead(callParams); if (result.isPresent()) { - switch (result.get().getResult().getStatus()) { + switch (result.get().result().getStatus()) { case INVALID: throw new IllegalStateException( "Transaction permissioning transaction found to be Invalid"); diff --git a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BlockchainReferenceTestCaseSpec.java b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BlockchainReferenceTestCaseSpec.java index f0d93f2243a..faf2faa5c62 100644 --- a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BlockchainReferenceTestCaseSpec.java +++ b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BlockchainReferenceTestCaseSpec.java @@ -107,8 +107,7 @@ public BlockchainReferenceTestCaseSpec( this.worldStateArchive = buildWorldStateArchive(accounts); this.blockchain = buildBlockchain(genesisBlockHeader); this.sealEngine = sealEngine; - this.protocolContext = - new ProtocolContext(this.blockchain, this.worldStateArchive, null, Optional.empty()); + this.protocolContext = new ProtocolContext(this.blockchain, this.worldStateArchive, null, null); } public String getNetwork() { diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java index 98054b27dbf..3388d7e8499 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java @@ -66,6 +66,8 @@ import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem; +import org.hyperledger.besu.plugin.services.PluginTransactionValidatorService; +import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidatorFactory; import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; import org.hyperledger.besu.util.Subscribers; import org.hyperledger.besu.util.number.Fraction; @@ -174,7 +176,7 @@ private boolean buildContext( genesisState.writeStateTo(worldState); blockchain = createInMemoryBlockchain(genesisState.getBlock()); - protocolContext = new ProtocolContext(blockchain, worldStateArchive, null, Optional.empty()); + protocolContext = new ProtocolContext(blockchain, worldStateArchive, null, null); blockchainQueries = new BlockchainQueries(blockchain, worldStateArchive, ethScheduler); @@ -251,7 +253,16 @@ private boolean buildContext( metricsSystem, syncState, transactionPoolConfiguration, - null, + new PluginTransactionValidatorService() { + @Override + public PluginTransactionValidatorFactory get() { + return null; + } + + @Override + public void registerTransactionValidatorFactory( + final PluginTransactionValidatorFactory transactionValidatorFactory) {} + }, new BlobCache()); if (LOG.isTraceEnabled()) { diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index a57330d1fb6..1529d2fc93e 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 = 'HWNIeaz59Z1pp7LriVzipUpwCXKXMsIrK6aswBhImvU=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/data/TransactionProcessingResult.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/data/TransactionProcessingResult.java index 22f35ea37bc..ac398788e40 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/data/TransactionProcessingResult.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/data/TransactionProcessingResult.java @@ -88,4 +88,11 @@ public interface TransactionProcessingResult { * @return the revert reason. */ Optional getRevertReason(); + + /** + * Return the reason why the transaction is invalid or empty if the transaction is successful + * + * @return the optional invalid reason as a string + */ + Optional getInvalidReason(); } diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/data/TransactionSimulationResult.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/data/TransactionSimulationResult.java new file mode 100644 index 00000000000..1651534a9fa --- /dev/null +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/data/TransactionSimulationResult.java @@ -0,0 +1,54 @@ +/* + * Copyright Hyperledger Besu Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.plugin.data; + +import org.hyperledger.besu.datatypes.Transaction; + +/** + * TransactionSimulationResult + * + * @param transaction tx + * @param result res + */ +public record TransactionSimulationResult( + Transaction transaction, TransactionProcessingResult result) { + + /** + * Was the simulation successful? + * + * @return boolean + */ + public boolean isSuccessful() { + return result.isSuccessful(); + } + + /** + * Was the transaction invalid? + * + * @return invalid + */ + public boolean isInvalid() { + return result.isInvalid(); + } + + /** + * Estimated gas used by the transaction + * + * @return estimated gas used + */ + public long getGasEstimate() { + return transaction.getGasLimit() - result.getGasRemaining(); + } +} 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 9f830162ecb..bf1b1ab58e9 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(); } diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BlockchainService.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BlockchainService.java index e9356ae76ef..76f66aba6ca 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BlockchainService.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BlockchainService.java @@ -14,8 +14,11 @@ */ package org.hyperledger.besu.plugin.services; +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.plugin.Unstable; import org.hyperledger.besu.plugin.data.BlockContext; +import org.hyperledger.besu.plugin.data.BlockHeader; import java.util.Optional; @@ -29,4 +32,25 @@ public interface BlockchainService extends BesuService { * @return the BlockContext */ Optional getBlockByNumber(final long number); + + /** + * Get the hash of the chain head + * + * @return chain head hash + */ + Hash getChainHeadHash(); + + /** + * Get the block header of the chain head + * + * @return chain head block header + */ + BlockHeader getChainHeadHeader(); + + /** + * Return the base fee for the next block + * + * @return base fee of the next block or empty if the fee market does not support base fee + */ + Optional getNextBlockBaseFee(); } diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/TransactionSimulationService.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/TransactionSimulationService.java new file mode 100644 index 00000000000..c3884b88a88 --- /dev/null +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/TransactionSimulationService.java @@ -0,0 +1,38 @@ +/* + * Copyright Hyperledger Besu Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.plugin.services; + +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.evm.tracing.OperationTracer; +import org.hyperledger.besu.plugin.Unstable; +import org.hyperledger.besu.plugin.data.TransactionSimulationResult; + +import java.util.Optional; + +/** Transaction simulation service interface */ +@Unstable +public interface TransactionSimulationService extends BesuService { + /** + * Simulate transaction execution at the block identified by the hash + * + * @param transaction tx + * @param blockHash the hash of the block + * @param operationTracer the tracer + * @return the result of the simulation + */ + Optional simulate( + Transaction transaction, Hash blockHash, OperationTracer operationTracer); +}