Refactor `TransactionSelectionService` (#6595)

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
pull/6618/head
Fabio Di Fabio 9 months ago committed by GitHub
parent b8ba3ee080
commit 2c1733c8f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 24
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java
  2. 12
      besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
  3. 25
      besu/src/main/java/org/hyperledger/besu/cli/options/MiningOptions.java
  4. 29
      besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java
  5. 11
      besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java
  6. 10
      besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java
  7. 13
      besu/src/main/java/org/hyperledger/besu/services/TransactionSelectionServiceImpl.java
  8. 28
      besu/src/test/java/org/hyperledger/besu/cli/CascadingDefaultProviderTest.java
  9. 7
      besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java
  10. 2
      besu/src/test/java/org/hyperledger/besu/cli/options/MiningOptionsTest.java
  11. 4
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculatorTest.java
  12. 22
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/NodeCanProduceNextBlockTest.java
  13. 3
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java
  14. 4
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockMinerTest.java
  15. 3
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java
  16. 4
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java
  17. 4
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueExtraDataValidationRuleTest.java
  18. 10
      consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingProtocolContext.java
  19. 7
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java
  20. 13
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java
  21. 11
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java
  22. 4
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java
  23. 3
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java
  24. 1
      consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java
  25. 1
      consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/tests/round/IbftRoundIntegrationTest.java
  26. 1
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftBlockHeaderValidationRulesetFactoryTest.java
  27. 2
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java
  28. 1
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/blockcreation/BftBlockCreatorTest.java
  29. 6
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java
  30. 1
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftRoundTest.java
  31. 1
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/validation/MessageValidatorTest.java
  32. 3
      consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java
  33. 3
      consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeReorgTest.java
  34. 1
      consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java
  35. 2
      consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/test/round/QbftRoundIntegrationTest.java
  36. 1
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftBlockHeaderValidationRulesetFactoryTest.java
  37. 1
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleTest.java
  38. 4
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/headervalidationrules/QbftValidatorsValidationRuleTest.java
  39. 1
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java
  40. 1
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftRoundTest.java
  41. 7
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidatorTest.java
  42. 1
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalValidatorTest.java
  43. 1
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/RoundChangeMessageValidatorTest.java
  44. 4
      ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java
  45. 3
      ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByNumberLatestDesyncIntegrationTest.java
  46. 6
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java
  47. 1
      ethereum/blockcreation/build.gradle
  48. 7
      ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java
  49. 55
      ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/AllAcceptingTransactionSelector.java
  50. 105
      ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java
  51. 6
      ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockMinerTest.java
  52. 25
      ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java
  53. 18
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java
  54. 17
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParameters.java
  55. 2
      ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java
  56. 4
      ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java
  57. 3
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/AbstractIsolationTests.java
  58. 2
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/AbstractBlockPropagationManagerTest.java
  59. 4
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java
  60. 4
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java
  61. 4
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java
  62. 3
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java
  63. 3
      ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BlockchainReferenceTestCaseSpec.java
  64. 3
      ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java
  65. 2
      plugin-api/build.gradle
  66. 11
      plugin-api/src/main/java/org/hyperledger/besu/plugin/services/TransactionSelectionService.java
  67. 18
      plugin-api/src/main/java/org/hyperledger/besu/plugin/services/txselection/PluginTransactionSelector.java

@ -50,7 +50,6 @@ 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.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;
@ -94,6 +93,7 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
final BesuNode node,
final StorageServiceImpl storageService,
final SecurityModuleServiceImpl securityModuleService,
final TransactionSelectionServiceImpl transactionSelectionServiceImpl,
final BesuConfiguration commonPluginConfiguration) {
final CommandLine commandLine = new CommandLine(CommandSpec.create());
final BesuPluginContextImpl besuPluginContext = new BesuPluginContextImpl();
@ -102,7 +102,7 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
besuPluginContext.addService(PicoCLIOptions.class, new PicoCLIOptionsImpl(commandLine));
besuPluginContext.addService(RpcEndpointService.class, new RpcEndpointServiceImpl());
besuPluginContext.addService(
TransactionSelectionService.class, new TransactionSelectionServiceImpl());
TransactionSelectionService.class, transactionSelectionServiceImpl);
besuPluginContext.addService(
PluginTransactionValidatorService.class, new PluginTransactionValidatorServiceImpl());
final Path pluginsPath;
@ -144,6 +144,8 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
final StorageServiceImpl storageService = new StorageServiceImpl();
final SecurityModuleServiceImpl securityModuleService = new SecurityModuleServiceImpl();
final TransactionSelectionServiceImpl transactionSelectionServiceImpl =
new TransactionSelectionServiceImpl();
final Path dataDir = node.homeDirectory();
final BesuConfigurationImpl commonPluginConfiguration = new BesuConfigurationImpl();
commonPluginConfiguration.init(
@ -156,7 +158,11 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
node,
n ->
buildPluginContext(
node, storageService, securityModuleService, commonPluginConfiguration));
node,
storageService,
securityModuleService,
transactionSelectionServiceImpl,
commonPluginConfiguration));
GlobalOpenTelemetry.resetForTest();
final ObservableMetricsSystem metricsSystem =
@ -193,8 +199,8 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
final int maxPeers = 25;
final Optional<PluginTransactionSelectorFactory> transactionSelectorFactory =
getTransactionSelectorFactory(besuPluginContext);
final TransactionSelectionService transactionSelectorService =
getTransactionSelectorService(besuPluginContext);
final PluginTransactionValidatorFactory pluginTransactionValidatorFactory =
getPluginTransactionValidatorFactory(besuPluginContext);
@ -220,7 +226,7 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
.maxRemotelyInitiatedPeers(15)
.networkConfiguration(node.getNetworkingConfiguration())
.randomPeerPriority(false)
.transactionSelectorFactory(transactionSelectorFactory)
.transactionSelectorService(transactionSelectorService)
.pluginTransactionValidatorFactory(pluginTransactionValidatorFactory);
node.getGenesisConfig()
@ -332,11 +338,9 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
throw new RuntimeException("Console contents can only be captured in process execution");
}
private Optional<PluginTransactionSelectorFactory> getTransactionSelectorFactory(
private TransactionSelectionService getTransactionSelectorService(
final BesuPluginContextImpl besuPluginContext) {
final Optional<TransactionSelectionService> txSelectionService =
besuPluginContext.getService(TransactionSelectionService.class);
return txSelectionService.isPresent() ? txSelectionService.get().get() : Optional.empty();
return besuPluginContext.getService(TransactionSelectionService.class).orElseThrow();
}
private PluginTransactionValidatorFactory getPluginTransactionValidatorFactory(

@ -174,7 +174,6 @@ import org.hyperledger.besu.plugin.services.securitymodule.SecurityModule;
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.txselection.PluginTransactionSelectorFactory;
import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidatorFactory;
import org.hyperledger.besu.services.BesuConfigurationImpl;
import org.hyperledger.besu.services.BesuEventsImpl;
@ -224,7 +223,6 @@ import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
@ -1793,7 +1791,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
.synchronizerConfiguration(buildSyncConfig())
.ethProtocolConfiguration(unstableEthProtocolOptions.toDomainObject())
.networkConfiguration(unstableNetworkingOptions.toDomainObject())
.transactionSelectorFactory(getTransactionSelectorFactory())
.transactionSelectorService(getTransactionSelectorService())
.pluginTransactionValidatorFactory(getPluginTransactionValidatorFactory())
.dataDirectory(dataDir())
.dataStorageConfiguration(getDataStorageConfiguration())
@ -1825,11 +1823,8 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
.cacheLastBlocks(numberOfblocksToCache);
}
@Nonnull
private Optional<PluginTransactionSelectorFactory> getTransactionSelectorFactory() {
final Optional<TransactionSelectionService> 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() {
@ -2147,6 +2142,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
if (miningParameters == null) {
miningOptions.setGenesisBlockPeriodSeconds(
getGenesisBlockPeriodSeconds(getActualGenesisConfigOptions()));
miningOptions.setTransactionSelectionService(transactionSelectionServiceImpl);
miningParameters = miningOptions.toDomainObject();
initMiningParametersMetrics(miningParameters);
}

@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.cli.options;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME;
@ -37,6 +38,7 @@ import org.hyperledger.besu.datatypes.Wei;
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.plugin.services.TransactionSelectionService;
import org.hyperledger.besu.util.number.PositiveNumber;
import java.util.List;
@ -190,6 +192,7 @@ public class MiningOptions implements CLIOptions<MiningParameters> {
}
private OptionalInt maybeGenesisBlockPeriodSeconds;
private TransactionSelectionService transactionSelectionService;
private MiningOptions() {}
@ -212,6 +215,16 @@ public class MiningOptions implements CLIOptions<MiningParameters> {
maybeGenesisBlockPeriodSeconds = genesisBlockPeriodSeconds;
}
/**
* Set the transaction selection service
*
* @param transactionSelectionService the transaction selection service
*/
public void setTransactionSelectionService(
final TransactionSelectionService transactionSelectionService) {
this.transactionSelectionService = transactionSelectionService;
}
/**
* Validate that there are no inconsistencies in the specified options. For example that the
* options are valid for the selected implementation.
@ -299,6 +312,7 @@ public class MiningOptions implements CLIOptions<MiningParameters> {
static MiningOptions fromConfig(final MiningParameters miningParameters) {
final MiningOptions miningOptions = MiningOptions.create();
miningOptions.setGenesisBlockPeriodSeconds(miningParameters.getGenesisBlockPeriodSeconds());
miningOptions.setTransactionSelectionService(miningParameters.getTransactionSelectionService());
miningOptions.isMiningEnabled = miningParameters.isMiningEnabled();
miningOptions.iStratumMiningEnabled = miningParameters.isStratumMiningEnabled();
miningOptions.stratumNetworkInterface = miningParameters.getStratumNetworkInterface();
@ -333,10 +347,12 @@ public class MiningOptions implements CLIOptions<MiningParameters> {
@Override
public MiningParameters toDomainObject() {
if (maybeGenesisBlockPeriodSeconds == null) {
throw new IllegalStateException(
"genesisBlockPeriodSeconds must be set before using this object");
}
checkNotNull(
maybeGenesisBlockPeriodSeconds,
"genesisBlockPeriodSeconds must be set before using this object");
checkNotNull(
transactionSelectionService,
"transactionSelectionService must be set before using this object");
final var updatableInitValuesBuilder =
MutableInitValues.builder()
@ -355,6 +371,7 @@ public class MiningOptions implements CLIOptions<MiningParameters> {
return ImmutableMiningParameters.builder()
.genesisBlockPeriodSeconds(maybeGenesisBlockPeriodSeconds)
.transactionSelectionService(transactionSelectionService)
.mutableInitValues(updatableInitValuesBuilder.build())
.isStratumMiningEnabled(iStratumMiningEnabled)
.stratumNetworkInterface(stratumNetworkInterface)

@ -97,9 +97,9 @@ 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.MetricsSystem;
import org.hyperledger.besu.plugin.services.TransactionSelectionService;
import org.hyperledger.besu.plugin.services.permissioning.NodeMessagePermissioningProvider;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;
import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory;
import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidatorFactory;
import java.io.Closeable;
@ -187,7 +187,6 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
private NetworkingConfiguration networkingConfiguration;
private Boolean randomPeerPriority;
private Optional<PluginTransactionSelectorFactory> transactionSelectorFactory = Optional.empty();
/** the Dagger configured context that can provide dependencies */
protected Optional<BesuComponent> besuComponent = Optional.empty();
@ -535,14 +534,13 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
}
/**
* 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<PluginTransactionSelectorFactory> transactionSelectorFactory) {
this.transactionSelectorFactory = transactionSelectorFactory;
public BesuControllerBuilder transactionSelectorService(
final TransactionSelectionService transactionSelectionService) {
return this;
}
@ -617,11 +615,7 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
final ProtocolContext protocolContext =
createProtocolContext(
blockchain,
worldStateArchive,
protocolSchedule,
this::createConsensusContext,
transactionSelectorFactory);
blockchain, worldStateArchive, protocolSchedule, this::createConsensusContext);
validateContext(protocolContext);
if (chainPrunerConfiguration.getChainPruningEnabled()) {
@ -1057,22 +1051,15 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
* @param worldStateArchive the world state archive
* @param protocolSchedule the protocol schedule
* @param consensusContextFactory the consensus context factory
* @param transactionSelectorFactory optional transaction selector factory
* @return the protocol context
*/
protected ProtocolContext createProtocolContext(
final MutableBlockchain blockchain,
final WorldStateArchive worldStateArchive,
final ProtocolSchedule protocolSchedule,
final ConsensusContextFactory consensusContextFactory,
final Optional<PluginTransactionSelectorFactory> transactionSelectorFactory) {
final ConsensusContextFactory consensusContextFactory) {
return ProtocolContext.init(
blockchain,
worldStateArchive,
protocolSchedule,
consensusContextFactory,
transactionSelectorFactory,
badBlockManager);
blockchain, worldStateArchive, protocolSchedule, consensusContextFactory, badBlockManager);
}
private Optional<SnapProtocolManager> createSnapProtocolManager(

@ -62,7 +62,6 @@ 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.permissioning.NodeMessagePermissioningProvider;
import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory;
import java.math.BigInteger;
import java.nio.file.Path;
@ -175,15 +174,9 @@ public class ConsensusScheduleBesuControllerBuilder extends BesuControllerBuilde
final MutableBlockchain blockchain,
final WorldStateArchive worldStateArchive,
final ProtocolSchedule protocolSchedule,
final ConsensusContextFactory consensusContextFactory,
final Optional<PluginTransactionSelectorFactory> transactionSelectorFactory) {
final ConsensusContextFactory consensusContextFactory) {
return MigratingProtocolContext.init(
blockchain,
worldStateArchive,
protocolSchedule,
consensusContextFactory,
transactionSelectorFactory,
badBlockManager);
blockchain, worldStateArchive, protocolSchedule, consensusContextFactory, badBlockManager);
}
@Override

@ -60,7 +60,6 @@ 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.permissioning.NodeMessagePermissioningProvider;
import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory;
import java.math.BigInteger;
import java.nio.file.Path;
@ -189,15 +188,10 @@ public class TransitionBesuControllerBuilder extends BesuControllerBuilder {
final MutableBlockchain blockchain,
final WorldStateArchive worldStateArchive,
final ProtocolSchedule protocolSchedule,
final ConsensusContextFactory consensusContextFactory,
final Optional<PluginTransactionSelectorFactory> transactionSelectorFactory) {
final ConsensusContextFactory consensusContextFactory) {
final ProtocolContext protocolContext =
super.createProtocolContext(
blockchain,
worldStateArchive,
protocolSchedule,
consensusContextFactory,
transactionSelectorFactory);
blockchain, worldStateArchive, protocolSchedule, consensusContextFactory);
transitionProtocolSchedule.setProtocolContext(protocolContext);
return protocolContext;
}

@ -15,6 +15,7 @@
package org.hyperledger.besu.services;
import org.hyperledger.besu.plugin.services.TransactionSelectionService;
import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelector;
import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory;
import java.util.Optional;
@ -25,13 +26,15 @@ public class TransactionSelectionServiceImpl implements TransactionSelectionServ
private Optional<PluginTransactionSelectorFactory> factory = Optional.empty();
@Override
public Optional<PluginTransactionSelectorFactory> get() {
return factory;
public PluginTransactionSelector createPluginTransactionSelector() {
return factory
.map(PluginTransactionSelectorFactory::create)
.orElse(PluginTransactionSelector.ACCEPT_ALL);
}
@Override
public void registerTransactionSelectorFactory(
final PluginTransactionSelectorFactory transactionSelectorFactory) {
factory = Optional.ofNullable(transactionSelectorFactory);
public void registerPluginTransactionSelectorFactory(
final PluginTransactionSelectorFactory pluginTransactionSelectorFactory) {
factory = Optional.ofNullable(pluginTransactionSelectorFactory);
}
}

@ -32,7 +32,7 @@ import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration;
import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.eth.sync.SyncMode;
import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration;
import org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl;
@ -198,14 +198,11 @@ public class CascadingDefaultProviderTest extends CommandTestAbstract {
setEnvironmentVariable("BESU_MINER_COINBASE", expectedCoinbase);
parseCommand("--config-file", configFile);
verify(mockControllerBuilder)
.miningParameters(
ImmutableMiningParameters.builder()
.mutableInitValues(
ImmutableMiningParameters.MutableInitValues.builder()
.coinbase(Address.fromHexString(expectedCoinbase))
.build())
.build());
final var captMiningParameters = ArgumentCaptor.forClass(MiningParameters.class);
verify(mockControllerBuilder).miningParameters(captMiningParameters.capture());
assertThat(captMiningParameters.getValue().getCoinbase())
.contains(Address.fromHexString(expectedCoinbase));
}
/**
@ -220,14 +217,11 @@ public class CascadingDefaultProviderTest extends CommandTestAbstract {
setEnvironmentVariable("BESU_MINER_COINBASE", "0x0000000000000000000000000000000000000004");
parseCommand("--config-file", configFile, "--miner-coinbase", expectedCoinbase);
verify(mockControllerBuilder)
.miningParameters(
ImmutableMiningParameters.builder()
.mutableInitValues(
ImmutableMiningParameters.MutableInitValues.builder()
.coinbase(Address.fromHexString(expectedCoinbase))
.build())
.build());
final var captMiningParameters = ArgumentCaptor.forClass(MiningParameters.class);
verify(mockControllerBuilder).miningParameters(captMiningParameters.capture());
assertThat(captMiningParameters.getValue().getCoinbase())
.contains(Address.fromHexString(expectedCoinbase));
}
/**

@ -77,6 +77,7 @@ import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.pki.config.PkiKeyStoreConfiguration;
import org.hyperledger.besu.plugin.services.PicoCLIOptions;
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;
@ -206,6 +207,7 @@ public abstract class CommandTestAbstract {
@Mock protected JsonBlockImporter jsonBlockImporter;
@Mock protected RlpBlockImporter rlpBlockImporter;
@Mock protected StorageServiceImpl storageService;
@Mock protected TransactionSelectionServiceImpl txSelectionService;
@Mock protected SecurityModuleServiceImpl securityModuleService;
@Mock protected SecurityModule securityModule;
@Mock protected BesuConfigurationImpl commonPluginConfiguration;
@ -292,7 +294,7 @@ public abstract class CommandTestAbstract {
when(mockControllerBuilder.maxPeers(anyInt())).thenReturn(mockControllerBuilder);
when(mockControllerBuilder.maxRemotelyInitiatedPeers(anyInt()))
.thenReturn(mockControllerBuilder);
when(mockControllerBuilder.transactionSelectorFactory(any())).thenReturn(mockControllerBuilder);
when(mockControllerBuilder.transactionSelectorService(any())).thenReturn(mockControllerBuilder);
when(mockControllerBuilder.pluginTransactionValidatorFactory(any()))
.thenReturn(mockControllerBuilder);
when(mockControllerBuilder.besuComponent(any(BesuComponent.class)))
@ -380,6 +382,9 @@ public abstract class CommandTestAbstract {
lenient()
.when(mockBesuPluginContext.getService(StorageService.class))
.thenReturn(Optional.of(storageService));
lenient()
.when(mockBesuPluginContext.getService(TransactionSelectionService.class))
.thenReturn(Optional.of(txSelectionService));
lenient()
.doReturn(mockPkiBlockCreationConfiguration)

@ -422,6 +422,6 @@ public class MiningOptionsTest extends AbstractCLIOptionsTest<MiningParameters,
@Override
protected String[] getNonOptionFields() {
return new String[] {"maybeGenesisBlockPeriodSeconds"};
return new String[] {"maybeGenesisBlockPeriodSeconds", "transactionSelectionService"};
}
}

@ -32,7 +32,6 @@ import org.hyperledger.besu.ethereum.core.Util;
import java.math.BigInteger;
import java.util.List;
import java.util.Optional;
import com.google.common.collect.Lists;
import org.junit.jupiter.api.BeforeEach;
@ -59,8 +58,7 @@ public class CliqueDifficultyCalculatorTest {
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext =
new ProtocolContext(null, null, cliqueContext, Optional.empty(), new BadBlockManager());
cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext, new BadBlockManager());
blockHeaderBuilder = new BlockHeaderTestFixture();
}

@ -38,7 +38,6 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.Util;
import java.util.List;
import java.util.Optional;
import com.google.common.collect.Lists;
import org.junit.jupiter.api.BeforeEach;
@ -82,8 +81,7 @@ public class NodeCanProduceNextBlockTest {
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext =
new ProtocolContext(
blockChain, null, cliqueContext, Optional.empty(), new BadBlockManager());
new ProtocolContext(blockChain, null, cliqueContext, new BadBlockManager());
headerBuilder.number(1).parentHash(genesisBlock.getHash());
final Block block_1 = createEmptyBlock(proposerKeyPair);
@ -108,8 +106,7 @@ public class NodeCanProduceNextBlockTest {
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext =
new ProtocolContext(
blockChain, null, cliqueContext, Optional.empty(), new BadBlockManager());
new ProtocolContext(blockChain, null, cliqueContext, new BadBlockManager());
headerBuilder.number(1).parentHash(genesisBlock.getHash());
final Block block_1 = createEmptyBlock(proposerKeyPair);
@ -143,8 +140,7 @@ public class NodeCanProduceNextBlockTest {
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext =
new ProtocolContext(
blockChain, null, cliqueContext, Optional.empty(), new BadBlockManager());
new ProtocolContext(blockChain, null, cliqueContext, new BadBlockManager());
headerBuilder.parentHash(genesisBlock.getHash()).number(1);
final Block block_1 = createEmptyBlock(proposerKeyPair);
@ -174,8 +170,7 @@ public class NodeCanProduceNextBlockTest {
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext =
new ProtocolContext(
blockChain, null, cliqueContext, Optional.empty(), new BadBlockManager());
new ProtocolContext(blockChain, null, cliqueContext, new BadBlockManager());
headerBuilder.parentHash(genesisBlock.getHash()).number(1);
final Block block_1 = createEmptyBlock(proposerKeyPair);
@ -220,8 +215,7 @@ public class NodeCanProduceNextBlockTest {
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext =
new ProtocolContext(
blockChain, null, cliqueContext, Optional.empty(), new BadBlockManager());
new ProtocolContext(blockChain, null, cliqueContext, new BadBlockManager());
headerBuilder.parentHash(genesisBlock.getHash()).number(1);
final Block block_1 = createEmptyBlock(otherNodeKeyPair);
@ -250,8 +244,7 @@ public class NodeCanProduceNextBlockTest {
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext =
new ProtocolContext(
blockChain, null, cliqueContext, Optional.empty(), new BadBlockManager());
new ProtocolContext(blockChain, null, cliqueContext, new BadBlockManager());
headerBuilder.parentHash(Hash.ZERO).number(3);
final BlockHeader parentHeader =
@ -275,8 +268,7 @@ public class NodeCanProduceNextBlockTest {
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext =
new ProtocolContext(
blockChain, null, cliqueContext, Optional.empty(), new BadBlockManager());
new ProtocolContext(blockChain, null, cliqueContext, new BadBlockManager());
headerBuilder.parentHash(Hash.ZERO).number(3);
final BlockHeader parentHeader = headerBuilder.buildHeader();

@ -119,8 +119,7 @@ public class CliqueBlockCreatorTest {
GenesisState.fromConfig(GenesisConfigFile.mainnet(), protocolSchedule).getBlock();
blockchain = createInMemoryBlockchain(genesis);
protocolContext =
new ProtocolContext(
blockchain, stateArchive, cliqueContext, Optional.empty(), new BadBlockManager());
new ProtocolContext(blockchain, stateArchive, cliqueContext, new BadBlockManager());
epochManager = new EpochManager(10);
// Add a block above the genesis

@ -71,7 +71,7 @@ class CliqueBlockMinerTest {
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, null);
final ProtocolContext protocolContext =
new ProtocolContext(null, null, cliqueContext, Optional.empty(), new BadBlockManager());
new ProtocolContext(null, null, cliqueContext, new BadBlockManager());
final CliqueBlockCreator blockCreator = mock(CliqueBlockCreator.class);
final Function<BlockHeader, CliqueBlockCreator> blockCreatorSupplier =
@ -126,7 +126,7 @@ class CliqueBlockMinerTest {
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, null);
final ProtocolContext protocolContext =
new ProtocolContext(null, null, cliqueContext, Optional.empty(), new BadBlockManager());
new ProtocolContext(null, null, cliqueContext, new BadBlockManager());
final CliqueBlockCreator blockCreator = mock(CliqueBlockCreator.class);
final Function<BlockHeader, CliqueBlockCreator> blockCreatorSupplier =

@ -95,8 +95,7 @@ public class CliqueMinerExecutorTest {
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext =
new ProtocolContext(null, null, cliqueContext, Optional.empty(), new BadBlockManager());
cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext, new BadBlockManager());
cliqueProtocolSchedule =
CliqueProtocolSchedule.create(
GENESIS_CONFIG_OPTIONS,

@ -35,7 +35,6 @@ import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.core.Util;
import java.util.List;
import java.util.Optional;
import com.google.common.collect.Lists;
import org.junit.jupiter.api.BeforeEach;
@ -59,8 +58,7 @@ public class CliqueDifficultyValidationRuleTest {
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext =
new ProtocolContext(null, null, cliqueContext, Optional.empty(), new BadBlockManager());
cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext, new BadBlockManager());
blockHeaderBuilder = new BlockHeaderTestFixture();
}

@ -36,7 +36,6 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.Util;
import java.util.List;
import java.util.Optional;
import com.google.common.collect.Lists;
import org.apache.tuweni.bytes.Bytes;
@ -63,8 +62,7 @@ public class CliqueExtraDataValidationRuleTest {
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext =
new ProtocolContext(null, null, cliqueContext, Optional.empty(), new BadBlockManager());
cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext, new BadBlockManager());
}
@Test

@ -21,9 +21,6 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager;
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;
/** The Migrating protocol context. */
public class MigratingProtocolContext extends ProtocolContext {
@ -36,16 +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 badBlockManager the cache to use to keep invalid blocks
*/
public MigratingProtocolContext(
final MutableBlockchain blockchain,
final WorldStateArchive worldStateArchive,
final ForksSchedule<ConsensusContext> consensusContextSchedule,
final Optional<PluginTransactionSelectorFactory> transactionSelectorFactory,
final BadBlockManager badBlockManager) {
super(blockchain, worldStateArchive, null, transactionSelectorFactory, badBlockManager);
super(blockchain, worldStateArchive, null, badBlockManager);
this.consensusContextSchedule = consensusContextSchedule;
}
@ -56,7 +51,6 @@ public class MigratingProtocolContext extends ProtocolContext {
* @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 badBlockManager the cache to use to keep invalid blocks
* @return the protocol context
*/
@ -65,7 +59,6 @@ public class MigratingProtocolContext extends ProtocolContext {
final WorldStateArchive worldStateArchive,
final ProtocolSchedule protocolSchedule,
final ConsensusContextFactory consensusContextFactory,
final Optional<PluginTransactionSelectorFactory> transactionSelectorFactory,
final BadBlockManager badBlockManager) {
final ConsensusContext consensusContext =
consensusContextFactory.create(blockchain, worldStateArchive, protocolSchedule);
@ -74,7 +67,6 @@ public class MigratingProtocolContext extends ProtocolContext {
blockchain,
worldStateArchive,
migratingContext.getConsensusContextSchedule(),
transactionSelectorFactory,
badBlockManager);
}

@ -24,7 +24,6 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
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;
@ -46,11 +45,7 @@ public class MigratingProtocolContextTest {
new ForksSchedule<>(List.of(new ForkSpec<>(0L, context1), new ForkSpec<>(10L, context2)));
final MigratingProtocolContext migratingProtocolContext =
new MigratingProtocolContext(
blockchain,
worldStateArchive,
contextSchedule,
Optional.empty(),
new BadBlockManager());
blockchain, worldStateArchive, contextSchedule, new BadBlockManager());
assertThat(migratingProtocolContext.getConsensusContext(ConsensusContext.class))
.isSameAs(context1);

@ -28,7 +28,6 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.Util;
import java.util.List;
import java.util.Optional;
import com.google.common.collect.Lists;
import org.junit.jupiter.api.Test;
@ -53,11 +52,7 @@ public class BftCoinbaseValidationRuleTest {
final ProtocolContext context =
new ProtocolContext(
null,
null,
setupContextWithValidators(validators),
Optional.empty(),
new BadBlockManager());
null, null, setupContextWithValidators(validators), new BadBlockManager());
final BftCoinbaseValidationRule coinbaseValidationRule = new BftCoinbaseValidationRule();
@ -78,11 +73,7 @@ public class BftCoinbaseValidationRuleTest {
final ProtocolContext context =
new ProtocolContext(
null,
null,
setupContextWithValidators(validators),
Optional.empty(),
new BadBlockManager());
null, null, setupContextWithValidators(validators), new BadBlockManager());
final BftCoinbaseValidationRule coinbaseValidationRule = new BftCoinbaseValidationRule();

@ -34,7 +34,6 @@ import org.hyperledger.besu.ethereum.core.Util;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@ -60,7 +59,7 @@ public class BftCommitSealsValidationRuleTest {
final BftContext bftContext = setupContextWithValidators(committerAddresses);
final ProtocolContext context =
new ProtocolContext(null, null, bftContext, Optional.empty(), new BadBlockManager());
new ProtocolContext(null, null, bftContext, new BadBlockManager());
when(bftContext.getBlockInterface().getCommitters(any())).thenReturn(committerAddresses);
assertThat(commitSealsValidationRule.validate(blockHeader, null, context)).isTrue();
@ -75,7 +74,7 @@ public class BftCommitSealsValidationRuleTest {
final List<Address> validators = singletonList(committerAddress);
final BftContext bftContext = setupContextWithValidators(validators);
final ProtocolContext context =
new ProtocolContext(null, null, bftContext, Optional.empty(), new BadBlockManager());
new ProtocolContext(null, null, bftContext, new BadBlockManager());
when(bftContext.getBlockInterface().getCommitters(any())).thenReturn(emptyList());
assertThat(commitSealsValidationRule.validate(blockHeader, null, context)).isFalse();
@ -93,7 +92,7 @@ public class BftCommitSealsValidationRuleTest {
final BftContext bftContext = setupContextWithValidators(validators);
final ProtocolContext context =
new ProtocolContext(null, null, bftContext, Optional.empty(), new BadBlockManager());
new ProtocolContext(null, null, bftContext, new BadBlockManager());
when(bftContext.getBlockInterface().getCommitters(any()))
.thenReturn(singletonList(Util.publicKeyToAddress(nonValidatorNodeKey.getPublicKey())));
@ -141,7 +140,7 @@ public class BftCommitSealsValidationRuleTest {
final BftContext bftContext = setupContextWithValidators(validators);
final ProtocolContext context =
new ProtocolContext(null, null, bftContext, Optional.empty(), new BadBlockManager());
new ProtocolContext(null, null, bftContext, new BadBlockManager());
when(bftContext.getBlockInterface().getCommitters(any()))
.thenReturn(List.of(committerAddress, committerAddress));
@ -161,7 +160,7 @@ public class BftCommitSealsValidationRuleTest {
final BftContext bftContext = setupContextWithValidators(validators);
final ProtocolContext context =
new ProtocolContext(null, null, bftContext, Optional.empty(), new BadBlockManager());
new ProtocolContext(null, null, bftContext, new BadBlockManager());
when(bftContext.getBlockInterface().getCommitters(any()))
.thenReturn(validators.subList(0, committerCount));

@ -27,7 +27,6 @@ import org.hyperledger.besu.ethereum.core.AddressHelpers;
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;
@ -50,7 +49,6 @@ public class BftValidatorsValidationRuleTest {
null,
null,
setupContextWithBftExtraData(validators, bftExtraData),
Optional.empty(),
new BadBlockManager());
when(bftExtraData.getValidators()).thenReturn(validators);
@ -69,7 +67,6 @@ public class BftValidatorsValidationRuleTest {
null,
null,
setupContextWithBftExtraData(validators, bftExtraData),
Optional.empty(),
new BadBlockManager());
when(bftExtraData.getValidators()).thenReturn(Lists.reverse(validators));
@ -91,7 +88,6 @@ public class BftValidatorsValidationRuleTest {
null,
null,
setupContextWithBftExtraData(storedValidators, bftExtraData),
Optional.empty(),
new BadBlockManager());
when(bftExtraData.getValidators()).thenReturn(Lists.reverse(reportedValidators));

@ -25,8 +25,6 @@ import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes;
import org.junit.jupiter.api.Test;
@ -51,7 +49,6 @@ public class BftVanityDataValidationRuleTest {
null,
null,
setupContextWithBftExtraData(emptyList(), extraData),
Optional.empty(),
new BadBlockManager());
return validationRule.validate(blockHeader, null, context);
}

@ -349,7 +349,6 @@ public class TestContextBuilder {
blockChain,
worldStateArchive,
new BftContext(validatorProvider, epochManager, blockInterface),
Optional.empty(),
new BadBlockManager());
final TransactionPoolConfiguration poolConf =
ImmutableTransactionPoolConfiguration.builder().txPoolMaxSize(1).build();

@ -127,7 +127,6 @@ public class IbftRoundIntegrationTest {
blockChain,
worldStateArchive,
setupContextWithBftExtraDataEncoder(emptyList(), bftExtraDataEncoder),
Optional.empty(),
new BadBlockManager());
}

@ -52,7 +52,6 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
null,
null,
setupContextWithBftExtraDataEncoder(validators, new IbftExtraDataCodec()),
Optional.empty(),
new BadBlockManager());
}

@ -48,7 +48,6 @@ import org.hyperledger.besu.evm.internal.EvmConfiguration;
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;
@ -123,7 +122,6 @@ public class IbftProtocolScheduleTest {
null,
null,
setupContextWithBftExtraDataEncoder(BftContext.class, validators, bftExtraDataCodec),
Optional.empty(),
new BadBlockManager());
}
}

@ -126,7 +126,6 @@ public class BftBlockCreatorTest {
blockchain,
createInMemoryWorldStateArchive(),
setupContextWithBftExtraDataEncoder(initialValidatorList, bftExtraDataEncoder),
Optional.empty(),
new BadBlockManager());
final TransactionPoolConfiguration poolConf =

@ -169,11 +169,7 @@ public class IbftBlockHeightManagerTest {
protocolContext =
new ProtocolContext(
blockchain,
null,
setupContextWithValidators(validators),
Optional.empty(),
new BadBlockManager());
blockchain, null, setupContextWithValidators(validators), new BadBlockManager());
final ProtocolScheduleBuilder protocolScheduleBuilder =
new ProtocolScheduleBuilder(

@ -113,7 +113,6 @@ public class IbftRoundTest {
blockChain,
worldStateArchive,
setupContextWithBftExtraDataEncoder(emptyList(), new IbftExtraDataCodec()),
Optional.empty(),
new BadBlockManager());
lenient().when(messageValidator.validateProposal(any())).thenReturn(true);

@ -105,7 +105,6 @@ public class MessageValidatorTest {
mock(MutableBlockchain.class),
mock(WorldStateArchive.class),
mockBftCtx,
Optional.empty(),
new BadBlockManager());
lenient()

@ -187,8 +187,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
.thenReturn(genesisState.getBlock().getHeader().getDifficulty().plus(1L));
protocolContext =
new ProtocolContext(
blockchain, worldStateArchive, mergeContext, Optional.empty(), badBlockManager);
new ProtocolContext(blockchain, worldStateArchive, mergeContext, badBlockManager);
var mutable = worldStateArchive.getMutable();
genesisState.writeStateTo(mutable);
mutable.persist(null);

@ -76,8 +76,7 @@ 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 BadBlockManager());
new ProtocolContext(blockchain, worldStateArchive, mergeContext, new BadBlockManager());
private final Address coinbase = genesisAllocations(getPowGenesisConfigFile()).findFirst().get();
private final BlockHeaderTestFixture headerGenerator = new BlockHeaderTestFixture();

@ -446,7 +446,6 @@ public class TestContextBuilder {
blockChain,
worldStateArchive,
new QbftContext(validatorProvider, epochManager, blockInterface, Optional.empty()),
Optional.empty(),
new BadBlockManager());
final TransactionPoolConfiguration poolConf =

@ -58,7 +58,6 @@ import org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleExcepti
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;
@ -131,7 +130,6 @@ public class QbftRoundIntegrationTest {
worldStateArchive,
setupContextWithBftExtraDataEncoder(
QbftContext.class, emptyList(), qbftExtraDataEncoder),
Optional.empty(),
new BadBlockManager());
}

@ -47,7 +47,6 @@ public class QbftBlockHeaderValidationRulesetFactoryTest {
null,
setupContextWithBftExtraDataEncoder(
QbftContext.class, validators, new QbftExtraDataCodec()),
Optional.empty(),
new BadBlockManager());
}

@ -59,7 +59,6 @@ public class QbftProtocolScheduleTest {
null,
setupContextWithBftExtraDataEncoder(
QbftContext.class, validators, new QbftExtraDataCodec()),
Optional.empty(),
new BadBlockManager());
}

@ -48,7 +48,6 @@ public class QbftValidatorsValidationRuleTest {
null,
null,
setupContextWithBftExtraData(QbftContext.class, Collections.emptyList(), bftExtraData),
Optional.empty(),
new BadBlockManager());
when(bftExtraData.getValidators()).thenReturn(Collections.emptyList());
when(bftExtraData.getVote()).thenReturn(Optional.empty());
@ -68,7 +67,6 @@ public class QbftValidatorsValidationRuleTest {
null,
null,
setupContextWithBftExtraData(QbftContext.class, validators, bftExtraData),
Optional.empty(),
new BadBlockManager());
when(bftExtraData.getValidators()).thenReturn(validators);
assertThat(qbftValidatorsValidationRule.validate(blockHeader, null, context)).isTrue();
@ -87,7 +85,6 @@ public class QbftValidatorsValidationRuleTest {
null,
null,
setupContextWithBftExtraData(QbftContext.class, validators, bftExtraData),
Optional.empty(),
new BadBlockManager());
when(bftExtraData.getValidators()).thenReturn(validators);
assertThat(qbftValidatorsValidationRule.validate(blockHeader, null, context)).isFalse();
@ -102,7 +99,6 @@ public class QbftValidatorsValidationRuleTest {
null,
null,
setupContextWithBftExtraData(QbftContext.class, Collections.emptyList(), bftExtraData),
Optional.empty(),
new BadBlockManager());
when(bftExtraData.getValidators()).thenReturn(Collections.emptyList());
when(bftExtraData.getVote()).thenReturn(Optional.of(mock(Vote.class)));

@ -169,7 +169,6 @@ public class QbftBlockHeightManagerTest {
null,
setupContextWithBftExtraDataEncoder(
QbftContext.class, validators, new QbftExtraDataCodec()),
Optional.empty(),
new BadBlockManager());
final ProtocolScheduleBuilder protocolScheduleBuilder =

@ -123,7 +123,6 @@ public class QbftRoundTest {
worldStateArchive,
setupContextWithBftExtraDataEncoder(
QbftContext.class, emptyList(), new QbftExtraDataCodec()),
Optional.empty(),
new BadBlockManager());
when(messageValidator.validateProposal(any())).thenReturn(true);

@ -88,7 +88,6 @@ public class ProposalPayloadValidatorTest {
blockChain,
worldStateArchive,
setupContextWithBftExtraDataEncoder(QbftContext.class, emptyList(), bftExtraDataCodec),
Optional.empty(),
new BadBlockManager());
}
@ -242,8 +241,7 @@ public class ProposalPayloadValidatorTest {
setupContextWithBftExtraDataEncoder(QbftContext.class, emptyList(), pkiQbftExtraDataCodec);
final Bytes cms = Bytes.fromHexStringLenient("0x1");
final ProtocolContext protocolContext =
new ProtocolContext(
blockChain, worldStateArchive, qbftContext, Optional.empty(), new BadBlockManager());
new ProtocolContext(blockChain, worldStateArchive, qbftContext, new BadBlockManager());
final ProposalPayloadValidator payloadValidator =
new ProposalPayloadValidator(
@ -278,8 +276,7 @@ public class ProposalPayloadValidatorTest {
setupContextWithBftExtraDataEncoder(QbftContext.class, emptyList(), pkiQbftExtraDataCodec);
final Bytes cms = Bytes.fromHexStringLenient("0x1");
final ProtocolContext protocolContext =
new ProtocolContext(
blockChain, worldStateArchive, qbftContext, Optional.empty(), new BadBlockManager());
new ProtocolContext(blockChain, worldStateArchive, qbftContext, new BadBlockManager());
final ProposalPayloadValidator payloadValidator =
new ProposalPayloadValidator(

@ -104,7 +104,6 @@ public class ProposalValidatorTest {
worldStateArchive,
setupContextWithBftExtraDataEncoder(
QbftContext.class, emptyList(), bftExtraDataEncoder),
Optional.empty(),
new BadBlockManager());
// typically tests require the blockValidation to be successful

@ -86,7 +86,6 @@ public class RoundChangeMessageValidatorTest {
worldStateArchive,
setupContextWithBftExtraDataEncoder(
QbftContext.class, emptyList(), bftExtraDataEncoder),
Optional.empty(),
new BadBlockManager());
lenient().when(protocolSchedule.getByBlockHeader(any())).thenReturn(protocolSpec);

@ -79,9 +79,7 @@ public class JsonRpcTestMethodsFactory {
this.blockchain = createInMemoryBlockchain(importer.getGenesisBlock());
this.stateArchive = createInMemoryWorldStateArchive();
this.importer.getGenesisState().writeStateTo(stateArchive.getMutable());
this.context =
new ProtocolContext(
blockchain, stateArchive, null, Optional.empty(), new BadBlockManager());
this.context = new ProtocolContext(blockchain, stateArchive, null, new BadBlockManager());
final ProtocolSchedule protocolSchedule = importer.getProtocolSchedule();
this.synchronizer = mock(Synchronizer.class);

@ -68,8 +68,7 @@ public class EthGetBlockByNumberLatestDesyncIntegrationTest {
InMemoryKeyValueStorageProvider.createInMemoryBlockchain(importer.getGenesisBlock());
WorldStateArchive state = InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive();
importer.getGenesisState().writeStateTo(state.getMutable());
ProtocolContext context =
new ProtocolContext(chain, state, null, Optional.empty(), new BadBlockManager());
ProtocolContext context = new ProtocolContext(chain, state, null, new BadBlockManager());
for (final Block block : importer.getBlocks()) {
final ProtocolSchedule protocolSchedule = importer.getProtocolSchedule();

@ -109,11 +109,7 @@ public abstract class AbstractEthGraphQLHttpServiceTest {
final MutableBlockchain blockchain = blockchainSetupUtil.getBlockchain();
ProtocolContext context =
new ProtocolContext(
blockchain,
blockchainSetupUtil.getWorldArchive(),
null,
Optional.empty(),
new BadBlockManager());
blockchain, blockchainSetupUtil.getWorldArchive(), null, new BadBlockManager());
final BlockchainQueries blockchainQueries =
new BlockchainQueries(
context.getBlockchain(),

@ -27,6 +27,7 @@ dependencies {
implementation 'io.tmio:tuweni-bytes'
implementation 'io.tmio:tuweni-units'
testImplementation project(':besu')
testImplementation project(path: ':config', configuration: 'testSupportArtifacts')
testImplementation project(path: ':ethereum:core', configuration: 'testArtifacts')
testImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')

@ -24,7 +24,6 @@ import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.blockcreation.txselection.BlockTransactionSelector;
import org.hyperledger.besu.ethereum.blockcreation.txselection.TransactionSelectionResults;
import org.hyperledger.besu.ethereum.blockcreation.txselection.selectors.AllAcceptingTransactionSelector;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockBody;
import org.hyperledger.besu.ethereum.core.BlockHeader;
@ -60,7 +59,6 @@ import org.hyperledger.besu.plugin.services.exception.StorageException;
import org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException;
import org.hyperledger.besu.plugin.services.tracer.BlockAwareOperationTracer;
import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelector;
import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory;
import java.math.BigInteger;
import java.util.List;
@ -192,10 +190,7 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator {
throwIfStopped();
final PluginTransactionSelector pluginTransactionSelector =
protocolContext
.getTransactionSelectorFactory()
.map(PluginTransactionSelectorFactory::create)
.orElseGet(() -> AllAcceptingTransactionSelector.INSTANCE);
miningParameters.getTransactionSelectionService().createPluginTransactionSelector();
final BlockAwareOperationTracer operationTracer =
pluginTransactionSelector.getOperationTracer();

@ -1,55 +0,0 @@
/*
* 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.ethereum.blockcreation.txselection.selectors;
import org.hyperledger.besu.datatypes.PendingTransaction;
import org.hyperledger.besu.plugin.data.TransactionProcessingResult;
import org.hyperledger.besu.plugin.data.TransactionSelectionResult;
import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelector;
import org.hyperledger.besu.plugin.services.txselection.TransactionEvaluationContext;
/** A TransactionSelector that unconditionally selects all transactions. */
public class AllAcceptingTransactionSelector implements PluginTransactionSelector {
public static final AllAcceptingTransactionSelector INSTANCE =
new AllAcceptingTransactionSelector();
private AllAcceptingTransactionSelector() {}
/**
* Always selects the transaction in the pre-processing stage.
*
* @param evaluationContext The current selection context.
* @return Always SELECTED.
*/
@Override
public TransactionSelectionResult evaluateTransactionPreProcessing(
final TransactionEvaluationContext<? extends PendingTransaction> evaluationContext) {
return TransactionSelectionResult.SELECTED;
}
/**
* Always selects the transaction in the post-processing stage.
*
* @param evaluationContext The current selection context.
* @param processingResult The result of the transaction processing.
* @return Always SELECTED.
*/
@Override
public TransactionSelectionResult evaluateTransactionPostProcessing(
final TransactionEvaluationContext<? extends PendingTransaction> evaluationContext,
final TransactionProcessingResult processingResult) {
return TransactionSelectionResult.SELECTED;
}
}

@ -27,7 +27,6 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ -43,7 +42,6 @@ import org.hyperledger.besu.ethereum.GasLimitCalculator;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.blockcreation.txselection.BlockTransactionSelector;
import org.hyperledger.besu.ethereum.blockcreation.txselection.TransactionSelectionResults;
import org.hyperledger.besu.ethereum.blockcreation.txselection.selectors.AllAcceptingTransactionSelector;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.DefaultBlockchain;
import org.hyperledger.besu.ethereum.chain.GenesisState;
@ -82,9 +80,11 @@ import org.hyperledger.besu.evm.worldstate.WorldState;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.data.TransactionSelectionResult;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.TransactionSelectionService;
import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelector;
import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory;
import org.hyperledger.besu.plugin.services.txselection.TransactionEvaluationContext;
import org.hyperledger.besu.services.TransactionSelectionServiceImpl;
import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage;
import org.hyperledger.besu.util.number.PositiveNumber;
@ -121,8 +121,6 @@ import org.mockito.stubbing.Answer;
public abstract class AbstractBlockTransactionSelectorTest {
protected static final double MIN_OCCUPANCY_80_PERCENT = 0.8;
protected static final double MIN_OCCUPANCY_100_PERCENT = 1;
protected static final PluginTransactionSelectorFactory NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY =
() -> AllAcceptingTransactionSelector.INSTANCE;
protected static final BigInteger CHAIN_ID = BigInteger.valueOf(42L);
protected static final KeyPair keyPair =
SignatureAlgorithmFactory.getInstance().generateKeyPair();
@ -135,9 +133,8 @@ public abstract class AbstractBlockTransactionSelectorTest {
protected TransactionPool transactionPool;
protected MutableWorldState worldState;
protected ProtocolSchedule protocolSchedule;
protected final MiningParameters defaultTestMiningParameters =
createMiningParameters(
Wei.ZERO, MIN_OCCUPANCY_80_PERCENT, DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME);
protected TransactionSelectionService transactionSelectionService;
protected MiningParameters defaultTestMiningParameters;
@Mock protected EthScheduler ethScheduler;
@ -153,6 +150,14 @@ public abstract class AbstractBlockTransactionSelectorTest {
public void setup() {
genesisConfigFile = getGenesisConfigFile();
protocolSchedule = createProtocolSchedule();
transactionSelectionService = new TransactionSelectionServiceImpl();
defaultTestMiningParameters =
createMiningParameters(
transactionSelectionService,
Wei.ZERO,
MIN_OCCUPANCY_80_PERCENT,
DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME);
final Block genesisBlock =
GenesisState.fromConfig(genesisConfigFile, protocolSchedule).getBlock();
@ -228,7 +233,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
blockHeader,
miningBeneficiary,
Wei.ZERO,
NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY);
transactionSelectionService);
final TransactionSelectionResults results = selector.buildTransactionListForBlock();
@ -249,7 +254,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
blockHeader,
miningBeneficiary,
Wei.ZERO,
NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY);
transactionSelectionService);
final Transaction transaction = createTransaction(1, Wei.of(7L), 100_000);
transactionPool.addRemoteTransactions(List.of(transaction));
@ -276,7 +281,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
blockHeader,
miningBeneficiary,
Wei.ZERO,
NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY);
transactionSelectionService);
final List<Transaction> transactionsToInject = Lists.newArrayList();
for (int i = 0; i < 5; i++) {
@ -317,7 +322,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
blockHeader,
miningBeneficiary,
Wei.ZERO,
NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY);
transactionSelectionService);
final List<Transaction> transactionsToInject = Lists.newArrayList();
for (int i = 0; i < 5; i++) {
@ -358,7 +363,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
blockHeader,
miningBeneficiary,
Wei.ZERO,
NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY);
transactionSelectionService);
// Add 3 transactions to the Pending Transactions, 79% of block, 100% of block and 10% of block
// should end up selecting the first and third only.
@ -393,7 +398,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
blockHeader,
miningBeneficiary,
Wei.ZERO,
NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY);
transactionSelectionService);
// Add 4 transactions to the Pending Transactions 15% (ok), 79% (ok), 25% (too large), 10%
// (not included, it would fit, however previous transaction was too large and block was
@ -427,12 +432,15 @@ public abstract class AbstractBlockTransactionSelectorTest {
final BlockTransactionSelector selector =
createBlockSelectorAndSetupTxPool(
createMiningParameters(
Wei.ZERO, MIN_OCCUPANCY_100_PERCENT, DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME),
transactionSelectionService,
Wei.ZERO,
MIN_OCCUPANCY_100_PERCENT,
DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME),
transactionProcessor,
blockHeader,
miningBeneficiary,
Wei.ZERO,
NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY);
transactionSelectionService);
final long minTxGasCost = getGasCalculator().getMinimumTransactionCost();
@ -486,12 +494,15 @@ public abstract class AbstractBlockTransactionSelectorTest {
final BlockTransactionSelector selector =
createBlockSelectorAndSetupTxPool(
createMiningParameters(
Wei.ZERO, MIN_OCCUPANCY_100_PERCENT, DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME),
transactionSelectionService,
Wei.ZERO,
MIN_OCCUPANCY_100_PERCENT,
DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME),
transactionProcessor,
blockHeader,
miningBeneficiary,
Wei.ZERO,
NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY);
transactionSelectionService);
final long minTxGasCost = getGasCalculator().getMinimumTransactionCost();
@ -543,7 +554,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
blockHeader,
miningBeneficiary,
Wei.ZERO,
NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY);
transactionSelectionService);
final Transaction validTransaction = createTransaction(0, Wei.of(10), 21_000);
@ -610,6 +621,8 @@ public abstract class AbstractBlockTransactionSelectorTest {
return SELECTED;
}
};
transactionSelectionService.registerPluginTransactionSelectorFactory(
transactionSelectorFactory);
final BlockTransactionSelector selector =
createBlockSelectorAndSetupTxPool(
@ -618,7 +631,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
blockHeader,
miningBeneficiary,
Wei.ZERO,
transactionSelectorFactory);
transactionSelectionService);
transactionPool.addRemoteTransactions(
List.of(selected, notSelectedTransient, notSelectedInvalid));
@ -676,17 +689,22 @@ public abstract class AbstractBlockTransactionSelectorTest {
return SELECTED;
}
};
transactionSelectionService.registerPluginTransactionSelectorFactory(
transactionSelectorFactory);
final Address miningBeneficiary = AddressHelpers.ofValue(1);
final BlockTransactionSelector selector =
createBlockSelectorAndSetupTxPool(
createMiningParameters(
Wei.ZERO, MIN_OCCUPANCY_80_PERCENT, DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME),
transactionSelectionService,
Wei.ZERO,
MIN_OCCUPANCY_80_PERCENT,
DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME),
transactionProcessor,
blockHeader,
miningBeneficiary,
Wei.ZERO,
transactionSelectorFactory);
transactionSelectionService);
transactionPool.addRemoteTransactions(List.of(selected, notSelected, selected3));
@ -703,9 +721,14 @@ public abstract class AbstractBlockTransactionSelectorTest {
public void transactionSelectionPluginShouldBeNotifiedWhenTransactionSelectionCompletes() {
final PluginTransactionSelectorFactory transactionSelectorFactory =
mock(PluginTransactionSelectorFactory.class);
PluginTransactionSelector transactionSelector = spy(AllAcceptingTransactionSelector.INSTANCE);
PluginTransactionSelector transactionSelector = mock(PluginTransactionSelector.class);
when(transactionSelector.evaluateTransactionPreProcessing(any())).thenReturn(SELECTED);
when(transactionSelector.evaluateTransactionPostProcessing(any(), any())).thenReturn(SELECTED);
when(transactionSelectorFactory.create()).thenReturn(transactionSelector);
transactionSelectionService.registerPluginTransactionSelectorFactory(
transactionSelectorFactory);
final Transaction transaction = createTransaction(0, Wei.of(10), 21_000);
ensureTransactionIsValid(transaction, 21_000, 0);
@ -720,7 +743,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
createBlock(300_000),
AddressHelpers.ofValue(1),
Wei.ZERO,
transactionSelectorFactory);
transactionSelectionService);
transactionPool.addRemoteTransactions(List.of(transaction, invalidTransaction));
@ -756,7 +779,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
blockHeader,
miningBeneficiary,
Wei.ZERO,
NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY);
transactionSelectionService);
final Transaction futureTransaction = createTransaction(4, Wei.of(10), 100_000);
@ -792,7 +815,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
blockHeader,
miningBeneficiary,
Wei.ZERO,
NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY);
transactionSelectionService);
transactionPool.addRemoteTransactions(List.of(transaction));
@ -828,7 +851,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
blockHeader,
miningBeneficiary,
Wei.ZERO,
NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY);
transactionSelectionService);
transactionPool.addRemoteTransactions(List.of(transaction));
ensureTransactionIsValid(transaction, 0, 5);
@ -856,7 +879,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
blockHeader,
miningBeneficiary,
Wei.ZERO,
NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY);
transactionSelectionService);
final TransactionSelectionResults results2 = selector2.buildTransactionListForBlock();
@ -884,7 +907,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
blockHeader,
AddressHelpers.ofValue(1),
Wei.ZERO,
NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY);
transactionSelectionService);
transactionPool.addRemoteTransactions(List.of(txSelected, txNotSelected));
@ -987,15 +1010,20 @@ public abstract class AbstractBlockTransactionSelectorTest {
mock(PluginTransactionSelectorFactory.class);
when(transactionSelectorFactory.create()).thenReturn(transactionSelector);
transactionSelectionService.registerPluginTransactionSelectorFactory(
transactionSelectorFactory);
final BlockTransactionSelector selector =
createBlockSelectorAndSetupTxPool(
isPoa
? createMiningParameters(
transactionSelectionService,
Wei.ZERO,
MIN_OCCUPANCY_100_PERCENT,
poaGenesisBlockPeriod,
PositiveNumber.fromInt(75))
: createMiningParameters(
transactionSelectionService,
Wei.ZERO,
MIN_OCCUPANCY_100_PERCENT,
PositiveNumber.fromInt(blockTxsSelectionMaxTime)),
@ -1003,7 +1031,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
blockHeader,
miningBeneficiary,
Wei.ZERO,
transactionSelectorFactory);
transactionSelectionService);
transactionPool.addRemoteTransactions(transactionsToInject);
@ -1136,15 +1164,20 @@ public abstract class AbstractBlockTransactionSelectorTest {
mock(PluginTransactionSelectorFactory.class);
when(transactionSelectorFactory.create()).thenReturn(transactionSelector);
transactionSelectionService.registerPluginTransactionSelectorFactory(
transactionSelectorFactory);
final BlockTransactionSelector selector =
createBlockSelectorAndSetupTxPool(
isPoa
? createMiningParameters(
transactionSelectionService,
Wei.ZERO,
MIN_OCCUPANCY_100_PERCENT,
poaGenesisBlockPeriod,
PositiveNumber.fromInt(75))
: createMiningParameters(
transactionSelectionService,
Wei.ZERO,
MIN_OCCUPANCY_100_PERCENT,
PositiveNumber.fromInt(blockTxsSelectionMaxTime)),
@ -1152,7 +1185,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
blockHeader,
miningBeneficiary,
Wei.ZERO,
transactionSelectorFactory);
transactionSelectionService);
transactionPool.addRemoteTransactions(transactionsToInject);
@ -1195,7 +1228,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
final ProcessableBlockHeader blockHeader,
final Address miningBeneficiary,
final Wei blobGasPrice,
final PluginTransactionSelectorFactory transactionSelectorFactory) {
final TransactionSelectionService transactionSelectionService) {
transactionPool = createTransactionPool();
@ -1205,7 +1238,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
blockHeader,
miningBeneficiary,
blobGasPrice,
transactionSelectorFactory);
transactionSelectionService);
}
protected BlockTransactionSelector createBlockSelector(
@ -1214,7 +1247,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
final ProcessableBlockHeader blockHeader,
final Address miningBeneficiary,
final Wei blobGasPrice,
final PluginTransactionSelectorFactory transactionSelectorFactory) {
final TransactionSelectionService transactionSelectionService) {
final BlockTransactionSelector selector =
new BlockTransactionSelector(
@ -1231,7 +1264,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
getFeeMarket(),
new LondonGasCalculator(),
GasLimitCalculator.constant(),
transactionSelectorFactory.create(),
transactionSelectionService.createPluginTransactionSelector(),
ethScheduler);
return selector;
@ -1344,6 +1377,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
}
protected MiningParameters createMiningParameters(
final TransactionSelectionService transactionSelectionService,
final Wei minGasPrice,
final double minBlockOccupancyRatio,
final PositiveNumber txsSelectionMaxTime) {
@ -1353,11 +1387,13 @@ public abstract class AbstractBlockTransactionSelectorTest {
.minTransactionGasPrice(minGasPrice)
.minBlockOccupancyRatio(minBlockOccupancyRatio)
.build())
.transactionSelectionService(transactionSelectionService)
.nonPoaBlockTxsSelectionMaxTime(txsSelectionMaxTime)
.build();
}
protected MiningParameters createMiningParameters(
final TransactionSelectionService transactionSelectionService,
final Wei minGasPrice,
final double minBlockOccupancyRatio,
final int genesisBlockPeriodSeconds,
@ -1368,6 +1404,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
.minTransactionGasPrice(minGasPrice)
.minBlockOccupancyRatio(minBlockOccupancyRatio)
.build())
.transactionSelectionService(transactionSelectionService)
.genesisBlockPeriodSeconds(genesisBlockPeriodSeconds)
.poaBlockTxsSelectionMaxTime(minBlockTimePercentage)
.build();

@ -58,7 +58,7 @@ public class BlockMinerTest {
headerBuilder.buildHeader(), new BlockBody(Lists.newArrayList(), Lists.newArrayList()));
final ProtocolContext protocolContext =
new ProtocolContext(null, null, null, Optional.empty(), new BadBlockManager());
new ProtocolContext(null, null, null, new BadBlockManager());
final PoWBlockCreator blockCreator = mock(PoWBlockCreator.class);
final Function<BlockHeader, PoWBlockCreator> blockCreatorSupplier =
@ -100,7 +100,7 @@ public class BlockMinerTest {
headerBuilder.buildHeader(), new BlockBody(Lists.newArrayList(), Lists.newArrayList()));
final ProtocolContext protocolContext =
new ProtocolContext(null, null, null, Optional.empty(), new BadBlockManager());
new ProtocolContext(null, null, null, new BadBlockManager());
final PoWBlockCreator blockCreator = mock(PoWBlockCreator.class);
final Function<BlockHeader, PoWBlockCreator> blockCreatorSupplier =
@ -146,7 +146,7 @@ public class BlockMinerTest {
headerBuilder.buildHeader(), new BlockBody(Lists.newArrayList(), Lists.newArrayList()));
final ProtocolContext protocolContext =
new ProtocolContext(null, null, null, Optional.empty(), new BadBlockManager());
new ProtocolContext(null, null, null, new BadBlockManager());
final PoWBlockCreator blockCreator = mock(PoWBlockCreator.class);
final Function<BlockHeader, PoWBlockCreator> blockCreatorSupplier =

@ -112,12 +112,15 @@ public class LondonFeeMarketBlockTransactionSelectorTest
final BlockTransactionSelector selector =
createBlockSelectorAndSetupTxPool(
createMiningParameters(
Wei.of(6), MIN_OCCUPANCY_80_PERCENT, DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME),
transactionSelectionService,
Wei.of(6),
MIN_OCCUPANCY_80_PERCENT,
DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME),
transactionProcessor,
blockHeader,
miningBeneficiary,
Wei.ZERO,
NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY);
transactionSelectionService);
// tx is willing to pay max 7 wei for gas, but current network condition (baseFee == 1)
// result in it paying 2 wei, that is below the minimum accepted by the node, so it is skipped
@ -141,12 +144,15 @@ public class LondonFeeMarketBlockTransactionSelectorTest
final BlockTransactionSelector selector =
createBlockSelectorAndSetupTxPool(
createMiningParameters(
Wei.of(6), MIN_OCCUPANCY_80_PERCENT, DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME),
transactionSelectionService,
Wei.of(6),
MIN_OCCUPANCY_80_PERCENT,
DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME),
transactionProcessor,
blockHeader,
miningBeneficiary,
Wei.ZERO,
NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY);
transactionSelectionService);
// tx is willing to pay max 7 wei for gas, and current network condition (baseFee == 5)
// result in it paying the max, that is >= the minimum accepted by the node, so it is selected
@ -169,12 +175,15 @@ public class LondonFeeMarketBlockTransactionSelectorTest
final BlockTransactionSelector selector =
createBlockSelectorAndSetupTxPool(
createMiningParameters(
Wei.of(6), MIN_OCCUPANCY_80_PERCENT, DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME),
transactionSelectionService,
Wei.of(6),
MIN_OCCUPANCY_80_PERCENT,
DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME),
transactionProcessor,
blockHeader,
miningBeneficiary,
Wei.ZERO,
NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY);
transactionSelectionService);
// tx is willing to pay max 7 wei for gas, but current network condition (baseFee == 1)
// result in it paying 2 wei, that is below the minimum accepted by the node, but since it is
@ -213,7 +222,7 @@ public class LondonFeeMarketBlockTransactionSelectorTest
blockHeader,
miningBeneficiary,
Wei.ZERO,
NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY);
transactionSelectionService);
transactionPool.addRemoteTransactions(List.of(txFrontier1, txLondon1, txFrontier2, txLondon2));
@ -254,7 +263,7 @@ public class LondonFeeMarketBlockTransactionSelectorTest
blockHeader,
AddressHelpers.ofValue(1),
Wei.ZERO,
NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY);
transactionSelectionService);
transactionPool.addRemoteTransactions(
List.of(txSelected1, txNotSelected1, txSelected2, txNotSelected2));

@ -19,7 +19,6 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
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 java.util.Optional;
@ -33,7 +32,6 @@ public class ProtocolContext {
private final WorldStateArchive worldStateArchive;
private final BadBlockManager badBlockManager;
private final ConsensusContext consensusContext;
private final Optional<PluginTransactionSelectorFactory> transactionSelectorFactory;
private Optional<Synchronizer> synchronizer;
@ -42,20 +40,10 @@ public class ProtocolContext {
final WorldStateArchive worldStateArchive,
final ConsensusContext consensusContext,
final BadBlockManager badBlockManager) {
this(blockchain, worldStateArchive, consensusContext, Optional.empty(), badBlockManager);
}
public ProtocolContext(
final MutableBlockchain blockchain,
final WorldStateArchive worldStateArchive,
final ConsensusContext consensusContext,
final Optional<PluginTransactionSelectorFactory> transactionSelectorFactory,
final BadBlockManager badBlockManager) {
this.blockchain = blockchain;
this.worldStateArchive = worldStateArchive;
this.consensusContext = consensusContext;
this.synchronizer = Optional.empty();
this.transactionSelectorFactory = transactionSelectorFactory;
this.badBlockManager = badBlockManager;
}
@ -64,13 +52,11 @@ public class ProtocolContext {
final WorldStateArchive worldStateArchive,
final ProtocolSchedule protocolSchedule,
final ConsensusContextFactory consensusContextFactory,
final Optional<PluginTransactionSelectorFactory> transactionSelectorFactory,
final BadBlockManager badBlockManager) {
return new ProtocolContext(
blockchain,
worldStateArchive,
consensusContextFactory.create(blockchain, worldStateArchive, protocolSchedule),
transactionSelectorFactory,
badBlockManager);
}
@ -103,8 +89,4 @@ public class ProtocolContext {
.filter(c -> klass.isAssignableFrom(c.getClass()))
.map(klass::cast);
}
public Optional<PluginTransactionSelectorFactory> getTransactionSelectorFactory() {
return transactionSelectorFactory;
}
}

@ -16,6 +16,9 @@ package org.hyperledger.besu.ethereum.core;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.plugin.services.TransactionSelectionService;
import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelector;
import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory;
import org.hyperledger.besu.util.number.PositiveNumber;
import java.time.Duration;
@ -144,6 +147,20 @@ public abstract class MiningParameters {
return DEFAULT_POA_BLOCK_TXS_SELECTION_MAX_TIME;
}
@Value.Default
public TransactionSelectionService getTransactionSelectionService() {
return new TransactionSelectionService() {
@Override
public PluginTransactionSelector createPluginTransactionSelector() {
return PluginTransactionSelector.ACCEPT_ALL;
}
@Override
public void registerPluginTransactionSelectorFactory(
final PluginTransactionSelectorFactory transactionSelectorFactory) {}
};
}
public abstract OptionalInt getGenesisBlockPeriodSeconds();
@Value.Derived

@ -50,7 +50,6 @@ import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import com.google.common.io.Resources;
@ -157,7 +156,6 @@ public class BlockchainSetupUtil {
return null;
}
},
Optional.empty(),
new BadBlockManager());
}

@ -36,7 +36,6 @@ import org.hyperledger.besu.plugin.services.storage.KeyValueStorage;
import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage;
import java.math.BigInteger;
import java.util.Optional;
import java.util.function.Function;
public class ExecutionContextTestFixture {
@ -71,8 +70,7 @@ public class ExecutionContextTestFixture {
this.stateArchive = createInMemoryWorldStateArchive();
this.protocolSchedule = protocolSchedule;
this.protocolContext =
new ProtocolContext(
blockchain, stateArchive, null, Optional.empty(), new BadBlockManager());
new ProtocolContext(blockchain, stateArchive, null, new BadBlockManager());
genesisState.writeStateTo(stateArchive.getMutable());
}

@ -161,8 +161,7 @@ public abstract class AbstractIsolationTests {
EvmConfiguration.DEFAULT);
var ws = archive.getMutable();
genesisState.writeStateTo(ws);
protocolContext =
new ProtocolContext(blockchain, archive, null, Optional.empty(), new BadBlockManager());
protocolContext = new ProtocolContext(blockchain, archive, null, new BadBlockManager());
ethContext = mock(EthContext.class, RETURNS_DEEP_STUBS);
when(ethContext.getEthPeers().subscribeConnect(any())).thenReturn(1L);
transactionPool =

@ -65,7 +65,6 @@ import org.hyperledger.besu.testutil.TestClock;
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,6 @@ public abstract class AbstractBlockPropagationManagerTest {
blockchain,
tempProtocolContext.getWorldStateArchive(),
tempProtocolContext.getConsensusContext(ConsensusContext.class),
Optional.empty(),
new BadBlockManager());
ethProtocolManager =
EthProtocolManagerTestUtil.create(

@ -39,7 +39,6 @@ import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream;
@ -77,8 +76,7 @@ public class FullSyncTargetManagerTest {
final ProtocolSchedule protocolSchedule = ProtocolScheduleFixture.MAINNET;
final ProtocolContext protocolContext =
new ProtocolContext(
localBlockchain, localWorldState, null, Optional.empty(), new BadBlockManager());
new ProtocolContext(localBlockchain, localWorldState, null, new BadBlockManager());
ethProtocolManager =
EthProtocolManagerTestUtil.create(
protocolSchedule,

@ -44,7 +44,6 @@ import org.hyperledger.besu.plugin.services.MetricsSystem;
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;
@ -151,8 +150,7 @@ public class DetermineCommonAncestorTaskParameterizedTest {
final EthContext ethContext = ethProtocolManager.ethContext();
final ProtocolContext protocolContext =
new ProtocolContext(
localBlockchain, worldStateArchive, null, Optional.empty(), new BadBlockManager());
new ProtocolContext(localBlockchain, worldStateArchive, null, new BadBlockManager());
final EthTask<BlockHeader> task =
DetermineCommonAncestorTask.create(

@ -55,7 +55,6 @@ import org.hyperledger.besu.plugin.services.MetricsSystem;
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;
@ -89,8 +88,7 @@ public class DetermineCommonAncestorTaskTest {
EthProtocolConfiguration.defaultConfig());
ethContext = ethProtocolManager.ethContext();
protocolContext =
new ProtocolContext(
localBlockchain, worldStateArchive, null, Optional.empty(), new BadBlockManager());
new ProtocolContext(localBlockchain, worldStateArchive, null, new BadBlockManager());
}
@Test

@ -125,8 +125,7 @@ public class TestNode implements Closeable {
final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive();
genesisState.writeStateTo(worldStateArchive.getMutable());
final ProtocolContext protocolContext =
new ProtocolContext(
blockchain, worldStateArchive, null, Optional.empty(), new BadBlockManager());
new ProtocolContext(blockchain, worldStateArchive, null, new BadBlockManager());
final SyncState syncState = mock(SyncState.class);
final SynchronizerConfiguration syncConfig = mock(SynchronizerConfiguration.class);

@ -109,8 +109,7 @@ public class BlockchainReferenceTestCaseSpec {
this.blockchain = buildBlockchain(genesisBlockHeader);
this.sealEngine = sealEngine;
this.protocolContext =
new ProtocolContext(
this.blockchain, this.worldStateArchive, null, Optional.empty(), new BadBlockManager());
new ProtocolContext(this.blockchain, this.worldStateArchive, null, new BadBlockManager());
}
public String getNetwork() {

@ -177,8 +177,7 @@ public class RetestethContext {
genesisState.writeStateTo(worldState);
blockchain = createInMemoryBlockchain(genesisState.getBlock());
protocolContext =
new ProtocolContext(blockchain, worldStateArchive, null, Optional.empty(), badBlockManager);
protocolContext = new ProtocolContext(blockchain, worldStateArchive, null, badBlockManager);
blockchainQueries = new BlockchainQueries(blockchain, worldStateArchive, ethScheduler);

@ -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 = 'jvIsInEUQ/NaxWCGkQIb72tuZsx5288Ownn2F6rsvjQ='
knownHash = 'Jv/pqyKOoZo3wlxRRwmzPuLIJjEqyV1i55wFyIUV90A='
}
check.dependsOn('checkAPIChanges')

@ -16,26 +16,25 @@
package org.hyperledger.besu.plugin.services;
import org.hyperledger.besu.plugin.Unstable;
import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelector;
import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory;
import java.util.Optional;
/** Transaction selection service interface */
@Unstable
public interface TransactionSelectionService extends BesuService {
/**
* Returns the (Optional) transaction selector factory
* Create a transaction selector plugin
*
* @return the transaction selector factory
* @return the transaction selector plugin
*/
Optional<PluginTransactionSelectorFactory> get();
PluginTransactionSelector createPluginTransactionSelector();
/**
* Registers the transaction selector factory with the service
*
* @param transactionSelectorFactory transaction selector factory to be used
*/
void registerTransactionSelectorFactory(
void registerPluginTransactionSelectorFactory(
PluginTransactionSelectorFactory transactionSelectorFactory);
}

@ -15,6 +15,8 @@
package org.hyperledger.besu.plugin.services.txselection;
import static org.hyperledger.besu.plugin.data.TransactionSelectionResult.SELECTED;
import org.hyperledger.besu.datatypes.PendingTransaction;
import org.hyperledger.besu.plugin.Unstable;
import org.hyperledger.besu.plugin.data.TransactionProcessingResult;
@ -24,6 +26,22 @@ import org.hyperledger.besu.plugin.services.tracer.BlockAwareOperationTracer;
/** Interface for the transaction selector */
@Unstable
public interface PluginTransactionSelector {
/** Plugin transaction selector that unconditionally select every transaction */
PluginTransactionSelector ACCEPT_ALL =
new PluginTransactionSelector() {
@Override
public TransactionSelectionResult evaluateTransactionPreProcessing(
TransactionEvaluationContext<? extends PendingTransaction> evaluationContext) {
return SELECTED;
}
@Override
public TransactionSelectionResult evaluateTransactionPostProcessing(
TransactionEvaluationContext<? extends PendingTransaction> evaluationContext,
TransactionProcessingResult processingResult) {
return SELECTED;
}
};
/**
* Method that returns an OperationTracer that will be used when executing transactions that are

Loading…
Cancel
Save