From b6dd25eeedb4815b6a6b0bb22c641b4e51da73ad Mon Sep 17 00:00:00 2001 From: Taccat Isid Date: Mon, 4 Oct 2021 11:48:01 +1300 Subject: [PATCH] WIP remove use of global quorum config Signed-off-by: Taccat Isid --- .../org/hyperledger/besu/RunnerBuilder.java | 4 +- .../besu/chainimport/RlpBlockImporter.java | 3 +- .../org/hyperledger/besu/cli/BesuCommand.java | 44 +++++++----- .../subcommands/operator/RestoreState.java | 6 +- .../controller/BesuControllerBuilder.java | 15 +++-- .../controller/IbftBesuControllerBuilder.java | 4 +- .../IbftLegacyBesuControllerBuilder.java | 8 +-- .../controller/QbftBesuControllerBuilder.java | 5 +- .../hyperledger/besu/PrivacyReorgTest.java | 3 +- .../org/hyperledger/besu/PrivacyTest.java | 3 +- .../hyperledger/besu/RunnerBuilderTest.java | 7 +- .../java/org/hyperledger/besu/RunnerTest.java | 6 +- .../chainexport/RlpBlockExporterTest.java | 6 +- .../chainimport/JsonBlockImporterTest.java | 3 +- .../chainimport/RlpBlockImporterTest.java | 9 +-- .../controller/BesuControllerBuilderTest.java | 5 +- .../besu/services/BesuEventsImplTest.java | 8 ++- .../besu/config/GoQuorumOptions.java | 26 ------- .../clique/NodeCanProduceNextBlockTest.java | 15 +++-- .../blockcreation/CliqueBlockCreatorTest.java | 3 +- .../CliqueMiningCoordinatorTest.java | 3 +- .../blockbased/VoteTallyCacheTestBase.java | 3 +- .../besu/consensus/ibft/IbftGossip.java | 12 +++- .../ibft/messagedata/ProposalMessageData.java | 19 ++++-- .../messagedata/RoundChangeMessageData.java | 20 ++++-- .../ibft/messagewrappers/Proposal.java | 8 ++- .../ibft/messagewrappers/RoundChange.java | 6 +- .../ibft/network/IbftMessageTransmitter.java | 13 +++- .../statemachine/IbftBlockHeightManager.java | 5 +- .../IbftBlockHeightManagerFactory.java | 5 ++ .../ibft/statemachine/IbftController.java | 8 ++- .../ibft/statemachine/IbftRoundFactory.java | 3 +- .../besu/consensus/ibft/IbftGossipTest.java | 17 ++++- .../ibft/messagedata/ProposalMessageTest.java | 12 ++-- .../messagedata/RoundChangeMessageTest.java | 13 ++-- .../IbftBlockHeightManagerTest.java | 15 +++++ .../ibft/statemachine/IbftControllerTest.java | 9 +++ .../protocol/Istanbul99ProtocolManager.java | 3 + .../Istanbul99ProtocolManagerTest.java | 1 + .../besu/consensus/qbft/QbftGossip.java | 14 +++- .../qbft/messagedata/ProposalMessageData.java | 19 ++++-- .../messagedata/RoundChangeMessageData.java | 20 ++++-- .../qbft/messagewrappers/Proposal.java | 10 ++- .../qbft/messagewrappers/RoundChange.java | 10 ++- .../qbft/network/QbftMessageTransmitter.java | 13 +++- .../qbft/payload/ProposalPayload.java | 9 ++- .../statemachine/QbftBlockHeightManager.java | 5 +- .../QbftBlockHeightManagerFactory.java | 5 ++ .../qbft/statemachine/QbftController.java | 10 ++- .../qbft/statemachine/QbftRoundFactory.java | 3 +- .../qbft/messagewrappers/ProposalTest.java | 4 +- .../qbft/messagewrappers/RoundChangeTest.java | 5 +- .../QbftBlockHeightManagerTest.java | 19 ++++++ .../qbft/statemachine/QbftControllerTest.java | 9 +++ .../ForkingValidatorProviderTest.java | 3 +- .../TransactionValidatorProviderTest.java | 3 +- .../api/graphql/GraphQLDataFetchers.java | 33 +++++---- .../pojoadapter/BlockAdapterBase.java | 11 +-- .../internal/pojoadapter/LogAdapter.java | 8 ++- .../pojoadapter/NormalBlockAdapter.java | 17 ++--- .../pojoadapter/PendingStateAdapter.java | 9 ++- .../pojoadapter/TransactionAdapter.java | 19 ++++-- .../pojoadapter/UncleBlockAdapter.java | 6 +- .../methods/DebugBatchSendRawTransaction.java | 16 +++-- .../internal/methods/DebugTraceBlock.java | 10 ++- .../jsonrpc/internal/methods/EthGetCode.java | 10 ++- .../methods/EthSendRawTransaction.java | 16 +++-- .../eea/AbstractEeaSendRawTransaction.java | 6 +- .../eea/PluginEeaSendRawTransaction.java | 9 ++- ...strictedOffchainEeaSendRawTransaction.java | 9 ++- ...estrictedOnchainEeaSendRawTransaction.java | 9 ++- .../GoQuorumSendRawPrivateTransaction.java | 7 +- .../jsonrpc/methods/DebugJsonRpcMethods.java | 7 +- .../jsonrpc/methods/EeaJsonRpcMethods.java | 3 + .../jsonrpc/methods/EthJsonRpcMethods.java | 8 ++- .../GoQuorumJsonRpcPrivacyMethods.java | 2 +- .../methods/JsonRpcMethodsFactory.java | 8 ++- .../api/util/DomainObjectDecodeUtils.java | 8 +-- .../api/graphql/AbstractDataFetcherTest.java | 4 +- .../AbstractEthGraphQLHttpServiceTest.java | 10 ++- .../graphql/GraphQLHttpServiceCorsTest.java | 4 +- .../GraphQLHttpServiceHostWhitelistTest.java | 4 +- .../api/graphql/GraphQLHttpServiceTest.java | 4 +- .../JsonRpcHttpServiceRpcApisTest.java | 2 +- .../DebugBatchSendRawTransactionTest.java | 3 +- .../internal/methods/DebugTraceBlockTest.java | 22 +++++- .../internal/methods/EthFeeHistoryTest.java | 3 +- .../methods/EthSendRawTransactionTest.java | 3 +- .../eea/EeaSendRawTransactionTest.java | 10 +++ .../eea/PluginEeaSendRawTransactionTest.java | 10 +++ ...ctedOffchainEeaSendRawTransactionTest.java | 10 +++ ...ictedOnchainEeaSendRawTransactionTest.java | 11 +++ ...GoQuorumSendRawPrivateTransactionTest.java | 14 +++- ...ewBlockHeadersSubscriptionServiceTest.java | 5 +- .../logs/LogsSubscriptionServiceTest.java | 4 +- .../api/query/BlockchainQueriesTest.java | 4 +- .../api/util/DomainObjectDecodeUtilsTest.java | 8 ++- .../blockcreation/BlockMinerTest.java | 4 +- .../BlockTransactionSelectorTest.java | 3 +- .../hyperledger/besu/ethereum/core/Block.java | 8 ++- .../besu/ethereum/core/BlockBody.java | 6 +- .../besu/ethereum/core/Transaction.java | 10 +-- .../core/encoding/TransactionDecoder.java | 5 -- .../mainnet/MutableProtocolSchedule.java | 11 ++- .../ethereum/mainnet/ProtocolSchedule.java | 3 + .../mainnet/ProtocolScheduleBuilder.java | 2 +- ...ueStoragePrefixedKeyBlockchainStorage.java | 7 +- .../GoQuorumKeyValueStorageProvider.java | 10 ++- ...ueStoragePrefixedKeyBlockchainStorage.java | 12 +++- .../keyvalue/KeyValueStorageProvider.java | 9 ++- .../KeyValueStorageProviderBuilder.java | 18 +++-- .../besu/ethereum/util/RawBlockIterator.java | 15 ++++- .../ethereum/core/BlockSyncTestUtils.java | 5 +- .../ethereum/core/BlockchainSetupUtil.java | 12 ++-- .../core/ExecutionContextTestFixture.java | 4 +- .../core/InMemoryKeyValueStorageProvider.java | 28 +++++--- .../BonsaiWorldStateKeyValueStorageTest.java | 4 +- .../besu/ethereum/bonsai/LogRollingTests.java | 7 +- .../besu/ethereum/bonsai/RollingImport.java | 4 +- .../ethereum/chain/DefaultBlockchainTest.java | 3 +- .../besu/ethereum/chain/GenesisStateTest.java | 7 +- .../ethereum/core/TransactionEIP1559Test.java | 4 +- .../core/TransactionIntegrationTest.java | 7 +- .../besu/ethereum/core/TransactionTest.java | 3 +- .../core/encoding/TransactionDecoderTest.java | 15 +++-- .../core/encoding/TransactionEncoderTest.java | 12 +++- .../ethereum/mainnet/IntrinsicGasTest.java | 4 +- .../mainnet/ProtocolScheduleTest.java | 13 +++- .../ethereum/mainnet/ValidationTestUtils.java | 8 ++- .../PrivateStateGenesisAllocatorTest.java | 3 +- .../privacy/PrivateStateRootResolverTest.java | 4 +- ...ngPrivateMarkerTransactionFactoryTest.java | 9 ++- ...ngPrivateMarkerTransactionFactoryTest.java | 9 ++- .../util/BlockchainUtilParameterizedTest.java | 9 ++- .../ethereum/util/RawBlockIteratorTest.java | 2 + .../besu/ethereum/vm/VMReferenceTest.java | 3 +- .../DefaultMutableWorldStateTest.java | 3 +- .../worldstate/MarkSweepPrunerTest.java | 4 +- .../besu/ethereum/worldstate/PrunerTest.java | 17 +++-- .../eth/manager/EthProtocolManager.java | 11 ++- .../besu/ethereum/eth/manager/EthServer.java | 67 +++++++------------ ...dGetPooledTransactionsFromPeerFetcher.java | 12 +++- .../manager/task/GetBodiesFromPeerTask.java | 4 +- .../GetPooledTransactionsFromPeerTask.java | 19 ++++-- .../eth/messages/BlockBodiesMessage.java | 17 +++-- .../messages/LimitedTransactionsMessages.java | 5 +- .../eth/messages/NewBlockMessage.java | 25 ++++--- .../messages/PooledTransactionsMessage.java | 16 +++-- .../eth/messages/TransactionsMessage.java | 18 +++-- .../ethereum/eth/sync/BlockBroadcaster.java | 9 ++- .../eth/sync/BlockPropagationManager.java | 9 ++- .../eth/sync/DefaultSynchronizer.java | 7 +- .../PendingTransactionsMessageProcessor.java | 7 +- .../transactions/TransactionPoolFactory.java | 4 +- .../TransactionsMessageHandler.java | 7 +- .../TransactionsMessageSender.java | 10 ++- .../besu/evmtool/DataStoreModule.java | 7 +- ethereum/p2p/build.gradle | 1 + .../BlockchainReferenceTestCaseSpec.java | 7 +- .../NoRewardProtocolScheduleWrapper.java | 7 ++ .../ethereum/retesteth/RetestethContext.java | 16 +++-- .../ethereum/retesteth/RetestethService.java | 8 ++- .../retesteth/methods/TestImportRawBlock.java | 6 +- 163 files changed, 1077 insertions(+), 433 deletions(-) delete mode 100644 config/src/main/java/org/hyperledger/besu/config/GoQuorumOptions.java diff --git a/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java b/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java index 4122643a1a3..7019a34add8 100644 --- a/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java @@ -585,7 +585,9 @@ public Runner build() { if (graphQLConfiguration.isEnabled()) { final GraphQLDataFetchers fetchers = new GraphQLDataFetchers( - supportedCapabilities, privacyParameters.getGoQuorumPrivacyParameters()); + supportedCapabilities, + besuController.getGenesisConfigOptions(), + privacyParameters.getGoQuorumPrivacyParameters()); final GraphQLDataFetcherContextImpl dataFetcherContext = new GraphQLDataFetcherContextImpl( blockchainQueries, diff --git a/besu/src/main/java/org/hyperledger/besu/chainimport/RlpBlockImporter.java b/besu/src/main/java/org/hyperledger/besu/chainimport/RlpBlockImporter.java index 96d7229fc33..b1dd83d1a29 100644 --- a/besu/src/main/java/org/hyperledger/besu/chainimport/RlpBlockImporter.java +++ b/besu/src/main/java/org/hyperledger/besu/chainimport/RlpBlockImporter.java @@ -96,7 +96,8 @@ public RlpBlockImporter.ImportResult importBlockchain( blocks, rlp -> BlockHeader.readFrom( - rlp, ScheduleBasedBlockHeaderFunctions.create(protocolSchedule)))) { + rlp, ScheduleBasedBlockHeaderFunctions.create(protocolSchedule)), + besuController.getGenesisConfigOptions())) { BlockHeader previousHeader = null; CompletableFuture previousBlockFuture = null; final AtomicReference threadedException = new AtomicReference<>(); 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 4dd8f06bdc3..3480807336b 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -78,7 +78,6 @@ import org.hyperledger.besu.cli.util.VersionProvider; import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.config.GenesisConfigOptions; -import org.hyperledger.besu.config.GoQuorumOptions; import org.hyperledger.besu.consensus.qbft.pki.PkiBlockCreationConfiguration; import org.hyperledger.besu.consensus.qbft.pki.PkiBlockCreationConfigurationProvider; import org.hyperledger.besu.controller.BesuController; @@ -1204,10 +1203,8 @@ public void run() { // Set the goquorum compatibility mode based on the genesis file if (genesisFile != null) { - genesisConfigOptions = readGenesisConfigOptions(); + genesisConfigOptions = readGenesisConfigOptions(false); if (genesisConfigOptions.isQuorum()) { - // this static flag is read by the RLP decoder - GoQuorumOptions.goQuorumCompatibilityMode = true; isGoQuorumCompatibilityMode = true; } } @@ -1517,18 +1514,6 @@ private void validateDnsOptionsParams() { } } - private GenesisConfigOptions readGenesisConfigOptions() { - final GenesisConfigOptions genesisConfigOptions; - try { - final GenesisConfigFile genesisConfigFile = GenesisConfigFile.fromConfig(genesisConfig()); - genesisConfigOptions = genesisConfigFile.getConfigOptions(genesisConfigOverrides); - } catch (final Exception e) { - throw new ParameterException( - this.commandLine, "Unable to load genesis file. " + e.getCause()); - } - return genesisConfigOptions; - } - private void issueOptionWarnings() { // Check that P2P options are able to work CommandLineUtils.checkOptionDependencies( @@ -2276,7 +2261,7 @@ private KeyValueStorageProvider keyValueStorageProvider(final String name) { "No KeyValueStorageFactory found for key: " + name))) .withCommonConfiguration(pluginCommonConfiguration) .withMetricsSystem(getMetricsSystem()) - .isGoQuorumCompatibilityMode(isGoQuorumCompatibilityMode.booleanValue()) + .withGenesisOptions(readGenesisConfigOptions(true)) .build(); } return this.keyValueStorageProvider; @@ -2512,8 +2497,23 @@ private EthNetworkConfig updateNetworkConfig(final NetworkName network) { return builder.build(); } + private GenesisConfigOptions readGenesisConfigOptions(final boolean enableDefaultFallback) { + try { + GenesisConfigFile genesisConfigFile = getGenesisConfigFile(enableDefaultFallback); + return genesisConfigFile.getConfigOptions(genesisConfigOverrides); + } catch (final Exception e) { + throw new ParameterException( + this.commandLine, "Unable to load genesis file. " + e.getCause()); + } + } + private GenesisConfigFile getGenesisConfigFile() { - return GenesisConfigFile.fromConfig(genesisConfig()); + return getGenesisConfigFile(false); + } + + private GenesisConfigFile getGenesisConfigFile(final boolean enableDefaultFallback) { + String genesisConfig = enableDefaultFallback ? genesisConfigOrDefault() : genesisConfig(); + return GenesisConfigFile.fromConfig(genesisConfig); } private String genesisConfig() { @@ -2525,6 +2525,14 @@ private String genesisConfig() { } } + private String genesisConfigOrDefault() { + if (genesisFile == null) { + return updateNetworkConfig(getNetwork()).getGenesisConfig(); + } else { + return genesisConfig(); + } + } + // dataDir() is public because it is accessed by subcommands public Path dataDir() { return dataPath.toAbsolutePath(); diff --git a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/RestoreState.java b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/RestoreState.java index c49237d3ce2..32dd4547018 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/RestoreState.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/RestoreState.java @@ -141,9 +141,13 @@ private void restoreBlocks() throws IOException { final BlockHeader header = BlockHeader.readFrom( new BytesValueRLPInput(Bytes.wrap(headerEntry), false, true), functions); + final boolean goQuorumCompatibilityMode = + besuController.getGenesisConfigOptions().isQuorum(); final BlockBody body = BlockBody.readFrom( - new BytesValueRLPInput(Bytes.wrap(bodyEntry), false, true), functions); + new BytesValueRLPInput(Bytes.wrap(bodyEntry), false, true), + functions, + goQuorumCompatibilityMode); final RLPInput receiptsRlp = new BytesValueRLPInput(Bytes.wrap(receiptEntry), false, true); final int receiptsCount = receiptsRlp.enterList(); final List receipts = new ArrayList<>(receiptsCount); 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 b937cb5707d..aaa4f5f4a6d 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import org.hyperledger.besu.config.GenesisConfigFile; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.consensus.qbft.pki.PkiBlockCreationConfiguration; import org.hyperledger.besu.crypto.NodeKey; import org.hyperledger.besu.datatypes.Hash; @@ -103,6 +104,7 @@ public abstract class BesuControllerBuilder { private boolean isPruningEnabled; private PrunerConfiguration prunerConfiguration; Map genesisConfigOverrides; + GenesisConfigOptions genesisConfigOptions; private Map requiredBlocks = Collections.emptyMap(); private long reorgLoggingThreshold; private DataStorageConfiguration dataStorageConfiguration = @@ -117,6 +119,8 @@ public BesuControllerBuilder storageProvider(final StorageProvider storageProvid public BesuControllerBuilder genesisConfigFile(final GenesisConfigFile genesisConfig) { this.genesisConfig = genesisConfig; + genesisConfigOptions = genesisConfig.getConfigOptions(genesisConfigOverrides); + return this; } @@ -203,6 +207,7 @@ public BesuControllerBuilder pruningConfiguration(final PrunerConfiguration prun public BesuControllerBuilder genesisConfigOverrides( final Map genesisConfigOverrides) { this.genesisConfigOverrides = genesisConfigOverrides; + genesisConfigOptions = genesisConfig.getConfigOptions(genesisConfigOverrides); return this; } @@ -341,7 +346,8 @@ public BesuController build() { syncState, dataDirectory, clock, - metricsSystem); + metricsSystem, + genesisConfigOptions); final MiningCoordinator miningCoordinator = createMiningCoordinator( @@ -434,6 +440,7 @@ protected EthProtocolManager createEthProtocolManager( protocolContext.getWorldStateArchive(), transactionPool, ethereumWireProtocolConfiguration, + genesisConfigOptions, ethPeers, ethMessages, ethContext, @@ -460,16 +467,14 @@ private WorldStateArchive createWorldStateArchive( private List createPeerValidators(final ProtocolSchedule protocolSchedule) { final List validators = new ArrayList<>(); - final OptionalLong daoBlock = - genesisConfig.getConfigOptions(genesisConfigOverrides).getDaoForkBlock(); + final OptionalLong daoBlock = genesisConfigOptions.getDaoForkBlock(); if (daoBlock.isPresent()) { // Setup dao validator validators.add( new DaoForkPeerValidator(protocolSchedule, metricsSystem, daoBlock.getAsLong())); } - final OptionalLong classicBlock = - genesisConfig.getConfigOptions(genesisConfigOverrides).getClassicForkBlock(); + final OptionalLong classicBlock = genesisConfigOptions.getClassicForkBlock(); // setup classic validator if (classicBlock.isPresent()) { validators.add( diff --git a/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java index b647c358cfd..9cccd574ad1 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java @@ -149,7 +149,7 @@ protected MiningCoordinator createMiningCoordinator( final UniqueMessageMulticaster uniqueMessageMulticaster = new UniqueMessageMulticaster(peers, bftConfig.getGossipedHistoryLimit()); - final IbftGossip gossiper = new IbftGossip(uniqueMessageMulticaster); + final IbftGossip gossiper = new IbftGossip(protocolSchedule, uniqueMessageMulticaster); final BftFinalState finalState = new BftFinalState( @@ -183,9 +183,11 @@ protected MiningCoordinator createMiningCoordinator( final BftEventHandler ibftController = new IbftController( + protocolSchedule, blockchain, finalState, new IbftBlockHeightManagerFactory( + protocolSchedule, finalState, new IbftRoundFactory( finalState, diff --git a/besu/src/main/java/org/hyperledger/besu/controller/IbftLegacyBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/IbftLegacyBesuControllerBuilder.java index 8d09fba928d..00df7cc0463 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/IbftLegacyBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/IbftLegacyBesuControllerBuilder.java @@ -74,9 +74,7 @@ protected MiningCoordinator createMiningCoordinator( @Override protected ProtocolSchedule createProtocolSchedule() { return IbftProtocolSchedule.create( - genesisConfig.getConfigOptions(genesisConfigOverrides), - privacyParameters, - isRevertReasonEnabled); + genesisConfigOptions, privacyParameters, isRevertReasonEnabled); } @Override @@ -84,8 +82,7 @@ protected IbftLegacyContext createConsensusContext( final Blockchain blockchain, final WorldStateArchive worldStateArchive, final ProtocolSchedule protocolSchedule) { - final IbftLegacyConfigOptions ibftConfig = - genesisConfig.getConfigOptions(genesisConfigOverrides).getIbftLegacyConfigOptions(); + final IbftLegacyConfigOptions ibftConfig = genesisConfigOptions.getIbftLegacyConfigOptions(); final EpochManager epochManager = new EpochManager(ibftConfig.getEpochLength()); final ValidatorProvider validatorProvider = BlockValidatorProvider.nonForkingValidatorProvider( @@ -132,6 +129,7 @@ protected EthProtocolManager createEthProtocolManager( protocolContext.getWorldStateArchive(), transactionPool, ethereumWireProtocolConfiguration, + genesisConfigOptions, ethPeers, ethMessages, ethContext, diff --git a/besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java index a82baf79598..837fa30b313 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java @@ -173,7 +173,8 @@ protected MiningCoordinator createMiningCoordinator( final UniqueMessageMulticaster uniqueMessageMulticaster = new UniqueMessageMulticaster(peers, qbftConfig.getGossipedHistoryLimit()); - final QbftGossip gossiper = new QbftGossip(uniqueMessageMulticaster, bftExtraDataCodec().get()); + final QbftGossip gossiper = + new QbftGossip(protocolSchedule, uniqueMessageMulticaster, bftExtraDataCodec().get()); final BftFinalState finalState = new BftFinalState( @@ -207,9 +208,11 @@ protected MiningCoordinator createMiningCoordinator( final BftEventHandler qbftController = new QbftController( + protocolSchedule, blockchain, finalState, new QbftBlockHeightManagerFactory( + protocolSchedule, finalState, new QbftRoundFactory( finalState, diff --git a/besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java b/besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java index ce1d5c6d92f..dee39f988fe 100644 --- a/besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java +++ b/besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java @@ -22,6 +22,7 @@ import static org.mockito.Mockito.when; import org.hyperledger.besu.config.GenesisConfigFile; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.controller.BesuController; import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.crypto.NodeKeyUtils; @@ -173,7 +174,7 @@ public void setUp() throws IOException { .fromGenesisConfig(GenesisConfigFile.development()) .synchronizerConfiguration(SynchronizerConfiguration.builder().build()) .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) - .storageProvider(new InMemoryKeyValueStorageProvider()) + .storageProvider(new InMemoryKeyValueStorageProvider(new StubGenesisConfigOptions())) .networkId(BigInteger.ONE) .miningParameters( new MiningParameters.Builder() diff --git a/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java b/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java index 4bbf09d0e38..2146846987f 100644 --- a/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java +++ b/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java @@ -19,6 +19,7 @@ import static org.hyperledger.besu.ethereum.core.PrivacyParameters.ONCHAIN_PRIVACY; import org.hyperledger.besu.config.GenesisConfigFile; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.controller.BesuController; import org.hyperledger.besu.crypto.NodeKeyUtils; import org.hyperledger.besu.datatypes.Address; @@ -105,7 +106,7 @@ private BesuController setUpControllerWithPrivacyEnabled(final boolean onchainEn .fromGenesisConfig(GenesisConfigFile.mainnet()) .synchronizerConfiguration(SynchronizerConfiguration.builder().build()) .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) - .storageProvider(new InMemoryKeyValueStorageProvider()) + .storageProvider(new InMemoryKeyValueStorageProvider(new StubGenesisConfigOptions())) .networkId(BigInteger.ONE) .miningParameters(new MiningParameters.Builder().enabled(false).build()) .nodeKey(NodeKeyUtils.generate()) diff --git a/besu/src/test/java/org/hyperledger/besu/RunnerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/RunnerBuilderTest.java index f8568878855..79fe9562293 100644 --- a/besu/src/test/java/org/hyperledger/besu/RunnerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/RunnerBuilderTest.java @@ -21,6 +21,7 @@ import static org.mockito.Mockito.when; import org.hyperledger.besu.cli.config.EthNetworkConfig; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.consensus.common.bft.BftEventQueue; import org.hyperledger.besu.consensus.common.bft.network.PeerConnectionTracker; import org.hyperledger.besu.consensus.common.bft.protocol.BftProtocolManager; @@ -160,10 +161,12 @@ public void movingAcrossProtocolSpecsUpdatesNodeRecord() { final BlockDataGenerator gen = new BlockDataGenerator(); final String p2pAdvertisedHost = "172.0.0.1"; final int p2pListenPort = 30301; - final StorageProvider storageProvider = new InMemoryKeyValueStorageProvider(); + final StorageProvider storageProvider = + new InMemoryKeyValueStorageProvider(new StubGenesisConfigOptions()); final Block genesisBlock = gen.genesisBlock(); final MutableBlockchain blockchain = - createInMemoryBlockchain(genesisBlock, new MainnetBlockHeaderFunctions()); + createInMemoryBlockchain( + new StubGenesisConfigOptions(), genesisBlock, new MainnetBlockHeaderFunctions()); when(besuController.getProtocolContext().getBlockchain()).thenReturn(blockchain); final Runner runner = new RunnerBuilder() diff --git a/besu/src/test/java/org/hyperledger/besu/RunnerTest.java b/besu/src/test/java/org/hyperledger/besu/RunnerTest.java index 70d181b363c..8e2a7dadb51 100644 --- a/besu/src/test/java/org/hyperledger/besu/RunnerTest.java +++ b/besu/src/test/java/org/hyperledger/besu/RunnerTest.java @@ -22,6 +22,7 @@ import org.hyperledger.besu.cli.config.EthNetworkConfig; import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.config.JsonUtil; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.controller.BesuController; import org.hyperledger.besu.controller.MainnetBesuControllerBuilder; import org.hyperledger.besu.crypto.KeyPairUtil; @@ -207,7 +208,7 @@ private void syncFromGenesis(final SyncMode mode, final GenesisConfigFile genesi .metricsSystem(noOpMetricsSystem) .permissioningService(new PermissioningServiceImpl()) .staticNodes(emptySet()) - .storageProvider(new InMemoryKeyValueStorageProvider()) + .storageProvider(new InMemoryKeyValueStorageProvider(new StubGenesisConfigOptions())) .forkIdSupplier(() -> Collections.singletonList(Bytes.EMPTY)); Runner runnerBehind = null; @@ -251,7 +252,7 @@ private void syncFromGenesis(final SyncMode mode, final GenesisConfigFile genesi .networkId(networkId) .miningParameters(new MiningParameters.Builder().enabled(false).build()) .nodeKey(NodeKeyUtils.generate()) - .storageProvider(new InMemoryKeyValueStorageProvider()) + .storageProvider(new InMemoryKeyValueStorageProvider(new StubGenesisConfigOptions())) .metricsSystem(noOpMetricsSystem) .privacyParameters(PrivacyParameters.DEFAULT) .clock(TestClock.fixed()) @@ -401,6 +402,7 @@ private StorageProvider createKeyValueStorageProvider(final Path dataDir, final RocksDBMetricsFactory.PUBLIC_ROCKS_DB_METRICS)) .withCommonConfiguration(new BesuConfigurationImpl(dataDir, dbDir)) .withMetricsSystem(new NoOpMetricsSystem()) + .withGenesisOptions(new StubGenesisConfigOptions()) .build(); } diff --git a/besu/src/test/java/org/hyperledger/besu/chainexport/RlpBlockExporterTest.java b/besu/src/test/java/org/hyperledger/besu/chainexport/RlpBlockExporterTest.java index 58e6db1ef0e..b3566bb586f 100644 --- a/besu/src/test/java/org/hyperledger/besu/chainexport/RlpBlockExporterTest.java +++ b/besu/src/test/java/org/hyperledger/besu/chainexport/RlpBlockExporterTest.java @@ -19,6 +19,7 @@ import org.hyperledger.besu.chainimport.RlpBlockImporter; import org.hyperledger.besu.config.GenesisConfigFile; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.controller.BesuController; import org.hyperledger.besu.crypto.NodeKeyUtils; import org.hyperledger.besu.ethereum.GasLimitCalculator; @@ -82,7 +83,7 @@ private static BesuController createController() throws IOException { .fromGenesisConfig(GenesisConfigFile.mainnet()) .synchronizerConfiguration(SynchronizerConfiguration.builder().build()) .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) - .storageProvider(new InMemoryKeyValueStorageProvider()) + .storageProvider(new InMemoryKeyValueStorageProvider(new StubGenesisConfigOptions())) .networkId(BigInteger.ONE) .miningParameters(new MiningParameters.Builder().enabled(false).build()) .nodeKey(NodeKeyUtils.generate()) @@ -239,7 +240,8 @@ private RawBlockIterator getBlockIterator(final Path blocks) throws IOException return new RawBlockIterator( blocks, rlp -> - BlockHeader.readFrom(rlp, ScheduleBasedBlockHeaderFunctions.create(protocolSchedule))); + BlockHeader.readFrom(rlp, ScheduleBasedBlockHeaderFunctions.create(protocolSchedule)), + new StubGenesisConfigOptions()); } private Block getBlock(final Blockchain blockchain, final long blockNumber) { diff --git a/besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java b/besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java index feca1d2fedc..1295e327133 100644 --- a/besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java +++ b/besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.config.JsonUtil; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.controller.BesuController; import org.hyperledger.besu.crypto.NodeKeyUtils; import org.hyperledger.besu.datatypes.Address; @@ -415,7 +416,7 @@ protected BesuController createController(final GenesisConfigFile genesisConfigF .fromGenesisConfig(genesisConfigFile) .synchronizerConfiguration(SynchronizerConfiguration.builder().build()) .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) - .storageProvider(new InMemoryKeyValueStorageProvider()) + .storageProvider(new InMemoryKeyValueStorageProvider(new StubGenesisConfigOptions())) .networkId(BigInteger.valueOf(10)) .miningParameters( new MiningParameters.Builder().minTransactionGasPrice(Wei.ZERO).enabled(true).build()) diff --git a/besu/src/test/java/org/hyperledger/besu/chainimport/RlpBlockImporterTest.java b/besu/src/test/java/org/hyperledger/besu/chainimport/RlpBlockImporterTest.java index c7b14bbb08c..37acd096ea3 100644 --- a/besu/src/test/java/org/hyperledger/besu/chainimport/RlpBlockImporterTest.java +++ b/besu/src/test/java/org/hyperledger/besu/chainimport/RlpBlockImporterTest.java @@ -19,6 +19,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.hyperledger.besu.config.GenesisConfigFile; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.controller.BesuController; import org.hyperledger.besu.crypto.NodeKeyUtils; import org.hyperledger.besu.ethereum.GasLimitCalculator; @@ -62,7 +63,7 @@ public void blockImport() throws IOException { .fromGenesisConfig(GenesisConfigFile.mainnet()) .synchronizerConfiguration(SynchronizerConfiguration.builder().build()) .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) - .storageProvider(new InMemoryKeyValueStorageProvider()) + .storageProvider(new InMemoryKeyValueStorageProvider(new StubGenesisConfigOptions())) .networkId(BigInteger.ONE) .miningParameters(new MiningParameters.Builder().enabled(false).build()) .nodeKey(NodeKeyUtils.generate()) @@ -90,7 +91,7 @@ public void blockImportRejectsBadPow() throws IOException { .fromGenesisConfig(GenesisConfigFile.mainnet()) .synchronizerConfiguration(SynchronizerConfiguration.builder().build()) .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) - .storageProvider(new InMemoryKeyValueStorageProvider()) + .storageProvider(new InMemoryKeyValueStorageProvider(new StubGenesisConfigOptions())) .networkId(BigInteger.ONE) .miningParameters(new MiningParameters.Builder().enabled(false).build()) .nodeKey(NodeKeyUtils.generate()) @@ -118,7 +119,7 @@ public void blockImportCanSkipPow() throws IOException { .fromGenesisConfig(GenesisConfigFile.mainnet()) .synchronizerConfiguration(SynchronizerConfiguration.builder().build()) .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) - .storageProvider(new InMemoryKeyValueStorageProvider()) + .storageProvider(new InMemoryKeyValueStorageProvider(new StubGenesisConfigOptions())) .networkId(BigInteger.ONE) .miningParameters(new MiningParameters.Builder().enabled(false).build()) .nodeKey(NodeKeyUtils.generate()) @@ -158,7 +159,7 @@ public void ibftImport() throws IOException { .fromGenesisConfig(GenesisConfigFile.fromConfig(config)) .synchronizerConfiguration(SynchronizerConfiguration.builder().build()) .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) - .storageProvider(new InMemoryKeyValueStorageProvider()) + .storageProvider(new InMemoryKeyValueStorageProvider(new StubGenesisConfigOptions())) .networkId(BigInteger.valueOf(10)) .miningParameters(new MiningParameters.Builder().enabled(false).build()) .nodeKey(NodeKeyUtils.generate()) diff --git a/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerBuilderTest.java index de8bb3f5493..03c9ca03dc6 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerBuilderTest.java @@ -25,6 +25,7 @@ import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.config.Keccak256ConfigOptions; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.crypto.NodeKey; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.GasLimitCalculator; @@ -105,7 +106,9 @@ public void setup() { when(storageProvider.createBlockchainStorage(any())) .thenReturn( new KeyValueStoragePrefixedKeyBlockchainStorage( - new InMemoryKeyValueStorage(), new MainnetBlockHeaderFunctions())); + new InMemoryKeyValueStorage(), + new MainnetBlockHeaderFunctions(), + new StubGenesisConfigOptions())); when(synchronizerConfiguration.getDownloaderParallelism()).thenReturn(1); when(synchronizerConfiguration.getTransactionsParallelism()).thenReturn(1); when(synchronizerConfiguration.getComputationParallelism()).thenReturn(1); diff --git a/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java b/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java index a5d71c440ab..6cccf4d7e02 100644 --- a/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java +++ b/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java @@ -21,6 +21,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.crypto.SignatureAlgorithm; import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; @@ -113,7 +114,9 @@ public void setUp() { DefaultBlockchain.createMutable( gen.genesisBlock(), new KeyValueStoragePrefixedKeyBlockchainStorage( - new InMemoryKeyValueStorage(), new MainnetBlockHeaderFunctions()), + new InMemoryKeyValueStorage(), + new MainnetBlockHeaderFunctions(), + new StubGenesisConfigOptions()), new NoOpMetricsSystem(), 0); @@ -124,6 +127,7 @@ public void setUp() { when(mockProtocolContext.getBlockchain()).thenReturn(blockchain); when(mockProtocolContext.getWorldStateArchive()).thenReturn(mockWorldStateArchive); when(mockProtocolSchedule.getByBlockNumber(anyLong())).thenReturn(mockProtocolSpec); + when(mockProtocolSchedule.getGenesisConfigOptions()).thenReturn(new StubGenesisConfigOptions()); when(mockProtocolSpec.getTransactionValidator()).thenReturn(mockTransactionValidator); when(mockProtocolSpec.getFeeMarket()).thenReturn(FeeMarket.london(0L)); when(mockTransactionValidator.validate(any(), any(Optional.class), any())) @@ -133,7 +137,7 @@ public void setUp() { when(mockWorldStateArchive.getMutable(any(), any(), anyBoolean())) .thenReturn(Optional.of(mockWorldState)); - blockBroadcaster = new BlockBroadcaster(mockEthContext); + blockBroadcaster = new BlockBroadcaster(mockEthContext, new StubGenesisConfigOptions()); syncState = new SyncState(blockchain, mockEthPeers); TransactionPoolConfiguration txPoolConfig = ImmutableTransactionPoolConfiguration.builder().txPoolMaxSize(1).build(); diff --git a/config/src/main/java/org/hyperledger/besu/config/GoQuorumOptions.java b/config/src/main/java/org/hyperledger/besu/config/GoQuorumOptions.java deleted file mode 100644 index 19434618825..00000000000 --- a/config/src/main/java/org/hyperledger/besu/config/GoQuorumOptions.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * 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.config; - -/** - * Flag to determine whether we are processing in GoQuorum mode. Note that this mode is incompatible - * with MainNet. - */ -public class GoQuorumOptions { - // To make it easier for tests to reset the value to default - public static final boolean GOQUORUM_COMPATIBILITY_MODE_DEFAULT_VALUE = false; - - public static boolean goQuorumCompatibilityMode = GOQUORUM_COMPATIBILITY_MODE_DEFAULT_VALUE; -} 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 4fbc5edaa26..bdc1734f488 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 @@ -21,6 +21,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.consensus.clique.headervalidationrules.SignerRateLimitValidationRule; import org.hyperledger.besu.consensus.common.validator.ValidatorProvider; import org.hyperledger.besu.crypto.KeyPair; @@ -74,7 +75,7 @@ public void networkWithOneValidatorIsAllowedToCreateConsecutiveBlocks() { genesisBlock = createEmptyBlock(proposerKeyPair); - blockChain = createInMemoryBlockchain(genesisBlock); + blockChain = createInMemoryBlockchain(new StubGenesisConfigOptions(), genesisBlock); final ValidatorProvider validatorProvider = mock(ValidatorProvider.class); when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); @@ -98,7 +99,7 @@ public void networkWithTwoValidatorsIsAllowedToProduceBlockIfNotPreviousBlockPro genesisBlock = createEmptyBlock(otherNodeKeyPair); - blockChain = createInMemoryBlockchain(genesisBlock); + blockChain = createInMemoryBlockchain(new StubGenesisConfigOptions(), genesisBlock); final ValidatorProvider validatorProvider = mock(ValidatorProvider.class); when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); @@ -131,7 +132,7 @@ public void networkWithTwoValidatorsIsNotAllowedToProduceBlockIfIsPreviousBlockP genesisBlock = createEmptyBlock(proposerKeyPair); - blockChain = createInMemoryBlockchain(genesisBlock); + blockChain = createInMemoryBlockchain(new StubGenesisConfigOptions(), genesisBlock); final ValidatorProvider validatorProvider = mock(ValidatorProvider.class); when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); @@ -160,7 +161,7 @@ public void withThreeValidatorsMustHaveOneBlockBetweenSignings() { genesisBlock = createEmptyBlock(proposerKeyPair); - blockChain = createInMemoryBlockchain(genesisBlock); + blockChain = createInMemoryBlockchain(new StubGenesisConfigOptions(), genesisBlock); final ValidatorProvider validatorProvider = mock(ValidatorProvider.class); when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); @@ -204,7 +205,7 @@ public void signerIsValidIfInsufficientBlocksExistInHistory() { genesisBlock = createEmptyBlock(proposerKeyPair); - blockChain = createInMemoryBlockchain(genesisBlock); + blockChain = createInMemoryBlockchain(new StubGenesisConfigOptions(), genesisBlock); final ValidatorProvider validatorProvider = mock(ValidatorProvider.class); when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); @@ -232,7 +233,7 @@ public void exceptionIsThrownIfOnAnOrphanedChain() { genesisBlock = createEmptyBlock(proposerKeyPair); - blockChain = createInMemoryBlockchain(genesisBlock); + blockChain = createInMemoryBlockchain(new StubGenesisConfigOptions(), genesisBlock); final ValidatorProvider validatorProvider = mock(ValidatorProvider.class); when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); @@ -255,7 +256,7 @@ public void exceptionIsThrownIfOnAnOrphanedChain() { public void nonValidatorIsNotAllowedToCreateABlock() { genesisBlock = createEmptyBlock(otherNodeKeyPair); - blockChain = createInMemoryBlockchain(genesisBlock); + blockChain = createInMemoryBlockchain(new StubGenesisConfigOptions(), genesisBlock); final ValidatorProvider validatorProvider = mock(ValidatorProvider.class); when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); 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 c20f25534c6..339622fcfdc 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 @@ -22,6 +22,7 @@ import static org.mockito.Mockito.when; import org.hyperledger.besu.config.GenesisConfigFile; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.consensus.clique.CliqueBlockInterface; import org.hyperledger.besu.consensus.clique.CliqueContext; import org.hyperledger.besu.consensus.clique.CliqueExtraData; @@ -99,7 +100,7 @@ public void setup() { final Block genesis = GenesisState.fromConfig(GenesisConfigFile.mainnet(), protocolSchedule).getBlock(); - blockchain = createInMemoryBlockchain(genesis); + blockchain = createInMemoryBlockchain(new StubGenesisConfigOptions(), genesis); protocolContext = new ProtocolContext(blockchain, stateArchive, cliqueContext); epochManager = new EpochManager(10); diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMiningCoordinatorTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMiningCoordinatorTest.java index 0d7c08a4568..7ab31aff375 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMiningCoordinatorTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMiningCoordinatorTest.java @@ -23,6 +23,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.consensus.clique.CliqueBlockInterface; import org.hyperledger.besu.consensus.clique.CliqueContext; import org.hyperledger.besu.consensus.clique.CliqueMiningTracker; @@ -85,7 +86,7 @@ public void setup() { headerTestFixture.number(1); Block genesisBlock = createEmptyBlock(0, Hash.ZERO, proposerKeys); // not normally signed but ok - blockChain = createInMemoryBlockchain(genesisBlock); + blockChain = createInMemoryBlockchain(new StubGenesisConfigOptions(), genesisBlock); when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validators); final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTestBase.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTestBase.java index ea5e308ab75..5ad1b186ce3 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTestBase.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTestBase.java @@ -19,6 +19,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.consensus.common.BlockInterface; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; @@ -62,7 +63,7 @@ public void constructThreeBlockChain() { genesisBlock = createEmptyBlock(0, Hash.ZERO); - blockChain = createInMemoryBlockchain(genesisBlock); + blockChain = createInMemoryBlockchain(new StubGenesisConfigOptions(), genesisBlock); block_1 = createEmptyBlock(1, genesisBlock.getHeader().getHash()); block_2 = createEmptyBlock(2, block_1.getHeader().getHash()); diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/IbftGossip.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/IbftGossip.java index c19f51bf6b9..be78d655860 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/IbftGossip.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/IbftGossip.java @@ -23,6 +23,7 @@ import org.hyperledger.besu.consensus.ibft.messagedata.ProposalMessageData; import org.hyperledger.besu.consensus.ibft.messagedata.RoundChangeMessageData; import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.Message; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; @@ -34,13 +35,16 @@ public class IbftGossip implements Gossiper { private final ValidatorMulticaster multicaster; + private final boolean goQuorumCompatibilityMode; /** * Constructor that attaches gossip logic to a set of multicaster * * @param multicaster Network connections to the remote validators */ - public IbftGossip(final ValidatorMulticaster multicaster) { + public IbftGossip( + final ProtocolSchedule protocolSchedule, final ValidatorMulticaster multicaster) { + this.goQuorumCompatibilityMode = protocolSchedule.getGenesisConfigOptions().isQuorum(); this.multicaster = multicaster; } @@ -55,7 +59,8 @@ public void send(final Message message) { final Authored decodedMessage; switch (messageData.getCode()) { case IbftV2.PROPOSAL: - decodedMessage = ProposalMessageData.fromMessageData(messageData).decode(); + decodedMessage = + ProposalMessageData.fromMessageData(messageData, goQuorumCompatibilityMode).decode(); break; case IbftV2.PREPARE: decodedMessage = PrepareMessageData.fromMessageData(messageData).decode(); @@ -64,7 +69,8 @@ public void send(final Message message) { decodedMessage = CommitMessageData.fromMessageData(messageData).decode(); break; case IbftV2.ROUND_CHANGE: - decodedMessage = RoundChangeMessageData.fromMessageData(messageData).decode(); + decodedMessage = + RoundChangeMessageData.fromMessageData(messageData, goQuorumCompatibilityMode).decode(); break; default: throw new IllegalArgumentException( diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/messagedata/ProposalMessageData.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/messagedata/ProposalMessageData.java index f2bde92b01a..4038fb0c2d3 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/messagedata/ProposalMessageData.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/messagedata/ProposalMessageData.java @@ -23,22 +23,29 @@ public class ProposalMessageData extends AbstractBftMessageData { private static final int MESSAGE_CODE = IbftV2.PROPOSAL; + private final boolean goQuorumCompatibilityMode; - private ProposalMessageData(final Bytes data) { + private ProposalMessageData(final Bytes data, final boolean goQuorumCompatibilityMode) { super(data); + this.goQuorumCompatibilityMode = goQuorumCompatibilityMode; } - public static ProposalMessageData fromMessageData(final MessageData messageData) { + public static ProposalMessageData fromMessageData( + final MessageData messageData, final boolean goQuorumCompatibilityMode) { return fromMessageData( - messageData, MESSAGE_CODE, ProposalMessageData.class, ProposalMessageData::new); + messageData, + MESSAGE_CODE, + ProposalMessageData.class, + data -> new ProposalMessageData(data, goQuorumCompatibilityMode)); } public Proposal decode() { - return Proposal.decode(data); + return Proposal.decode(data, goQuorumCompatibilityMode); } - public static ProposalMessageData create(final Proposal proposal) { - return new ProposalMessageData(proposal.encode()); + public static ProposalMessageData create( + final Proposal proposal, final boolean goQuorumCompatibilityMode) { + return new ProposalMessageData(proposal.encode(), goQuorumCompatibilityMode); } @Override diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/messagedata/RoundChangeMessageData.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/messagedata/RoundChangeMessageData.java index b9ae7fa2397..31a598e7c82 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/messagedata/RoundChangeMessageData.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/messagedata/RoundChangeMessageData.java @@ -24,22 +24,30 @@ public class RoundChangeMessageData extends AbstractBftMessageData { private static final int MESSAGE_CODE = IbftV2.ROUND_CHANGE; - private RoundChangeMessageData(final Bytes data) { + private final boolean goQuorumCompatibilityMode; + + private RoundChangeMessageData(final Bytes data, final boolean goQuorumCompatibilityMode) { super(data); + this.goQuorumCompatibilityMode = goQuorumCompatibilityMode; } - public static RoundChangeMessageData fromMessageData(final MessageData messageData) { + public static RoundChangeMessageData fromMessageData( + final MessageData messageData, final boolean goQuorumCompatibilityMode) { return fromMessageData( - messageData, MESSAGE_CODE, RoundChangeMessageData.class, RoundChangeMessageData::new); + messageData, + MESSAGE_CODE, + RoundChangeMessageData.class, + data -> new RoundChangeMessageData(data, goQuorumCompatibilityMode)); } public RoundChange decode() { - return RoundChange.decode(data); + return RoundChange.decode(data, goQuorumCompatibilityMode); } - public static RoundChangeMessageData create(final RoundChange signedPayload) { + public static RoundChangeMessageData create( + final RoundChange signedPayload, final boolean goQuorumCompatibilityMode) { - return new RoundChangeMessageData(signedPayload.encode()); + return new RoundChangeMessageData(signedPayload.encode(), goQuorumCompatibilityMode); } @Override diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/messagewrappers/Proposal.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/messagewrappers/Proposal.java index e3671732d12..a3fdc7c25ca 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/messagewrappers/Proposal.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/messagewrappers/Proposal.java @@ -35,7 +35,6 @@ public class Proposal extends BftMessage { private static final IbftExtraDataCodec BFT_EXTRA_DATA_ENCODER = new IbftExtraDataCodec(); private final Block proposedBlock; - private final Optional roundChangeCertificate; public Proposal( @@ -74,13 +73,16 @@ public Bytes encode() { return rlpOut.encoded(); } - public static Proposal decode(final Bytes data) { + public static Proposal decode(final Bytes data, final boolean goQuorumCompatibilityMode) { final RLPInput rlpIn = RLP.input(data); rlpIn.enterList(); final SignedData payload = PayloadDeserializers.readSignedProposalPayloadFrom(rlpIn); final Block proposedBlock = - Block.readFrom(rlpIn, BftBlockHeaderFunctions.forCommittedSeal(BFT_EXTRA_DATA_ENCODER)); + Block.readFrom( + rlpIn, + BftBlockHeaderFunctions.forCommittedSeal(BFT_EXTRA_DATA_ENCODER), + goQuorumCompatibilityMode); final Optional roundChangeCertificate = readRoundChangeCertificate(rlpIn); diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/messagewrappers/RoundChange.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/messagewrappers/RoundChange.java index c01b324ae84..2e375abdecc 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/messagewrappers/RoundChange.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/messagewrappers/RoundChange.java @@ -69,7 +69,7 @@ public Bytes encode() { return rlpOut.encoded(); } - public static RoundChange decode(final Bytes data) { + public static RoundChange decode(final Bytes data, final boolean goQuorumCompatibilityMode) { final RLPInput rlpIn = RLP.input(data); rlpIn.enterList(); @@ -80,7 +80,9 @@ public static RoundChange decode(final Bytes data) { block = Optional.of( Block.readFrom( - rlpIn, BftBlockHeaderFunctions.forCommittedSeal(BFT_EXTRA_DATA_ENCODER))); + rlpIn, + BftBlockHeaderFunctions.forCommittedSeal(BFT_EXTRA_DATA_ENCODER), + goQuorumCompatibilityMode)); } else { rlpIn.skipNext(); } diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/network/IbftMessageTransmitter.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/network/IbftMessageTransmitter.java index dd52e8b40a6..ddb7bb65f58 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/network/IbftMessageTransmitter.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/network/IbftMessageTransmitter.java @@ -30,6 +30,7 @@ import org.hyperledger.besu.crypto.SECPSignature; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.core.Block; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException; import java.util.Optional; @@ -43,9 +44,13 @@ public class IbftMessageTransmitter { private final MessageFactory messageFactory; private final ValidatorMulticaster multicaster; + private final boolean goQuorumCompatibilityMode; public IbftMessageTransmitter( - final MessageFactory messageFactory, final ValidatorMulticaster multicaster) { + final ProtocolSchedule protocolSchedule, + final MessageFactory messageFactory, + final ValidatorMulticaster multicaster) { + this.goQuorumCompatibilityMode = protocolSchedule.getGenesisConfigOptions().isQuorum(); this.messageFactory = messageFactory; this.multicaster = multicaster; } @@ -58,7 +63,8 @@ public void multicastProposal( final Proposal data = messageFactory.createProposal(roundIdentifier, block, roundChangeCertificate); - final ProposalMessageData message = ProposalMessageData.create(data); + final ProposalMessageData message = + ProposalMessageData.create(data, goQuorumCompatibilityMode); multicaster.send(message); } catch (final SecurityModuleException e) { @@ -100,7 +106,8 @@ public void multicastRoundChange( final RoundChange data = messageFactory.createRoundChange(roundIdentifier, preparedRoundArtifacts); - final RoundChangeMessageData message = RoundChangeMessageData.create(data); + final RoundChangeMessageData message = + RoundChangeMessageData.create(data, goQuorumCompatibilityMode); multicaster.send(message); } catch (final SecurityModuleException e) { diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManager.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManager.java index 4c2bf311033..226d201ad65 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManager.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManager.java @@ -33,6 +33,7 @@ import org.hyperledger.besu.consensus.ibft.validation.FutureRoundProposalMessageValidator; import org.hyperledger.besu.consensus.ibft.validation.MessageValidatorFactory; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException; import java.time.Clock; @@ -75,6 +76,7 @@ public class IbftBlockHeightManager implements BaseIbftBlockHeightManager { private IbftRound currentRound; public IbftBlockHeightManager( + final ProtocolSchedule protocolSchedule, final BlockHeader parentHeader, final BftFinalState finalState, final RoundChangeManager roundChangeManager, @@ -86,7 +88,8 @@ public IbftBlockHeightManager( this.roundFactory = ibftRoundFactory; this.blockTimer = finalState.getBlockTimer(); this.transmitter = - new IbftMessageTransmitter(messageFactory, finalState.getValidatorMulticaster()); + new IbftMessageTransmitter( + protocolSchedule, messageFactory, finalState.getValidatorMulticaster()); this.messageFactory = messageFactory; this.clock = clock; this.roundChangeManager = roundChangeManager; diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerFactory.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerFactory.java index 8ed1f48a7ab..45711944e7a 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerFactory.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerFactory.java @@ -19,6 +19,7 @@ import org.hyperledger.besu.consensus.ibft.payload.MessageFactory; import org.hyperledger.besu.consensus.ibft.validation.MessageValidatorFactory; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; public class IbftBlockHeightManagerFactory { @@ -26,12 +27,15 @@ public class IbftBlockHeightManagerFactory { private final BftFinalState finalState; private final MessageValidatorFactory messageValidatorFactory; private final MessageFactory messageFactory; + private final ProtocolSchedule protocolSchedule; public IbftBlockHeightManagerFactory( + final ProtocolSchedule protocolSchedule, final BftFinalState finalState, final IbftRoundFactory roundFactory, final MessageValidatorFactory messageValidatorFactory, final MessageFactory messageFactory) { + this.protocolSchedule = protocolSchedule; this.roundFactory = roundFactory; this.finalState = finalState; this.messageValidatorFactory = messageValidatorFactory; @@ -52,6 +56,7 @@ private BaseIbftBlockHeightManager createNoOpBlockHeightManager(final BlockHeade private BaseIbftBlockHeightManager createFullBlockHeightManager(final BlockHeader parentHeader) { return new IbftBlockHeightManager( + protocolSchedule, parentHeader, finalState, new RoundChangeManager( diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftController.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftController.java index 5485a1d8b50..c538fc86cf6 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftController.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftController.java @@ -28,6 +28,7 @@ import org.hyperledger.besu.consensus.ibft.messagedata.RoundChangeMessageData; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.Message; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; @@ -35,8 +36,10 @@ public class IbftController extends BaseBftController { private BaseIbftBlockHeightManager currentHeightManager; private final IbftBlockHeightManagerFactory ibftBlockHeightManagerFactory; + private final boolean goQuorumCompatibilityMode; public IbftController( + final ProtocolSchedule protocolSchedule, final Blockchain blockchain, final BftFinalState bftFinalState, final IbftBlockHeightManagerFactory ibftBlockHeightManagerFactory, @@ -52,6 +55,7 @@ public IbftController( duplicateMessageTracker, futureMessageBuffer, sychronizerUpdater); + this.goQuorumCompatibilityMode = protocolSchedule.getGenesisConfigOptions().isQuorum(); this.ibftBlockHeightManagerFactory = ibftBlockHeightManagerFactory; } @@ -63,7 +67,7 @@ protected void handleMessage(final Message message) { case IbftV2.PROPOSAL: consumeMessage( message, - ProposalMessageData.fromMessageData(messageData).decode(), + ProposalMessageData.fromMessageData(messageData, goQuorumCompatibilityMode).decode(), currentHeightManager::handleProposalPayload); break; @@ -84,7 +88,7 @@ protected void handleMessage(final Message message) { case IbftV2.ROUND_CHANGE: consumeMessage( message, - RoundChangeMessageData.fromMessageData(messageData).decode(), + RoundChangeMessageData.fromMessageData(messageData, goQuorumCompatibilityMode).decode(), currentHeightManager::handleRoundChangePayload); break; diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftRoundFactory.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftRoundFactory.java index 2206af0ee28..da5cf31a085 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftRoundFactory.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftRoundFactory.java @@ -78,7 +78,8 @@ public IbftRound createNewRoundWithState( blockCreatorFactory.create(parentHeader, roundIdentifier.getRoundNumber()); final IbftMessageTransmitter messageTransmitter = - new IbftMessageTransmitter(messageFactory, finalState.getValidatorMulticaster()); + new IbftMessageTransmitter( + protocolSchedule, messageFactory, finalState.getValidatorMulticaster()); return new IbftRound( roundState, diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftGossipTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftGossipTest.java index 2846d28691c..3d175174f51 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftGossipTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftGossipTest.java @@ -15,8 +15,10 @@ package org.hyperledger.besu.consensus.ibft; import static com.google.common.collect.Lists.newArrayList; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.verify; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.consensus.common.bft.messagewrappers.BftMessage; import org.hyperledger.besu.consensus.common.bft.network.MockPeerFactory; import org.hyperledger.besu.consensus.common.bft.network.ValidatorMulticaster; @@ -26,6 +28,7 @@ import org.hyperledger.besu.crypto.NodeKeyUtils; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.ethereum.core.AddressHelpers; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.DefaultMessage; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.Message; @@ -43,12 +46,16 @@ public class IbftGossipTest { private IbftGossip ibftGossip; @Mock private ValidatorMulticaster validatorMulticaster; + @Mock private ProtocolSchedule mockProtocolSchedule; private PeerConnection peerConnection; private static final Address senderAddress = AddressHelpers.ofValue(9); @Before public void setup() { - ibftGossip = new IbftGossip(validatorMulticaster); + lenient() + .when(mockProtocolSchedule.getGenesisConfigOptions()) + .thenReturn(new StubGenesisConfigOptions()); + ibftGossip = new IbftGossip(mockProtocolSchedule, validatorMulticaster); peerConnection = MockPeerFactory.create(senderAddress); } @@ -66,13 +73,17 @@ private

> void assertRebroadcastToAllExceptSignerAndSend @Test public void assertRebroadcastsProposalToAllExceptSignerAndSender() { + final boolean isGoQuorumCompatible = false; assertRebroadcastToAllExceptSignerAndSender( - TestHelpers::createSignedProposalPayload, ProposalMessageData::create); + TestHelpers::createSignedProposalPayload, + proposalMessage -> ProposalMessageData.create(proposalMessage, isGoQuorumCompatible)); } @Test public void assertRebroadcastsRoundChangeToAllExceptSignerAndSender() { + final boolean isGoQuorumCompatible = false; assertRebroadcastToAllExceptSignerAndSender( - TestHelpers::createSignedRoundChangePayload, RoundChangeMessageData::create); + TestHelpers::createSignedRoundChangePayload, + roundChange -> RoundChangeMessageData.create(roundChange, isGoQuorumCompatible)); } } diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/messagedata/ProposalMessageTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/messagedata/ProposalMessageTest.java index b8bb1f949c0..19df6a091ac 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/messagedata/ProposalMessageTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/messagedata/ProposalMessageTest.java @@ -34,11 +34,13 @@ public class ProposalMessageTest { @Mock private Bytes messageBytes; @Mock private MessageData messageData; @Mock private ProposalMessageData proposalMessage; + private final boolean isGoQuorumCompatible = false; @Test public void createMessageFromPrePrepareMessageData() { when(proposalMessageData.encode()).thenReturn(messageBytes); - final ProposalMessageData proposalMessage = ProposalMessageData.create(proposalMessageData); + final ProposalMessageData proposalMessage = + ProposalMessageData.create(proposalMessageData, isGoQuorumCompatible); assertThat(proposalMessage.getData()).isEqualTo(messageBytes); assertThat(proposalMessage.getCode()).isEqualTo(IbftV2.PROPOSAL); @@ -47,7 +49,8 @@ public void createMessageFromPrePrepareMessageData() { @Test public void createMessageFromPrePrepareMessage() { - final ProposalMessageData message = ProposalMessageData.fromMessageData(proposalMessage); + final ProposalMessageData message = + ProposalMessageData.fromMessageData(proposalMessage, isGoQuorumCompatible); assertThat(message).isSameAs(proposalMessage); } @@ -55,7 +58,8 @@ public void createMessageFromPrePrepareMessage() { public void createMessageFromGenericMessageData() { when(messageData.getCode()).thenReturn(IbftV2.PROPOSAL); when(messageData.getData()).thenReturn(messageBytes); - final ProposalMessageData proposalMessage = ProposalMessageData.fromMessageData(messageData); + final ProposalMessageData proposalMessage = + ProposalMessageData.fromMessageData(messageData, isGoQuorumCompatible); assertThat(proposalMessage.getData()).isEqualTo(messageData.getData()); assertThat(proposalMessage.getCode()).isEqualTo(IbftV2.PROPOSAL); @@ -64,7 +68,7 @@ public void createMessageFromGenericMessageData() { @Test public void createMessageFailsWhenIncorrectMessageCode() { when(messageData.getCode()).thenReturn(42); - assertThatThrownBy(() -> ProposalMessageData.fromMessageData(messageData)) + assertThatThrownBy(() -> ProposalMessageData.fromMessageData(messageData, isGoQuorumCompatible)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("MessageData has code 42 and thus is not a ProposalMessageData"); } diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/messagedata/RoundChangeMessageTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/messagedata/RoundChangeMessageTest.java index ed0b36f02e6..4a7277faac6 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/messagedata/RoundChangeMessageTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/messagedata/RoundChangeMessageTest.java @@ -34,11 +34,13 @@ public class RoundChangeMessageTest { @Mock private Bytes messageBytes; @Mock private MessageData messageData; @Mock private RoundChangeMessageData roundChangeMessage; + private final boolean isGoQuorumCompatible = false; @Test public void createMessageFromRoundChangeMessageData() { when(roundChangePayload.encode()).thenReturn(messageBytes); - RoundChangeMessageData roundChangeMessage = RoundChangeMessageData.create(roundChangePayload); + RoundChangeMessageData roundChangeMessage = + RoundChangeMessageData.create(roundChangePayload, isGoQuorumCompatible); assertThat(roundChangeMessage.getData()).isEqualTo(messageBytes); assertThat(roundChangeMessage.getCode()).isEqualTo(IbftV2.ROUND_CHANGE); @@ -47,7 +49,8 @@ public void createMessageFromRoundChangeMessageData() { @Test public void createMessageFromRoundChangeMessage() { - RoundChangeMessageData message = RoundChangeMessageData.fromMessageData(roundChangeMessage); + RoundChangeMessageData message = + RoundChangeMessageData.fromMessageData(roundChangeMessage, isGoQuorumCompatible); assertThat(message).isSameAs(roundChangeMessage); } @@ -55,7 +58,8 @@ public void createMessageFromRoundChangeMessage() { public void createMessageFromGenericMessageData() { when(messageData.getData()).thenReturn(messageBytes); when(messageData.getCode()).thenReturn(IbftV2.ROUND_CHANGE); - RoundChangeMessageData roundChangeMessage = RoundChangeMessageData.fromMessageData(messageData); + RoundChangeMessageData roundChangeMessage = + RoundChangeMessageData.fromMessageData(messageData, isGoQuorumCompatible); assertThat(roundChangeMessage.getData()).isEqualTo(messageData.getData()); assertThat(roundChangeMessage.getCode()).isEqualTo(IbftV2.ROUND_CHANGE); @@ -64,7 +68,8 @@ public void createMessageFromGenericMessageData() { @Test public void createMessageFailsWhenIncorrectMessageCode() { when(messageData.getCode()).thenReturn(42); - assertThatThrownBy(() -> RoundChangeMessageData.fromMessageData(messageData)) + assertThatThrownBy( + () -> RoundChangeMessageData.fromMessageData(messageData, isGoQuorumCompatible)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("MessageData has code 42 and thus is not a RoundChangeMessageData"); } 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 f0c0ca6b8c1..f22aa3d4be7 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 @@ -23,6 +23,7 @@ import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; @@ -30,6 +31,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.consensus.common.bft.BftExtraData; import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec; import org.hyperledger.besu.consensus.common.bft.BlockTimer; @@ -64,6 +66,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.BlockImporter; import org.hyperledger.besu.ethereum.core.Util; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; import org.hyperledger.besu.util.Subscribers; @@ -103,6 +106,7 @@ public class IbftBlockHeightManagerTest { @Mock private RoundTimer roundTimer; @Mock private FutureRoundProposalMessageValidator futureRoundProposalMessageValidator; @Mock private ValidatorMulticaster validatorMulticaster; + @Mock private ProtocolSchedule protocolSchedule; @Captor private ArgumentCaptor sentMessageArgCaptor; @@ -147,6 +151,9 @@ public void setup() { when(messageValidatorFactory.createFutureRoundProposalMessageValidator(anyLong(), any())) .thenReturn(futureRoundProposalMessageValidator); when(messageValidatorFactory.createMessageValidator(any(), any())).thenReturn(messageValidator); + lenient() + .when(protocolSchedule.getGenesisConfigOptions()) + .thenReturn(new StubGenesisConfigOptions()); protocolContext = new ProtocolContext(null, null, setupContextWithValidators(validators)); @@ -194,6 +201,7 @@ public void startsABlockTimerOnStartIfLocalNodeIsTheProoserForRound() { when(finalState.isLocalNodeProposerForRound(any())).thenReturn(true); new IbftBlockHeightManager( + protocolSchedule, headerTestFixture.buildHeader(), finalState, roundChangeManager, @@ -209,6 +217,7 @@ public void startsABlockTimerOnStartIfLocalNodeIsTheProoserForRound() { public void onBlockTimerExpiryProposalMessageIsTransmitted() { final IbftBlockHeightManager manager = new IbftBlockHeightManager( + protocolSchedule, headerTestFixture.buildHeader(), finalState, roundChangeManager, @@ -234,6 +243,7 @@ public void onRoundChangeReceptionRoundChangeManagerIsInvokedAndNewRoundStarted( final IbftBlockHeightManager manager = new IbftBlockHeightManager( + protocolSchedule, headerTestFixture.buildHeader(), finalState, roundChangeManager, @@ -254,6 +264,7 @@ public void onRoundChangeReceptionRoundChangeManagerIsInvokedAndNewRoundStarted( public void onRoundTimerExpiryANewRoundIsCreatedWithAnIncrementedRoundNumber() { final IbftBlockHeightManager manager = new IbftBlockHeightManager( + protocolSchedule, headerTestFixture.buildHeader(), finalState, roundChangeManager, @@ -281,6 +292,7 @@ public void whenSufficientRoundChangesAreReceivedAProposalMessageIsTransmitted() final IbftBlockHeightManager manager = new IbftBlockHeightManager( + protocolSchedule, headerTestFixture.buildHeader(), finalState, roundChangeManager, @@ -302,6 +314,7 @@ public void messagesForFutureRoundsAreBufferedAndUsedToPreloadNewRoundWhenItIsSt final IbftBlockHeightManager manager = new IbftBlockHeightManager( + protocolSchedule, headerTestFixture.buildHeader(), finalState, roundChangeManager, @@ -344,6 +357,7 @@ public void messagesForFutureRoundsAreBufferedAndUsedToPreloadNewRoundWhenItIsSt public void preparedCertificateIncludedInRoundChangeMessageOnRoundTimeoutExpired() { final IbftBlockHeightManager manager = new IbftBlockHeightManager( + protocolSchedule, headerTestFixture.buildHeader(), finalState, roundChangeManager, @@ -388,6 +402,7 @@ public void illegalFutureRoundProposalDoesNotTriggerNewRound() { final IbftBlockHeightManager manager = new IbftBlockHeightManager( + protocolSchedule, headerTestFixture.buildHeader(), finalState, roundChangeManager, diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftControllerTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftControllerTest.java index c35dcf3ea53..0e44a64f68a 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftControllerTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftControllerTest.java @@ -19,6 +19,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; @@ -26,6 +27,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier; import org.hyperledger.besu.consensus.common.bft.EthSynchronizerUpdater; import org.hyperledger.besu.consensus.common.bft.MessageTracker; @@ -49,6 +51,7 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.DefaultMessage; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.Message; @@ -95,6 +98,7 @@ public class IbftControllerTest { @Mock private IbftGossip ibftGossip; @Mock private FutureMessageBuffer futureMessageBuffer; private IbftController ibftController; + @Mock private ProtocolSchedule protocolSchedule; @Before public void setup() { @@ -113,11 +117,16 @@ public void setup() { when(bftFinalState.isLocalNodeValidator()).thenReturn(true); when(messageTracker.hasSeenMessage(any())).thenReturn(false); + + lenient() + .when(protocolSchedule.getGenesisConfigOptions()) + .thenReturn(new StubGenesisConfigOptions()); } private void constructIbftController() { ibftController = new IbftController( + protocolSchedule, blockChain, bftFinalState, blockHeightManagerFactory, diff --git a/consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/protocol/Istanbul99ProtocolManager.java b/consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/protocol/Istanbul99ProtocolManager.java index bf0a7a1799f..e4b6dec4296 100644 --- a/consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/protocol/Istanbul99ProtocolManager.java +++ b/consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/protocol/Istanbul99ProtocolManager.java @@ -16,6 +16,7 @@ import static java.util.Collections.singletonList; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthContext; @@ -40,6 +41,7 @@ public Istanbul99ProtocolManager( final WorldStateArchive worldStateArchive, final TransactionPool transactionPool, final EthProtocolConfiguration ethereumWireProtocolConfiguration, + final GenesisConfigOptions genesisConfigOptions, final EthPeers ethPeers, final EthMessages ethMessages, final EthContext ethContext, @@ -52,6 +54,7 @@ public Istanbul99ProtocolManager( worldStateArchive, transactionPool, ethereumWireProtocolConfiguration, + genesisConfigOptions, ethPeers, ethMessages, ethContext, diff --git a/consensus/ibftlegacy/src/test/java/org/hyperledger/besu/consensus/ibftlegacy/protocol/Istanbul99ProtocolManagerTest.java b/consensus/ibftlegacy/src/test/java/org/hyperledger/besu/consensus/ibftlegacy/protocol/Istanbul99ProtocolManagerTest.java index 515915c44f7..1382334fbae 100644 --- a/consensus/ibftlegacy/src/test/java/org/hyperledger/besu/consensus/ibftlegacy/protocol/Istanbul99ProtocolManagerTest.java +++ b/consensus/ibftlegacy/src/test/java/org/hyperledger/besu/consensus/ibftlegacy/protocol/Istanbul99ProtocolManagerTest.java @@ -117,6 +117,7 @@ public void respondToEth65GetHeadersUsingIstanbul99() protocolContext.getWorldStateArchive(), transactionPool, EthProtocolConfiguration.defaultConfig(), + protocolSchedule.getGenesisConfigOptions(), peers, messages, new EthContext(peers, messages, ethScheduler), diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/QbftGossip.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/QbftGossip.java index 333228fbc01..444da95087e 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/QbftGossip.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/QbftGossip.java @@ -24,6 +24,7 @@ import org.hyperledger.besu.consensus.qbft.messagedata.QbftV1; import org.hyperledger.besu.consensus.qbft.messagedata.RoundChangeMessageData; import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.Message; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; @@ -36,6 +37,7 @@ public class QbftGossip implements Gossiper { private final ValidatorMulticaster multicaster; private final BftExtraDataCodec bftExtraDataCodec; + private final boolean goQuorumCompatibilityMode; /** * Constructor that attaches gossip logic to a set of multicaster @@ -44,9 +46,12 @@ public class QbftGossip implements Gossiper { * @param bftExtraDataCodec Codec used when decoding MessageData */ public QbftGossip( - final ValidatorMulticaster multicaster, final BftExtraDataCodec bftExtraDataCodec) { + final ProtocolSchedule protocolSchedule, + final ValidatorMulticaster multicaster, + final BftExtraDataCodec bftExtraDataCodec) { this.multicaster = multicaster; this.bftExtraDataCodec = bftExtraDataCodec; + this.goQuorumCompatibilityMode = protocolSchedule.getGenesisConfigOptions().isQuorum(); } /** @@ -60,7 +65,9 @@ public void send(final Message message) { final Authored decodedMessage; switch (messageData.getCode()) { case QbftV1.PROPOSAL: - decodedMessage = ProposalMessageData.fromMessageData(messageData).decode(bftExtraDataCodec); + decodedMessage = + ProposalMessageData.fromMessageData(messageData, goQuorumCompatibilityMode) + .decode(bftExtraDataCodec); break; case QbftV1.PREPARE: decodedMessage = PrepareMessageData.fromMessageData(messageData).decode(); @@ -70,7 +77,8 @@ public void send(final Message message) { break; case QbftV1.ROUND_CHANGE: decodedMessage = - RoundChangeMessageData.fromMessageData(messageData).decode(bftExtraDataCodec); + RoundChangeMessageData.fromMessageData(messageData, goQuorumCompatibilityMode) + .decode(bftExtraDataCodec); break; default: throw new IllegalArgumentException( diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/messagedata/ProposalMessageData.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/messagedata/ProposalMessageData.java index 53a3d3110f8..2bc14dc537a 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/messagedata/ProposalMessageData.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/messagedata/ProposalMessageData.java @@ -24,22 +24,29 @@ public class ProposalMessageData extends AbstractBftMessageData { private static final int MESSAGE_CODE = QbftV1.PROPOSAL; + private final boolean goQuorumCompatibilityMode; - private ProposalMessageData(final Bytes data) { + private ProposalMessageData(final Bytes data, final boolean goQuorumCompatibilityMode) { super(data); + this.goQuorumCompatibilityMode = goQuorumCompatibilityMode; } - public static ProposalMessageData fromMessageData(final MessageData messageData) { + public static ProposalMessageData fromMessageData( + final MessageData messageData, final boolean goQuorumCompatibilityMode) { return fromMessageData( - messageData, MESSAGE_CODE, ProposalMessageData.class, ProposalMessageData::new); + messageData, + MESSAGE_CODE, + ProposalMessageData.class, + data -> new ProposalMessageData(data, goQuorumCompatibilityMode)); } public Proposal decode(final BftExtraDataCodec bftExtraDataCodec) { - return Proposal.decode(data, bftExtraDataCodec); + return Proposal.decode(data, bftExtraDataCodec, goQuorumCompatibilityMode); } - public static ProposalMessageData create(final Proposal proposal) { - return new ProposalMessageData(proposal.encode()); + public static ProposalMessageData create( + final Proposal proposal, final boolean goQuorumCompatibilityMode) { + return new ProposalMessageData(proposal.encode(), goQuorumCompatibilityMode); } @Override diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/messagedata/RoundChangeMessageData.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/messagedata/RoundChangeMessageData.java index 6e13dc8c251..198e3073618 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/messagedata/RoundChangeMessageData.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/messagedata/RoundChangeMessageData.java @@ -25,22 +25,30 @@ public class RoundChangeMessageData extends AbstractBftMessageData { private static final int MESSAGE_CODE = QbftV1.ROUND_CHANGE; - private RoundChangeMessageData(final Bytes data) { + private final boolean goQuorumCompatibilityMode; + + private RoundChangeMessageData(final Bytes data, final boolean goQuorumCompatibilityMode) { super(data); + this.goQuorumCompatibilityMode = goQuorumCompatibilityMode; } - public static RoundChangeMessageData fromMessageData(final MessageData messageData) { + public static RoundChangeMessageData fromMessageData( + final MessageData messageData, final boolean goQuorumCompatibilityMode) { return fromMessageData( - messageData, MESSAGE_CODE, RoundChangeMessageData.class, RoundChangeMessageData::new); + messageData, + MESSAGE_CODE, + RoundChangeMessageData.class, + data -> new RoundChangeMessageData(data, goQuorumCompatibilityMode)); } public RoundChange decode(final BftExtraDataCodec bftExtraDataCodec) { - return RoundChange.decode(data, bftExtraDataCodec); + return RoundChange.decode(data, bftExtraDataCodec, goQuorumCompatibilityMode); } - public static RoundChangeMessageData create(final RoundChange signedPayload) { + public static RoundChangeMessageData create( + final RoundChange signedPayload, final boolean goQuorumCompatibilityMode) { - return new RoundChangeMessageData(signedPayload.encode()); + return new RoundChangeMessageData(signedPayload.encode(), goQuorumCompatibilityMode); } @Override diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/messagewrappers/Proposal.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/messagewrappers/Proposal.java index b8a7ce1b8e8..9d251267d83 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/messagewrappers/Proposal.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/messagewrappers/Proposal.java @@ -70,11 +70,17 @@ public Bytes encode() { return rlpOut.encoded(); } - public static Proposal decode(final Bytes data, final BftExtraDataCodec bftExtraDataCodec) { + public static Proposal decode( + final Bytes data, + final BftExtraDataCodec bftExtraDataCodec, + final boolean goQuorumCompatibilityMode) { final RLPInput rlpIn = RLP.input(data); rlpIn.enterList(); final SignedData payload = - readPayload(rlpIn, rlpInput -> ProposalPayload.readFrom(rlpInput, bftExtraDataCodec)); + readPayload( + rlpIn, + rlpInput -> + ProposalPayload.readFrom(rlpInput, bftExtraDataCodec, goQuorumCompatibilityMode)); rlpIn.enterList(); final List> roundChanges = diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/messagewrappers/RoundChange.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/messagewrappers/RoundChange.java index a82ef1f2782..6568792b69b 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/messagewrappers/RoundChange.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/messagewrappers/RoundChange.java @@ -72,7 +72,10 @@ public Bytes encode() { return rlpOut.encoded(); } - public static RoundChange decode(final Bytes data, final BftExtraDataCodec bftExtraDataCodec) { + public static RoundChange decode( + final Bytes data, + final BftExtraDataCodec bftExtraDataCodec, + final boolean goQuorumCompatibilityMode) { final RLPInput rlpIn = RLP.input(data); rlpIn.enterList(); @@ -85,7 +88,10 @@ public static RoundChange decode(final Bytes data, final BftExtraDataCodec bftEx } else { block = Optional.of( - Block.readFrom(rlpIn, BftBlockHeaderFunctions.forCommittedSeal(bftExtraDataCodec))); + Block.readFrom( + rlpIn, + BftBlockHeaderFunctions.forCommittedSeal(bftExtraDataCodec), + goQuorumCompatibilityMode)); } final List> prepares = diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/network/QbftMessageTransmitter.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/network/QbftMessageTransmitter.java index 39c577c051f..11104e82bac 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/network/QbftMessageTransmitter.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/network/QbftMessageTransmitter.java @@ -32,6 +32,7 @@ import org.hyperledger.besu.crypto.SECPSignature; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.core.Block; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException; import java.util.List; @@ -46,11 +47,15 @@ public class QbftMessageTransmitter { private final MessageFactory messageFactory; private final ValidatorMulticaster multicaster; + private final boolean goQuorumCompatibilityMode; public QbftMessageTransmitter( - final MessageFactory messageFactory, final ValidatorMulticaster multicaster) { + final ProtocolSchedule protocolSchedule, + final MessageFactory messageFactory, + final ValidatorMulticaster multicaster) { this.messageFactory = messageFactory; this.multicaster = multicaster; + this.goQuorumCompatibilityMode = protocolSchedule.getGenesisConfigOptions().isQuorum(); } public void multicastProposal( @@ -62,7 +67,8 @@ public void multicastProposal( final Proposal data = messageFactory.createProposal(roundIdentifier, block, roundChanges, prepares); - final ProposalMessageData message = ProposalMessageData.create(data); + final ProposalMessageData message = + ProposalMessageData.create(data, goQuorumCompatibilityMode); multicaster.send(message); } catch (final SecurityModuleException e) { @@ -104,7 +110,8 @@ public void multicastRoundChange( final RoundChange data = messageFactory.createRoundChange(roundIdentifier, preparedRoundCertificate); - final RoundChangeMessageData message = RoundChangeMessageData.create(data); + final RoundChangeMessageData message = + RoundChangeMessageData.create(data, goQuorumCompatibilityMode); multicaster.send(message); } catch (final SecurityModuleException e) { diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/payload/ProposalPayload.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/payload/ProposalPayload.java index 8bb29666a66..0b20424d2bf 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/payload/ProposalPayload.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/payload/ProposalPayload.java @@ -39,11 +39,16 @@ public ProposalPayload( } public static ProposalPayload readFrom( - final RLPInput rlpInput, final BftExtraDataCodec bftExtraDataCodec) { + final RLPInput rlpInput, + final BftExtraDataCodec bftExtraDataCodec, + final boolean goQuorumCompatibilityMode) { rlpInput.enterList(); final ConsensusRoundIdentifier roundIdentifier = readConsensusRound(rlpInput); final Block proposedBlock = - Block.readFrom(rlpInput, BftBlockHeaderFunctions.forCommittedSeal(bftExtraDataCodec)); + Block.readFrom( + rlpInput, + BftBlockHeaderFunctions.forCommittedSeal(bftExtraDataCodec), + goQuorumCompatibilityMode); rlpInput.leaveList(); return new ProposalPayload(roundIdentifier, proposedBlock); diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManager.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManager.java index dc97f97b7d3..de74146a86a 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManager.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManager.java @@ -28,6 +28,7 @@ import org.hyperledger.besu.consensus.qbft.validation.FutureRoundProposalMessageValidator; import org.hyperledger.besu.consensus.qbft.validation.MessageValidatorFactory; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException; import java.time.Clock; @@ -68,6 +69,7 @@ public class QbftBlockHeightManager implements BaseQbftBlockHeightManager { private Optional currentRound = Optional.empty(); public QbftBlockHeightManager( + final ProtocolSchedule protocolSchedule, final BlockHeader parentHeader, final BftFinalState finalState, final RoundChangeManager roundChangeManager, @@ -78,7 +80,8 @@ public QbftBlockHeightManager( this.parentHeader = parentHeader; this.roundFactory = qbftRoundFactory; this.transmitter = - new QbftMessageTransmitter(messageFactory, finalState.getValidatorMulticaster()); + new QbftMessageTransmitter( + protocolSchedule, messageFactory, finalState.getValidatorMulticaster()); this.messageFactory = messageFactory; this.clock = clock; this.roundChangeManager = roundChangeManager; diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerFactory.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerFactory.java index eb17d8362e8..ac260fa05d8 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerFactory.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerFactory.java @@ -19,19 +19,23 @@ import org.hyperledger.besu.consensus.qbft.payload.MessageFactory; import org.hyperledger.besu.consensus.qbft.validation.MessageValidatorFactory; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; public class QbftBlockHeightManagerFactory { + private final ProtocolSchedule protocolSchedule; private final QbftRoundFactory roundFactory; private final BftFinalState finalState; private final MessageValidatorFactory messageValidatorFactory; private final MessageFactory messageFactory; public QbftBlockHeightManagerFactory( + final ProtocolSchedule protocolSchedule, final BftFinalState finalState, final QbftRoundFactory roundFactory, final MessageValidatorFactory messageValidatorFactory, final MessageFactory messageFactory) { + this.protocolSchedule = protocolSchedule; this.roundFactory = roundFactory; this.finalState = finalState; this.messageValidatorFactory = messageValidatorFactory; @@ -52,6 +56,7 @@ private BaseQbftBlockHeightManager createNoOpBlockHeightManager(final BlockHeade private BaseQbftBlockHeightManager createFullBlockHeightManager(final BlockHeader parentHeader) { return new QbftBlockHeightManager( + protocolSchedule, parentHeader, finalState, new RoundChangeManager( diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftController.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftController.java index 4eef9485af8..e9754c2baa8 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftController.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftController.java @@ -29,6 +29,7 @@ import org.hyperledger.besu.consensus.qbft.messagedata.RoundChangeMessageData; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.Message; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; @@ -37,8 +38,10 @@ public class QbftController extends BaseBftController { private BaseQbftBlockHeightManager currentHeightManager; private final QbftBlockHeightManagerFactory qbftBlockHeightManagerFactory; private final BftExtraDataCodec bftExtraDataCodec; + private final boolean goQuorumCompatibilityMode; public QbftController( + final ProtocolSchedule protocolSchedule, final Blockchain blockchain, final BftFinalState bftFinalState, final QbftBlockHeightManagerFactory qbftBlockHeightManagerFactory, @@ -57,6 +60,7 @@ public QbftController( sychronizerUpdater); this.qbftBlockHeightManagerFactory = qbftBlockHeightManagerFactory; this.bftExtraDataCodec = bftExtraDataCodec; + this.goQuorumCompatibilityMode = protocolSchedule.getGenesisConfigOptions().isQuorum(); } @Override @@ -67,7 +71,8 @@ protected void handleMessage(final Message message) { case QbftV1.PROPOSAL: consumeMessage( message, - ProposalMessageData.fromMessageData(messageData).decode(bftExtraDataCodec), + ProposalMessageData.fromMessageData(messageData, goQuorumCompatibilityMode) + .decode(bftExtraDataCodec), currentHeightManager::handleProposalPayload); break; @@ -88,7 +93,8 @@ protected void handleMessage(final Message message) { case QbftV1.ROUND_CHANGE: consumeMessage( message, - RoundChangeMessageData.fromMessageData(messageData).decode(bftExtraDataCodec), + RoundChangeMessageData.fromMessageData(messageData, goQuorumCompatibilityMode) + .decode(bftExtraDataCodec), currentHeightManager::handleRoundChangePayload); break; diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftRoundFactory.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftRoundFactory.java index 9557fc623ce..30bb6fe002f 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftRoundFactory.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftRoundFactory.java @@ -78,7 +78,8 @@ public QbftRound createNewRoundWithState( // TODO(tmm): Why is this created everytime?! final QbftMessageTransmitter messageTransmitter = - new QbftMessageTransmitter(messageFactory, finalState.getValidatorMulticaster()); + new QbftMessageTransmitter( + protocolSchedule, messageFactory, finalState.getValidatorMulticaster()); return new QbftRound( roundState, diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/ProposalTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/ProposalTest.java index 14dde662d57..67e739df6f7 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/ProposalTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/ProposalTest.java @@ -78,7 +78,9 @@ public void canRoundTripProposalMessage() { final Proposal proposal = new Proposal(signedPayload, List.of(roundChange), List.of(prepare)); - final Proposal decodedProposal = Proposal.decode(proposal.encode(), bftExtraDataCodec); + final boolean isGoQuorumCompatible = false; + final Proposal decodedProposal = + Proposal.decode(proposal.encode(), bftExtraDataCodec, isGoQuorumCompatible); assertThat(decodedProposal.getAuthor()).isEqualTo(addr); assertThat(decodedProposal.getMessageType()).isEqualTo(QbftV1.PROPOSAL); diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/RoundChangeTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/RoundChangeTest.java index 34c430801a4..6baba4db144 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/RoundChangeTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/RoundChangeTest.java @@ -52,6 +52,7 @@ public class RoundChangeTest { .extraData(new QbftExtraDataCodec().encode(extraData)) .buildHeader(), new BlockBody(Collections.emptyList(), Collections.emptyList())); + private final boolean isGoQuorumCompatible = false; @Test public void canRoundTripARoundChangeMessage() { @@ -76,7 +77,7 @@ public void canRoundTripARoundChangeMessage() { signedRoundChangePayload, Optional.of(BLOCK), List.of(signedPreparePayload)); final RoundChange decodedRoundChange = - RoundChange.decode(roundChange.encode(), bftExtraDataCodec); + RoundChange.decode(roundChange.encode(), bftExtraDataCodec, isGoQuorumCompatible); assertThat(decodedRoundChange.getMessageType()).isEqualTo(QbftV1.ROUND_CHANGE); assertThat(decodedRoundChange.getAuthor()).isEqualTo(addr); @@ -104,7 +105,7 @@ public void canRoundTripEmptyPreparedRoundAndPreparedList() { new RoundChange(signedRoundChangePayload, Optional.empty(), Collections.emptyList()); final RoundChange decodedRoundChange = - RoundChange.decode(roundChange.encode(), bftExtraDataCodec); + RoundChange.decode(roundChange.encode(), bftExtraDataCodec, isGoQuorumCompatible); assertThat(decodedRoundChange.getMessageType()).isEqualTo(QbftV1.ROUND_CHANGE); assertThat(decodedRoundChange.getAuthor()).isEqualTo(addr); 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 b9071d1bd05..bf0ed8d0ea8 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 @@ -24,6 +24,7 @@ import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; @@ -31,6 +32,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.consensus.common.bft.BftExtraData; import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec; import org.hyperledger.besu.consensus.common.bft.BlockTimer; @@ -64,6 +66,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.BlockImporter; import org.hyperledger.besu.ethereum.core.Util; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; import org.hyperledger.besu.util.Subscribers; @@ -103,6 +106,7 @@ public class QbftBlockHeightManagerTest { @Mock private RoundTimer roundTimer; @Mock private FutureRoundProposalMessageValidator futureRoundProposalMessageValidator; @Mock private ValidatorMulticaster validatorMulticaster; + @Mock private ProtocolSchedule protocolSchedule; @Captor private ArgumentCaptor sentMessageArgCaptor; @@ -146,6 +150,9 @@ public void setup() { when(messageValidatorFactory.createFutureRoundProposalMessageValidator(anyLong(), any())) .thenReturn(futureRoundProposalMessageValidator); when(messageValidatorFactory.createMessageValidator(any(), any())).thenReturn(messageValidator); + lenient() + .when(protocolSchedule.getGenesisConfigOptions()) + .thenReturn(new StubGenesisConfigOptions()); protocolContext = new ProtocolContext( @@ -196,6 +203,7 @@ public void setup() { @Test public void startsABlockTimerOnStart() { new QbftBlockHeightManager( + protocolSchedule, headerTestFixture.buildHeader(), finalState, roundChangeManager, @@ -211,6 +219,7 @@ public void startsABlockTimerOnStart() { @Test public void doesNotStartRoundTimerOnStart() { new QbftBlockHeightManager( + protocolSchedule, headerTestFixture.buildHeader(), finalState, roundChangeManager, @@ -229,6 +238,7 @@ public void onBlockTimerExpiryRoundTimerIsStartedAndProposalMessageIsTransmitted final QbftBlockHeightManager manager = new QbftBlockHeightManager( + protocolSchedule, headerTestFixture.buildHeader(), finalState, roundChangeManager, @@ -252,6 +262,7 @@ public void onBlockTimerExpiryRoundTimerIsStartedAndProposalMessageIsTransmitted final QbftBlockHeightManager manager = new QbftBlockHeightManager( + protocolSchedule, headerTestFixture.buildHeader(), finalState, roundChangeManager, @@ -271,6 +282,7 @@ public void onBlockTimerExpiryRoundTimerIsStartedAndProposalMessageIsTransmitted public void onBlockTimerExpiryDoNothingIfExistingRoundAlreadyStarted() { final QbftBlockHeightManager manager = new QbftBlockHeightManager( + protocolSchedule, headerTestFixture.buildHeader(), finalState, roundChangeManager, @@ -307,6 +319,7 @@ public void onRoundChangeReceptionRoundChangeManagerIsInvokedAndNewRoundStarted( final QbftBlockHeightManager manager = new QbftBlockHeightManager( + protocolSchedule, headerTestFixture.buildHeader(), finalState, roundChangeManager, @@ -328,6 +341,7 @@ public void onRoundChangeReceptionRoundChangeManagerIsInvokedAndNewRoundStarted( public void onRoundTimerExpiryANewRoundIsCreatedWithAnIncrementedRoundNumber() { final QbftBlockHeightManager manager = new QbftBlockHeightManager( + protocolSchedule, headerTestFixture.buildHeader(), finalState, roundChangeManager, @@ -356,6 +370,7 @@ public void whenSufficientRoundChangesAreReceivedAProposalMessageIsTransmitted() final QbftBlockHeightManager manager = new QbftBlockHeightManager( + protocolSchedule, headerTestFixture.buildHeader(), finalState, roundChangeManager, @@ -383,6 +398,7 @@ public void messagesForFutureRoundsAreBufferedAndUsedToPreloadNewRoundWhenItIsSt final QbftBlockHeightManager manager = new QbftBlockHeightManager( + protocolSchedule, headerTestFixture.buildHeader(), finalState, roundChangeManager, @@ -425,6 +441,7 @@ public void messagesForCurrentRoundAreBufferedAndUsedToPreloadRoundWhenItIsStart final QbftBlockHeightManager manager = new QbftBlockHeightManager( + protocolSchedule, headerTestFixture.buildHeader(), finalState, roundChangeManager, @@ -462,6 +479,7 @@ public void preparedCertificateIncludedInRoundChangeMessageOnRoundTimeoutExpired final QbftBlockHeightManager manager = new QbftBlockHeightManager( + protocolSchedule, headerTestFixture.buildHeader(), finalState, roundChangeManager, @@ -519,6 +537,7 @@ public void illegalFutureRoundProposalDoesNotTriggerNewRound() { final QbftBlockHeightManager manager = new QbftBlockHeightManager( + protocolSchedule, headerTestFixture.buildHeader(), finalState, roundChangeManager, diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftControllerTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftControllerTest.java index 2642b6f2289..616c832a42d 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftControllerTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftControllerTest.java @@ -19,6 +19,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; @@ -26,6 +27,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec; import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier; import org.hyperledger.besu.consensus.common.bft.EthSynchronizerUpdater; @@ -51,6 +53,7 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.DefaultMessage; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.Message; @@ -98,6 +101,7 @@ public class QbftControllerTest { private final ConsensusRoundIdentifier pastRoundIdentifier = new ConsensusRoundIdentifier(3, 0); @Mock private QbftGossip ibftGossip; @Mock private FutureMessageBuffer futureMessageBuffer; + @Mock private ProtocolSchedule protocolSchedule; private QbftController qbftController; @Before @@ -117,11 +121,16 @@ public void setup() { when(bftFinalState.isLocalNodeValidator()).thenReturn(true); when(messageTracker.hasSeenMessage(any())).thenReturn(false); + + lenient() + .when(protocolSchedule.getGenesisConfigOptions()) + .thenReturn(new StubGenesisConfigOptions()); } private void constructIbftController() { qbftController = new QbftController( + protocolSchedule, blockChain, bftFinalState, blockHeightManagerFactory, diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/ForkingValidatorProviderTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/ForkingValidatorProviderTest.java index 2ea4427d8c2..ac977460c4c 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/ForkingValidatorProviderTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/ForkingValidatorProviderTest.java @@ -21,6 +21,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.consensus.common.validator.VoteProvider; import org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider; import org.hyperledger.besu.datatypes.Address; @@ -75,7 +76,7 @@ public void setup() { header1 = block_1.getHeader(); header2 = block_2.getHeader(); - blockChain = createInMemoryBlockchain(genesisBlock); + blockChain = createInMemoryBlockchain(new StubGenesisConfigOptions(), genesisBlock); blockChain.appendBlock(block_1, emptyList()); blockChain.appendBlock(block_2, emptyList()); diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/TransactionValidatorProviderTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/TransactionValidatorProviderTest.java index cddaeeafab5..ad7126f4c4d 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/TransactionValidatorProviderTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/TransactionValidatorProviderTest.java @@ -22,6 +22,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; @@ -54,7 +55,7 @@ public class TransactionValidatorProviderTest { @Before public void setup() { genesisBlock = createEmptyBlock(0, Hash.ZERO); - blockChain = createInMemoryBlockchain(genesisBlock); + blockChain = createInMemoryBlockchain(new StubGenesisConfigOptions(), genesisBlock); headerBuilder.extraData(Bytes.wrap(new byte[32])); block_1 = createEmptyBlock(1, genesisBlock.getHeader().getHash()); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLDataFetchers.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLDataFetchers.java index 60c2f02adb9..20233e34b7e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLDataFetchers.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLDataFetchers.java @@ -16,7 +16,7 @@ import static com.google.common.base.Preconditions.checkArgument; -import org.hyperledger.besu.config.GoQuorumOptions; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; @@ -69,21 +69,26 @@ public class GraphQLDataFetchers { private static final Logger LOG = LogManager.getLogger(); private Optional goQuorumPrivacyParameters = Optional.empty(); + private final GenesisConfigOptions genesisConfigOptions; public GraphQLDataFetchers( final Set supportedCapabilities, + final GenesisConfigOptions genesisConfigOptions, final Optional goQuorumPrivacyParameters) { - this(supportedCapabilities); + this(supportedCapabilities, genesisConfigOptions); this.goQuorumPrivacyParameters = goQuorumPrivacyParameters; } - public GraphQLDataFetchers(final Set supportedCapabilities) { + public GraphQLDataFetchers( + final Set supportedCapabilities, + final GenesisConfigOptions genesisConfigOptions) { final OptionalInt version = supportedCapabilities.stream() .filter(cap -> EthProtocol.NAME.equals(cap.getName())) .mapToInt(Capability::getVersion) .max(); highestEthVersion = version.isPresent() ? version.getAsInt() : null; + this.genesisConfigOptions = genesisConfigOptions; } private final Integer highestEthVersion; @@ -99,7 +104,8 @@ DataFetcher> getSendRawTransactionDataFetcher() { ((GraphQLDataFetcherContext) dataFetchingEnvironment.getContext()).getTransactionPool(); final Bytes rawTran = dataFetchingEnvironment.getArgument("data"); - final Transaction transaction = Transaction.readFrom(RLP.input(rawTran)); + final Transaction transaction = + Transaction.readFrom(RLP.input(rawTran), genesisConfigOptions.isQuorum()); final ValidationResult validationResult = transactionPool.addLocalTransaction(transaction); if (validationResult.isValid()) { @@ -126,7 +132,8 @@ DataFetcher> getPendingStateDataFetcher() { return dataFetchingEnvironment -> { final TransactionPool txPool = ((GraphQLDataFetcherContext) dataFetchingEnvironment.getContext()).getTransactionPool(); - return Optional.of(new PendingStateAdapter(txPool.getPendingTransactions())); + return Optional.of( + new PendingStateAdapter(txPool.getPendingTransactions(), genesisConfigOptions)); }; } @@ -163,7 +170,7 @@ DataFetcher> getRangeBlockDataFetcher() { for (long i = from; i <= to; i++) { final Optional> block = blockchainQuery.blockByNumber(i); - block.ifPresent(e -> results.add(new NormalBlockAdapter(e))); + block.ifPresent(e -> results.add(new NormalBlockAdapter(e, genesisConfigOptions))); } return results; }; @@ -190,7 +197,7 @@ public DataFetcher> getBlockDataFetcher() { } else { block = blockchain.latestBlock(); } - return block.map(NormalBlockAdapter::new); + return block.map(aBlock -> new NormalBlockAdapter(aBlock, genesisConfigOptions)); }; } @@ -264,7 +271,7 @@ DataFetcher>> getLogsDataFetcher() { fromBlock, toBlock, query, dataFetcherContext.getIsAliveHandler()); final List results = new ArrayList<>(); for (final LogWithMetadata log : logs) { - results.add(new LogAdapter(log)); + results.add(new LogAdapter(log, genesisConfigOptions)); } return Optional.of(results); }; @@ -284,10 +291,10 @@ private TransactionAdapter getTransactionAdapter( final TransactionWithMetadata transactionWithMetadata) { final Transaction transaction = transactionWithMetadata.getTransaction(); final boolean isGoQuorumPrivateTransaction = - transaction.isGoQuorumPrivateTransaction(GoQuorumOptions.goQuorumCompatibilityMode); + transaction.isGoQuorumPrivateTransaction(genesisConfigOptions.isQuorum()); return isGoQuorumPrivateTransaction && goQuorumPrivacyParameters.isPresent() ? updatePrivatePayload(transaction) - : new TransactionAdapter(transactionWithMetadata); + : new TransactionAdapter(transactionWithMetadata, genesisConfigOptions); } private TransactionAdapter updatePrivatePayload(final Transaction transaction) { @@ -304,7 +311,7 @@ private TransactionAdapter updatePrivatePayload(final Transaction transaction) { } // Return a new transaction containing the retrieved payload - return new TransactionAdapter( + TransactionWithMetadata extendedTransaction = new TransactionWithMetadata( new Transaction( transaction.getNonce(), @@ -318,6 +325,8 @@ private TransactionAdapter updatePrivatePayload(final Transaction transaction) { enclavePayload, transaction.getSender(), transaction.getChainId(), - Optional.ofNullable(transaction.getV())))); + Optional.ofNullable(transaction.getV()))); + + return new TransactionAdapter(extendedTransaction, genesisConfigOptions); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/BlockAdapterBase.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/BlockAdapterBase.java index c20a3f574c1..d548ba87a8f 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/BlockAdapterBase.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/BlockAdapterBase.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; @@ -50,17 +51,19 @@ public class BlockAdapterBase extends AdapterBase { private final BlockHeader header; + protected final GenesisConfigOptions genesisConfigOptions; - BlockAdapterBase(final BlockHeader header) { + BlockAdapterBase(final BlockHeader header, final GenesisConfigOptions genesisConfigOptions) { this.header = header; + this.genesisConfigOptions = genesisConfigOptions; } public Optional getParent(final DataFetchingEnvironment environment) { final BlockchainQueries query = getBlockchainQueries(environment); final Hash parentHash = header.getParentHash(); - final Optional> block = + final Optional> maybeBlock = query.blockByHash(parentHash); - return block.map(NormalBlockAdapter::new); + return maybeBlock.map(block -> new NormalBlockAdapter(block, genesisConfigOptions)); } public Optional getHash() { @@ -171,7 +174,7 @@ public List getLogs(final DataFetchingEnvironment environment) { final List logs = blockchain.matchingLogs(hash, query, () -> true); final List results = new ArrayList<>(); for (final LogWithMetadata log : logs) { - results.add(new LogAdapter(log)); + results.add(new LogAdapter(log, genesisConfigOptions)); } return results; } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/LogAdapter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/LogAdapter.java index a638044ea49..51bbfe9a13c 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/LogAdapter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/LogAdapter.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata; @@ -30,9 +31,12 @@ @SuppressWarnings("unused") // reflected by GraphQL public class LogAdapter extends AdapterBase { private final LogWithMetadata logWithMetadata; + private final GenesisConfigOptions genesisConfigOptions; - public LogAdapter(final LogWithMetadata logWithMetadata) { + public LogAdapter( + final LogWithMetadata logWithMetadata, final GenesisConfigOptions genesisConfigOptions) { this.logWithMetadata = logWithMetadata; + this.genesisConfigOptions = genesisConfigOptions; } public Optional getIndex() { @@ -52,7 +56,7 @@ public Optional getTransaction(final DataFetchingEnvironment final BlockchainQueries query = getBlockchainQueries(environment); final Hash hash = logWithMetadata.getTransactionHash(); final Optional tran = query.transactionByHash(hash); - return tran.map(TransactionAdapter::new); + return tran.map(transaction -> new TransactionAdapter(transaction, genesisConfigOptions)); } public Optional getAccount(final DataFetchingEnvironment environment) { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/NormalBlockAdapter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/NormalBlockAdapter.java index 0245b404cc4..91af1b0c4e0 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/NormalBlockAdapter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/NormalBlockAdapter.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.api.query.BlockWithMetadata; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -29,15 +30,15 @@ @SuppressWarnings("unused") // reflected by GraphQL public class NormalBlockAdapter extends BlockAdapterBase { + private final BlockWithMetadata blockWithMetaData; public NormalBlockAdapter( - final BlockWithMetadata blockWithMetaData) { - super(blockWithMetaData.getHeader()); + final BlockWithMetadata blockWithMetaData, + final GenesisConfigOptions genesisConfigOptions) { + super(blockWithMetaData.getHeader(), genesisConfigOptions); this.blockWithMetaData = blockWithMetaData; } - private final BlockWithMetadata blockWithMetaData; - public Optional getTransactionCount() { return Optional.of(blockWithMetaData.getTransactions().size()); } @@ -57,7 +58,7 @@ public List getOmmers(final DataFetchingEnvironment environme final Hash hash = blockWithMetaData.getHeader().getHash(); for (int i = 0; i < ommers.size(); i++) { final Optional header = query.getOmmer(hash, i); - header.ifPresent(item -> results.add(new UncleBlockAdapter(item))); + header.ifPresent(item -> results.add(new UncleBlockAdapter(item, genesisConfigOptions))); } return results; @@ -70,7 +71,7 @@ public Optional getOmmerAt(final DataFetchingEnvironment envi if (ommers.size() > index) { final Hash hash = blockWithMetaData.getHeader().getHash(); final Optional header = query.getOmmer(hash, index); - return header.map(UncleBlockAdapter::new); + return header.map(aHeader -> new UncleBlockAdapter(aHeader, genesisConfigOptions)); } return Optional.empty(); } @@ -79,7 +80,7 @@ public List getTransactions() { final List trans = blockWithMetaData.getTransactions(); final List results = new ArrayList<>(); for (final TransactionWithMetadata tran : trans) { - results.add(new TransactionAdapter(tran)); + results.add(new TransactionAdapter(tran, genesisConfigOptions)); } return results; } @@ -89,7 +90,7 @@ public Optional getTransactionAt(final DataFetchingEnvironme final List trans = blockWithMetaData.getTransactions(); if (trans.size() > index) { - return Optional.of(new TransactionAdapter(trans.get(index))); + return Optional.of(new TransactionAdapter(trans.get(index), genesisConfigOptions)); } return Optional.empty(); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/PendingStateAdapter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/PendingStateAdapter.java index 198453b2d73..2552182e629 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/PendingStateAdapter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/PendingStateAdapter.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.api.graphql.GraphQLDataFetcherContext; @@ -39,9 +40,13 @@ public class PendingStateAdapter extends AdapterBase { private final AbstractPendingTransactionsSorter pendingTransactions; + private final GenesisConfigOptions genesisConfigOptions; - public PendingStateAdapter(final AbstractPendingTransactionsSorter pendingTransactions) { + public PendingStateAdapter( + final AbstractPendingTransactionsSorter pendingTransactions, + final GenesisConfigOptions genesisConfigOptions) { this.pendingTransactions = pendingTransactions; + this.genesisConfigOptions = genesisConfigOptions; } public Integer getTransactionCount() { @@ -52,7 +57,7 @@ public List getTransactions() { return pendingTransactions.getTransactionInfo().stream() .map(AbstractPendingTransactionsSorter.TransactionInfo::getTransaction) .map(TransactionWithMetadata::new) - .map(TransactionAdapter::new) + .map(transaction -> new TransactionAdapter(transaction, genesisConfigOptions)) .collect(Collectors.toList()); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/TransactionAdapter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/TransactionAdapter.java index 2c3b684ca81..f68971208ae 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/TransactionAdapter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/TransactionAdapter.java @@ -14,7 +14,7 @@ */ package org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter; -import org.hyperledger.besu.config.GoQuorumOptions; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; @@ -36,9 +36,16 @@ @SuppressWarnings("unused") // reflected by GraphQL public class TransactionAdapter extends AdapterBase { private final TransactionWithMetadata transactionWithMetadata; + private final GenesisConfigOptions genesisConfigOptions; - public TransactionAdapter(final TransactionWithMetadata transactionWithMetadata) { + private final boolean isGoQuorumCompatibilityMode; + + public TransactionAdapter( + final TransactionWithMetadata transactionWithMetadata, + final GenesisConfigOptions genesisConfigOptions) { this.transactionWithMetadata = transactionWithMetadata; + this.genesisConfigOptions = genesisConfigOptions; + this.isGoQuorumCompatibilityMode = genesisConfigOptions.isQuorum(); } public Optional getHash() { @@ -107,7 +114,7 @@ public Optional getBlock(final DataFetchingEnvironment envir return transactionWithMetadata .getBlockHash() .flatMap(blockHash -> getBlockchainQueries(environment).blockByHash(blockHash)) - .map(NormalBlockAdapter::new); + .map(block -> new NormalBlockAdapter(block, genesisConfigOptions)); } public Optional getStatus(final DataFetchingEnvironment environment) { @@ -181,7 +188,7 @@ public List getLogs(final DataFetchingEnvironment environment) { transactionWithMetadata.getTransactionIndex().get(), false); for (final LogWithMetadata log : logs) { - results.add(new LogAdapter(log)); + results.add(new LogAdapter(log, genesisConfigOptions)); } } return results; @@ -190,12 +197,12 @@ public List getLogs(final DataFetchingEnvironment environment) { public boolean getIsPrivate() { return transactionWithMetadata .getTransaction() - .isGoQuorumPrivateTransaction(GoQuorumOptions.goQuorumCompatibilityMode); + .isGoQuorumPrivateTransaction(isGoQuorumCompatibilityMode); } public Optional getPrivateInputData() { final Transaction transaction = transactionWithMetadata.getTransaction(); - if (transaction.isGoQuorumPrivateTransaction(GoQuorumOptions.goQuorumCompatibilityMode)) { + if (transaction.isGoQuorumPrivateTransaction(isGoQuorumCompatibilityMode)) { return Optional.ofNullable(transaction.getPayload()); } return Optional.of(Bytes.EMPTY); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/UncleBlockAdapter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/UncleBlockAdapter.java index c0e2736820e..6369cc4bb02 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/UncleBlockAdapter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/UncleBlockAdapter.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.ethereum.core.BlockHeader; import java.util.ArrayList; @@ -25,8 +26,9 @@ @SuppressWarnings("unused") // reflected by GraphQL class UncleBlockAdapter extends BlockAdapterBase { - UncleBlockAdapter(final BlockHeader uncleHeader) { - super(uncleHeader); + UncleBlockAdapter( + final BlockHeader uncleHeader, final GenesisConfigOptions genesisConfigOptions) { + super(uncleHeader, genesisConfigOptions); } public Optional getTransactionCount() { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugBatchSendRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugBatchSendRawTransaction.java index 34b1f06f47e..1172fc7e3d0 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugBatchSendRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugBatchSendRawTransaction.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -37,13 +38,18 @@ public class DebugBatchSendRawTransaction implements JsonRpcMethod { private final Supplier transactionPool; + private final GenesisConfigOptions genesisConfigOptions; - public DebugBatchSendRawTransaction(final TransactionPool transactionPool) { - this(Suppliers.ofInstance(transactionPool)); + public DebugBatchSendRawTransaction( + final TransactionPool transactionPool, final GenesisConfigOptions genesisConfigOptions) { + this(Suppliers.ofInstance(transactionPool), genesisConfigOptions); } - public DebugBatchSendRawTransaction(final Supplier transactionPool) { + public DebugBatchSendRawTransaction( + final Supplier transactionPool, + final GenesisConfigOptions genesisConfigOptions) { this.transactionPool = transactionPool; + this.genesisConfigOptions = genesisConfigOptions; } @Override @@ -68,7 +74,9 @@ private ExecutionStatus process(final int index, final String rawTransaction) { final ValidationResult validationResult = transactionPool .get() - .addLocalTransaction(DomainObjectDecodeUtils.decodeRawTransaction(rawTransaction)); + .addLocalTransaction( + DomainObjectDecodeUtils.decodeRawTransaction( + rawTransaction, genesisConfigOptions)); return validationResult.either( () -> new ExecutionStatus(index), errorReason -> new ExecutionStatus(index, false, errorReason.name())); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlock.java index fa7c9566b93..ece3a2fc5af 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlock.java @@ -28,6 +28,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; import org.hyperledger.besu.ethereum.debug.TraceOptions; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.rlp.RLPException; import org.hyperledger.besu.ethereum.vm.DebugOperationTracer; @@ -45,11 +46,14 @@ public class DebugTraceBlock implements JsonRpcMethod { private final Supplier blockTracerSupplier; private final BlockHeaderFunctions blockHeaderFunctions; private final BlockchainQueries blockchain; + private final boolean isQuorumCompatibilityMode; public DebugTraceBlock( + final ProtocolSchedule protocolSchedule, final Supplier blockTracerSupplier, final BlockHeaderFunctions blockHeaderFunctions, final BlockchainQueries blockchain) { + this.isQuorumCompatibilityMode = protocolSchedule.getGenesisConfigOptions().isQuorum(); this.blockTracerSupplier = blockTracerSupplier; this.blockHeaderFunctions = blockHeaderFunctions; this.blockchain = blockchain; @@ -65,7 +69,11 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { final String input = requestContext.getRequiredParameter(0, String.class); final Block block; try { - block = Block.readFrom(RLP.input(Bytes.fromHexString(input)), this.blockHeaderFunctions); + block = + Block.readFrom( + RLP.input(Bytes.fromHexString(input)), + this.blockHeaderFunctions, + isQuorumCompatibilityMode); } catch (final RLPException e) { LOG.debug("Failed to parse block RLP", e); return new JsonRpcErrorResponse( diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java index 065d30254a3..fc0736947f4 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java @@ -16,7 +16,7 @@ import static org.hyperledger.besu.ethereum.goquorum.GoQuorumPrivateStateUtil.getPrivateWorldStateAtBlock; -import org.hyperledger.besu.config.GoQuorumOptions; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; @@ -35,19 +35,24 @@ public class EthGetCode extends AbstractBlockParameterOrBlockHashMethod { final Optional privacyParameters; + final GenesisConfigOptions genesisConfigOptions; public EthGetCode( final BlockchainQueries blockchainQueries, + final GenesisConfigOptions genesisConfigOptions, final Optional privacyParameters) { super(blockchainQueries); this.privacyParameters = privacyParameters; + this.genesisConfigOptions = genesisConfigOptions; } public EthGetCode( final Supplier blockchainQueries, + final GenesisConfigOptions genesisConfigOptions, final Optional privacyParameters) { super(blockchainQueries); this.privacyParameters = privacyParameters; + this.genesisConfigOptions = genesisConfigOptions; } @Override @@ -64,8 +69,7 @@ protected BlockParameterOrBlockHash blockParameterOrBlockHash( @Override protected String resultByBlockHash(final JsonRpcRequestContext request, final Hash blockHash) { final Address address = request.getRequiredParameter(0, Address.class); - final boolean isGoQuorumCompatibilityMode = GoQuorumOptions.goQuorumCompatibilityMode; - if (isGoQuorumCompatibilityMode && privacyParameters.isPresent()) { + if (genesisConfigOptions.isQuorum() && privacyParameters.isPresent()) { // get from private state if we can final Optional blockHeader = blockchainQueries.get().getBlockHeaderByHash(blockHash); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java index 678bd8d31c1..fb1e49efab3 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcErrorConverter; import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; @@ -39,16 +40,20 @@ public class EthSendRawTransaction implements JsonRpcMethod { private static final Logger LOG = LogManager.getLogger(); private final boolean sendEmptyHashOnInvalidBlock; - + private final GenesisConfigOptions genesisConfigOptions; private final Supplier transactionPool; - public EthSendRawTransaction(final TransactionPool transactionPool) { - this(Suppliers.ofInstance(transactionPool), false); + public EthSendRawTransaction( + final TransactionPool transactionPool, final GenesisConfigOptions genesisConfigOptions) { + this(Suppliers.ofInstance(transactionPool), genesisConfigOptions, false); } public EthSendRawTransaction( - final Supplier transactionPool, final boolean sendEmptyHashOnInvalidBlock) { + final Supplier transactionPool, + final GenesisConfigOptions genesisConfigOptions, + final boolean sendEmptyHashOnInvalidBlock) { this.transactionPool = transactionPool; + this.genesisConfigOptions = genesisConfigOptions; this.sendEmptyHashOnInvalidBlock = sendEmptyHashOnInvalidBlock; } @@ -67,7 +72,8 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { final Transaction transaction; try { - transaction = DomainObjectDecodeUtils.decodeRawTransaction(rawTransaction); + transaction = + DomainObjectDecodeUtils.decodeRawTransaction(rawTransaction, genesisConfigOptions); } catch (final RLPException | IllegalArgumentException e) { return new JsonRpcErrorResponse( requestContext.getRequest().getId(), JsonRpcError.INVALID_PARAMS); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/AbstractEeaSendRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/AbstractEeaSendRawTransaction.java index 560137f8646..51d921bb189 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/AbstractEeaSendRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/AbstractEeaSendRawTransaction.java @@ -31,6 +31,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ValidationResult; import org.hyperledger.besu.ethereum.privacy.PrivateTransaction; import org.hyperledger.besu.ethereum.rlp.RLP; @@ -52,12 +53,15 @@ public abstract class AbstractEeaSendRawTransaction implements JsonRpcMethod { private final PrivacyIdProvider privacyIdProvider; private final PrivateMarkerTransactionFactory privateMarkerTransactionFactory; private final NonceProvider publicNonceProvider; + private final boolean goQuorumCompatibilityMode; protected AbstractEeaSendRawTransaction( + final ProtocolSchedule protocolSchedule, final TransactionPool transactionPool, final PrivacyIdProvider privacyIdProvider, final PrivateMarkerTransactionFactory privateMarkerTransactionFactory, final NonceProvider publicNonceProvider) { + this.goQuorumCompatibilityMode = protocolSchedule.getGenesisConfigOptions().isQuorum(); this.transactionPool = transactionPool; this.privacyIdProvider = privacyIdProvider; this.privateMarkerTransactionFactory = privateMarkerTransactionFactory; @@ -147,7 +151,7 @@ protected Transaction createPrivateMarkerTransaction( final Bytes rlpBytes = privateMarkerTransactionFactory.create( unsignedPrivateMarkerTransaction, privateTransaction, privacyUserId); - return Transaction.readFrom(rlpBytes); + return Transaction.readFrom(rlpBytes, goQuorumCompatibilityMode); } protected abstract long getGasLimit(PrivateTransaction privateTransaction, String pmtPayload); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/PluginEeaSendRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/PluginEeaSendRawTransaction.java index 96017b5bc2e..cf8420215f0 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/PluginEeaSendRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/PluginEeaSendRawTransaction.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ValidationResult; import org.hyperledger.besu.ethereum.privacy.PrivacyController; import org.hyperledger.besu.ethereum.privacy.PrivateTransaction; @@ -39,13 +40,19 @@ public class PluginEeaSendRawTransaction extends AbstractEeaSendRawTransaction { private final GasCalculator gasCalculator; public PluginEeaSendRawTransaction( + final ProtocolSchedule protocolSchedule, final TransactionPool transactionPool, final PrivacyIdProvider privacyIdProvider, final PrivateMarkerTransactionFactory privateMarkerTransactionFactory, final NonceProvider publicNonceProvider, final PrivacyController privacyController, final GasCalculator gasCalculator) { - super(transactionPool, privacyIdProvider, privateMarkerTransactionFactory, publicNonceProvider); + super( + protocolSchedule, + transactionPool, + privacyIdProvider, + privateMarkerTransactionFactory, + publicNonceProvider); this.privacyController = privacyController; this.privacyIdProvider = privacyIdProvider; this.gasCalculator = gasCalculator; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOffchainEeaSendRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOffchainEeaSendRawTransaction.java index 49210cc5054..fae55b49da9 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOffchainEeaSendRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOffchainEeaSendRawTransaction.java @@ -23,6 +23,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ValidationResult; import org.hyperledger.besu.ethereum.privacy.PrivacyController; import org.hyperledger.besu.ethereum.privacy.PrivateTransaction; @@ -42,12 +43,18 @@ public class RestrictedOffchainEeaSendRawTransaction extends AbstractEeaSendRawT private final PrivacyIdProvider privacyIdProvider; public RestrictedOffchainEeaSendRawTransaction( + final ProtocolSchedule protocolSchedule, final TransactionPool transactionPool, final PrivacyIdProvider privacyIdProvider, final PrivateMarkerTransactionFactory privateMarkerTransactionFactory, final NonceProvider publicNonceProvider, final PrivacyController privacyController) { - super(transactionPool, privacyIdProvider, privateMarkerTransactionFactory, publicNonceProvider); + super( + protocolSchedule, + transactionPool, + privacyIdProvider, + privateMarkerTransactionFactory, + publicNonceProvider); this.privacyIdProvider = privacyIdProvider; this.privacyController = privacyController; } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOnchainEeaSendRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOnchainEeaSendRawTransaction.java index c365c4b6881..8293743c83f 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOnchainEeaSendRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOnchainEeaSendRawTransaction.java @@ -23,6 +23,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ValidationResult; import org.hyperledger.besu.ethereum.privacy.PrivacyController; import org.hyperledger.besu.ethereum.privacy.PrivateTransaction; @@ -43,12 +44,18 @@ public class RestrictedOnchainEeaSendRawTransaction extends AbstractEeaSendRawTr private final PrivacyIdProvider privacyIdProvider; public RestrictedOnchainEeaSendRawTransaction( + final ProtocolSchedule protocolSchedule, final TransactionPool transactionPool, final PrivacyIdProvider privacyIdProvider, final PrivateMarkerTransactionFactory privateMarkerTransactionFactory, final NonceProvider publicNonceProvider, final PrivacyController privacyController) { - super(transactionPool, privacyIdProvider, privateMarkerTransactionFactory, publicNonceProvider); + super( + protocolSchedule, + transactionPool, + privacyIdProvider, + privateMarkerTransactionFactory, + publicNonceProvider); this.privacyController = privacyController; this.privacyIdProvider = privacyIdProvider; } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/GoQuorumSendRawPrivateTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/GoQuorumSendRawPrivateTransaction.java index 65af69998a7..9b66caf58be 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/GoQuorumSendRawPrivateTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/GoQuorumSendRawPrivateTransaction.java @@ -31,6 +31,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.privacy.GoQuorumSendRawTxArgs; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.rlp.RLPException; @@ -47,11 +48,14 @@ public class GoQuorumSendRawPrivateTransaction implements JsonRpcMethod { final TransactionPool transactionPool; private final PrivacyIdProvider privacyIdProvider; private final GoQuorumEnclave enclave; + private final boolean goQuorumCompatibilityMode; public GoQuorumSendRawPrivateTransaction( + final ProtocolSchedule protocolSchedule, final GoQuorumEnclave enclave, final TransactionPool transactionPool, final PrivacyIdProvider privacyIdProvider) { + this.goQuorumCompatibilityMode = protocolSchedule.getGenesisConfigOptions().isQuorum(); this.enclave = enclave; this.transactionPool = transactionPool; this.privacyIdProvider = privacyIdProvider; @@ -72,7 +76,8 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { try { final Transaction transaction = - Transaction.readFrom(RLP.input(Bytes.fromHexString(rawPrivateTransaction))); + Transaction.readFrom( + RLP.input(Bytes.fromHexString(rawPrivateTransaction)), goQuorumCompatibilityMode); checkAndHandlePrivateTransaction(transaction, rawTxArgs, requestContext); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/DebugJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/DebugJsonRpcMethods.java index 7bac0f87634..0790d93375b 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/DebugJsonRpcMethods.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/DebugJsonRpcMethods.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.api.jsonrpc.methods; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugAccountAt; @@ -46,6 +47,7 @@ public class DebugJsonRpcMethods extends ApiGroupJsonRpcMethods { private final BlockResultFactory blockResult = new BlockResultFactory(); + private final GenesisConfigOptions genesisConfigOptions; private final BlockchainQueries blockchainQueries; private final ProtocolSchedule protocolSchedule; private final ObservableMetricsSystem metricsSystem; @@ -53,11 +55,13 @@ public class DebugJsonRpcMethods extends ApiGroupJsonRpcMethods { private final Path dataDir; DebugJsonRpcMethods( + final GenesisConfigOptions genesisConfigOptions, final BlockchainQueries blockchainQueries, final ProtocolSchedule protocolSchedule, final ObservableMetricsSystem metricsSystem, final TransactionPool transactionPool, final Path dataDir) { + this.genesisConfigOptions = genesisConfigOptions; this.blockchainQueries = blockchainQueries; this.protocolSchedule = protocolSchedule; this.metricsSystem = metricsSystem; @@ -84,12 +88,13 @@ protected Map create() { new DebugStorageRangeAt(blockchainQueries, blockReplay), new DebugMetrics(metricsSystem), new DebugTraceBlock( + protocolSchedule, () -> new BlockTracer(blockReplay), ScheduleBasedBlockHeaderFunctions.create(protocolSchedule), blockchainQueries), new DebugTraceBlockByNumber(() -> new BlockTracer(blockReplay), blockchainQueries), new DebugTraceBlockByHash(() -> new BlockTracer(blockReplay)), - new DebugBatchSendRawTransaction(transactionPool), + new DebugBatchSendRawTransaction(transactionPool, genesisConfigOptions), new DebugGetBadBlocks(blockchainQueries, protocolSchedule, blockResult), new DebugStandardTraceBlockToFile( () -> new TransactionTracer(blockReplay), blockchainQueries, dataDir), diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EeaJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EeaJsonRpcMethods.java index 31fc7e791e3..20a882e3d62 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EeaJsonRpcMethods.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EeaJsonRpcMethods.java @@ -60,6 +60,7 @@ protected Map create( if (privacyParameters.isPrivacyPluginEnabled()) { return mapOf( new PluginEeaSendRawTransaction( + getProtocolSchedule(), transactionPool, privacyIdProvider, privateMarkerTransactionFactory, @@ -70,6 +71,7 @@ protected Map create( } else if (getPrivacyParameters().isOnchainPrivacyGroupsEnabled()) { return mapOf( new RestrictedOnchainEeaSendRawTransaction( + getProtocolSchedule(), transactionPool, privacyIdProvider, privateMarkerTransactionFactory, @@ -79,6 +81,7 @@ protected Map create( } else { // off chain privacy return mapOf( new RestrictedOffchainEeaSendRawTransaction( + getProtocolSchedule(), transactionPool, privacyIdProvider, privateMarkerTransactionFactory, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthJsonRpcMethods.java index ffba7c3a40a..7df5c77a41b 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthJsonRpcMethods.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthJsonRpcMethods.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.api.jsonrpc.methods; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager; @@ -79,6 +80,7 @@ public class EthJsonRpcMethods extends ApiGroupJsonRpcMethods { private final BlockResultFactory blockResult = new BlockResultFactory(); + private final GenesisConfigOptions genesisConfigOptions; private final BlockchainQueries blockchainQueries; private final Synchronizer synchronizer; private final ProtocolSchedule protocolSchedule; @@ -89,6 +91,7 @@ public class EthJsonRpcMethods extends ApiGroupJsonRpcMethods { private final PrivacyParameters privacyParameters; public EthJsonRpcMethods( + final GenesisConfigOptions genesisConfigOptions, final BlockchainQueries blockchainQueries, final Synchronizer synchronizer, final ProtocolSchedule protocolSchedule, @@ -97,6 +100,7 @@ public EthJsonRpcMethods( final MiningCoordinator miningCoordinator, final Set supportedCapabilities, final PrivacyParameters privacyParameters) { + this.genesisConfigOptions = genesisConfigOptions; this.blockchainQueries = blockchainQueries; this.synchronizer = synchronizer; this.protocolSchedule = protocolSchedule; @@ -130,7 +134,7 @@ protected Map create() { protocolSchedule, privacyParameters)), new EthFeeHistory(protocolSchedule, blockchainQueries.getBlockchain()), - new EthGetCode(blockchainQueries, Optional.of(privacyParameters)), + new EthGetCode(blockchainQueries, genesisConfigOptions, Optional.of(privacyParameters)), new EthGetLogs(blockchainQueries), new EthGetProof(blockchainQueries), new EthGetUncleCountByBlockHash(blockchainQueries), @@ -150,7 +154,7 @@ protected Map create() { new EthGetFilterLogs(filterManager), new EthSyncing(synchronizer), new EthGetStorageAt(blockchainQueries), - new EthSendRawTransaction(transactionPool), + new EthSendRawTransaction(transactionPool, genesisConfigOptions), new EthSendTransaction(), new EthEstimateGas( blockchainQueries, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/GoQuorumJsonRpcPrivacyMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/GoQuorumJsonRpcPrivacyMethods.java index ec9f1011689..960fdfb3e04 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/GoQuorumJsonRpcPrivacyMethods.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/GoQuorumJsonRpcPrivacyMethods.java @@ -57,7 +57,7 @@ protected Map create( final GoQuorumEnclave enclave = goQuorumParameters.get().enclave(); return mapOf( new GoQuorumSendRawPrivateTransaction( - enclave, getTransactionPool(), enclavePublicKeyProvider), + getProtocolSchedule(), enclave, getTransactionPool(), enclavePublicKeyProvider), new GoQuorumStoreRawPrivateTransaction(enclave), new GoQuorumEthGetQuorumPayload(enclave)); } else { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java index 05694a38817..348c082fdd6 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java @@ -90,12 +90,18 @@ public Map methods( natService, ethPeers), new DebugJsonRpcMethods( - blockchainQueries, protocolSchedule, metricsSystem, transactionPool, dataDir), + genesisConfigOptions, + blockchainQueries, + protocolSchedule, + metricsSystem, + transactionPool, + dataDir), new EeaJsonRpcMethods( blockchainQueries, protocolSchedule, transactionPool, privacyParameters), new GoQuorumJsonRpcPrivacyMethods( blockchainQueries, protocolSchedule, transactionPool, privacyParameters), new EthJsonRpcMethods( + genesisConfigOptions, blockchainQueries, synchronizer, protocolSchedule, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtils.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtils.java index 6dc45a980be..08e308feb29 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtils.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtils.java @@ -14,7 +14,7 @@ */ package org.hyperledger.besu.ethereum.api.util; -import org.hyperledger.besu.config.GoQuorumOptions; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcRequestException; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.encoding.TransactionDecoder; @@ -27,12 +27,12 @@ public class DomainObjectDecodeUtils { private static final Logger LOG = LogManager.getLogger(); - public static Transaction decodeRawTransaction(final String rawTransaction) + public static Transaction decodeRawTransaction( + final String rawTransaction, final GenesisConfigOptions genesisConfigOptions) throws InvalidJsonRpcRequestException { try { Bytes txnBytes = Bytes.fromHexString(rawTransaction); - final boolean isGoQuorumCompatibilityMode = GoQuorumOptions.goQuorumCompatibilityMode; - return TransactionDecoder.decodeOpaqueBytes(txnBytes, isGoQuorumCompatibilityMode); + return TransactionDecoder.decodeOpaqueBytes(txnBytes, genesisConfigOptions.isQuorum()); } catch (final IllegalArgumentException | RLPException e) { LOG.debug(e); throw new InvalidJsonRpcRequestException("Invalid raw transaction hex", e); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractDataFetcherTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractDataFetcherTest.java index 35b374b9a83..df9cafa012a 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractDataFetcherTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractDataFetcherTest.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.api.graphql; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter.NormalBlockAdapter; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.core.BlockHeader; @@ -47,7 +48,8 @@ public abstract class AbstractDataFetcherTest { @Before public void before() { - final GraphQLDataFetchers fetchers = new GraphQLDataFetchers(supportedCapabilities); + final GraphQLDataFetchers fetchers = + new GraphQLDataFetchers(supportedCapabilities, new StubGenesisConfigOptions()); fetcher = fetchers.getBlockDataFetcher(); Mockito.when(environment.getContext()).thenReturn(context); Mockito.when(context.getBlockchainQueries()).thenReturn(query); 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 edab09430c5..89554329dda 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 @@ -16,6 +16,7 @@ import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.ImmutableApiConfiguration; @@ -109,7 +110,8 @@ public static void setupConstants() throws Exception { try (final RawBlockIterator iterator = new RawBlockIterator( Paths.get(blocksUrl.toURI()), - rlp -> BlockHeader.readFrom(rlp, new MainnetBlockHeaderFunctions()))) { + rlp -> BlockHeader.readFrom(rlp, new MainnetBlockHeaderFunctions()), + new StubGenesisConfigOptions())) { while (iterator.hasNext()) { BLOCKS.add(iterator.next()); } @@ -158,7 +160,8 @@ public void setupTest() throws Exception { GENESIS_CONFIG.writeStateTo(stateArchive.getMutable()); final MutableBlockchain blockchain = - InMemoryKeyValueStorageProvider.createInMemoryBlockchain(GENESIS_BLOCK); + InMemoryKeyValueStorageProvider.createInMemoryBlockchain( + new StubGenesisConfigOptions(), GENESIS_BLOCK); context = new ProtocolContext(blockchain, stateArchive, null); final BlockchainQueries blockchainQueries = new BlockchainQueries( @@ -183,7 +186,8 @@ public void setupTest() throws Exception { miningCoordinatorMock, synchronizerMock); - final GraphQLDataFetchers dataFetchers = new GraphQLDataFetchers(supportedCapabilities); + final GraphQLDataFetchers dataFetchers = + new GraphQLDataFetchers(supportedCapabilities, new StubGenesisConfigOptions()); final GraphQL graphQL = GraphQLProvider.buildGraphQL(dataFetchers); service = diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceCorsTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceCorsTest.java index 801a1977c79..24479ba6ee5 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceCorsTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceCorsTest.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.api.graphql; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.core.Synchronizer; @@ -224,7 +225,8 @@ private GraphQLHttpService createGraphQLHttpServiceWithAllowedDomains( final Set supportedCapabilities = new HashSet<>(); supportedCapabilities.add(EthProtocol.ETH62); supportedCapabilities.add(EthProtocol.ETH63); - final GraphQLDataFetchers dataFetchers = new GraphQLDataFetchers(supportedCapabilities); + final GraphQLDataFetchers dataFetchers = + new GraphQLDataFetchers(supportedCapabilities, new StubGenesisConfigOptions()); final GraphQL graphQL = GraphQLProvider.buildGraphQL(dataFetchers); final GraphQLHttpService graphQLHttpService = diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceHostWhitelistTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceHostWhitelistTest.java index 70b34cdb114..49c3e62af46 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceHostWhitelistTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceHostWhitelistTest.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.api.graphql; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.core.Synchronizer; @@ -85,7 +86,8 @@ private GraphQLHttpService createGraphQLHttpService() throws Exception { final Set supportedCapabilities = new HashSet<>(); supportedCapabilities.add(EthProtocol.ETH62); supportedCapabilities.add(EthProtocol.ETH63); - final GraphQLDataFetchers dataFetchers = new GraphQLDataFetchers(supportedCapabilities); + final GraphQLDataFetchers dataFetchers = + new GraphQLDataFetchers(supportedCapabilities, new StubGenesisConfigOptions()); final GraphQL graphQL = GraphQLProvider.buildGraphQL(dataFetchers); return new GraphQLHttpService( diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceTest.java index cd4a49baeaf..7d536c3d461 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceTest.java @@ -16,6 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.api.query.BlockWithMetadata; @@ -93,7 +94,8 @@ public static void initServerAndClient() throws Exception { final Set supportedCapabilities = new HashSet<>(); supportedCapabilities.add(EthProtocol.ETH62); supportedCapabilities.add(EthProtocol.ETH63); - final GraphQLDataFetchers dataFetchers = new GraphQLDataFetchers(supportedCapabilities); + final GraphQLDataFetchers dataFetchers = + new GraphQLDataFetchers(supportedCapabilities, new StubGenesisConfigOptions()); graphQL = GraphQLProvider.buildGraphQL(dataFetchers); service = createGraphQLHttpService(); service.start().join(); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java index d7c9f069833..4beadce4861 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java @@ -264,7 +264,7 @@ private P2PNetwork createP2pNetwork() { .vertx(vertx) .config(config) .metricsSystem(new NoOpMetricsSystem()) - .storageProvider(new InMemoryKeyValueStorageProvider()) + .storageProvider(new InMemoryKeyValueStorageProvider(new StubGenesisConfigOptions())) .forkIdSupplier(() -> Collections.singletonList(Bytes.EMPTY)) .build(); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugBatchSendRawTransactionTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugBatchSendRawTransactionTest.java index feec12cba0b..6659c67d37b 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugBatchSendRawTransactionTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugBatchSendRawTransactionTest.java @@ -18,6 +18,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; @@ -46,7 +47,7 @@ public class DebugBatchSendRawTransactionTest { @Before public void setUp() { - method = new DebugBatchSendRawTransaction(transactionPool); + method = new DebugBatchSendRawTransaction(transactionPool, new StubGenesisConfigOptions()); } @Test diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockTest.java index d05c5507bdf..bf67590b756 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceBlockTest.java @@ -18,9 +18,11 @@ import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; @@ -36,6 +38,7 @@ import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.debug.TraceFrame; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; import org.hyperledger.besu.evm.Gas; @@ -44,15 +47,30 @@ import java.util.Optional; import org.apache.tuweni.bytes.Bytes; +import org.junit.Before; import org.junit.Test; +import org.mockito.Mock; import org.mockito.Mockito; public class DebugTraceBlockTest { private final BlockTracer blockTracer = mock(BlockTracer.class); private final BlockchainQueries blockchainQueries = mock(BlockchainQueries.class); - private final DebugTraceBlock debugTraceBlock = - new DebugTraceBlock(() -> blockTracer, new MainnetBlockHeaderFunctions(), blockchainQueries); + @Mock private ProtocolSchedule protocolSchedule; + private DebugTraceBlock debugTraceBlock; + + @Before + public void before() { + lenient() + .when(protocolSchedule.getGenesisConfigOptions()) + .thenReturn(new StubGenesisConfigOptions()); + debugTraceBlock = + new DebugTraceBlock( + protocolSchedule, + () -> blockTracer, + new MainnetBlockHeaderFunctions(), + blockchainQueries); + } @Test public void nameShouldBeDebugTraceBlock() { diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java index f8e3ff8d418..c26d01f02f9 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java @@ -22,6 +22,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; @@ -54,7 +55,7 @@ public class EthFeeHistoryTest { public void setUp() { protocolSchedule = mock(ProtocolSchedule.class); final Block genesisBlock = gen.genesisBlock(); - blockchain = createInMemoryBlockchain(genesisBlock); + blockchain = createInMemoryBlockchain(new StubGenesisConfigOptions(), genesisBlock); gen.blockSequence(genesisBlock, 10) .forEach(block -> blockchain.appendBlock(block, gen.receipts(block))); method = new EthFeeHistory(protocolSchedule, blockchain); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransactionTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransactionTest.java index 73a97c9d54c..9b4957d4b87 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransactionTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransactionTest.java @@ -19,6 +19,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; @@ -46,7 +47,7 @@ public class EthSendRawTransactionTest { @Before public void before() { - method = new EthSendRawTransaction(transactionPool); + method = new EthSendRawTransaction(transactionPool, new StubGenesisConfigOptions()); } @Test diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransactionTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransactionTest.java index e953689b078..bafe8fbf6b9 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransactionTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransactionTest.java @@ -19,11 +19,13 @@ import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.PRIVATE_TRANSACTION_FAILED; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; @@ -31,6 +33,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ValidationResult; import org.hyperledger.besu.ethereum.privacy.MultiTenancyValidationException; import org.hyperledger.besu.ethereum.privacy.PrivateTransaction; @@ -39,6 +42,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) @@ -58,11 +62,17 @@ public class EeaSendRawTransactionTest extends BaseEeaSendRawTransaction { RestrictedOffchainEeaSendRawTransaction method; + @Mock private ProtocolSchedule protocolSchedule; + @Before public void before() { + lenient() + .when(protocolSchedule.getGenesisConfigOptions()) + .thenReturn(new StubGenesisConfigOptions()); method = new RestrictedOffchainEeaSendRawTransaction( + protocolSchedule, transactionPool, privacyIdProvider, privateMarkerTransactionFactory, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/PluginEeaSendRawTransactionTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/PluginEeaSendRawTransactionTest.java index 84e8c78a4e7..b96a6ce4ed8 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/PluginEeaSendRawTransactionTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/PluginEeaSendRawTransactionTest.java @@ -16,16 +16,20 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ValidationResult; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) @@ -33,10 +37,16 @@ public class PluginEeaSendRawTransactionTest extends BaseEeaSendRawTransaction { PluginEeaSendRawTransaction method; + @Mock private ProtocolSchedule protocolSchedule; + @Before public void before() { + lenient() + .when(protocolSchedule.getGenesisConfigOptions()) + .thenReturn(new StubGenesisConfigOptions()); method = new PluginEeaSendRawTransaction( + protocolSchedule, transactionPool, user -> "", privateMarkerTransactionFactory, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOffchainEeaSendRawTransactionTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOffchainEeaSendRawTransactionTest.java index d84d0f6143a..31d5267d089 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOffchainEeaSendRawTransactionTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOffchainEeaSendRawTransactionTest.java @@ -17,15 +17,18 @@ import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.enclave.types.PrivacyGroup; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ValidationResult; import java.util.Optional; @@ -33,6 +36,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) @@ -43,10 +47,16 @@ public class RestrictedOffchainEeaSendRawTransactionTest extends BaseEeaSendRawT RestrictedOffchainEeaSendRawTransaction method; + @Mock private ProtocolSchedule protocolSchedule; + @Before public void before() { + lenient() + .when(protocolSchedule.getGenesisConfigOptions()) + .thenReturn(new StubGenesisConfigOptions()); method = new RestrictedOffchainEeaSendRawTransaction( + protocolSchedule, transactionPool, privacyIdProvider, privateMarkerTransactionFactory, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOnchainEeaSendRawTransactionTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOnchainEeaSendRawTransactionTest.java index 5056e20314d..68480ae4d1a 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOnchainEeaSendRawTransactionTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOnchainEeaSendRawTransactionTest.java @@ -16,9 +16,11 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.enclave.types.PrivacyGroup; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; @@ -26,6 +28,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.core.Transaction; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ValidationResult; import java.util.Arrays; @@ -34,6 +37,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) @@ -44,10 +48,17 @@ public class RestrictedOnchainEeaSendRawTransactionTest extends BaseEeaSendRawTr RestrictedOnchainEeaSendRawTransaction method; + @Mock private ProtocolSchedule protocolSchedule; + @Before public void before() { + lenient() + .when(protocolSchedule.getGenesisConfigOptions()) + .thenReturn(new StubGenesisConfigOptions()); + method = new RestrictedOnchainEeaSendRawTransaction( + protocolSchedule, transactionPool, privacyIdProvider, privateMarkerTransactionFactory, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/goquorum/GoQuorumSendRawPrivateTransactionTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/goquorum/GoQuorumSendRawPrivateTransactionTest.java index 43e14a65c4d..5d935a300f0 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/goquorum/GoQuorumSendRawPrivateTransactionTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/goquorum/GoQuorumSendRawPrivateTransactionTest.java @@ -17,11 +17,12 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; -import org.hyperledger.besu.config.GoQuorumOptions; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.crypto.SignatureAlgorithm; import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; @@ -38,6 +39,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ValidationResult; import org.hyperledger.besu.ethereum.privacy.GoQuorumSendRawTxArgs; import org.hyperledger.besu.ethereum.privacy.PrivateTransaction; @@ -72,6 +74,7 @@ public class GoQuorumSendRawPrivateTransactionTest { @Mock GoQuorumSendRawPrivateTransaction method; @Mock TransactionPool transactionPool; @Mock GoQuorumEnclave enclave; + @Mock private ProtocolSchedule protocolSchedule; private static final String RAW_TRANSACTION_STRING = "someString"; private static final String RAW_TRANSACTION = createValidTransactionRLP(); private static final GoQuorumSendRawTxArgs GO_QUORUM_SEND_RAW_TX_ARGS = @@ -80,7 +83,12 @@ public class GoQuorumSendRawPrivateTransactionTest { @Before public void before() { - method = new GoQuorumSendRawPrivateTransaction(enclave, transactionPool, privacyIdProvider); + lenient() + .when(protocolSchedule.getGenesisConfigOptions()) + .thenReturn(new StubGenesisConfigOptions()); + method = + new GoQuorumSendRawPrivateTransaction( + protocolSchedule, enclave, transactionPool, privacyIdProvider); } @Test @@ -126,7 +134,7 @@ public void requestHasNullArrayParameter() { @Test public void validTransactionIsSentToTransactionPool() { - GoQuorumOptions.goQuorumCompatibilityMode = true; + // TODO: update from GoQuorumOptions.goQuorumCompatibilityMode = true; when(enclave.sendSignedTransaction(any(), any())).thenReturn(null); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/blockheaders/NewBlockHeadersSubscriptionServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/blockheaders/NewBlockHeadersSubscriptionServiceTest.java index 3259d873ab7..f3c26b39cb4 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/blockheaders/NewBlockHeadersSubscriptionServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/blockheaders/NewBlockHeadersSubscriptionServiceTest.java @@ -21,6 +21,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResult; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.JsonRpcResult; @@ -60,7 +61,9 @@ public class NewBlockHeadersSubscriptionServiceTest { private final BlockDataGenerator gen = new BlockDataGenerator(); private final BlockchainStorage blockchainStorage = new KeyValueStoragePrefixedKeyBlockchainStorage( - new InMemoryKeyValueStorage(), new MainnetBlockHeaderFunctions()); + new InMemoryKeyValueStorage(), + new MainnetBlockHeaderFunctions(), + new StubGenesisConfigOptions()); private final Block genesisBlock = gen.genesisBlock(); private final MutableBlockchain blockchain = DefaultBlockchain.createMutable(genesisBlock, blockchainStorage, new NoOpMetricsSystem(), 0); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/logs/LogsSubscriptionServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/logs/LogsSubscriptionServiceTest.java index 80727e2f197..46b1f11c9f7 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/logs/LogsSubscriptionServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/logs/LogsSubscriptionServiceTest.java @@ -21,6 +21,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; @@ -66,7 +67,8 @@ public class LogsSubscriptionServiceTest { private final BlockDataGenerator gen = new BlockDataGenerator(1); private final MutableBlockchain blockchain = - InMemoryKeyValueStorageProvider.createInMemoryBlockchain(gen.genesisBlock()); + InMemoryKeyValueStorageProvider.createInMemoryBlockchain( + new StubGenesisConfigOptions(), gen.genesisBlock()); private LogsSubscriptionService logsSubscriptionService; private final AtomicLong nextSubscriptionId = new AtomicLong(); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesTest.java index d1abacc0a04..34fe2828893 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesTest.java @@ -21,6 +21,7 @@ import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain; import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; @@ -556,7 +557,8 @@ private BlockchainWithData setupBlockchain( } // Setup blockchain - final MutableBlockchain blockchain = createInMemoryBlockchain(blocks.get(0)); + final MutableBlockchain blockchain = + createInMemoryBlockchain(new StubGenesisConfigOptions(), blocks.get(0)); blockData .subList(1, blockData.size()) .forEach(b -> blockchain.appendBlock(b.block, b.receipts)); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtilsTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtilsTest.java index 942898b8128..64b9badbea8 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtilsTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtilsTest.java @@ -16,6 +16,7 @@ */ package org.hyperledger.besu.ethereum.api.util; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.crypto.SECPSignature; import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; import org.hyperledger.besu.datatypes.Address; @@ -61,7 +62,8 @@ public void testAccessListRLPSerDes() { final BytesValueRLPOutput encoded = new BytesValueRLPOutput(); TransactionEncoder.encodeForWire(accessListTxn, encoded); Transaction decoded = - DomainObjectDecodeUtils.decodeRawTransaction(encoded.encoded().toHexString()); + DomainObjectDecodeUtils.decodeRawTransaction( + encoded.encoded().toHexString(), new StubGenesisConfigOptions()); Assertions.assertThat(decoded.getAccessList().isPresent()).isTrue(); Assertions.assertThat(decoded.getAccessList().map(List::size).get()).isEqualTo(1); } @@ -69,7 +71,9 @@ public void testAccessListRLPSerDes() { @Test public void testAccessList2718OpaqueSerDes() { final Bytes encoded = TransactionEncoder.encodeOpaqueBytes(accessListTxn); - Transaction decoded = DomainObjectDecodeUtils.decodeRawTransaction(encoded.toString()); + Transaction decoded = + DomainObjectDecodeUtils.decodeRawTransaction( + encoded.toString(), new StubGenesisConfigOptions()); Assertions.assertThat(decoded.getAccessList().isPresent()).isTrue(); Assertions.assertThat(decoded.getAccessList().map(List::size).get()).isEqualTo(1); } 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 c9480eb80d3..deaa64d48d1 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 @@ -21,6 +21,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.MinedBlockObserver; import org.hyperledger.besu.ethereum.core.Block; @@ -134,7 +135,8 @@ private static Subscribers subscribersContaining( private ProtocolSchedule singleSpecSchedule(final ProtocolSpec protocolSpec) { final MutableProtocolSchedule protocolSchedule = - new MutableProtocolSchedule(Optional.of(BigInteger.valueOf(1234))); + new MutableProtocolSchedule( + Optional.of(BigInteger.valueOf(1234)), new StubGenesisConfigOptions()); protocolSchedule.putMilestone(0, protocolSpec); return protocolSchedule; } diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockTransactionSelectorTest.java index 510001a434d..6fab991c0e6 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockTransactionSelectorTest.java @@ -22,6 +22,7 @@ import static org.mockito.Mockito.when; import org.hyperledger.besu.config.GenesisConfigFile; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; import org.hyperledger.besu.datatypes.Address; @@ -89,7 +90,7 @@ public class BlockTransactionSelectorTest { BlockTransactionSelectorTest::mockBlockHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP); private final MutableWorldState worldState = - InMemoryKeyValueStorageProvider.createInMemoryWorldState(); + InMemoryKeyValueStorageProvider.createInMemoryWorldState(new StubGenesisConfigOptions()); @Mock private MainnetTransactionProcessor transactionProcessor; @Mock private MainnetTransactionValidator transactionValidator; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Block.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Block.java index aeb115c1f41..765054d250e 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Block.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Block.java @@ -64,10 +64,14 @@ public void writeTo(final RLPOutput out) { out.endList(); } - public static Block readFrom(final RLPInput in, final BlockHeaderFunctions hashFunction) { + public static Block readFrom( + final RLPInput in, + final BlockHeaderFunctions hashFunction, + final boolean goQuorumCompatibilityMode) { in.enterList(); final BlockHeader header = BlockHeader.readFrom(in, hashFunction); - final List transactions = in.readList(Transaction::readFrom); + final List transactions = + in.readList(rlp -> Transaction.readFrom(rlp, goQuorumCompatibilityMode)); final List ommers = in.readList(rlp -> BlockHeader.readFrom(rlp, hashFunction)); in.leaveList(); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockBody.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockBody.java index 8ae7024b32d..3244131a53b 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockBody.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockBody.java @@ -65,12 +65,14 @@ public void writeTo(final RLPOutput output) { } public static BlockBody readFrom( - final RLPInput input, final BlockHeaderFunctions blockHeaderFunctions) { + final RLPInput input, + final BlockHeaderFunctions blockHeaderFunctions, + final boolean goQuorumCompatibilityMode) { input.enterList(); // TODO: Support multiple hard fork transaction formats. final BlockBody body = new BlockBody( - input.readList(Transaction::readFrom), + input.readList(rlp -> Transaction.readFrom(rlp, goQuorumCompatibilityMode)), input.readList(rlp -> BlockHeader.readFrom(rlp, blockHeaderFunctions))); input.leaveList(); return body; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java index d7ca152c974..7f557bf3fae 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java @@ -111,12 +111,14 @@ public static Builder builder() { return new Builder(); } - public static Transaction readFrom(final Bytes rlpBytes) { - return readFrom(RLP.input(rlpBytes)); + public static Transaction readFrom( + final Bytes rlpBytes, final boolean goQuorumCompatibilityMode) { + return readFrom(RLP.input(rlpBytes), goQuorumCompatibilityMode); } - public static Transaction readFrom(final RLPInput rlpInput) { - return TransactionDecoder.decodeForWire(rlpInput); + public static Transaction readFrom( + final RLPInput rlpInput, final boolean goQuorumCompatibilityMode) { + return TransactionDecoder.decodeForWire(rlpInput, goQuorumCompatibilityMode); } /** diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionDecoder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionDecoder.java index 38b17b0ca1b..8d83b8fbf8d 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionDecoder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionDecoder.java @@ -22,7 +22,6 @@ import static org.hyperledger.besu.ethereum.core.Transaction.REPLAY_UNPROTECTED_V_BASE_PLUS_1; import static org.hyperledger.besu.ethereum.core.Transaction.TWO; -import org.hyperledger.besu.config.GoQuorumOptions; import org.hyperledger.besu.crypto.SECPSignature; import org.hyperledger.besu.crypto.SignatureAlgorithm; import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; @@ -61,10 +60,6 @@ interface Decoder { private static final Supplier SIGNATURE_ALGORITHM = Suppliers.memoize(SignatureAlgorithmFactory::getInstance); - public static Transaction decodeForWire(final RLPInput rlpInput) { - return decodeForWire(rlpInput, GoQuorumOptions.goQuorumCompatibilityMode); - } - public static Transaction decodeForWire( final RLPInput rlpInput, final boolean goQuorumCompatibilityMode) { if (rlpInput.nextIsList()) { diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MutableProtocolSchedule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MutableProtocolSchedule.java index 9c58fea7f7a..342baf91c61 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MutableProtocolSchedule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MutableProtocolSchedule.java @@ -16,6 +16,7 @@ import static com.google.common.base.Preconditions.checkArgument; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.ethereum.core.TransactionFilter; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; @@ -34,9 +35,12 @@ public class MutableProtocolSchedule implements ProtocolSchedule { Comparator.comparing(ScheduledProtocolSpec::getBlock) .reversed()); private final Optional chainId; + private final GenesisConfigOptions genesisConfigOptions; - public MutableProtocolSchedule(final Optional chainId) { + public MutableProtocolSchedule( + final Optional chainId, final GenesisConfigOptions genesisConfigOptions) { this.chainId = chainId; + this.genesisConfigOptions = genesisConfigOptions; } @Override @@ -100,4 +104,9 @@ public void setPublicWorldStateArchiveForPrivacyBlockProcessor( .setPublicWorldStateArchive(publicWorldStateArchive); }); } + + @Override + public GenesisConfigOptions getGenesisConfigOptions() { + return genesisConfigOptions; + } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSchedule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSchedule.java index fc4979f06b5..e3aa92ea6d7 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSchedule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSchedule.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.mainnet; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.ethereum.core.TransactionFilter; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; @@ -33,4 +34,6 @@ public interface ProtocolSchedule { void setPublicWorldStateArchiveForPrivacyBlockProcessor( WorldStateArchive publicWorldStateArchive); + + GenesisConfigOptions getGenesisConfigOptions(); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java index f96e4d5c41d..181067048e0 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java @@ -128,7 +128,7 @@ private ProtocolScheduleBuilder( public ProtocolSchedule createProtocolSchedule() { final Optional chainId = config.getChainId().map(Optional::of).orElse(defaultChainId); - final MutableProtocolSchedule protocolSchedule = new MutableProtocolSchedule(chainId); + final MutableProtocolSchedule protocolSchedule = new MutableProtocolSchedule(chainId, config); final MainnetProtocolSpecFactory specFactory = new MainnetProtocolSpecFactory( diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/GoQuorumKeyValueStoragePrefixedKeyBlockchainStorage.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/GoQuorumKeyValueStoragePrefixedKeyBlockchainStorage.java index 55254d7ebd3..5cc2a8325b2 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/GoQuorumKeyValueStoragePrefixedKeyBlockchainStorage.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/GoQuorumKeyValueStoragePrefixedKeyBlockchainStorage.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.storage.keyvalue; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; @@ -32,8 +33,10 @@ public class GoQuorumKeyValueStoragePrefixedKeyBlockchainStorage private static final Bytes BLOCK_HEADER_PRIVATE_BLOOM_PREFIX = Bytes.of(8); public GoQuorumKeyValueStoragePrefixedKeyBlockchainStorage( - final KeyValueStorage storage, final BlockHeaderFunctions blockHeaderFunctions) { - super(storage, blockHeaderFunctions); + final KeyValueStorage storage, + final BlockHeaderFunctions blockHeaderFunctions, + final GenesisConfigOptions genesisConfigOptions) { + super(storage, blockHeaderFunctions, genesisConfigOptions); } @Override diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/GoQuorumKeyValueStorageProvider.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/GoQuorumKeyValueStorageProvider.java index 35c5d54b700..9190a09f5d1 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/GoQuorumKeyValueStorageProvider.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/GoQuorumKeyValueStorageProvider.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.storage.keyvalue; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.ethereum.chain.BlockchainStorage; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; @@ -25,18 +26,22 @@ public class GoQuorumKeyValueStorageProvider extends KeyValueStorageProvider { public GoQuorumKeyValueStorageProvider( + final GenesisConfigOptions genesisConfigOptions, final Function storageCreator, final KeyValueStorage worldStatePreimageStorage, final boolean segmentIsolationSupported) { - super(storageCreator, worldStatePreimageStorage, segmentIsolationSupported); + super( + genesisConfigOptions, storageCreator, worldStatePreimageStorage, segmentIsolationSupported); } public GoQuorumKeyValueStorageProvider( + final GenesisConfigOptions genesisConfigOptions, final Function storageCreator, final KeyValueStorage worldStatePreimageStorage, final KeyValueStorage privateWorldStatePreimageStorage, final boolean segmentIsolationSupported) { super( + genesisConfigOptions, storageCreator, worldStatePreimageStorage, privateWorldStatePreimageStorage, @@ -47,6 +52,7 @@ public GoQuorumKeyValueStorageProvider( public BlockchainStorage createBlockchainStorage(final ProtocolSchedule protocolSchedule) { return new GoQuorumKeyValueStoragePrefixedKeyBlockchainStorage( getStorageBySegmentIdentifier(KeyValueSegmentIdentifier.BLOCKCHAIN), - ScheduleBasedBlockHeaderFunctions.create(protocolSchedule)); + ScheduleBasedBlockHeaderFunctions.create(protocolSchedule), + genesisConfigOptions); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStoragePrefixedKeyBlockchainStorage.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStoragePrefixedKeyBlockchainStorage.java index 95797c876ea..5f5d2e95d71 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStoragePrefixedKeyBlockchainStorage.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStoragePrefixedKeyBlockchainStorage.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.storage.keyvalue; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.chain.BlockchainStorage; import org.hyperledger.besu.ethereum.chain.TransactionLocation; @@ -53,11 +54,15 @@ public class KeyValueStoragePrefixedKeyBlockchainStorage implements BlockchainSt final KeyValueStorage storage; final BlockHeaderFunctions blockHeaderFunctions; + private final boolean goQuorumCompatibilityMode; public KeyValueStoragePrefixedKeyBlockchainStorage( - final KeyValueStorage storage, final BlockHeaderFunctions blockHeaderFunctions) { + final KeyValueStorage storage, + final BlockHeaderFunctions blockHeaderFunctions, + final GenesisConfigOptions genesisConfigOptions) { this.storage = storage; this.blockHeaderFunctions = blockHeaderFunctions; + this.goQuorumCompatibilityMode = genesisConfigOptions.isQuorum(); } @Override @@ -81,7 +86,10 @@ public Optional getBlockHeader(final Hash blockHash) { @Override public Optional getBlockBody(final Hash blockHash) { return get(BLOCK_BODY_PREFIX, blockHash) - .map(bytes -> BlockBody.readFrom(RLP.input(bytes), blockHeaderFunctions)); + .map( + bytes -> + BlockBody.readFrom( + RLP.input(bytes), blockHeaderFunctions, goQuorumCompatibilityMode)); } @Override diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStorageProvider.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStorageProvider.java index f709fee1428..64d576a341c 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStorageProvider.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStorageProvider.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.storage.keyvalue; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.ethereum.bonsai.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.chain.BlockchainStorage; import org.hyperledger.besu.ethereum.goquorum.GoQuorumPrivateKeyValueStorage; @@ -34,6 +35,7 @@ public class KeyValueStorageProvider implements StorageProvider { + protected final GenesisConfigOptions genesisConfigOptions; private final Function storageCreator; private final KeyValueStorage worldStatePreimageStorage; private final KeyValueStorage privateWorldStatePreimageStorage; @@ -41,9 +43,11 @@ public class KeyValueStorageProvider implements StorageProvider { private final Map storageInstances = new HashMap<>(); public KeyValueStorageProvider( + final GenesisConfigOptions genesisConfigOptions, final Function storageCreator, final KeyValueStorage worldStatePreimageStorage, final boolean segmentIsolationSupported) { + this.genesisConfigOptions = genesisConfigOptions; this.storageCreator = storageCreator; this.worldStatePreimageStorage = worldStatePreimageStorage; this.privateWorldStatePreimageStorage = null; @@ -51,10 +55,12 @@ public KeyValueStorageProvider( } public KeyValueStorageProvider( + final GenesisConfigOptions genesisConfigOptions, final Function storageCreator, final KeyValueStorage worldStatePreimageStorage, final KeyValueStorage privateWorldStatePreimageStorage, final boolean segmentIsolationSupported) { + this.genesisConfigOptions = genesisConfigOptions; this.storageCreator = storageCreator; this.worldStatePreimageStorage = worldStatePreimageStorage; this.privateWorldStatePreimageStorage = privateWorldStatePreimageStorage; @@ -65,7 +71,8 @@ public KeyValueStorageProvider( public BlockchainStorage createBlockchainStorage(final ProtocolSchedule protocolSchedule) { return new KeyValueStoragePrefixedKeyBlockchainStorage( getStorageBySegmentIdentifier(KeyValueSegmentIdentifier.BLOCKCHAIN), - ScheduleBasedBlockHeaderFunctions.create(protocolSchedule)); + ScheduleBasedBlockHeaderFunctions.create(protocolSchedule), + genesisConfigOptions); } @Override diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStorageProviderBuilder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStorageProviderBuilder.java index 0be2831e17e..268a331eaa9 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStorageProviderBuilder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStorageProviderBuilder.java @@ -16,6 +16,7 @@ import static com.google.common.base.Preconditions.checkNotNull; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.plugin.services.BesuConfiguration; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.storage.KeyValueStorage; @@ -29,7 +30,7 @@ public class KeyValueStorageProviderBuilder { private KeyValueStorageFactory storageFactory; private BesuConfiguration commonConfiguration; private MetricsSystem metricsSystem; - private boolean isGoQuorumCompatibilityMode; + private GenesisConfigOptions genesisConfigOptions; public KeyValueStorageProviderBuilder withStorageFactory( final KeyValueStorageFactory storageFactory) { @@ -43,14 +44,14 @@ public KeyValueStorageProviderBuilder withCommonConfiguration( return this; } - public KeyValueStorageProviderBuilder withMetricsSystem(final MetricsSystem metricsSystem) { - this.metricsSystem = metricsSystem; + public KeyValueStorageProviderBuilder withGenesisOptions( + final GenesisConfigOptions genesisConfigOptions) { + this.genesisConfigOptions = genesisConfigOptions; return this; } - public KeyValueStorageProviderBuilder isGoQuorumCompatibilityMode( - final boolean isGoQuorumCompatibilityMode) { - this.isGoQuorumCompatibilityMode = isGoQuorumCompatibilityMode; + public KeyValueStorageProviderBuilder withMetricsSystem(final MetricsSystem metricsSystem) { + this.metricsSystem = metricsSystem; return this; } @@ -60,6 +61,7 @@ public KeyValueStorageProvider build() { commonConfiguration, "Cannot build a storage provider without the plugin common configuration."); checkNotNull(metricsSystem, "Cannot build a storage provider without a metrics system."); + checkNotNull(genesisConfigOptions, "Cannot build a storage provider without genesis options."); final KeyValueStorage worldStatePreImageStorage = new LimitedInMemoryKeyValueStorage(DEFAULT_WORLD_STATE_PRE_IMAGE_CACHE_SIZE); @@ -69,14 +71,16 @@ public KeyValueStorageProvider build() { // this tickles init needed for isSegmentIsolationSupported storageFactory.create(KeyValueSegmentIdentifier.BLOCKCHAIN, commonConfiguration, metricsSystem); - if (isGoQuorumCompatibilityMode) { + if (genesisConfigOptions.isQuorum()) { return new GoQuorumKeyValueStorageProvider( + genesisConfigOptions, segment -> storageFactory.create(segment, commonConfiguration, metricsSystem), worldStatePreImageStorage, privateWorldStatePreImageStorage, storageFactory.isSegmentIsolationSupported()); } else { return new KeyValueStorageProvider( + genesisConfigOptions, segment -> storageFactory.create(segment, commonConfiguration, metricsSystem), worldStatePreImageStorage, privateWorldStatePreImageStorage, diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/util/RawBlockIterator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/util/RawBlockIterator.java index ef980ef5ff4..651b7366ed9 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/util/RawBlockIterator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/util/RawBlockIterator.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.util; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; @@ -38,6 +39,7 @@ public final class RawBlockIterator implements Iterator, Closeable { private final FileChannel fileChannel; private final Function headerReader; + private final boolean goQuorumCompatibilityMode; private ByteBuffer readBuffer; private Block next; @@ -45,17 +47,22 @@ public final class RawBlockIterator implements Iterator, Closeable { RawBlockIterator( final Path file, final Function headerReader, + final GenesisConfigOptions genesisConfigOptions, final int initialCapacity) throws IOException { + goQuorumCompatibilityMode = genesisConfigOptions.isQuorum(); fileChannel = FileChannel.open(file); this.headerReader = headerReader; readBuffer = ByteBuffer.allocate(initialCapacity); nextBlock(); } - public RawBlockIterator(final Path file, final Function headerReader) + public RawBlockIterator( + final Path file, + final Function headerReader, + final GenesisConfigOptions genesisConfigOptions) throws IOException { - this(file, headerReader, DEFAULT_INIT_BUFFER_CAPACITY); + this(file, headerReader, genesisConfigOptions, DEFAULT_INIT_BUFFER_CAPACITY); } @Override @@ -101,7 +108,9 @@ private void nextBlock() throws IOException { rlp.enterList(); final BlockHeader header = headerReader.apply(rlp); final BlockBody body = - new BlockBody(rlp.readList(Transaction::readFrom), rlp.readList(headerReader)); + new BlockBody( + rlp.readList(input -> (Transaction.readFrom(input, goQuorumCompatibilityMode))), + rlp.readList(headerReader)); next = new Block(header, body); readBuffer.position(length); readBuffer.compact(); diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockSyncTestUtils.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockSyncTestUtils.java index af3027a1ffe..f679c04d08b 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockSyncTestUtils.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockSyncTestUtils.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.core; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.ethereum.util.RawBlockIterator; import org.hyperledger.besu.testutil.BlockTestUtil; @@ -40,7 +41,9 @@ public static List firstBlocks(final int count) { BlockTestUtil.write1000Blocks(blocks); try (final RawBlockIterator iterator = new RawBlockIterator( - blocks, rlp -> BlockHeader.readFrom(rlp, new MainnetBlockHeaderFunctions()))) { + blocks, + rlp -> BlockHeader.readFrom(rlp, new MainnetBlockHeaderFunctions()), + new StubGenesisConfigOptions())) { for (int i = 0; i < count; ++i) { result.add(iterator.next()); } 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 8154f8386f8..6546b8996f2 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 @@ -21,6 +21,7 @@ import static org.mockito.Mockito.mock; import org.hyperledger.besu.config.GenesisConfigFile; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.GenesisState; @@ -155,12 +156,13 @@ private static BlockchainSetupUtil create( final GenesisConfigFile genesisConfigFile = GenesisConfigFile.fromConfig(genesisJson); final ProtocolSchedule protocolSchedule = protocolScheduleProvider.get(genesisConfigFile); - + final GenesisConfigOptions genesisConfigOptions = protocolSchedule.getGenesisConfigOptions(); final GenesisState genesisState = GenesisState.fromJson(genesisJson, protocolSchedule); - final MutableBlockchain blockchain = createInMemoryBlockchain(genesisState.getBlock()); + final MutableBlockchain blockchain = + createInMemoryBlockchain(genesisConfigOptions, genesisState.getBlock()); final WorldStateArchive worldArchive = storageFormat == DataStorageFormat.BONSAI - ? createBonsaiInMemoryWorldStateArchive(blockchain) + ? createBonsaiInMemoryWorldStateArchive(genesisConfigOptions, blockchain) : createInMemoryWorldStateArchive(); final TransactionPool transactionPool = mock(TransactionPool.class); @@ -173,7 +175,9 @@ private static BlockchainSetupUtil create( ScheduleBasedBlockHeaderFunctions.create(protocolSchedule); try (final RawBlockIterator iterator = new RawBlockIterator( - blocksPath, rlp -> BlockHeader.readFrom(rlp, blockHeaderFunctions))) { + blocksPath, + rlp -> BlockHeader.readFrom(rlp, blockHeaderFunctions), + protocolSchedule.getGenesisConfigOptions())) { while (iterator.hasNext()) { blocks.add(iterator.next()); } 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 1e06900af36..c12833b2a61 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 @@ -55,7 +55,9 @@ private ExecutionContextTestFixture( DefaultBlockchain.createMutable( genesis, new KeyValueStoragePrefixedKeyBlockchainStorage( - keyValueStorage, new MainnetBlockHeaderFunctions()), + keyValueStorage, + new MainnetBlockHeaderFunctions(), + protocolSchedule.getGenesisConfigOptions()), new NoOpMetricsSystem(), 0); this.stateArchive = createInMemoryWorldStateArchive(); diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/InMemoryKeyValueStorageProvider.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/InMemoryKeyValueStorageProvider.java index 8ce4a09e3c4..765bf174438 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/InMemoryKeyValueStorageProvider.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/InMemoryKeyValueStorageProvider.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.core; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.ethereum.bonsai.BonsaiWorldStateArchive; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.DefaultBlockchain; @@ -33,24 +34,30 @@ public class InMemoryKeyValueStorageProvider extends KeyValueStorageProvider { - public InMemoryKeyValueStorageProvider() { + public InMemoryKeyValueStorageProvider(final GenesisConfigOptions genesisConfigOptions) { super( + genesisConfigOptions, segmentIdentifier -> new InMemoryKeyValueStorage(), new InMemoryKeyValueStorage(), new InMemoryKeyValueStorage(), true); } - public static MutableBlockchain createInMemoryBlockchain(final Block genesisBlock) { - return createInMemoryBlockchain(genesisBlock, new MainnetBlockHeaderFunctions()); + public static MutableBlockchain createInMemoryBlockchain( + final GenesisConfigOptions genesisConfigOptions, final Block genesisBlock) { + return createInMemoryBlockchain( + genesisConfigOptions, genesisBlock, new MainnetBlockHeaderFunctions()); } public static MutableBlockchain createInMemoryBlockchain( - final Block genesisBlock, final BlockHeaderFunctions blockHeaderFunctions) { + final GenesisConfigOptions genesisConfigOptions, + final Block genesisBlock, + final BlockHeaderFunctions blockHeaderFunctions) { final InMemoryKeyValueStorage keyValueStorage = new InMemoryKeyValueStorage(); return DefaultBlockchain.createMutable( genesisBlock, - new KeyValueStoragePrefixedKeyBlockchainStorage(keyValueStorage, blockHeaderFunctions), + new KeyValueStoragePrefixedKeyBlockchainStorage( + keyValueStorage, blockHeaderFunctions, genesisConfigOptions), new NoOpMetricsSystem(), 0); } @@ -62,12 +69,15 @@ public static DefaultWorldStateArchive createInMemoryWorldStateArchive() { } public static BonsaiWorldStateArchive createBonsaiInMemoryWorldStateArchive( - final Blockchain blockchain) { - return new BonsaiWorldStateArchive(new InMemoryKeyValueStorageProvider(), blockchain); + final GenesisConfigOptions genesisConfigOptions, final Blockchain blockchain) { + return new BonsaiWorldStateArchive( + new InMemoryKeyValueStorageProvider(genesisConfigOptions), blockchain); } - public static MutableWorldState createInMemoryWorldState() { - final InMemoryKeyValueStorageProvider provider = new InMemoryKeyValueStorageProvider(); + public static MutableWorldState createInMemoryWorldState( + final GenesisConfigOptions genesisConfigOptions) { + final InMemoryKeyValueStorageProvider provider = + new InMemoryKeyValueStorageProvider(genesisConfigOptions); return new DefaultMutableWorldState( provider.createWorldStateStorage(DataStorageFormat.FOREST), provider.createWorldStatePreimageStorage()); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateKeyValueStorageTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateKeyValueStorageTest.java index 0224d2bbcf8..e97d8b9a9b6 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateKeyValueStorageTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateKeyValueStorageTest.java @@ -17,6 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.ethereum.bonsai.BonsaiWorldStateKeyValueStorage.WORLD_ROOT_HASH_KEY; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; @@ -193,6 +194,7 @@ public void isWorldStateAvailable_StateAvailableByRootHash() { } private BonsaiWorldStateKeyValueStorage emptyStorage() { - return new BonsaiWorldStateKeyValueStorage(new InMemoryKeyValueStorageProvider()); + return new BonsaiWorldStateKeyValueStorage( + new InMemoryKeyValueStorageProvider(new StubGenesisConfigOptions())); } } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/LogRollingTests.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/LogRollingTests.java index 5cb81456140..99105cfdd48 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/LogRollingTests.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/LogRollingTests.java @@ -19,6 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; @@ -105,7 +106,8 @@ public class LogRollingTests { @Before public void createStorage() { - final InMemoryKeyValueStorageProvider provider = new InMemoryKeyValueStorageProvider(); + final InMemoryKeyValueStorageProvider provider = + new InMemoryKeyValueStorageProvider(new StubGenesisConfigOptions()); archive = new BonsaiWorldStateArchive(provider, blockchain); accountStorage = (InMemoryKeyValueStorage) @@ -124,7 +126,8 @@ public void createStorage() { (InMemoryKeyValueStorage) provider.getStorageBySegmentIdentifier(KeyValueSegmentIdentifier.TRIE_LOG_STORAGE); - final InMemoryKeyValueStorageProvider secondProvider = new InMemoryKeyValueStorageProvider(); + final InMemoryKeyValueStorageProvider secondProvider = + new InMemoryKeyValueStorageProvider(new StubGenesisConfigOptions()); secondArchive = new BonsaiWorldStateArchive(secondProvider, blockchain); secondAccountStorage = (InMemoryKeyValueStorage) diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/RollingImport.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/RollingImport.java index a1cf2948d6a..c72c5459c9a 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/RollingImport.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/RollingImport.java @@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier; @@ -37,7 +38,8 @@ public static void main(final String[] arg) throws IOException { final RollingFileReader reader = new RollingFileReader((i, c) -> Path.of(String.format(arg[0] + "-%04d.rdat", i)), false); - final InMemoryKeyValueStorageProvider provider = new InMemoryKeyValueStorageProvider(); + final InMemoryKeyValueStorageProvider provider = + new InMemoryKeyValueStorageProvider(new StubGenesisConfigOptions()); final BonsaiWorldStateArchive archive = new BonsaiWorldStateArchive(provider, null); final InMemoryKeyValueStorage accountStorage = (InMemoryKeyValueStorage) diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchainTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchainTest.java index 7ce4c5d127f..db70988e2d9 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchainTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchainTest.java @@ -17,6 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; @@ -942,7 +943,7 @@ private void assertTotalDifficultiesAreConsistent(final Blockchain blockchain, f private BlockchainStorage createStorage(final KeyValueStorage kvStore) { return new KeyValueStoragePrefixedKeyBlockchainStorage( - kvStore, new MainnetBlockHeaderFunctions()); + kvStore, new MainnetBlockHeaderFunctions(), new StubGenesisConfigOptions()); } private DefaultBlockchain createMutableBlockchain( diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/chain/GenesisStateTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/chain/GenesisStateTest.java index 16347e80bbc..0abf9c0c9f9 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/chain/GenesisStateTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/chain/GenesisStateTest.java @@ -16,6 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.core.BlockHeader; @@ -61,7 +62,8 @@ public void createFromJsonWithAllocs() throws Exception { assertThat(header.getOmmersHash()).isEqualTo(Hash.EMPTY_LIST_HASH); assertThat(header.getExtraData()).isEqualTo(Bytes.EMPTY); assertThat(header.getParentHash()).isEqualTo(Hash.ZERO); - final MutableWorldState worldState = InMemoryKeyValueStorageProvider.createInMemoryWorldState(); + final MutableWorldState worldState = + InMemoryKeyValueStorageProvider.createInMemoryWorldState(new StubGenesisConfigOptions()); genesisState.writeStateTo(worldState); final Account first = worldState.get(Address.fromHexString("0x0000000000000000000000000000000000000001")); @@ -97,7 +99,8 @@ private void assertContractInvariants(final String sourceFile, final String bloc final BlockHeader header = genesisState.getBlock().getHeader(); assertThat(header.getHash()).isEqualTo(Hash.fromHexString(blockHash)); - final MutableWorldState worldState = InMemoryKeyValueStorageProvider.createInMemoryWorldState(); + final MutableWorldState worldState = + InMemoryKeyValueStorageProvider.createInMemoryWorldState(new StubGenesisConfigOptions()); genesisState.writeStateTo(worldState); final Account contract = worldState.get(Address.fromHexString("0x3850000000000000000000000000000000000000")); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionEIP1559Test.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionEIP1559Test.java index 2a2211b9380..3089c75ca84 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionEIP1559Test.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionEIP1559Test.java @@ -65,7 +65,9 @@ public void buildEip1559Transaction() { // final String raw = // "b8a902f8a686796f6c6f7632800285012a05f20082753094000000000000000000000000000000000000aaaa8080f838f794000000000000000000000000000000000000aaaae1a0000000000000000000000000000000000000000000000000000000000000000001a00c1d69648e348fe26155b45de45004f0e4195f6352d8f0935bc93e98a3e2a862a060064e5b9765c0ac74223b0cf49635c59ae0faf82044fd17bcc68a549ade6f95"; final String raw = out.encoded().toHexString(); - final Transaction decoded = Transaction.readFrom(RLP.input(Bytes.fromHexString(raw))); + final boolean isGoQuorumCompatible = false; + final Transaction decoded = + Transaction.readFrom(RLP.input(Bytes.fromHexString(raw)), isGoQuorumCompatible); System.out.println(decoded); System.out.println(decoded.getAccessList().orElseThrow().get(0).getAddressString()); System.out.println(decoded.getAccessList().orElseThrow().get(0).getStorageKeysString()); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionIntegrationTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionIntegrationTest.java index da914033bd5..08a5e5783e6 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionIntegrationTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionIntegrationTest.java @@ -27,6 +27,7 @@ import org.junit.Test; public class TransactionIntegrationTest { + private final boolean isGoQuorumCompatible = false; @Test public void @@ -35,7 +36,7 @@ public class TransactionIntegrationTest { "0xf902560c843b9aca00832dc6c08080b90202608060405234801561001057600080fd5b506040516020806101e283398101604052516000556101ae806100346000396000f30060806040526004361061006c5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632113522a81146100715780632a1afcd9146100af5780633bc5de30146100d657806360fe47b1146100eb578063db613e8114610105575b600080fd5b34801561007d57600080fd5b5061008661011a565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b3480156100bb57600080fd5b506100c4610136565b60408051918252519081900360200190f35b3480156100e257600080fd5b506100c461013c565b3480156100f757600080fd5b50610103600435610142565b005b34801561011157600080fd5b50610086610166565b60015473ffffffffffffffffffffffffffffffffffffffff1681565b60005481565b60005490565b6000556001805473ffffffffffffffffffffffffffffffffffffffff191633179055565b60015473ffffffffffffffffffffffffffffffffffffffff16905600a165627a7a723058208293fac83e9cc01039adf5e41eefd557d1324a3a4c830a4802fa1dd2515227a20029000000000000000000000000000000000000000000000000000000000000007b820fe8a009e7b69af4c318e7fb915f53649bd9f99e5423d41c2cd6a01ab69bb34a951b2fa01b5d39b7c9041ec022d13e6e89eec2cddbe27572eda7956ada5de1032cd5da15"; final Bytes encoded = Bytes.fromHexString(encodedString); final RLPInput input = RLP.input(encoded); - final Transaction transaction = Transaction.readFrom(input); + final Transaction transaction = Transaction.readFrom(input, isGoQuorumCompatible); assertThat(transaction).isNotNull(); assertThat(transaction.isContractCreation()).isTrue(); assertThat(transaction.getChainId()).contains(BigInteger.valueOf(2018)); @@ -49,7 +50,7 @@ public void shouldDecodeAndEncodeTransactionCorrectly() { "0xf9025780843b9aca00832dc6c08080b90202608060405234801561001057600080fd5b506040516020806101e283398101604052516000556101ae806100346000396000f30060806040526004361061006c5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632113522a81146100715780632a1afcd9146100af5780633bc5de30146100d657806360fe47b1146100eb578063db613e8114610105575b600080fd5b34801561007d57600080fd5b5061008661011a565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b3480156100bb57600080fd5b506100c4610136565b60408051918252519081900360200190f35b3480156100e257600080fd5b506100c461013c565b3480156100f757600080fd5b50610103600435610142565b005b34801561011157600080fd5b50610086610166565b60015473ffffffffffffffffffffffffffffffffffffffff1681565b60005481565b60005490565b6000556001805473ffffffffffffffffffffffffffffffffffffffff191633179055565b60015473ffffffffffffffffffffffffffffffffffffffff16905600a165627a7a723058208293fac83e9cc01039adf5e41eefd557d1324a3a4c830a4802fa1dd2515227a20029000000000000000000000000000000000000000000000000000000000000000c830628cba0482ba9b1136cd9337408938eea6b991fd153900a014867da2f4bb113d4003888a00c5a2f8f279fe2c86831afb5c9578dd1c3be457e3aca3abe439b1a5dd122e676"; final Bytes encoded = Bytes.fromHexString(encodedString); final RLPInput input = RLP.input(encoded); - final Transaction transaction = Transaction.readFrom(input); + final Transaction transaction = Transaction.readFrom(input, isGoQuorumCompatible); final BytesValueRLPOutput output = new BytesValueRLPOutput(); transaction.writeTo(output); assertThat(output.encoded().toString()).isEqualTo(encodedString); @@ -61,7 +62,7 @@ public void shouldDecodeTransactionWithLargeChainId() { "0xf86a018609184e72a0008276c094d30c3d13b07029deba00de1da369cd69a02c20560180850100000021a07d344f26d7329e8932d2878b99f07b12752bbd13a0b3b822644dbf9600fe718da01d6e6b6c66e1aadf4e33e318a7eef03d3bd3602de52662f0cb5af5b372d44dcd"; final Bytes encoded = Bytes.fromHexString(encodedString); final RLPInput input = RLP.input(encoded); - final Transaction transaction = Transaction.readFrom(input); + final Transaction transaction = Transaction.readFrom(input, isGoQuorumCompatible); assertThat(transaction).isNotNull(); assertThat(transaction.isContractCreation()).isFalse(); assertThat(transaction.getChainId()).contains(BigInteger.valueOf(2147483647)); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java index 5088edd96b3..92b28b4b9fc 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java @@ -109,7 +109,8 @@ public void milestone(final String milestone) { final Bytes rlp = spec.getRlp(); // Test transaction deserialization (will throw an exception if it fails). - final Transaction transaction = Transaction.readFrom(RLP.input(rlp)); + final boolean isGoQuorumCompatible = false; + final Transaction transaction = Transaction.readFrom(RLP.input(rlp), isGoQuorumCompatible); if (!transactionValidator(milestone) .validate(transaction, Optional.empty(), TransactionValidationParams.processingBlock()) .isValid()) { diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/TransactionDecoderTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/TransactionDecoderTest.java index 94ebd6c06b2..d64a0605786 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/TransactionDecoderTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/TransactionDecoderTest.java @@ -17,7 +17,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import org.hyperledger.besu.config.GoQuorumOptions; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.Transaction; @@ -41,22 +40,22 @@ public class TransactionDecoderTest { @Test public void decodeGoQuorumPrivateTransactionRlp() { - GoQuorumOptions.goQuorumCompatibilityMode = true; RLPInput input = RLP.input(Bytes.fromHexString(GOQUORUM_PRIVATE_TX_RLP)); - final Transaction transaction = TransactionDecoder.decodeForWire(input); + final boolean isGoQuorumCompatible = true; + final Transaction transaction = TransactionDecoder.decodeForWire(input, isGoQuorumCompatible); assertThat(transaction).isNotNull(); assertThat(transaction.getV()).isEqualTo(38); assertThat(transaction.getSender()) .isEqualByComparingTo(Address.fromHexString("0xed9d02e382b34818e88b88a309c7fe71e65f419d")); - GoQuorumOptions.goQuorumCompatibilityMode = - GoQuorumOptions.GOQUORUM_COMPATIBILITY_MODE_DEFAULT_VALUE; } @Test public void decodeFrontierNominalCase() { + final boolean isGoQuorumCompatible = false; final Transaction transaction = - TransactionDecoder.decodeForWire(RLP.input(Bytes.fromHexString(FRONTIER_TX_RLP))); + TransactionDecoder.decodeForWire( + RLP.input(Bytes.fromHexString(FRONTIER_TX_RLP)), isGoQuorumCompatible); assertThat(transaction).isNotNull(); assertThat(transaction.getGasPrice().get()).isEqualByComparingTo(Wei.of(50L)); assertThat(transaction.getMaxPriorityFeePerGas()).isEmpty(); @@ -65,8 +64,10 @@ public void decodeFrontierNominalCase() { @Test public void decodeEIP1559NominalCase() { + final boolean isGoQuorumCompatible = false; final Transaction transaction = - TransactionDecoder.decodeForWire(RLP.input(Bytes.fromHexString(EIP1559_TX_RLP))); + TransactionDecoder.decodeForWire( + RLP.input(Bytes.fromHexString(EIP1559_TX_RLP)), isGoQuorumCompatible); assertThat(transaction).isNotNull(); assertThat(transaction.getMaxPriorityFeePerGas()).hasValue(Wei.of(2L)); assertThat(transaction.getMaxFeePerGas()).hasValue(Wei.of(new BigInteger("5000000000", 10))); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/TransactionEncoderTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/TransactionEncoderTest.java index 61a4a03250b..a44a2dbae43 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/TransactionEncoderTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/TransactionEncoderTest.java @@ -45,11 +45,14 @@ public class TransactionEncoderTest { "0xf901fc8032830138808080b901ae60056013565b6101918061001d6000396000f35b3360008190555056006001600060e060020a6000350480630a874df61461003a57806341c0e1b514610058578063a02b161e14610066578063dbbdf0831461007757005b610045600435610149565b80600160a060020a031660005260206000f35b610060610161565b60006000f35b6100716004356100d4565b60006000f35b61008560043560243561008b565b60006000f35b600054600160a060020a031632600160a060020a031614156100ac576100b1565b6100d0565b8060018360005260205260406000208190555081600060005260206000a15b5050565b600054600160a060020a031633600160a060020a031614158015610118575033600160a060020a0316600182600052602052604060002054600160a060020a031614155b61012157610126565b610146565b600060018260005260205260406000208190555080600060005260206000a15b50565b60006001826000526020526040600020549050919050565b600054600160a060020a031633600160a060020a0316146101815761018f565b600054600160a060020a0316ff5b561ca0c5689ed1ad124753d54576dfb4b571465a41900a1dff4058d8adf16f752013d0a01221cbd70ec28c94a3b55ec771bcbc70778d6ee0b51ca7ea9514594c861b1884"; private static final String EIP1559_TX_RLP = "0xb8a902f8a686796f6c6f7632800285012a05f20082753094000000000000000000000000000000000000aaaa8080f838f794000000000000000000000000000000000000aaaae1a0000000000000000000000000000000000000000000000000000000000000000001a00c1d69648e348fe26155b45de45004f0e4195f6352d8f0935bc93e98a3e2a862a060064e5b9765c0ac74223b0cf49635c59ae0faf82044fd17bcc68a549ade6f95"; + private final boolean isGoQuorumCompatible = false; @Test public void encodeFrontierTxNominalCase() { + final Transaction transaction = - TransactionDecoder.decodeForWire(RLP.input(Bytes.fromHexString(FRONTIER_TX_RLP))); + TransactionDecoder.decodeForWire( + RLP.input(Bytes.fromHexString(FRONTIER_TX_RLP)), isGoQuorumCompatible); final BytesValueRLPOutput output = new BytesValueRLPOutput(); TransactionEncoder.encodeForWire(transaction, output); assertThat(FRONTIER_TX_RLP).isEqualTo(output.encoded().toHexString()); @@ -58,7 +61,8 @@ public void encodeFrontierTxNominalCase() { @Test public void encodeEIP1559TxNominalCase() { final Transaction transaction = - TransactionDecoder.decodeForWire(RLP.input(Bytes.fromHexString(EIP1559_TX_RLP))); + TransactionDecoder.decodeForWire( + RLP.input(Bytes.fromHexString(EIP1559_TX_RLP)), isGoQuorumCompatible); final BytesValueRLPOutput output = new BytesValueRLPOutput(); TransactionEncoder.encodeForWire(transaction, output); assertThat(EIP1559_TX_RLP).isEqualTo(output.encoded().toHexString()); @@ -75,7 +79,9 @@ public void blockWithLegacyAndEIP2930TransactionsRoundTrips() { assertThat( Block.readFrom( - RLP.input(RLP.encode(block::writeTo)), new MainnetBlockHeaderFunctions())) + RLP.input(RLP.encode(block::writeTo)), + new MainnetBlockHeaderFunctions(), + isGoQuorumCompatible)) .isEqualTo(block); } } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/IntrinsicGasTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/IntrinsicGasTest.java index 3b6a9445619..3c268e0e199 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/IntrinsicGasTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/IntrinsicGasTest.java @@ -111,7 +111,9 @@ public static Collection data() { @Test public void validateGasCost() { - Transaction t = Transaction.readFrom(RLP.input(Bytes.fromHexString(txRlp))); + final boolean isGoQuorumCompatible = false; + Transaction t = + Transaction.readFrom(RLP.input(Bytes.fromHexString(txRlp)), isGoQuorumCompatible); Assertions.assertThat( gasCalculator.transactionIntrinsicGasCost(t.getPayload(), t.isContractCreation())) .isEqualTo(expectedGas); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleTest.java index 9246103aef7..324626cb871 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleTest.java @@ -17,6 +17,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; +import org.hyperledger.besu.config.StubGenesisConfigOptions; + import java.math.BigInteger; import java.util.Optional; @@ -35,7 +37,8 @@ public void getByBlockNumber() { final ProtocolSpec spec3 = mock(ProtocolSpec.class); final ProtocolSpec spec4 = mock(ProtocolSpec.class); - final MutableProtocolSchedule schedule = new MutableProtocolSchedule(CHAIN_ID); + final MutableProtocolSchedule schedule = + new MutableProtocolSchedule(CHAIN_ID, new StubGenesisConfigOptions()); schedule.putMilestone(20, spec3); schedule.putMilestone(0, spec1); schedule.putMilestone(30, spec4); @@ -49,7 +52,10 @@ public void getByBlockNumber() { @Test public void emptySchedule() { - Assertions.assertThatThrownBy(() -> new MutableProtocolSchedule(CHAIN_ID).getByBlockNumber(0)) + Assertions.assertThatThrownBy( + () -> + new MutableProtocolSchedule(CHAIN_ID, new StubGenesisConfigOptions()) + .getByBlockNumber(0)) .hasMessage("At least 1 milestone must be provided to the protocol schedule"); } @@ -59,7 +65,8 @@ public void conflictingSchedules() { final ProtocolSpec spec1 = mock(ProtocolSpec.class); final ProtocolSpec spec2 = mock(ProtocolSpec.class); - final MutableProtocolSchedule protocolSchedule = new MutableProtocolSchedule(CHAIN_ID); + final MutableProtocolSchedule protocolSchedule = + new MutableProtocolSchedule(CHAIN_ID, new StubGenesisConfigOptions()); protocolSchedule.putMilestone(0, spec1); protocolSchedule.putMilestone(0, spec2); assertThat(protocolSchedule.getByBlockNumber(0)).isSameAs(spec2); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ValidationTestUtils.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ValidationTestUtils.java index 25a74a518c9..074770ee6d8 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ValidationTestUtils.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ValidationTestUtils.java @@ -49,7 +49,9 @@ public static BlockBody readBody(final long num) throws IOException { false); input.enterList(); input.skipNext(); - final List transactions = input.readList(Transaction::readFrom); + final boolean isGoQuorumCompatible = false; + final List transactions = + input.readList(rlp -> Transaction.readFrom(rlp, isGoQuorumCompatible)); final List ommers = input.readList(rlp -> BlockHeader.readFrom(rlp, new MainnetBlockHeaderFunctions())); return new BlockBody(transactions, ommers); @@ -64,7 +66,9 @@ public static Block readBlock(final long num) throws IOException { false); input.enterList(); final BlockHeader header = BlockHeader.readFrom(input, new MainnetBlockHeaderFunctions()); - final List transactions = input.readList(Transaction::readFrom); + final boolean isGoQuorumCompatible = false; + final List transactions = + input.readList(rlp -> Transaction.readFrom(rlp, isGoQuorumCompatible)); final List ommers = input.readList(rlp -> BlockHeader.readFrom(rlp, new MainnetBlockHeaderFunctions())); final BlockBody body = new BlockBody(transactions, ommers); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/PrivateStateGenesisAllocatorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/PrivateStateGenesisAllocatorTest.java index 4df561c9173..929c101432c 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/PrivateStateGenesisAllocatorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/PrivateStateGenesisAllocatorTest.java @@ -21,6 +21,7 @@ import static org.hyperledger.besu.ethereum.privacy.group.OnchainGroupManagement.DEFAULT_GROUP_MANAGEMENT_RUNTIME_BYTECODE; import static org.hyperledger.besu.ethereum.privacy.group.OnchainGroupManagement.PROXY_RUNTIME_BYTECODE; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; @@ -45,7 +46,7 @@ public class PrivateStateGenesisAllocatorTest { public static final Hash EMPTY_ROOT_HASH = Hash.wrap(MerklePatriciaTrie.EMPTY_TRIE_NODE_HASH); private final MutableWorldState worldState = - InMemoryKeyValueStorageProvider.createInMemoryWorldState(); + InMemoryKeyValueStorageProvider.createInMemoryWorldState(new StubGenesisConfigOptions()); final WorldUpdater updater = worldState.updater(); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/PrivateStateRootResolverTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/PrivateStateRootResolverTest.java index 3428d74f04c..dc995410f0c 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/PrivateStateRootResolverTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/PrivateStateRootResolverTest.java @@ -16,6 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; @@ -56,7 +57,8 @@ public class PrivateStateRootResolverTest { @BeforeClass public static void setupClass() { BLOCKCHAIN = - InMemoryKeyValueStorageProvider.createInMemoryBlockchain(BLOCK_GENERATOR.genesisBlock()); + InMemoryKeyValueStorageProvider.createInMemoryBlockchain( + new StubGenesisConfigOptions(), BLOCK_GENERATOR.genesisBlock()); for (int i = 1; i <= 69; i++) { final BlockDataGenerator.BlockOptions options = new BlockDataGenerator.BlockOptions() diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/markertransaction/FixedKeySigningPrivateMarkerTransactionFactoryTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/markertransaction/FixedKeySigningPrivateMarkerTransactionFactoryTest.java index ef13c30ae53..6b3cb66acfd 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/markertransaction/FixedKeySigningPrivateMarkerTransactionFactoryTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/markertransaction/FixedKeySigningPrivateMarkerTransactionFactoryTest.java @@ -36,6 +36,7 @@ public class FixedKeySigningPrivateMarkerTransactionFactoryTest { @Test public void createsFullyPopulatedPrivateMarkerTransactionUsingProvidedNonce() { final PrivateTransaction privTransaction = mock(PrivateTransaction.class); + final boolean isGoQuorumCompatible = false; final Wei gasPrice = Wei.of(100); final long gasLimit = 500; @@ -61,7 +62,9 @@ public void createsFullyPopulatedPrivateMarkerTransactionUsingProvidedNonce() { .build(); final Transaction transaction = - Transaction.readFrom(factory.create(unsignedPrivateMarkerTransaction, privTransaction, "")); + Transaction.readFrom( + factory.create(unsignedPrivateMarkerTransaction, privTransaction, ""), + isGoQuorumCompatible); assertThat(transaction.getNonce()).isEqualTo(providedNonce); assertThat(transaction.getGasLimit()).isEqualTo(gasLimit); @@ -73,7 +76,9 @@ public void createsFullyPopulatedPrivateMarkerTransactionUsingProvidedNonce() { assertThat(transaction.getPayload()).isEqualTo(Bytes.fromBase64String(enclaveKey)); final Transaction nextTransaction = - Transaction.readFrom(factory.create(unsignedPrivateMarkerTransaction, privTransaction, "")); + Transaction.readFrom( + factory.create(unsignedPrivateMarkerTransaction, privTransaction, ""), + isGoQuorumCompatible); assertThat(nextTransaction.getSender()).isEqualTo(transaction.getSender()); } } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/markertransaction/RandomSigningPrivateMarkerTransactionFactoryTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/markertransaction/RandomSigningPrivateMarkerTransactionFactoryTest.java index f0b1dcd50d1..43f8af50360 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/markertransaction/RandomSigningPrivateMarkerTransactionFactoryTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/markertransaction/RandomSigningPrivateMarkerTransactionFactoryTest.java @@ -34,6 +34,7 @@ public class RandomSigningPrivateMarkerTransactionFactoryTest { public void producedTransactionHasZeroNonceAndDifferentSendThanPrior() { final PrivateTransaction privTransaction = mock(PrivateTransaction.class); + final boolean isGoQuorumCompatible = false; final Wei gasPrice = Wei.of(100); final long gasLimit = 500; @@ -57,7 +58,9 @@ public void producedTransactionHasZeroNonceAndDifferentSendThanPrior() { new RandomSigningPrivateMarkerTransactionFactory(); final Transaction transaction = - Transaction.readFrom(factory.create(unsignedPrivateMarkerTransaction, privTransaction, "")); + Transaction.readFrom( + factory.create(unsignedPrivateMarkerTransaction, privTransaction, ""), + isGoQuorumCompatible); assertThat(transaction.getNonce()).isEqualTo(0); assertThat(transaction.getGasLimit()).isEqualTo(gasLimit); @@ -67,7 +70,9 @@ public void producedTransactionHasZeroNonceAndDifferentSendThanPrior() { assertThat(transaction.getPayload()).isEqualTo(Bytes.fromBase64String(enclaveKey)); final Transaction nextTransaction = - Transaction.readFrom(factory.create(unsignedPrivateMarkerTransaction, privTransaction, "")); + Transaction.readFrom( + factory.create(unsignedPrivateMarkerTransaction, privTransaction, ""), + isGoQuorumCompatible); assertThat(nextTransaction.getSender()).isNotEqualTo(transaction.getSender()); } } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/BlockchainUtilParameterizedTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/BlockchainUtilParameterizedTest.java index 742469b0840..7790c2961c7 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/BlockchainUtilParameterizedTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/BlockchainUtilParameterizedTest.java @@ -16,6 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; @@ -60,7 +61,9 @@ public BlockchainUtilParameterizedTest(final int commonAncestorHeight) { @BeforeClass public static void setupClass() { genesisBlock = blockDataGenerator.genesisBlock(); - localBlockchain = InMemoryKeyValueStorageProvider.createInMemoryBlockchain(genesisBlock); + localBlockchain = + InMemoryKeyValueStorageProvider.createInMemoryBlockchain( + new StubGenesisConfigOptions(), genesisBlock); // Setup local chain. for (int i = 1; i <= chainHeight; i++) { final BlockDataGenerator.BlockOptions options = @@ -75,7 +78,9 @@ public static void setupClass() { @Before public void setup() { - remoteBlockchain = InMemoryKeyValueStorageProvider.createInMemoryBlockchain(genesisBlock); + remoteBlockchain = + InMemoryKeyValueStorageProvider.createInMemoryBlockchain( + new StubGenesisConfigOptions(), genesisBlock); commonHeader = genesisBlock.getHeader(); for (long i = 1; i <= commonAncestorHeight; i++) { diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/RawBlockIteratorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/RawBlockIteratorTest.java index 8461d7c120a..4523c2fa329 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/RawBlockIteratorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/RawBlockIteratorTest.java @@ -16,6 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; @@ -84,6 +85,7 @@ public void readsBlocksWithInitialCapacity( new RawBlockIterator( blocksFile.toPath(), rlp -> BlockHeader.readFrom(rlp, new MainnetBlockHeaderFunctions()), + new StubGenesisConfigOptions(), initialCapacity); // Read blocks and check that they match diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/VMReferenceTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/VMReferenceTest.java index fdfcabb74a3..bf19a89833b 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/VMReferenceTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/VMReferenceTest.java @@ -17,6 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assume.assumeTrue; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.PrivacyParameters; @@ -102,7 +103,7 @@ protected void runTest() { .privacyParameters(PrivacyParameters.DEFAULT) .privateTransactionValidatorBuilder(() -> new PrivateTransactionValidator(CHAIN_ID)) .badBlocksManager(new BadBlockManager()) - .build(new MutableProtocolSchedule(CHAIN_ID)); + .build(new MutableProtocolSchedule(CHAIN_ID, new StubGenesisConfigOptions())); final ReferenceTestBlockchain blockchain = new ReferenceTestBlockchain(execEnv.getBlockHeader().getNumber()); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/DefaultMutableWorldStateTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/DefaultMutableWorldStateTest.java index 5745d24226e..0a6bbed54f5 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/DefaultMutableWorldStateTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/DefaultMutableWorldStateTest.java @@ -17,6 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldState; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; @@ -60,7 +61,7 @@ private static MutableWorldState createEmpty(final WorldStateKeyValueStorage sto } private static MutableWorldState createEmpty() { - return createInMemoryWorldState(); + return createInMemoryWorldState(new StubGenesisConfigOptions()); } @Test diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/MarkSweepPrunerTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/MarkSweepPrunerTest.java index e3ef5f43efd..094baa96c23 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/MarkSweepPrunerTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/MarkSweepPrunerTest.java @@ -20,6 +20,7 @@ import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.spy; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; @@ -64,7 +65,8 @@ public class MarkSweepPrunerTest { worldStateStorage, new WorldStatePreimageKeyValueStorage(new InMemoryKeyValueStorage())); private final InMemoryKeyValueStorage markStorage = new InMemoryKeyValueStorage(); private final Block genesisBlock = gen.genesisBlock(); - private final MutableBlockchain blockchain = createInMemoryBlockchain(genesisBlock); + private final MutableBlockchain blockchain = + createInMemoryBlockchain(new StubGenesisConfigOptions(), genesisBlock); @Test public void mark_marksAllExpectedNodes() { diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/PrunerTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/PrunerTest.java index dfaef9fae1d..75af66e279f 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/PrunerTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/PrunerTest.java @@ -20,6 +20,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.BlockchainStorage; @@ -60,7 +61,9 @@ public class PrunerTest { public void shouldMarkCorrectBlockAndSweep() throws ExecutionException, InterruptedException { final BlockchainStorage blockchainStorage = new KeyValueStoragePrefixedKeyBlockchainStorage( - new InMemoryKeyValueStorage(), new MainnetBlockHeaderFunctions()); + new InMemoryKeyValueStorage(), + new MainnetBlockHeaderFunctions(), + new StubGenesisConfigOptions()); final MutableBlockchain blockchain = DefaultBlockchain.createMutable(genesisBlock, blockchainStorage, metricsSystem, 0); @@ -81,7 +84,9 @@ public void shouldMarkCorrectBlockAndSweep() throws ExecutionException, Interrup public void shouldOnlySweepAfterBlockConfirmationPeriodAndRetentionPeriodEnds() { final BlockchainStorage blockchainStorage = new KeyValueStoragePrefixedKeyBlockchainStorage( - new InMemoryKeyValueStorage(), new MainnetBlockHeaderFunctions()); + new InMemoryKeyValueStorage(), + new MainnetBlockHeaderFunctions(), + new StubGenesisConfigOptions()); final MutableBlockchain blockchain = DefaultBlockchain.createMutable(genesisBlock, blockchainStorage, metricsSystem, 0); @@ -107,7 +112,9 @@ public void shouldOnlySweepAfterBlockConfirmationPeriodAndRetentionPeriodEnds() public void abortsPruningWhenFullyMarkedBlockNoLongerOnCanonicalChain() { final BlockchainStorage blockchainStorage = new KeyValueStoragePrefixedKeyBlockchainStorage( - new InMemoryKeyValueStorage(), new MainnetBlockHeaderFunctions()); + new InMemoryKeyValueStorage(), + new MainnetBlockHeaderFunctions(), + new StubGenesisConfigOptions()); final MutableBlockchain blockchain = DefaultBlockchain.createMutable(genesisBlock, blockchainStorage, metricsSystem, 0); @@ -177,7 +184,9 @@ public void shouldRejectInvalidArguments() { public void shouldCleanUpPruningStrategyOnShutdown() throws InterruptedException { final BlockchainStorage blockchainStorage = new KeyValueStoragePrefixedKeyBlockchainStorage( - new InMemoryKeyValueStorage(), new MainnetBlockHeaderFunctions()); + new InMemoryKeyValueStorage(), + new MainnetBlockHeaderFunctions(), + new StubGenesisConfigOptions()); final MutableBlockchain blockchain = DefaultBlockchain.createMutable(genesisBlock, blockchainStorage, metricsSystem, 0); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java index 313b470c8c7..2a6b0cba221 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java @@ -16,6 +16,7 @@ import static com.google.common.base.Preconditions.checkArgument; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.MinedBlockObserver; @@ -78,6 +79,7 @@ public EthProtocolManager( final WorldStateArchive worldStateArchive, final TransactionPool transactionPool, final EthProtocolConfiguration ethereumWireProtocolConfiguration, + final GenesisConfigOptions genesisConfigOptions, final EthPeers ethPeers, final EthMessages ethMessages, final EthContext ethContext, @@ -99,7 +101,7 @@ public EthProtocolManager( this.ethMessages = ethMessages; this.ethContext = ethContext; - this.blockBroadcaster = new BlockBroadcaster(ethContext); + this.blockBroadcaster = new BlockBroadcaster(ethContext, genesisConfigOptions); supportedCapabilities = calculateCapabilities(fastSyncEnabled); @@ -114,7 +116,8 @@ public EthProtocolManager( worldStateArchive, transactionPool, ethMessages, - ethereumWireProtocolConfiguration); + ethereumWireProtocolConfiguration, + genesisConfigOptions); } @VisibleForTesting @@ -124,6 +127,7 @@ public EthProtocolManager( final WorldStateArchive worldStateArchive, final TransactionPool transactionPool, final EthProtocolConfiguration ethereumWireProtocolConfiguration, + final GenesisConfigOptions genesisConfigOptions, final EthPeers ethPeers, final EthMessages ethMessages, final EthContext ethContext, @@ -136,6 +140,7 @@ public EthProtocolManager( worldStateArchive, transactionPool, ethereumWireProtocolConfiguration, + genesisConfigOptions, ethPeers, ethMessages, ethContext, @@ -154,6 +159,7 @@ public EthProtocolManager( final WorldStateArchive worldStateArchive, final TransactionPool transactionPool, final EthProtocolConfiguration ethereumWireProtocolConfiguration, + final GenesisConfigOptions genesisConfigOptions, final EthPeers ethPeers, final EthMessages ethMessages, final EthContext ethContext, @@ -167,6 +173,7 @@ public EthProtocolManager( worldStateArchive, transactionPool, ethereumWireProtocolConfiguration, + genesisConfigOptions, ethPeers, ethMessages, ethContext, diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthServer.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthServer.java index 8857a08477e..2e4577c6636 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthServer.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthServer.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.eth.manager; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockBody; @@ -53,61 +54,45 @@ class EthServer { private final TransactionPool transactionPool; private final EthMessages ethMessages; private final EthProtocolConfiguration ethereumWireProtocolConfiguration; + private final GenesisConfigOptions genesisConfigOptions; EthServer( final Blockchain blockchain, final WorldStateArchive worldStateArchive, final TransactionPool transactionPool, final EthMessages ethMessages, - final EthProtocolConfiguration ethereumWireProtocolConfiguration) { + final EthProtocolConfiguration ethereumWireProtocolConfiguration, + final GenesisConfigOptions genesisConfigOptions) { this.blockchain = blockchain; this.worldStateArchive = worldStateArchive; this.transactionPool = transactionPool; this.ethMessages = ethMessages; this.ethereumWireProtocolConfiguration = ethereumWireProtocolConfiguration; - this.registerResponseConstructors(); + this.genesisConfigOptions = genesisConfigOptions; + registerResponseConstructors(); } private void registerResponseConstructors() { ethMessages.registerResponseConstructor( - EthPV62.GET_BLOCK_HEADERS, - messageData -> - constructGetHeadersResponse( - blockchain, - messageData, - ethereumWireProtocolConfiguration.getMaxGetBlockHeaders())); + EthPV62.GET_BLOCK_HEADERS, messageData -> constructGetHeadersResponse(messageData)); ethMessages.registerResponseConstructor( - EthPV62.GET_BLOCK_BODIES, - messageData -> - constructGetBodiesResponse( - blockchain, messageData, ethereumWireProtocolConfiguration.getMaxGetBlockBodies())); + EthPV62.GET_BLOCK_BODIES, messageData -> constructGetBodiesResponse(messageData)); ethMessages.registerResponseConstructor( - EthPV63.GET_RECEIPTS, - messageData -> - constructGetReceiptsResponse( - blockchain, messageData, ethereumWireProtocolConfiguration.getMaxGetReceipts())); + EthPV63.GET_RECEIPTS, messageData -> constructGetReceiptsResponse(messageData)); ethMessages.registerResponseConstructor( - EthPV63.GET_NODE_DATA, - messageData -> - constructGetNodeDataResponse( - worldStateArchive, - messageData, - ethereumWireProtocolConfiguration.getMaxGetNodeData())); + EthPV63.GET_NODE_DATA, messageData -> constructGetNodeDataResponse(messageData)); ethMessages.registerResponseConstructor( EthPV65.GET_POOLED_TRANSACTIONS, - messageData -> - constructGetPooledTransactionsResponse( - transactionPool, - messageData, - ethereumWireProtocolConfiguration.getMaxGetPooledTransactions())); + messageData -> constructGetPooledTransactionsResponse(messageData)); } - static MessageData constructGetHeadersResponse( - final Blockchain blockchain, final MessageData message, final int requestLimit) { + private MessageData constructGetHeadersResponse(final MessageData message) { final GetBlockHeadersMessage getHeaders = GetBlockHeadersMessage.readFrom(message); final Optional hash = getHeaders.hash(); final int skip = getHeaders.skip(); - final int maxHeaders = Math.min(requestLimit, getHeaders.maxHeaders()); + final int maxHeaders = + Math.min( + ethereumWireProtocolConfiguration.getMaxGetBlockHeaders(), getHeaders.maxHeaders()); final boolean reversed = getHeaders.reverse(); final BlockHeader firstHeader; if (hash.isPresent()) { @@ -139,13 +124,13 @@ static MessageData constructGetHeadersResponse( return BlockHeadersMessage.create(resp); } - static MessageData constructGetBodiesResponse( - final Blockchain blockchain, final MessageData message, final int requestLimit) { + private MessageData constructGetBodiesResponse(final MessageData message) { final GetBlockBodiesMessage getBlockBodiesMessage = GetBlockBodiesMessage.readFrom(message); final Iterable hashes = getBlockBodiesMessage.hashes(); final Collection bodies = new ArrayList<>(); int count = 0; + int requestLimit = ethereumWireProtocolConfiguration.getMaxGetBlockBodies(); for (final Hash hash : hashes) { if (count >= requestLimit) { break; @@ -157,16 +142,16 @@ static MessageData constructGetBodiesResponse( } bodies.add(maybeBody.get()); } - return BlockBodiesMessage.create(bodies); + return BlockBodiesMessage.create(bodies, genesisConfigOptions.isQuorum()); } - static MessageData constructGetReceiptsResponse( - final Blockchain blockchain, final MessageData message, final int requestLimit) { + private MessageData constructGetReceiptsResponse(final MessageData message) { final GetReceiptsMessage getReceipts = GetReceiptsMessage.readFrom(message); final Iterable hashes = getReceipts.hashes(); final List> receipts = new ArrayList<>(); int count = 0; + int requestLimit = ethereumWireProtocolConfiguration.getMaxGetReceipts(); for (final Hash hash : hashes) { if (count >= requestLimit) { break; @@ -181,14 +166,14 @@ static MessageData constructGetReceiptsResponse( return ReceiptsMessage.create(receipts); } - static MessageData constructGetPooledTransactionsResponse( - final TransactionPool transactionPool, final MessageData message, final int requestLimit) { + private MessageData constructGetPooledTransactionsResponse(final MessageData message) { final GetPooledTransactionsMessage getPooledTransactions = GetPooledTransactionsMessage.readFrom(message); final Iterable hashes = getPooledTransactions.pooledTransactions(); final List tx = new ArrayList<>(); int count = 0; + int requestLimit = ethereumWireProtocolConfiguration.getMaxGetPooledTransactions(); for (final Hash hash : hashes) { if (count >= requestLimit) { break; @@ -200,18 +185,16 @@ static MessageData constructGetPooledTransactionsResponse( } tx.add(maybeTx.get()); } - return PooledTransactionsMessage.create(tx); + return PooledTransactionsMessage.create(tx, genesisConfigOptions.isQuorum()); } - static MessageData constructGetNodeDataResponse( - final WorldStateArchive worldStateArchive, - final MessageData message, - final int requestLimit) { + private MessageData constructGetNodeDataResponse(final MessageData message) { final GetNodeDataMessage getNodeDataMessage = GetNodeDataMessage.readFrom(message); final Iterable hashes = getNodeDataMessage.hashes(); final List nodeData = new ArrayList<>(); int count = 0; + int requestLimit = ethereumWireProtocolConfiguration.getMaxGetNodeData(); for (final Hash hash : hashes) { if (count >= requestLimit) { break; diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/BufferedGetPooledTransactionsFromPeerFetcher.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/BufferedGetPooledTransactionsFromPeerFetcher.java index 31329ed0404..736a47da9d8 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/BufferedGetPooledTransactionsFromPeerFetcher.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/BufferedGetPooledTransactionsFromPeerFetcher.java @@ -19,6 +19,7 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.eth.manager.EthPeer; import org.hyperledger.besu.ethereum.eth.transactions.PendingTransactionsMessageProcessor; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import java.util.ArrayList; import java.util.List; @@ -35,12 +36,16 @@ public class BufferedGetPooledTransactionsFromPeerFetcher { private final EthPeer peer; private final PendingTransactionsMessageProcessor processor; private final Queue txAnnounces; + private final ProtocolSchedule protocolSchedule; public BufferedGetPooledTransactionsFromPeerFetcher( - final EthPeer peer, final PendingTransactionsMessageProcessor processor) { + final ProtocolSchedule protocolSchedule, + final EthPeer peer, + final PendingTransactionsMessageProcessor processor) { this.peer = peer; this.processor = processor; this.txAnnounces = Queues.synchronizedQueue(EvictingQueue.create(MAX_PENDING_TRANSACTIONS)); + this.protocolSchedule = protocolSchedule; } public void requestTransactions() { @@ -49,7 +54,10 @@ public void requestTransactions() { txAnnounces = getTxAnnounces()) { final GetPooledTransactionsFromPeerTask task = GetPooledTransactionsFromPeerTask.forHashes( - processor.getEthContext(), txAnnounces, processor.getMetricsSystem()); + protocolSchedule, + processor.getEthContext(), + txAnnounces, + processor.getMetricsSystem()); task.assignPeer(peer); processor .getEthContext() diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBodiesFromPeerTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBodiesFromPeerTask.java index 2b8c02c627d..1241ecce2e4 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBodiesFromPeerTask.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBodiesFromPeerTask.java @@ -102,7 +102,9 @@ protected Optional> processResponse( return Optional.of(Collections.emptyList()); } - final BlockBodiesMessage bodiesMessage = BlockBodiesMessage.readFrom(message); + final boolean isQuorumCompatibilityMode = protocolSchedule.getGenesisConfigOptions().isQuorum(); + final BlockBodiesMessage bodiesMessage = + BlockBodiesMessage.readFrom(message, isQuorumCompatibilityMode); final List bodies = bodiesMessage.bodies(protocolSchedule); if (bodies.size() == 0) { // Message contains no data - nothing to do diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetPooledTransactionsFromPeerTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetPooledTransactionsFromPeerTask.java index 753da275979..d7079f174bb 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetPooledTransactionsFromPeerTask.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetPooledTransactionsFromPeerTask.java @@ -23,6 +23,7 @@ import org.hyperledger.besu.ethereum.eth.manager.PendingPeerRequest; import org.hyperledger.besu.ethereum.eth.messages.EthPV65; import org.hyperledger.besu.ethereum.eth.messages.PooledTransactionsMessage; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; import org.hyperledger.besu.plugin.services.MetricsSystem; @@ -38,16 +39,25 @@ public class GetPooledTransactionsFromPeerTask extends AbstractPeerRequestTask hashes; + private final ProtocolSchedule protocolSchedule; private GetPooledTransactionsFromPeerTask( - final EthContext ethContext, final List hashes, final MetricsSystem metricsSystem) { + final ProtocolSchedule protocolSchedule, + final EthContext ethContext, + final List hashes, + final MetricsSystem metricsSystem) { super(ethContext, EthPV65.GET_POOLED_TRANSACTIONS, metricsSystem); this.hashes = new ArrayList<>(hashes); + this.protocolSchedule = protocolSchedule; } public static GetPooledTransactionsFromPeerTask forHashes( - final EthContext ethContext, final List hashes, final MetricsSystem metricsSystem) { - return new GetPooledTransactionsFromPeerTask(ethContext, hashes, metricsSystem); + final ProtocolSchedule protocolSchedule, + final EthContext ethContext, + final List hashes, + final MetricsSystem metricsSystem) { + return new GetPooledTransactionsFromPeerTask( + protocolSchedule, ethContext, hashes, metricsSystem); } @Override @@ -68,8 +78,9 @@ protected Optional> processResponse( // the data we're requesting. return Optional.of(emptyList()); } + final boolean isQuorumCompatibilityMode = protocolSchedule.getGenesisConfigOptions().isQuorum(); final PooledTransactionsMessage pooledTransactionsMessage = - PooledTransactionsMessage.readFrom(message); + PooledTransactionsMessage.readFrom(message, isQuorumCompatibilityMode); final List tx = pooledTransactionsMessage.transactions(); if (tx.size() > hashes.size()) { // Can't be the response to our request diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/BlockBodiesMessage.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/BlockBodiesMessage.java index 8d4dd31ec73..052b9f0d797 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/BlockBodiesMessage.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/BlockBodiesMessage.java @@ -29,7 +29,10 @@ public final class BlockBodiesMessage extends AbstractMessageData { - public static BlockBodiesMessage readFrom(final MessageData message) { + private final boolean goQuorumCompatibilityMode; + + public static BlockBodiesMessage readFrom( + final MessageData message, final boolean goQuorumCompatibilityMode) { if (message instanceof BlockBodiesMessage) { return (BlockBodiesMessage) message; } @@ -38,17 +41,19 @@ public static BlockBodiesMessage readFrom(final MessageData message) { throw new IllegalArgumentException( String.format("Message has code %d and thus is not a BlockBodiesMessage.", code)); } - return new BlockBodiesMessage(message.getData()); + return new BlockBodiesMessage(message.getData(), goQuorumCompatibilityMode); } - public static BlockBodiesMessage create(final Iterable bodies) { + public static BlockBodiesMessage create( + final Iterable bodies, final boolean goQuorumCompatibilityMode) { final BytesValueRLPOutput tmp = new BytesValueRLPOutput(); tmp.writeList(bodies, BlockBody::writeTo); - return new BlockBodiesMessage(tmp.encoded()); + return new BlockBodiesMessage(tmp.encoded(), goQuorumCompatibilityMode); } - private BlockBodiesMessage(final Bytes data) { + private BlockBodiesMessage(final Bytes data, final boolean goQuorumCompatibilityMode) { super(data); + this.goQuorumCompatibilityMode = goQuorumCompatibilityMode; } @Override @@ -60,6 +65,6 @@ public List bodies(final ProtocolSchedule protocolSchedule) { final BlockHeaderFunctions blockHeaderFunctions = ScheduleBasedBlockHeaderFunctions.create(protocolSchedule); return new BytesValueRLPInput(data, false) - .readList(rlp -> BlockBody.readFrom(rlp, blockHeaderFunctions)); + .readList(rlp -> BlockBody.readFrom(rlp, blockHeaderFunctions, goQuorumCompatibilityMode)); } } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/LimitedTransactionsMessages.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/LimitedTransactionsMessages.java index 7136a60ad26..73623c4960e 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/LimitedTransactionsMessages.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/LimitedTransactionsMessages.java @@ -36,7 +36,7 @@ public LimitedTransactionsMessages( } public static LimitedTransactionsMessages createLimited( - final Iterable transactions) { + final Iterable transactions, final boolean goQuorumCompatibilityMode) { final Set includedTransactions = new HashSet<>(); final BytesValueRLPOutput message = new BytesValueRLPOutput(); int messageSize = 0; @@ -56,7 +56,8 @@ public static LimitedTransactionsMessages createLimited( } message.endList(); return new LimitedTransactionsMessages( - new TransactionsMessage(message.encoded()), includedTransactions); + new TransactionsMessage(message.encoded(), goQuorumCompatibilityMode), + includedTransactions); } public final TransactionsMessage getTransactionsMessage() { diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/NewBlockMessage.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/NewBlockMessage.java index 9227e574136..3c15c3ea451 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/NewBlockMessage.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/NewBlockMessage.java @@ -34,9 +34,11 @@ public class NewBlockMessage extends AbstractMessageData { private static final int MESSAGE_CODE = EthPV62.NEW_BLOCK; private NewBlockMessageData messageFields = null; + private final boolean goQuorumCompatibilityMode; - private NewBlockMessage(final Bytes data) { + private NewBlockMessage(final Bytes data, final boolean goQuorumCompatibilityMode) { super(data); + this.goQuorumCompatibilityMode = goQuorumCompatibilityMode; } @Override @@ -44,14 +46,18 @@ public int getCode() { return MESSAGE_CODE; } - public static NewBlockMessage create(final Block block, final Difficulty totalDifficulty) { + public static NewBlockMessage create( + final Block block, + final Difficulty totalDifficulty, + final boolean goQuorumCompatibilityMode) { final NewBlockMessageData msgData = new NewBlockMessageData(block, totalDifficulty); final BytesValueRLPOutput out = new BytesValueRLPOutput(); msgData.writeTo(out); - return new NewBlockMessage(out.encoded()); + return new NewBlockMessage(out.encoded(), goQuorumCompatibilityMode); } - public static NewBlockMessage readFrom(final MessageData message) { + public static NewBlockMessage readFrom( + final MessageData message, final boolean goQuorumCompatibilityMode) { if (message instanceof NewBlockMessage) { return (NewBlockMessage) message; } @@ -60,7 +66,7 @@ public static NewBlockMessage readFrom(final MessageData message) { throw new IllegalArgumentException( String.format("Message has code %d and thus is not a NewBlockMessage.", code)); } - return new NewBlockMessage(message.getData()); + return new NewBlockMessage(message.getData(), goQuorumCompatibilityMode); } public Block block(final ProtocolSchedule protocolSchedule) { @@ -74,7 +80,8 @@ public Difficulty totalDifficulty(final ProtocolSchedule protocolSchedule) { private NewBlockMessageData messageFields(final ProtocolSchedule protocolSchedule) { if (messageFields == null) { final RLPInput input = RLP.input(data); - messageFields = NewBlockMessageData.readFrom(input, protocolSchedule); + messageFields = + NewBlockMessageData.readFrom(input, protocolSchedule, goQuorumCompatibilityMode); } return messageFields; } @@ -105,11 +112,13 @@ public void writeTo(final RLPOutput out) { } public static NewBlockMessageData readFrom( - final RLPInput in, final ProtocolSchedule protocolSchedule) { + final RLPInput in, + final ProtocolSchedule protocolSchedule, + final boolean goQuorumCompatibilityMode) { final BlockHeaderFunctions blockHeaderFunctions = ScheduleBasedBlockHeaderFunctions.create(protocolSchedule); in.enterList(); - final Block block = Block.readFrom(in, blockHeaderFunctions); + final Block block = Block.readFrom(in, blockHeaderFunctions, goQuorumCompatibilityMode); final UInt256 totaldifficulty = in.readUInt256Scalar(); return new NewBlockMessageData(block, Difficulty.of(totaldifficulty)); } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/PooledTransactionsMessage.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/PooledTransactionsMessage.java index d89c12e7189..67696b3dfed 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/PooledTransactionsMessage.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/PooledTransactionsMessage.java @@ -26,11 +26,13 @@ public final class PooledTransactionsMessage extends AbstractMessageData { + private final boolean goQuorumCompatibilityMode; private static final int MESSAGE_CODE = EthPV65.POOLED_TRANSACTIONS; private List pooledTransactions; - private PooledTransactionsMessage(final Bytes rlp) { + private PooledTransactionsMessage(final Bytes rlp, final boolean goQuorumCompatibilityMode) { super(rlp); + this.goQuorumCompatibilityMode = goQuorumCompatibilityMode; } @Override @@ -38,14 +40,16 @@ public int getCode() { return MESSAGE_CODE; } - public static PooledTransactionsMessage create(final List transactions) { + public static PooledTransactionsMessage create( + final List transactions, final boolean goQuorumCompatibilityMode) { List tx = transactions; final BytesValueRLPOutput out = new BytesValueRLPOutput(); out.writeList(tx, Transaction::writeTo); - return new PooledTransactionsMessage(out.encoded()); + return new PooledTransactionsMessage(out.encoded(), goQuorumCompatibilityMode); } - public static PooledTransactionsMessage readFrom(final MessageData message) { + public static PooledTransactionsMessage readFrom( + final MessageData message, final boolean goQuorumCompatibilityMode) { if (message instanceof PooledTransactionsMessage) { return (PooledTransactionsMessage) message; } @@ -55,13 +59,13 @@ public static PooledTransactionsMessage readFrom(final MessageData message) { String.format("Message has code %d and thus is not a PooledTransactionsMessage.", code)); } - return new PooledTransactionsMessage(message.getData()); + return new PooledTransactionsMessage(message.getData(), goQuorumCompatibilityMode); } public List transactions() { if (pooledTransactions == null) { final BytesValueRLPInput in = new BytesValueRLPInput(getData(), false); - pooledTransactions = in.readList(Transaction::readFrom); + pooledTransactions = in.readList(rlp -> Transaction.readFrom(rlp, goQuorumCompatibilityMode)); } return pooledTransactions; } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/TransactionsMessage.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/TransactionsMessage.java index 2865551a10d..52a85662941 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/TransactionsMessage.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/TransactionsMessage.java @@ -26,7 +26,10 @@ public class TransactionsMessage extends AbstractMessageData { - public static TransactionsMessage readFrom(final MessageData message) { + private final boolean goQuorumCompatibilityMode; + + public static TransactionsMessage readFrom( + final MessageData message, final boolean goQuorumCompatibilityMode) { if (message instanceof TransactionsMessage) { return (TransactionsMessage) message; } @@ -35,21 +38,23 @@ public static TransactionsMessage readFrom(final MessageData message) { throw new IllegalArgumentException( String.format("Message has code %d and thus is not a TransactionsMessage.", code)); } - return new TransactionsMessage(message.getData()); + return new TransactionsMessage(message.getData(), goQuorumCompatibilityMode); } - public static TransactionsMessage create(final Iterable transactions) { + public static TransactionsMessage create( + final Iterable transactions, final boolean goQuorumCompatibilityMode) { final BytesValueRLPOutput tmp = new BytesValueRLPOutput(); tmp.startList(); for (final Transaction transaction : transactions) { transaction.writeTo(tmp); } tmp.endList(); - return new TransactionsMessage(tmp.encoded()); + return new TransactionsMessage(tmp.encoded(), goQuorumCompatibilityMode); } - TransactionsMessage(final Bytes data) { + TransactionsMessage(final Bytes data, final boolean goQuorumCompatibilityMode) { super(data); + this.goQuorumCompatibilityMode = goQuorumCompatibilityMode; } @Override @@ -58,6 +63,7 @@ public int getCode() { } public List transactions() { - return new BytesValueRLPInput(data, false).readList(Transaction::readFrom); + return new BytesValueRLPInput(data, false) + .readList(rlp -> Transaction.readFrom(rlp, goQuorumCompatibilityMode)); } } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockBroadcaster.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockBroadcaster.java index 75b96ed7ea1..88ce38bb748 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockBroadcaster.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockBroadcaster.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.eth.sync; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.eth.manager.EthContext; @@ -28,11 +29,14 @@ public class BlockBroadcaster { private static final Logger LOG = LogManager.getLogger(); private final EthContext ethContext; + private final GenesisConfigOptions genesisConfigOptions; private final Subscribers blockPropagatedSubscribers = Subscribers.create(); - public BlockBroadcaster(final EthContext ethContext) { + public BlockBroadcaster( + final EthContext ethContext, final GenesisConfigOptions genesisConfigOptions) { this.ethContext = ethContext; + this.genesisConfigOptions = genesisConfigOptions; } public long subscribePropagateNewBlocks(final BlockPropagatedSubscriber callback) { @@ -45,7 +49,8 @@ public void unsubscribePropagateNewBlocks(final long id) { public void propagate(final Block block, final Difficulty totalDifficulty) { blockPropagatedSubscribers.forEach(listener -> listener.accept(block, totalDifficulty)); - final NewBlockMessage newBlockMessage = NewBlockMessage.create(block, totalDifficulty); + final NewBlockMessage newBlockMessage = + NewBlockMessage.create(block, totalDifficulty, genesisConfigOptions.isQuorum()); ethContext .getEthPeers() .streamAvailablePeers() diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockPropagationManager.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockPropagationManager.java index 16af5952d32..23e75418030 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockPropagationManager.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockPropagationManager.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.eth.sync; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.BadBlockManager; @@ -71,6 +72,7 @@ public class BlockPropagationManager { private final SyncState syncState; private final MetricsSystem metricsSystem; private final BlockBroadcaster blockBroadcaster; + private final boolean goQuorumCompatibilityMode; private final AtomicBoolean started = new AtomicBoolean(false); @@ -86,7 +88,8 @@ public class BlockPropagationManager { final SyncState syncState, final PendingBlocksManager pendingBlocksManager, final MetricsSystem metricsSystem, - final BlockBroadcaster blockBroadcaster) { + final BlockBroadcaster blockBroadcaster, + final GenesisConfigOptions genesisConfigOptions) { this.config = config; this.protocolSchedule = protocolSchedule; this.protocolContext = protocolContext; @@ -95,6 +98,7 @@ public class BlockPropagationManager { this.blockBroadcaster = blockBroadcaster; this.syncState = syncState; this.pendingBlocksManager = pendingBlocksManager; + this.goQuorumCompatibilityMode = genesisConfigOptions.isQuorum(); } public void start() { @@ -182,7 +186,8 @@ private void onBlockAdded(final BlockAddedEvent blockAddedEvent) { private void handleNewBlockFromNetwork(final EthMessage message) { final Blockchain blockchain = protocolContext.getBlockchain(); - final NewBlockMessage newBlockMessage = NewBlockMessage.readFrom(message.getData()); + final NewBlockMessage newBlockMessage = + NewBlockMessage.readFrom(message.getData(), goQuorumCompatibilityMode); try { final Block block = newBlockMessage.block(protocolSchedule); final Difficulty totalDifficulty = newBlockMessage.totalDifficulty(protocolSchedule); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java index 553e08e6972..b7686086926 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java @@ -16,6 +16,7 @@ import static com.google.common.base.Preconditions.checkNotNull; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.manager.EthContext; @@ -66,7 +67,8 @@ public DefaultSynchronizer( final SyncState syncState, final Path dataDirectory, final Clock clock, - final MetricsSystem metricsSystem) { + final MetricsSystem metricsSystem, + final GenesisConfigOptions genesisConfigOptions) { this.maybePruner = maybePruner; this.syncState = syncState; @@ -87,7 +89,8 @@ public DefaultSynchronizer( syncState, new PendingBlocksManager(syncConfig), metricsSystem, - blockBroadcaster); + blockBroadcaster, + genesisConfigOptions); this.fullSyncDownloader = new FullSyncDownloader( diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/PendingTransactionsMessageProcessor.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/PendingTransactionsMessageProcessor.java index e4b75e97153..ba714cce553 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/PendingTransactionsMessageProcessor.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/PendingTransactionsMessageProcessor.java @@ -23,6 +23,7 @@ import org.hyperledger.besu.ethereum.eth.manager.task.BufferedGetPooledTransactionsFromPeerFetcher; import org.hyperledger.besu.ethereum.eth.messages.NewPooledTransactionHashesMessage; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason; import org.hyperledger.besu.ethereum.rlp.RLPException; import org.hyperledger.besu.metrics.RunnableCounter; @@ -49,6 +50,7 @@ public class PendingTransactionsMessageProcessor { private final Counter totalSkippedTransactionsMessageCounter; private final TransactionPool transactionPool; private final TransactionPoolConfiguration transactionPoolConfiguration; + private final ProtocolSchedule protocolSchedule; private final EthContext ethContext; private final MetricsSystem metricsSystem; private final SyncState syncState; @@ -58,6 +60,7 @@ public PendingTransactionsMessageProcessor( final TransactionPool transactionPool, final TransactionPoolConfiguration transactionPoolConfiguration, final Counter metricsCounter, + final ProtocolSchedule protocolSchedule, final EthContext ethContext, final MetricsSystem metricsSystem, final SyncState syncState) { @@ -76,6 +79,7 @@ public PendingTransactionsMessageProcessor( SKIPPED_MESSAGES_LOGGING_THRESHOLD), SKIPPED_MESSAGES_LOGGING_THRESHOLD); this.scheduledTasks = new ConcurrentHashMap<>(); + this.protocolSchedule = protocolSchedule; } void processNewPooledTransactionHashesMessage( @@ -109,7 +113,8 @@ private void processNewPooledTransactionHashesMessage( .scheduleFutureTask( new FetcherCreatorTask(peer), transactionPoolConfiguration.getEth65TrxAnnouncedBufferingPeriod()); - return new BufferedGetPooledTransactionsFromPeerFetcher(peer, this); + return new BufferedGetPooledTransactionsFromPeerFetcher( + protocolSchedule, peer, this); }); for (final Hash hash : transactionsMessage.pendingTransactions()) { diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactory.java index 9a619f4a0e9..236fd9c9d0c 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactory.java @@ -49,7 +49,7 @@ public static TransactionPool createTransactionPool( final PeerTransactionTracker transactionTracker = new PeerTransactionTracker(); final TransactionsMessageSender transactionsMessageSender = - new TransactionsMessageSender(transactionTracker); + new TransactionsMessageSender(protocolSchedule, transactionTracker); final PeerPendingTransactionTracker pendingTransactionTracker = new PeerPendingTransactionTracker(pendingTransactions); @@ -101,6 +101,7 @@ static TransactionPool createTransactionPool( transactionPoolConfiguration); final TransactionsMessageHandler transactionsMessageHandler = new TransactionsMessageHandler( + protocolSchedule, ethContext.getScheduler(), new TransactionsMessageProcessor( transactionTracker, @@ -122,6 +123,7 @@ static TransactionPool createTransactionPool( BesuMetricCategory.TRANSACTION_POOL, "pending_transactions_messages_skipped_total", "Total number of pending transactions messages skipped by the processor."), + protocolSchedule, ethContext, metricsSystem, syncState), diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionsMessageHandler.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionsMessageHandler.java index 372778fc2c2..e2fc731ec0b 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionsMessageHandler.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionsMessageHandler.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.ethereum.eth.manager.EthMessages; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.messages.TransactionsMessage; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import java.time.Duration; import java.time.Instant; @@ -29,19 +30,23 @@ class TransactionsMessageHandler implements EthMessages.MessageCallback { private final TransactionsMessageProcessor transactionsMessageProcessor; private final EthScheduler scheduler; private final Duration txMsgKeepAlive; + private final boolean goQuorumCompatibilityMode; public TransactionsMessageHandler( + final ProtocolSchedule protocolSchedule, final EthScheduler scheduler, final TransactionsMessageProcessor transactionsMessageProcessor, final int txMsgKeepAliveSeconds) { this.scheduler = scheduler; this.transactionsMessageProcessor = transactionsMessageProcessor; this.txMsgKeepAlive = Duration.ofSeconds(txMsgKeepAliveSeconds); + this.goQuorumCompatibilityMode = protocolSchedule.getGenesisConfigOptions().isQuorum(); } @Override public void exec(final EthMessage message) { - final TransactionsMessage transactionsMessage = TransactionsMessage.readFrom(message.getData()); + final TransactionsMessage transactionsMessage = + TransactionsMessage.readFrom(message.getData(), goQuorumCompatibilityMode); final Instant startedAt = now(); scheduler.scheduleTxWorkerTask( () -> diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionsMessageSender.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionsMessageSender.java index a0e6eacc41a..19d0d83d89a 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionsMessageSender.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionsMessageSender.java @@ -17,6 +17,7 @@ import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.manager.EthPeer; import org.hyperledger.besu.ethereum.eth.messages.LimitedTransactionsMessages; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection.PeerNotConnected; import java.util.Set; @@ -28,9 +29,12 @@ class TransactionsMessageSender { private static final Logger LOG = LogManager.getLogger(); + private final ProtocolSchedule protocolSchedule; private final PeerTransactionTracker transactionTracker; - public TransactionsMessageSender(final PeerTransactionTracker transactionTracker) { + public TransactionsMessageSender( + final ProtocolSchedule protocolSchedule, final PeerTransactionTracker transactionTracker) { + this.protocolSchedule = protocolSchedule; this.transactionTracker = transactionTracker; } @@ -43,8 +47,10 @@ public void sendTransactionsToPeers() { private void sendTransactionsToPeer(final EthPeer peer) { final Set allTxToSend = transactionTracker.claimTransactionsToSendToPeer(peer); while (!allTxToSend.isEmpty()) { + final boolean isQuorumCompatibilityMode = + protocolSchedule.getGenesisConfigOptions().isQuorum(); final LimitedTransactionsMessages limitedTransactionsMessages = - LimitedTransactionsMessages.createLimited(allTxToSend); + LimitedTransactionsMessages.createLimited(allTxToSend, isQuorumCompatibilityMode); LOG.trace("Sending transactions to peer {} TRANSACTIONS count {}", peer, allTxToSend.size()); allTxToSend.removeAll(limitedTransactionsMessages.getIncludedTransactions()); try { diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/DataStoreModule.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/DataStoreModule.java index c4b334526ea..a70a0a69610 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/DataStoreModule.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/DataStoreModule.java @@ -15,6 +15,7 @@ */ package org.hyperledger.besu.evmtool; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.ethereum.chain.BlockchainStorage; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier; @@ -127,6 +128,10 @@ private KeyValueStorage constructKeyValueStorage( static BlockchainStorage provideBlockchainStorage( @Named("blockchain") final KeyValueStorage keyValueStorage, final BlockHeaderFunctions blockHashFunction) { - return new KeyValueStoragePrefixedKeyBlockchainStorage(keyValueStorage, blockHashFunction); + return new KeyValueStoragePrefixedKeyBlockchainStorage( + keyValueStorage, + blockHashFunction, + // TODO: do we decide goQuorumCompatibilityMode here? + new StubGenesisConfigOptions()); } } diff --git a/ethereum/p2p/build.gradle b/ethereum/p2p/build.gradle index 8bff3d38772..1cbd2790f7c 100644 --- a/ethereum/p2p/build.gradle +++ b/ethereum/p2p/build.gradle @@ -36,6 +36,7 @@ dependencies { implementation project(':metrics:core') implementation project(':nat') + implementation 'com.google.guava:guava' implementation 'dnsjava:dnsjava' implementation 'io.prometheus:simpleclient' 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 f3fdf8ce1b2..9aa969f68fb 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 @@ -17,6 +17,7 @@ import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.ProtocolContext; @@ -82,7 +83,8 @@ private static WorldStateArchive buildWorldStateArchive( private static MutableBlockchain buildBlockchain(final BlockHeader genesisBlockHeader) { final Block genesisBlock = new Block(genesisBlockHeader, BlockBody.empty()); - return InMemoryKeyValueStorageProvider.createInMemoryBlockchain(genesisBlock); + return InMemoryKeyValueStorageProvider.createInMemoryBlockchain( + new StubGenesisConfigOptions(), genesisBlock); } @JsonCreator @@ -246,9 +248,10 @@ public Block getBlock() { input.enterList(); final MainnetBlockHeaderFunctions blockHeaderFunctions = new MainnetBlockHeaderFunctions(); final BlockHeader header = BlockHeader.readFrom(input, blockHeaderFunctions); + final boolean goQuorumCompatibilityMode = false; final BlockBody body = new BlockBody( - input.readList(Transaction::readFrom), + input.readList(rlp -> Transaction.readFrom(rlp, goQuorumCompatibilityMode)), input.readList(rlp -> BlockHeader.readFrom(rlp, blockHeaderFunctions))); return new Block(header, body); } diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java index bd1be09ac88..330aef12e32 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java @@ -14,6 +14,8 @@ */ package org.hyperledger.besu.ethereum.retesteth; +import org.hyperledger.besu.config.GenesisConfigOptions; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.BlockValidator; import org.hyperledger.besu.ethereum.MainnetBlockValidator; @@ -102,4 +104,9 @@ public void setPublicWorldStateArchiveForPrivacyBlockProcessor( final WorldStateArchive publicWorldStateArchive) { delegate.setPublicWorldStateArchiveForPrivacyBlockProcessor(publicWorldStateArchive); } + + @Override + public GenesisConfigOptions getGenesisConfigOptions() { + return new StubGenesisConfigOptions(); + } } 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 f2823631748..a62901eb5c1 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 @@ -16,6 +16,7 @@ import static org.hyperledger.besu.config.JsonUtil.normalizeKeys; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.config.JsonGenesisConfigOptions; import org.hyperledger.besu.config.JsonUtil; import org.hyperledger.besu.datatypes.Address; @@ -148,7 +149,7 @@ private boolean buildContext( final MutableWorldState worldState = worldStateArchive.getMutable(); genesisState.writeStateTo(worldState); - blockchain = createInMemoryBlockchain(genesisState.getBlock()); + blockchain = createInMemoryBlockchain(jsonGenesisConfigOptions, genesisState.getBlock()); protocolContext = new ProtocolContext(blockchain, worldStateArchive, null); blockchainQueries = new BlockchainQueries(blockchain, worldStateArchive, ethScheduler); @@ -212,16 +213,21 @@ private boolean buildContext( return true; } - private static MutableBlockchain createInMemoryBlockchain(final Block genesisBlock) { - return createInMemoryBlockchain(genesisBlock, new MainnetBlockHeaderFunctions()); + private static MutableBlockchain createInMemoryBlockchain( + final GenesisConfigOptions genesisConfigOptions, final Block genesisBlock) { + return createInMemoryBlockchain( + genesisConfigOptions, genesisBlock, new MainnetBlockHeaderFunctions()); } private static MutableBlockchain createInMemoryBlockchain( - final Block genesisBlock, final BlockHeaderFunctions blockHeaderFunctions) { + final GenesisConfigOptions genesisConfigOptions, + final Block genesisBlock, + final BlockHeaderFunctions blockHeaderFunctions) { final InMemoryKeyValueStorage keyValueStorage = new InMemoryKeyValueStorage(); return DefaultBlockchain.createMutable( genesisBlock, - new KeyValueStoragePrefixedKeyBlockchainStorage(keyValueStorage, blockHeaderFunctions), + new KeyValueStoragePrefixedKeyBlockchainStorage( + keyValueStorage, blockHeaderFunctions, genesisConfigOptions), new NoOpMetricsSystem(), 100); } diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethService.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethService.java index 8f3dcfc8e6c..7c1a83f23a6 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethService.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethService.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.retesteth; +import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcHttpService; import org.hyperledger.besu.ethereum.api.jsonrpc.health.HealthService; @@ -63,6 +64,7 @@ public RetestethService( final BlockResultFactory blockResult = new BlockResultFactory(); final NatService natService = new NatService(Optional.empty()); + final StubGenesisConfigOptions genesisConfigOptions = new StubGenesisConfigOptions(); // Synchronizer needed by RPC methods. Didn't wanna mock it, since this isn't the test module. Synchronizer sync = new DummySynchronizer(); @@ -78,7 +80,8 @@ public RetestethService( new DebugAccountRange(retestethContext::getBlockchainQueries), new EthGetBalance(retestethContext::getBlockchainQueries), new EthGetBlockByHash(retestethContext::getBlockchainQueries, blockResult, true), - new EthGetCode(retestethContext::getBlockchainQueries, Optional.empty()), + new EthGetCode( + retestethContext::getBlockchainQueries, genesisConfigOptions, Optional.empty()), new EthGetTransactionCount( retestethContext::getBlockchainQueries, retestethContext::getPendingTransactions, @@ -86,7 +89,8 @@ public RetestethService( new DebugStorageRangeAt( retestethContext::getBlockchainQueries, retestethContext::getBlockReplay, true), new TestModifyTimestamp(retestethContext), - new EthSendRawTransaction(retestethContext::getTransactionPool, true), + new EthSendRawTransaction( + retestethContext::getTransactionPool, genesisConfigOptions, true), new TestMineBlocks(retestethContext), new TestGetLogHash(retestethContext), new TestRewindToBlock(retestethContext)); diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java index 897719ecc39..a1203b0a018 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java @@ -56,8 +56,12 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { final Block block; try { + final boolean goQuorumCompatibilityMode = false; block = - Block.readFrom(RLP.input(Bytes.fromHexString(input)), context.getBlockHeaderFunctions()); + Block.readFrom( + RLP.input(Bytes.fromHexString(input)), + context.getBlockHeaderFunctions(), + goQuorumCompatibilityMode); } catch (final RLPException | IllegalArgumentException e) { LOG.debug("Failed to parse block RLP", e); return new JsonRpcErrorResponse(