diff --git a/CHANGELOG.md b/CHANGELOG.md index 76e7ccb838b..1210e351382 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Update commons-compress to 1.26.0 [#6648](https://github.com/hyperledger/besu/pull/6648) - Add blob transaction support to `eth_call` [#6661](https://github.com/hyperledger/besu/pull/6661) - Add blobs to `eth_feeHistory` [#6679](https://github.com/hyperledger/besu/pull/6679) +- Refactor and extend `TransactionPoolValidatorService` [#6636](https://github.com/hyperledger/besu/pull/6636) ### Bug fixes 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 c4b36df2a92..1c10f82e3bf 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 @@ -45,22 +45,21 @@ import org.hyperledger.besu.plugin.services.BesuConfiguration; import org.hyperledger.besu.plugin.services.BesuEvents; 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.TransactionPoolValidatorService; import org.hyperledger.besu.plugin.services.TransactionSelectionService; import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBPlugin; -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.PermissioningServiceImpl; import org.hyperledger.besu.services.PicoCLIOptionsImpl; -import org.hyperledger.besu.services.PluginTransactionValidatorServiceImpl; import org.hyperledger.besu.services.RpcEndpointServiceImpl; import org.hyperledger.besu.services.SecurityModuleServiceImpl; import org.hyperledger.besu.services.StorageServiceImpl; +import org.hyperledger.besu.services.TransactionPoolValidatorServiceImpl; import org.hyperledger.besu.services.TransactionSelectionServiceImpl; import java.io.File; @@ -71,7 +70,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; @@ -105,7 +103,7 @@ private BesuPluginContextImpl buildPluginContext( besuPluginContext.addService( TransactionSelectionService.class, transactionSelectionServiceImpl); besuPluginContext.addService( - PluginTransactionValidatorService.class, new PluginTransactionValidatorServiceImpl()); + TransactionPoolValidatorService.class, new TransactionPoolValidatorServiceImpl()); final Path pluginsPath; final String pluginDir = System.getProperty("besu.plugins.dir"); if (pluginDir == null || pluginDir.isEmpty()) { @@ -205,8 +203,6 @@ public void startNode(final BesuNode node) { final int maxPeers = 25; - final PluginTransactionValidatorFactory pluginTransactionValidatorFactory = - getPluginTransactionValidatorFactory(besuPluginContext); builder .synchronizerConfiguration(new SynchronizerConfiguration.Builder().build()) .dataDirectory(node.homeDirectory()) @@ -228,8 +224,7 @@ public void startNode(final BesuNode node) { .maxPeers(maxPeers) .maxRemotelyInitiatedPeers(15) .networkConfiguration(node.getNetworkingConfiguration()) - .randomPeerPriority(false) - .pluginTransactionValidatorFactory(pluginTransactionValidatorFactory); + .randomPeerPriority(false); node.getGenesisConfig() .map(GenesisConfigFile::fromConfig) @@ -339,11 +334,4 @@ public void startConsoleCapture() { public String getConsoleContents() { throw new RuntimeException("Console contents can only be captured in process execution"); } - - private PluginTransactionValidatorFactory getPluginTransactionValidatorFactory( - final BesuPluginContextImpl besuPluginContext) { - final Optional txValidatorService = - besuPluginContext.getService(PluginTransactionValidatorService.class); - return txValidatorService.map(PluginTransactionValidatorService::get).orElse(null); - } } 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 ccafeeb4580..679bfc88dd7 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -160,12 +160,12 @@ import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.PermissioningService; import org.hyperledger.besu.plugin.services.PicoCLIOptions; -import org.hyperledger.besu.plugin.services.PluginTransactionValidatorService; import org.hyperledger.besu.plugin.services.PrivacyPluginService; 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.TraceService; +import org.hyperledger.besu.plugin.services.TransactionPoolValidatorService; import org.hyperledger.besu.plugin.services.TransactionSelectionService; import org.hyperledger.besu.plugin.services.exception.StorageException; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; @@ -174,19 +174,18 @@ import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; import org.hyperledger.besu.plugin.services.storage.PrivacyKeyValueStorageFactory; import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBPlugin; -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; import org.hyperledger.besu.services.PrivacyPluginServiceImpl; import org.hyperledger.besu.services.RpcEndpointServiceImpl; import org.hyperledger.besu.services.SecurityModuleServiceImpl; import org.hyperledger.besu.services.StorageServiceImpl; import org.hyperledger.besu.services.TraceServiceImpl; +import org.hyperledger.besu.services.TransactionPoolValidatorServiceImpl; import org.hyperledger.besu.services.TransactionSelectionServiceImpl; import org.hyperledger.besu.services.kvstore.InMemoryStoragePlugin; import org.hyperledger.besu.util.InvalidConfigurationException; @@ -370,7 +369,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable { P2PDiscoveryOptionGroup p2PDiscoveryOptionGroup = new P2PDiscoveryOptionGroup(); private final TransactionSelectionServiceImpl transactionSelectionServiceImpl; - private final PluginTransactionValidatorServiceImpl transactionValidatorServiceImpl; + private final TransactionPoolValidatorServiceImpl transactionValidatorServiceImpl; private final BlockchainServiceImpl blockchainServiceImpl; static class P2PDiscoveryOptionGroup { @@ -956,7 +955,7 @@ public BesuCommand( new PkiBlockCreationConfigurationProvider(), new RpcEndpointServiceImpl(), new TransactionSelectionServiceImpl(), - new PluginTransactionValidatorServiceImpl(), + new TransactionPoolValidatorServiceImpl(), new BlockchainServiceImpl()); } @@ -998,7 +997,7 @@ protected BesuCommand( final PkiBlockCreationConfigurationProvider pkiBlockCreationConfigProvider, final RpcEndpointServiceImpl rpcEndpointServiceImpl, final TransactionSelectionServiceImpl transactionSelectionServiceImpl, - final PluginTransactionValidatorServiceImpl transactionValidatorServiceImpl, + final TransactionPoolValidatorServiceImpl transactionValidatorServiceImpl, final BlockchainServiceImpl blockchainServiceImpl) { this.besuComponent = besuComponent; this.logger = besuComponent.getBesuCommandLogger(); @@ -1210,7 +1209,7 @@ private void preparePlugins() { besuPluginContext.addService( TransactionSelectionService.class, transactionSelectionServiceImpl); besuPluginContext.addService( - PluginTransactionValidatorService.class, transactionValidatorServiceImpl); + TransactionPoolValidatorService.class, transactionValidatorServiceImpl); besuPluginContext.addService(BlockchainService.class, blockchainServiceImpl); // register built-in plugins @@ -1812,7 +1811,6 @@ public BesuControllerBuilder getControllerBuilder() { .synchronizerConfiguration(buildSyncConfig()) .ethProtocolConfiguration(unstableEthProtocolOptions.toDomainObject()) .networkConfiguration(unstableNetworkingOptions.toDomainObject()) - .pluginTransactionValidatorFactory(getPluginTransactionValidatorFactory()) .dataDirectory(dataDir()) .dataStorageConfiguration(getDataStorageConfiguration()) .miningParameters(getMiningParameters()) @@ -1843,12 +1841,6 @@ public BesuControllerBuilder getControllerBuilder() { .cacheLastBlocks(numberOfblocksToCache); } - private PluginTransactionValidatorFactory getPluginTransactionValidatorFactory() { - final Optional txSValidatorService = - besuPluginContext.getService(PluginTransactionValidatorService.class); - return txSValidatorService.map(PluginTransactionValidatorService::get).orElse(null); - } - private JsonRpcConfiguration createEngineJsonRpcConfiguration( final Integer engineListenPort, final List allowCallsFrom) { jsonRpcHttpOptions.checkDependencies(logger, commandLine); @@ -2115,6 +2107,7 @@ private SynchronizerConfiguration buildSyncConfig() { } private TransactionPoolConfiguration buildTransactionPoolConfiguration() { + transactionPoolOptions.setPluginTransactionValidatorService(transactionValidatorServiceImpl); final var txPoolConf = transactionPoolOptions.toDomainObject(); final var txPoolConfBuilder = ImmutableTransactionPoolConfiguration.builder() diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/TransactionPoolOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/TransactionPoolOptions.java index 0b6718387b1..04b9f1f1d8a 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/TransactionPoolOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/TransactionPoolOptions.java @@ -30,6 +30,7 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; +import org.hyperledger.besu.plugin.services.TransactionPoolValidatorService; import org.hyperledger.besu.util.number.Fraction; import org.hyperledger.besu.util.number.Percentage; @@ -57,6 +58,8 @@ public class TransactionPoolOptions implements CLIOptions besuComponent = Optional.empty(); - private PluginTransactionValidatorFactory pluginTransactionValidatorFactory; - private int numberOfBlocksToCache = 0; /** @@ -532,18 +529,6 @@ public BesuControllerBuilder randomPeerPriority(final Boolean randomPeerPriority return this; } - /** - * sets the pluginTransactionValidatorFactory - * - * @param pluginTransactionValidatorFactory factory that creates plugin transaction Validators - * @return the besu controller builder - */ - public BesuControllerBuilder pluginTransactionValidatorFactory( - final PluginTransactionValidatorFactory pluginTransactionValidatorFactory) { - this.pluginTransactionValidatorFactory = pluginTransactionValidatorFactory; - return this; - } - /** * Build besu controller. * @@ -697,7 +682,6 @@ public BesuController build() { metricsSystem, syncState, transactionPoolConfiguration, - pluginTransactionValidatorFactory, besuComponent.map(BesuComponent::getBlobCache).orElse(new BlobCache()), miningParameters); diff --git a/besu/src/main/java/org/hyperledger/besu/services/PluginTransactionValidatorServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/PluginTransactionValidatorServiceImpl.java deleted file mode 100644 index 171a31388c8..00000000000 --- a/besu/src/main/java/org/hyperledger/besu/services/PluginTransactionValidatorServiceImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright contributors to Hyperledger Besu. - * - * 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.plugin.services.PluginTransactionValidatorService; -import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidatorFactory; - -/** The Transaction Validation service implementation. */ -public class PluginTransactionValidatorServiceImpl implements PluginTransactionValidatorService { - - private PluginTransactionValidatorFactory factory; - - @Override - public PluginTransactionValidatorFactory get() { - return factory; - } - - @Override - public void registerTransactionValidatorFactory( - final PluginTransactionValidatorFactory transactionValidatorFactory) { - factory = transactionValidatorFactory; - } -} diff --git a/besu/src/main/java/org/hyperledger/besu/services/TransactionPoolValidatorServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/TransactionPoolValidatorServiceImpl.java new file mode 100644 index 00000000000..8a8662893fc --- /dev/null +++ b/besu/src/main/java/org/hyperledger/besu/services/TransactionPoolValidatorServiceImpl.java @@ -0,0 +1,40 @@ +/* + * Copyright contributors to Hyperledger Besu. + * + * 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.plugin.services.TransactionPoolValidatorService; +import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionPoolValidator; +import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionPoolValidatorFactory; + +import java.util.Optional; + +/** The Transaction pool validator service implementation. */ +public class TransactionPoolValidatorServiceImpl implements TransactionPoolValidatorService { + + private Optional factory = Optional.empty(); + + @Override + public PluginTransactionPoolValidator createTransactionValidator() { + return factory + .map(PluginTransactionPoolValidatorFactory::createTransactionValidator) + .orElse(PluginTransactionPoolValidator.VALIDATE_ALL); + } + + @Override + public void registerPluginTransactionValidatorFactory( + final PluginTransactionPoolValidatorFactory pluginTransactionPoolValidatorFactory) { + factory = Optional.ofNullable(pluginTransactionPoolValidatorFactory); + } +} 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 7671973fe47..d784733608f 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java @@ -86,11 +86,11 @@ 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; import org.hyperledger.besu.services.RpcEndpointServiceImpl; import org.hyperledger.besu.services.SecurityModuleServiceImpl; import org.hyperledger.besu.services.StorageServiceImpl; +import org.hyperledger.besu.services.TransactionPoolValidatorServiceImpl; import org.hyperledger.besu.services.TransactionSelectionServiceImpl; import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; @@ -297,8 +297,6 @@ public void initMocks() throws Exception { when(mockControllerBuilder.maxPeers(anyInt())).thenReturn(mockControllerBuilder); when(mockControllerBuilder.maxRemotelyInitiatedPeers(anyInt())) .thenReturn(mockControllerBuilder); - when(mockControllerBuilder.pluginTransactionValidatorFactory(any())) - .thenReturn(mockControllerBuilder); when(mockControllerBuilder.besuComponent(any(BesuComponent.class))) .thenReturn(mockControllerBuilder); when(mockControllerBuilder.cacheLastBlocks(any())).thenReturn(mockControllerBuilder); @@ -574,7 +572,7 @@ public static class TestBesuCommand extends BesuCommand { pkiBlockCreationConfigProvider, rpcEndpointServiceImpl, new TransactionSelectionServiceImpl(), - new PluginTransactionValidatorServiceImpl(), + new TransactionPoolValidatorServiceImpl(), new BlockchainServiceImpl()); } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java index 00d4efc3b9f..ad82b98ed49 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java @@ -370,4 +370,9 @@ protected TransactionPoolOptions optionsFromDomainObject( protected TransactionPoolOptions getOptionsFromBesuCommand(final TestBesuCommand besuCommand) { return besuCommand.getTransactionPoolOptions(); } + + @Override + protected String[] getNonOptionFields() { + return new String[] {"transactionPoolValidatorService"}; + } } 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 8b21fa215fa..2aa5b7c010c 100644 --- a/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java +++ b/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java @@ -167,7 +167,6 @@ public void setUp() { new NoOpMetricsSystem(), syncState, txPoolConfig, - null, new BlobCache(), MiningParameters.newDefault()); 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 58f7c72fce3..b6edc930477 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 @@ -243,8 +243,7 @@ private TransactionPool createTransactionPool() { mock(TransactionBroadcaster.class), ethContext, new TransactionPoolMetrics(metricsSystem), - conf, - null); + conf); transactionPool.setEnabled(); return transactionPool; } 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 3d3e005f274..185674aa90c 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 @@ -230,8 +230,7 @@ private TransactionPool createTransactionPool() { mock(TransactionBroadcaster.class), cliqueEthContext, new TransactionPoolMetrics(metricsSystem), - conf, - null); + conf); transactionPool.setEnabled(); return transactionPool; 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 63c28901a8a..cd34570827f 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 @@ -368,8 +368,7 @@ private static ControllerAndState createControllerAndFinalState( mock(TransactionBroadcaster.class), ethContext, new TransactionPoolMetrics(metricsSystem), - poolConf, - null); + poolConf); transactionPool.setEnabled(); 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 5481297dee7..621340d8299 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 @@ -149,8 +149,7 @@ public BlockHeaderValidator.Builder createBlockHeaderRuleset( mock(TransactionBroadcaster.class), ethContext, new TransactionPoolMetrics(metricsSystem), - poolConf, - null); + poolConf); transactionPool.setEnabled(); 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 7aa9e92a7f4..7fdfbad3bd6 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 @@ -214,8 +214,7 @@ public void setUp() { mock(TransactionBroadcaster.class), ethContext, new TransactionPoolMetrics(metricsSystem), - poolConf, - null); + poolConf); this.transactionPool.setEnabled(); 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 caffe3f2ba8..dcfb049dade 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 @@ -466,8 +466,7 @@ private static ControllerAndState createControllerAndFinalState( mock(TransactionBroadcaster.class), ethContext, new TransactionPoolMetrics(metricsSystem), - poolConf, - null); + poolConf); transactionPool.setEnabled(); diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetFilterChangesIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetFilterChangesIntegrationTest.java index 1864246401e..64e0155287c 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetFilterChangesIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetFilterChangesIntegrationTest.java @@ -120,8 +120,7 @@ public void setUp() { batchAddedListener, ethContext, new TransactionPoolMetrics(metricsSystem), - TransactionPoolConfiguration.DEFAULT, - null); + TransactionPoolConfiguration.DEFAULT); transactionPool.setEnabled(); final BlockchainQueries blockchainQueries = new BlockchainQueries(blockchain, protocolContext.getWorldStateArchive()); diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthGetFilterChangesIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthGetFilterChangesIntegrationTest.java index 49a2fbcd87b..57612545aa7 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthGetFilterChangesIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthGetFilterChangesIntegrationTest.java @@ -120,8 +120,7 @@ public void setUp() { batchAddedListener, ethContext, new TransactionPoolMetrics(metricsSystem), - TransactionPoolConfiguration.DEFAULT, - null); + TransactionPoolConfiguration.DEFAULT); transactionPool.setEnabled(); final BlockchainQueries blockchainQueries = new BlockchainQueries(blockchain, protocolContext.getWorldStateArchive()); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcErrorConverter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcErrorConverter.java index 8a17f101c21..c583401b3f1 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcErrorConverter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcErrorConverter.java @@ -75,7 +75,7 @@ public static RpcErrorType convertTransactionInvalidReason( return RpcErrorType.TOTAL_BLOB_GAS_TOO_HIGH; case TX_POOL_DISABLED: return RpcErrorType.TX_POOL_DISABLED; - case PLUGIN_TX_VALIDATOR: + case PLUGIN_TX_POOL_VALIDATOR: return RpcErrorType.PLUGIN_TX_VALIDATOR; case INVALID_BLOBS: return RpcErrorType.INVALID_BLOBS; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java index 45e554bc9a5..9382bd34f3c 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java @@ -103,7 +103,7 @@ private JsonRpcResponse getJsonRpcResponse( if (sendEmptyHashOnInvalidBlock) { return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), Hash.EMPTY.toString()); } else { - if (errorReason == TransactionInvalidReason.PLUGIN_TX_VALIDATOR) { + if (errorReason == TransactionInvalidReason.PLUGIN_TX_POOL_VALIDATOR) { final RpcErrorType rpcErrorType = JsonRpcErrorConverter.convertTransactionInvalidReason( validationResult.getInvalidReason()); 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 1797d994b09..3e8cc8a685c 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 @@ -386,8 +386,7 @@ private AbstractBlockCreator createBlockCreator( mock(TransactionBroadcaster.class), ethContext, new TransactionPoolMetrics(new NoOpMetricsSystem()), - poolConf, - null); + poolConf); transactionPool.setEnabled(); final MiningParameters miningParameters = diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java index 3fc970110ca..ebca2bb17aa 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java @@ -732,9 +732,11 @@ public void transactionSelectionPluginShouldBeNotifiedWhenTransactionSelectionCo final Transaction transaction = createTransaction(0, Wei.of(10), 21_000); ensureTransactionIsValid(transaction, 21_000, 0); - final TransactionInvalidReason invalidReason = TransactionInvalidReason.PLUGIN_TX_VALIDATOR; + final TransactionInvalidReason invalidReason = + TransactionInvalidReason.PLUGIN_TX_POOL_VALIDATOR; final Transaction invalidTransaction = createTransaction(1, Wei.of(10), 21_000); - ensureTransactionIsInvalid(invalidTransaction, TransactionInvalidReason.PLUGIN_TX_VALIDATOR); + ensureTransactionIsInvalid( + invalidTransaction, TransactionInvalidReason.PLUGIN_TX_POOL_VALIDATOR); final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( 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 3b252569174..10d54576b42 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 @@ -90,8 +90,7 @@ protected TransactionPool createTransactionPool() { mock(TransactionBroadcaster.class), ethContext, new TransactionPoolMetrics(metricsSystem), - poolConf, - null); + poolConf); 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 32b3935018c..4a961d07e80 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 @@ -98,8 +98,7 @@ protected TransactionPool createTransactionPool() { mock(TransactionBroadcaster.class), ethContext, new TransactionPoolMetrics(metricsSystem), - poolConf, - null); + poolConf); 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 784d119cbeb..ad3ce47887a 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 @@ -338,8 +338,7 @@ private TransactionPool createTransactionPool( mock(TransactionBroadcaster.class), ethContext, new TransactionPoolMetrics(metricsSystem), - poolConf, - null); + poolConf); transactionPool.setEnabled(); return transactionPool; diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutorTest.java index 905a6c979de..6859409d49f 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutorTest.java @@ -117,8 +117,7 @@ private TransactionPool createTransactionPool() { mock(TransactionBroadcaster.class), ethContext, new TransactionPoolMetrics(new NoOpMetricsSystem()), - poolConf, - null); + poolConf); transactionPool.setEnabled(); return transactionPool; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionInvalidReason.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionInvalidReason.java index acdb73c6978..0760740467f 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionInvalidReason.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionInvalidReason.java @@ -49,7 +49,7 @@ public enum TransactionInvalidReason { INTERNAL_ERROR, TX_POOL_DISABLED, INVALID_BLOBS, - PLUGIN_TX_VALIDATOR, + PLUGIN_TX_POOL_VALIDATOR, EXECUTION_HALTED, // Private Transaction Invalid Reasons PRIVATE_TRANSACTION_INVALID, 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 b6c9c14a632..b8ad4a68a5d 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 @@ -173,8 +173,7 @@ public void createStorage() { mock(TransactionBroadcaster.class), ethContext, txPoolMetrics, - poolConfiguration, - null); + poolConfiguration); transactionPool.setEnabled(); } 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 dab6d13a240..0396d0dea4f 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,6 @@ 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.util.Subscribers; import java.io.BufferedReader; @@ -92,7 +90,6 @@ 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 volatile PendingTransactions pendingTransactions; private final ProtocolSchedule protocolSchedule; private final ProtocolContext protocolContext; @@ -115,8 +112,7 @@ public TransactionPool( final TransactionBroadcaster transactionBroadcaster, final EthContext ethContext, final TransactionPoolMetrics metrics, - final TransactionPoolConfiguration configuration, - final PluginTransactionValidatorFactory pluginTransactionValidatorFactory) { + final TransactionPoolConfiguration configuration) { this.pendingTransactionsSupplier = pendingTransactionsSupplier; this.protocolSchedule = protocolSchedule; this.protocolContext = protocolContext; @@ -124,10 +120,6 @@ public TransactionPool( this.transactionBroadcaster = transactionBroadcaster; this.metrics = metrics; this.configuration = configuration; - this.pluginTransactionValidator = - pluginTransactionValidatorFactory == null - ? null - : pluginTransactionValidatorFactory.create(); this.blockAddedEventOrderedProcessor = ethContext.getScheduler().createOrderedProcessor(this::processBlockAddedEvent); initLogForReplay(); @@ -442,14 +434,15 @@ && strictReplayProtectionShouldBeEnforcedLocally(chainHeadBlockHeader) TransactionInvalidReason.INVALID_BLOBS, "Blob transaction must have at least one blob"); } - // Call the transaction validator plugin if one is available - if (pluginTransactionValidator != null) { - final Optional maybeError = - pluginTransactionValidator.validateTransaction(transaction); - if (maybeError.isPresent()) { - return ValidationResultAndAccount.invalid( - TransactionInvalidReason.PLUGIN_TX_VALIDATOR, maybeError.get()); - } + // Call the transaction validator plugin + final Optional maybePluginInvalid = + configuration + .getTransactionPoolValidatorService() + .createTransactionValidator() + .validateTransaction(transaction, isLocal, hasPriority); + if (maybePluginInvalid.isPresent()) { + return ValidationResultAndAccount.invalid( + TransactionInvalidReason.PLUGIN_TX_POOL_VALIDATOR, maybePluginInvalid.get()); } try (final var worldState = diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolConfiguration.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolConfiguration.java index f6ef30667e6..7479bc441bc 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolConfiguration.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolConfiguration.java @@ -16,6 +16,9 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.plugin.services.TransactionPoolValidatorService; +import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionPoolValidator; +import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionPoolValidatorFactory; import org.hyperledger.besu.util.number.Fraction; import org.hyperledger.besu.util.number.Percentage; @@ -154,6 +157,20 @@ default Wei getMinGasPrice() { return DEFAULT_TX_POOL_MIN_GAS_PRICE; } + @Value.Default + default TransactionPoolValidatorService getTransactionPoolValidatorService() { + return new TransactionPoolValidatorService() { + @Override + public PluginTransactionPoolValidator createTransactionValidator() { + return PluginTransactionPoolValidator.VALIDATE_ALL; + } + + @Override + public void registerPluginTransactionValidatorFactory( + final PluginTransactionPoolValidatorFactory pluginTransactionPoolValidatorFactory) {} + }; + } + @Value.Default default Unstable getUnstable() { return Unstable.DEFAULT; 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 0f9aaa002db..3a36cedfdae 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 @@ -36,7 +36,6 @@ 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 java.time.Clock; import java.util.function.BiFunction; @@ -55,7 +54,6 @@ public static TransactionPool createTransactionPool( final MetricsSystem metricsSystem, final SyncState syncState, final TransactionPoolConfiguration transactionPoolConfiguration, - final PluginTransactionValidatorFactory pluginTransactionValidatorFactory, final BlobCache blobCache, final MiningParameters miningParameters) { @@ -79,7 +77,6 @@ public static TransactionPool createTransactionPool( transactionTracker, transactionsMessageSender, newPooledTransactionHashesMessageSender, - pluginTransactionValidatorFactory, blobCache, miningParameters); } @@ -95,7 +92,6 @@ static TransactionPool createTransactionPool( final PeerTransactionTracker transactionTracker, final TransactionsMessageSender transactionsMessageSender, final NewPooledTransactionHashesMessageSender newPooledTransactionHashesMessageSender, - final PluginTransactionValidatorFactory pluginTransactionValidatorFactory, final BlobCache blobCache, final MiningParameters miningParameters) { @@ -119,8 +115,7 @@ static TransactionPool createTransactionPool( newPooledTransactionHashesMessageSender), ethContext, metrics, - transactionPoolConfiguration, - pluginTransactionValidatorFactory); + transactionPoolConfiguration); 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 7602de7ab69..130c740749e 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 @@ -1118,7 +1118,6 @@ public void transactionMessagesGoToTheCorrectExecutor() { metricsSystem, new SyncState(blockchain, ethManager.ethContext().getEthPeers()), TransactionPoolConfiguration.DEFAULT, - null, new BlobCache(), MiningParameters.newDefault()) .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 e78ea930885..2f0657d23d7 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 @@ -138,7 +138,6 @@ public void setupTest() { metricsSystem, syncState, TransactionPoolConfiguration.DEFAULT, - null, new BlobCache(), MiningParameters.newDefault()); transactionPool.setEnabled(); 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 62a2e615b07..e811df51f1b 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 @@ -87,8 +87,9 @@ 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.txvalidator.PluginTransactionValidator; -import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidatorFactory; +import org.hyperledger.besu.plugin.services.TransactionPoolValidatorService; +import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionPoolValidator; +import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionPoolValidatorFactory; import org.hyperledger.besu.util.number.Percentage; import java.math.BigInteger; @@ -256,14 +257,8 @@ protected TransactionPool createTransactionPool() { return createTransactionPool(b -> b.minGasPrice(Wei.of(2))); } - protected TransactionPool createTransactionPool( - final Consumer configConsumer) { - return createTransactionPool(configConsumer, null); - } - private TransactionPool createTransactionPool( - final Consumer configConsumer, - final PluginTransactionValidatorFactory pluginTransactionValidatorFactory) { + final Consumer configConsumer) { final ImmutableTransactionPoolConfiguration.Builder configBuilder = ImmutableTransactionPoolConfiguration.builder(); configConsumer.accept(configBuilder); @@ -287,8 +282,7 @@ private TransactionPool createTransactionPool( transactionBroadcaster, ethContext, new TransactionPoolMetrics(metricsSystem), - poolConfig, - pluginTransactionValidatorFactory); + poolConfig); txPool.setEnabled(); return txPool; } @@ -794,11 +788,13 @@ 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 TransactionPoolValidatorService transactionPoolValidatorService = + getTransactionPoolValidatorServiceReturning(null); // null -> not rejecting !! this.transactionPool = createTransactionPool( - b -> b.noLocalPriority(noLocalPriority), pluginTransactionValidatorFactory); + b -> + b.noLocalPriority(noLocalPriority) + .transactionPoolValidatorService(transactionPoolValidatorService)); givenTransactionIsValid(transaction0); @@ -808,23 +804,27 @@ public void transactionNotRejectedByPluginShouldBeAdded(final boolean noLocalPri @ParameterizedTest @ValueSource(booleans = {true, false}) public void transactionRejectedByPluginShouldNotBeAdded(final boolean noLocalPriority) { - final PluginTransactionValidatorFactory pluginTransactionValidatorFactory = - getPluginTransactionValidatorFactoryReturning("false"); + final TransactionPoolValidatorService transactionPoolValidatorService = + getTransactionPoolValidatorServiceReturning("false"); this.transactionPool = createTransactionPool( - b -> b.noLocalPriority(noLocalPriority), pluginTransactionValidatorFactory); + b -> + b.noLocalPriority(noLocalPriority) + .transactionPoolValidatorService(transactionPoolValidatorService)); givenTransactionIsValid(transaction0); addAndAssertTransactionViaApiInvalid( - transaction0, TransactionInvalidReason.PLUGIN_TX_VALIDATOR); + transaction0, TransactionInvalidReason.PLUGIN_TX_POOL_VALIDATOR); } @Test public void remoteTransactionRejectedByPluginShouldNotBeAdded() { - final PluginTransactionValidatorFactory pluginTransactionValidatorFactory = - getPluginTransactionValidatorFactoryReturning("false"); - this.transactionPool = createTransactionPool(b -> {}, pluginTransactionValidatorFactory); + final TransactionPoolValidatorService transactionPoolValidatorService = + getTransactionPoolValidatorServiceReturning("false"); + this.transactionPool = + createTransactionPool( + b -> b.transactionPoolValidatorService(transactionPoolValidatorService)); givenTransactionIsValid(transaction0); @@ -1270,11 +1270,18 @@ public void addRemoteTransactionsShouldAllowDuplicates() { .containsExactlyInAnyOrder(transaction1, transaction2a, transaction3); } - private static PluginTransactionValidatorFactory getPluginTransactionValidatorFactoryReturning( + private static TransactionPoolValidatorService getTransactionPoolValidatorServiceReturning( final String errorMessage) { - final PluginTransactionValidator pluginTransactionValidator = - transaction -> Optional.ofNullable(errorMessage); - return () -> pluginTransactionValidator; + return new TransactionPoolValidatorService() { + @Override + public PluginTransactionPoolValidator createTransactionValidator() { + return (transaction, isLocal, hasPriority) -> Optional.ofNullable(errorMessage); + } + + @Override + public void registerPluginTransactionValidatorFactory( + final PluginTransactionPoolValidatorFactory pluginTransactionPoolValidatorFactory) {} + }; } @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 674dec68530..762e7cf7a94 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 @@ -166,7 +166,6 @@ public boolean isMessagePermitted(final EnodeURL destinationEnode, final int cod metricsSystem, syncState, TransactionPoolConfiguration.DEFAULT, - null, new BlobCache(), MiningParameters.newDefault()); 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 66419f62525..95d7f389f55 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 @@ -251,7 +251,6 @@ private void setupInitialSyncPhase(final boolean hasInitialSyncPhase) { peerTransactionTracker, transactionsMessageSender, newPooledTransactionHashesMessageSender, - null, new BlobCache(), MiningParameters.newDefault()); @@ -360,7 +359,6 @@ private TransactionPool createTransactionPool( .txMessageKeepAliveSeconds(1) .build()) .build(), - null, new BlobCache(), MiningParameters.newDefault()); 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 c927b6f692d..4b142464247 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 @@ -255,7 +255,6 @@ private boolean buildContext( metricsSystem, syncState, transactionPoolConfiguration, - null, new BlobCache(), MiningParameters.newDefault()); diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index bd3e0e43ef8..8d051eb516d 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 = 'Jv/pqyKOoZo3wlxRRwmzPuLIJjEqyV1i55wFyIUV90A=' + knownHash = 'B/pzTaARYvd/T9WtAXtX6vFbxoK5u82GigByKD0YP6M=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PluginTransactionValidatorService.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/TransactionPoolValidatorService.java similarity index 63% rename from plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PluginTransactionValidatorService.java rename to plugin-api/src/main/java/org/hyperledger/besu/plugin/services/TransactionPoolValidatorService.java index 993cbdafe1f..2d210c13e41 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PluginTransactionValidatorService.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/TransactionPoolValidatorService.java @@ -16,24 +16,25 @@ package org.hyperledger.besu.plugin.services; import org.hyperledger.besu.plugin.Unstable; -import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidatorFactory; +import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionPoolValidator; +import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionPoolValidatorFactory; /** Transaction validator for addition of transactions to the transaction pool */ @Unstable -public interface PluginTransactionValidatorService extends BesuService { +public interface TransactionPoolValidatorService extends BesuService { /** - * Returns the transaction validator factory + * Returns the transaction validator to be used in the txpool * - * @return the transaction validator factory + * @return the transaction validator */ - PluginTransactionValidatorFactory get(); + PluginTransactionPoolValidator createTransactionValidator(); /** * Registers the transaction validator factory with the service * - * @param transactionValidatorFactory transaction validator factory to be used + * @param pluginTransactionPoolValidatorFactory transaction validator factory to be used */ - void registerTransactionValidatorFactory( - PluginTransactionValidatorFactory transactionValidatorFactory); + void registerPluginTransactionValidatorFactory( + PluginTransactionPoolValidatorFactory pluginTransactionPoolValidatorFactory); } diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/txvalidator/PluginTransactionValidator.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/txvalidator/PluginTransactionPoolValidator.java similarity index 65% rename from plugin-api/src/main/java/org/hyperledger/besu/plugin/services/txvalidator/PluginTransactionValidator.java rename to plugin-api/src/main/java/org/hyperledger/besu/plugin/services/txvalidator/PluginTransactionPoolValidator.java index ab47b31f0d7..02fcd9b21f7 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/txvalidator/PluginTransactionValidator.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/txvalidator/PluginTransactionPoolValidator.java @@ -20,16 +20,22 @@ import java.util.Optional; -/** Interface for the transaction validator plugin */ +/** Interface for the transaction validator plugin for txpool usage */ @Unstable -public interface PluginTransactionValidator { +public interface PluginTransactionPoolValidator { + /** Plugin transaction pool validator that unconditionally validates every transaction */ + PluginTransactionPoolValidator VALIDATE_ALL = + (transaction, isLocal, hasPriority) -> Optional.empty(); /** * Method called to decide whether a transaction can be added to the transaction pool. * * @param transaction candidate transaction + * @param isLocal if the transaction was sent to this node via API + * @param hasPriority if the transaction has priority * @return Optional.empty() if the transaction is valid, an Optional containing an error message, * if not */ - Optional validateTransaction(final Transaction transaction); + Optional validateTransaction( + final Transaction transaction, final boolean isLocal, final boolean hasPriority); } diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/txvalidator/PluginTransactionValidatorFactory.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/txvalidator/PluginTransactionPoolValidatorFactory.java similarity index 81% rename from plugin-api/src/main/java/org/hyperledger/besu/plugin/services/txvalidator/PluginTransactionValidatorFactory.java rename to plugin-api/src/main/java/org/hyperledger/besu/plugin/services/txvalidator/PluginTransactionPoolValidatorFactory.java index bfbf86bd1be..3163667b86e 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/txvalidator/PluginTransactionValidatorFactory.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/txvalidator/PluginTransactionPoolValidatorFactory.java @@ -17,14 +17,14 @@ import org.hyperledger.besu.plugin.Unstable; -/** Interface for a factory that creates transaction validators */ +/** Interface for a factory that creates transaction validators for txpool usage */ @Unstable -public interface PluginTransactionValidatorFactory { +public interface PluginTransactionPoolValidatorFactory { /** - * Create a transaction validator + * Create a transaction validator for txpool usage * * @return the transaction validator */ - PluginTransactionValidator create(); + PluginTransactionPoolValidator createTransactionValidator(); }