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 bd94a4a3451..2727c25e259 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 @@ -50,7 +50,6 @@ 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 @@ private BesuPluginContextImpl buildPluginContext( 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 @@ private BesuPluginContextImpl buildPluginContext( 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 void startNode(final BesuNode node) { 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 void startNode(final BesuNode node) { node, n -> buildPluginContext( - node, storageService, securityModuleService, commonPluginConfiguration)); + node, + storageService, + securityModuleService, + transactionSelectionServiceImpl, + commonPluginConfiguration)); GlobalOpenTelemetry.resetForTest(); final ObservableMetricsSystem metricsSystem = @@ -193,8 +199,8 @@ public void startNode(final BesuNode node) { final int maxPeers = 25; - final Optional transactionSelectorFactory = - getTransactionSelectorFactory(besuPluginContext); + final TransactionSelectionService transactionSelectorService = + getTransactionSelectorService(besuPluginContext); final PluginTransactionValidatorFactory pluginTransactionValidatorFactory = getPluginTransactionValidatorFactory(besuPluginContext); @@ -220,7 +226,7 @@ public void startNode(final BesuNode node) { .maxRemotelyInitiatedPeers(15) .networkConfiguration(node.getNetworkingConfiguration()) .randomPeerPriority(false) - .transactionSelectorFactory(transactionSelectorFactory) + .transactionSelectorService(transactionSelectorService) .pluginTransactionValidatorFactory(pluginTransactionValidatorFactory); node.getGenesisConfig() @@ -332,11 +338,9 @@ public String getConsoleContents() { throw new RuntimeException("Console contents can only be captured in process execution"); } - private Optional getTransactionSelectorFactory( + private TransactionSelectionService getTransactionSelectorService( final BesuPluginContextImpl besuPluginContext) { - final Optional txSelectionService = - besuPluginContext.getService(TransactionSelectionService.class); - return txSelectionService.isPresent() ? txSelectionService.get().get() : Optional.empty(); + return besuPluginContext.getService(TransactionSelectionService.class).orElseThrow(); } private PluginTransactionValidatorFactory getPluginTransactionValidatorFactory( 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 6429339dbb4..d254cc0b0df 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -174,7 +174,6 @@ 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.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 BesuControllerBuilder getControllerBuilder() { .synchronizerConfiguration(buildSyncConfig()) .ethProtocolConfiguration(unstableEthProtocolOptions.toDomainObject()) .networkConfiguration(unstableNetworkingOptions.toDomainObject()) - .transactionSelectorFactory(getTransactionSelectorFactory()) + .transactionSelectorService(getTransactionSelectorService()) .pluginTransactionValidatorFactory(getPluginTransactionValidatorFactory()) .dataDirectory(dataDir()) .dataStorageConfiguration(getDataStorageConfiguration()) @@ -1825,11 +1823,8 @@ public BesuControllerBuilder getControllerBuilder() { .cacheLastBlocks(numberOfblocksToCache); } - @Nonnull - private Optional getTransactionSelectorFactory() { - final Optional txSelectionService = - besuPluginContext.getService(TransactionSelectionService.class); - return txSelectionService.isPresent() ? txSelectionService.get().get() : Optional.empty(); + private TransactionSelectionService getTransactionSelectorService() { + return besuPluginContext.getService(TransactionSelectionService.class).orElseThrow(); } private PluginTransactionValidatorFactory getPluginTransactionValidatorFactory() { @@ -2147,6 +2142,7 @@ private MiningParameters getMiningParameters() { if (miningParameters == null) { miningOptions.setGenesisBlockPeriodSeconds( getGenesisBlockPeriodSeconds(getActualGenesisConfigOptions())); + miningOptions.setTransactionSelectionService(transactionSelectionServiceImpl); miningParameters = miningOptions.toDomainObject(); initMiningParametersMetrics(miningParameters); } diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/MiningOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/MiningOptions.java index 2e5a239f16d..976be808495 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/MiningOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/MiningOptions.java @@ -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.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 @@ static class Unstable { } private OptionalInt maybeGenesisBlockPeriodSeconds; + private TransactionSelectionService transactionSelectionService; private MiningOptions() {} @@ -212,6 +215,16 @@ public void setGenesisBlockPeriodSeconds(final OptionalInt genesisBlockPeriodSec 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 void validate( 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 @@ static MiningOptions fromConfig(final MiningParameters 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 MiningParameters toDomainObject() { return ImmutableMiningParameters.builder() .genesisBlockPeriodSeconds(maybeGenesisBlockPeriodSeconds) + .transactionSelectionService(transactionSelectionService) .mutableInitValues(updatableInitValuesBuilder.build()) .isStratumMiningEnabled(iStratumMiningEnabled) .stratumNetworkInterface(stratumNetworkInterface) diff --git a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java index 2ca4a1d12ec..1a74e4996e2 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java @@ -97,9 +97,9 @@ import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.ObservableMetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem; +import org.hyperledger.besu.plugin.services.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 transactionSelectorFactory = Optional.empty(); /** the Dagger configured context that can provide dependencies */ protected Optional besuComponent = Optional.empty(); @@ -535,14 +534,13 @@ public BesuControllerBuilder randomPeerPriority(final Boolean randomPeerPriority } /** - * sets the transactionSelectorFactory in the builder + * sets the transactionSelectionService in the builder * - * @param transactionSelectorFactory the optional transaction selector factory + * @param transactionSelectionService the transaction selector service * @return the besu controller builder */ - public BesuControllerBuilder transactionSelectorFactory( - final Optional transactionSelectorFactory) { - this.transactionSelectorFactory = transactionSelectorFactory; + public BesuControllerBuilder transactionSelectorService( + final TransactionSelectionService transactionSelectionService) { return this; } @@ -617,11 +615,7 @@ public BesuController build() { final ProtocolContext protocolContext = createProtocolContext( - blockchain, - worldStateArchive, - protocolSchedule, - this::createConsensusContext, - transactionSelectorFactory); + blockchain, worldStateArchive, protocolSchedule, this::createConsensusContext); validateContext(protocolContext); if (chainPrunerConfiguration.getChainPruningEnabled()) { @@ -1057,22 +1051,15 @@ protected EthProtocolManager createEthProtocolManager( * @param worldStateArchive the world state archive * @param protocolSchedule the protocol schedule * @param consensusContextFactory the consensus context factory - * @param transactionSelectorFactory optional transaction selector factory * @return the protocol context */ protected ProtocolContext createProtocolContext( final MutableBlockchain blockchain, final WorldStateArchive worldStateArchive, final ProtocolSchedule protocolSchedule, - final ConsensusContextFactory consensusContextFactory, - final Optional transactionSelectorFactory) { + final ConsensusContextFactory consensusContextFactory) { return ProtocolContext.init( - blockchain, - worldStateArchive, - protocolSchedule, - consensusContextFactory, - transactionSelectorFactory, - badBlockManager); + blockchain, worldStateArchive, protocolSchedule, consensusContextFactory, badBlockManager); } private Optional createSnapProtocolManager( diff --git a/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java index 0754f96ff11..a41e9bb3ee0 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java @@ -62,7 +62,6 @@ 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 @@ protected ProtocolContext createProtocolContext( final MutableBlockchain blockchain, final WorldStateArchive worldStateArchive, final ProtocolSchedule protocolSchedule, - final ConsensusContextFactory consensusContextFactory, - final Optional transactionSelectorFactory) { + final ConsensusContextFactory consensusContextFactory) { return MigratingProtocolContext.init( - blockchain, - worldStateArchive, - protocolSchedule, - consensusContextFactory, - transactionSelectorFactory, - badBlockManager); + blockchain, worldStateArchive, protocolSchedule, consensusContextFactory, badBlockManager); } @Override diff --git a/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java index 65aadd46c63..a9de9de7e9f 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java @@ -60,7 +60,6 @@ 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 @@ protected ProtocolContext createProtocolContext( final MutableBlockchain blockchain, final WorldStateArchive worldStateArchive, final ProtocolSchedule protocolSchedule, - final ConsensusContextFactory consensusContextFactory, - final Optional transactionSelectorFactory) { + final ConsensusContextFactory consensusContextFactory) { final ProtocolContext protocolContext = super.createProtocolContext( - blockchain, - worldStateArchive, - protocolSchedule, - consensusContextFactory, - transactionSelectorFactory); + blockchain, worldStateArchive, protocolSchedule, consensusContextFactory); transitionProtocolSchedule.setProtocolContext(protocolContext); return protocolContext; } diff --git a/besu/src/main/java/org/hyperledger/besu/services/TransactionSelectionServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/TransactionSelectionServiceImpl.java index 3175fe731f9..c6d2125e7d5 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/TransactionSelectionServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/TransactionSelectionServiceImpl.java @@ -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 factory = Optional.empty(); @Override - public Optional 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); } } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/CascadingDefaultProviderTest.java b/besu/src/test/java/org/hyperledger/besu/cli/CascadingDefaultProviderTest.java index 008ae6a89b1..bb3849f4492 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/CascadingDefaultProviderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/CascadingDefaultProviderTest.java @@ -32,7 +32,7 @@ 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 void envVariableOverridesValueFromConfigFile() { 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 void cliOptionOverridesEnvVariableAndConfig() { 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)); } /** 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 c5e34295a5b..271ed1b8155 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java @@ -77,6 +77,7 @@ 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 void initMocks() throws Exception { 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 void initMocks() throws Exception { lenient() .when(mockBesuPluginContext.getService(StorageService.class)) .thenReturn(Optional.of(storageService)); + lenient() + .when(mockBesuPluginContext.getService(TransactionSelectionService.class)) + .thenReturn(Optional.of(txSelectionService)); lenient() .doReturn(mockPkiBlockCreationConfiguration) diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/MiningOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/MiningOptionsTest.java index 74b696cdf9a..fda642d6ead 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/MiningOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/MiningOptionsTest.java @@ -422,6 +422,6 @@ protected MiningOptions getOptionsFromBesuCommand(final TestBesuCommand besuComm @Override protected String[] getNonOptionFields() { - return new String[] {"maybeGenesisBlockPeriodSeconds"}; + return new String[] {"maybeGenesisBlockPeriodSeconds", "transactionSelectionService"}; } } diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculatorTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculatorTest.java index c3bf0a6def6..3c9da2520d9 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculatorTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculatorTest.java @@ -32,7 +32,6 @@ 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 void setup() { 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(); } diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/NodeCanProduceNextBlockTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/NodeCanProduceNextBlockTest.java index 1f97cb88d9f..afd9651df61 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/NodeCanProduceNextBlockTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/NodeCanProduceNextBlockTest.java @@ -38,7 +38,6 @@ 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 void networkWithOneValidatorIsAllowedToCreateConsecutiveBlocks() { 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 void networkWithTwoValidatorsIsAllowedToProduceBlockIfNotPreviousBlockPro 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 void networkWithTwoValidatorsIsNotAllowedToProduceBlockIfIsPreviousBlockP 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 void withThreeValidatorsMustHaveOneBlockBetweenSignings() { 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 void signerIsValidIfInsufficientBlocksExistInHistory() { 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 void exceptionIsThrownIfOnAnOrphanedChain() { 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 void nonValidatorIsNotAllowedToCreateABlock() { 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(); 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 5b0fc0357bb..a98c9f7b95e 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 @@ -119,8 +119,7 @@ public void setup() { 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 diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockMinerTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockMinerTest.java index 7f8d6a3babf..370847638f1 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockMinerTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockMinerTest.java @@ -71,7 +71,7 @@ void doesNotMineBlockIfNoTransactionsWhenEmptyBlocksNotAllowed() throws Interrup final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, null); final ProtocolContext protocolContext = - new ProtocolContext(null, null, cliqueContext, Optional.empty(), new BadBlockManager()); + new ProtocolContext(null, null, cliqueContext, new BadBlockManager()); final CliqueBlockCreator blockCreator = mock(CliqueBlockCreator.class); final Function blockCreatorSupplier = @@ -126,7 +126,7 @@ void minesBlockIfHasTransactionsWhenEmptyBlocksNotAllowed() throws InterruptedEx final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, null); final ProtocolContext protocolContext = - new ProtocolContext(null, null, cliqueContext, Optional.empty(), new BadBlockManager()); + new ProtocolContext(null, null, cliqueContext, new BadBlockManager()); final CliqueBlockCreator blockCreator = mock(CliqueBlockCreator.class); final Function blockCreatorSupplier = diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java index 5400f46ed94..a919360f5d5 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 @@ -95,8 +95,7 @@ public void setup() { when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); - cliqueProtocolContext = - new ProtocolContext(null, null, cliqueContext, Optional.empty(), new BadBlockManager()); + cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext, new BadBlockManager()); cliqueProtocolSchedule = CliqueProtocolSchedule.create( GENESIS_CONFIG_OPTIONS, diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java index 38f8c3536e0..d970d83d80e 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java @@ -35,7 +35,6 @@ 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 void setup() { 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(); } diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueExtraDataValidationRuleTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueExtraDataValidationRuleTest.java index 8f2e8d8a9b9..0d30cdf655b 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueExtraDataValidationRuleTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueExtraDataValidationRuleTest.java @@ -36,7 +36,6 @@ 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 void setup() { 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 diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingProtocolContext.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingProtocolContext.java index 2c4ff215cce..f34c101c299 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingProtocolContext.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingProtocolContext.java @@ -21,9 +21,6 @@ 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 consensusContextSchedule, - final Optional transactionSelectorFactory, final BadBlockManager badBlockManager) { - super(blockchain, worldStateArchive, null, transactionSelectorFactory, badBlockManager); + super(blockchain, worldStateArchive, null, badBlockManager); this.consensusContextSchedule = consensusContextSchedule; } @@ -56,7 +51,6 @@ public MigratingProtocolContext( * @param worldStateArchive the world state archive * @param protocolSchedule the protocol schedule * @param consensusContextFactory the consensus context factory - * @param transactionSelectorFactory the optional transaction selector factory * @param badBlockManager the cache to use to keep invalid blocks * @return the protocol context */ @@ -65,7 +59,6 @@ public static ProtocolContext init( final WorldStateArchive worldStateArchive, final ProtocolSchedule protocolSchedule, final ConsensusContextFactory consensusContextFactory, - final Optional transactionSelectorFactory, final BadBlockManager badBlockManager) { final ConsensusContext consensusContext = consensusContextFactory.create(blockchain, worldStateArchive, protocolSchedule); @@ -74,7 +67,6 @@ public static ProtocolContext init( blockchain, worldStateArchive, migratingContext.getConsensusContextSchedule(), - transactionSelectorFactory, badBlockManager); } diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java index 0017e79d59c..f1d19059920 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java @@ -24,7 +24,6 @@ import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import java.util.List; -import java.util.Optional; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -46,11 +45,7 @@ public void returnsContextForSpecificChainHeight() { 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); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java index 091141fcc9f..791edaf636d 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java @@ -28,7 +28,6 @@ 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 void proposerInValidatorListPassesValidation() { 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 void proposerNotInValidatorListFailsValidation() { final ProtocolContext context = new ProtocolContext( - null, - null, - setupContextWithValidators(validators), - Optional.empty(), - new BadBlockManager()); + null, null, setupContextWithValidators(validators), new BadBlockManager()); final BftCoinbaseValidationRule coinbaseValidationRule = new BftCoinbaseValidationRule(); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java index ee1c44b7534..84d59397bcd 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java @@ -34,7 +34,6 @@ 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 void correctlyConstructedHeaderPassesValidation() { 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 void insufficientCommitSealsFailsValidation() { final List
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 void committerNotInValidatorListFailsValidation() { 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 void headerContainsDuplicateSealsFailsValidation() { 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 @@ private boolean subExecution(final int validatorCount, final int committerCount) 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)); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java index 8fb065d740b..8ffd5633456 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java @@ -27,7 +27,6 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import java.util.List; -import java.util.Optional; import com.google.common.collect.Lists; import org.junit.jupiter.api.Test; @@ -50,7 +49,6 @@ public void correctlyConstructedHeaderPassesValidation() { null, null, setupContextWithBftExtraData(validators, bftExtraData), - Optional.empty(), new BadBlockManager()); when(bftExtraData.getValidators()).thenReturn(validators); @@ -69,7 +67,6 @@ public void validatorsInNonAscendingOrderFailValidation() { null, null, setupContextWithBftExtraData(validators, bftExtraData), - Optional.empty(), new BadBlockManager()); when(bftExtraData.getValidators()).thenReturn(Lists.reverse(validators)); @@ -91,7 +88,6 @@ public void mismatchingReportedValidatorsVsLocallyStoredListFailsValidation() { null, null, setupContextWithBftExtraData(storedValidators, bftExtraData), - Optional.empty(), new BadBlockManager()); when(bftExtraData.getValidators()).thenReturn(Lists.reverse(reportedValidators)); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java index 15da7c04e89..39f296a9937 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java @@ -25,8 +25,6 @@ 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 boolean headerWithVanityDataOfSize(final int extraDataSize) { null, null, setupContextWithBftExtraData(emptyList(), extraData), - Optional.empty(), new BadBlockManager()); return validationRule.validate(blockHeader, null, context); } diff --git a/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java b/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java index 101581e4ec2..63c28901a8a 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 @@ -349,7 +349,6 @@ private static ControllerAndState createControllerAndFinalState( blockChain, worldStateArchive, new BftContext(validatorProvider, epochManager, blockInterface), - Optional.empty(), new BadBlockManager()); final TransactionPoolConfiguration poolConf = ImmutableTransactionPoolConfiguration.builder().txPoolMaxSize(1).build(); diff --git a/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/tests/round/IbftRoundIntegrationTest.java b/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/tests/round/IbftRoundIntegrationTest.java index 02a20b0ad32..5c43e086fb8 100644 --- a/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/tests/round/IbftRoundIntegrationTest.java +++ b/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/tests/round/IbftRoundIntegrationTest.java @@ -127,7 +127,6 @@ public void setup() { blockChain, worldStateArchive, setupContextWithBftExtraDataEncoder(emptyList(), bftExtraDataEncoder), - Optional.empty(), new BadBlockManager()); } diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftBlockHeaderValidationRulesetFactoryTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftBlockHeaderValidationRulesetFactoryTest.java index 8ed7f6aa87e..a7deb9e1973 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftBlockHeaderValidationRulesetFactoryTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftBlockHeaderValidationRulesetFactoryTest.java @@ -52,7 +52,6 @@ private ProtocolContext protocolContext(final Collection
validators) { null, null, setupContextWithBftExtraDataEncoder(validators, new IbftExtraDataCodec()), - Optional.empty(), new BadBlockManager()); } diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java index 8ba9f0be2fc..de8ead1d23e 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java @@ -48,7 +48,6 @@ import java.math.BigInteger; import java.util.Collection; import java.util.List; -import java.util.Optional; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -123,7 +122,6 @@ private ProtocolContext protocolContext(final Collection
validators) { null, null, setupContextWithBftExtraDataEncoder(BftContext.class, validators, bftExtraDataCodec), - Optional.empty(), new BadBlockManager()); } } 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 8e1717b12f9..5481297dee7 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 @@ -126,7 +126,6 @@ public BlockHeaderValidator.Builder createBlockHeaderRuleset( blockchain, createInMemoryWorldStateArchive(), setupContextWithBftExtraDataEncoder(initialValidatorList, bftExtraDataEncoder), - Optional.empty(), new BadBlockManager()); final TransactionPoolConfiguration poolConf = diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java index f1c0750a5d0..2521737f81c 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java @@ -169,11 +169,7 @@ public void setup() { protocolContext = new ProtocolContext( - blockchain, - null, - setupContextWithValidators(validators), - Optional.empty(), - new BadBlockManager()); + blockchain, null, setupContextWithValidators(validators), new BadBlockManager()); final ProtocolScheduleBuilder protocolScheduleBuilder = new ProtocolScheduleBuilder( diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftRoundTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftRoundTest.java index d7a79a9f0c5..5057b057409 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftRoundTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftRoundTest.java @@ -113,7 +113,6 @@ public void setup() { blockChain, worldStateArchive, setupContextWithBftExtraDataEncoder(emptyList(), new IbftExtraDataCodec()), - Optional.empty(), new BadBlockManager()); lenient().when(messageValidator.validateProposal(any())).thenReturn(true); diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/validation/MessageValidatorTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/validation/MessageValidatorTest.java index c0927769b67..f7fb7af3e94 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/validation/MessageValidatorTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/validation/MessageValidatorTest.java @@ -105,7 +105,6 @@ public void setup() { mock(MutableBlockchain.class), mock(WorldStateArchive.class), mockBftCtx, - Optional.empty(), new BadBlockManager()); lenient() 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 552c93b8aa8..7f54bbc96d4 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 @@ -187,8 +187,7 @@ public void setUp() { .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); diff --git a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeReorgTest.java b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeReorgTest.java index 4462386a0dd..bd539123e04 100644 --- a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeReorgTest.java +++ b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeReorgTest.java @@ -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(); 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 1679575d14c..caffe3f2ba8 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 @@ -446,7 +446,6 @@ private static ControllerAndState createControllerAndFinalState( blockChain, worldStateArchive, new QbftContext(validatorProvider, epochManager, blockInterface, Optional.empty()), - Optional.empty(), new BadBlockManager()); final TransactionPoolConfiguration poolConf = diff --git a/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/test/round/QbftRoundIntegrationTest.java b/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/test/round/QbftRoundIntegrationTest.java index 45090e908be..52cdfa1ed04 100644 --- a/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/test/round/QbftRoundIntegrationTest.java +++ b/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/test/round/QbftRoundIntegrationTest.java @@ -58,7 +58,6 @@ import org.hyperledger.besu.util.Subscribers; import java.math.BigInteger; -import java.util.Optional; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.BeforeEach; @@ -131,7 +130,6 @@ public void setup() { worldStateArchive, setupContextWithBftExtraDataEncoder( QbftContext.class, emptyList(), qbftExtraDataEncoder), - Optional.empty(), new BadBlockManager()); } diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftBlockHeaderValidationRulesetFactoryTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftBlockHeaderValidationRulesetFactoryTest.java index 41ed04ef78a..3a09295a990 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftBlockHeaderValidationRulesetFactoryTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftBlockHeaderValidationRulesetFactoryTest.java @@ -47,7 +47,6 @@ private ProtocolContext protocolContext(final Collection
validators) { null, setupContextWithBftExtraDataEncoder( QbftContext.class, validators, new QbftExtraDataCodec()), - Optional.empty(), new BadBlockManager()); } diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleTest.java index 65afc58e231..16a5f4ca31a 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleTest.java @@ -59,7 +59,6 @@ private ProtocolContext protocolContext(final Collection
validators) { null, setupContextWithBftExtraDataEncoder( QbftContext.class, validators, new QbftExtraDataCodec()), - Optional.empty(), new BadBlockManager()); } diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/headervalidationrules/QbftValidatorsValidationRuleTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/headervalidationrules/QbftValidatorsValidationRuleTest.java index 9c86df33fce..3e325142c4d 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/headervalidationrules/QbftValidatorsValidationRuleTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/headervalidationrules/QbftValidatorsValidationRuleTest.java @@ -48,7 +48,6 @@ public void validationPassesIfValidatorsAndVoteAreEmpty() { 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 void validationIsDelegatedWhenConstructorFlagIsFalse() { 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 void validationFailsIfValidatorsAreNotEmpty() { 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 void validationFailsIfVoteIsPresent() { 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))); diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java index 8d0a1628636..b582f1a9b88 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java @@ -169,7 +169,6 @@ public void setup() { null, setupContextWithBftExtraDataEncoder( QbftContext.class, validators, new QbftExtraDataCodec()), - Optional.empty(), new BadBlockManager()); final ProtocolScheduleBuilder protocolScheduleBuilder = diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftRoundTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftRoundTest.java index d369c155ddf..bf730bbf7e6 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftRoundTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftRoundTest.java @@ -123,7 +123,6 @@ public void setup() { worldStateArchive, setupContextWithBftExtraDataEncoder( QbftContext.class, emptyList(), new QbftExtraDataCodec()), - Optional.empty(), new BadBlockManager()); when(messageValidator.validateProposal(any())).thenReturn(true); diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidatorTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidatorTest.java index 5a0660b59f6..e4687f3c104 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidatorTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidatorTest.java @@ -88,7 +88,6 @@ public void setup() { blockChain, worldStateArchive, setupContextWithBftExtraDataEncoder(QbftContext.class, emptyList(), bftExtraDataCodec), - Optional.empty(), new BadBlockManager()); } @@ -242,8 +241,7 @@ public void validationForCmsFailsWhenCmsFailsValidation() { setupContextWithBftExtraDataEncoder(QbftContext.class, emptyList(), pkiQbftExtraDataCodec); final Bytes cms = Bytes.fromHexStringLenient("0x1"); final ProtocolContext protocolContext = - new ProtocolContext( - blockChain, worldStateArchive, qbftContext, Optional.empty(), new BadBlockManager()); + new ProtocolContext(blockChain, worldStateArchive, qbftContext, new BadBlockManager()); final ProposalPayloadValidator payloadValidator = new ProposalPayloadValidator( @@ -278,8 +276,7 @@ public void validationForCmsPassesWhenCmsIsValid() { setupContextWithBftExtraDataEncoder(QbftContext.class, emptyList(), pkiQbftExtraDataCodec); final Bytes cms = Bytes.fromHexStringLenient("0x1"); final ProtocolContext protocolContext = - new ProtocolContext( - blockChain, worldStateArchive, qbftContext, Optional.empty(), new BadBlockManager()); + new ProtocolContext(blockChain, worldStateArchive, qbftContext, new BadBlockManager()); final ProposalPayloadValidator payloadValidator = new ProposalPayloadValidator( diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalValidatorTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalValidatorTest.java index c7c2d6e316b..53876f5b87e 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalValidatorTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalValidatorTest.java @@ -104,7 +104,6 @@ public void setup() { worldStateArchive, setupContextWithBftExtraDataEncoder( QbftContext.class, emptyList(), bftExtraDataEncoder), - Optional.empty(), new BadBlockManager()); // typically tests require the blockValidation to be successful diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/RoundChangeMessageValidatorTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/RoundChangeMessageValidatorTest.java index e850372951b..e02a668c2dc 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/RoundChangeMessageValidatorTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/RoundChangeMessageValidatorTest.java @@ -86,7 +86,6 @@ public void setup() { worldStateArchive, setupContextWithBftExtraDataEncoder( QbftContext.class, emptyList(), bftExtraDataEncoder), - Optional.empty(), new BadBlockManager()); lenient().when(protocolSchedule.getByBlockHeader(any())).thenReturn(protocolSpec); diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java index 8552b99d8bd..d31a12e0f68 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java @@ -79,9 +79,7 @@ public JsonRpcTestMethodsFactory(final BlockchainImporter importer) { this.blockchain = createInMemoryBlockchain(importer.getGenesisBlock()); this.stateArchive = createInMemoryWorldStateArchive(); this.importer.getGenesisState().writeStateTo(stateArchive.getMutable()); - this.context = - new ProtocolContext( - blockchain, stateArchive, null, Optional.empty(), new BadBlockManager()); + this.context = new ProtocolContext(blockchain, stateArchive, null, new BadBlockManager()); final ProtocolSchedule protocolSchedule = importer.getProtocolSchedule(); this.synchronizer = mock(Synchronizer.class); diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByNumberLatestDesyncIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByNumberLatestDesyncIntegrationTest.java index 20d937f022b..927aff6404c 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByNumberLatestDesyncIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByNumberLatestDesyncIntegrationTest.java @@ -68,8 +68,7 @@ public static void setUpOnce() throws Exception { InMemoryKeyValueStorageProvider.createInMemoryBlockchain(importer.getGenesisBlock()); WorldStateArchive state = InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive(); importer.getGenesisState().writeStateTo(state.getMutable()); - ProtocolContext context = - new ProtocolContext(chain, state, null, Optional.empty(), new BadBlockManager()); + ProtocolContext context = new ProtocolContext(chain, state, null, new BadBlockManager()); for (final Block block : importer.getBlocks()) { final ProtocolSchedule protocolSchedule = importer.getProtocolSchedule(); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java index 771385af3c3..5565c9e4855 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java @@ -109,11 +109,7 @@ public void setupTest() throws Exception { 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(), diff --git a/ethereum/blockcreation/build.gradle b/ethereum/blockcreation/build.gradle index 7fc35a6ec10..5f426fd9320 100644 --- a/ethereum/blockcreation/build.gradle +++ b/ethereum/blockcreation/build.gradle @@ -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') diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java index deac72bc5da..f7503c65791 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java @@ -24,7 +24,6 @@ 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.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 @@ protected BlockCreationResult createBlock( throwIfStopped(); final PluginTransactionSelector pluginTransactionSelector = - protocolContext - .getTransactionSelectorFactory() - .map(PluginTransactionSelectorFactory::create) - .orElseGet(() -> AllAcceptingTransactionSelector.INSTANCE); + miningParameters.getTransactionSelectionService().createPluginTransactionSelector(); final BlockAwareOperationTracer operationTracer = pluginTransactionSelector.getOperationTracer(); diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/AllAcceptingTransactionSelector.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/AllAcceptingTransactionSelector.java deleted file mode 100644 index a2b8d57ff29..00000000000 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/AllAcceptingTransactionSelector.java +++ /dev/null @@ -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 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 evaluationContext, - final TransactionProcessingResult processingResult) { - return TransactionSelectionResult.SELECTED; - } -} 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 335e94aea6c..3fc970110ca 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 @@ -27,7 +27,6 @@ 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.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.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 @@ 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 void emptyPendingTransactionsResultsInEmptyVettingResult() { blockHeader, miningBeneficiary, Wei.ZERO, - NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY); + transactionSelectionService); final TransactionSelectionResults results = selector.buildTransactionListForBlock(); @@ -249,7 +254,7 @@ public void validPendingTransactionIsIncludedInTheBlock() { 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 void invalidTransactionsAreSkippedButBlockStillFills() { blockHeader, miningBeneficiary, Wei.ZERO, - NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY); + transactionSelectionService); final List transactionsToInject = Lists.newArrayList(); for (int i = 0; i < 5; i++) { @@ -317,7 +322,7 @@ public void subsetOfPendingTransactionsIncludedWhenBlockGasLimitHit() { blockHeader, miningBeneficiary, Wei.ZERO, - NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY); + transactionSelectionService); final List transactionsToInject = Lists.newArrayList(); for (int i = 0; i < 5; i++) { @@ -358,7 +363,7 @@ public void transactionTooLargeForBlockDoesNotPreventMoreBeingAddedIfBlockOccupa 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 void transactionSelectionStopsWhenSufficientBlockOccupancyIsReached() { 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 void transactionSelectionStopsWhenBlockIsFull() { 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 void transactionSelectionStopsWhenRemainingGasIsNotEnoughForAnyMoreTransa 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 void shouldDiscardTransactionsThatFailValidation() { 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 TransactionSelectionResult evaluateTransactionPostProcessing( return SELECTED; } }; + transactionSelectionService.registerPluginTransactionSelectorFactory( + transactionSelectorFactory); final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( @@ -618,7 +631,7 @@ public TransactionSelectionResult evaluateTransactionPostProcessing( blockHeader, miningBeneficiary, Wei.ZERO, - transactionSelectorFactory); + transactionSelectionService); transactionPool.addRemoteTransactions( List.of(selected, notSelectedTransient, notSelectedInvalid)); @@ -676,17 +689,22 @@ public TransactionSelectionResult evaluateTransactionPostProcessing( 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 TransactionSelectionResult evaluateTransactionPostProcessing( 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 void transactionSelectionPluginShouldBeNotifiedWhenTransactionSelectionCo createBlock(300_000), AddressHelpers.ofValue(1), Wei.ZERO, - transactionSelectorFactory); + transactionSelectionService); transactionPool.addRemoteTransactions(List.of(transaction, invalidTransaction)); @@ -756,7 +779,7 @@ public void transactionWithIncorrectNonceRemainsInPoolAndNotSelected() { 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 void increaseOfMinGasPriceAtRuntimeExcludeTxFromBeingSelected() { blockHeader, miningBeneficiary, Wei.ZERO, - NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY); + transactionSelectionService); transactionPool.addRemoteTransactions(List.of(transaction)); @@ -828,7 +851,7 @@ public void decreaseOfMinGasPriceAtRuntimeIncludeTxThatWasPreviouslyNotSelected( blockHeader, miningBeneficiary, Wei.ZERO, - NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY); + transactionSelectionService); transactionPool.addRemoteTransactions(List.of(transaction)); ensureTransactionIsValid(transaction, 0, 5); @@ -856,7 +879,7 @@ public void decreaseOfMinGasPriceAtRuntimeIncludeTxThatWasPreviouslyNotSelected( blockHeader, miningBeneficiary, Wei.ZERO, - NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY); + transactionSelectionService); final TransactionSelectionResults results2 = selector2.buildTransactionListForBlock(); @@ -884,7 +907,7 @@ public void shouldNotSelectTransactionsWithPriorityFeeLessThanConfig() { blockHeader, AddressHelpers.ofValue(1), Wei.ZERO, - NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY); + transactionSelectionService); transactionPool.addRemoteTransactions(List.of(txSelected, txNotSelected)); @@ -987,15 +1010,20 @@ private void internalBlockSelectionTimeoutSimulation( 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 @@ private void internalBlockSelectionTimeoutSimulation( blockHeader, miningBeneficiary, Wei.ZERO, - transactionSelectorFactory); + transactionSelectionService); transactionPool.addRemoteTransactions(transactionsToInject); @@ -1136,15 +1164,20 @@ private void internalBlockSelectionTimeoutSimulationInvalidTxs( 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 @@ private void internalBlockSelectionTimeoutSimulationInvalidTxs( blockHeader, miningBeneficiary, Wei.ZERO, - transactionSelectorFactory); + transactionSelectionService); transactionPool.addRemoteTransactions(transactionsToInject); @@ -1195,7 +1228,7 @@ protected BlockTransactionSelector createBlockSelectorAndSetupTxPool( final ProcessableBlockHeader blockHeader, final Address miningBeneficiary, final Wei blobGasPrice, - final PluginTransactionSelectorFactory transactionSelectorFactory) { + final TransactionSelectionService transactionSelectionService) { transactionPool = createTransactionPool(); @@ -1205,7 +1238,7 @@ protected BlockTransactionSelector createBlockSelectorAndSetupTxPool( blockHeader, miningBeneficiary, blobGasPrice, - transactionSelectorFactory); + transactionSelectionService); } protected BlockTransactionSelector createBlockSelector( @@ -1214,7 +1247,7 @@ protected BlockTransactionSelector createBlockSelector( final ProcessableBlockHeader blockHeader, final Address miningBeneficiary, final Wei blobGasPrice, - final PluginTransactionSelectorFactory transactionSelectorFactory) { + final TransactionSelectionService transactionSelectionService) { final BlockTransactionSelector selector = new BlockTransactionSelector( @@ -1231,7 +1264,7 @@ protected BlockTransactionSelector createBlockSelector( getFeeMarket(), new LondonGasCalculator(), GasLimitCalculator.constant(), - transactionSelectorFactory.create(), + transactionSelectionService.createPluginTransactionSelector(), ethScheduler); return selector; @@ -1344,6 +1377,7 @@ private BlockHeader blockHeader(final long number) { } protected MiningParameters createMiningParameters( + final TransactionSelectionService transactionSelectionService, final Wei minGasPrice, final double minBlockOccupancyRatio, final PositiveNumber txsSelectionMaxTime) { @@ -1353,11 +1387,13 @@ protected MiningParameters createMiningParameters( .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 @@ protected MiningParameters createMiningParameters( .minTransactionGasPrice(minGasPrice) .minBlockOccupancyRatio(minBlockOccupancyRatio) .build()) + .transactionSelectionService(transactionSelectionService) .genesisBlockPeriodSeconds(genesisBlockPeriodSeconds) .poaBlockTxsSelectionMaxTime(minBlockTimePercentage) .build(); diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockMinerTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockMinerTest.java index 6afa8ea593c..066fe5b2be3 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockMinerTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockMinerTest.java @@ -58,7 +58,7 @@ public void blockCreatedIsAddedToBlockChain() throws InterruptedException { 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 blockCreatorSupplier = @@ -100,7 +100,7 @@ public void failureToImportDoesNotTriggerObservers() throws InterruptedException 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 blockCreatorSupplier = @@ -146,7 +146,7 @@ public void blockValidationFailureBeforeImportDoesNotImportBlock() throws Interr 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 blockCreatorSupplier = 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 08e9092339a..32b3935018c 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 @@ -112,12 +112,15 @@ public void eip1559TransactionCurrentGasPriceLessThanMinimumIsSkippedAndKeptInTh 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 void eip1559TransactionCurrentGasPriceGreaterThanMinimumIsSelected() { 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 void eip1559PriorityTransactionCurrentGasPriceLessThanMinimumIsSelected() 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 void transactionFromSameSenderWithMixedTypes() { blockHeader, miningBeneficiary, Wei.ZERO, - NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY); + transactionSelectionService); transactionPool.addRemoteTransactions(List.of(txFrontier1, txLondon1, txFrontier2, txLondon2)); @@ -254,7 +263,7 @@ public void shouldNotSelectTransactionsWithPriorityFeeLessThanConfig() { blockHeader, AddressHelpers.ofValue(1), Wei.ZERO, - NO_PLUGIN_TRANSACTION_SELECTOR_FACTORY); + transactionSelectionService); transactionPool.addRemoteTransactions( List.of(txSelected1, txNotSelected1, txSelected2, txNotSelected2)); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java index f82bcbbecc5..1468c621026 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java @@ -19,7 +19,6 @@ 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 transactionSelectorFactory; private Optional synchronizer; @@ -42,20 +40,10 @@ public 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 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 static ProtocolContext init( final WorldStateArchive worldStateArchive, final ProtocolSchedule protocolSchedule, final ConsensusContextFactory consensusContextFactory, - final Optional transactionSelectorFactory, final BadBlockManager badBlockManager) { return new ProtocolContext( blockchain, worldStateArchive, consensusContextFactory.create(blockchain, worldStateArchive, protocolSchedule), - transactionSelectorFactory, badBlockManager); } @@ -103,8 +89,4 @@ public Optional safeConsensusContext(final Class .filter(c -> klass.isAssignableFrom(c.getClass())) .map(klass::cast); } - - public Optional getTransactionSelectorFactory() { - return transactionSelectorFactory; - } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParameters.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParameters.java index 7f543f370a3..0a7144d30d9 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParameters.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParameters.java @@ -16,6 +16,9 @@ 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 PositiveNumber getPoaBlockTxsSelectionMaxTime() { 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 diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java index 349c819ddac..cf142eb2ed8 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java @@ -50,7 +50,6 @@ 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 C as(final Class klass) { return null; } }, - Optional.empty(), new BadBlockManager()); } diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java index 03419637b66..25c65b357f8 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java @@ -36,7 +36,6 @@ 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 @@ private 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()); } 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 e14ab5969a5..9f061facac5 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 @@ -161,8 +161,7 @@ public void createStorage() { 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 = diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/AbstractBlockPropagationManagerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/AbstractBlockPropagationManagerTest.java index 4406d9a7ee5..a91b19c8e9e 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/AbstractBlockPropagationManagerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/AbstractBlockPropagationManagerTest.java @@ -65,7 +65,6 @@ import java.util.Collections; import java.util.List; -import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.function.Supplier; @@ -106,7 +105,6 @@ protected void setup(final DataStorageFormat dataStorageFormat) { blockchain, tempProtocolContext.getWorldStateArchive(), tempProtocolContext.getConsensusContext(ConsensusContext.class), - Optional.empty(), new BadBlockManager()); ethProtocolManager = EthProtocolManagerTestUtil.create( diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java index b4a2c8eaa69..d10be455ea5 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java @@ -39,7 +39,6 @@ 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 void setup(final DataStorageFormat storageFormat) { 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, diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java index 6fbbf3ed889..71c0bcb5440 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java @@ -44,7 +44,6 @@ import java.io.IOException; import java.util.List; -import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; @@ -151,8 +150,7 @@ public void searchesAgainstNetwork(final int headerRequestSize, final int common final EthContext ethContext = ethProtocolManager.ethContext(); final ProtocolContext protocolContext = - new ProtocolContext( - localBlockchain, worldStateArchive, null, Optional.empty(), new BadBlockManager()); + new ProtocolContext(localBlockchain, worldStateArchive, null, new BadBlockManager()); final EthTask task = DetermineCommonAncestorTask.create( diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java index 346dafe8ab4..1b19a076d2c 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java @@ -55,7 +55,6 @@ import org.hyperledger.besu.util.ExceptionUtils; import java.util.List; -import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicReference; @@ -89,8 +88,7 @@ public void setup() { EthProtocolConfiguration.defaultConfig()); ethContext = ethProtocolManager.ethContext(); protocolContext = - new ProtocolContext( - localBlockchain, worldStateArchive, null, Optional.empty(), new BadBlockManager()); + new ProtocolContext(localBlockchain, worldStateArchive, null, new BadBlockManager()); } @Test 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 2545eb818de..ff624baa761 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 @@ -125,8 +125,7 @@ public TestNode( 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); diff --git a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BlockchainReferenceTestCaseSpec.java b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BlockchainReferenceTestCaseSpec.java index 4c459fc2d06..985c977507f 100644 --- a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BlockchainReferenceTestCaseSpec.java +++ b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BlockchainReferenceTestCaseSpec.java @@ -109,8 +109,7 @@ public 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() { 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 bc08935037d..a78e689bcf4 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 @@ -177,8 +177,7 @@ private boolean buildContext( 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); diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 5e09c0cfa4f..bd3e0e43ef8 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 = 'jvIsInEUQ/NaxWCGkQIb72tuZsx5288Ownn2F6rsvjQ=' + knownHash = 'Jv/pqyKOoZo3wlxRRwmzPuLIJjEqyV1i55wFyIUV90A=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/TransactionSelectionService.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/TransactionSelectionService.java index aab6e717bad..b780015f0be 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/TransactionSelectionService.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/TransactionSelectionService.java @@ -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 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); } diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/txselection/PluginTransactionSelector.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/txselection/PluginTransactionSelector.java index 3d152c370ca..c323f6071c7 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/txselection/PluginTransactionSelector.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/txselection/PluginTransactionSelector.java @@ -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 @@ /** 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 evaluationContext) { + return SELECTED; + } + + @Override + public TransactionSelectionResult evaluateTransactionPostProcessing( + TransactionEvaluationContext evaluationContext, + TransactionProcessingResult processingResult) { + return SELECTED; + } + }; /** * Method that returns an OperationTracer that will be used when executing transactions that are