From 72d2781f1f98eeb734863f7a4d0f1cf0fa28a1c7 Mon Sep 17 00:00:00 2001 From: Karim Taam Date: Wed, 27 Nov 2024 20:33:54 +0700 Subject: [PATCH] merge main into verkle (#7928) Signed-off-by: Karim Taam --- .github/ISSUE_TEMPLATE/bug-report.md | 50 ++ .github/ISSUE_TEMPLATE/feature-request.md | 45 ++ .github/issue_template.md | 22 +- .github/workflows/stale-issues.yml | 27 ++ CHANGELOG.md | 19 +- CONTRIBUTING.md | 2 +- DCO.md | 2 +- MAINTAINERS.md | 3 +- README.md | 4 +- SUPPORT.md | 2 +- .../tests/acceptance/dsl/node/BesuNode.java | 16 +- .../dsl/node/ProcessBesuNodeRunner.java | 2 +- .../dsl/node/ThreadBesuNodeRunner.java | 60 ++- .../configuration/BesuNodeConfiguration.java | 12 +- .../BesuNodeConfigurationBuilder.java | 19 +- .../plugins/BadCLIOptionsPlugin.java | 4 +- .../plugins/TestBesuEventsPlugin.java | 6 +- .../TestBlockchainServiceFinalizedPlugin.java | 8 +- .../TestInProcessRpcServicePlugin.java | 4 +- .../acceptance/plugins/TestMetricsPlugin.java | 76 +++ .../plugins/TestPermissioningPlugin.java | 4 +- .../acceptance/plugins/TestPicoCLIPlugin.java | 4 +- .../plugins/TestPrivacyServicePlugin.java | 6 +- .../plugins/TestRpcEndpointServicePlugin.java | 4 +- .../TestPrivacyPluginPayloadProvider.java | 1 + acceptance-tests/tests/build.gradle | 4 + .../bft/BftMiningAcceptanceTest.java | 10 +- .../acceptance/plugins/MetricsPluginTest.java | 73 +++ besu/build.gradle | 1 - .../org/hyperledger/besu/RunnerBuilder.java | 30 +- .../org/hyperledger/besu/cli/BesuCommand.java | 142 +++--- .../cli/ConfigurationOverviewBuilder.java | 14 +- .../converter/MetricCategoryConverter.java | 73 --- .../{stable => }/ApiConfigurationOptions.java | 2 +- .../{unstable => }/ChainPruningOptions.java | 3 +- .../options/{unstable => }/DnsOptions.java | 3 +- .../{stable => }/EngineRPCConfiguration.java | 2 +- .../{stable => }/EngineRPCOptions.java | 3 +- .../{unstable => }/EthProtocolOptions.java | 4 +- .../options/{stable => }/EthstatsOptions.java | 3 +- .../options/{unstable => }/EvmOptions.java | 3 +- .../options/{stable => }/GraphQlOptions.java | 2 +- .../{unstable => }/InProcessRpcOptions.java | 3 +- .../options/{unstable => }/IpcOptions.java | 2 +- .../{stable => }/JsonRpcHttpOptions.java | 2 +- .../{stable => }/LoggingLevelOption.java | 2 +- .../options/{stable => }/MetricsOptions.java | 50 +- .../besu/cli/options/MiningOptions.java | 82 ++-- .../options/{unstable => }/NatOptions.java | 2 +- .../{unstable => }/NativeLibraryOptions.java | 2 +- .../{unstable => }/NetworkingOptions.java | 4 +- .../NodePrivateKeyFileOption.java | 2 +- .../{stable => }/P2PDiscoveryOptions.java | 3 +- .../{unstable => }/P2PTLSConfigOptions.java | 2 +- .../{stable => }/PermissionsOptions.java | 2 +- .../PluginsConfigurationOptions.java | 3 +- .../{unstable => }/PrivacyPluginOptions.java | 5 +- .../options/{unstable => }/RPCOptions.java | 2 +- .../{stable => }/RpcWebsocketOptions.java | 135 +++++- .../{unstable => }/SynchronizerOptions.java | 4 +- .../cli/subcommands/PublicKeySubCommand.java | 2 +- .../cli/subcommands/RetestethSubCommand.java | 149 ------ .../subcommands/blocks/BlocksSubCommand.java | 12 +- .../subcommands/operator/RestoreState.java | 6 +- .../besu/components/BesuCommandModule.java | 4 +- .../besu/controller/BesuController.java | 14 +- .../controller/BesuControllerBuilder.java | 100 ++-- .../CliqueBesuControllerBuilder.java | 22 +- ...onsensusScheduleBesuControllerBuilder.java | 39 +- .../controller/IbftBesuControllerBuilder.java | 14 +- .../MainnetBesuControllerBuilder.java | 24 +- .../MergeBesuControllerBuilder.java | 14 +- .../controller/MiningParameterOverrides.java | 4 +- .../controller/QbftBesuControllerBuilder.java | 21 +- .../TransitionBesuControllerBuilder.java | 34 +- .../besu/services/BesuConfigurationImpl.java | 14 +- .../besu/services/BesuPluginContextImpl.java | 4 +- .../besu/services/BlockchainServiceImpl.java | 18 +- .../besu/services/MiningServiceImpl.java | 49 ++ .../services/PrivacyPluginServiceImpl.java | 1 + .../TransactionSimulationServiceImpl.java | 13 + besu/src/main/scripts/unixStartScript.txt | 24 +- .../besu/FlexGroupPrivacyTest.java | 4 +- .../besu/ForkIdsNetworkConfigTest.java | 6 +- .../hyperledger/besu/PrivacyReorgTest.java | 4 +- .../org/hyperledger/besu/PrivacyTest.java | 4 +- .../hyperledger/besu/RunnerBuilderTest.java | 4 +- .../java/org/hyperledger/besu/RunnerTest.java | 42 +- .../chainexport/RlpBlockExporterTest.java | 4 +- .../chainimport/JsonBlockImporterTest.java | 40 +- .../chainimport/RlpBlockImporterTest.java | 8 +- .../hyperledger/besu/cli/BesuCommandTest.java | 59 ++- .../cli/CascadingDefaultProviderTest.java | 6 +- .../besu/cli/CommandTestAbstract.java | 8 +- .../MetricCategoryConverterTest.java | 63 --- .../cli/options/EthProtocolOptionsTest.java | 1 - .../{stable => }/LoggingLevelOptionTest.java | 2 +- .../besu/cli/options/MetricsOptionsTest.java | 46 +- .../besu/cli/options/MiningOptionsTest.java | 34 +- .../cli/options/NetworkingOptionsTest.java | 1 - .../cli/options/SynchronizerOptionsTest.java | 1 - ...onfigDefaultValueProviderStrategyTest.java | 2 +- .../AbstractBftBesuControllerBuilderTest.java | 10 +- .../CliqueBesuControllerBuilderTest.java | 10 +- ...nsusScheduleBesuControllerBuilderTest.java | 21 +- .../MergeBesuControllerBuilderTest.java | 8 +- .../QbftBesuControllerBuilderTest.java | 4 +- .../TransitionControllerBuilderTest.java | 20 +- .../besu/services/BesuEventsImplTest.java | 4 +- .../besu/services/TraceServiceImplTest.java | 4 +- .../src/test/resources/everything_config.toml | 13 + build.gradle | 3 - config/build.gradle | 2 + .../besu/config/GenesisReader.java | 4 +- .../besu/config/GenesisReaderTest.java | 15 + .../clique/CliqueDifficultyCalculator.java | 8 +- .../besu/consensus/clique/CliqueHelpers.java | 18 +- .../consensus/clique/CliqueMiningTracker.java | 5 +- .../clique/CliqueProtocolSchedule.java | 51 +- .../blockcreation/CliqueBlockCreator.java | 8 +- .../blockcreation/CliqueMinerExecutor.java | 10 +- .../CliqueDifficultyValidationRule.java | 3 +- .../clique/jsonrpc/CliqueJsonRpcMethods.java | 12 +- .../CliqueDifficultyCalculatorTest.java | 14 +- .../clique/CliqueProtocolScheduleTest.java | 18 +- .../blockcreation/CliqueBlockCreatorTest.java | 46 +- .../CliqueMinerExecutorTest.java | 30 +- .../CliqueMiningCoordinatorTest.java | 2 + .../CliqueDifficultyValidationRuleTest.java | 2 + ...xt.java => MigratingConsensusContext.java} | 4 +- .../common/MigratingProtocolContext.java | 36 +- .../bft/BaseBftProtocolScheduleBuilder.java | 13 +- .../bft/blockcreation/BftBlockCreator.java | 8 +- .../blockcreation/BftBlockCreatorFactory.java | 20 +- .../CombinedProtocolScheduleFactoryTest.java | 6 +- .../common/MigratingProtocolContextTest.java | 6 +- .../BaseBftProtocolScheduleBuilderTest.java | 4 +- consensus/ibft/build.gradle | 2 + .../ibft/support/TestContextBuilder.java | 12 +- .../ibft/IbftProtocolScheduleBuilder.java | 14 +- .../ibft/jsonrpc/IbftJsonRpcMethods.java | 12 +- .../ibft/IbftProtocolScheduleTest.java | 144 ++++-- .../blockcreation/BftBlockCreatorTest.java | 14 +- .../IbftBlockHeightManagerTest.java | 6 +- .../merge/MergeProtocolSchedule.java | 18 +- .../merge/TransitionProtocolSchedule.java | 10 +- .../blockcreation/MergeBlockCreator.java | 10 +- .../merge/blockcreation/MergeCoordinator.java | 32 +- .../merge/MergeProtocolScheduleTest.java | 15 +- .../blockcreation/MergeCoordinatorTest.java | 32 +- .../MergeGenesisConfigHelper.java | 4 +- .../merge/blockcreation/MergeReorgTest.java | 6 +- consensus/qbft/build.gradle | 2 - .../qbft/support/TestContextBuilder.java | 12 +- .../qbft/QbftProtocolScheduleBuilder.java | 20 +- .../QbftBlockCreatorFactory.java | 6 +- .../qbft/jsonrpc/QbftJsonRpcMethods.java | 12 +- .../qbft/QbftProtocolScheduleTest.java | 4 +- .../QbftBlockCreatorFactoryTest.java | 10 +- .../QbftBlockHeightManagerTest.java | 6 +- .../besu/datatypes/AccountOverride.java | 197 ++++++++ .../besu/datatypes/AccountOverrideMap.java | 27 ++ docs/Private-Txns-Migration.md | 4 +- docs/README.md | 2 +- docs/trace_rpc_apis.md | 2 +- docs/tracing/README.md | 2 +- .../api/jsonrpc/BlockchainImporter.java | 4 +- .../jsonrpc/JsonRpcTestMethodsFactory.java | 17 +- ...ckByNumberLatestDesyncIntegrationTest.java | 4 +- .../EthGetFilterChangesIntegrationTest.java | 4 +- .../EthGetFilterChangesIntegrationTest.java | 4 +- .../api/handlers/AbstractJsonRpcExecutor.java | 1 + .../api/handlers/JsonRpcExecutorHandler.java | 44 +- .../jsonrpc/execution/JsonRpcExecutor.java | 4 +- .../internal/methods/DebugSetHead.java | 123 ++++- .../api/jsonrpc/internal/methods/EthCall.java | 20 + .../internal/methods/EthEstimateGas.java | 25 +- .../jsonrpc/internal/methods/TraceBlock.java | 37 +- .../internal/methods/TraceCallMany.java | 7 +- .../jsonrpc/internal/methods/TraceFilter.java | 28 +- .../methods/TraceReplayBlockTransactions.java | 25 +- .../methods/engine/EngineNewPayloadV2.java | 4 +- .../methods/miner/MinerGetExtraData.java | 10 +- .../methods/miner/MinerGetMinGasPrice.java | 10 +- .../methods/miner/MinerGetMinPriorityFee.java | 10 +- .../methods/miner/MinerSetExtraData.java | 10 +- .../methods/miner/MinerSetMinGasPrice.java | 10 +- .../methods/miner/MinerSetMinPriorityFee.java | 10 +- .../methods/DisabledPrivacyRpcMethod.java | 1 + .../MultiTenancyRpcMethodDecorator.java | 1 + .../privacy/methods/MultiTenancyUserUtil.java | 1 + .../privacy/methods/PrivGetFilterChanges.java | 1 + .../privacy/methods/PrivGetFilterLogs.java | 1 + .../privacy/methods/PrivUninstallFilter.java | 1 + .../privacy/methods/PrivacyIdProvider.java | 1 + .../eea/AbstractEeaSendRawTransaction.java | 1 + .../eea/JsonRpcErrorResponseException.java | 1 + .../eea/PluginEeaSendRawTransaction.java | 1 + ...strictedFlexibleEeaSendRawTransaction.java | 1 + ...strictedOffchainEeaSendRawTransaction.java | 1 + .../priv/AbstractPrivateTraceByHash.java | 1 + .../privacy/methods/priv/PrivCall.java | 1 + .../methods/priv/PrivCreatePrivacyGroup.java | 1 + .../methods/priv/PrivDebugGetStateRoot.java | 1 + .../methods/priv/PrivDeletePrivacyGroup.java | 1 + .../priv/PrivDistributeRawTransaction.java | 1 + .../methods/priv/PrivFindPrivacyGroup.java | 1 + .../privacy/methods/priv/PrivGetCode.java | 1 + .../priv/PrivGetEeaTransactionCount.java | 1 + .../privacy/methods/priv/PrivGetLogs.java | 1 + .../priv/PrivGetPrivacyPrecompileAddress.java | 1 + .../priv/PrivGetPrivateTransaction.java | 1 + .../methods/priv/PrivGetTransactionCount.java | 1 + .../priv/PrivGetTransactionReceipt.java | 1 + .../privacy/methods/priv/PrivNewFilter.java | 1 + .../methods/priv/PrivTraceTransaction.java | 1 + .../privacy/methods/priv/PrivUtil.java | 1 + .../privx/PrivxFindFlexiblePrivacyGroup.java | 1 + .../privx/PrivxFindOnchainPrivacyGroup.java | 2 +- .../CreatePrivacyGroupParameter.java | 1 + .../results/proof/GetProofResult.java | 5 +- .../methods/JsonRpcMethodsFactory.java | 12 +- .../jsonrpc/methods/MinerJsonRpcMethods.java | 20 +- .../jsonrpc/methods/PrivJsonRpcMethods.java | 1 + .../PrivacyApiGroupJsonRpcMethods.java | 1 + .../jsonrpc/methods/TraceJsonRpcMethods.java | 15 +- .../websocket/WebSocketConfiguration.java | 112 +++++ .../jsonrpc/websocket/WebSocketService.java | 72 ++- .../ethereum/api/query/BlockchainQueries.java | 26 +- .../api/query/StateBackupService.java | 6 +- .../AbstractEthGraphQLHttpServiceTest.java | 10 +- .../handlers/JsonRpcExecutorHandlerTest.java | 110 +++++ .../AbstractJsonRpcHttpServiceTest.java | 8 +- .../JsonRpcHttpServiceHostAllowlistTest.java | 6 +- .../jsonrpc/JsonRpcHttpServiceLoginTest.java | 6 +- .../JsonRpcHttpServiceRpcApisTest.java | 6 +- .../jsonrpc/JsonRpcHttpServiceTestBase.java | 6 +- .../JsonRpcHttpServiceTlsClientAuthTest.java | 6 +- ...RpcHttpServiceTlsMisconfigurationTest.java | 6 +- .../jsonrpc/JsonRpcHttpServiceTlsTest.java | 6 +- .../internal/methods/DebugSetHeadTest.java | 198 ++++++++ .../jsonrpc/internal/methods/EthCallTest.java | 84 +++- .../internal/methods/EthEstimateGasTest.java | 47 ++ .../internal/methods/EthGasPriceTest.java | 18 +- .../methods/EthGetBlockByNumberTest.java | 4 +- .../methods/EthGetBlockReceiptsTest.java | 4 +- .../internal/methods/EthGetProofTest.java | 8 +- .../methods/EthGetTransactionReceiptTest.java | 4 +- .../methods/EthMaxPriorityFeePerGasTest.java | 16 +- .../internal/methods/TraceFilterTest.java | 4 +- .../engine/AbstractEngineNewPayloadTest.java | 88 ++-- .../engine/EngineNewPayloadV2Test.java | 24 +- .../engine/EngineNewPayloadV3Test.java | 37 +- .../engine/EngineNewPayloadV4Test.java | 137 +++--- .../methods/miner/MinerGetExtraDataTest.java | 14 +- .../miner/MinerGetMinGasPriceTest.java | 17 +- .../miner/MinerGetMinPriorityFeeTest.java | 9 +- .../methods/miner/MinerSetExtraDataTest.java | 10 +- .../miner/MinerSetMinGasPriceTest.java | 8 +- .../miner/MinerSetMinPriorityFeeTest.java | 8 +- .../websocket/WebSocketServiceLoginTest.java | 6 +- .../websocket/WebSocketServiceTLSTest.java | 444 ++++++++++++++++++ ...ewBlockHeadersSubscriptionServiceTest.java | 4 +- .../query/BlockchainQueriesLogCacheTest.java | 4 +- .../api/query/BlockchainQueriesTest.java | 4 +- .../jsonrpc/eth/eth_call_overrides_empty.json | 24 + .../jsonrpc/eth/eth_call_stateOverride.json | 32 ++ ...all_stateOverride_insufficientBalance.json | 34 ++ .../blockcreation/AbstractBlockCreator.java | 19 +- .../blockcreation/AbstractMinerExecutor.java | 14 +- .../blockcreation/NoopMiningCoordinator.java | 14 +- .../blockcreation/PoWBlockCreator.java | 8 +- .../blockcreation/PoWMinerExecutor.java | 16 +- .../txselection/BlockSelectionContext.java | 4 +- .../txselection/BlockTransactionSelector.java | 10 +- .../BlockSizeTransactionSelector.java | 4 +- ...nPriorityFeePerGasTransactionSelector.java | 2 +- .../selectors/PriceTransactionSelector.java | 4 +- .../AbstractBlockCreatorTest.java | 20 +- .../AbstractBlockTransactionSelectorTest.java | 78 +-- .../blockcreation/BlockMinerTest.java | 7 +- ...FeeMarketBlockTransactionSelectorTest.java | 7 +- ...FeeMarketBlockTransactionSelectorTest.java | 21 +- ...orityFeePerGasTransactionSelectorTest.java | 8 +- .../blockcreation/PoWBlockCreatorTest.java | 51 +- .../blockcreation/PoWMinerExecutorTest.java | 10 +- .../PoWMiningCoordinatorTest.java | 4 +- ethereum/core/build.gradle | 4 +- .../ethereum/ConsensusContextFactory.java | 38 -- .../besu/ethereum/MainnetBlockValidator.java | 22 +- .../besu/ethereum/ProtocolContext.java | 49 +- .../ethereum/chain/DefaultBlockchain.java | 32 +- .../components/ProtocolScheduleModule.java | 100 ++++ .../components/ProtocolSpecModule.java | 51 ++ ...rameters.java => MiningConfiguration.java} | 38 +- .../core/MiningParametersMetrics.java | 6 +- .../core/components/CoinbaseModule.java | 31 ++ .../components/EthereumCoreComponent.java | 32 ++ .../components/MiningParametersModule.java | 64 +++ .../fixed/FixedDifficultyCalculators.java | 2 +- .../FixedDifficultyProtocolSchedule.java | 22 +- .../mainnet/BaseFeeBlockBodyValidator.java | 6 +- .../ethereum/mainnet/BlockBodyValidator.java | 15 +- .../ethereum/mainnet/BodyValidationMode.java | 3 + .../mainnet/ClassicDifficultyCalculators.java | 8 +- .../mainnet/ClearEmptyAccountStrategy.java | 16 + .../mainnet/DifficultyCalculator.java | 4 +- .../mainnet/MainnetBlockBodyValidator.java | 67 +-- .../mainnet/MainnetDifficultyCalculators.java | 25 +- .../mainnet/MainnetProtocolSchedule.java | 67 +-- .../mainnet/MainnetProtocolSpecFactory.java | 32 +- .../mainnet/MainnetProtocolSpecs.java | 52 +- .../mainnet/MainnetTransactionProcessor.java | 10 +- .../besu/ethereum/mainnet/PoWSolver.java | 16 +- .../mainnet/ProtocolScheduleBuilder.java | 63 +-- .../CalculatedDifficultyValidationRule.java | 2 +- .../PrivacyPluginPrecompiledContract.java | 1 + .../besu/ethereum/proof/WorldStateProof.java | 8 +- .../proof/WorldStateProofProvider.java | 6 +- .../transaction/TransactionSimulator.java | 83 +++- .../common/AbstractStateTrieAccountValue.java | 81 ++++ .../common/PmtStateTrieAccountValue.java} | 63 +-- .../common/VerkleStateTrieAccountValue.java | 104 ++++ .../bonsai/BonsaiWorldStateProvider.java | 23 +- .../cache/BonsaiCachedMerkleTrieLoader.java | 13 +- .../BonsaiWorldStateKeyValueStorage.java | 4 +- .../bonsai/trielog/TrieLogFactoryImpl.java | 8 +- .../common/DiffBasedWorldStateProvider.java | 9 +- .../common/trielog/TrieLogManager.java | 6 +- .../verkle/VerkleWorldStateProvider.java | 6 +- .../verkle/trielog/TrieLogFactoryImpl.java | 8 +- .../trie/forest/ForestWorldStateArchive.java | 5 + .../worldview/ForestMutableWorldState.java | 14 +- .../worldstate/WorldStateArchive.java | 20 + .../ethereum/core/BlockchainSetupUtil.java | 14 +- .../core/ConsensusContextFixture.java} | 20 +- .../core/ExecutionContextTestFixture.java | 7 +- .../core/InMemoryKeyValueStorageProvider.java | 5 +- .../core/ProtocolScheduleFixture.java | 10 +- .../besu/ethereum/core/TrieGenerator.java | 7 +- .../ethereum/core/WorldStateHealerHelper.java | 39 ++ .../BlockImportExceptionHandlingTest.java | 9 +- .../ethereum/MainnetBlockValidatorTest.java | 40 +- .../fixed/FixedProtocolScheduleTest.java | 10 +- .../mainnet/DefaultProtocolScheduleTest.java | 6 +- .../MainnetBlockBodyValidatorTest.java | 106 +++-- .../mainnet/MainnetProtocolScheduleTest.java | 8 +- .../MainnetTransactionProcessorTest.java | 1 - .../besu/ethereum/mainnet/PoWSolverTest.java | 12 +- .../mainnet/ProtocolScheduleBuilderTest.java | 10 +- .../proof/WorldStateProofProviderTest.java | 7 +- .../transaction/TransactionSimulatorTest.java | 41 ++ .../bonsai/AbstractIsolationTests.java | 31 +- .../BonsaiCachedMerkleTrieLoaderTest.java | 10 +- .../bonsai/BonsaiWorldStateProviderTest.java | 22 +- .../BonsaiWorldStateKeyValueStorageTest.java | 6 +- .../bonsai/trielog/TrieLogFactoryTests.java | 4 +- .../common/trielog/TrieLogLayerTests.java | 17 +- .../util/AccountOverrideParameterTest.java | 190 ++++++++ .../worldstate/StateTrieAccountValueTest.java | 7 +- .../eth/manager/EthProtocolManager.java | 1 - .../ethereum/eth/manager/EthScheduler.java | 15 +- .../eth/manager/MonitoredExecutors.java | 4 +- .../eth/manager/peertask/PeerTask.java | 4 +- .../manager/peertask/PeerTaskExecutor.java | 8 +- .../task/GetReceiptsFromPeerTask.java | 135 ++++++ .../eth/manager/snap/SnapProtocolManager.java | 7 +- .../ethereum/eth/manager/snap/SnapServer.java | 6 +- .../messages/snap/AccountRangeMessage.java | 6 +- .../eth/sync/DefaultSynchronizer.java | 5 + .../CheckpointDownloadBlockStep.java | 73 ++- .../CheckpointDownloaderFactory.java | 4 + .../checkpointsync/CheckpointSyncActions.java | 4 + .../CheckpointSyncChainDownloader.java | 10 +- ...CheckpointSyncDownloadPipelineFactory.java | 14 +- .../sync/fastsync/DownloadReceiptsStep.java | 80 +++- .../eth/sync/fastsync/FastSyncActions.java | 5 + .../fastsync/FastSyncChainDownloader.java | 10 +- .../FastSyncDownloadPipelineFactory.java | 16 +- .../eth/sync/fastsync/ImportBlocksStep.java | 8 +- .../AccountTrieNodeDataRequest.java | 5 +- .../worldstate/FastDownloaderFactory.java | 3 + .../sync/snapsync/SnapDownloaderFactory.java | 3 + .../sync/snapsync/SnapSyncMetricsManager.java | 14 +- .../request/AccountRangeDataRequest.java | 6 +- ...ccountFlatDatabaseHealingRangeRequest.java | 6 +- .../heal/AccountTrieNodeHealingRequest.java | 7 +- .../transactions/TransactionBroadcaster.java | 8 +- .../eth/transactions/TransactionPool.java | 1 + .../transactions/TransactionPoolFactory.java | 20 +- .../transactions/TransactionPoolMetrics.java | 18 +- .../AbstractPrioritizedTransactions.java | 8 +- .../BaseFeePrioritizedTransactions.java | 12 +- .../GasPricePrioritizedTransactions.java | 8 +- .../eth/manager/EthProtocolManagerTest.java | 4 +- .../ethtaskutils/AbstractMessageTaskTest.java | 4 +- .../peertask/PeerTaskExecutorTest.java | 12 +- .../task/GetReceiptsFromPeerTaskTest.java | 264 +++++++++++ .../snap/SnapServerGetAccountRangeTest.java | 5 +- .../eth/manager/snap/SnapServerTest.java | 8 +- .../eth/messages/BlockBodiesMessageTest.java | 4 +- .../eth/messages/BlockHeadersMessageTest.java | 4 +- .../snap/AccountRangeMessageTest.java | 14 +- .../eth/sync/ChainHeadTrackerTest.java | 4 +- .../backwardsync/BackwardSyncContextTest.java | 4 +- .../backwardsync/BackwardSyncStepTest.java | 4 +- .../backwardsync/ForwardSyncStepTest.java | 4 +- .../CheckPointSyncChainDownloaderTest.java | 137 +++++- .../fastsync/DownloadReceiptsStepTest.java | 73 ++- .../fastsync/FastDownloaderFactoryTest.java | 7 + .../sync/fastsync/FastSyncActionsTest.java | 2 + .../fastsync/FastSyncChainDownloaderTest.java | 2 + .../sync/fastsync/ImportBlocksStepTest.java | 7 +- .../FastWorldStateDownloaderTest.java | 6 +- .../fullsync/FullSyncTargetManagerTest.java | 4 +- .../snapsync/AccountHealingTrackingTest.java | 32 +- .../eth/sync/snapsync/TaskGenerator.java | 6 +- ...geFlatDatabaseHealingRangeRequestTest.java | 6 +- .../StorageTrieNodeHealingRequestTest.java | 6 +- ...neCommonAncestorTaskParameterizedTest.java | 7 +- .../DetermineCommonAncestorTaskTest.java | 7 +- .../AbstractTransactionPoolTestBase.java | 6 +- .../ethereum/eth/transactions/TestNode.java | 10 +- .../TransactionPoolFactoryTest.java | 8 +- ...stractPrioritizedTransactionsTestBase.java | 15 +- .../BaseFeePrioritizedTransactionsTest.java | 10 +- .../GasPricePrioritizedTransactionsTest.java | 6 +- .../LayeredPendingTransactionsTest.java | 4 +- .../LayeredTransactionPoolBaseFeeTest.java | 4 +- .../LayeredTransactionPoolGasPriceTest.java | 4 +- .../eth/transactions/layered/LayersTest.java | 4 +- .../eth/transactions/layered/ReplayTest.java | 4 +- .../evmtool/MainnetGenesisFileModule.java | 8 +- ethereum/p2p/build.gradle | 1 - ethereum/referencetests/build.gradle | 2 + .../BlockchainReferenceTestCaseSpec.java | 7 +- .../referencetests/ReferenceTestEnv.java | 3 +- .../ReferenceTestProtocolSchedules.java | 7 +- .../mainnet/DifficultyCalculatorTests.java | 34 +- ethereum/retesteth/build.gradle | 58 --- .../ethereum/retesteth/RetestethClock.java | 60 --- .../ethereum/retesteth/RetestethContext.java | 370 --------------- .../ethereum/retesteth/RetestethService.java | 122 ----- .../retesteth/methods/TestGetLogHash.java | 73 --- .../retesteth/methods/TestImportRawBlock.java | 107 ----- .../retesteth/methods/TestMineBlocks.java | 97 ---- .../methods/TestModifyTimestamp.java | 51 -- .../retesteth/methods/TestRewindToBlock.java | 53 --- .../retesteth/methods/TestSetChainParams.java | 159 ------- .../methods/TestImportRawBlockTest.java | 129 ----- .../methods/TestSetChainParamsTest.java | 115 ----- .../retesteth/methods/1559ChainParams.json | 21 - ...ultimpleBalanceInstructionChainParams.json | 102 ---- .../besu/evm/operation/PushOperation.java | 18 +- .../besu/evm/operation/PushOperationTest.java | 83 ++++ metrics/core/build.gradle | 1 + .../metrics/MetricCategoryRegistryImpl.java | 70 ++- .../besu/metrics/ObservableMetricsSystem.java | 31 +- .../besu/metrics/noop/NoOpMetricsSystem.java | 68 ++- .../besu/metrics/noop/NoOpValueCollector.java | 10 +- .../opentelemetry/OpenTelemetryGauge.java | 50 +- .../OpenTelemetryLabelledSuppliedMetric.java | 67 +++ .../OpenTelemetrySuppliedCounter.java | 43 ++ .../opentelemetry/OpenTelemetrySystem.java | 35 +- .../prometheus/PrometheusMetricsSystem.java | 155 ++++-- ... => PrometheusSuppliedValueCollector.java} | 26 +- .../besu/metrics/StubMetricsSystem.java | 36 +- .../MetricCategoryRegistryImplTest.java | 66 +++ .../OpenTelemetryMetricsSystemTest.java | 6 +- .../PrometheusMetricsSystemTest.java | 10 +- metrics/rocksdb/build.gradle | 2 - .../besu/metrics/rocksdb/RocksDBStats.java | 90 ++-- platform/build.gradle | 15 +- plugin-api/build.gradle | 2 +- .../hyperledger/besu/plugin/BesuContext.java | 42 +- .../hyperledger/besu/plugin/BesuPlugin.java | 2 +- .../besu/plugin/ServiceManager.java | 55 +++ .../besu/plugin/services/BesuService.java | 6 +- .../besu/plugin/services/MetricsSystem.java | 103 +++- .../plugin/services/PrivacyPluginService.java | 1 + .../TransactionSimulationService.java | 18 + .../services/metrics/ExternalSummary.java | 36 ++ .../services/metrics/LabelledGauge.java | 30 +- .../metrics/LabelledSuppliedMetric.java | 28 ++ .../metrics/MetricCategoryRegistry.java | 10 +- .../plugin/services/mining/MiningService.java | 27 ++ .../privacy/PrivacyPluginPayloadProvider.java | 1 + plugins/rocksdb/build.gradle | 1 - .../rocksdb/RocksDBMetricsFactory.java | 6 +- .../storage/rocksdb/RocksDBPlugin.java | 6 +- .../RocksDBColumnarKeyValueStorageTest.java | 2 +- .../kvstore/InMemoryStoragePlugin.java | 6 +- settings.gradle | 1 - .../besu/testfuzz/javafuzz/FuzzTarget.java | 2 +- 494 files changed, 7114 insertions(+), 4513 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug-report.md create mode 100644 .github/ISSUE_TEMPLATE/feature-request.md create mode 100644 .github/workflows/stale-issues.yml create mode 100644 acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestMetricsPlugin.java create mode 100644 acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/MetricsPluginTest.java delete mode 100644 besu/src/main/java/org/hyperledger/besu/cli/converter/MetricCategoryConverter.java rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/ApiConfigurationOptions.java (99%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/ChainPruningOptions.java (98%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/DnsOptions.java (96%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/EngineRPCConfiguration.java (96%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/EngineRPCOptions.java (96%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/EthProtocolOptions.java (97%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/EthstatsOptions.java (96%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/EvmOptions.java (96%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/GraphQlOptions.java (98%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/InProcessRpcOptions.java (96%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/IpcOptions.java (98%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/JsonRpcHttpOptions.java (99%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/LoggingLevelOption.java (97%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/MetricsOptions.java (83%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/NatOptions.java (97%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/NativeLibraryOptions.java (98%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/NetworkingOptions.java (96%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/NodePrivateKeyFileOption.java (96%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/P2PDiscoveryOptions.java (98%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/P2PTLSConfigOptions.java (99%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/PermissionsOptions.java (99%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/PluginsConfigurationOptions.java (97%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/PrivacyPluginOptions.java (82%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/RPCOptions.java (97%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/RpcWebsocketOptions.java (67%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/SynchronizerOptions.java (99%) delete mode 100644 besu/src/main/java/org/hyperledger/besu/cli/subcommands/RetestethSubCommand.java create mode 100644 besu/src/main/java/org/hyperledger/besu/services/MiningServiceImpl.java delete mode 100644 besu/src/test/java/org/hyperledger/besu/cli/converter/MetricCategoryConverterTest.java rename besu/src/test/java/org/hyperledger/besu/cli/options/{stable => }/LoggingLevelOptionTest.java (97%) rename consensus/common/src/main/java/org/hyperledger/besu/consensus/common/{MigratingContext.java => MigratingConsensusContext.java} (88%) create mode 100644 datatypes/src/main/java/org/hyperledger/besu/datatypes/AccountOverride.java create mode 100644 datatypes/src/main/java/org/hyperledger/besu/datatypes/AccountOverrideMap.java create mode 100644 ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/handlers/JsonRpcExecutorHandlerTest.java create mode 100644 ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHeadTest.java create mode 100644 ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketServiceTLSTest.java create mode 100644 ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_overrides_empty.json create mode 100644 ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_stateOverride.json create mode 100644 ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_stateOverride_insufficientBalance.json delete mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ConsensusContextFactory.java create mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/components/ProtocolScheduleModule.java create mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/components/ProtocolSpecModule.java rename ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/{MiningParameters.java => MiningConfiguration.java} (88%) create mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/CoinbaseModule.java create mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/EthereumCoreComponent.java create mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/MiningParametersModule.java create mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/common/AbstractStateTrieAccountValue.java rename ethereum/core/src/main/java/org/hyperledger/besu/ethereum/{worldstate/StateTrieAccountValue.java => trie/common/PmtStateTrieAccountValue.java} (64%) create mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/common/VerkleStateTrieAccountValue.java rename ethereum/{retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethConfiguration.java => core/src/test-support/java/org/hyperledger/besu/ethereum/core/ConsensusContextFixture.java} (66%) create mode 100644 ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/WorldStateHealerHelper.java create mode 100644 ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/AccountOverrideParameterTest.java create mode 100644 ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTask.java create mode 100644 ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTaskTest.java delete mode 100644 ethereum/retesteth/build.gradle delete mode 100644 ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethClock.java delete mode 100644 ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java delete mode 100644 ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethService.java delete mode 100644 ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestGetLogHash.java delete mode 100644 ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java delete mode 100644 ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java delete mode 100644 ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestModifyTimestamp.java delete mode 100644 ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestRewindToBlock.java delete mode 100644 ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParams.java delete mode 100644 ethereum/retesteth/src/test/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlockTest.java delete mode 100644 ethereum/retesteth/src/test/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParamsTest.java delete mode 100644 ethereum/retesteth/src/test/resources/org/hyperledger/besu/ethereum/retesteth/methods/1559ChainParams.json delete mode 100644 ethereum/retesteth/src/test/resources/org/hyperledger/besu/ethereum/retesteth/methods/multimpleBalanceInstructionChainParams.json create mode 100644 evm/src/test/java/org/hyperledger/besu/evm/operation/PushOperationTest.java create mode 100644 metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryLabelledSuppliedMetric.java create mode 100644 metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySuppliedCounter.java rename metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/{PrometheusGauge.java => PrometheusSuppliedValueCollector.java} (76%) create mode 100644 metrics/core/src/test/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImplTest.java create mode 100644 plugin-api/src/main/java/org/hyperledger/besu/plugin/ServiceManager.java create mode 100644 plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/ExternalSummary.java create mode 100644 plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/LabelledSuppliedMetric.java create mode 100644 plugin-api/src/main/java/org/hyperledger/besu/plugin/services/mining/MiningService.java diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md new file mode 100644 index 0000000000..7b88a84379 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -0,0 +1,50 @@ +--- +name: Bug Report +about: necessary information to help us resolve the issue +title: '' +labels: 'bug' +assignees: '' + +--- + + + + + + + + + +### Steps to Reproduce +1. [Step 1] +2. [Step 2] +3. [Step ...] + +**Expected behavior:** [What you expect to happen] + +**Actual behavior:** [What actually happens] + +**Frequency:** [What percentage of the time does it occur?] + +### Logs +Please post relevant logs from Besu (and the consensus client, if running proof of stake) from before and after the issue. + +### Versions (Add all that apply) +* Software version: [`besu --version`] +* Java version: [`java -version`] +* OS Name & Version: [`cat /etc/*release`] +* Kernel Version: [`uname -a`] +* Virtual Machine software & version: [`vmware -v`] +* Docker Version: [`docker version`] +* Cloud VM, type, size: [Amazon Web Services I3-large] +* Consensus Client & Version if using Proof of Stake: [e.g. Teku, Lighthouse, Prysm, Nimbus, Lodestar] + +### Smart contract information (If you're reporting an issue arising from deploying or calling a smart contract, please supply related information) +* Solidity version [`solc --version`] +* Repo with minimal set of deployable/reproducible contract code - please provide a link +* Please include specifics on how you are deploying/calling the contract +* Have you reproduced the issue on other eth clients + +### Additional Information (Add any of the following or anything else that may be relevant) +* Besu setup info - genesis file, config options +* System info - memory, CPU diff --git a/.github/ISSUE_TEMPLATE/feature-request.md b/.github/ISSUE_TEMPLATE/feature-request.md new file mode 100644 index 0000000000..73ebe5f060 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature-request.md @@ -0,0 +1,45 @@ +--- +name: Feature Request +about: suggesting new or altered functionality +title: '' +labels: '' +assignees: '' + +--- + + + + + + + +### Description +As an [Actor], I want [feature] so that [why]. + +### Acceptance Criteria +* [Criteria 1] +* [Criteria 2] +* [Criteria 3...] + +### Logs (if a change in behavior) +Please post relevant logs from Besu (and the consensus client, if running proof of stake) illustrating behavior to be altered + +### Versions (Add all that apply) +* Software version: [`besu --version`] +* Java version: [`java -version`] +* OS Name & Version: [`cat /etc/*release`] +* Kernel Version: [`uname -a`] +* Virtual Machine software & version: [`vmware -v`] +* Docker Version: [`docker version`] +* Cloud VM, type, size: [Amazon Web Services I3-large] +* Consensus Client & Version if using Proof of Stake: [e.g. Teku, Lighthouse, Prysm, Nimbus, Lodestar] + +### Smart contract information (If you're reporting an issue arising from deploying or calling a smart contract, please supply related information) +* Solidity version [`solc --version`] +* Repo with minimal set of deployable/reproducible contract code - please provide a link +* Please include specifics on how you are deploying/calling the contract +* Have you reproduced the issue on other eth clients + +### Additional Information (Add any of the following or anything else that may be relevant) +* Besu setup info - genesis file, config options +* System info - memory, CPU diff --git a/.github/issue_template.md b/.github/issue_template.md index 54acf4c196..7fe82b4f07 100644 --- a/.github/issue_template.md +++ b/.github/issue_template.md @@ -2,30 +2,10 @@ - - - + -### Description -As an [Actor], I want [feature] so that [why]. -### Acceptance Criteria -* [Criteria 1] - -### Steps to Reproduce (Bug) -1. [Step 1] -2. [Step 2] -3. [Step ...] - -**Expected behavior:** [What you expect to happen] - -**Actual behavior:** [What actually happens] - -**Frequency:** [What percentage of the time does it occur?] - -### Logs (if a bug) -Please post relevant logs from Besu (and the consensus client, if running proof of stake) from before and after the issue. ### Versions (Add all that apply) * Software version: [`besu --version`] diff --git a/.github/workflows/stale-issues.yml b/.github/workflows/stale-issues.yml new file mode 100644 index 0000000000..fe45d91b49 --- /dev/null +++ b/.github/workflows/stale-issues.yml @@ -0,0 +1,27 @@ +name: Close inactive issues +on: + schedule: + - cron: "30 1 * * *" + +jobs: + close-issues: + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + contents: write + steps: + - uses: actions/stale@v5 + with: + days-before-issue-stale: 180 + days-before-issue-close: 14 + stale-issue-label: "stale" + stale-issue-message: "This issue is stale because it has been open for 6 months with no activity." + close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale." + days-before-pr-stale: 30 + days-before-pr-close: 14 + stale-pr-message: "This pr is stale because it has been open for 30 days with no activity." + close-pr-message: "This pr was closed because it has been inactive for 14 days since being marked as stale." + remove-issue-stale-when-updated: true + remove-pr-stale-when-updated: true + repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bfb4ebd3e..5472920ef5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,19 +1,35 @@ # Changelog ## [Unreleased] -- Added isLabelsObserved to LabelledGauge in plugin-api. Default implementation returns false. ### Breaking Changes +- Removed Retesteth rpc service and commands [#7833](https://github.com/hyperledger/besu/pull/7783) ### Upcoming Breaking Changes +- Plugin API will be deprecating the BesuContext interface to be replaced with the ServiceManager interface. +- `MetricSystem::createLabelledGauge` is deprecated and will be removed in a future release, replace it with `MetricSystem::createLabelledSuppliedGauge` +- k8s (KUBERNETES) Nat method is now deprecated and will be removed in a future release +- `--host-whitelist` has been deprecated in favor of `--host-allowlist` since 2020 and will be removed in a future release +- Sunsetting features - for more context on the reasoning behind the deprecation of these features, including alternative options, read [this blog post](https://www.lfdecentralizedtrust.org/blog/sunsetting-tessera-and-simplifying-hyperledger-besu) + - Tessera privacy + - Smart-contract-based permissioning + - Proof of Work consensus + - Fast Sync ### Additions and Improvements - Fine tune already seen txs tracker when a tx is removed from the pool [#7755](https://github.com/hyperledger/besu/pull/7755) +- Support for enabling and configuring TLS/mTLS in WebSocket service. [#7854](https://github.com/hyperledger/besu/pull/7854) - Create and publish Besu BOM (Bill of Materials) [#7615](https://github.com/hyperledger/besu/pull/7615) - Update Java dependencies [#7786](https://github.com/hyperledger/besu/pull/7786) - Add a method to get all the transaction in the pool, to the `TransactionPoolService`, to easily access the transaction pool content from plugins [#7813](https://github.com/hyperledger/besu/pull/7813) +- Upgrade RocksDB JNI library from version 8.3.2 to 9.7.3 [#7817](https://github.com/hyperledger/besu/pull/7817) +- Add a method to check if a metric category is enabled to the plugin API [#7832](https://github.com/hyperledger/besu/pull/7832) +- Add a new metric collector for counters which get their value from suppliers [#7894](https://github.com/hyperledger/besu/pull/7894) +- Add account and state overrides to `eth_call` [#7801](https://github.com/hyperledger/besu/pull/7801) and `eth_estimateGas` [#7890](https://github.com/hyperledger/besu/pull/7890) ### Bug fixes +- Fix registering new metric categories from plugins [#7825](https://github.com/hyperledger/besu/pull/7825) +- Fix CVE-2024-47535 [7878](https://github.com/hyperledger/besu/pull/7878) ## 24.10.0 @@ -99,6 +115,7 @@ This release version has been deprecated release due to CI bug - Remove long-deprecated `perm*whitelist*` methods [#7401](https://github.com/hyperledger/besu/pull/7401) ### Additions and Improvements +- Allow optional loading of `jemalloc` (if installed) by setting the environment variable `BESU_USING_JEMALLOC` to true/false. It that env is not set at all it will behave as if it is set to `true` - Expose set finalized/safe block in plugin api BlockchainService. These method can be used by plugins to set finalized/safe block for a PoA network (such as QBFT, IBFT and Clique).[#7382](https://github.com/hyperledger/besu/pull/7382) - In process RPC service [#7395](https://github.com/hyperledger/besu/pull/7395) - Added support for tracing private transactions using `priv_traceTransaction` API. [#6161](https://github.com/hyperledger/besu/pull/6161) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c2d6c57d25..c13ea67852 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,7 +8,7 @@ Welcome to the Besu repository! The following links are a set of guidelines for Having the following accounts is necessary for contributing code/issues to Besu. * If you want to contribute code, you can make a [github account here](https://github.com). * If you want to raise an issue, do so [in the issues tab](https://github.com/hyperledger/besu/issues). -* To ask questions or chat with us, join our [Discord](https://discord.gg/hyperledger) +* To ask questions or chat with us, join our [Discord](https://discord.com/invite/hyperledger) * To edit pages in our wiki, you'll need a [Linux Foundation (LF) account]. ### Useful contributing links diff --git a/DCO.md b/DCO.md index 4bf56cb80a..48227cadcd 100644 --- a/DCO.md +++ b/DCO.md @@ -5,4 +5,4 @@ As per section 13.a of the [Hyperledger Charter](https://www.hyperledger.org/abo The sign off needs to be using your legal name, not a pseudonym. Git has a built-in mechanism to allow this with the `-s` or `--signoff` argument to `git commit` command, providing your `user.name` and `user.email` have been setup correctly. -If you have any questions, you can reach us on Besu chat; first, [join the Discord server](https://discord.gg/hyperledger/) then [join the Besu channel](https://discord.com/channels/905194001349627914/938504958909747250). +If you have any questions, you can reach us on Besu chat; first, [join the Discord server](https://discord.com/invite/hyperledger) then [join the Besu channel](https://discord.com/channels/905194001349627914/938504958909747250). diff --git a/MAINTAINERS.md b/MAINTAINERS.md index ae6720632a..6c17df8823 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -22,6 +22,7 @@ | Luis Pinto | lu-pinto | lu-pinto | | Lucas Saldanha | lucassaldanha | lucassaldanha | | Sally MacFarlane | macfarla | macfarla | +| Matilda Clerke | Matilda-Clerke | MatildaClerke | | Karim Taam | matkt | matkt | | Matthew Whitehead| matthew1001 | matthew.whitehead | | Meredith Baxter | mbaxter | mbaxter | @@ -84,7 +85,7 @@ The following steps must occur for a contributor to be "upgraded" as a maintaine - The proposed maintainer accepts the nomination and expresses a willingness to be a long-term (more than 6 month) committer by adding a comment in the proposal PR. - The PR will be communicated in all appropriate communication channels - including at least [besu-contributors channel on Discord](https://discord.gg/hyperledger), + including at least [besu-contributors channel on Discord](https://discord.com/invite/hyperledger), the [mailing list](https://lists.hyperledger.org/g/besu) and any maintainer/community call. - Approval by at least 3 current maintainers within two weeks of the proposal or diff --git a/README.md b/README.md index 7139df8580..8f5f51a726 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Documentation](https://img.shields.io/github/actions/workflow/status/hyperledger/besu-docs/publish-main-docs.yml?branch=main&label=docs)](https://github.com/hyperledger/besu-docs/actions/workflows/publish-main-docs.yml) [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/3174/badge)](https://bestpractices.coreinfrastructure.org/projects/3174) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/hyperledger/besu/blob/main/LICENSE) - [![Discord](https://img.shields.io/discord/905194001349627914?logo=Hyperledger&style=plastic)](https://discord.gg/hyperledger) + [![Discord](https://img.shields.io/discord/905194001349627914?logo=Hyperledger&style=plastic)](https://discord.com/invite/hyperledger) [![Twitter Follow](https://img.shields.io/twitter/follow/HyperledgerBesu)](https://twitter.com/HyperledgerBesu) [Download](https://github.com/hyperledger/besu/releases) @@ -67,5 +67,5 @@ and YourKit YouMonitor. [Besu Issues]: https://github.com/hyperledger/besu/issues [Besu User Documentation]: https://besu.hyperledger.org -[Besu channel on Discord]: https://discord.gg/hyperledger +[Besu channel on Discord]: https://discord.com/invite/hyperledger [Contributing Guidelines]: CONTRIBUTING.md diff --git a/SUPPORT.md b/SUPPORT.md index 9e4a7b7b42..97715857cb 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -20,5 +20,5 @@ Having Github, Discord, and Linux Foundation accounts is necessary for obtaining [Besu User Documentation]: https://besu.hyperledger.org -[Besu channel on Discord]: https://discord.gg/hyperledger +[Besu channel on Discord]: https://discord.com/invite/hyperledger [Contributing Guidelines]: CONTRIBUTING.md diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java index 21ca45070b..76e18812b0 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java @@ -27,7 +27,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.InProcessRpcConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.ipc.JsonRpcIpcConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; @@ -101,7 +101,7 @@ public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable private final boolean revertReasonEnabled; private final String name; - private MiningParameters miningParameters; + private MiningConfiguration miningConfiguration; private TransactionPoolConfiguration txPoolConfiguration; private final List runCommand; private PrivacyParameters privacyParameters = PrivacyParameters.DEFAULT; @@ -139,7 +139,7 @@ public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable public BesuNode( final String name, final Optional dataPath, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final TransactionPoolConfiguration txPoolConfiguration, final JsonRpcConfiguration jsonRpcConfiguration, final Optional engineRpcConfiguration, @@ -191,7 +191,7 @@ public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable }, () -> this.keyPair = KeyPairUtil.loadKeyPair(homeDirectory)); this.name = name; - this.miningParameters = miningParameters; + this.miningConfiguration = miningConfiguration; this.txPoolConfiguration = txPoolConfiguration; this.jsonRpcConfiguration = jsonRpcConfiguration; this.engineRpcConfiguration = engineRpcConfiguration; @@ -678,12 +678,12 @@ public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable this.bootnodes.addAll(bootnodes); } - public MiningParameters getMiningParameters() { - return miningParameters; + public MiningConfiguration getMiningParameters() { + return miningConfiguration; } - public void setMiningParameters(final MiningParameters miningParameters) { - this.miningParameters = miningParameters; + public void setMiningParameters(final MiningConfiguration miningConfiguration) { + this.miningConfiguration = miningConfiguration; } public TransactionPoolConfiguration getTransactionPoolConfiguration() { diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ProcessBesuNodeRunner.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ProcessBesuNodeRunner.java index 75307d9520..ee865a8142 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ProcessBesuNodeRunner.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ProcessBesuNodeRunner.java @@ -17,9 +17,9 @@ package org.hyperledger.besu.tests.acceptance.dsl.node; import static com.google.common.base.Preconditions.checkState; import static java.nio.charset.StandardCharsets.UTF_8; +import org.hyperledger.besu.cli.options.NetworkingOptions; import org.hyperledger.besu.cli.options.TransactionPoolOptions; import org.hyperledger.besu.cli.options.storage.DataStorageOptions; -import org.hyperledger.besu.cli.options.unstable.NetworkingOptions; import org.hyperledger.besu.ethereum.api.jsonrpc.ipc.JsonRpcIpcConfiguration; import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration; import org.hyperledger.besu.ethereum.p2p.rlpx.connections.netty.TLSConfiguration; diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java index 42c0df73c7..9effaff4d4 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java @@ -36,8 +36,8 @@ import org.hyperledger.besu.ethereum.api.ApiConfiguration; import org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.InProcessRpcConfiguration; import org.hyperledger.besu.ethereum.chain.Blockchain; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.plugins.PluginConfiguration; import org.hyperledger.besu.ethereum.core.plugins.PluginInfo; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; @@ -57,6 +57,7 @@ import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.MetricCategoryRegistryImpl; import org.hyperledger.besu.metrics.MetricsSystemModule; import org.hyperledger.besu.metrics.ObservableMetricsSystem; +import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; import org.hyperledger.besu.plugin.data.EnodeURL; import org.hyperledger.besu.plugin.services.BesuConfiguration; @@ -73,17 +74,21 @@ import org.hyperledger.besu.plugin.services.TransactionPoolValidatorService; import org.hyperledger.besu.plugin.services.TransactionSelectionService; import org.hyperledger.besu.plugin.services.TransactionSimulationService; import org.hyperledger.besu.plugin.services.metrics.MetricCategoryRegistry; +import org.hyperledger.besu.plugin.services.mining.MiningService; import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBPlugin; +import org.hyperledger.besu.plugin.services.transactionpool.TransactionPoolService; import org.hyperledger.besu.services.BesuConfigurationImpl; import org.hyperledger.besu.services.BesuEventsImpl; import org.hyperledger.besu.services.BesuPluginContextImpl; import org.hyperledger.besu.services.BlockchainServiceImpl; +import org.hyperledger.besu.services.MiningServiceImpl; import org.hyperledger.besu.services.PermissioningServiceImpl; import org.hyperledger.besu.services.PicoCLIOptionsImpl; import org.hyperledger.besu.services.PrivacyPluginServiceImpl; import org.hyperledger.besu.services.RpcEndpointServiceImpl; import org.hyperledger.besu.services.SecurityModuleServiceImpl; import org.hyperledger.besu.services.StorageServiceImpl; +import org.hyperledger.besu.services.TransactionPoolServiceImpl; import org.hyperledger.besu.services.TransactionPoolValidatorServiceImpl; import org.hyperledger.besu.services.TransactionSelectionServiceImpl; import org.hyperledger.besu.services.TransactionSimulationServiceImpl; @@ -214,6 +219,11 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner { besuController.getTransactionPool(), besuController.getSyncState(), besuController.getProtocolContext().getBadBlockManager())); + besuPluginContext.addService( + TransactionPoolService.class, + new TransactionPoolServiceImpl(besuController.getTransactionPool())); + besuPluginContext.addService( + MiningService.class, new MiningServiceImpl(besuController.getMiningCoordinator())); component.rpcEndpointService().init(runner.getInProcessRpcMethods()); @@ -326,7 +336,9 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner { @Singleton BlockchainServiceImpl provideBlockchainService(final BesuController besuController) { BlockchainServiceImpl retval = new BlockchainServiceImpl(); - retval.init(besuController.getProtocolContext(), besuController.getProtocolSchedule()); + retval.init( + besuController.getProtocolContext().getBlockchain(), + besuController.getProtocolSchedule()); return retval; } @@ -406,9 +418,18 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner { } } + @Module + public static class ThreadBesuNodeRunnerModule { + @Provides + @Singleton + public ThreadBesuNodeRunner provideThreadBesuNodeRunner() { + return new ThreadBesuNodeRunner(); + } + } + @Module @SuppressWarnings("CloseableProvides") - static class BesuControllerModule { + public static class BesuControllerModule { @Provides @Singleton public SynchronizerConfiguration provideSynchronizationConfiguration() { @@ -438,7 +459,7 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner { final BesuControllerBuilder builder, final MetricsSystem metricsSystem, final KeyValueStorageProvider storageProvider, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { builder .synchronizerConfiguration(synchronizerConfiguration) @@ -451,7 +472,7 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner { .evmConfiguration(EvmConfiguration.DEFAULT) .maxPeers(25) .maxRemotelyInitiatedPeers(15) - .miningParameters(miningParameters) + .miningParameters(miningConfiguration) .randomPeerPriority(false) .besuComponent(null); return builder.build(); @@ -484,6 +505,7 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner { final RpcEndpointServiceImpl rpcEndpointServiceImpl, final BesuConfiguration commonPluginConfiguration, final PermissioningServiceImpl permissioningService, + final MetricsConfiguration metricsConfiguration, final MetricCategoryRegistryImpl metricCategoryRegistry, final MetricsSystem metricsSystem, final @Named("ExtraCLIOptions") List extraCLIOptions, @@ -502,6 +524,7 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner { TransactionSimulationService.class, transactionSimulationServiceImpl); besuPluginContext.addService(BlockchainService.class, blockchainServiceImpl); besuPluginContext.addService(BesuConfiguration.class, commonPluginConfiguration); + metricCategoryRegistry.setMetricsConfiguration(metricsConfiguration); besuPluginContext.addService(MetricCategoryRegistry.class, metricCategoryRegistry); besuPluginContext.addService(MetricsSystem.class, metricsSystem); @@ -554,11 +577,11 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner { } @Provides - public MiningParameters provideMiningParameters( + public MiningConfiguration provideMiningParameters( final TransactionSelectionServiceImpl transactionSelectionServiceImpl, final BesuNode node) { final var miningParameters = - ImmutableMiningParameters.builder() + ImmutableMiningConfiguration.builder() .from(node.getMiningParameters()) .transactionSelectionService(transactionSelectionServiceImpl) .build(); @@ -569,17 +592,26 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner { @Provides @Inject BesuConfiguration provideBesuConfiguration( - final Path dataDir, final MiningParameters miningParameters, final BesuNode node) { + final Path dataDir, final MiningConfiguration miningConfiguration, final BesuNode node) { final BesuConfigurationImpl commonPluginConfiguration = new BesuConfigurationImpl(); commonPluginConfiguration.init( dataDir, dataDir.resolve(DATABASE_PATH), node.getDataStorageConfiguration()); - commonPluginConfiguration.withMiningParameters(miningParameters); + commonPluginConfiguration.withMiningParameters(miningConfiguration); return commonPluginConfiguration; } } @Module - static class MockBesuCommandModule { + public static class ObservableMetricsSystemModule { + @Provides + @Singleton + public ObservableMetricsSystem provideObservableMetricsSystem() { + return new NoOpMetricsSystem(); + } + } + + @Module + public static class MockBesuCommandModule { @Provides BesuCommand provideBesuCommand(final BesuPluginContextImpl pluginContext) { @@ -610,6 +642,8 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner { modules = { ThreadBesuNodeRunner.BesuControllerModule.class, ThreadBesuNodeRunner.MockBesuCommandModule.class, + ThreadBesuNodeRunner.ObservableMetricsSystemModule.class, + ThreadBesuNodeRunnerModule.class, BonsaiCachedMerkleTrieLoaderModule.class, MetricsSystemModule.class, ThreadBesuNodeRunner.BesuNodeProviderModule.class, @@ -625,5 +659,9 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner { RpcEndpointServiceImpl rpcEndpointService(); BlockchainServiceImpl blockchainService(); + + ObservableMetricsSystem getObservableMetricsSystem(); + + ThreadBesuNodeRunner getThreadBesuNodeRunner(); } } diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfiguration.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfiguration.java index ba69e4ddd7..5840f1e4f1 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfiguration.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfiguration.java @@ -21,7 +21,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.InProcessRpcConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.ipc.JsonRpcIpcConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration; @@ -40,7 +40,7 @@ public class BesuNodeConfiguration { private final String name; private final Optional dataPath; - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; private final TransactionPoolConfiguration transactionPoolConfiguration; private final JsonRpcConfiguration jsonRpcConfiguration; private final Optional engineRpcConfiguration; @@ -78,7 +78,7 @@ public class BesuNodeConfiguration { BesuNodeConfiguration( final String name, final Optional dataPath, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final TransactionPoolConfiguration transactionPoolConfiguration, final JsonRpcConfiguration jsonRpcConfiguration, final Optional engineRpcConfiguration, @@ -113,7 +113,7 @@ public class BesuNodeConfiguration { final boolean strictTxReplayProtectionEnabled, final Map environment) { this.name = name; - this.miningParameters = miningParameters; + this.miningConfiguration = miningConfiguration; this.transactionPoolConfiguration = transactionPoolConfiguration; this.jsonRpcConfiguration = jsonRpcConfiguration; this.engineRpcConfiguration = engineRpcConfiguration; @@ -154,8 +154,8 @@ public class BesuNodeConfiguration { return name; } - public MiningParameters getMiningParameters() { - return miningParameters; + public MiningConfiguration getMiningParameters() { + return miningConfiguration; } public TransactionPoolConfiguration getTransactionPoolConfiguration() { diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfigurationBuilder.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfigurationBuilder.java index ead01ce97d..9b000f56f1 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfigurationBuilder.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfigurationBuilder.java @@ -33,9 +33,9 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.ipc.JsonRpcIpcConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; import org.hyperledger.besu.ethereum.api.tls.FileBasedPasswordProvider; import org.hyperledger.besu.ethereum.core.AddressHelpers; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration; @@ -61,8 +61,8 @@ public class BesuNodeConfigurationBuilder { private String name; private Optional dataPath = Optional.empty(); - private MiningParameters miningParameters = - ImmutableMiningParameters.builder() + private MiningConfiguration miningConfiguration = + ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder().coinbase(AddressHelpers.ofValue(1)).build()) .build(); @@ -125,13 +125,14 @@ public class BesuNodeConfigurationBuilder { } public BesuNodeConfigurationBuilder miningEnabled(final boolean enabled) { - this.miningParameters = miningParameters.setMiningEnabled(enabled); + this.miningConfiguration = miningConfiguration.setMiningEnabled(enabled); this.jsonRpcConfiguration.addRpcApi(RpcApis.MINER.name()); return this; } - public BesuNodeConfigurationBuilder miningConfiguration(final MiningParameters miningParameters) { - this.miningParameters = miningParameters; + public BesuNodeConfigurationBuilder miningConfiguration( + final MiningConfiguration miningConfiguration) { + this.miningConfiguration = miningConfiguration; this.jsonRpcConfiguration.addRpcApi(RpcApis.MINER.name()); return this; } @@ -527,7 +528,7 @@ public class BesuNodeConfigurationBuilder { return new BesuNodeConfiguration( name, dataPath, - miningParameters, + miningConfiguration, transactionPoolConfiguration, jsonRpcConfiguration, Optional.of(engineRpcConfiguration), diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/BadCLIOptionsPlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/BadCLIOptionsPlugin.java index d9bde19b1e..ec048ea0d3 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/BadCLIOptionsPlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/BadCLIOptionsPlugin.java @@ -16,8 +16,8 @@ package org.hyperledger.besu.tests.acceptance.plugins; import static java.nio.charset.StandardCharsets.UTF_8; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.PicoCLIOptions; import java.io.File; @@ -39,7 +39,7 @@ public class BadCLIOptionsPlugin implements BesuPlugin { private File callbackDir; @Override - public void register(final BesuContext context) { + public void register(final ServiceManager context) { LOG.info("Registering BadCliOptionsPlugin"); callbackDir = new File(System.getProperty("besu.plugins.dir", "plugins")); writeStatus("init"); diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestBesuEventsPlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestBesuEventsPlugin.java index 44e728010c..7a4a17cf71 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestBesuEventsPlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestBesuEventsPlugin.java @@ -14,8 +14,8 @@ */ package org.hyperledger.besu.tests.acceptance.plugins; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.data.BlockHeader; import org.hyperledger.besu.plugin.data.PropagatedBlockContext; import org.hyperledger.besu.plugin.services.BesuEvents; @@ -35,14 +35,14 @@ import org.slf4j.LoggerFactory; public class TestBesuEventsPlugin implements BesuPlugin { private static final Logger LOG = LoggerFactory.getLogger(TestBesuEventsPlugin.class); - private BesuContext context; + private ServiceManager context; private Optional subscriptionId; private final AtomicInteger blockCounter = new AtomicInteger(); private File callbackDir; @Override - public void register(final BesuContext context) { + public void register(final ServiceManager context) { this.context = context; LOG.info("Registered"); callbackDir = new File(System.getProperty("besu.plugins.dir", "plugins")); diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestBlockchainServiceFinalizedPlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestBlockchainServiceFinalizedPlugin.java index a61b80ab8e..4984e7a00e 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestBlockchainServiceFinalizedPlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestBlockchainServiceFinalizedPlugin.java @@ -17,8 +17,8 @@ package org.hyperledger.besu.tests.acceptance.plugins; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.data.BlockContext; import org.hyperledger.besu.plugin.services.BlockchainService; import org.hyperledger.besu.plugin.services.RpcEndpointService; @@ -40,11 +40,11 @@ public class TestBlockchainServiceFinalizedPlugin implements BesuPlugin { private static final String RPC_METHOD_SAFE_BLOCK = "updateSafeBlockV1"; @Override - public void register(final BesuContext besuContext) { + public void register(final ServiceManager serviceManager) { LOG.trace("Registering plugin ..."); final RpcEndpointService rpcEndpointService = - besuContext + serviceManager .getService(RpcEndpointService.class) .orElseThrow( () -> @@ -52,7 +52,7 @@ public class TestBlockchainServiceFinalizedPlugin implements BesuPlugin { "Failed to obtain RpcEndpointService from the BesuContext.")); final BlockchainService blockchainService = - besuContext + serviceManager .getService(BlockchainService.class) .orElseThrow( () -> diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestInProcessRpcServicePlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestInProcessRpcServicePlugin.java index 3ebced0df9..adbc1a3579 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestInProcessRpcServicePlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestInProcessRpcServicePlugin.java @@ -15,8 +15,8 @@ package org.hyperledger.besu.tests.acceptance.plugins; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.PicoCLIOptions; import org.hyperledger.besu.plugin.services.RpcEndpointService; import org.hyperledger.besu.plugin.services.rpc.RpcResponseType; @@ -36,7 +36,7 @@ public class TestInProcessRpcServicePlugin implements BesuPlugin { long minGasPrice = -1; @Override - public void register(final BesuContext context) { + public void register(final ServiceManager context) { final PicoCLIOptions cmdlineOptions = context .getService(PicoCLIOptions.class) diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestMetricsPlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestMetricsPlugin.java new file mode 100644 index 0000000000..9400fb4bcc --- /dev/null +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestMetricsPlugin.java @@ -0,0 +1,76 @@ +/* + * Copyright contributors to Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.plugins; + +import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; +import org.hyperledger.besu.plugin.services.MetricsSystem; +import org.hyperledger.besu.plugin.services.metrics.MetricCategory; +import org.hyperledger.besu.plugin.services.metrics.MetricCategoryRegistry; + +import java.util.Locale; +import java.util.Optional; + +import com.google.auto.service.AutoService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@AutoService(BesuPlugin.class) +public class TestMetricsPlugin implements BesuPlugin { + private static final Logger LOG = LoggerFactory.getLogger(TestMetricsPlugin.class); + private ServiceManager serviceManager; + + @Override + public void register(final ServiceManager context) { + LOG.info("Registering TestMetricsPlugin"); + serviceManager = context; + context + .getService(MetricCategoryRegistry.class) + .orElseThrow() + .addMetricCategory(TestMetricCategory.TEST_METRIC_CATEGORY); + } + + @Override + public void start() { + LOG.info("Starting TestMetricsPlugin"); + serviceManager + .getService(MetricsSystem.class) + .orElseThrow() + .createGauge( + TestMetricCategory.TEST_METRIC_CATEGORY, + "test_metric", + "Returns 1 on success", + () -> 1.0); + } + + @Override + public void stop() { + LOG.info("Stopping TestMetricsPlugin"); + } + + public enum TestMetricCategory implements MetricCategory { + TEST_METRIC_CATEGORY; + + @Override + public String getName() { + return name().toLowerCase(Locale.ROOT); + } + + @Override + public Optional getApplicationPrefix() { + return Optional.of("plugin_test_"); + } + } +} diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java index 44afeeadaa..c2503ed811 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java @@ -14,8 +14,8 @@ */ package org.hyperledger.besu.tests.acceptance.plugins; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.PermissioningService; import org.hyperledger.besu.plugin.services.PicoCLIOptions; @@ -40,7 +40,7 @@ public class TestPermissioningPlugin implements BesuPlugin { PermissioningService service; @Override - public void register(final BesuContext context) { + public void register(final ServiceManager context) { context.getService(PicoCLIOptions.class).orElseThrow().addPicoCLIOptions("permissioning", this); service = context.getService(PermissioningService.class).orElseThrow(); } diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPicoCLIPlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPicoCLIPlugin.java index 375fbd490e..bb83ba676d 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPicoCLIPlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPicoCLIPlugin.java @@ -14,8 +14,8 @@ */ package org.hyperledger.besu.tests.acceptance.plugins; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.PicoCLIOptions; import java.io.File; @@ -57,7 +57,7 @@ public class TestPicoCLIPlugin implements BesuPlugin { private File callbackDir; @Override - public void register(final BesuContext context) { + public void register(final ServiceManager context) { LOG.info("Registering. Test Option is '{}'", testOption); state = "registering"; diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPrivacyServicePlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPrivacyServicePlugin.java index 4cdd35e8dc..698653f356 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPrivacyServicePlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPrivacyServicePlugin.java @@ -14,8 +14,8 @@ */ package org.hyperledger.besu.tests.acceptance.plugins; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.PicoCLIOptions; import org.hyperledger.besu.plugin.services.PrivacyPluginService; import org.hyperledger.besu.tests.acceptance.plugins.privacy.TestPrivacyGroupGenesisProvider; @@ -32,7 +32,7 @@ public class TestPrivacyServicePlugin implements BesuPlugin { private static final Logger LOG = LoggerFactory.getLogger(TestPrivacyServicePlugin.class); PrivacyPluginService pluginService; - BesuContext context; + ServiceManager context; TestPrivacyGroupGenesisProvider privacyGroupGenesisProvider = new TestPrivacyGroupGenesisProvider(); @@ -40,7 +40,7 @@ public class TestPrivacyServicePlugin implements BesuPlugin { new TestSigningPrivateMarkerTransactionFactory(); @Override - public void register(final BesuContext context) { + public void register(final ServiceManager context) { this.context = context; context diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestRpcEndpointServicePlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestRpcEndpointServicePlugin.java index 67980373ea..75d72473bf 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestRpcEndpointServicePlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestRpcEndpointServicePlugin.java @@ -16,8 +16,8 @@ package org.hyperledger.besu.tests.acceptance.plugins; import static com.google.common.base.Preconditions.checkArgument; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.RpcEndpointService; import org.hyperledger.besu.plugin.services.rpc.PluginRpcRequest; @@ -51,7 +51,7 @@ public class TestRpcEndpointServicePlugin implements BesuPlugin { } @Override - public void register(final BesuContext context) { + public void register(final ServiceManager context) { context .getService(RpcEndpointService.class) .ifPresent( diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/privacy/TestPrivacyPluginPayloadProvider.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/privacy/TestPrivacyPluginPayloadProvider.java index c375946c98..c4044fc432 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/privacy/TestPrivacyPluginPayloadProvider.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/privacy/TestPrivacyPluginPayloadProvider.java @@ -28,6 +28,7 @@ import org.apache.tuweni.bytes.Bytes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class TestPrivacyPluginPayloadProvider implements PrivacyPluginPayloadProvider { private static final Logger LOG = LoggerFactory.getLogger(TestPrivacyPluginPayloadProvider.class); private String prefix; diff --git a/acceptance-tests/tests/build.gradle b/acceptance-tests/tests/build.gradle index fdc7735452..b6c388172e 100644 --- a/acceptance-tests/tests/build.gradle +++ b/acceptance-tests/tests/build.gradle @@ -31,6 +31,7 @@ dependencies { api 'org.slf4j:slf4j-api' implementation project(':crypto:algorithms') + implementation project(':ethereum:eth') testImplementation project(':acceptance-tests:dsl') testImplementation project(':acceptance-tests:test-plugins') @@ -42,6 +43,7 @@ dependencies { testImplementation project(':ethereum:api') testImplementation project(':ethereum:core') testImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts') + testImplementation project(':ethereum:eth') testImplementation project(':ethereum:p2p') testImplementation project(':ethereum:permissioning') testImplementation project(':ethereum:rlp') @@ -78,6 +80,8 @@ dependencies { testImplementation 'org.web3j:besu' testImplementation 'org.web3j:core' testImplementation 'org.wiremock:wiremock' + testImplementation 'com.google.dagger:dagger' + testAnnotationProcessor 'com.google.dagger:dagger-compiler' testImplementation project(path: ':acceptance-tests:tests:shanghai') } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftMiningAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftMiningAcceptanceTest.java index 1e741a5cc6..177987aaaf 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftMiningAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftMiningAcceptanceTest.java @@ -17,9 +17,9 @@ package org.hyperledger.besu.tests.acceptance.bft; import org.hyperledger.besu.config.JsonUtil; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.AddressHelpers; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.tests.acceptance.dsl.account.Account; import org.hyperledger.besu.tests.acceptance.dsl.blockchain.Amount; import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; @@ -62,8 +62,8 @@ public class BftMiningAcceptanceTest extends ParameterizedBftTestBase { final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception { setUp(testName, nodeFactory); final BesuNode minerNode = nodeFactory.createNode(besu, "miner1"); - final MiningParameters zeroGasMiningParams = - ImmutableMiningParameters.builder() + final MiningConfiguration zeroGasMiningParams = + ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .isMiningEnabled(true) diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/MetricsPluginTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/MetricsPluginTest.java new file mode 100644 index 0000000000..7559200720 --- /dev/null +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/MetricsPluginTest.java @@ -0,0 +1,73 @@ +/* + * Copyright contributors to Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.tests.acceptance.plugins; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hyperledger.besu.tests.acceptance.plugins.TestMetricsPlugin.TestMetricCategory.TEST_METRIC_CATEGORY; + +import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; +import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; +import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; +import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.BesuNodeConfigurationBuilder; + +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.util.List; +import java.util.Set; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class MetricsPluginTest extends AcceptanceTestBase { + private BesuNode node; + private MetricsConfiguration metricsConfiguration; + + @BeforeEach + public void setUp() throws Exception { + metricsConfiguration = + MetricsConfiguration.builder() + .enabled(true) + .port(0) + .metricCategories(Set.of(TEST_METRIC_CATEGORY)) + .build(); + node = + besu.create( + new BesuNodeConfigurationBuilder() + .name("node1") + .plugins(List.of("testPlugins")) + .metricsConfiguration(metricsConfiguration) + .build()); + + cluster.start(node); + } + + @Test + public void metricCategoryAdded() throws IOException, InterruptedException { + final var httpClient = HttpClient.newHttpClient(); + final var req = HttpRequest.newBuilder(URI.create(node.metricsHttpUrl().get())).build(); + final var resp = httpClient.send(req, HttpResponse.BodyHandlers.ofLines()); + assertThat(resp.statusCode()).isEqualTo(200); + final var foundMetric = + resp.body() + .filter( + line -> line.startsWith(TEST_METRIC_CATEGORY.getApplicationPrefix().orElseThrow())) + .findFirst() + .orElseThrow(); + assertThat(foundMetric).endsWith("1.0"); + } +} diff --git a/besu/build.gradle b/besu/build.gradle index 41a4b11494..b6e506d9c1 100644 --- a/besu/build.gradle +++ b/besu/build.gradle @@ -49,7 +49,6 @@ dependencies { implementation project(':ethereum:eth') implementation project(':ethereum:p2p') implementation project(':ethereum:permissioning') - implementation project(':ethereum:retesteth') implementation project(':ethereum:rlp') implementation project(':ethereum:trie') implementation project(':ethereum:stratum') diff --git a/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java b/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java index 96eef547fe..06dca6c6f0 100644 --- a/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java @@ -23,7 +23,7 @@ import static org.hyperledger.besu.ethereum.core.PrivacyParameters.FLEXIBLE_PRIV import org.hyperledger.besu.cli.config.EthNetworkConfig; import org.hyperledger.besu.cli.config.NetworkName; -import org.hyperledger.besu.cli.options.stable.EthstatsOptions; +import org.hyperledger.besu.cli.options.EthstatsOptions; import org.hyperledger.besu.controller.BesuController; import org.hyperledger.besu.cryptoservices.NodeKey; import org.hyperledger.besu.ethereum.ProtocolContext; @@ -70,7 +70,7 @@ import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.manager.EthPeers; @@ -773,7 +773,7 @@ public class RunnerBuilder { final TransactionPool transactionPool = besuController.getTransactionPool(); final MiningCoordinator miningCoordinator = besuController.getMiningCoordinator(); - final MiningParameters miningParameters = besuController.getMiningParameters(); + final MiningConfiguration miningConfiguration = besuController.getMiningParameters(); final BlockchainQueries blockchainQueries = new BlockchainQueries( @@ -783,7 +783,7 @@ public class RunnerBuilder { Optional.of(dataDir.resolve(CACHE_PATH)), Optional.of(besuController.getProtocolManager().ethContext().getScheduler()), apiConfiguration, - miningParameters); + miningConfiguration); final PrivacyParameters privacyParameters = besuController.getPrivacyParameters(); @@ -802,7 +802,7 @@ public class RunnerBuilder { Optional stratumServer = Optional.empty(); - if (miningParameters.isStratumMiningEnabled()) { + if (miningConfiguration.isStratumMiningEnabled()) { if (!(miningCoordinator instanceof PoWMiningCoordinator powMiningCoordinator)) { throw new IllegalArgumentException( "Stratum mining requires the network option(--network) to be set to CLASSIC. Stratum server requires a PoWMiningCoordinator not " @@ -813,9 +813,9 @@ public class RunnerBuilder { new StratumServer( vertx, powMiningCoordinator, - miningParameters.getStratumPort(), - miningParameters.getStratumNetworkInterface(), - miningParameters.getUnstable().getStratumExtranonce(), + miningConfiguration.getStratumPort(), + miningConfiguration.getStratumNetworkInterface(), + miningConfiguration.getUnstable().getStratumExtranonce(), metricsSystem)); miningCoordinator.addEthHashObserver(stratumServer.get()); LOG.debug("added ethash observer: {}", stratumServer.get()); @@ -849,7 +849,7 @@ public class RunnerBuilder { blockchainQueries, synchronizer, transactionPool, - miningParameters, + miningConfiguration, miningCoordinator, metricsSystem, supportedCapabilities, @@ -896,7 +896,7 @@ public class RunnerBuilder { blockchainQueries, synchronizer, transactionPool, - miningParameters, + miningConfiguration, miningCoordinator, metricsSystem, supportedCapabilities, @@ -989,7 +989,7 @@ public class RunnerBuilder { blockchainQueries, synchronizer, transactionPool, - miningParameters, + miningConfiguration, miningCoordinator, metricsSystem, supportedCapabilities, @@ -1070,7 +1070,7 @@ public class RunnerBuilder { blockchainQueries, synchronizer, transactionPool, - miningParameters, + miningConfiguration, miningCoordinator, metricsSystem, supportedCapabilities, @@ -1111,7 +1111,7 @@ public class RunnerBuilder { blockchainQueries, synchronizer, transactionPool, - miningParameters, + miningConfiguration, miningCoordinator, metricsSystem, supportedCapabilities, @@ -1273,7 +1273,7 @@ public class RunnerBuilder { final BlockchainQueries blockchainQueries, final Synchronizer synchronizer, final TransactionPool transactionPool, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final MiningCoordinator miningCoordinator, final ObservableMetricsSystem metricsSystem, final Set supportedCapabilities, @@ -1308,7 +1308,7 @@ public class RunnerBuilder { protocolContext, filterManager, transactionPool, - miningParameters, + miningConfiguration, miningCoordinator, metricsSystem, supportedCapabilities, 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 886e3d6838..1a842acc58 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -37,45 +37,43 @@ import org.hyperledger.besu.chainimport.RlpBlockImporter; import org.hyperledger.besu.cli.config.EthNetworkConfig; import org.hyperledger.besu.cli.config.NetworkName; import org.hyperledger.besu.cli.config.ProfilesCompletionCandidates; -import org.hyperledger.besu.cli.converter.MetricCategoryConverter; import org.hyperledger.besu.cli.custom.JsonRPCAllowlistHostsProperty; import org.hyperledger.besu.cli.error.BesuExecutionExceptionHandler; import org.hyperledger.besu.cli.error.BesuParameterExceptionHandler; +import org.hyperledger.besu.cli.options.ApiConfigurationOptions; +import org.hyperledger.besu.cli.options.ChainPruningOptions; +import org.hyperledger.besu.cli.options.DnsOptions; +import org.hyperledger.besu.cli.options.EngineRPCConfiguration; +import org.hyperledger.besu.cli.options.EngineRPCOptions; +import org.hyperledger.besu.cli.options.EthProtocolOptions; +import org.hyperledger.besu.cli.options.EthstatsOptions; +import org.hyperledger.besu.cli.options.EvmOptions; +import org.hyperledger.besu.cli.options.GraphQlOptions; +import org.hyperledger.besu.cli.options.InProcessRpcOptions; +import org.hyperledger.besu.cli.options.IpcOptions; +import org.hyperledger.besu.cli.options.JsonRpcHttpOptions; +import org.hyperledger.besu.cli.options.LoggingLevelOption; +import org.hyperledger.besu.cli.options.MetricsOptions; import org.hyperledger.besu.cli.options.MiningOptions; +import org.hyperledger.besu.cli.options.NatOptions; +import org.hyperledger.besu.cli.options.NativeLibraryOptions; +import org.hyperledger.besu.cli.options.NetworkingOptions; +import org.hyperledger.besu.cli.options.NodePrivateKeyFileOption; +import org.hyperledger.besu.cli.options.P2PDiscoveryOptions; +import org.hyperledger.besu.cli.options.P2PTLSConfigOptions; +import org.hyperledger.besu.cli.options.PermissionsOptions; +import org.hyperledger.besu.cli.options.PluginsConfigurationOptions; +import org.hyperledger.besu.cli.options.PrivacyPluginOptions; +import org.hyperledger.besu.cli.options.RPCOptions; +import org.hyperledger.besu.cli.options.RpcWebsocketOptions; +import org.hyperledger.besu.cli.options.SynchronizerOptions; import org.hyperledger.besu.cli.options.TransactionPoolOptions; -import org.hyperledger.besu.cli.options.stable.ApiConfigurationOptions; -import org.hyperledger.besu.cli.options.stable.EngineRPCConfiguration; -import org.hyperledger.besu.cli.options.stable.EngineRPCOptions; -import org.hyperledger.besu.cli.options.stable.EthstatsOptions; -import org.hyperledger.besu.cli.options.stable.GraphQlOptions; -import org.hyperledger.besu.cli.options.stable.JsonRpcHttpOptions; -import org.hyperledger.besu.cli.options.stable.LoggingLevelOption; -import org.hyperledger.besu.cli.options.stable.MetricsOptions; -import org.hyperledger.besu.cli.options.stable.NodePrivateKeyFileOption; -import org.hyperledger.besu.cli.options.stable.P2PDiscoveryOptions; -import org.hyperledger.besu.cli.options.stable.PermissionsOptions; -import org.hyperledger.besu.cli.options.stable.PluginsConfigurationOptions; -import org.hyperledger.besu.cli.options.stable.RpcWebsocketOptions; import org.hyperledger.besu.cli.options.storage.DataStorageOptions; import org.hyperledger.besu.cli.options.storage.DiffBasedSubStorageOptions; -import org.hyperledger.besu.cli.options.unstable.ChainPruningOptions; -import org.hyperledger.besu.cli.options.unstable.DnsOptions; -import org.hyperledger.besu.cli.options.unstable.EthProtocolOptions; -import org.hyperledger.besu.cli.options.unstable.EvmOptions; -import org.hyperledger.besu.cli.options.unstable.InProcessRpcOptions; -import org.hyperledger.besu.cli.options.unstable.IpcOptions; -import org.hyperledger.besu.cli.options.unstable.NatOptions; -import org.hyperledger.besu.cli.options.unstable.NativeLibraryOptions; -import org.hyperledger.besu.cli.options.unstable.NetworkingOptions; -import org.hyperledger.besu.cli.options.unstable.P2PTLSConfigOptions; -import org.hyperledger.besu.cli.options.unstable.PrivacyPluginOptions; -import org.hyperledger.besu.cli.options.unstable.RPCOptions; -import org.hyperledger.besu.cli.options.unstable.SynchronizerOptions; import org.hyperledger.besu.cli.presynctasks.PreSynchronizationTaskRunner; import org.hyperledger.besu.cli.presynctasks.PrivateDatabaseMigrationPreSyncTask; import org.hyperledger.besu.cli.subcommands.PasswordSubCommand; import org.hyperledger.besu.cli.subcommands.PublicKeySubCommand; -import org.hyperledger.besu.cli.subcommands.RetestethSubCommand; import org.hyperledger.besu.cli.subcommands.TxParseSubCommand; import org.hyperledger.besu.cli.subcommands.ValidateConfigSubCommand; import org.hyperledger.besu.cli.subcommands.blocks.BlocksSubCommand; @@ -115,7 +113,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.ipc.JsonRpcIpcConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.chain.Blockchain; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.MiningParametersMetrics; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.VersionMetadata; @@ -170,8 +168,8 @@ import org.hyperledger.besu.plugin.services.TransactionPoolValidatorService; import org.hyperledger.besu.plugin.services.TransactionSelectionService; import org.hyperledger.besu.plugin.services.TransactionSimulationService; import org.hyperledger.besu.plugin.services.exception.StorageException; -import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.MetricCategoryRegistry; +import org.hyperledger.besu.plugin.services.mining.MiningService; import org.hyperledger.besu.plugin.services.p2p.P2PService; import org.hyperledger.besu.plugin.services.rlp.RlpConverterService; import org.hyperledger.besu.plugin.services.securitymodule.SecurityModule; @@ -184,6 +182,7 @@ import org.hyperledger.besu.services.BesuConfigurationImpl; import org.hyperledger.besu.services.BesuEventsImpl; import org.hyperledger.besu.services.BesuPluginContextImpl; import org.hyperledger.besu.services.BlockchainServiceImpl; +import org.hyperledger.besu.services.MiningServiceImpl; import org.hyperledger.besu.services.P2PServiceImpl; import org.hyperledger.besu.services.PermissioningServiceImpl; import org.hyperledger.besu.services.PicoCLIOptionsImpl; @@ -332,7 +331,6 @@ public class BesuCommand implements DefaultCommandValues, Runnable { private final Map environment; private final MetricCategoryRegistryImpl metricCategoryRegistry = new MetricCategoryRegistryImpl(); - private final MetricCategoryConverter metricCategoryConverter = new MetricCategoryConverter(); private final PreSynchronizationTaskRunner preSynchronizationTaskRunner = new PreSynchronizationTaskRunner(); @@ -342,7 +340,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable { Suppliers.memoize(this::readGenesisConfigFile); private final Supplier genesisConfigOptionsSupplier = Suppliers.memoize(this::readGenesisConfigOptions); - private final Supplier miningParametersSupplier = + private final Supplier miningParametersSupplier = Suppliers.memoize(this::getMiningParameters); private RocksDBPlugin rocksDBPlugin; @@ -509,77 +507,95 @@ public class BesuCommand implements DefaultCommandValues, Runnable { @CommandLine.ArgGroup(validate = false, heading = "@|bold In-Process RPC Options|@%n") InProcessRpcOptions inProcessRpcOptions = InProcessRpcOptions.create(); + private static final String PRIVACY_DEPRECATION_PREFIX = + "Deprecated. Tessera-based privacy is deprecated. See CHANGELOG for alternative options. "; + // Privacy Options Group - @CommandLine.ArgGroup(validate = false, heading = "@|bold Privacy Options|@%n") + @CommandLine.ArgGroup(validate = false, heading = "@|bold (Deprecated) Privacy Options |@%n") PrivacyOptionGroup privacyOptionGroup = new PrivacyOptionGroup(); static class PrivacyOptionGroup { @Option( names = {"--privacy-tls-enabled"}, paramLabel = MANDATORY_FILE_FORMAT_HELP, - description = "Enable TLS for connecting to privacy enclave (default: ${DEFAULT-VALUE})") + description = + PRIVACY_DEPRECATION_PREFIX + + "Enable TLS for connecting to privacy enclave (default: ${DEFAULT-VALUE})") private final Boolean isPrivacyTlsEnabled = false; @Option( names = "--privacy-tls-keystore-file", paramLabel = MANDATORY_FILE_FORMAT_HELP, description = - "Path to a PKCS#12 formatted keystore; used to enable TLS on inbound connections.") + PRIVACY_DEPRECATION_PREFIX + + "Path to a PKCS#12 formatted keystore; used to enable TLS on inbound connections.") private final Path privacyKeyStoreFile = null; @Option( names = "--privacy-tls-keystore-password-file", paramLabel = MANDATORY_FILE_FORMAT_HELP, - description = "Path to a file containing the password used to decrypt the keystore.") + description = + PRIVACY_DEPRECATION_PREFIX + + "Path to a file containing the password used to decrypt the keystore.") private final Path privacyKeyStorePasswordFile = null; @Option( names = "--privacy-tls-known-enclave-file", paramLabel = MANDATORY_FILE_FORMAT_HELP, description = - "Path to a file containing the fingerprints of the authorized privacy enclave.") + PRIVACY_DEPRECATION_PREFIX + + "Path to a file containing the fingerprints of the authorized privacy enclave.") private final Path privacyTlsKnownEnclaveFile = null; @Option( names = {"--privacy-enabled"}, - description = "Enable private transactions (default: ${DEFAULT-VALUE})") + description = + PRIVACY_DEPRECATION_PREFIX + "Enable private transactions (default: ${DEFAULT-VALUE})") private final Boolean isPrivacyEnabled = false; @Option( names = {"--privacy-multi-tenancy-enabled"}, - description = "Enable multi-tenant private transactions (default: ${DEFAULT-VALUE})") + description = + PRIVACY_DEPRECATION_PREFIX + + "Enable multi-tenant private transactions (default: ${DEFAULT-VALUE})") private final Boolean isPrivacyMultiTenancyEnabled = false; @Option( names = {"--privacy-url"}, - description = "The URL on which the enclave is running") + description = PRIVACY_DEPRECATION_PREFIX + "The URL on which the enclave is running") private final URI privacyUrl = PrivacyParameters.DEFAULT_ENCLAVE_URL; @Option( names = {"--privacy-public-key-file"}, - description = "The enclave's public key file") + description = PRIVACY_DEPRECATION_PREFIX + "The enclave's public key file") private final File privacyPublicKeyFile = null; @Option( names = {"--privacy-marker-transaction-signing-key-file"}, description = - "The name of a file containing the private key used to sign privacy marker transactions. If unset, each will be signed with a random key.") + PRIVACY_DEPRECATION_PREFIX + + "The name of a file containing the private key used to sign privacy marker transactions. If unset, each will be signed with a random key.") private final Path privateMarkerTransactionSigningKeyPath = null; @Option( names = {"--privacy-enable-database-migration"}, - description = "Enable private database metadata migration (default: ${DEFAULT-VALUE})") + description = + PRIVACY_DEPRECATION_PREFIX + + "Enable private database metadata migration (default: ${DEFAULT-VALUE})") private final Boolean migratePrivateDatabase = false; @Option( names = {"--privacy-flexible-groups-enabled"}, - description = "Enable flexible privacy groups (default: ${DEFAULT-VALUE})") + description = + PRIVACY_DEPRECATION_PREFIX + + "Enable flexible privacy groups (default: ${DEFAULT-VALUE})") private final Boolean isFlexiblePrivacyGroupsEnabled = false; @Option( names = {"--privacy-nonce-always-increments"}, description = - "Enable private nonce " + PRIVACY_DEPRECATION_PREFIX + + "Enable private nonce " + "incrementation even if the transaction didn't succeeded (default: ${DEFAULT-VALUE})") private final Boolean isPrivateNonceAlwaysIncrementsEnabled = false; } @@ -1108,7 +1124,6 @@ public class BesuCommand implements DefaultCommandValues, Runnable { PublicKeySubCommand.COMMAND_NAME, new PublicKeySubCommand(commandLine.getOut())); commandLine.addSubcommand( PasswordSubCommand.COMMAND_NAME, new PasswordSubCommand(commandLine.getOut())); - commandLine.addSubcommand(RetestethSubCommand.COMMAND_NAME, new RetestethSubCommand()); commandLine.addSubcommand( RLPSubCommand.COMMAND_NAME, new RLPSubCommand(commandLine.getOut(), in)); commandLine.addSubcommand( @@ -1136,10 +1151,6 @@ public class BesuCommand implements DefaultCommandValues, Runnable { commandLine.registerConverter(Hash.class, Hash::fromHexString); commandLine.registerConverter(Optional.class, Optional::of); commandLine.registerConverter(Double.class, Double::parseDouble); - - metricCategoryConverter.addCategories(BesuMetricCategory.class); - metricCategoryConverter.addCategories(StandardMetricCategory.class); - commandLine.registerConverter(MetricCategory.class, metricCategoryConverter); } private void handleStableOptions() { @@ -1174,6 +1185,9 @@ public class BesuCommand implements DefaultCommandValues, Runnable { besuPluginContext.addService(PicoCLIOptions.class, new PicoCLIOptionsImpl(commandLine)); besuPluginContext.addService(SecurityModuleService.class, securityModuleService); besuPluginContext.addService(StorageService.class, storageService); + + metricCategoryRegistry.addCategories(BesuMetricCategory.class); + metricCategoryRegistry.addCategories(StandardMetricCategory.class); besuPluginContext.addService(MetricCategoryRegistry.class, metricCategoryRegistry); besuPluginContext.addService(PermissioningService.class, permissioningService); besuPluginContext.addService(PrivacyPluginService.class, privacyPluginService); @@ -1191,10 +1205,6 @@ public class BesuCommand implements DefaultCommandValues, Runnable { rocksDBPlugin.register(besuPluginContext); new InMemoryStoragePlugin().register(besuPluginContext); - metricCategoryRegistry - .getMetricCategories() - .forEach(metricCategoryConverter::addRegistryCategory); - // register default security module securityModuleService.register( DEFAULT_SECURITY_MODULE, Suppliers.memoize(this::defaultSecurityModule)); @@ -1243,7 +1253,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable { private void startPlugins(final Runner runner) { blockchainServiceImpl.init( - besuController.getProtocolContext(), besuController.getProtocolSchedule()); + besuController.getProtocolContext().getBlockchain(), besuController.getProtocolSchedule()); transactionSimulationServiceImpl.init( besuController.getProtocolContext().getBlockchain(), new TransactionSimulator( @@ -1293,6 +1303,9 @@ public class BesuCommand implements DefaultCommandValues, Runnable { miningParametersSupplier.get()), besuController.getProtocolSchedule())); + besuPluginContext.addService( + MiningService.class, new MiningServiceImpl(besuController.getMiningCoordinator())); + besuController.getAdditionalPluginServices().appendPluginServices(besuPluginContext); besuPluginContext.startPlugins(); } @@ -1303,6 +1316,8 @@ public class BesuCommand implements DefaultCommandValues, Runnable { // after start has been called on plugins if (Boolean.TRUE.equals(privacyOptionGroup.isPrivacyEnabled)) { + logger.warn( + "--Xprivacy-plugin-enabled and related options are " + PRIVACY_DEPRECATION_PREFIX); if (privacyOptionGroup.privateMarkerTransactionSigningKeyPath != null && privacyPluginService != null @@ -1342,7 +1357,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable { private void setReleaseMetrics() { besuComponent .getMetricsSystem() - .createLabelledGauge( + .createLabelledSuppliedGauge( StandardMetricCategory.PROCESS, "release", "Release information", "version") .labels(() -> 1, BesuInfo.version()); } @@ -1891,6 +1906,10 @@ public class BesuCommand implements DefaultCommandValues, Runnable { "--metrics-push-interval", "--metrics-push-prometheus-job")); + metricsOptions.setMetricCategoryRegistry(metricCategoryRegistry); + + metricsOptions.validate(commandLine); + final MetricsConfiguration.Builder metricsConfigurationBuilder = metricsOptions.toDomainObject(); metricsConfigurationBuilder @@ -1903,7 +1922,9 @@ public class BesuCommand implements DefaultCommandValues, Runnable { ? p2PDiscoveryOptions.autoDiscoverDefaultIP().getHostAddress() : metricsOptions.getMetricsPushHost()) .hostsAllowlist(hostsAllowlist); - return metricsConfigurationBuilder.build(); + final var metricsConfiguration = metricsConfigurationBuilder.build(); + metricCategoryRegistry.setMetricsConfiguration(metricsConfiguration); + return metricsConfiguration; } private PrivacyParameters privacyParameters() { @@ -1926,6 +1947,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable { final PrivacyParameters.Builder privacyParametersBuilder = new PrivacyParameters.Builder(); if (Boolean.TRUE.equals(privacyOptionGroup.isPrivacyEnabled)) { + logger.warn("--privacy-enabled and related options are " + PRIVACY_DEPRECATION_PREFIX); final String errorSuffix = "cannot be enabled with privacy."; if (syncMode == SyncMode.FAST) { throw new ParameterException(commandLine, String.format("%s %s", "Fast sync", errorSuffix)); @@ -2121,7 +2143,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable { return txPoolConfBuilder.build(); } - private MiningParameters getMiningParameters() { + private MiningConfiguration getMiningParameters() { miningOptions.setTransactionSelectionService(transactionSelectionServiceImpl); final var miningParameters = miningOptions.toDomainObject(); getGenesisBlockPeriodSeconds(genesisConfigOptionsSupplier.get()) @@ -2173,8 +2195,8 @@ public class BesuCommand implements DefaultCommandValues, Runnable { return dataStorageConfiguration; } - private void initMiningParametersMetrics(final MiningParameters miningParameters) { - new MiningParametersMetrics(getMetricsSystem(), miningParameters); + private void initMiningParametersMetrics(final MiningConfiguration miningConfiguration) { + new MiningParametersMetrics(getMetricsSystem(), miningConfiguration); } private OptionalInt getGenesisBlockPeriodSeconds( diff --git a/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java b/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java index b3dfa2a054..a7b43d0d9e 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java @@ -433,14 +433,18 @@ public class ConfigurationOverviewBuilder { private void detectJemalloc(final List lines) { Optional.ofNullable(Objects.isNull(environment) ? null : environment.get("BESU_USING_JEMALLOC")) .ifPresentOrElse( - t -> { + jemallocEnabled -> { try { - final String version = PlatformDetector.getJemalloc(); - lines.add("jemalloc: " + version); + if (Boolean.parseBoolean(jemallocEnabled)) { + final String version = PlatformDetector.getJemalloc(); + lines.add("jemalloc: " + version); + } else { + logger.warn( + "besu_using_jemalloc is present but is not set to true, jemalloc library not loaded"); + } } catch (final Throwable throwable) { logger.warn( - "BESU_USING_JEMALLOC is present but we failed to load jemalloc library to get the version", - throwable); + "besu_using_jemalloc is present but we failed to load jemalloc library to get the version"); } }, () -> { diff --git a/besu/src/main/java/org/hyperledger/besu/cli/converter/MetricCategoryConverter.java b/besu/src/main/java/org/hyperledger/besu/cli/converter/MetricCategoryConverter.java deleted file mode 100644 index 339da86b2d..0000000000 --- a/besu/src/main/java/org/hyperledger/besu/cli/converter/MetricCategoryConverter.java +++ /dev/null @@ -1,73 +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.cli.converter; - -import org.hyperledger.besu.plugin.services.metrics.MetricCategory; - -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -import com.google.common.annotations.VisibleForTesting; -import picocli.CommandLine; - -/** The Metric category converter for CLI options. */ -public class MetricCategoryConverter implements CommandLine.ITypeConverter { - - private final Map metricCategories = new HashMap<>(); - - /** Default Constructor. */ - public MetricCategoryConverter() {} - - @Override - public MetricCategory convert(final String value) { - final MetricCategory category = metricCategories.get(value); - if (category == null) { - throw new IllegalArgumentException("Unknown category: " + value); - } - return category; - } - - /** - * Add Metrics categories. - * - * @param the type parameter - * @param categoryEnum the category enum - */ - public & MetricCategory> void addCategories(final Class categoryEnum) { - EnumSet.allOf(categoryEnum) - .forEach(category -> metricCategories.put(category.name(), category)); - } - - /** - * Add registry category. - * - * @param metricCategory the metric category - */ - public void addRegistryCategory(final MetricCategory metricCategory) { - metricCategories.put(metricCategory.getName().toUpperCase(Locale.ROOT), metricCategory); - } - - /** - * Gets metric categories. - * - * @return the metric categories - */ - @VisibleForTesting - Map getMetricCategories() { - return metricCategories; - } -} diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/ApiConfigurationOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/ApiConfigurationOptions.java similarity index 99% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/ApiConfigurationOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/ApiConfigurationOptions.java index d6bc17026c..c5954f5063 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/ApiConfigurationOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/ApiConfigurationOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import static java.util.Arrays.asList; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/ChainPruningOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/ChainPruningOptions.java similarity index 98% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/ChainPruningOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/ChainPruningOptions.java index 0a59ef9b04..3f26b676ce 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/ChainPruningOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/ChainPruningOptions.java @@ -12,9 +12,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; -import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.ethereum.chain.ChainPrunerConfiguration; import org.hyperledger.besu.util.number.PositiveNumber; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/DnsOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/DnsOptions.java similarity index 96% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/DnsOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/DnsOptions.java index 9f9670e8e6..9a720bebbb 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/DnsOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/DnsOptions.java @@ -12,9 +12,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; -import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.ethereum.p2p.peers.EnodeDnsConfiguration; import org.hyperledger.besu.ethereum.p2p.peers.ImmutableEnodeDnsConfiguration; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/EngineRPCConfiguration.java b/besu/src/main/java/org/hyperledger/besu/cli/options/EngineRPCConfiguration.java similarity index 96% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/EngineRPCConfiguration.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/EngineRPCConfiguration.java index c0eb9d1be0..ec98204d3b 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/EngineRPCConfiguration.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/EngineRPCConfiguration.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import org.hyperledger.besu.cli.custom.JsonRPCAllowlistHostsProperty; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/EngineRPCOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/EngineRPCOptions.java similarity index 96% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/EngineRPCOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/EngineRPCOptions.java index 1aa5b3d326..e660e6c821 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/EngineRPCOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/EngineRPCOptions.java @@ -12,13 +12,12 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration.DEFAULT_ENGINE_JSON_RPC_PORT; import org.hyperledger.besu.cli.DefaultCommandValues; import org.hyperledger.besu.cli.custom.JsonRPCAllowlistHostsProperty; -import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.cli.util.CommandLineUtils; import java.nio.file.Path; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/EthProtocolOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/EthProtocolOptions.java similarity index 97% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/EthProtocolOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/EthProtocolOptions.java index 1d5434ff02..a20403027d 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/EthProtocolOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/EthProtocolOptions.java @@ -12,10 +12,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; -import org.hyperledger.besu.cli.options.CLIOptions; -import org.hyperledger.besu.cli.options.OptionParser; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.util.number.PositiveNumber; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/EthstatsOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/EthstatsOptions.java similarity index 96% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/EthstatsOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/EthstatsOptions.java index a6e939fdf0..08e8b49c52 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/EthstatsOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/EthstatsOptions.java @@ -12,9 +12,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; -import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.ethstats.util.EthStatsConnectOptions; import java.nio.file.Path; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/EvmOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/EvmOptions.java similarity index 96% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/EvmOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/EvmOptions.java index 39d95324df..6a58d6830a 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/EvmOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/EvmOptions.java @@ -12,9 +12,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; -import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.evm.internal.EvmConfiguration; import java.util.List; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/GraphQlOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/GraphQlOptions.java similarity index 98% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/GraphQlOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/GraphQlOptions.java index 6aac24a6fb..643ca22e00 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/GraphQlOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/GraphQlOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import static java.util.Arrays.asList; import static org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration.DEFAULT_GRAPHQL_HTTP_PORT; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/InProcessRpcOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/InProcessRpcOptions.java similarity index 96% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/InProcessRpcOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/InProcessRpcOptions.java index 9adeb37db7..278a55e187 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/InProcessRpcOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/InProcessRpcOptions.java @@ -12,12 +12,11 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; import static org.hyperledger.besu.ethereum.api.jsonrpc.InProcessRpcConfiguration.DEFAULT_IN_PROCESS_RPC_APIS; import static org.hyperledger.besu.ethereum.api.jsonrpc.InProcessRpcConfiguration.DEFAULT_IN_PROCESS_RPC_ENABLED; -import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.cli.util.CommandLineUtils; import org.hyperledger.besu.ethereum.api.jsonrpc.ImmutableInProcessRpcConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.InProcessRpcConfiguration; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/IpcOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/IpcOptions.java similarity index 98% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/IpcOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/IpcOptions.java index 19ba294193..689ac4e9b3 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/IpcOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/IpcOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.DEFAULT_RPC_APIS; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/JsonRpcHttpOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/JsonRpcHttpOptions.java similarity index 99% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/JsonRpcHttpOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/JsonRpcHttpOptions.java index 7d08a6f9aa..c8c2c73344 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/JsonRpcHttpOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/JsonRpcHttpOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import static java.util.Arrays.asList; import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration.DEFAULT_JSON_RPC_HOST; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/LoggingLevelOption.java b/besu/src/main/java/org/hyperledger/besu/cli/options/LoggingLevelOption.java similarity index 97% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/LoggingLevelOption.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/LoggingLevelOption.java index 39b2a2482b..1a498fd196 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/LoggingLevelOption.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/LoggingLevelOption.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import java.util.Locale; import java.util.Set; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/MetricsOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/MetricsOptions.java similarity index 83% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/MetricsOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/MetricsOptions.java index 4906cf538e..1f777286bf 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/MetricsOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/MetricsOptions.java @@ -12,8 +12,10 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; +import static com.google.common.base.Preconditions.checkState; +import static java.util.stream.Collectors.toUnmodifiableSet; import static org.hyperledger.besu.cli.DefaultCommandValues.MANDATORY_HOST_FORMAT_HELP; import static org.hyperledger.besu.cli.DefaultCommandValues.MANDATORY_INTEGER_FORMAT_HELP; import static org.hyperledger.besu.cli.DefaultCommandValues.MANDATORY_PORT_FORMAT_HELP; @@ -22,8 +24,8 @@ import static org.hyperledger.besu.metrics.MetricsProtocol.PROMETHEUS; import static org.hyperledger.besu.metrics.prometheus.MetricsConfiguration.DEFAULT_METRICS_PORT; import static org.hyperledger.besu.metrics.prometheus.MetricsConfiguration.DEFAULT_METRICS_PUSH_PORT; -import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.cli.util.CommandLineUtils; +import org.hyperledger.besu.metrics.MetricCategoryRegistryImpl; import org.hyperledger.besu.metrics.MetricsProtocol; import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; @@ -36,6 +38,7 @@ import picocli.CommandLine; /** Command line options for configuring metrics. */ // TODO: implement CLIOption public class MetricsOptions implements CLIOptions { + private MetricCategoryRegistryImpl metricCategoryRegistry; /** * Returns a MetricsConfiguration.Builder because fields are often overridden from other domains, @@ -77,7 +80,10 @@ public class MetricsOptions implements CLIOptions metricsOptions.metricsHost = config.getHost(); metricsOptions.metricsPort = config.getPort(); metricsOptions.metricsProtocol = config.getProtocol(); - metricsOptions.metricCategories = config.getMetricCategories(); + metricsOptions.metricCategories = + config.getMetricCategories().stream() + .map(MetricCategory::getName) + .collect(toUnmodifiableSet()); metricsOptions.metricsPrometheusJob = config.getPrometheusJob(); metricsOptions.isMetricsPushEnabled = config.isPushEnabled(); metricsOptions.metricsPushHost = config.getPushHost(); @@ -126,7 +132,8 @@ public class MetricsOptions implements CLIOptions arity = "1..*", description = "Comma separated list of categories to track metrics for (default: ${DEFAULT-VALUE})") - private Set metricCategories = DEFAULT_METRIC_CATEGORIES; + private Set metricCategories = + DEFAULT_METRIC_CATEGORIES.stream().map(MetricCategory::getName).collect(toUnmodifiableSet()); @CommandLine.Option( names = {"--metrics-push-enabled"}, @@ -216,7 +223,13 @@ public class MetricsOptions implements CLIOptions * @return the metric categories */ public Set getMetricCategories() { - return metricCategories; + checkState( + metricCategoryRegistry != null, "Set metricCategoryRegistry before calling this method"); + + final var list = + metricCategories.stream().map(metricCategoryRegistry::getMetricCategory).toList(); + + return Set.copyOf(list); } /** @@ -264,6 +277,33 @@ public class MetricsOptions implements CLIOptions return metricsPrometheusJob; } + /** + * Perform final validation after all the options, and the metric category registry, have been set + * + * @param commandLine the command line + */ + public void validate(final CommandLine commandLine) { + checkState( + metricCategoryRegistry != null, "Set metricCategoryRegistry before calling this method"); + final var unknownCategories = + metricCategories.stream() + .filter(category -> !metricCategoryRegistry.containsMetricCategory(category)) + .toList(); + if (!unknownCategories.isEmpty()) { + throw new CommandLine.ParameterException( + commandLine, "--metrics-categories contains unknown categories: " + unknownCategories); + } + } + + /** + * Set the metric category registry in order to support verification and conversion + * + * @param metricCategoryRegistry the metric category registry + */ + public void setMetricCategoryRegistry(final MetricCategoryRegistryImpl metricCategoryRegistry) { + this.metricCategoryRegistry = metricCategoryRegistry; + } + @CommandLine.ArgGroup(validate = false) private final MetricsOptions.Unstable unstableOptions = new MetricsOptions.Unstable(); diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/MiningOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/MiningOptions.java index a884edfe33..fa0cf4dc06 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/MiningOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/MiningOptions.java @@ -17,27 +17,27 @@ package org.hyperledger.besu.cli.options; import static com.google.common.base.Preconditions.checkNotNull; import static java.util.Arrays.asList; import static java.util.Collections.singletonList; -import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME; -import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_POA_BLOCK_TXS_SELECTION_MAX_TIME; -import static org.hyperledger.besu.ethereum.core.MiningParameters.MutableInitValues.DEFAULT_EXTRA_DATA; -import static org.hyperledger.besu.ethereum.core.MiningParameters.MutableInitValues.DEFAULT_MIN_BLOCK_OCCUPANCY_RATIO; -import static org.hyperledger.besu.ethereum.core.MiningParameters.MutableInitValues.DEFAULT_MIN_PRIORITY_FEE_PER_GAS; -import static org.hyperledger.besu.ethereum.core.MiningParameters.MutableInitValues.DEFAULT_MIN_TRANSACTION_GAS_PRICE; -import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_MAX_OMMERS_DEPTH; -import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_POS_BLOCK_CREATION_MAX_TIME; -import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_POS_BLOCK_CREATION_REPETITION_MIN_DURATION; -import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_POW_JOB_TTL; -import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_REMOTE_SEALERS_LIMIT; -import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_REMOTE_SEALERS_TTL; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.DEFAULT_POA_BLOCK_TXS_SELECTION_MAX_TIME; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.MutableInitValues.DEFAULT_EXTRA_DATA; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.MutableInitValues.DEFAULT_MIN_BLOCK_OCCUPANCY_RATIO; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.MutableInitValues.DEFAULT_MIN_PRIORITY_FEE_PER_GAS; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.MutableInitValues.DEFAULT_MIN_TRANSACTION_GAS_PRICE; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.Unstable.DEFAULT_MAX_OMMERS_DEPTH; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.Unstable.DEFAULT_POS_BLOCK_CREATION_MAX_TIME; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.Unstable.DEFAULT_POS_BLOCK_CREATION_REPETITION_MIN_DURATION; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.Unstable.DEFAULT_POW_JOB_TTL; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.Unstable.DEFAULT_REMOTE_SEALERS_LIMIT; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.Unstable.DEFAULT_REMOTE_SEALERS_TTL; import org.hyperledger.besu.cli.converter.PositiveNumberConverter; import org.hyperledger.besu.cli.util.CommandLineUtils; import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.plugin.services.TransactionSelectionService; import org.hyperledger.besu.util.number.PositiveNumber; @@ -50,7 +50,7 @@ import picocli.CommandLine.Option; import picocli.CommandLine.ParameterException; /** The Mining CLI options. */ -public class MiningOptions implements CLIOptions { +public class MiningOptions implements CLIOptions { @Option( names = {"--miner-enabled"}, @@ -300,43 +300,45 @@ public class MiningOptions implements CLIOptions { } } - static MiningOptions fromConfig(final MiningParameters miningParameters) { + static MiningOptions fromConfig(final MiningConfiguration miningConfiguration) { final MiningOptions miningOptions = MiningOptions.create(); - miningOptions.setTransactionSelectionService(miningParameters.getTransactionSelectionService()); - miningOptions.isMiningEnabled = miningParameters.isMiningEnabled(); - miningOptions.iStratumMiningEnabled = miningParameters.isStratumMiningEnabled(); - miningOptions.stratumNetworkInterface = miningParameters.getStratumNetworkInterface(); - miningOptions.stratumPort = miningParameters.getStratumPort(); - miningOptions.extraData = miningParameters.getExtraData(); - miningOptions.minTransactionGasPrice = miningParameters.getMinTransactionGasPrice(); - miningOptions.minPriorityFeePerGas = miningParameters.getMinPriorityFeePerGas(); - miningOptions.minBlockOccupancyRatio = miningParameters.getMinBlockOccupancyRatio(); + miningOptions.setTransactionSelectionService( + miningConfiguration.getTransactionSelectionService()); + miningOptions.isMiningEnabled = miningConfiguration.isMiningEnabled(); + miningOptions.iStratumMiningEnabled = miningConfiguration.isStratumMiningEnabled(); + miningOptions.stratumNetworkInterface = miningConfiguration.getStratumNetworkInterface(); + miningOptions.stratumPort = miningConfiguration.getStratumPort(); + miningOptions.extraData = miningConfiguration.getExtraData(); + miningOptions.minTransactionGasPrice = miningConfiguration.getMinTransactionGasPrice(); + miningOptions.minPriorityFeePerGas = miningConfiguration.getMinPriorityFeePerGas(); + miningOptions.minBlockOccupancyRatio = miningConfiguration.getMinBlockOccupancyRatio(); miningOptions.nonPoaBlockTxsSelectionMaxTime = - miningParameters.getNonPoaBlockTxsSelectionMaxTime(); - miningOptions.poaBlockTxsSelectionMaxTime = miningParameters.getPoaBlockTxsSelectionMaxTime(); + miningConfiguration.getNonPoaBlockTxsSelectionMaxTime(); + miningOptions.poaBlockTxsSelectionMaxTime = + miningConfiguration.getPoaBlockTxsSelectionMaxTime(); miningOptions.unstableOptions.remoteSealersLimit = - miningParameters.getUnstable().getRemoteSealersLimit(); + miningConfiguration.getUnstable().getRemoteSealersLimit(); miningOptions.unstableOptions.remoteSealersTimeToLive = - miningParameters.getUnstable().getRemoteSealersTimeToLive(); + miningConfiguration.getUnstable().getRemoteSealersTimeToLive(); miningOptions.unstableOptions.powJobTimeToLive = - miningParameters.getUnstable().getPowJobTimeToLive(); + miningConfiguration.getUnstable().getPowJobTimeToLive(); miningOptions.unstableOptions.maxOmmersDepth = - miningParameters.getUnstable().getMaxOmmerDepth(); + miningConfiguration.getUnstable().getMaxOmmerDepth(); miningOptions.unstableOptions.stratumExtranonce = - miningParameters.getUnstable().getStratumExtranonce(); + miningConfiguration.getUnstable().getStratumExtranonce(); miningOptions.unstableOptions.posBlockCreationMaxTime = - miningParameters.getUnstable().getPosBlockCreationMaxTime(); + miningConfiguration.getUnstable().getPosBlockCreationMaxTime(); miningOptions.unstableOptions.posBlockCreationRepetitionMinDuration = - miningParameters.getUnstable().getPosBlockCreationRepetitionMinDuration(); + miningConfiguration.getUnstable().getPosBlockCreationRepetitionMinDuration(); - miningParameters.getCoinbase().ifPresent(coinbase -> miningOptions.coinbase = coinbase); - miningParameters.getTargetGasLimit().ifPresent(tgl -> miningOptions.targetGasLimit = tgl); + miningConfiguration.getCoinbase().ifPresent(coinbase -> miningOptions.coinbase = coinbase); + miningConfiguration.getTargetGasLimit().ifPresent(tgl -> miningOptions.targetGasLimit = tgl); return miningOptions; } @Override - public MiningParameters toDomainObject() { + public MiningConfiguration toDomainObject() { checkNotNull( transactionSelectionService, "transactionSelectionService must be set before using this object"); @@ -356,7 +358,7 @@ public class MiningOptions implements CLIOptions { updatableInitValuesBuilder.coinbase(coinbase); } - return ImmutableMiningParameters.builder() + return ImmutableMiningConfiguration.builder() .transactionSelectionService(transactionSelectionService) .mutableInitValues(updatableInitValuesBuilder.build()) .isStratumMiningEnabled(iStratumMiningEnabled) @@ -365,7 +367,7 @@ public class MiningOptions implements CLIOptions { .nonPoaBlockTxsSelectionMaxTime(nonPoaBlockTxsSelectionMaxTime) .poaBlockTxsSelectionMaxTime(poaBlockTxsSelectionMaxTime) .unstable( - ImmutableMiningParameters.Unstable.builder() + ImmutableMiningConfiguration.Unstable.builder() .remoteSealersLimit(unstableOptions.remoteSealersLimit) .remoteSealersTimeToLive(unstableOptions.remoteSealersTimeToLive) .powJobTimeToLive(unstableOptions.powJobTimeToLive) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NatOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/NatOptions.java similarity index 97% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NatOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/NatOptions.java index 31716543d5..11e8051d0e 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NatOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/NatOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; import static org.hyperledger.besu.nat.kubernetes.KubernetesNatManager.DEFAULT_BESU_SERVICE_NAME_FILTER; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NativeLibraryOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/NativeLibraryOptions.java similarity index 98% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NativeLibraryOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/NativeLibraryOptions.java index ec7f043b8f..f3fc9c3ba4 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NativeLibraryOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/NativeLibraryOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; import picocli.CommandLine; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NetworkingOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/NetworkingOptions.java similarity index 96% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NetworkingOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/NetworkingOptions.java index aed7b079d8..dc001d0231 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NetworkingOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/NetworkingOptions.java @@ -12,10 +12,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; -import org.hyperledger.besu.cli.options.CLIOptions; -import org.hyperledger.besu.cli.options.OptionParser; import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration; import java.util.Arrays; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/NodePrivateKeyFileOption.java b/besu/src/main/java/org/hyperledger/besu/cli/options/NodePrivateKeyFileOption.java similarity index 96% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/NodePrivateKeyFileOption.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/NodePrivateKeyFileOption.java index 107ced545d..781dcb06e8 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/NodePrivateKeyFileOption.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/NodePrivateKeyFileOption.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import static org.hyperledger.besu.cli.DefaultCommandValues.MANDATORY_PATH_FORMAT_HELP; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/P2PDiscoveryOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/P2PDiscoveryOptions.java similarity index 98% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/P2PDiscoveryOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/P2PDiscoveryOptions.java index a15be99dc7..798d246b52 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/P2PDiscoveryOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/P2PDiscoveryOptions.java @@ -12,12 +12,11 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import org.hyperledger.besu.cli.DefaultCommandValues; import org.hyperledger.besu.cli.converter.PercentageConverter; import org.hyperledger.besu.cli.converter.SubnetInfoConverter; -import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.cli.util.CommandLineUtils; import org.hyperledger.besu.ethereum.p2p.discovery.P2PDiscoveryConfiguration; import org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/P2PTLSConfigOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/P2PTLSConfigOptions.java similarity index 99% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/P2PTLSConfigOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/P2PTLSConfigOptions.java index 5939eb3d39..ee53a5e96f 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/P2PTLSConfigOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/P2PTLSConfigOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; import static java.util.Arrays.asList; import static org.hyperledger.besu.cli.DefaultCommandValues.DEFAULT_KEYSTORE_TYPE; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/PermissionsOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/PermissionsOptions.java similarity index 99% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/PermissionsOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/PermissionsOptions.java index 4dc693d36e..b6c744c98f 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/PermissionsOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/PermissionsOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import org.hyperledger.besu.cli.DefaultCommandValues; import org.hyperledger.besu.datatypes.Address; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/PluginsConfigurationOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/PluginsConfigurationOptions.java similarity index 97% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/PluginsConfigurationOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/PluginsConfigurationOptions.java index 25893fff89..5a5a064608 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/PluginsConfigurationOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/PluginsConfigurationOptions.java @@ -12,14 +12,13 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import static org.hyperledger.besu.cli.DefaultCommandValues.DEFAULT_CONTINUE_ON_PLUGIN_ERROR_OPTION_NAME; import static org.hyperledger.besu.cli.DefaultCommandValues.DEFAULT_PLUGINS_EXTERNAL_ENABLED_OPTION_NAME; import static org.hyperledger.besu.cli.DefaultCommandValues.DEFAULT_PLUGINS_OPTION_NAME; import org.hyperledger.besu.cli.converter.PluginInfoConverter; -import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.cli.util.CommandLineUtils; import org.hyperledger.besu.ethereum.core.plugins.PluginConfiguration; import org.hyperledger.besu.ethereum.core.plugins.PluginInfo; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/PrivacyPluginOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/PrivacyPluginOptions.java similarity index 82% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/PrivacyPluginOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/PrivacyPluginOptions.java index fe2f4df3fe..7842c09923 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/PrivacyPluginOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/PrivacyPluginOptions.java @@ -12,11 +12,12 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; import static picocli.CommandLine.Option; /** The Privacy plugin Cli options. */ +@Deprecated(since = "24.11.0") public class PrivacyPluginOptions { /** Default Constructor. */ PrivacyPluginOptions() {} @@ -33,7 +34,7 @@ public class PrivacyPluginOptions { @Option( names = "--Xprivacy-plugin-enabled", description = - "Enables the use of a plugin to implement your own privacy strategy (default: ${DEFAULT-VALUE})", + "Deprecated. Tessera-based privacy is deprecated. See CHANGELOG for alternative options. Enables the use of a plugin to implement your own privacy strategy (default: ${DEFAULT-VALUE})", hidden = true) private final Boolean isPrivacyPluginEnabled = false; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/RPCOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/RPCOptions.java similarity index 97% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/RPCOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/RPCOptions.java index 2dd11f428d..63759af1c6 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/RPCOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/RPCOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; import org.hyperledger.besu.ethereum.api.handlers.TimeoutOptions; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/RpcWebsocketOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/RpcWebsocketOptions.java similarity index 67% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/RpcWebsocketOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/RpcWebsocketOptions.java index 40edeecc0d..2dde517ccc 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/RpcWebsocketOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/RpcWebsocketOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.DEFAULT_RPC_APIS; import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.VALID_APIS; @@ -120,6 +120,71 @@ public class RpcWebsocketOptions { arity = "1") private final File rpcWsAuthenticationPublicKeyFile = null; + @CommandLine.Option( + names = {"--rpc-ws-ssl-enabled"}, + description = "Enable SSL/TLS for the WebSocket RPC service") + private final Boolean isRpcWsSslEnabled = false; + + @CommandLine.Option( + names = {"--rpc-ws-ssl-keystore-file"}, + paramLabel = DefaultCommandValues.MANDATORY_FILE_FORMAT_HELP, + description = "Path to the keystore file for the WebSocket RPC service") + private String rpcWsKeyStoreFile = null; + + @CommandLine.Option( + names = {"--rpc-ws-ssl-keystore-password"}, + paramLabel = "", + description = "Password for the WebSocket RPC keystore file") + private String rpcWsKeyStorePassword = null; + + @CommandLine.Option( + names = {"--rpc-ws-ssl-key-file"}, + paramLabel = DefaultCommandValues.MANDATORY_FILE_FORMAT_HELP, + description = "Path to the PEM key file for the WebSocket RPC service") + private String rpcWsKeyFile = null; + + @CommandLine.Option( + names = {"--rpc-ws-ssl-cert-file"}, + paramLabel = DefaultCommandValues.MANDATORY_FILE_FORMAT_HELP, + description = "Path to the PEM cert file for the WebSocket RPC service") + private String rpcWsCertFile = null; + + @CommandLine.Option( + names = {"--rpc-ws-ssl-keystore-type"}, + paramLabel = "", + description = "Type of the WebSocket RPC keystore (JKS, PKCS12, PEM)") + private String rpcWsKeyStoreType = null; + + // For client authentication (mTLS) + @CommandLine.Option( + names = {"--rpc-ws-ssl-client-auth-enabled"}, + description = "Enable client authentication for the WebSocket RPC service") + private final Boolean isRpcWsClientAuthEnabled = false; + + @CommandLine.Option( + names = {"--rpc-ws-ssl-truststore-file"}, + paramLabel = DefaultCommandValues.MANDATORY_FILE_FORMAT_HELP, + description = "Path to the truststore file for the WebSocket RPC service") + private String rpcWsTrustStoreFile = null; + + @CommandLine.Option( + names = {"--rpc-ws-ssl-truststore-password"}, + paramLabel = "", + description = "Password for the WebSocket RPC truststore file") + private String rpcWsTrustStorePassword = null; + + @CommandLine.Option( + names = {"--rpc-ws-ssl-trustcert-file"}, + paramLabel = DefaultCommandValues.MANDATORY_FILE_FORMAT_HELP, + description = "Path to the PEM trustcert file for the WebSocket RPC service") + private String rpcWsTrustCertFile = null; + + @CommandLine.Option( + names = {"--rpc-ws-ssl-truststore-type"}, + paramLabel = "", + description = "Type of the truststore (JKS, PKCS12, PEM)") + private String rpcWsTrustStoreType = null; + /** Default Constructor. */ public RpcWebsocketOptions() {} @@ -184,7 +249,61 @@ public class RpcWebsocketOptions { "--rpc-ws-authentication-enabled", "--rpc-ws-authentication-credentials-file", "--rpc-ws-authentication-public-key-file", - "--rpc-ws-authentication-jwt-algorithm")); + "--rpc-ws-authentication-jwt-algorithm", + "--rpc-ws-ssl-enabled")); + + CommandLineUtils.checkOptionDependencies( + logger, + commandLine, + "--rpc-ws-ssl-enabled", + !isRpcWsSslEnabled, + List.of( + "--rpc-ws-ssl-keystore-file", + "--rpc-ws-ssl-keystore-type", + "--rpc-ws-ssl-client-auth-enabled")); + + CommandLineUtils.checkOptionDependencies( + logger, + commandLine, + "--rpc-ws-ssl-client-auth-enabled", + !isRpcWsClientAuthEnabled, + List.of( + "--rpc-ws-ssl-truststore-file", + "--rpc-ws-ssl-truststore-type", + "--rpc-ws-ssl-trustcert-file")); + + if (isRpcWsSslEnabled) { + if ("PEM".equalsIgnoreCase(rpcWsKeyStoreType)) { + CommandLineUtils.checkOptionDependencies( + logger, + commandLine, + "--rpc-ws-ssl-key-file", + rpcWsKeyFile == null, + List.of("--rpc-ws-ssl-cert-file")); + CommandLineUtils.checkOptionDependencies( + logger, + commandLine, + "--rpc-ws-ssl-cert-file", + rpcWsCertFile == null, + List.of("--rpc-ws-ssl-key-file")); + } else { + CommandLineUtils.checkOptionDependencies( + logger, + commandLine, + "--rpc-ws-ssl-keystore-file", + rpcWsKeyStoreFile == null, + List.of("--rpc-ws-ssl-keystore-password")); + } + } + + if (isRpcWsClientAuthEnabled && !"PEM".equalsIgnoreCase(rpcWsTrustStoreType)) { + CommandLineUtils.checkOptionDependencies( + logger, + commandLine, + "--rpc-ws-ssl-truststore-file", + rpcWsTrustStoreFile == null, + List.of("--rpc-ws-ssl-truststore-password")); + } if (isRpcWsAuthenticationEnabled) { CommandLineUtils.checkOptionDependencies( @@ -222,6 +341,18 @@ public class RpcWebsocketOptions { webSocketConfiguration.setAuthenticationPublicKeyFile(rpcWsAuthenticationPublicKeyFile); webSocketConfiguration.setAuthenticationAlgorithm(rpcWebsocketsAuthenticationAlgorithm); webSocketConfiguration.setTimeoutSec(wsTimoutSec); + webSocketConfiguration.setSslEnabled(isRpcWsSslEnabled); + webSocketConfiguration.setKeyStorePath(rpcWsKeyStoreFile); + webSocketConfiguration.setKeyStorePassword(rpcWsKeyStorePassword); + webSocketConfiguration.setKeyStoreType(rpcWsKeyStoreType); + webSocketConfiguration.setClientAuthEnabled(isRpcWsClientAuthEnabled); + webSocketConfiguration.setTrustStorePath(rpcWsTrustStoreFile); + webSocketConfiguration.setTrustStorePassword(rpcWsTrustStorePassword); + webSocketConfiguration.setTrustStoreType(rpcWsTrustStoreType); + webSocketConfiguration.setKeyPath(rpcWsKeyFile); + webSocketConfiguration.setCertPath(rpcWsCertFile); + webSocketConfiguration.setTrustCertPath(rpcWsTrustCertFile); + return webSocketConfiguration; } diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/SynchronizerOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/SynchronizerOptions.java similarity index 99% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/SynchronizerOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/SynchronizerOptions.java index 816d9df00a..c7d20c17fb 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/SynchronizerOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/SynchronizerOptions.java @@ -12,10 +12,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; -import org.hyperledger.besu.cli.options.CLIOptions; -import org.hyperledger.besu.cli.options.OptionParser; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import org.hyperledger.besu.ethereum.eth.sync.snapsync.ImmutableSnapSyncConfiguration; import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncConfiguration; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/PublicKeySubCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/PublicKeySubCommand.java index 73916a936e..593fc6cd77 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/PublicKeySubCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/PublicKeySubCommand.java @@ -20,7 +20,7 @@ import static org.hyperledger.besu.cli.subcommands.PublicKeySubCommand.COMMAND_N import org.hyperledger.besu.cli.BesuCommand; import org.hyperledger.besu.cli.DefaultCommandValues; -import org.hyperledger.besu.cli.options.stable.NodePrivateKeyFileOption; +import org.hyperledger.besu.cli.options.NodePrivateKeyFileOption; import org.hyperledger.besu.cli.subcommands.PublicKeySubCommand.AddressSubCommand; import org.hyperledger.besu.cli.subcommands.PublicKeySubCommand.ExportSubCommand; import org.hyperledger.besu.cli.util.VersionProvider; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/RetestethSubCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/RetestethSubCommand.java deleted file mode 100644 index 67af49c400..0000000000 --- a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/RetestethSubCommand.java +++ /dev/null @@ -1,149 +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.cli.subcommands; - -import static org.hyperledger.besu.cli.subcommands.RetestethSubCommand.COMMAND_NAME; - -import org.hyperledger.besu.BesuInfo; -import org.hyperledger.besu.cli.DefaultCommandValues; -import org.hyperledger.besu.cli.custom.JsonRPCAllowlistHostsProperty; -import org.hyperledger.besu.cli.options.stable.LoggingLevelOption; -import org.hyperledger.besu.cli.util.VersionProvider; -import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration; -import org.hyperledger.besu.ethereum.retesteth.RetestethConfiguration; -import org.hyperledger.besu.ethereum.retesteth.RetestethService; -import org.hyperledger.besu.util.LogConfigurator; - -import java.net.InetAddress; -import java.nio.file.Path; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import picocli.CommandLine.Command; -import picocli.CommandLine.Mixin; -import picocli.CommandLine.Option; - -/** Subcommand to run a Retesteth compatible server for reference tests. */ -@Command( - name = COMMAND_NAME, - description = "Run a Retesteth compatible server for reference tests.", - mixinStandardHelpOptions = true, - versionProvider = VersionProvider.class) -@SuppressWarnings("unused") -public class RetestethSubCommand implements Runnable { - - private static final Logger LOG = LoggerFactory.getLogger(RetestethSubCommand.class); - - /** The constant COMMAND_NAME. */ - public static final String COMMAND_NAME = "retesteth"; - - /** - * Using a distinct port for retesteth will result in less testing collisions and accidental RPC - * calls. This is 0xba5e in hex, a hex speak play on the english translation of - * "Besu." - */ - public static final int RETESTETH_PORT = 47710; - - @Option( - names = {"--data-path"}, - paramLabel = DefaultCommandValues.MANDATORY_PATH_FORMAT_HELP, - description = "The path to Besu data directory (default: ${DEFAULT-VALUE})") - private final Path dataPath = DefaultCommandValues.getDefaultBesuDataPath(this); - - @Mixin private LoggingLevelOption loggingLevelOption; - - @SuppressWarnings({"FieldCanBeFinal", "FieldMayBeFinal"}) // PicoCLI requires non-final Strings. - @Option( - names = {"--rpc-http-host"}, - paramLabel = DefaultCommandValues.MANDATORY_HOST_FORMAT_HELP, - description = "Host for Retesteth JSON-RPC HTTP to listen on (default: ${DEFAULT-VALUE})", - arity = "1") - private String rpcHttpHost = autoDiscoverDefaultIP().getHostAddress(); - - @Option( - names = {"--rpc-http-port"}, - paramLabel = DefaultCommandValues.MANDATORY_PORT_FORMAT_HELP, - description = "Port for Retesteth JSON-RPC HTTP to listen on (default: ${DEFAULT-VALUE})", - arity = "1") - private final Integer rpcHttpPort = RETESTETH_PORT; - - @Option( - names = {"--host-allowlist", "--host-whitelist"}, - paramLabel = "[,...]... or * or all", - description = - "Comma separated list of hostnames to allow for RPC access, or * to accept any host (default: ${DEFAULT-VALUE})", - defaultValue = "localhost,127.0.0.1") - private final JsonRPCAllowlistHostsProperty hostsAllowlist = new JsonRPCAllowlistHostsProperty(); - - private InetAddress autoDiscoveredDefaultIP; - - /** Default Constructor. */ - public RetestethSubCommand() {} - - // Used to discover the default IP of the client. - // Loopback IP is used by default as this is how smokeTests require it to be - // and it's probably a good security behaviour to default only on the localhost. - private InetAddress autoDiscoverDefaultIP() { - - if (autoDiscoveredDefaultIP != null) { - return autoDiscoveredDefaultIP; - } - - autoDiscoveredDefaultIP = InetAddress.getLoopbackAddress(); - - return autoDiscoveredDefaultIP; - } - - private void prepareLogging() { - // set log level per CLI flags - final String logLevel = loggingLevelOption.getLogLevel(); - if (logLevel != null) { - System.out.println("Setting logging level to " + logLevel); - LogConfigurator.setLevel("", logLevel); - } - } - - @Override - public void run() { - prepareLogging(); - - final RetestethConfiguration retestethConfiguration = new RetestethConfiguration(dataPath); - final JsonRpcConfiguration jsonRpcConfiguration = JsonRpcConfiguration.createDefault(); - jsonRpcConfiguration.setHost(rpcHttpHost); - jsonRpcConfiguration.setPort(rpcHttpPort); - jsonRpcConfiguration.setHostsAllowlist(hostsAllowlist); - - final RetestethService retestethService = - new RetestethService(BesuInfo.version(), retestethConfiguration, jsonRpcConfiguration); - - Runtime.getRuntime() - .addShutdownHook( - new Thread( - () -> { - try { - retestethService.close(); - LogConfigurator.shutdown(); - } catch (final Exception e) { - LOG.error("Failed to stop Besu Retesteth"); - } - })); - retestethService.start(); - try { - Thread.sleep(Long.MAX_VALUE); // Is there a better way? - } catch (final InterruptedException e) { - // e.printStackTrace(); - } - } -} diff --git a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommand.java index 5bd0aacee2..95617fe8ca 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommand.java @@ -31,9 +31,9 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.blockcreation.IncrementingNonceGenerator; import org.hyperledger.besu.ethereum.chain.Blockchain; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.metrics.MetricsService; import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; @@ -265,12 +265,12 @@ public class BlocksSubCommand implements Runnable { } } - private MiningParameters getMiningParameters() { + private MiningConfiguration getMiningParameters() { final Wei minTransactionGasPrice = Wei.ZERO; // Extradata and coinbase can be configured on a per-block level via the json file final Address coinbase = Address.ZERO; final Bytes extraData = Bytes.EMPTY; - return ImmutableMiningParameters.builder() + return ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .nonceGenerator(new IncrementingNonceGenerator(0)) @@ -377,7 +377,7 @@ public class BlocksSubCommand implements Runnable { return parentCommand .parentCommand .setupControllerBuilder() - .miningParameters(MiningParameters.newDefault()) + .miningParameters(MiningConfiguration.newDefault()) .build(); } 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 6480380240..47a6c2294a 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 @@ -34,9 +34,9 @@ import org.hyperledger.besu.ethereum.rlp.RLPInput; import org.hyperledger.besu.ethereum.trie.Node; import org.hyperledger.besu.ethereum.trie.PersistVisitor; import org.hyperledger.besu.ethereum.trie.RestoreVisitor; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive; import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.util.io.RollingFileReader; import java.io.IOException; @@ -192,8 +192,8 @@ public class RestoreState implements Runnable { final Bytes accountRlp = accountInput.readBytes(); final Bytes code = accountInput.readBytes(); - final StateTrieAccountValue trieAccount = - StateTrieAccountValue.readFrom(new BytesValueRLPInput(accountRlp, false, true)); + final PmtStateTrieAccountValue trieAccount = + PmtStateTrieAccountValue.readFrom(new BytesValueRLPInput(accountRlp, false, true)); if (!trieAccount.getCodeHash().equals(Hash.hash(code))) { throw new RuntimeException("Code hash doesn't match"); } diff --git a/besu/src/main/java/org/hyperledger/besu/components/BesuCommandModule.java b/besu/src/main/java/org/hyperledger/besu/components/BesuCommandModule.java index e757fd62a2..ce4f00db73 100644 --- a/besu/src/main/java/org/hyperledger/besu/components/BesuCommandModule.java +++ b/besu/src/main/java/org/hyperledger/besu/components/BesuCommandModule.java @@ -20,8 +20,8 @@ import org.hyperledger.besu.chainexport.RlpBlockExporter; import org.hyperledger.besu.chainimport.JsonBlockImporter; import org.hyperledger.besu.chainimport.RlpBlockImporter; import org.hyperledger.besu.cli.BesuCommand; -import org.hyperledger.besu.cli.options.stable.P2PDiscoveryOptions; -import org.hyperledger.besu.cli.options.unstable.RPCOptions; +import org.hyperledger.besu.cli.options.P2PDiscoveryOptions; +import org.hyperledger.besu.cli.options.RPCOptions; import org.hyperledger.besu.controller.BesuController; import org.hyperledger.besu.ethereum.p2p.discovery.P2PDiscoveryConfiguration; import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; diff --git a/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java b/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java index fb99318905..238e5c3c1c 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java @@ -24,7 +24,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethods; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.manager.EthPeers; @@ -71,7 +71,7 @@ public class BesuController implements java.io.Closeable { private final MiningCoordinator miningCoordinator; private final PrivacyParameters privacyParameters; private final List closeables; - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; private final PluginServiceFactory additionalPluginServices; private final SyncState syncState; private final EthPeers ethPeers; @@ -91,7 +91,7 @@ public class BesuController implements java.io.Closeable { * @param transactionPool the transaction pool * @param miningCoordinator the mining coordinator * @param privacyParameters the privacy parameters - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param additionalJsonRpcMethodsFactory the additional json rpc methods factory * @param nodeKey the node key * @param closeables the closeables @@ -111,7 +111,7 @@ public class BesuController implements java.io.Closeable { final TransactionPool transactionPool, final MiningCoordinator miningCoordinator, final PrivacyParameters privacyParameters, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final JsonRpcMethods additionalJsonRpcMethodsFactory, final NodeKey nodeKey, final List closeables, @@ -132,7 +132,7 @@ public class BesuController implements java.io.Closeable { this.miningCoordinator = miningCoordinator; this.privacyParameters = privacyParameters; this.closeables = closeables; - this.miningParameters = miningParameters; + this.miningConfiguration = miningConfiguration; this.additionalPluginServices = additionalPluginServices; this.ethPeers = ethPeers; this.storageProvider = storageProvider; @@ -265,8 +265,8 @@ public class BesuController implements java.io.Closeable { * * @return the mining parameters */ - public MiningParameters getMiningParameters() { - return miningParameters; + public MiningConfiguration getMiningParameters() { + return miningConfiguration; } /** 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 8f1b8dec84..1953e1aa31 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java @@ -26,7 +26,6 @@ import org.hyperledger.besu.consensus.qbft.BFTPivotSelectorFromPeers; import org.hyperledger.besu.cryptoservices.NodeKey; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.ConsensusContext; -import org.hyperledger.besu.ethereum.ConsensusContextFactory; import org.hyperledger.besu.ethereum.GasLimitCalculator; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethods; @@ -43,8 +42,9 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.chain.VariablesStorage; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; +import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.SnapProtocol; @@ -55,6 +55,8 @@ import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.MergePeerFilter; import org.hyperledger.besu.ethereum.eth.manager.MonitoredExecutors; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskRequestSender; import org.hyperledger.besu.ethereum.eth.manager.snap.SnapProtocolManager; import org.hyperledger.besu.ethereum.eth.peervalidation.CheckpointBlocksPeerValidator; import org.hyperledger.besu.ethereum.eth.peervalidation.ClassicForkPeerValidator; @@ -93,6 +95,7 @@ import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; import org.hyperledger.besu.ethereum.worldstate.DiffBasedSubStorageConfiguration; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; +import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive.WorldStateHealer; import org.hyperledger.besu.ethereum.worldstate.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStatePreimageStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; @@ -113,6 +116,7 @@ import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.OptionalLong; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; import org.slf4j.Logger; @@ -144,7 +148,7 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides protected BigInteger networkId; /** The Mining parameters. */ - protected MiningParameters miningParameters; + protected MiningConfiguration miningConfiguration; /** The Metrics system. */ protected ObservableMetricsSystem metricsSystem; @@ -296,11 +300,11 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides /** * Mining parameters besu controller builder. * - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @return the besu controller builder */ - public BesuControllerBuilder miningParameters(final MiningParameters miningParameters) { - this.miningParameters = miningParameters; + public BesuControllerBuilder miningParameters(final MiningConfiguration miningConfiguration) { + this.miningConfiguration = miningConfiguration; return this; } @@ -543,7 +547,7 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides checkNotNull(syncConfig, "Missing sync config"); checkNotNull(ethereumWireProtocolConfiguration, "Missing ethereum protocol configuration"); checkNotNull(networkId, "Missing network ID"); - checkNotNull(miningParameters, "Missing mining parameters"); + checkNotNull(miningConfiguration, "Missing mining parameters"); checkNotNull(metricsSystem, "Missing metrics system"); checkNotNull(privacyParameters, "Missing privacy parameters"); checkNotNull(dataDirectory, "Missing data directory"); // Why do we need this? @@ -589,17 +593,24 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides .map(BesuComponent::getCachedMerkleTrieLoader) .orElseGet(() -> new BonsaiCachedMerkleTrieLoader(metricsSystem)); + final var worldStateHealerSupplier = new AtomicReference(); + final WorldStateArchive worldStateArchive = createWorldStateArchive( - worldStateStorageCoordinator, blockchain, bonsaiCachedMerkleTrieLoader); + worldStateStorageCoordinator, + blockchain, + bonsaiCachedMerkleTrieLoader, + worldStateHealerSupplier::get); if (maybeStoredGenesisBlockHash.isEmpty()) { genesisState.writeStateTo(worldStateArchive.getMutable()); } + final var consensusContext = + createConsensusContext(blockchain, worldStateArchive, protocolSchedule); + final ProtocolContext protocolContext = - createProtocolContext( - blockchain, worldStateArchive, protocolSchedule, this::createConsensusContext); + createProtocolContext(blockchain, worldStateArchive, consensusContext); validateContext(protocolContext); protocolSchedule.setPublicWorldStateArchiveForPrivacyBlockProcessor( @@ -616,7 +627,7 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides ethereumWireProtocolConfiguration.isLegacyEth64ForkIdEnabled()); final EthPeers ethPeers = new EthPeers( - getSupportedProtocol(), + EthProtocol.NAME, currentProtocolSpecSupplier, clock, metricsSystem, @@ -655,6 +666,8 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides } final EthContext ethContext = new EthContext(ethPeers, ethMessages, snapMessages, scheduler); + final PeerTaskExecutor peerTaskExecutor = + new PeerTaskExecutor(ethPeers, new PeerTaskRequestSender(), metricsSystem); final boolean fullSyncDisabled = !SyncMode.isFullSync(syncConfig.getSyncMode()); final SyncState syncState = new SyncState(blockchain, ethPeers, fullSyncDisabled, checkpoint); @@ -678,7 +691,7 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides syncState, transactionPoolConfiguration, besuComponent.map(BesuComponent::getBlobCache).orElse(new BlobCache()), - miningParameters); + miningConfiguration); final List peerValidators = createPeerValidators(protocolSchedule); @@ -706,10 +719,13 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides worldStateStorageCoordinator, protocolContext, ethContext, + peerTaskExecutor, syncState, ethProtocolManager, pivotBlockSelector); + worldStateHealerSupplier.set(synchronizer::healWorldState); + ethPeers.setTrailingPeerRequirementsSupplier(synchronizer::calculateTrailingPeerRequirements); if (syncConfig.getSyncMode() == SyncMode.SNAP @@ -720,18 +736,16 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides ethPeers.snapServerPeersNeeded(false); } - protocolContext.setSynchronizer(synchronizer); - final Optional maybeSnapProtocolManager = createSnapProtocolManager( - protocolContext, worldStateStorageCoordinator, ethPeers, snapMessages); + protocolContext, worldStateStorageCoordinator, ethPeers, snapMessages, synchronizer); final MiningCoordinator miningCoordinator = createMiningCoordinator( protocolSchedule, protocolContext, transactionPool, - miningParameters, + miningConfiguration, syncState, ethProtocolManager); @@ -742,7 +756,8 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides createSubProtocolConfiguration(ethProtocolManager, maybeSnapProtocolManager); final JsonRpcMethods additionalJsonRpcMethodFactory = - createAdditionalJsonRpcMethodFactory(protocolContext, protocolSchedule, miningParameters); + createAdditionalJsonRpcMethodFactory( + protocolContext, protocolSchedule, miningConfiguration); if (DataStorageFormat.BONSAI.equals(dataStorageConfiguration.getDataStorageFormat())) { final DiffBasedSubStorageConfiguration subStorageConfiguration = @@ -776,7 +791,7 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides transactionPool, miningCoordinator, privacyParameters, - miningParameters, + miningConfiguration, additionalJsonRpcMethodFactory, nodeKey, closeables, @@ -832,6 +847,7 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides * @param worldStateStorageCoordinator the world state storage * @param protocolContext the protocol context * @param ethContext the eth context + * @param peerTaskExecutor the PeerTaskExecutor * @param syncState the sync state * @param ethProtocolManager the eth protocol manager * @param pivotBlockSelector the pivot block selector @@ -842,6 +858,7 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides final WorldStateStorageCoordinator worldStateStorageCoordinator, final ProtocolContext protocolContext, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final SyncState syncState, final EthProtocolManager ethProtocolManager, final PivotBlockSelector pivotBlockSelector) { @@ -853,6 +870,7 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides worldStateStorageCoordinator, ethProtocolManager.getBlockBroadcaster(), ethContext, + peerTaskExecutor, syncState, dataDirectory, storageProvider, @@ -932,13 +950,13 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides * * @param protocolContext the protocol context * @param protocolSchedule the protocol schedule - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @return the json rpc methods */ protected JsonRpcMethods createAdditionalJsonRpcMethodFactory( final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { return apis -> Collections.emptyMap(); } @@ -961,12 +979,12 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides } /** - * Create mining coordinator mining coordinator. + * Create mining coordinator. * * @param protocolSchedule the protocol schedule * @param protocolContext the protocol context * @param transactionPool the transaction pool - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param syncState the sync state * @param ethProtocolManager the eth protocol manager * @return the mining coordinator @@ -975,7 +993,7 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides ProtocolSchedule protocolSchedule, ProtocolContext protocolContext, TransactionPool transactionPool, - MiningParameters miningParameters, + MiningConfiguration miningConfiguration, SyncState syncState, EthProtocolManager ethProtocolManager); @@ -1002,18 +1020,9 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides * @return the consensus context */ protected abstract ConsensusContext createConsensusContext( - Blockchain blockchain, - WorldStateArchive worldStateArchive, - ProtocolSchedule protocolSchedule); - - /** - * Gets supported protocol. - * - * @return the supported protocol - */ - protected String getSupportedProtocol() { - return EthProtocol.NAME; - } + final Blockchain blockchain, + final WorldStateArchive worldStateArchive, + final ProtocolSchedule protocolSchedule); /** * Create eth protocol manager eth protocol manager. @@ -1064,37 +1073,37 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides * * @param blockchain the blockchain * @param worldStateArchive the world state archive - * @param protocolSchedule the protocol schedule - * @param consensusContextFactory the consensus context factory + * @param consensusContext the consensus context * @return the protocol context */ protected ProtocolContext createProtocolContext( final MutableBlockchain blockchain, final WorldStateArchive worldStateArchive, - final ProtocolSchedule protocolSchedule, - final ConsensusContextFactory consensusContextFactory) { - return ProtocolContext.init( - blockchain, worldStateArchive, protocolSchedule, consensusContextFactory, badBlockManager); + final ConsensusContext consensusContext) { + return new ProtocolContext(blockchain, worldStateArchive, consensusContext, badBlockManager); } private Optional createSnapProtocolManager( final ProtocolContext protocolContext, final WorldStateStorageCoordinator worldStateStorageCoordinator, final EthPeers ethPeers, - final EthMessages snapMessages) { + final EthMessages snapMessages, + final Synchronizer synchronizer) { return Optional.of( new SnapProtocolManager( worldStateStorageCoordinator, syncConfig.getSnapSyncConfiguration(), ethPeers, snapMessages, - protocolContext)); + protocolContext, + synchronizer)); } WorldStateArchive createWorldStateArchive( final WorldStateStorageCoordinator worldStateStorageCoordinator, final Blockchain blockchain, - final BonsaiCachedMerkleTrieLoader bonsaiCachedMerkleTrieLoader) { + final BonsaiCachedMerkleTrieLoader bonsaiCachedMerkleTrieLoader, + final Supplier worldStateHealerSupplier) { return switch (dataStorageConfiguration.getDataStorageFormat()) { case BONSAI -> { final BonsaiWorldStateKeyValueStorage worldStateKeyValueStorage = @@ -1109,7 +1118,8 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides .getMaxLayersToLoad()), bonsaiCachedMerkleTrieLoader, besuComponent.map(BesuComponent::getBesuPluginContext).orElse(null), - evmConfiguration); + evmConfiguration, + worldStateHealerSupplier); } case VERKLE -> { final VerkleWorldStateKeyValueStorage worldStateKeyValueStorage = diff --git a/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java index b4ada60549..ccd4363412 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java @@ -14,12 +14,11 @@ */ package org.hyperledger.besu.controller; -import static org.hyperledger.besu.consensus.clique.CliqueHelpers.installCliqueBlockChoiceRule; - import org.hyperledger.besu.config.CliqueConfigOptions; import org.hyperledger.besu.consensus.clique.CliqueBlockInterface; import org.hyperledger.besu.consensus.clique.CliqueContext; import org.hyperledger.besu.consensus.clique.CliqueForksSchedulesFactory; +import org.hyperledger.besu.consensus.clique.CliqueHelpers; import org.hyperledger.besu.consensus.clique.CliqueMiningTracker; import org.hyperledger.besu.consensus.clique.CliqueProtocolSchedule; import org.hyperledger.besu.consensus.clique.blockcreation.CliqueBlockScheduler; @@ -36,7 +35,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethods; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; @@ -74,8 +73,8 @@ public class CliqueBesuControllerBuilder extends BesuControllerBuilder { protected JsonRpcMethods createAdditionalJsonRpcMethodFactory( final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, - final MiningParameters miningParameters) { - return new CliqueJsonRpcMethods(protocolContext, protocolSchedule, miningParameters); + final MiningConfiguration miningConfiguration) { + return new CliqueJsonRpcMethods(protocolContext, protocolSchedule, miningConfiguration); } @Override @@ -83,7 +82,7 @@ public class CliqueBesuControllerBuilder extends BesuControllerBuilder { final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final TransactionPool transactionPool, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final SyncState syncState, final EthProtocolManager ethProtocolManager) { final CliqueMinerExecutor miningExecutor = @@ -92,7 +91,7 @@ public class CliqueBesuControllerBuilder extends BesuControllerBuilder { protocolSchedule, transactionPool, nodeKey, - miningParameters, + miningConfiguration, new CliqueBlockScheduler( clock, protocolContext.getConsensusContext(CliqueContext.class).getValidatorProvider(), @@ -113,7 +112,7 @@ public class CliqueBesuControllerBuilder extends BesuControllerBuilder { .getBlockchain() .observeBlockAdded( o -> - miningParameters.setBlockPeriodSeconds( + miningConfiguration.setBlockPeriodSeconds( forksSchedule .getFork(o.getBlock().getHeader().getNumber() + 1) .getValue() @@ -135,7 +134,7 @@ public class CliqueBesuControllerBuilder extends BesuControllerBuilder { privacyParameters, isRevertReasonEnabled, evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); @@ -167,12 +166,13 @@ public class CliqueBesuControllerBuilder extends BesuControllerBuilder { blockchain, epochManager, blockInterface), epochManager, blockInterface); - installCliqueBlockChoiceRule(blockchain, cliqueContext); + CliqueHelpers.setCliqueContext(cliqueContext); + CliqueHelpers.installCliqueBlockChoiceRule(blockchain, cliqueContext); return cliqueContext; } @Override - public MiningParameters getMiningParameterOverrides(final MiningParameters fromCli) { + public MiningConfiguration getMiningParameterOverrides(final MiningConfiguration fromCli) { // Clique mines by default, reflect that with in the mining parameters: return fromCli.setMiningEnabled(true); } diff --git a/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java index 0d0f8d2fd8..31f84b6ae0 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java @@ -20,20 +20,19 @@ import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.consensus.common.CombinedProtocolScheduleFactory; import org.hyperledger.besu.consensus.common.ForkSpec; import org.hyperledger.besu.consensus.common.ForksSchedule; -import org.hyperledger.besu.consensus.common.MigratingContext; +import org.hyperledger.besu.consensus.common.MigratingConsensusContext; import org.hyperledger.besu.consensus.common.MigratingMiningCoordinator; import org.hyperledger.besu.consensus.common.MigratingProtocolContext; import org.hyperledger.besu.cryptoservices.NodeKey; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.ConsensusContext; -import org.hyperledger.besu.ethereum.ConsensusContextFactory; import org.hyperledger.besu.ethereum.GasLimitCalculator; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethods; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthContext; @@ -128,7 +127,7 @@ public class ConsensusScheduleBesuControllerBuilder extends BesuControllerBuilde final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final TransactionPool transactionPool, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final SyncState syncState, final EthProtocolManager ethProtocolManager) { @@ -143,7 +142,7 @@ public class ConsensusScheduleBesuControllerBuilder extends BesuControllerBuilde protocolSchedule, protocolContext, transactionPool, - miningParameters, + miningConfiguration, syncState, ethProtocolManager))) .collect(Collectors.toList()); @@ -168,10 +167,12 @@ public class ConsensusScheduleBesuControllerBuilder extends BesuControllerBuilde protected ProtocolContext createProtocolContext( final MutableBlockchain blockchain, final WorldStateArchive worldStateArchive, - final ProtocolSchedule protocolSchedule, - final ConsensusContextFactory consensusContextFactory) { - return MigratingProtocolContext.init( - blockchain, worldStateArchive, protocolSchedule, consensusContextFactory, badBlockManager); + final ConsensusContext consensusContext) { + return new MigratingProtocolContext( + blockchain, + worldStateArchive, + consensusContext.as(MigratingConsensusContext.class), + badBlockManager); } @Override @@ -188,10 +189,10 @@ public class ConsensusScheduleBesuControllerBuilder extends BesuControllerBuilde e.getValue() .createConsensusContext( blockchain, worldStateArchive, protocolSchedule))) - .collect(Collectors.toList()); + .toList(); final ForksSchedule consensusContextsSchedule = new ForksSchedule<>(consensusContextSpecs); - return new MigratingContext(consensusContextsSchedule); + return new MigratingConsensusContext(consensusContextsSchedule); } @Override @@ -206,10 +207,11 @@ public class ConsensusScheduleBesuControllerBuilder extends BesuControllerBuilde protected JsonRpcMethods createAdditionalJsonRpcMethodFactory( final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { return besuControllerBuilderSchedule .get(0L) - .createAdditionalJsonRpcMethodFactory(protocolContext, protocolSchedule, miningParameters); + .createAdditionalJsonRpcMethodFactory( + protocolContext, protocolSchedule, miningConfiguration); } @Override @@ -226,11 +228,6 @@ public class ConsensusScheduleBesuControllerBuilder extends BesuControllerBuilde besuControllerBuilderSchedule.get(GENESIS_BLOCK_NUMBER).validateContext(context); } - @Override - protected String getSupportedProtocol() { - return besuControllerBuilderSchedule.get(0L).getSupportedProtocol(); - } - @Override protected EthProtocolManager createEthProtocolManager( final ProtocolContext protocolContext, @@ -297,9 +294,9 @@ public class ConsensusScheduleBesuControllerBuilder extends BesuControllerBuilde } @Override - public BesuControllerBuilder miningParameters(final MiningParameters miningParameters) { - besuControllerBuilderSchedule.values().forEach(b -> b.miningParameters(miningParameters)); - return super.miningParameters(miningParameters); + public BesuControllerBuilder miningParameters(final MiningConfiguration miningConfiguration) { + besuControllerBuilderSchedule.values().forEach(b -> b.miningParameters(miningConfiguration)); + return super.miningParameters(miningConfiguration); } @Override 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 738dcfc596..ae08b11cca 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java @@ -60,7 +60,7 @@ import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.MinedBlockObserver; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.EthProtocol; import org.hyperledger.besu.ethereum.eth.SnapProtocol; @@ -114,8 +114,8 @@ public class IbftBesuControllerBuilder extends BftBesuControllerBuilder { protected JsonRpcMethods createAdditionalJsonRpcMethodFactory( final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, - final MiningParameters miningParameters) { - return new IbftJsonRpcMethods(protocolContext, protocolSchedule, miningParameters); + final MiningConfiguration miningConfiguration) { + return new IbftJsonRpcMethods(protocolContext, protocolSchedule, miningConfiguration); } @Override @@ -141,7 +141,7 @@ public class IbftBesuControllerBuilder extends BftBesuControllerBuilder { final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final TransactionPool transactionPool, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final SyncState syncState, final EthProtocolManager ethProtocolManager) { final MutableBlockchain blockchain = protocolContext.getBlockchain(); @@ -156,7 +156,7 @@ public class IbftBesuControllerBuilder extends BftBesuControllerBuilder { protocolContext, bftProtocolSchedule, forksSchedule, - miningParameters, + miningConfiguration, localAddress, bftExtraDataCodec().get(), ethProtocolManager.ethContext().getScheduler()); @@ -247,7 +247,7 @@ public class IbftBesuControllerBuilder extends BftBesuControllerBuilder { .getBlockchain() .observeBlockAdded( o -> - miningParameters.setBlockPeriodSeconds( + miningConfiguration.setBlockPeriodSeconds( forksSchedule .getFork(o.getBlock().getHeader().getNumber() + 1) .getValue() @@ -303,7 +303,7 @@ public class IbftBesuControllerBuilder extends BftBesuControllerBuilder { isRevertReasonEnabled, bftExtraDataCodec().get(), evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); diff --git a/besu/src/main/java/org/hyperledger/besu/controller/MainnetBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/MainnetBesuControllerBuilder.java index e0fbed608a..a642539ac5 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/MainnetBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/MainnetBesuControllerBuilder.java @@ -21,7 +21,7 @@ import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; import org.hyperledger.besu.ethereum.blockcreation.PoWMinerExecutor; import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.Blockchain; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; @@ -31,6 +31,8 @@ import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; +import java.util.Optional; + /** The Mainnet besu controller builder. */ public class MainnetBesuControllerBuilder extends BesuControllerBuilder { @@ -44,7 +46,7 @@ public class MainnetBesuControllerBuilder extends BesuControllerBuilder { final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final TransactionPool transactionPool, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final SyncState syncState, final EthProtocolManager ethProtocolManager) { @@ -53,7 +55,7 @@ public class MainnetBesuControllerBuilder extends BesuControllerBuilder { protocolContext, protocolSchedule, transactionPool, - miningParameters, + miningConfiguration, new DefaultBlockScheduler( MainnetBlockHeaderValidator.MINIMUM_SECONDS_SINCE_PARENT, MainnetBlockHeaderValidator.TIMESTAMP_TOLERANCE_S, @@ -66,11 +68,11 @@ public class MainnetBesuControllerBuilder extends BesuControllerBuilder { protocolContext.getBlockchain(), executor, syncState, - miningParameters.getUnstable().getRemoteSealersLimit(), - miningParameters.getUnstable().getRemoteSealersTimeToLive()); + miningConfiguration.getUnstable().getRemoteSealersLimit(), + miningConfiguration.getUnstable().getRemoteSealersTimeToLive()); miningCoordinator.addMinedBlockObserver(ethProtocolManager); - miningCoordinator.setStratumMiningEnabled(miningParameters.isStratumMiningEnabled()); - if (miningParameters.isMiningEnabled()) { + miningCoordinator.setStratumMiningEnabled(miningConfiguration.isStratumMiningEnabled()); + if (miningConfiguration.isMiningEnabled()) { miningCoordinator.enable(); } @@ -95,10 +97,10 @@ public class MainnetBesuControllerBuilder extends BesuControllerBuilder { protected ProtocolSchedule createProtocolSchedule() { return MainnetProtocolSchedule.fromConfig( genesisConfigOptions, - privacyParameters, - isRevertReasonEnabled, - evmConfiguration, - miningParameters, + Optional.of(privacyParameters), + Optional.of(isRevertReasonEnabled), + Optional.of(evmConfiguration), + super.miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); diff --git a/besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java index f5fc75959e..e7c1a5c40d 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java @@ -26,7 +26,7 @@ import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthMessages; @@ -67,14 +67,14 @@ public class MergeBesuControllerBuilder extends BesuControllerBuilder { final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final TransactionPool transactionPool, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final SyncState syncState, final EthProtocolManager ethProtocolManager) { return createTransitionMiningCoordinator( protocolSchedule, protocolContext, transactionPool, - miningParameters, + miningConfiguration, syncState, new BackwardSyncContext( protocolContext, @@ -140,7 +140,7 @@ public class MergeBesuControllerBuilder extends BesuControllerBuilder { * @param protocolSchedule the protocol schedule * @param protocolContext the protocol context * @param transactionPool the transaction pool - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param syncState the sync state * @param backwardSyncContext the backward sync context * @param ethScheduler the scheduler @@ -150,7 +150,7 @@ public class MergeBesuControllerBuilder extends BesuControllerBuilder { final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final TransactionPool transactionPool, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final SyncState syncState, final BackwardSyncContext backwardSyncContext, final EthScheduler ethScheduler) { @@ -165,7 +165,7 @@ public class MergeBesuControllerBuilder extends BesuControllerBuilder { protocolSchedule, ethScheduler, transactionPool, - miningParameters, + miningConfiguration, backwardSyncContext, depositContractAddress); } @@ -176,7 +176,7 @@ public class MergeBesuControllerBuilder extends BesuControllerBuilder { genesisConfigOptions, privacyParameters, isRevertReasonEnabled, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); diff --git a/besu/src/main/java/org/hyperledger/besu/controller/MiningParameterOverrides.java b/besu/src/main/java/org/hyperledger/besu/controller/MiningParameterOverrides.java index e4cebc0d64..ae2ae250ba 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/MiningParameterOverrides.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/MiningParameterOverrides.java @@ -14,7 +14,7 @@ */ package org.hyperledger.besu.controller; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; /** * This interface wraps the provided MiningParameters to enable controller-specific parameter @@ -27,7 +27,7 @@ public interface MiningParameterOverrides { * @param fromCli The mining parameters that contains original values. * @return MiningParameters constructed from provided param with additional overridden parameters. */ - default MiningParameters getMiningParameterOverrides(final MiningParameters fromCli) { + default MiningConfiguration getMiningParameterOverrides(final MiningConfiguration fromCli) { return fromCli; } } 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 498435e4af..b6f579ea68 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java @@ -69,7 +69,7 @@ import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.MinedBlockObserver; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.EthProtocol; import org.hyperledger.besu.ethereum.eth.SnapProtocol; @@ -112,10 +112,7 @@ public class QbftBesuControllerBuilder extends BftBesuControllerBuilder { @Override protected Supplier bftExtraDataCodec() { - return Suppliers.memoize( - () -> { - return new QbftExtraDataCodec(); - }); + return Suppliers.memoize(QbftExtraDataCodec::new); } @Override @@ -130,12 +127,12 @@ public class QbftBesuControllerBuilder extends BftBesuControllerBuilder { protected JsonRpcMethods createAdditionalJsonRpcMethodFactory( final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { return new QbftJsonRpcMethods( protocolContext, protocolSchedule, - miningParameters, + miningConfiguration, createReadOnlyValidatorProvider(protocolContext.getBlockchain()), bftConfigOptions); } @@ -181,7 +178,7 @@ public class QbftBesuControllerBuilder extends BftBesuControllerBuilder { final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final TransactionPool transactionPool, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final SyncState syncState, final EthProtocolManager ethProtocolManager) { final MutableBlockchain blockchain = protocolContext.getBlockchain(); @@ -196,7 +193,7 @@ public class QbftBesuControllerBuilder extends BftBesuControllerBuilder { protocolContext, bftProtocolSchedule, qbftForksSchedule, - miningParameters, + miningConfiguration, localAddress, bftExtraDataCodec().get(), ethProtocolManager.ethContext().getScheduler()); @@ -289,12 +286,12 @@ public class QbftBesuControllerBuilder extends BftBesuControllerBuilder { .getBlockchain() .observeBlockAdded( o -> { - miningParameters.setBlockPeriodSeconds( + miningConfiguration.setBlockPeriodSeconds( qbftForksSchedule .getFork(o.getBlock().getHeader().getNumber() + 1) .getValue() .getBlockPeriodSeconds()); - miningParameters.setEmptyBlockPeriodSeconds( + miningConfiguration.setEmptyBlockPeriodSeconds( qbftForksSchedule .getFork(o.getBlock().getHeader().getNumber() + 1) .getValue() @@ -351,7 +348,7 @@ public class QbftBesuControllerBuilder extends BftBesuControllerBuilder { isRevertReasonEnabled, bftExtraDataCodec().get(), evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); diff --git a/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java index ee2611d9c8..75abca6a57 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java @@ -24,14 +24,13 @@ import org.hyperledger.besu.consensus.merge.blockcreation.TransitionCoordinator; import org.hyperledger.besu.cryptoservices.NodeKey; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.ConsensusContext; -import org.hyperledger.besu.ethereum.ConsensusContextFactory; import org.hyperledger.besu.ethereum.GasLimitCalculator; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthContext; @@ -40,6 +39,7 @@ import org.hyperledger.besu.ethereum.eth.manager.EthPeers; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.MergePeerFilter; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator; import org.hyperledger.besu.ethereum.eth.sync.DefaultSynchronizer; import org.hyperledger.besu.ethereum.eth.sync.PivotBlockSelector; @@ -101,7 +101,7 @@ public class TransitionBesuControllerBuilder extends BesuControllerBuilder { final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final TransactionPool transactionPool, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final SyncState syncState, final EthProtocolManager ethProtocolManager) { @@ -111,8 +111,8 @@ public class TransitionBesuControllerBuilder extends BesuControllerBuilder { // PoA consensus mines by default, get consensus-specific mining parameters for // TransitionCoordinator: - MiningParameters transitionMiningParameters = - preMergeBesuControllerBuilder.getMiningParameterOverrides(miningParameters); + MiningConfiguration transitionMiningConfiguration = + preMergeBesuControllerBuilder.getMiningParameterOverrides(miningConfiguration); // construct a transition backward sync context BackwardSyncContext transitionBackwardsSyncContext = @@ -130,10 +130,10 @@ public class TransitionBesuControllerBuilder extends BesuControllerBuilder { transitionProtocolSchedule.getPreMergeSchedule(), protocolContext, transactionPool, - ImmutableMiningParameters.builder() - .from(miningParameters) + ImmutableMiningConfiguration.builder() + .from(miningConfiguration) .mutableInitValues( - ImmutableMiningParameters.MutableInitValues.builder() + ImmutableMiningConfiguration.MutableInitValues.builder() .isMiningEnabled(false) .build()) .build(), @@ -143,7 +143,7 @@ public class TransitionBesuControllerBuilder extends BesuControllerBuilder { transitionProtocolSchedule, protocolContext, transactionPool, - transitionMiningParameters, + transitionMiningConfiguration, syncState, transitionBackwardsSyncContext, ethProtocolManager.ethContext().getScheduler())); @@ -192,11 +192,9 @@ public class TransitionBesuControllerBuilder extends BesuControllerBuilder { protected ProtocolContext createProtocolContext( final MutableBlockchain blockchain, final WorldStateArchive worldStateArchive, - final ProtocolSchedule protocolSchedule, - final ConsensusContextFactory consensusContextFactory) { + final ConsensusContext consensusContext) { final ProtocolContext protocolContext = - super.createProtocolContext( - blockchain, worldStateArchive, protocolSchedule, consensusContextFactory); + super.createProtocolContext(blockchain, worldStateArchive, consensusContext); transitionProtocolSchedule.setProtocolContext(protocolContext); return protocolContext; } @@ -225,6 +223,7 @@ public class TransitionBesuControllerBuilder extends BesuControllerBuilder { final WorldStateStorageCoordinator worldStateStorageCoordinator, final ProtocolContext protocolContext, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final SyncState syncState, final EthProtocolManager ethProtocolManager, final PivotBlockSelector pivotBlockSelector) { @@ -235,6 +234,7 @@ public class TransitionBesuControllerBuilder extends BesuControllerBuilder { worldStateStorageCoordinator, protocolContext, ethContext, + peerTaskExecutor, syncState, ethProtocolManager, pivotBlockSelector); @@ -326,9 +326,9 @@ public class TransitionBesuControllerBuilder extends BesuControllerBuilder { } @Override - public BesuControllerBuilder miningParameters(final MiningParameters miningParameters) { - super.miningParameters(miningParameters); - return propagateConfig(z -> z.miningParameters(miningParameters)); + public BesuControllerBuilder miningParameters(final MiningConfiguration miningConfiguration) { + super.miningParameters(miningConfiguration); + return propagateConfig(z -> z.miningParameters(miningConfiguration)); } @Override diff --git a/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java b/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java index 0adbda23b7..f2f5fa53da 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java @@ -14,9 +14,9 @@ */ package org.hyperledger.besu.services; -import org.hyperledger.besu.cli.options.stable.JsonRpcHttpOptions; +import org.hyperledger.besu.cli.options.JsonRpcHttpOptions; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; import org.hyperledger.besu.plugin.services.BesuConfiguration; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; @@ -31,7 +31,7 @@ public class BesuConfigurationImpl implements BesuConfiguration { private DataStorageConfiguration dataStorageConfiguration; // defaults - private MiningParameters miningParameters = MiningParameters.newDefault(); + private MiningConfiguration miningConfiguration; private Optional rpcHttpHost = Optional.of("http://localhost"); private Optional rpcHttpPort = Optional.of(8545); @@ -59,11 +59,11 @@ public class BesuConfigurationImpl implements BesuConfiguration { /** * Set the mining parameters * - * @param miningParameters configured mining parameters + * @param miningConfiguration configured mining parameters * @return BesuConfigurationImpl instance */ - public BesuConfigurationImpl withMiningParameters(final MiningParameters miningParameters) { - this.miningParameters = miningParameters; + public BesuConfigurationImpl withMiningParameters(final MiningConfiguration miningConfiguration) { + this.miningConfiguration = miningConfiguration; return this; } @@ -106,7 +106,7 @@ public class BesuConfigurationImpl implements BesuConfiguration { @Override public Wei getMinGasPrice() { - return miningParameters.getMinTransactionGasPrice(); + return miningConfiguration.getMinTransactionGasPrice(); } @Override diff --git a/besu/src/main/java/org/hyperledger/besu/services/BesuPluginContextImpl.java b/besu/src/main/java/org/hyperledger/besu/services/BesuPluginContextImpl.java index ad4dbd4481..fbee90edef 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/BesuPluginContextImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/BesuPluginContextImpl.java @@ -18,8 +18,8 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import org.hyperledger.besu.ethereum.core.plugins.PluginConfiguration; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.BesuService; import org.hyperledger.besu.plugin.services.PluginVersionsProvider; @@ -49,7 +49,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** The Besu plugin context implementation. */ -public class BesuPluginContextImpl implements BesuContext, PluginVersionsProvider { +public class BesuPluginContextImpl implements ServiceManager, PluginVersionsProvider { private static final Logger LOG = LoggerFactory.getLogger(BesuPluginContextImpl.class); diff --git a/besu/src/main/java/org/hyperledger/besu/services/BlockchainServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/BlockchainServiceImpl.java index e981a3e78d..76b4d7e150 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/BlockchainServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/BlockchainServiceImpl.java @@ -16,7 +16,6 @@ package org.hyperledger.besu.services; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -40,7 +39,6 @@ import java.util.stream.Collectors; @Unstable public class BlockchainServiceImpl implements BlockchainService { - private ProtocolContext protocolContext; private ProtocolSchedule protocolSchedule; private MutableBlockchain blockchain; @@ -50,13 +48,12 @@ public class BlockchainServiceImpl implements BlockchainService { /** * Initialize the Blockchain service. * - * @param protocolContext the protocol context + * @param blockchain the blockchain * @param protocolSchedule the protocol schedule */ - public void init(final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule) { - this.protocolContext = protocolContext; + public void init(final MutableBlockchain blockchain, final ProtocolSchedule protocolSchedule) { this.protocolSchedule = protocolSchedule; - this.blockchain = protocolContext.getBlockchain(); + this.blockchain = blockchain; } /** @@ -67,25 +64,24 @@ public class BlockchainServiceImpl implements BlockchainService { */ @Override public Optional getBlockByNumber(final long number) { - return protocolContext - .getBlockchain() + return blockchain .getBlockByNumber(number) .map(block -> blockContext(block::getHeader, block::getBody)); } @Override public Hash getChainHeadHash() { - return protocolContext.getBlockchain().getChainHeadHash(); + return blockchain.getChainHeadHash(); } @Override public BlockHeader getChainHeadHeader() { - return protocolContext.getBlockchain().getChainHeadHeader(); + return blockchain.getChainHeadHeader(); } @Override public Optional getNextBlockBaseFee() { - final var chainHeadHeader = protocolContext.getBlockchain().getChainHeadHeader(); + final var chainHeadHeader = blockchain.getChainHeadHeader(); final var protocolSpec = protocolSchedule.getForNextBlockHeader(chainHeadHeader, System.currentTimeMillis()); return Optional.of(protocolSpec.getFeeMarket()) diff --git a/besu/src/main/java/org/hyperledger/besu/services/MiningServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/MiningServiceImpl.java new file mode 100644 index 0000000000..1ee4355066 --- /dev/null +++ b/besu/src/main/java/org/hyperledger/besu/services/MiningServiceImpl.java @@ -0,0 +1,49 @@ +/* + * Copyright contributors to Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.services; + +import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; +import org.hyperledger.besu.plugin.services.mining.MiningService; + +/** + * Implementation of the {@link MiningService} interface. This class provides methods to start and + * stop the mining process using a {@link MiningCoordinator}. + */ +public class MiningServiceImpl implements MiningService { + + private final MiningCoordinator miningCoordinator; + + /** + * Constructs a new {@code MiningServiceImpl} with the specified {@link MiningCoordinator}. + * + * @param miningCoordinator the mining coordinator to be used for starting and stopping the mining + * process + */ + public MiningServiceImpl(final MiningCoordinator miningCoordinator) { + this.miningCoordinator = miningCoordinator; + } + + /** Stops the mining process by delegating to the {@link MiningCoordinator}. */ + @Override + public void stop() { + miningCoordinator.stop(); + } + + /** Starts the mining process by delegating to the {@link MiningCoordinator}. */ + @Override + public void start() { + miningCoordinator.start(); + } +} diff --git a/besu/src/main/java/org/hyperledger/besu/services/PrivacyPluginServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/PrivacyPluginServiceImpl.java index 4592753b9c..fe61c7a450 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/PrivacyPluginServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/PrivacyPluginServiceImpl.java @@ -24,6 +24,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** The Privacy plugin service implementation. */ +@Deprecated(since = "24.11.0") public class PrivacyPluginServiceImpl implements PrivacyPluginService { private static final Logger LOG = LoggerFactory.getLogger(PrivacyPluginServiceImpl.class); diff --git a/besu/src/main/java/org/hyperledger/besu/services/TransactionSimulationServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/TransactionSimulationServiceImpl.java index 54cce205a3..4dc411ee0b 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/TransactionSimulationServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/TransactionSimulationServiceImpl.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.services; +import org.hyperledger.besu.datatypes.AccountOverrideMap; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.ethereum.chain.Blockchain; @@ -62,6 +63,17 @@ public class TransactionSimulationServiceImpl implements TransactionSimulationSe final Hash blockHash, final OperationTracer operationTracer, final boolean isAllowExceedingBalance) { + return simulate( + transaction, Optional.empty(), blockHash, operationTracer, isAllowExceedingBalance); + } + + @Override + public Optional simulate( + final Transaction transaction, + final Optional maybeAccountOverrides, + final Hash blockHash, + final OperationTracer operationTracer, + final boolean isAllowExceedingBalance) { final CallParameter callParameter = CallParameter.fromTransaction(transaction); @@ -79,6 +91,7 @@ public class TransactionSimulationServiceImpl implements TransactionSimulationSe return transactionSimulator .process( callParameter, + maybeAccountOverrides, isAllowExceedingBalance ? SIMULATOR_ALLOWING_EXCEEDING_BALANCE : TransactionValidationParams.transactionSimulator(), diff --git a/besu/src/main/scripts/unixStartScript.txt b/besu/src/main/scripts/unixStartScript.txt index 3302b9c2fe..9e5c5a300b 100644 --- a/besu/src/main/scripts/unixStartScript.txt +++ b/besu/src/main/scripts/unixStartScript.txt @@ -182,19 +182,19 @@ APP_ARGS=`save "\$@"` # Collect all arguments for the java command, following the shell quoting and substitution rules eval set -- \$DEFAULT_JVM_OPTS \$JAVA_OPTS \$${optsEnvironmentVar} <% if ( appNameSystemProperty ) { %>"\"-D${appNameSystemProperty}=\$APP_BASE_NAME\"" <% } %>-classpath "\"\$CLASSPATH\"" <% if ( mainClassName.startsWith('--module ') ) { %>--module-path "\"\$MODULE_PATH\"" <% } %>${mainClassName} "\$APP_ARGS" -unset BESU_USING_JEMALLOC if [ "\$darwin" = "false" -a "\$msys" = "false" ]; then - # check if jemalloc is available - TEST_JEMALLOC=\$(LD_PRELOAD=libjemalloc.so sh -c true 2>&1) - - # if jemalloc is available the output is empty, otherwise the output has an error line - if [ -z "\$TEST_JEMALLOC" ]; then - export LD_PRELOAD=libjemalloc.so - export BESU_USING_JEMALLOC=true - else - # jemalloc not available, as fallback limit malloc to 2 arenas - export MALLOC_ARENA_MAX=2 - fi + if [ "\$BESU_USING_JEMALLOC" != "FALSE" -a "\$BESU_USING_JEMALLOC" != "false" ]; then + # check if jemalloc is available + TEST_JEMALLOC=\$(LD_PRELOAD=libjemalloc.so sh -c true 2>&1) + + # if jemalloc is available the output is empty, otherwise the output has an error line + if [ -z "\$TEST_JEMALLOC" ]; then + export LD_PRELOAD=libjemalloc.so + else + # jemalloc not available, as fallback limit malloc to 2 arenas + export MALLOC_ARENA_MAX=2 + fi + fi fi exec "\$JAVACMD" "\$@" diff --git a/besu/src/test/java/org/hyperledger/besu/FlexGroupPrivacyTest.java b/besu/src/test/java/org/hyperledger/besu/FlexGroupPrivacyTest.java index a246d18d2f..ff205e8751 100644 --- a/besu/src/test/java/org/hyperledger/besu/FlexGroupPrivacyTest.java +++ b/besu/src/test/java/org/hyperledger/besu/FlexGroupPrivacyTest.java @@ -31,7 +31,7 @@ import org.hyperledger.besu.ethereum.GasLimitCalculator; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; @@ -150,7 +150,7 @@ class FlexGroupPrivacyTest { .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .storageProvider(new InMemoryKeyValueStorageProvider()) .networkId(BigInteger.ONE) - .miningParameters(MiningParameters.newDefault()) + .miningParameters(MiningConfiguration.newDefault()) .dataStorageConfiguration(dataStorageConfiguration) .nodeKey(NodeKeyUtils.generate()) .metricsSystem(new NoOpMetricsSystem()) diff --git a/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java b/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java index 5a58091577..87bab916f2 100644 --- a/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java +++ b/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java @@ -31,7 +31,7 @@ import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.GenesisState; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.forkid.ForkId; import org.hyperledger.besu.ethereum.forkid.ForkIdManager; import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule; @@ -174,7 +174,7 @@ public class ForkIdsNetworkConfigTest { (DefaultProtocolSchedule) MainnetProtocolSchedule.fromConfig( configOptions, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem())); @@ -184,7 +184,7 @@ public class ForkIdsNetworkConfigTest { MergeProtocolSchedule.create( configOptions, false, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem())); diff --git a/besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java b/besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java index 6298b70a95..a79b664458 100644 --- a/besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java +++ b/besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java @@ -47,7 +47,7 @@ import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; import org.hyperledger.besu.ethereum.core.InMemoryPrivacyStorageProvider; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; @@ -547,7 +547,7 @@ public class PrivacyReorgTest { .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .storageProvider(new InMemoryKeyValueStorageProvider()) .networkId(BigInteger.ONE) - .miningParameters(MiningParameters.newDefault()) + .miningParameters(MiningConfiguration.newDefault()) .nodeKey(NodeKeyUtils.generate()) .metricsSystem(new NoOpMetricsSystem()) .dataDirectory(dataDir) diff --git a/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java b/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java index 4d488ced3b..305d786b8b 100644 --- a/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java +++ b/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java @@ -31,7 +31,7 @@ import org.hyperledger.besu.ethereum.GasLimitCalculator; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; @@ -125,7 +125,7 @@ class PrivacyTest { .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .storageProvider(new InMemoryKeyValueStorageProvider()) .networkId(BigInteger.ONE) - .miningParameters(MiningParameters.newDefault()) + .miningParameters(MiningConfiguration.newDefault()) .dataStorageConfiguration(dataStorageConfiguration) .nodeKey(NodeKeyUtils.generate()) .metricsSystem(new NoOpMetricsSystem()) diff --git a/besu/src/test/java/org/hyperledger/besu/RunnerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/RunnerBuilderTest.java index 7c5579d471..230de6efd2 100644 --- a/besu/src/test/java/org/hyperledger/besu/RunnerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/RunnerBuilderTest.java @@ -49,7 +49,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.manager.EthContext; @@ -128,7 +128,7 @@ public final class RunnerBuilderTest { when(besuController.getProtocolContext()).thenReturn(protocolContext); when(besuController.getProtocolSchedule()).thenReturn(protocolSchedule); when(besuController.getNodeKey()).thenReturn(nodeKey); - when(besuController.getMiningParameters()).thenReturn(mock(MiningParameters.class)); + when(besuController.getMiningParameters()).thenReturn(mock(MiningConfiguration.class)); when(besuController.getPrivacyParameters()).thenReturn(mock(PrivacyParameters.class)); when(besuController.getTransactionPool()) .thenReturn(mock(TransactionPool.class, RETURNS_DEEP_STUBS)); diff --git a/besu/src/test/java/org/hyperledger/besu/RunnerTest.java b/besu/src/test/java/org/hyperledger/besu/RunnerTest.java index cbbf980408..4239cbdc34 100644 --- a/besu/src/test/java/org/hyperledger/besu/RunnerTest.java +++ b/besu/src/test/java/org/hyperledger/besu/RunnerTest.java @@ -46,7 +46,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockImporter; import org.hyperledger.besu.ethereum.core.BlockSyncTestUtils; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; @@ -153,7 +153,15 @@ public final class RunnerTest { // set merge flag to false, otherwise this test can fail if a merge test runs first MergeConfiguration.setMergeEnabled(false); - syncFromGenesis(SyncMode.FULL, getFastSyncGenesis()); + syncFromGenesis(SyncMode.FULL, getFastSyncGenesis(), false); + } + + @Test + public void fullSyncFromGenesisUsingPeerTaskSystem() throws Exception { + // set merge flag to false, otherwise this test can fail if a merge test runs first + MergeConfiguration.setMergeEnabled(false); + + syncFromGenesis(SyncMode.FULL, getFastSyncGenesis(), true); } @Test @@ -161,10 +169,21 @@ public final class RunnerTest { // set merge flag to false, otherwise this test can fail if a merge test runs first MergeConfiguration.setMergeEnabled(false); - syncFromGenesis(SyncMode.FAST, getFastSyncGenesis()); + syncFromGenesis(SyncMode.FAST, getFastSyncGenesis(), false); + } + + @Test + public void fastSyncFromGenesisUsingPeerTaskSystem() throws Exception { + // set merge flag to false, otherwise this test can fail if a merge test runs first + MergeConfiguration.setMergeEnabled(false); + + syncFromGenesis(SyncMode.FAST, getFastSyncGenesis(), true); } - private void syncFromGenesis(final SyncMode mode, final GenesisConfigFile genesisConfig) + private void syncFromGenesis( + final SyncMode mode, + final GenesisConfigFile genesisConfig, + final boolean isPeerTaskSystemEnabled) throws Exception { final Path dataDirAhead = Files.createTempDirectory(temp, "db-ahead"); final Path dbAhead = dataDirAhead.resolve("database"); @@ -172,9 +191,12 @@ public final class RunnerTest { final NodeKey aheadDbNodeKey = NodeKeyUtils.createFrom(KeyPairUtil.loadKeyPair(dataDirAhead)); final NodeKey behindDbNodeKey = NodeKeyUtils.generate(); final SynchronizerConfiguration syncConfigAhead = - SynchronizerConfiguration.builder().syncMode(SyncMode.FULL).build(); + SynchronizerConfiguration.builder() + .syncMode(SyncMode.FULL) + .isPeerTaskSystemEnabled(isPeerTaskSystemEnabled) + .build(); final ObservableMetricsSystem noOpMetricsSystem = new NoOpMetricsSystem(); - final var miningParameters = MiningParameters.newDefault(); + final var miningParameters = MiningConfiguration.newDefault(); final var dataStorageConfiguration = DataStorageConfiguration.DEFAULT_FOREST_CONFIG; // Setup Runner with blocks final BesuController controllerAhead = @@ -393,11 +415,11 @@ public final class RunnerTest { final Path dataDir, final Path dbDir, final DataStorageConfiguration dataStorageConfiguration, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { final var besuConfiguration = new BesuConfigurationImpl(); besuConfiguration .init(dataDir, dbDir, dataStorageConfiguration) - .withMiningParameters(miningParameters); + .withMiningParameters(miningConfiguration); return new KeyValueStorageProviderBuilder() .withStorageFactory( new RocksDBKeyValueStorageFactory( @@ -466,14 +488,14 @@ public final class RunnerTest { final NodeKey nodeKey, final StorageProvider storageProvider, final ObservableMetricsSystem metricsSystem, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { return new MainnetBesuControllerBuilder() .genesisConfigFile(genesisConfig) .synchronizerConfiguration(syncConfig) .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .dataDirectory(dataDir) .networkId(NETWORK_ID) - .miningParameters(miningParameters) + .miningParameters(miningConfiguration) .nodeKey(nodeKey) .storageProvider(storageProvider) .metricsSystem(metricsSystem) 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 bbc7dea1ab..e76c06fe2d 100644 --- a/besu/src/test/java/org/hyperledger/besu/chainexport/RlpBlockExporterTest.java +++ b/besu/src/test/java/org/hyperledger/besu/chainexport/RlpBlockExporterTest.java @@ -31,7 +31,7 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; @@ -94,7 +94,7 @@ public final class RlpBlockExporterTest { .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .storageProvider(new InMemoryKeyValueStorageProvider()) .networkId(BigInteger.ONE) - .miningParameters(MiningParameters.newDefault()) + .miningParameters(MiningConfiguration.newDefault()) .nodeKey(NodeKeyUtils.generate()) .metricsSystem(new NoOpMetricsSystem()) .privacyParameters(PrivacyParameters.DEFAULT) 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 7b1a4bc7d2..2b534660ed 100644 --- a/besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java +++ b/besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java @@ -17,9 +17,10 @@ package org.hyperledger.besu.chainimport; import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.mock; +import org.hyperledger.besu.components.BesuCommandModule; import org.hyperledger.besu.components.BesuComponent; +import org.hyperledger.besu.components.BesuPluginContextModule; import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.config.JsonUtil; import org.hyperledger.besu.controller.BesuController; @@ -31,17 +32,21 @@ import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Transaction; +import org.hyperledger.besu.ethereum.core.components.MiningParametersModule; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; +import org.hyperledger.besu.ethereum.eth.transactions.BlobCacheModule; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration; +import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.cache.BonsaiCachedMerkleTrieLoader; import org.hyperledger.besu.evm.internal.EvmConfiguration; +import org.hyperledger.besu.metrics.MetricsSystemModule; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.testutil.TestClock; @@ -52,9 +57,13 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.stream.Stream; +import javax.inject.Singleton; import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.io.Resources; +import dagger.Component; +import dagger.Module; +import dagger.Provides; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -449,7 +458,7 @@ public abstract class JsonBlockImporterTest { .storageProvider(new InMemoryKeyValueStorageProvider()) .networkId(BigInteger.valueOf(10)) .miningParameters( - ImmutableMiningParameters.builder() + ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .isMiningEnabled(true) @@ -465,7 +474,28 @@ public abstract class JsonBlockImporterTest { .gasLimitCalculator(GasLimitCalculator.constant()) .evmConfiguration(EvmConfiguration.DEFAULT) .networkConfiguration(NetworkingConfiguration.create()) - .besuComponent(mock(BesuComponent.class)) + .besuComponent(DaggerJsonBlockImporterTest_JsonBlockImportComponent.builder().build()) .build(); } + + @Module + public static class JsonBlockImporterModule { + + @Provides + BonsaiCachedMerkleTrieLoader provideCachedMerkleTrieLoaderModule() { + return new BonsaiCachedMerkleTrieLoader(new NoOpMetricsSystem()); + } + } + + @Singleton + @Component( + modules = { + BesuCommandModule.class, + MiningParametersModule.class, + MetricsSystemModule.class, + JsonBlockImporterModule.class, + BesuPluginContextModule.class, + BlobCacheModule.class + }) + interface JsonBlockImportComponent extends BesuComponent {} } 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 2d9e587c3f..9f405d4cb3 100644 --- a/besu/src/test/java/org/hyperledger/besu/chainimport/RlpBlockImporterTest.java +++ b/besu/src/test/java/org/hyperledger/besu/chainimport/RlpBlockImporterTest.java @@ -26,7 +26,7 @@ import org.hyperledger.besu.controller.BesuController; import org.hyperledger.besu.cryptoservices.NodeKeyUtils; import org.hyperledger.besu.ethereum.GasLimitCalculator; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; @@ -69,7 +69,7 @@ public final class RlpBlockImporterTest { .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .storageProvider(new InMemoryKeyValueStorageProvider()) .networkId(BigInteger.ONE) - .miningParameters(MiningParameters.newDefault()) + .miningParameters(MiningConfiguration.newDefault()) .nodeKey(NodeKeyUtils.generate()) .metricsSystem(new NoOpMetricsSystem()) .privacyParameters(PrivacyParameters.DEFAULT) @@ -103,7 +103,7 @@ public final class RlpBlockImporterTest { .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .storageProvider(new InMemoryKeyValueStorageProvider()) .networkId(BigInteger.ONE) - .miningParameters(MiningParameters.newDefault()) + .miningParameters(MiningConfiguration.newDefault()) .nodeKey(NodeKeyUtils.generate()) .metricsSystem(new NoOpMetricsSystem()) .privacyParameters(PrivacyParameters.DEFAULT) @@ -134,7 +134,7 @@ public final class RlpBlockImporterTest { .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .storageProvider(new InMemoryKeyValueStorageProvider()) .networkId(BigInteger.ONE) - .miningParameters(MiningParameters.newDefault()) + .miningParameters(MiningConfiguration.newDefault()) .nodeKey(NodeKeyUtils.generate()) .metricsSystem(new NoOpMetricsSystem()) .privacyParameters(PrivacyParameters.DEFAULT) diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index 019e8d83cd..eb789478b9 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -37,9 +37,11 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.contains; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNotNull; +import static org.mockito.Mockito.argThat; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; import org.hyperledger.besu.BesuInfo; import org.hyperledger.besu.cli.config.EthNetworkConfig; @@ -56,7 +58,7 @@ import org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration; import org.hyperledger.besu.ethereum.api.handlers.TimeoutOptions; import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl; @@ -99,7 +101,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.io.TempDir; import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import picocli.CommandLine; @@ -277,8 +278,8 @@ public class BesuCommandTest extends CommandTestAbstract { verify(mockRunnerBuilder).build(); verify(mockControllerBuilderFactory).fromEthNetworkConfig(ethNetworkArg.capture(), any()); - final ArgumentCaptor miningArg = - ArgumentCaptor.forClass(MiningParameters.class); + final ArgumentCaptor miningArg = + ArgumentCaptor.forClass(MiningConfiguration.class); verify(mockControllerBuilder).synchronizerConfiguration(syncConfigurationCaptor.capture()); verify(mockControllerBuilder).dataDirectory(isNotNull()); verify(mockControllerBuilder).miningParameters(miningArg.capture()); @@ -566,7 +567,7 @@ public class BesuCommandTest extends CommandTestAbstract { parseCommand("--genesis-file", genesisFile.toString(), "--network", "mainnet"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) @@ -578,7 +579,7 @@ public class BesuCommandTest extends CommandTestAbstract { final String nonExistentGenesis = "non-existent-genesis.json"; parseCommand("--genesis-file", nonExistentGenesis); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)).startsWith("Unable to load genesis file"); @@ -1177,7 +1178,7 @@ public class BesuCommandTest extends CommandTestAbstract { parseCommand( "--remote-connections-limit-enabled", "--remote-connections-max-percentage", "invalid"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) .contains( @@ -1190,7 +1191,7 @@ public class BesuCommandTest extends CommandTestAbstract { parseCommand( "--remote-connections-limit-enabled", "--remote-connections-max-percentage", "150"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) .contains( @@ -1225,7 +1226,7 @@ public class BesuCommandTest extends CommandTestAbstract { @Test public void syncMode_invalid() { parseCommand("--sync-mode", "bogus"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) @@ -1275,7 +1276,7 @@ public class BesuCommandTest extends CommandTestAbstract { public void helpShouldDisplayFastSyncOptions() { parseCommand("--help"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).contains("--fast-sync-min-peers"); // whitelist is now a hidden option @@ -1335,7 +1336,7 @@ public class BesuCommandTest extends CommandTestAbstract { public void parsesInvalidFastSyncMinPeersOptionWrongFormatShouldFail() { parseCommand("--sync-mode", "FAST", "--fast-sync-min-peers", "ten"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) .contains("Invalid value for option '--fast-sync-min-peers': 'ten' is not an int"); @@ -1358,7 +1359,7 @@ public class BesuCommandTest extends CommandTestAbstract { public void netRestrictInvalidShouldFail() { final String subnet = "127.0.0.1/abc"; parseCommand("--net-restrict", subnet); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandErrorOutput.toString(UTF_8)) .contains("Invalid value for option '--net-restrict'"); } @@ -1382,7 +1383,7 @@ public class BesuCommandTest extends CommandTestAbstract { @Test public void ethStatsContactOptionCannotBeUsedWithoutEthStatsServerProvided() { parseCommand("--ethstats-contact", "besu-updated"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) .contains( @@ -1435,7 +1436,7 @@ public class BesuCommandTest extends CommandTestAbstract { public void parsesInvalidWhenFullSyncAndBonsaiLimitTrieLogsExplicitlyTrue() { parseCommand("--sync-mode=FULL", "--bonsai-limit-trie-logs-enabled=true"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) .contains( @@ -1467,7 +1468,7 @@ public class BesuCommandTest extends CommandTestAbstract { parseCommand("--data-storage-format", "BONSAI", "--bonsai-maximum-back-layers-to-load", "ten"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) .contains( @@ -1501,7 +1502,7 @@ public class BesuCommandTest extends CommandTestAbstract { @Test public void dnsUpdateEnabledOptionCannotBeUsedWithoutDnsEnabled() { parseCommand("--Xdns-update-enabled", "true"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) .contains( @@ -1720,6 +1721,17 @@ public class BesuCommandTest extends CommandTestAbstract { assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); } + @Test + public void metricsUnknownCategoryRaiseError() { + parseCommand("--metrics-enabled", "--metrics-category", "UNKNOWN_CATEGORY"); + + verifyNoInteractions(mockRunnerBuilder); + + assertThat(commandOutput.toString(UTF_8)).isEmpty(); + assertThat(commandErrorOutput.toString(UTF_8)) + .startsWith("--metrics-categories contains unknown categories: [UNKNOWN_CATEGORY]"); + } + @Test public void metricsPushEnabledPropertyMustBeUsed() { parseCommand("--metrics-push-enabled"); @@ -1799,7 +1811,7 @@ public class BesuCommandTest extends CommandTestAbstract { public void metricsAndMetricsPushMustNotBeUsedTogether() { parseCommand("--metrics-enabled", "--metrics-push-enabled"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) @@ -2023,7 +2035,7 @@ public class BesuCommandTest extends CommandTestAbstract { public void fullCLIOptionsShown() { parseCommand("--help"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).contains("--config-file"); assertThat(commandOutput.toString(UTF_8)).contains("--data-path"); @@ -2401,13 +2413,16 @@ public class BesuCommandTest extends CommandTestAbstract { @Test public void logsWarningWhenFailToLoadJemalloc() { assumeTrue(PlatformDetector.getOSType().equals("linux")); - setEnvironmentVariable("BESU_USING_JEMALLOC", "true"); + setEnvironmentVariable("BESU_USING_JEMALLOC", "false"); parseCommand(); verify(mockLogger) .warn( - eq( - "BESU_USING_JEMALLOC is present but we failed to load jemalloc library to get the version"), - any(Throwable.class)); + argThat( + arg -> + arg.equals( + "besu_using_jemalloc is present but is not set to true, jemalloc library not loaded") + || arg.equals( + "besu_using_jemalloc is present but we failed to load jemalloc library to get the version"))); } @Test diff --git a/besu/src/test/java/org/hyperledger/besu/cli/CascadingDefaultProviderTest.java b/besu/src/test/java/org/hyperledger/besu/cli/CascadingDefaultProviderTest.java index 4cdd8163d9..c142838814 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/CascadingDefaultProviderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/CascadingDefaultProviderTest.java @@ -33,7 +33,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl; @@ -200,7 +200,7 @@ public class CascadingDefaultProviderTest extends CommandTestAbstract { setEnvironmentVariable("BESU_MINER_COINBASE", expectedCoinbase); parseCommand("--config-file", configFile); - final var captMiningParameters = ArgumentCaptor.forClass(MiningParameters.class); + final var captMiningParameters = ArgumentCaptor.forClass(MiningConfiguration.class); verify(mockControllerBuilder).miningParameters(captMiningParameters.capture()); assertThat(captMiningParameters.getValue().getCoinbase()) @@ -219,7 +219,7 @@ public class CascadingDefaultProviderTest extends CommandTestAbstract { setEnvironmentVariable("BESU_MINER_COINBASE", "0x0000000000000000000000000000000000000004"); parseCommand("--config-file", configFile, "--miner-coinbase", expectedCoinbase); - final var captMiningParameters = ArgumentCaptor.forClass(MiningParameters.class); + final var captMiningParameters = ArgumentCaptor.forClass(MiningConfiguration.class); verify(mockControllerBuilder).miningParameters(captMiningParameters.capture()); assertThat(captMiningParameters.getValue().getCoinbase()) diff --git a/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java b/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java index 5c7bf3ce88..7239659398 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java @@ -34,13 +34,13 @@ import org.hyperledger.besu.chainexport.RlpBlockExporter; import org.hyperledger.besu.chainimport.JsonBlockImporter; import org.hyperledger.besu.chainimport.RlpBlockImporter; import org.hyperledger.besu.cli.config.EthNetworkConfig; +import org.hyperledger.besu.cli.options.EthProtocolOptions; +import org.hyperledger.besu.cli.options.EthstatsOptions; import org.hyperledger.besu.cli.options.MiningOptions; +import org.hyperledger.besu.cli.options.NetworkingOptions; +import org.hyperledger.besu.cli.options.SynchronizerOptions; import org.hyperledger.besu.cli.options.TransactionPoolOptions; -import org.hyperledger.besu.cli.options.stable.EthstatsOptions; import org.hyperledger.besu.cli.options.storage.DataStorageOptions; -import org.hyperledger.besu.cli.options.unstable.EthProtocolOptions; -import org.hyperledger.besu.cli.options.unstable.NetworkingOptions; -import org.hyperledger.besu.cli.options.unstable.SynchronizerOptions; import org.hyperledger.besu.components.BesuComponent; import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.controller.BesuController; diff --git a/besu/src/test/java/org/hyperledger/besu/cli/converter/MetricCategoryConverterTest.java b/besu/src/test/java/org/hyperledger/besu/cli/converter/MetricCategoryConverterTest.java deleted file mode 100644 index 8c78b7fecc..0000000000 --- a/besu/src/test/java/org/hyperledger/besu/cli/converter/MetricCategoryConverterTest.java +++ /dev/null @@ -1,63 +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.cli.converter; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.mockito.Mockito.when; - -import org.hyperledger.besu.plugin.services.metrics.MetricCategory; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -@ExtendWith(MockitoExtension.class) -public class MetricCategoryConverterTest { - - private MetricCategoryConverter metricCategoryConverter; - - @Mock MetricCategory metricCategory; - - @BeforeEach - public void setUp() { - metricCategoryConverter = new MetricCategoryConverter(); - } - - @Test - public void convertShouldFailIfValueNotRegistered() { - assertThatExceptionOfType(IllegalArgumentException.class) - .isThrownBy(() -> metricCategoryConverter.convert("notRegistered")); - } - - @Test - public void addRegistryCategoryShouldUppercaseInputValues() { - when(metricCategory.getName()).thenReturn("testcat"); - metricCategoryConverter.addRegistryCategory(metricCategory); - when(metricCategory.getName()).thenReturn("tesTCat2"); - metricCategoryConverter.addRegistryCategory(metricCategory); - - final boolean containsLowercase = - metricCategoryConverter.getMetricCategories().keySet().stream() - .anyMatch(testString -> testString.chars().anyMatch(Character::isLowerCase)); - - assertThat(containsLowercase).isFalse(); - assertThat(metricCategoryConverter.getMetricCategories().size()).isEqualTo(2); - assertThat(metricCategoryConverter.getMetricCategories().keySet()) - .containsExactlyInAnyOrder("TESTCAT", "TESTCAT2"); - } -} diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/EthProtocolOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/EthProtocolOptionsTest.java index 6f7aa637cd..33c91f2c03 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/EthProtocolOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/EthProtocolOptionsTest.java @@ -18,7 +18,6 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.verifyNoInteractions; -import org.hyperledger.besu.cli.options.unstable.EthProtocolOptions; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.junit.jupiter.api.Test; diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/stable/LoggingLevelOptionTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/LoggingLevelOptionTest.java similarity index 97% rename from besu/src/test/java/org/hyperledger/besu/cli/options/stable/LoggingLevelOptionTest.java rename to besu/src/test/java/org/hyperledger/besu/cli/options/LoggingLevelOptionTest.java index b1fb3217c2..78c0f694ad 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/stable/LoggingLevelOptionTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/LoggingLevelOptionTest.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java index 992dcc437d..f68a87643b 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java @@ -14,15 +14,32 @@ */ package org.hyperledger.besu.cli.options; -import org.hyperledger.besu.cli.options.stable.MetricsOptions; +import static org.assertj.core.api.Assertions.assertThat; + +import org.hyperledger.besu.metrics.BesuMetricCategory; +import org.hyperledger.besu.metrics.MetricCategoryRegistryImpl; +import org.hyperledger.besu.metrics.StandardMetricCategory; import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; +import java.util.EnumSet; +import java.util.stream.Collectors; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) public class MetricsOptionsTest extends AbstractCLIOptionsTest { + private MetricCategoryRegistryImpl categoryRegistry; + + @BeforeEach + public void setUp() { + categoryRegistry = new MetricCategoryRegistryImpl(); + categoryRegistry.addCategories(BesuMetricCategory.class); + categoryRegistry.addCategories(StandardMetricCategory.class); + } @Override protected MetricsConfiguration.Builder createDefaultDomainObject() { @@ -39,11 +56,36 @@ public class MetricsOptionsTest @Override protected MetricsOptions optionsFromDomainObject( final MetricsConfiguration.Builder domainObject) { - return MetricsOptions.fromConfiguration(domainObject.build()); + final var options = MetricsOptions.fromConfiguration(domainObject.build()); + options.setMetricCategoryRegistry(categoryRegistry); + return options; } @Override protected MetricsOptions getOptionsFromBesuCommand(final TestBesuCommand besuCommand) { return besuCommand.getMetricsOptions(); } + + @Override + protected String[] getNonOptionFields() { + return new String[] {"metricCategoryRegistry"}; + } + + @Test + public void enableRocksDbCategories() { + final var rocksDbMetricsCategories = + EnumSet.of( + BesuMetricCategory.KVSTORE_ROCKSDB, + BesuMetricCategory.KVSTORE_ROCKSDB_STATS, + BesuMetricCategory.KVSTORE_PRIVATE_ROCKSDB, + BesuMetricCategory.KVSTORE_PRIVATE_ROCKSDB_STATS); + + internalTestSuccess( + metricsConfBuilder -> { + assertThat(metricsConfBuilder.build().getMetricCategories()) + .containsExactlyInAnyOrderElementsOf(rocksDbMetricsCategories); + }, + "--metrics-categories", + rocksDbMetricsCategories.stream().map(Enum::name).collect(Collectors.joining(","))); + } } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/MiningOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/MiningOptionsTest.java index e32ff0e463..f94504ea47 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/MiningOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/MiningOptionsTest.java @@ -15,19 +15,19 @@ package org.hyperledger.besu.cli.options; import static org.assertj.core.api.Assertions.assertThat; -import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME; -import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_POA_BLOCK_TXS_SELECTION_MAX_TIME; -import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_POS_BLOCK_CREATION_MAX_TIME; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.DEFAULT_POA_BLOCK_TXS_SELECTION_MAX_TIME; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.Unstable.DEFAULT_POS_BLOCK_CREATION_MAX_TIME; import static org.mockito.Mockito.atMost; import static org.mockito.Mockito.verify; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.GasLimitCalculator; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.Unstable; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.Unstable; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.util.number.PositiveNumber; import java.io.IOException; @@ -42,7 +42,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -public class MiningOptionsTest extends AbstractCLIOptionsTest { +public class MiningOptionsTest extends AbstractCLIOptionsTest { @Test public void besuDoesNotStartInMiningModeIfCoinbaseNotSet() { @@ -390,13 +390,13 @@ public class MiningOptionsTest extends AbstractCLIOptionsTest besuControllerBuilderSchedule = new TreeMap<>(); besuControllerBuilderSchedule.put(0L, besuControllerBuilder1); @@ -180,15 +180,14 @@ public class ConsensusScheduleBesuControllerBuilderTest { new ConsensusScheduleBesuControllerBuilder(besuControllerBuilderSchedule); final ConsensusContext consensusContext = controllerBuilder.createConsensusContext( - Mockito.mock(Blockchain.class), - Mockito.mock(WorldStateArchive.class), - Mockito.mock(ProtocolSchedule.class)); + mock(Blockchain.class), mock(WorldStateArchive.class), mock(ProtocolSchedule.class)); - assertThat(consensusContext).isInstanceOf(MigratingContext.class); - final MigratingContext migratingContext = (MigratingContext) consensusContext; + assertThat(consensusContext).isInstanceOf(MigratingConsensusContext.class); + final MigratingConsensusContext migratingConsensusContext = + (MigratingConsensusContext) consensusContext; final ForksSchedule contextSchedule = - migratingContext.getConsensusContextSchedule(); + migratingConsensusContext.getConsensusContextSchedule(); final NavigableSet> expectedConsensusContextSpecs = new TreeSet<>(ForkSpec.COMPARATOR); diff --git a/besu/src/test/java/org/hyperledger/besu/controller/MergeBesuControllerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/controller/MergeBesuControllerBuilderTest.java index f8c00b20ea..47971b6442 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/MergeBesuControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/MergeBesuControllerBuilderTest.java @@ -41,7 +41,7 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; @@ -95,7 +95,7 @@ public class MergeBesuControllerBuilderTest { @Mock CheckpointConfigOptions checkpointConfigOptions; @Mock(answer = Answers.RETURNS_DEEP_STUBS) - MiningParameters miningParameters; + MiningConfiguration miningConfiguration; @Mock PrivacyParameters privacyParameters; @Mock Clock clock; @@ -167,7 +167,7 @@ public class MergeBesuControllerBuilderTest { lenient() .when(worldStateKeyValueStorage.updater()) .thenReturn(mock(ForestWorldStateKeyValueStorage.Updater.class)); - lenient().when(miningParameters.getTargetGasLimit()).thenReturn(OptionalLong.empty()); + lenient().when(miningConfiguration.getTargetGasLimit()).thenReturn(OptionalLong.empty()); besuControllerBuilder = visitWithMockConfigs(new MergeBesuControllerBuilder()); } @@ -179,7 +179,7 @@ public class MergeBesuControllerBuilderTest { .genesisConfigFile(genesisConfigFile) .synchronizerConfiguration(synchronizerConfiguration) .ethProtocolConfiguration(ethProtocolConfiguration) - .miningParameters(miningParameters) + .miningParameters(miningConfiguration) .metricsSystem(observableMetricsSystem) .privacyParameters(privacyParameters) .dataDirectory(tempDir) diff --git a/besu/src/test/java/org/hyperledger/besu/controller/QbftBesuControllerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/controller/QbftBesuControllerBuilderTest.java index a6cb42b185..5e41a65bd0 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/QbftBesuControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/QbftBesuControllerBuilderTest.java @@ -32,7 +32,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import java.util.List; @@ -108,7 +108,7 @@ public class QbftBesuControllerBuilderTest extends AbstractBftBesuControllerBuil assertThatThrownBy( () -> bftBesuControllerBuilder.createAdditionalJsonRpcMethodFactory( - protocolContext, protocolSchedule, MiningParameters.newDefault())) + protocolContext, protocolSchedule, MiningConfiguration.newDefault())) .isInstanceOf(NullPointerException.class) .hasMessage("transactionValidatorProvider should have been initialised"); } diff --git a/besu/src/test/java/org/hyperledger/besu/controller/TransitionControllerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/controller/TransitionControllerBuilderTest.java index 40d72e4ed1..24b0133a0f 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/TransitionControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/TransitionControllerBuilderTest.java @@ -35,10 +35,10 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; @@ -84,7 +84,7 @@ public class TransitionControllerBuilderTest { CliqueBesuControllerBuilder cliqueBuilder = new CliqueBesuControllerBuilder(); BesuControllerBuilder powBuilder = new MainnetBesuControllerBuilder(); MergeBesuControllerBuilder postMergeBuilder = new MergeBesuControllerBuilder(); - MiningParameters miningParameters; + MiningConfiguration miningConfiguration; TransitionProtocolSchedule transitionProtocolSchedule; @@ -118,27 +118,27 @@ public class TransitionControllerBuilderTest { .thenReturn(mergeContext); when(ethProtocolManager.ethContext().getScheduler()) .thenReturn(new DeterministicEthScheduler()); - miningParameters = MiningParameters.newDefault(); + miningConfiguration = MiningConfiguration.newDefault(); } @Test public void assertCliqueMiningOverridePreMerge() { - assertThat(miningParameters.isMiningEnabled()).isFalse(); + assertThat(miningConfiguration.isMiningEnabled()).isFalse(); var transCoordinator = buildTransitionCoordinator(cliqueBuilder, postMergeBuilder); assertThat(transCoordinator.isMiningBeforeMerge()).isTrue(); } @Test public void assertPoWIsNotMiningPreMerge() { - assertThat(miningParameters.isMiningEnabled()).isFalse(); + assertThat(miningConfiguration.isMiningEnabled()).isFalse(); var transCoordinator = buildTransitionCoordinator(powBuilder, postMergeBuilder); assertThat(transCoordinator.isMiningBeforeMerge()).isFalse(); } @Test public void assertPowMiningPreMerge() { - miningParameters = - ImmutableMiningParameters.builder() + miningConfiguration = + ImmutableMiningConfiguration.builder() .mutableInitValues(MutableInitValues.builder().isMiningEnabled(true).build()) .build(); var transCoordinator = buildTransitionCoordinator(powBuilder, postMergeBuilder); @@ -273,7 +273,7 @@ public class TransitionControllerBuilderTest { transitionProtocolSchedule, protocolContext, transactionPool, - miningParameters, + miningConfiguration, syncState, ethProtocolManager); 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 f2f78f102a..7e1edb601e 100644 --- a/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java +++ b/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java @@ -36,7 +36,7 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; @@ -173,7 +173,7 @@ public class BesuEventsImplTest { syncState, txPoolConfig, new BlobCache(), - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); serviceImpl = new BesuEventsImpl( diff --git a/besu/src/test/java/org/hyperledger/besu/services/TraceServiceImplTest.java b/besu/src/test/java/org/hyperledger/besu/services/TraceServiceImplTest.java index 1e734f6231..bcbf1c2fe7 100644 --- a/besu/src/test/java/org/hyperledger/besu/services/TraceServiceImplTest.java +++ b/besu/src/test/java/org/hyperledger/besu/services/TraceServiceImplTest.java @@ -31,7 +31,7 @@ import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.evm.log.Log; import org.hyperledger.besu.evm.worldstate.WorldView; @@ -80,7 +80,7 @@ class TraceServiceImplTest { blockchainSetupUtil.getProtocolSchedule(), blockchain, worldStateArchive, - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); traceService = new TraceServiceImpl(blockchainQueries, blockchainSetupUtil.getProtocolSchedule()); } diff --git a/besu/src/test/resources/everything_config.toml b/besu/src/test/resources/everything_config.toml index e89442f7f7..960b2b5772 100644 --- a/besu/src/test/resources/everything_config.toml +++ b/besu/src/test/resources/everything_config.toml @@ -120,6 +120,19 @@ rpc-ws-max-frame-size=65535 rpc-ws-authentication-enabled=false rpc-ws-authentication-credentials-file="none" rpc-ws-authentication-jwt-public-key-file="none" +rpc-ws-ssl-enabled=false +rpc-ws-ssl-keystore-file="none.pfx" +rpc-ws-ssl-keystore-password="none.passwd" +rpc-ws-ssl-keystore-type="none" +rpc-ws-ssl-client-auth-enabled=false +rpc-ws-ssl-truststore-file="none.pfx" +rpc-ws-ssl-truststore-password="none.passwd" +rpc-ws-ssl-truststore-type="none" +rpc-ws-ssl-key-file="none.pfx" +rpc-ws-ssl-cert-file="none.pfx" +rpc-ws-ssl-trustcert-file="none.pfx" + + # API api-gas-price-blocks=100 diff --git a/build.gradle b/build.gradle index 09a600dd25..1981965a8e 100644 --- a/build.gradle +++ b/build.gradle @@ -418,9 +418,6 @@ configure(allprojects - project(':platform')) { '-org.hyperledger.besu.ethereum.permissioning.*,' + // referencetests module '-org.hyperledger.besu.ethereum.referencetests,' + - // retesteth module - '-org.hyperledger.besu.ethereum.retesteth.methods,' + - '-org.hyperledger.besu.ethereum.retesteth,' + //rlp module '-org.hyperledger.besu.ethereum.rlp,' + // stratum module diff --git a/config/build.gradle b/config/build.gradle index a78b9a7105..e269ce51fc 100644 --- a/config/build.gradle +++ b/config/build.gradle @@ -36,11 +36,13 @@ dependencies { implementation 'com.fasterxml.jackson.core:jackson-databind' implementation 'com.google.guava:guava' + implementation 'com.google.dagger:dagger' implementation 'info.picocli:picocli' implementation 'io.tmio:tuweni-bytes' implementation 'io.tmio:tuweni-units' implementation "org.immutables:value-annotations" annotationProcessor "org.immutables:value" + annotationProcessor 'com.google.dagger:dagger-compiler' testImplementation project(':testutil') diff --git a/config/src/main/java/org/hyperledger/besu/config/GenesisReader.java b/config/src/main/java/org/hyperledger/besu/config/GenesisReader.java index 6b42c3c2ed..4ee99f0bd8 100644 --- a/config/src/main/java/org/hyperledger/besu/config/GenesisReader.java +++ b/config/src/main/java/org/hyperledger/besu/config/GenesisReader.java @@ -80,7 +80,9 @@ interface GenesisReader { final var on = normalizeKeys((ObjectNode) entry.getValue()); return new GenesisAccount( Address.fromHexString(entry.getKey()), - JsonUtil.getString(on, "nonce").map(ParserUtils::parseUnsignedLong).orElse(0L), + JsonUtil.getValueAsString(on, "nonce") + .map(ParserUtils::parseUnsignedLong) + .orElse(0L), JsonUtil.getString(on, "balance") .map(ParserUtils::parseBalance) .orElse(Wei.ZERO), diff --git a/config/src/test/java/org/hyperledger/besu/config/GenesisReaderTest.java b/config/src/test/java/org/hyperledger/besu/config/GenesisReaderTest.java index f8327174a3..eab6dfac73 100644 --- a/config/src/test/java/org/hyperledger/besu/config/GenesisReaderTest.java +++ b/config/src/test/java/org/hyperledger/besu/config/GenesisReaderTest.java @@ -17,6 +17,7 @@ package org.hyperledger.besu.config; import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.config.GenesisReader.ALLOCATION_FIELD; import static org.hyperledger.besu.config.GenesisReader.CONFIG_FIELD; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; @@ -27,6 +28,7 @@ import java.nio.file.Path; import java.util.Map; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.ObjectNode; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -111,4 +113,17 @@ public class GenesisReaderTest { entry.put("balance", balance.toShortHexString()); return entry; } + + @Test + void testNonceHandlingAsStringAndInteger() { + ObjectNode accountNode = JsonNodeFactory.instance.objectNode(); + + accountNode.put("nonce", 10); + String nonceAsStringFromInt = JsonUtil.getValueAsString(accountNode, "nonce").orElse(""); + assertEquals("10", nonceAsStringFromInt, "Nonce should convert integer to string correctly"); + + accountNode.put("nonce", "20"); + String nonceAsStringDirect = JsonUtil.getValueAsString(accountNode, "nonce").orElse(""); + assertEquals("20", nonceAsStringDirect, "Nonce should keep string as string correctly"); + } } diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculator.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculator.java index a5771238d2..b0869feb23 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculator.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculator.java @@ -15,7 +15,6 @@ package org.hyperledger.besu.consensus.clique; import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.mainnet.DifficultyCalculator; @@ -39,12 +38,9 @@ public class CliqueDifficultyCalculator implements DifficultyCalculator { } @Override - public BigInteger nextDifficulty( - final long time, final BlockHeader parent, final ProtocolContext context) { + public BigInteger nextDifficulty(final long time, final BlockHeader parent) { - final Address nextProposer = - CliqueHelpers.getProposerForBlockAfter( - parent, context.getConsensusContext(CliqueContext.class).getValidatorProvider()); + final Address nextProposer = CliqueHelpers.getProposerForBlockAfter(parent); return nextProposer.equals(localAddress) ? IN_TURN_DIFFICULTY : OUT_OF_TURN_DIFFICULTY; } } diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueHelpers.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueHelpers.java index cba98a5a5e..d64fe899a6 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueHelpers.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueHelpers.java @@ -27,9 +27,20 @@ import java.util.Comparator; /** The Clique helpers. */ public class CliqueHelpers { + private static CliqueContext cliqueContext; + /** Default constructor. */ CliqueHelpers() {} + /** + * Set the clique consensus context + * + * @param cliqueContext the clique consensus context + */ + public static void setCliqueContext(final CliqueContext cliqueContext) { + CliqueHelpers.cliqueContext = cliqueContext; + } + /** * Gets proposer of block. * @@ -45,12 +56,11 @@ public class CliqueHelpers { * Gets proposer for block after. * * @param parent the parent - * @param validatorProvider the validator provider * @return the proposer for block after */ - static Address getProposerForBlockAfter( - final BlockHeader parent, final ValidatorProvider validatorProvider) { - final CliqueProposerSelector proposerSelector = new CliqueProposerSelector(validatorProvider); + static Address getProposerForBlockAfter(final BlockHeader parent) { + final CliqueProposerSelector proposerSelector = + new CliqueProposerSelector(cliqueContext.getValidatorProvider()); return proposerSelector.selectProposerForNextBlock(parent); } diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueMiningTracker.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueMiningTracker.java index d636212283..8f350609dc 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueMiningTracker.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueMiningTracker.java @@ -42,10 +42,7 @@ public class CliqueMiningTracker { * @return the boolean */ public boolean isProposerAfter(final BlockHeader header) { - final Address nextProposer = - CliqueHelpers.getProposerForBlockAfter( - header, - protocolContext.getConsensusContext(CliqueContext.class).getValidatorProvider()); + final Address nextProposer = CliqueHelpers.getProposerForBlockAfter(header); return localAddress.equals(nextProposer); } diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java index cd19755638..a60fcc5812 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java @@ -22,7 +22,7 @@ import org.hyperledger.besu.cryptoservices.NodeKey; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; @@ -44,8 +44,6 @@ import java.util.Map; import java.util.Optional; import java.util.function.Function; -import com.google.common.annotations.VisibleForTesting; - /** Defines the protocol behaviours for a blockchain using Clique. */ public class CliqueProtocolSchedule { @@ -63,7 +61,7 @@ public class CliqueProtocolSchedule { * @param privacyParameters the privacy parameters * @param isRevertReasonEnabled the is revert reason enabled * @param evmConfiguration the evm configuration - * @param miningParameters the mining parameters + * @param miningConfiguration the mining configuration * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled * @param metricsSystem A metricSystem instance to be able to expose metrics in the underlying @@ -77,7 +75,7 @@ public class CliqueProtocolSchedule { final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -110,57 +108,18 @@ public class CliqueProtocolSchedule { return new ProtocolScheduleBuilder( config, - DEFAULT_CHAIN_ID, + Optional.of(DEFAULT_CHAIN_ID), specAdapters, privacyParameters, isRevertReasonEnabled, evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem) .createProtocolSchedule(); } - /** - * Create protocol schedule. - * - * @param config the config - * @param forksSchedule the transitions - * @param nodeKey the node key - * @param isRevertReasonEnabled the is revert reason enabled - * @param evmConfiguration the evm configuration - * @param miningParameters the mining parameters - * @param badBlockManager the cache to use to keep invalid blocks - * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled - * @param metricsSystem A metricSystem instance to be able to expose metrics in the underlying - * calls - * @return the protocol schedule - */ - @VisibleForTesting - public static ProtocolSchedule create( - final GenesisConfigOptions config, - final ForksSchedule forksSchedule, - final NodeKey nodeKey, - final boolean isRevertReasonEnabled, - final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, - final BadBlockManager badBlockManager, - final boolean isParallelTxProcessingEnabled, - final MetricsSystem metricsSystem) { - return create( - config, - forksSchedule, - nodeKey, - PrivacyParameters.DEFAULT, - isRevertReasonEnabled, - evmConfiguration, - miningParameters, - badBlockManager, - isParallelTxProcessingEnabled, - metricsSystem); - } - private static ProtocolSpecBuilder applyCliqueSpecificModifications( final EpochManager epochManager, final long secondsBetweenBlocks, diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreator.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreator.java index ed17529a9f..18d3449ba8 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreator.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreator.java @@ -29,7 +29,7 @@ import org.hyperledger.besu.ethereum.blockcreation.AbstractBlockCreator; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.SealableBlockHeader; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; @@ -48,7 +48,7 @@ public class CliqueBlockCreator extends AbstractBlockCreator { /** * Instantiates a new Clique block creator. * - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param extraDataCalculator the extra data calculator * @param transactionPool the pending transactions * @param protocolContext the protocol context @@ -58,7 +58,7 @@ public class CliqueBlockCreator extends AbstractBlockCreator { * @param ethScheduler the scheduler for asynchronous block creation tasks */ public CliqueBlockCreator( - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final ExtraDataCalculator extraDataCalculator, final TransactionPool transactionPool, final ProtocolContext protocolContext, @@ -67,7 +67,7 @@ public class CliqueBlockCreator extends AbstractBlockCreator { final EpochManager epochManager, final EthScheduler ethScheduler) { super( - miningParameters, + miningConfiguration, __ -> Util.publicKeyToAddress(nodeKey.getPublicKey()), extraDataCalculator, transactionPool, diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutor.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutor.java index ef3d58fbff..998a237e91 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutor.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutor.java @@ -28,7 +28,7 @@ import org.hyperledger.besu.ethereum.blockcreation.AbstractMinerExecutor; import org.hyperledger.besu.ethereum.chain.MinedBlockObserver; import org.hyperledger.besu.ethereum.chain.PoWObserver; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; @@ -70,7 +70,7 @@ public class CliqueMinerExecutor extends AbstractMinerExecutor final ProtocolSchedule protocolSchedule, final TransactionPool transactionPool, final NodeKey nodeKey, - final MiningParameters miningParams, + final MiningConfiguration miningParams, final AbstractBlockScheduler blockScheduler, final EpochManager epochManager, final ForksSchedule forksSchedule, @@ -97,7 +97,7 @@ public class CliqueMinerExecutor extends AbstractMinerExecutor final Function blockCreator = (header) -> new CliqueBlockCreator( - miningParameters, + miningConfiguration, this::calculateExtraData, transactionPool, protocolContext, @@ -119,7 +119,7 @@ public class CliqueMinerExecutor extends AbstractMinerExecutor @Override public Optional
getCoinbase() { - return miningParameters.getCoinbase(); + return miningConfiguration.getCoinbase(); } /** @@ -134,7 +134,7 @@ public class CliqueMinerExecutor extends AbstractMinerExecutor final Bytes vanityDataToInsert = ConsensusHelpers.zeroLeftPad( - miningParameters.getExtraData(), CliqueExtraData.EXTRA_VANITY_LENGTH); + miningConfiguration.getExtraData(), CliqueExtraData.EXTRA_VANITY_LENGTH); // Building ON TOP of canonical head, if the next block is epoch, include validators. if (epochManager.isEpochBlock(parentHeader.getNumber() + 1)) { diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRule.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRule.java index a14b5187ef..87c83b2cb0 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRule.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRule.java @@ -38,10 +38,9 @@ public class CliqueDifficultyValidationRule implements AttachedBlockHeaderValida public boolean validate( final BlockHeader header, final BlockHeader parent, final ProtocolContext protocolContext) { final Address actualBlockCreator = CliqueHelpers.getProposerOfBlock(header); - final CliqueDifficultyCalculator diffCalculator = new CliqueDifficultyCalculator(actualBlockCreator); - final BigInteger expectedDifficulty = diffCalculator.nextDifficulty(0, parent, protocolContext); + final BigInteger expectedDifficulty = diffCalculator.nextDifficulty(0, parent); final BigInteger actualDifficulty = header.getDifficulty().toBigInteger(); diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/CliqueJsonRpcMethods.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/CliqueJsonRpcMethods.java index 762cce1c56..4e1e75f54c 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/CliqueJsonRpcMethods.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/CliqueJsonRpcMethods.java @@ -31,7 +31,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.methods.ApiGroupJsonRpcMethods; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; @@ -41,22 +41,22 @@ import java.util.Map; public class CliqueJsonRpcMethods extends ApiGroupJsonRpcMethods { private final ProtocolContext context; private final ProtocolSchedule protocolSchedule; - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; /** * Instantiates a new Clique json rpc methods. * * @param context the protocol context * @param protocolSchedule the protocol schedule - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters */ public CliqueJsonRpcMethods( final ProtocolContext context, final ProtocolSchedule protocolSchedule, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { this.context = context; this.protocolSchedule = protocolSchedule; - this.miningParameters = miningParameters; + this.miningConfiguration = miningConfiguration; } @Override @@ -69,7 +69,7 @@ public class CliqueJsonRpcMethods extends ApiGroupJsonRpcMethods { final MutableBlockchain blockchain = context.getBlockchain(); final WorldStateArchive worldStateArchive = context.getWorldStateArchive(); final BlockchainQueries blockchainQueries = - new BlockchainQueries(protocolSchedule, blockchain, worldStateArchive, miningParameters); + new BlockchainQueries(protocolSchedule, blockchain, worldStateArchive, miningConfiguration); final ValidatorProvider validatorProvider = context.getConsensusContext(CliqueContext.class).getValidatorProvider(); diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculatorTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculatorTest.java index 3c9da2520d..74537b2ad1 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculatorTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculatorTest.java @@ -23,8 +23,6 @@ import org.hyperledger.besu.consensus.common.validator.ValidatorProvider; import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.ethereum.ProtocolContext; -import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.AddressHelpers; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; @@ -43,9 +41,7 @@ public class CliqueDifficultyCalculatorTest { private Address localAddr; private final List
validatorList = Lists.newArrayList(); - private ProtocolContext cliqueProtocolContext; private BlockHeaderTestFixture blockHeaderBuilder; - private final CliqueBlockInterface blockInterface = new CliqueBlockInterface(); @BeforeEach public void setup() { @@ -56,9 +52,7 @@ public class CliqueDifficultyCalculatorTest { final ValidatorProvider validatorProvider = mock(ValidatorProvider.class); when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); - - final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); - cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext, new BadBlockManager()); + CliqueHelpers.setCliqueContext(new CliqueContext(validatorProvider, null, null)); blockHeaderBuilder = new BlockHeaderTestFixture(); } @@ -68,8 +62,7 @@ public class CliqueDifficultyCalculatorTest { final BlockHeader parentHeader = blockHeaderBuilder.number(1).buildHeader(); - assertThat(calculator.nextDifficulty(0, parentHeader, cliqueProtocolContext)) - .isEqualTo(BigInteger.valueOf(2)); + assertThat(calculator.nextDifficulty(0, parentHeader)).isEqualTo(BigInteger.valueOf(2)); } @Test @@ -78,7 +71,6 @@ public class CliqueDifficultyCalculatorTest { final BlockHeader parentHeader = blockHeaderBuilder.number(2).buildHeader(); - assertThat(calculator.nextDifficulty(0, parentHeader, cliqueProtocolContext)) - .isEqualTo(BigInteger.valueOf(1)); + assertThat(calculator.nextDifficulty(0, parentHeader)).isEqualTo(BigInteger.valueOf(1)); } } diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueProtocolScheduleTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueProtocolScheduleTest.java index 5cbdbb6d06..4774120622 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueProtocolScheduleTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueProtocolScheduleTest.java @@ -32,7 +32,8 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; +import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; @@ -66,9 +67,10 @@ public class CliqueProtocolScheduleTest { config, new ForksSchedule<>(List.of()), NODE_KEY, + PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -92,9 +94,10 @@ public class CliqueProtocolScheduleTest { GenesisConfigFile.DEFAULT.getConfigOptions(), forksSchedule, NODE_KEY, + PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) @@ -118,9 +121,10 @@ public class CliqueProtocolScheduleTest { genesisConfig, new ForksSchedule<>(List.of()), NODE_KEY, + PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem())) @@ -140,9 +144,10 @@ public class CliqueProtocolScheduleTest { genesisConfig, new ForksSchedule<>(List.of()), NODE_KEY, + PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem())) @@ -166,9 +171,10 @@ public class CliqueProtocolScheduleTest { config, forksSchedule, NODE_KEY, + PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); 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 ca76517c62..0ece282332 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 @@ -49,9 +49,10 @@ import org.hyperledger.besu.ethereum.core.AddressHelpers; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; +import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; @@ -99,26 +100,29 @@ public class CliqueBlockCreatorTest { @BeforeEach void setup() { + final Address otherAddress = Util.publicKeyToAddress(otherKeyPair.getPublicKey()); + validatorList.add(otherAddress); + + validatorProvider = mock(ValidatorProvider.class); + voteProvider = mock(VoteProvider.class); + when(validatorProvider.getVoteProviderAtHead()).thenReturn(Optional.of(voteProvider)); + when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); + protocolSchedule = CliqueProtocolSchedule.create( GenesisConfigFile.DEFAULT.getConfigOptions(), new ForksSchedule<>(List.of()), proposerNodeKey, + PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); - final Address otherAddress = Util.publicKeyToAddress(otherKeyPair.getPublicKey()); - validatorList.add(otherAddress); - - validatorProvider = mock(ValidatorProvider.class); - voteProvider = mock(VoteProvider.class); - when(validatorProvider.getVoteProviderAtHead()).thenReturn(Optional.of(voteProvider)); - when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); + CliqueHelpers.setCliqueContext(cliqueContext); final Block genesis = GenesisState.fromConfig(GenesisConfigFile.mainnet(), protocolSchedule).getBlock(); @@ -146,11 +150,11 @@ public class CliqueBlockCreatorTest { final Address coinbase = AddressHelpers.ofValue(1); - final MiningParameters miningParameters = createMiningParameters(extraData, coinbase); + final MiningConfiguration miningConfiguration = createMiningConfiguration(extraData, coinbase); final CliqueBlockCreator blockCreator = new CliqueBlockCreator( - miningParameters, + miningConfiguration, parent -> extraData, createTransactionPool(), protocolContext, @@ -175,11 +179,11 @@ public class CliqueBlockCreatorTest { when(voteProvider.getVoteAfterBlock(any(), any())) .thenReturn(Optional.of(new ValidatorVote(VoteType.ADD, coinbase, a1))); - final MiningParameters miningParameters = createMiningParameters(extraData, coinbase); + final MiningConfiguration miningConfiguration = createMiningConfiguration(extraData, coinbase); final CliqueBlockCreator blockCreator = new CliqueBlockCreator( - miningParameters, + miningConfiguration, parent -> extraData, createTransactionPool(), protocolContext, @@ -209,11 +213,11 @@ public class CliqueBlockCreatorTest { when(mockVoteProvider.getVoteAfterBlock(any(), any())) .thenReturn(Optional.of(new ValidatorVote(VoteType.ADD, coinbase, a1))); - final MiningParameters miningParameters = createMiningParameters(extraData, coinbase); + final MiningConfiguration miningConfiguration = createMiningConfiguration(extraData, coinbase); final CliqueBlockCreator blockCreator = new CliqueBlockCreator( - miningParameters, + miningConfiguration, parent -> extraData, createTransactionPool(), protocolContext, @@ -252,10 +256,10 @@ public class CliqueBlockCreatorTest { return transactionPool; } - private static MiningParameters createMiningParameters( + private static MiningConfiguration createMiningConfiguration( final Bytes extraData, final Address coinbase) { - final MiningParameters miningParameters = - ImmutableMiningParameters.builder() + final MiningConfiguration miningConfiguration = + ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .extraData(extraData) @@ -264,6 +268,6 @@ public class CliqueBlockCreatorTest { .coinbase(coinbase) .build()) .build(); - return miningParameters; + return miningConfiguration; } } diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java index 1aa2d75ef3..9c2bf04bce 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java @@ -26,6 +26,7 @@ import org.hyperledger.besu.consensus.clique.CliqueBlockHeaderFunctions; import org.hyperledger.besu.consensus.clique.CliqueBlockInterface; import org.hyperledger.besu.consensus.clique.CliqueContext; import org.hyperledger.besu.consensus.clique.CliqueExtraData; +import org.hyperledger.besu.consensus.clique.CliqueHelpers; import org.hyperledger.besu.consensus.clique.CliqueProtocolSchedule; import org.hyperledger.besu.consensus.common.EpochManager; import org.hyperledger.besu.consensus.common.ForksSchedule; @@ -39,9 +40,10 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.AddressHelpers; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; +import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; @@ -97,15 +99,17 @@ public class CliqueMinerExecutorTest { when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); + CliqueHelpers.setCliqueContext(cliqueContext); cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext, new BadBlockManager()); cliqueProtocolSchedule = CliqueProtocolSchedule.create( GENESIS_CONFIG_OPTIONS, new ForksSchedule<>(List.of()), proposerNodeKey, + PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -117,7 +121,7 @@ public class CliqueMinerExecutorTest { public void extraDataCreatedOnEpochBlocksContainsValidators() { final Bytes vanityData = generateRandomVanityData(); - final MiningParameters miningParameters = createMiningParameters(vanityData); + final MiningConfiguration miningConfiguration = createMiningConfiguration(vanityData); final CliqueMinerExecutor executor = new CliqueMinerExecutor( @@ -125,7 +129,7 @@ public class CliqueMinerExecutorTest { cliqueProtocolSchedule, createTransactionPool(), proposerNodeKey, - miningParameters, + miningConfiguration, mock(CliqueBlockScheduler.class), new EpochManager(EPOCH_LENGTH), null, @@ -153,7 +157,7 @@ public class CliqueMinerExecutorTest { public void extraDataForNonEpochBlocksDoesNotContainValidaors() { final Bytes vanityData = generateRandomVanityData(); - final MiningParameters miningParameters = createMiningParameters(vanityData); + final MiningConfiguration miningConfiguration = createMiningConfiguration(vanityData); final CliqueMinerExecutor executor = new CliqueMinerExecutor( @@ -161,7 +165,7 @@ public class CliqueMinerExecutorTest { cliqueProtocolSchedule, createTransactionPool(), proposerNodeKey, - miningParameters, + miningConfiguration, mock(CliqueBlockScheduler.class), new EpochManager(EPOCH_LENGTH), null, @@ -189,7 +193,7 @@ public class CliqueMinerExecutorTest { final Bytes initialVanityData = generateRandomVanityData(); final Bytes modifiedVanityData = generateRandomVanityData(); - final MiningParameters miningParameters = createMiningParameters(initialVanityData); + final MiningConfiguration miningConfiguration = createMiningConfiguration(initialVanityData); final CliqueMinerExecutor executor = new CliqueMinerExecutor( @@ -197,13 +201,13 @@ public class CliqueMinerExecutorTest { cliqueProtocolSchedule, createTransactionPool(), proposerNodeKey, - miningParameters, + miningConfiguration, mock(CliqueBlockScheduler.class), new EpochManager(EPOCH_LENGTH), null, ethScheduler); - miningParameters.setExtraData(modifiedVanityData); + miningConfiguration.setExtraData(modifiedVanityData); final Bytes extraDataBytes = executor.calculateExtraData(blockHeaderBuilder.buildHeader()); final CliqueExtraData cliqueExtraData = @@ -253,8 +257,8 @@ public class CliqueMinerExecutorTest { return Bytes.wrap(vanityData); } - private static MiningParameters createMiningParameters(final Bytes vanityData) { - return ImmutableMiningParameters.builder() + private static MiningConfiguration createMiningConfiguration(final Bytes vanityData) { + return ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .extraData(vanityData) 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 543d110ef4..fd39a46cfc 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 @@ -25,6 +25,7 @@ import static org.mockito.Mockito.when; import org.hyperledger.besu.consensus.clique.CliqueBlockInterface; import org.hyperledger.besu.consensus.clique.CliqueContext; +import org.hyperledger.besu.consensus.clique.CliqueHelpers; import org.hyperledger.besu.consensus.clique.CliqueMiningTracker; import org.hyperledger.besu.consensus.clique.TestHelpers; import org.hyperledger.besu.consensus.common.validator.ValidatorProvider; @@ -258,6 +259,7 @@ public class CliqueMiningCoordinatorTest { when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validators); final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); + CliqueHelpers.setCliqueContext(cliqueContext); when(protocolContext.getConsensusContext(CliqueContext.class)).thenReturn(cliqueContext); when(protocolContext.getBlockchain()).thenReturn(blockChain); diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java index d970d83d80..d7e4d07409 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java @@ -21,6 +21,7 @@ import static org.mockito.Mockito.when; import org.hyperledger.besu.consensus.clique.CliqueBlockInterface; import org.hyperledger.besu.consensus.clique.CliqueContext; +import org.hyperledger.besu.consensus.clique.CliqueHelpers; import org.hyperledger.besu.consensus.clique.TestHelpers; import org.hyperledger.besu.consensus.common.validator.ValidatorProvider; import org.hyperledger.besu.crypto.KeyPair; @@ -58,6 +59,7 @@ public class CliqueDifficultyValidationRuleTest { when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); + CliqueHelpers.setCliqueContext(cliqueContext); cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext, new BadBlockManager()); blockHeaderBuilder = new BlockHeaderTestFixture(); } diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingContext.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingConsensusContext.java similarity index 88% rename from consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingContext.java rename to consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingConsensusContext.java index f71e3ac7f3..91ace1a04b 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingContext.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingConsensusContext.java @@ -17,7 +17,7 @@ package org.hyperledger.besu.consensus.common; import org.hyperledger.besu.ethereum.ConsensusContext; /** The Migrating context. */ -public class MigratingContext implements ConsensusContext { +public class MigratingConsensusContext implements ConsensusContext { private final ForksSchedule consensusContextSchedule; @@ -26,7 +26,7 @@ public class MigratingContext implements ConsensusContext { * * @param consensusContextSchedule the consensus context schedule */ - public MigratingContext(final ForksSchedule consensusContextSchedule) { + public MigratingConsensusContext(final ForksSchedule consensusContextSchedule) { this.consensusContextSchedule = consensusContextSchedule; } diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingProtocolContext.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingProtocolContext.java index c0557485f3..27cce3157b 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingProtocolContext.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingProtocolContext.java @@ -15,11 +15,9 @@ package org.hyperledger.besu.consensus.common; import org.hyperledger.besu.ethereum.ConsensusContext; -import org.hyperledger.besu.ethereum.ConsensusContextFactory; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; /** The Migrating protocol context. */ @@ -32,42 +30,16 @@ public class MigratingProtocolContext extends ProtocolContext { * * @param blockchain the blockchain * @param worldStateArchive the world state archive - * @param consensusContextSchedule the consensus context schedule + * @param migratingConsensusContext the consensus context * @param badBlockManager the cache to use to keep invalid blocks */ public MigratingProtocolContext( final MutableBlockchain blockchain, final WorldStateArchive worldStateArchive, - final ForksSchedule consensusContextSchedule, + final MigratingConsensusContext migratingConsensusContext, final BadBlockManager badBlockManager) { - super(blockchain, worldStateArchive, null, badBlockManager); - this.consensusContextSchedule = consensusContextSchedule; - } - - /** - * Init protocol context. - * - * @param blockchain the blockchain - * @param worldStateArchive the world state archive - * @param protocolSchedule the protocol schedule - * @param consensusContextFactory the consensus context factory - * @param badBlockManager the cache to use to keep invalid blocks - * @return the protocol context - */ - public static ProtocolContext init( - final MutableBlockchain blockchain, - final WorldStateArchive worldStateArchive, - final ProtocolSchedule protocolSchedule, - final ConsensusContextFactory consensusContextFactory, - final BadBlockManager badBlockManager) { - final ConsensusContext consensusContext = - consensusContextFactory.create(blockchain, worldStateArchive, protocolSchedule); - final MigratingContext migratingContext = consensusContext.as(MigratingContext.class); - return new MigratingProtocolContext( - blockchain, - worldStateArchive, - migratingContext.getConsensusContextSchedule(), - badBlockManager); + super(blockchain, worldStateArchive, migratingConsensusContext, badBlockManager); + this.consensusContextSchedule = migratingConsensusContext.getConsensusContextSchedule(); } @Override diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilder.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilder.java index 311bf30fae..f92b58bbfa 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilder.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilder.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.consensus.common.ForksSchedule; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule; @@ -38,6 +38,7 @@ import org.hyperledger.besu.plugin.services.MetricsSystem; import java.math.BigInteger; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import java.util.function.Function; /** Defines the protocol behaviours for a blockchain using a BFT consensus mechanism. */ @@ -57,7 +58,7 @@ public abstract class BaseBftProtocolScheduleBuilder { * @param isRevertReasonEnabled the is revert reason enabled * @param bftExtraDataCodec the bft extra data codec * @param evmConfiguration the evm configuration - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled. * @param metricsSystem metricsSystem A metricSystem instance to be able to expose metrics in the @@ -71,7 +72,7 @@ public abstract class BaseBftProtocolScheduleBuilder { final boolean isRevertReasonEnabled, final BftExtraDataCodec bftExtraDataCodec, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -90,12 +91,12 @@ public abstract class BaseBftProtocolScheduleBuilder { final ProtocolSchedule protocolSchedule = new ProtocolScheduleBuilder( config, - DEFAULT_CHAIN_ID, + Optional.of(DEFAULT_CHAIN_ID), specAdapters, privacyParameters, isRevertReasonEnabled, evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem) @@ -132,7 +133,7 @@ public abstract class BaseBftProtocolScheduleBuilder { .blockBodyValidatorBuilder(MainnetBlockBodyValidator::new) .blockValidatorBuilder(MainnetProtocolSpecs.blockValidatorBuilder()) .blockImporterBuilder(MainnetBlockImporter::new) - .difficultyCalculator((time, parent, protocolContext) -> BigInteger.ONE) + .difficultyCalculator((time, parent) -> BigInteger.ONE) .skipZeroBlockRewards(true) .blockHeaderFunctions(BftBlockHeaderFunctions.forOnchainBlock(bftExtraDataCodec)) .blockReward(Wei.of(configOptions.getBlockRewardWei())) diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreator.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreator.java index 6bc0254b69..70d18fc3c9 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreator.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreator.java @@ -25,7 +25,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.blockcreation.AbstractBlockCreator; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.SealableBlockHeader; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; @@ -46,7 +46,7 @@ public class BftBlockCreator extends AbstractBlockCreator { /** * Instantiates a new Bft block creator. * - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param forksSchedule the forks schedule * @param localAddress the local address * @param extraDataCalculator the extra data calculator @@ -57,7 +57,7 @@ public class BftBlockCreator extends AbstractBlockCreator { * @param ethScheduler the scheduler for asynchronous block creation tasks */ public BftBlockCreator( - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final ForksSchedule forksSchedule, final Address localAddress, final ExtraDataCalculator extraDataCalculator, @@ -67,7 +67,7 @@ public class BftBlockCreator extends AbstractBlockCreator { final BftExtraDataCodec bftExtraDataCodec, final EthScheduler ethScheduler) { super( - miningParameters.setCoinbase(localAddress), + miningConfiguration.setCoinbase(localAddress), miningBeneficiaryCalculator(localAddress, forksSchedule), extraDataCalculator, transactionPool, diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreatorFactory.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreatorFactory.java index 7c679763b6..1349bbf461 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreatorFactory.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreatorFactory.java @@ -31,7 +31,7 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.blockcreation.BlockCreator; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import org.hyperledger.besu.ethereum.mainnet.AbstractGasLimitSpecification; @@ -54,7 +54,7 @@ public class BftBlockCreatorFactory { protected final ForksSchedule forksSchedule; /** The Mining parameters */ - protected final MiningParameters miningParameters; + protected final MiningConfiguration miningConfiguration; private final TransactionPool transactionPool; @@ -89,7 +89,7 @@ public class BftBlockCreatorFactory { final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, final ForksSchedule forksSchedule, - final MiningParameters miningParams, + final MiningConfiguration miningParams, final Address localAddress, final BftExtraDataCodec bftExtraDataCodec, final EthScheduler ethScheduler) { @@ -98,7 +98,7 @@ public class BftBlockCreatorFactory { this.protocolSchedule = protocolSchedule; this.forksSchedule = forksSchedule; this.localAddress = localAddress; - this.miningParameters = miningParams; + this.miningConfiguration = miningParams; this.bftExtraDataCodec = bftExtraDataCodec; this.ethScheduler = ethScheduler; } @@ -111,7 +111,7 @@ public class BftBlockCreatorFactory { */ public BlockCreator create(final int round) { return new BftBlockCreator( - miningParameters, + miningConfiguration, forksSchedule, localAddress, ph -> createExtraData(round, ph), @@ -128,7 +128,7 @@ public class BftBlockCreatorFactory { * @param minTransactionGasPrice the min transaction gas price */ public void setMinTransactionGasPrice(final Wei minTransactionGasPrice) { - miningParameters.setMinTransactionGasPrice(minTransactionGasPrice); + miningConfiguration.setMinTransactionGasPrice(minTransactionGasPrice); } /** @@ -137,7 +137,7 @@ public class BftBlockCreatorFactory { * @return the min transaction gas price */ public Wei getMinTransactionGasPrice() { - return miningParameters.getMinTransactionGasPrice(); + return miningConfiguration.getMinTransactionGasPrice(); } /** @@ -146,7 +146,7 @@ public class BftBlockCreatorFactory { * @return min priority fee per gas */ public Wei getMinPriorityFeePerGas() { - return miningParameters.getMinPriorityFeePerGas(); + return miningConfiguration.getMinPriorityFeePerGas(); } /** @@ -171,7 +171,7 @@ public class BftBlockCreatorFactory { final BftExtraData extraData = new BftExtraData( ConsensusHelpers.zeroLeftPad( - miningParameters.getExtraData(), BftExtraDataCodec.EXTRA_VANITY_LENGTH), + miningConfiguration.getExtraData(), BftExtraDataCodec.EXTRA_VANITY_LENGTH), Collections.emptyList(), toVote(proposal), round, @@ -187,7 +187,7 @@ public class BftBlockCreatorFactory { */ public void changeTargetGasLimit(final Long newTargetGasLimit) { if (AbstractGasLimitSpecification.isValidTargetGasLimit(newTargetGasLimit)) { - miningParameters.setTargetGasLimit(newTargetGasLimit); + miningConfiguration.setTargetGasLimit(newTargetGasLimit); } else { throw new UnsupportedOperationException("Specified target gas limit is invalid"); } diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java index 02689d52af..02da30f507 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java @@ -21,7 +21,7 @@ import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -172,12 +172,12 @@ public class CombinedProtocolScheduleFactoryTest { final ProtocolScheduleBuilder protocolScheduleBuilder = new ProtocolScheduleBuilder( genesisConfigOptions, - BigInteger.ONE, + Optional.of(BigInteger.ONE), ProtocolSpecAdapters.create(0, Function.identity()), new PrivacyParameters(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java index d62de57eac..39ab9f8cb2 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java @@ -43,9 +43,13 @@ public class MigratingProtocolContextTest { final ForksSchedule contextSchedule = new ForksSchedule<>(List.of(new ForkSpec<>(0L, context1), new ForkSpec<>(10L, context2))); + final MigratingProtocolContext migratingProtocolContext = new MigratingProtocolContext( - blockchain, worldStateArchive, contextSchedule, new BadBlockManager()); + blockchain, + worldStateArchive, + new MigratingConsensusContext(contextSchedule), + new BadBlockManager()); assertThat(migratingProtocolContext.getConsensusContext(ConsensusContext.class)) .isSameAs(context1); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java index e23664fd8d..56a0e33986 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java @@ -31,7 +31,7 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule; @@ -245,7 +245,7 @@ public class BaseBftProtocolScheduleBuilderTest { false, bftExtraDataCodec, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/consensus/ibft/build.gradle b/consensus/ibft/build.gradle index da6304c4e5..e95c866143 100644 --- a/consensus/ibft/build.gradle +++ b/consensus/ibft/build.gradle @@ -76,4 +76,6 @@ dependencies { testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' testImplementation 'org.mockito:mockito-junit-jupiter' + testImplementation 'com.google.dagger:dagger' + testAnnotationProcessor 'com.google.dagger:dagger-compiler' } diff --git a/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java b/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java index 8896733548..a5d24ff4db 100644 --- a/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java +++ b/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java @@ -78,9 +78,9 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; @@ -310,8 +310,8 @@ public class TestContextBuilder { final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); - final MiningParameters miningParams = - ImmutableMiningParameters.builder() + final MiningConfiguration miningParams = + ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .isMiningEnabled(true) @@ -334,7 +334,7 @@ public class TestContextBuilder { forksSchedule, IBFT_EXTRA_DATA_ENCODER, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleBuilder.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleBuilder.java index 3adf571895..adc4698e4d 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleBuilder.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleBuilder.java @@ -21,7 +21,7 @@ import org.hyperledger.besu.consensus.common.bft.BaseBftProtocolScheduleBuilder; import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec; import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket; @@ -46,7 +46,7 @@ public class IbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder * @param isRevertReasonEnabled the is revert reason enabled * @param bftExtraDataCodec the bft extra data codec * @param evmConfiguration the evm configuration - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled * @param metricsSystem A metricSystem instance to be able to expose metrics in the underlying @@ -60,7 +60,7 @@ public class IbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder final boolean isRevertReasonEnabled, final BftExtraDataCodec bftExtraDataCodec, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -72,7 +72,7 @@ public class IbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder isRevertReasonEnabled, bftExtraDataCodec, evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); @@ -85,7 +85,7 @@ public class IbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder * @param forksSchedule the forks schedule * @param bftExtraDataCodec the bft extra data codec * @param evmConfiguration the evm configuration - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled. * @param metricsSystem A metricSystem instance to be able to expose metrics in the underlying @@ -97,7 +97,7 @@ public class IbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder final ForksSchedule forksSchedule, final BftExtraDataCodec bftExtraDataCodec, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -108,7 +108,7 @@ public class IbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder false, bftExtraDataCodec, evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/IbftJsonRpcMethods.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/IbftJsonRpcMethods.java index 1afe067867..a777d7d175 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/IbftJsonRpcMethods.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/IbftJsonRpcMethods.java @@ -32,7 +32,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.methods.ApiGroupJsonRpcMethods; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import java.util.Map; @@ -42,22 +42,22 @@ public class IbftJsonRpcMethods extends ApiGroupJsonRpcMethods { private final ProtocolContext context; private final ProtocolSchedule protocolSchedule; - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; /** * Instantiates a new Ibft json rpc methods. * * @param context the protocol context * @param protocolSchedule the protocol schedule - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters */ public IbftJsonRpcMethods( final ProtocolContext context, final ProtocolSchedule protocolSchedule, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { this.context = context; this.protocolSchedule = protocolSchedule; - this.miningParameters = miningParameters; + this.miningConfiguration = miningConfiguration; } @Override @@ -70,7 +70,7 @@ public class IbftJsonRpcMethods extends ApiGroupJsonRpcMethods { final MutableBlockchain blockchain = context.getBlockchain(); final BlockchainQueries blockchainQueries = new BlockchainQueries( - protocolSchedule, blockchain, context.getWorldStateArchive(), miningParameters); + protocolSchedule, blockchain, context.getWorldStateArchive(), miningConfiguration); final BftContext bftContext = context.getConsensusContext(BftContext.class); final BlockInterface blockInterface = bftContext.getBlockInterface(); final ValidatorProvider validatorProvider = diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java index e5551ff3f3..9cb760551e 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java @@ -22,7 +22,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.hyperledger.besu.config.BftConfigOptions; -import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.config.JsonGenesisConfigOptions; import org.hyperledger.besu.config.JsonQbftConfigOptions; import org.hyperledger.besu.config.JsonUtil; @@ -40,31 +39,39 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Util; +import org.hyperledger.besu.ethereum.core.components.EthereumCoreComponent; import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import java.math.BigInteger; -import java.util.Collection; import java.util.List; +import javax.inject.Singleton; +import dagger.Component; +import dagger.Module; +import dagger.Provides; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public class IbftProtocolScheduleTest { - private final BftExtraDataCodec bftExtraDataCodec = mock(BftExtraDataCodec.class); - private final BftExtraData bftExtraData = mock(BftExtraData.class); - private final NodeKey proposerNodeKey = NodeKeyUtils.generate(); - private final Address proposerAddress = Util.publicKeyToAddress(proposerNodeKey.getPublicKey()); - private final List
validators = singletonList(proposerAddress); + + private ProtocolContext protocolContext; + private List
validators; + private NodeKey proposerNodeKey; + private TestEthCoreComponent component; @BeforeEach public void setup() { - when(bftExtraDataCodec.decode(any())).thenReturn(bftExtraData); - when(bftExtraData.getValidators()).thenReturn(validators); + TestEthCoreComponent component = + DaggerIbftProtocolScheduleTest_TestEthCoreComponent.builder().build(); + this.component = component; + this.protocolContext = component.protocolContext(); + this.validators = component.validators(); + this.proposerNodeKey = component.nodeKey(); } @Test @@ -81,52 +88,111 @@ public class IbftProtocolScheduleTest { .buildHeader(); final BftProtocolSchedule schedule = - createProtocolSchedule( - JsonGenesisConfigOptions.fromJsonObject(JsonUtil.createEmptyObjectNode()), - List.of( - new ForkSpec<>(0, JsonQbftConfigOptions.DEFAULT), - new ForkSpec<>(1, arbitraryTransition), - new ForkSpec<>(2, JsonQbftConfigOptions.DEFAULT))); + createProtocolSchedule(component.bftExtraDataCodec(), arbitraryTransition); assertThat(new MilestoneStreamingProtocolSchedule(schedule).streamMilestoneBlocks().count()) .isEqualTo(3); - assertThat(validateHeader(schedule, validators, parentHeader, blockHeader, 0)).isTrue(); - assertThat(validateHeader(schedule, validators, parentHeader, blockHeader, 1)).isTrue(); - assertThat(validateHeader(schedule, validators, parentHeader, blockHeader, 2)).isTrue(); + assertThat(validateHeader(schedule, parentHeader, blockHeader, 0)).isTrue(); + assertThat(validateHeader(schedule, parentHeader, blockHeader, 1)).isTrue(); + assertThat(validateHeader(schedule, parentHeader, blockHeader, 2)).isTrue(); + } + + private boolean validateHeader( + final BftProtocolSchedule schedule, + final BlockHeader parentHeader, + final BlockHeader blockHeader, + final int block) { + return schedule + .getByBlockNumberOrTimestamp(block, blockHeader.getTimestamp()) + .getBlockHeaderValidator() + .validateHeader( + blockHeader, parentHeader, this.protocolContext, HeaderValidationMode.LIGHT); } private BftProtocolSchedule createProtocolSchedule( - final GenesisConfigOptions genesisConfig, final List> forks) { + final BftExtraDataCodec bftExtraDataCodec, + final MutableBftConfigOptions arbitraryTransition) { + + var genesisConfig = JsonGenesisConfigOptions.fromJsonObject(JsonUtil.createEmptyObjectNode()); + ForksSchedule forkSched = + new ForksSchedule<>( + List.of( + new ForkSpec<>(0, JsonQbftConfigOptions.DEFAULT), + new ForkSpec<>(1, arbitraryTransition), + new ForkSpec<>(2, JsonQbftConfigOptions.DEFAULT))); + return IbftProtocolScheduleBuilder.create( genesisConfig, - new ForksSchedule<>(forks), + forkSched, PrivacyParameters.DEFAULT, false, bftExtraDataCodec, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); } - private boolean validateHeader( - final BftProtocolSchedule schedule, - final List
validators, - final BlockHeader parentHeader, - final BlockHeader blockHeader, - final int block) { - return schedule - .getByBlockNumberOrTimestamp(block, blockHeader.getTimestamp()) - .getBlockHeaderValidator() - .validateHeader( - blockHeader, parentHeader, protocolContext(validators), HeaderValidationMode.LIGHT); + @Module + static class IbftProtocolScheduleModule { + @Provides + @Singleton + NodeKey nodeKey() { + return NodeKeyUtils.generate(); + } + + @Provides + Address provideProposerAddress(final NodeKey proposerNodeKey) { + return Util.publicKeyToAddress(proposerNodeKey.getPublicKey()); + } + + @Provides + List
provideValidators(final Address proposerAddress) { + return singletonList(proposerAddress); + } + + @Provides + public BftExtraData mockBftExtraData(final List
validators) { + BftExtraData bftExtraData = mock(BftExtraData.class); + when(bftExtraData.getValidators()).thenReturn(validators); + return bftExtraData; + } + + @Provides + public BftExtraDataCodec mockBftExtraDataCodec(final BftExtraData bftExtraData) { + BftExtraDataCodec bftExtraDataCodec = mock(BftExtraDataCodec.class); + when(bftExtraDataCodec.decode(any())).thenReturn(bftExtraData); + return bftExtraDataCodec; + } + + @Provides + ProtocolContext protocolContext( + final List
validators, final BftExtraDataCodec bftExtraDataCodec) { + return new ProtocolContext( + null, + null, + setupContextWithBftExtraDataEncoder(BftContext.class, validators, bftExtraDataCodec), + new BadBlockManager()); + } + } + + @Singleton + @Component(modules = {NoMiningParamters.class, IbftProtocolScheduleModule.class}) + interface TestEthCoreComponent extends EthereumCoreComponent { + ProtocolContext protocolContext(); + + List
validators(); + + NodeKey nodeKey(); + + BftExtraDataCodec bftExtraDataCodec(); } - private ProtocolContext protocolContext(final Collection
validators) { - return new ProtocolContext( - null, - null, - setupContextWithBftExtraDataEncoder(BftContext.class, validators, bftExtraDataCodec), - new BadBlockManager()); + @Module + static class NoMiningParamters { + @Provides + MiningConfiguration provideMiningParameters() { + return MiningConfiguration.MINING_DISABLED; + } } } diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/blockcreation/BftBlockCreatorTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/blockcreation/BftBlockCreatorTest.java index 5469717b13..df5a313ae7 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/blockcreation/BftBlockCreatorTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/blockcreation/BftBlockCreatorTest.java @@ -42,9 +42,9 @@ import org.hyperledger.besu.ethereum.core.AddressHelpers; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; @@ -122,7 +122,7 @@ public class BftBlockCreatorTest { false, bftExtraDataEncoder, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -159,8 +159,8 @@ public class BftBlockCreatorTest { transactionPool.setEnabled(); - final MiningParameters miningParameters = - ImmutableMiningParameters.builder() + final MiningConfiguration miningConfiguration = + ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .extraData( @@ -178,7 +178,7 @@ public class BftBlockCreatorTest { final BftBlockCreator blockCreator = new BftBlockCreator( - miningParameters, + miningConfiguration, forksSchedule, initialValidatorList.get(0), parent -> 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 b9f57debb6..79022b7d54 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 @@ -70,7 +70,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule; @@ -180,12 +180,12 @@ public class IbftBlockHeightManagerTest { final ProtocolScheduleBuilder protocolScheduleBuilder = new ProtocolScheduleBuilder( new StubGenesisConfigOptions(), - BigInteger.ONE, + Optional.empty(), ProtocolSpecAdapters.create(0, Function.identity()), new PrivacyParameters(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/MergeProtocolSchedule.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/MergeProtocolSchedule.java index abbc3b130a..66e177efee 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/MergeProtocolSchedule.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/MergeProtocolSchedule.java @@ -17,7 +17,7 @@ package org.hyperledger.besu.consensus.merge; import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -48,7 +48,7 @@ public class MergeProtocolSchedule { * * @param config the config * @param isRevertReasonEnabled the is revert reason enabled - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled. * @return the protocol schedule @@ -56,7 +56,7 @@ public class MergeProtocolSchedule { public static ProtocolSchedule create( final GenesisConfigOptions config, final boolean isRevertReasonEnabled, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -64,7 +64,7 @@ public class MergeProtocolSchedule { config, PrivacyParameters.DEFAULT, isRevertReasonEnabled, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); @@ -76,7 +76,7 @@ public class MergeProtocolSchedule { * @param config the config * @param privacyParameters the privacy parameters * @param isRevertReasonEnabled the is revert reason enabled - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled. * @return the protocol schedule @@ -85,7 +85,7 @@ public class MergeProtocolSchedule { final GenesisConfigOptions config, final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -101,12 +101,12 @@ public class MergeProtocolSchedule { return new ProtocolScheduleBuilder( config, - DEFAULT_CHAIN_ID, + Optional.of(DEFAULT_CHAIN_ID), new ProtocolSpecAdapters(postMergeModifications), privacyParameters, isRevertReasonEnabled, EvmConfiguration.DEFAULT, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem) @@ -129,7 +129,7 @@ public class MergeProtocolSchedule { gasCalculator, chainId.orElse(BigInteger.ZERO), EvmConfiguration.DEFAULT)) .blockHeaderValidatorBuilder(MergeProtocolSchedule::getBlockHeaderValidator) .blockReward(Wei.ZERO) - .difficultyCalculator((a, b, c) -> BigInteger.ZERO) + .difficultyCalculator((a, b) -> BigInteger.ZERO) .skipZeroBlockRewards(true) .isPoS(true) .name("Paris"); diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java index e733cc800e..44fd5f8edf 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java @@ -20,7 +20,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PermissionTransactionFilter; import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule; @@ -65,21 +65,21 @@ public class TransitionProtocolSchedule implements ProtocolSchedule { * * @param genesisConfigOptions {@link GenesisConfigOptions} containing the config options for the * milestone starting points - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled. * @return an initialised TransitionProtocolSchedule using post-merge defaults */ public static TransitionProtocolSchedule fromConfig( final GenesisConfigOptions genesisConfigOptions, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { ProtocolSchedule preMergeProtocolSchedule = MainnetProtocolSchedule.fromConfig( genesisConfigOptions, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); @@ -87,7 +87,7 @@ public class TransitionProtocolSchedule implements ProtocolSchedule { MergeProtocolSchedule.create( genesisConfigOptions, false, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeBlockCreator.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeBlockCreator.java index c56c62d80d..56c78877a6 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeBlockCreator.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeBlockCreator.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.ethereum.blockcreation.AbstractBlockCreator; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.SealableBlockHeader; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.Withdrawal; @@ -39,7 +39,7 @@ class MergeBlockCreator extends AbstractBlockCreator { /** * Instantiates a new Merge block creator. * - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param extraDataCalculator the extra data calculator * @param transactionPool the pending transactions * @param protocolContext the protocol context @@ -47,7 +47,7 @@ class MergeBlockCreator extends AbstractBlockCreator { * @param parentHeader the parent header */ public MergeBlockCreator( - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final ExtraDataCalculator extraDataCalculator, final TransactionPool transactionPool, final ProtocolContext protocolContext, @@ -55,8 +55,8 @@ class MergeBlockCreator extends AbstractBlockCreator { final BlockHeader parentHeader, final EthScheduler ethScheduler) { super( - miningParameters, - __ -> miningParameters.getCoinbase().orElseThrow(), + miningConfiguration, + __ -> miningConfiguration.getCoinbase().orElseThrow(), extraDataCalculator, transactionPool, protocolContext, diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java index a3f9a4b69f..16daa442d3 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java @@ -33,7 +33,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockWithReceipts; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.Withdrawal; @@ -81,7 +81,7 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene private static final long DEFAULT_TARGET_GAS_LIMIT = 30000000L; /** The Mining parameters. */ - protected final MiningParameters miningParameters; + protected final MiningConfiguration miningConfiguration; /** The Merge block creator factory. */ protected final MergeBlockCreatorFactory mergeBlockCreatorFactory; @@ -120,7 +120,7 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene final ProtocolSchedule protocolSchedule, final EthScheduler ethScheduler, final TransactionPool transactionPool, - final MiningParameters miningParams, + final MiningConfiguration miningParams, final BackwardSyncContext backwardSyncContext, final Optional
depositContractAddress) { this.protocolContext = protocolContext; @@ -137,14 +137,14 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene } miningParams.setMinBlockOccupancyRatio(TRY_FILL_BLOCK); - this.miningParameters = miningParams; + this.miningConfiguration = miningParams; this.mergeBlockCreatorFactory = (parentHeader, address) -> { address.ifPresent(miningParams::setCoinbase); return new MergeBlockCreator( - miningParameters, - parent -> miningParameters.getExtraData(), + miningConfiguration, + parent -> miningConfiguration.getExtraData(), transactionPool, protocolContext, protocolSchedule, @@ -169,7 +169,7 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, final EthScheduler ethScheduler, - final MiningParameters miningParams, + final MiningConfiguration miningParams, final BackwardSyncContext backwardSyncContext, final MergeBlockCreatorFactory mergeBlockCreatorFactory) { @@ -182,7 +182,7 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene miningParams.setTargetGasLimit(DEFAULT_TARGET_GAS_LIMIT); } miningParams.setMinBlockOccupancyRatio(TRY_FILL_BLOCK); - this.miningParameters = miningParams; + this.miningConfiguration = miningParams; this.mergeBlockCreatorFactory = mergeBlockCreatorFactory; @@ -215,17 +215,17 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene @Override public Wei getMinTransactionGasPrice() { - return miningParameters.getMinTransactionGasPrice(); + return miningConfiguration.getMinTransactionGasPrice(); } @Override public Wei getMinPriorityFeePerGas() { - return miningParameters.getMinPriorityFeePerGas(); + return miningConfiguration.getMinPriorityFeePerGas(); } @Override public Optional
getCoinbase() { - return miningParameters.getCoinbase(); + return miningConfiguration.getCoinbase(); } @Override @@ -244,7 +244,7 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene @Override public void changeTargetGasLimit(final Long newTargetGasLimit) { if (AbstractGasLimitSpecification.isValidTargetGasLimit(newTargetGasLimit)) { - this.miningParameters.setTargetGasLimit(newTargetGasLimit); + this.miningConfiguration.setTargetGasLimit(newTargetGasLimit); } else { throw new IllegalArgumentException("Specified target gas limit is invalid"); } @@ -383,13 +383,13 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene LOG.debug( "Block creation started for payload id {}, remaining time is {}ms", payloadIdentifier, - miningParameters.getUnstable().getPosBlockCreationMaxTime()); + miningConfiguration.getUnstable().getPosBlockCreationMaxTime()); ethScheduler .scheduleBlockCreationTask( () -> retryBlockCreationUntilUseful(payloadIdentifier, blockCreator)) .orTimeout( - miningParameters.getUnstable().getPosBlockCreationMaxTime(), TimeUnit.MILLISECONDS) + miningConfiguration.getUnstable().getPosBlockCreationMaxTime(), TimeUnit.MILLISECONDS) .whenComplete( (unused, throwable) -> { if (throwable != null) { @@ -416,7 +416,7 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene final long waitBeforeRepetition = Math.max( 100, - miningParameters.getUnstable().getPosBlockCreationRepetitionMinDuration() + miningConfiguration.getUnstable().getPosBlockCreationRepetitionMinDuration() - lastDuration); LOG.debug("Waiting {}ms before repeating block creation", waitBeforeRepetition); Thread.sleep(waitBeforeRepetition); @@ -726,7 +726,7 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene @Override public boolean isMiningBeforeMerge() { - return miningParameters.isMiningEnabled(); + return miningConfiguration.isMiningEnabled(); } private Optional findValidAncestor(final Blockchain chain, final Hash parentHash) { diff --git a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/MergeProtocolScheduleTest.java b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/MergeProtocolScheduleTest.java index 0d4aede3a1..2fff61a829 100644 --- a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/MergeProtocolScheduleTest.java +++ b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/MergeProtocolScheduleTest.java @@ -22,7 +22,7 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockProcessor; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; @@ -51,7 +51,7 @@ public class MergeProtocolScheduleTest { MergeProtocolSchedule.create( config, false, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -72,7 +72,7 @@ public class MergeProtocolScheduleTest { MergeProtocolSchedule.create( config, false, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -113,7 +113,7 @@ public class MergeProtocolScheduleTest { MergeProtocolSchedule.create( config, false, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -146,7 +146,7 @@ public class MergeProtocolScheduleTest { MergeProtocolSchedule.create( config, false, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -180,7 +180,7 @@ public class MergeProtocolScheduleTest { MergeProtocolSchedule.create( GenesisConfigFile.DEFAULT.getConfigOptions(), false, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) @@ -193,8 +193,7 @@ public class MergeProtocolScheduleTest { private static void assertProofOfStakeConfigIsEnabled(final ProtocolSpec spec) { assertThat(spec.isPoS()).isTrue(); assertThat(spec.getEvm().getOperationsUnsafe()[0x44]).isInstanceOf(PrevRanDaoOperation.class); - assertThat(spec.getDifficultyCalculator().nextDifficulty(-1, null, null)) - .isEqualTo(BigInteger.ZERO); + assertThat(spec.getDifficultyCalculator().nextDifficulty(-1, null)).isEqualTo(BigInteger.ZERO); assertThat(spec.getBlockReward()).isEqualTo(Wei.ZERO); assertThat(spec.isSkipZeroBlockRewards()).isTrue(); assertThat(spec.getBlockProcessor()).isInstanceOf(MainnetBlockProcessor.class); diff --git a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java index 4efcdc1e0f..90c4b6866e 100644 --- a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java +++ b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java @@ -55,11 +55,10 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.Unstable; -import org.hyperledger.besu.ethereum.core.MiningParameters; -import org.hyperledger.besu.ethereum.core.Synchronizer; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.Unstable; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; @@ -135,8 +134,8 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper { private final Address coinbase = genesisAllocations(getPosGenesisConfigFile()).findFirst().get(); - private MiningParameters miningParameters = - ImmutableMiningParameters.builder() + private MiningConfiguration miningConfiguration = + ImmutableMiningConfiguration.builder() .mutableInitValues(MutableInitValues.builder().coinbase(coinbase).build()) .unstable( Unstable.builder() @@ -190,7 +189,6 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper { protocolContext = new ProtocolContext(blockchain, worldStateArchive, mergeContext, badBlockManager); - protocolContext.setSynchronizer(mock(Synchronizer.class)); var mutable = worldStateArchive.getMutable(); genesisState.writeStateTo(mutable); mutable.persist(null); @@ -228,7 +226,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper { protocolSchedule, ethScheduler, transactionPool, - miningParameters, + miningConfiguration, backwardSyncContext, Optional.empty()); } @@ -273,7 +271,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper { MergeBlockCreator beingSpiedOn = spy( new MergeBlockCreator( - miningParameters, + miningConfiguration, parent -> Bytes.EMPTY, transactionPool, protocolContext, @@ -302,7 +300,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper { protocolContext, protocolSchedule, ethScheduler, - miningParameters, + miningConfiguration, backwardSyncContext, mergeBlockCreatorFactory)); @@ -543,9 +541,9 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper { @Test public void shouldStopRetryBlockCreationIfTimeExpired() throws InterruptedException { final AtomicLong retries = new AtomicLong(0); - miningParameters = - ImmutableMiningParameters.builder() - .from(miningParameters) + miningConfiguration = + ImmutableMiningConfiguration.builder() + .from(miningConfiguration) .unstable(Unstable.builder().posBlockCreationMaxTime(100).build()) .build(); doAnswer( @@ -737,8 +735,8 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper { public void shouldUseExtraDataFromMiningParameters() { final Bytes extraData = Bytes.fromHexString("0x1234"); - miningParameters = - ImmutableMiningParameters.builder() + miningConfiguration = + ImmutableMiningConfiguration.builder() .mutableInitValues(MutableInitValues.builder().extraData(extraData).build()) .build(); @@ -748,7 +746,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper { protocolSchedule, ethScheduler, transactionPool, - miningParameters, + miningConfiguration, backwardSyncContext, Optional.empty()); diff --git a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeGenesisConfigHelper.java b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeGenesisConfigHelper.java index dcfe5f98e3..582c8c5dd5 100644 --- a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeGenesisConfigHelper.java +++ b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeGenesisConfigHelper.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.consensus.merge.MergeProtocolSchedule; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -56,7 +56,7 @@ public interface MergeGenesisConfigHelper { return MergeProtocolSchedule.create( getPosGenesisConfigFile().getConfigOptions(), false, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeReorgTest.java b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeReorgTest.java index 7b111268e0..22153eecee 100644 --- a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeReorgTest.java +++ b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeReorgTest.java @@ -34,8 +34,8 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.sync.backwardsync.BackwardSyncContext; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; @@ -96,7 +96,7 @@ public class MergeReorgTest implements MergeGenesisConfigHelper { mockProtocolSchedule, ethScheduler, mockTransactionPool, - ImmutableMiningParameters.builder() + ImmutableMiningConfiguration.builder() .mutableInitValues(MutableInitValues.builder().coinbase(coinbase).build()) .build(), mock(BackwardSyncContext.class), diff --git a/consensus/qbft/build.gradle b/consensus/qbft/build.gradle index 9675c4df89..23e5576eba 100644 --- a/consensus/qbft/build.gradle +++ b/consensus/qbft/build.gradle @@ -40,8 +40,6 @@ dependencies { implementation project(':ethereum:p2p') implementation project(':ethereum:rlp') implementation project(':evm') - implementation project(':pki') - implementation project(':services:kvstore') implementation 'com.google.guava:guava' implementation 'io.vertx:vertx-core' diff --git a/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java b/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java index d90d5a1527..cc7066f17e 100644 --- a/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java +++ b/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java @@ -91,9 +91,9 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.manager.EthContext; @@ -387,8 +387,8 @@ public class TestContextBuilder { final boolean useFixedBaseFee, final List qbftForks) { - final MiningParameters miningParams = - ImmutableMiningParameters.builder() + final MiningConfiguration miningParams = + ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .isMiningEnabled(true) @@ -438,7 +438,7 @@ public class TestContextBuilder { forksSchedule, BFT_EXTRA_DATA_ENCODER, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleBuilder.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleBuilder.java index e1cbc134b6..473b99332e 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleBuilder.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleBuilder.java @@ -24,7 +24,7 @@ import org.hyperledger.besu.consensus.common.bft.BaseBftProtocolScheduleBuilder; import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec; import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -50,7 +50,7 @@ public class QbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder * @param isRevertReasonEnabled the is revert reason enabled * @param bftExtraDataCodec the bft extra data codec * @param evmConfiguration the evm configuration - * @param miningParameters The mining parameters + * @param miningConfiguration The mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled. * @param metricsSystem A metricSystem instance to be able to expose metrics in the underlying @@ -64,7 +64,7 @@ public class QbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder final boolean isRevertReasonEnabled, final BftExtraDataCodec bftExtraDataCodec, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -76,7 +76,7 @@ public class QbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder isRevertReasonEnabled, bftExtraDataCodec, evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); @@ -89,7 +89,7 @@ public class QbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder * @param qbftForksSchedule the qbft forks schedule * @param bftExtraDataCodec the bft extra data codec * @param evmConfiguration the evm configuration - * @param miningParameters The mining parameters + * @param miningConfiguration The mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled. * @param metricsSystem A metricSystem instance to be able to expose metrics in the underlying @@ -101,7 +101,7 @@ public class QbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder final ForksSchedule qbftForksSchedule, final BftExtraDataCodec bftExtraDataCodec, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -112,7 +112,7 @@ public class QbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder false, bftExtraDataCodec, evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); @@ -125,7 +125,7 @@ public class QbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder * @param qbftForksSchedule the qbft forks schedule * @param isRevertReasonEnabled the is revert reason enabled * @param bftExtraDataCodec the bft extra data codec - * @param miningParameters The mining parameters + * @param miningConfiguration The mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled. * @param metricsSystem A metricSystem instance to be able to expose metrics in the underlying @@ -137,7 +137,7 @@ public class QbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder final ForksSchedule qbftForksSchedule, final boolean isRevertReasonEnabled, final BftExtraDataCodec bftExtraDataCodec, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -148,7 +148,7 @@ public class QbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder isRevertReasonEnabled, bftExtraDataCodec, EvmConfiguration.DEFAULT, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/blockcreation/QbftBlockCreatorFactory.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/blockcreation/QbftBlockCreatorFactory.java index 10f61713d9..fc46b6c32f 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/blockcreation/QbftBlockCreatorFactory.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/blockcreation/QbftBlockCreatorFactory.java @@ -23,7 +23,7 @@ import org.hyperledger.besu.consensus.common.bft.blockcreation.BftBlockCreatorFa import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -52,7 +52,7 @@ public class QbftBlockCreatorFactory extends BftBlockCreatorFactory forksSchedule, - final MiningParameters miningParams, + final MiningConfiguration miningParams, final Address localAddress, final BftExtraDataCodec bftExtraDataCodec, final EthScheduler ethScheduler) { @@ -74,7 +74,7 @@ public class QbftBlockCreatorFactory extends BftBlockCreatorFactory balance; + private final Optional nonce; + private final Optional code; + private final Optional> stateDiff; + + private AccountOverride( + final Optional balance, + final Optional nonce, + final Optional code, + final Optional> stateDiff) { + this.balance = balance; + this.nonce = nonce; + this.code = code; + this.stateDiff = stateDiff; + } + + /** + * Gets the balance override + * + * @return the balance if present + */ + public Optional getBalance() { + return balance; + } + + /** + * Gets the nonce override + * + * @return the nonce if present + */ + public Optional getNonce() { + return nonce; + } + + /** + * Gets the code override + * + * @return the code if present + */ + public Optional getCode() { + return code; + } + + /** + * Gets the state override map + * + * @return the state override map if present + */ + public Optional> getStateDiff() { + return stateDiff; + } + + /** Builder class for Account overrides */ + public static class Builder { + private Optional balance = Optional.empty(); + private Optional nonce = Optional.empty(); + private Optional code = Optional.empty(); + private Optional> stateDiff = Optional.empty(); + + /** Default constructor. */ + public Builder() {} + + /** + * Sets the balance override + * + * @param balance the balance override + * @return the builder + */ + public Builder withBalance(final Wei balance) { + this.balance = Optional.ofNullable(balance); + return this; + } + + /** + * Sets the nonce override + * + * @param nonce the nonce override + * @return the builder + */ + public Builder withNonce(final Long nonce) { + this.nonce = Optional.ofNullable(nonce); + return this; + } + + /** + * Sets the code override + * + * @param code the code override + * @return the builder + */ + public Builder withCode(final String code) { + this.code = Optional.ofNullable(code); + return this; + } + + /** + * Sets the state diff override + * + * @param stateDiff the map of state overrides + * @return the builder + */ + public Builder withStateDiff(final Map stateDiff) { + this.stateDiff = Optional.ofNullable(stateDiff); + return this; + } + + /** + * build the account override from the builder + * + * @return account override + */ + public AccountOverride build() { + return new AccountOverride(balance, nonce, code, stateDiff); + } + } + + /** + * utility method to log unknown properties + * + * @param key key for the unrecognized value + * @param value the unrecognized value + */ + @JsonAnySetter + public void withUnknownProperties(final String key, final Object value) { + LOG.debug( + "unknown property - {} with value - {} and type - {} caught during serialization", + key, + value, + value != null ? value.getClass() : "NULL"); + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final AccountOverride accountOverride = (AccountOverride) o; + return balance.equals(accountOverride.balance) + && nonce.equals(accountOverride.nonce) + && code.equals(accountOverride.code) + && stateDiff.equals(accountOverride.stateDiff); + } + + @Override + public int hashCode() { + return Objects.hash(balance, nonce, code, stateDiff); + } + + @Override + public String toString() { + return "AccountOverride{" + + "balance=" + + balance + + ", nonce=" + + nonce + + ", code=" + + code + + ", stateDiff=" + + stateDiff + + '}'; + } +} diff --git a/datatypes/src/main/java/org/hyperledger/besu/datatypes/AccountOverrideMap.java b/datatypes/src/main/java/org/hyperledger/besu/datatypes/AccountOverrideMap.java new file mode 100644 index 0000000000..20aee46185 --- /dev/null +++ b/datatypes/src/main/java/org/hyperledger/besu/datatypes/AccountOverrideMap.java @@ -0,0 +1,27 @@ +/* + * Copyright contributors to Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.datatypes; + +import java.util.HashMap; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +/** Map of account overrides, indexed by address */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class AccountOverrideMap extends HashMap { + + /** Default constructor */ + public AccountOverrideMap() {} +} diff --git a/docs/Private-Txns-Migration.md b/docs/Private-Txns-Migration.md index 0ae06dae3c..042e83c8dd 100644 --- a/docs/Private-Txns-Migration.md +++ b/docs/Private-Txns-Migration.md @@ -12,7 +12,7 @@ state storage when upgrading to v1.4. It is not possible to upgrade to v1.4 with ## Private transactions created using v1.3.4 or earlier A critical issue for privacy users with private transactions created using Hyperledger Besu v1.3.4 -or earlier has been identified. If you have a network with private transaction created using v1.3.4 +or earlier has been identified. If you have a network with private transactions created using v1.3.4 or earlier, please read the following and take the appropriate steps: https://wiki.hyperledger.org/display/BESU/Critical+Issue+for+Privacy+Users @@ -41,4 +41,4 @@ your Besu database from backup and restart the migration process. ## Migration support If you have a long running network with a large volume of private transactions and/or would like to discuss -the migration process with us before upgrading, contact us at support@pegasys.tech \ No newline at end of file +the migration process with us before upgrading, contact us at support@pegasys.tech diff --git a/docs/README.md b/docs/README.md index c9584bfadc..5b22a3c3b5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,4 @@ -Besu user documentation was moved to as separate repository to help manage versions and releases. +Besu user documentation was moved to a separate repository to help manage versions and releases. If you want to contribute to the doc site, make a pull request against https://github.com/hyperledger/besu-docs diff --git a/docs/trace_rpc_apis.md b/docs/trace_rpc_apis.md index e8db0bcbc5..7f04d497a7 100644 --- a/docs/trace_rpc_apis.md +++ b/docs/trace_rpc_apis.md @@ -16,7 +16,7 @@ implementations of Besu might track gas refunds separately. ### Returned Memory from Calls -In the `vmTrace` `ope.ex.mem` fields Besu only reports actual data returned +In the `vmTrace` `op.ex.mem` fields Besu only reports actual data returned from a `RETURN` opcode. Other implementations return the contents of the reserved output space for the call operations. Note two major differences: diff --git a/docs/tracing/README.md b/docs/tracing/README.md index 3a3f9fa435..798496cfd4 100644 --- a/docs/tracing/README.md +++ b/docs/tracing/README.md @@ -2,7 +2,7 @@ Hyperledger Besu integrates with the [open-telemetry](https://opentelemetry.io/) project to integrate tracing reporting. -This allows to report all JSON-RPC traffic as traces. +This allows reporting all JSON-RPC traffic as traces. To try out this example, start the Open Telemetry Collector and the Zipkin service with: diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/BlockchainImporter.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/BlockchainImporter.java index 3e261abf6d..7e1be90e10 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/BlockchainImporter.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/BlockchainImporter.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.GenesisState; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; @@ -46,7 +46,7 @@ public class BlockchainImporter { protocolSchedule = MainnetProtocolSchedule.fromConfig( GenesisConfigFile.fromConfig(genesisJson).getConfigOptions(), - MiningParameters.newDefault(), + MiningConfiguration.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java index c7ba5a4f93..2a65b1e7cb 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java @@ -19,6 +19,7 @@ import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider import static org.mockito.Mockito.mock; import org.hyperledger.besu.config.StubGenesisConfigOptions; +import org.hyperledger.besu.ethereum.ConsensusContext; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.ImmutableApiConfiguration; import org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration; @@ -33,7 +34,7 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockImporter; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.manager.EthPeers; @@ -82,7 +83,9 @@ public class JsonRpcTestMethodsFactory { this.blockchain = createInMemoryBlockchain(importer.getGenesisBlock()); this.stateArchive = createInMemoryWorldStateArchive(); this.importer.getGenesisState().writeStateTo(stateArchive.getMutable()); - this.context = new ProtocolContext(blockchain, stateArchive, null, new BadBlockManager()); + this.context = + new ProtocolContext( + blockchain, stateArchive, mock(ConsensusContext.class), new BadBlockManager()); this.protocolSchedule = importer.getProtocolSchedule(); this.synchronizer = mock(Synchronizer.class); @@ -94,7 +97,7 @@ public class JsonRpcTestMethodsFactory { } this.blockchainQueries = new BlockchainQueries( - protocolSchedule, blockchain, stateArchive, MiningParameters.newDefault()); + protocolSchedule, blockchain, stateArchive, MiningConfiguration.newDefault()); } public JsonRpcTestMethodsFactory( @@ -112,7 +115,7 @@ public class JsonRpcTestMethodsFactory { importer.getProtocolSchedule(), blockchain, stateArchive, - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); this.synchronizer = mock(Synchronizer.class); } @@ -133,7 +136,7 @@ public class JsonRpcTestMethodsFactory { importer.getProtocolSchedule(), blockchain, stateArchive, - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); } public BlockchainQueries getBlockchainQueries() { @@ -152,7 +155,7 @@ public class JsonRpcTestMethodsFactory { final P2PNetwork peerDiscovery = mock(P2PNetwork.class); final EthPeers ethPeers = mock(EthPeers.class); final TransactionPool transactionPool = mock(TransactionPool.class); - final MiningParameters miningParameters = mock(MiningParameters.class); + final MiningConfiguration miningConfiguration = mock(MiningConfiguration.class); final PoWMiningCoordinator miningCoordinator = mock(PoWMiningCoordinator.class); final ObservableMetricsSystem metricsSystem = new NoOpMetricsSystem(); final Optional accountWhitelistController = @@ -198,7 +201,7 @@ public class JsonRpcTestMethodsFactory { context, filterManager, transactionPool, - miningParameters, + miningConfiguration, miningCoordinator, metricsSystem, new HashSet<>(), diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByNumberLatestDesyncIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByNumberLatestDesyncIntegrationTest.java index 088eff8500..7e26a4d812 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByNumberLatestDesyncIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByNumberLatestDesyncIntegrationTest.java @@ -20,6 +20,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.ethereum.ConsensusContext; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.jsonrpc.BlockchainImporter; import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcTestMethodsFactory; @@ -67,7 +68,8 @@ public class EthGetBlockByNumberLatestDesyncIntegrationTest { InMemoryKeyValueStorageProvider.createInMemoryBlockchain(importer.getGenesisBlock()); WorldStateArchive state = InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive(); importer.getGenesisState().writeStateTo(state.getMutable()); - ProtocolContext context = new ProtocolContext(chain, state, null, new BadBlockManager()); + ProtocolContext context = + new ProtocolContext(chain, state, mock(ConsensusContext.class), new BadBlockManager()); for (final Block block : importer.getBlocks()) { final ProtocolSchedule protocolSchedule = importer.getProtocolSchedule(); diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetFilterChangesIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetFilterChangesIntegrationTest.java index d4de405305..b238259d66 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetFilterChangesIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetFilterChangesIntegrationTest.java @@ -45,7 +45,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; @@ -130,7 +130,7 @@ public class EthGetFilterChangesIntegrationTest { executionContext.getProtocolSchedule(), blockchain, protocolContext.getWorldStateArchive(), - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); filterManager = new FilterManagerBuilder() .blockchainQueries(blockchainQueries) diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthGetFilterChangesIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthGetFilterChangesIntegrationTest.java index 0c194ad22f..fc5379f196 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthGetFilterChangesIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthGetFilterChangesIntegrationTest.java @@ -45,7 +45,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; @@ -130,7 +130,7 @@ public class EthGetFilterChangesIntegrationTest { executionContext.getProtocolSchedule(), blockchain, protocolContext.getWorldStateArchive(), - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); filterManager = new FilterManagerBuilder() .blockchainQueries(blockchainQueries) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/AbstractJsonRpcExecutor.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/AbstractJsonRpcExecutor.java index 95dc88f6a5..f73d162fa1 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/AbstractJsonRpcExecutor.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/AbstractJsonRpcExecutor.java @@ -106,6 +106,7 @@ public abstract class AbstractJsonRpcExecutor { private static HttpResponseStatus statusCodeFromError(final RpcErrorType error) { return switch (error) { case INVALID_REQUEST, PARSE_ERROR -> HttpResponseStatus.BAD_REQUEST; + case TIMEOUT_ERROR -> HttpResponseStatus.REQUEST_TIMEOUT; default -> HttpResponseStatus.OK; }; } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/JsonRpcExecutorHandler.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/JsonRpcExecutorHandler.java index 278a38c557..8386631695 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/JsonRpcExecutorHandler.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/JsonRpcExecutorHandler.java @@ -34,6 +34,9 @@ import org.slf4j.LoggerFactory; public class JsonRpcExecutorHandler { private static final Logger LOG = LoggerFactory.getLogger(JsonRpcExecutorHandler.class); + // Default timeout for RPC calls in seconds + private static final long DEFAULT_TIMEOUT_MILLISECONDS = 30_000L; + private JsonRpcExecutorHandler() {} public static Handler handler( @@ -49,6 +52,19 @@ public class JsonRpcExecutorHandler { final Tracer tracer, final JsonRpcConfiguration jsonRpcConfiguration) { return ctx -> { + final long timerId = + ctx.vertx() + .setTimer( + DEFAULT_TIMEOUT_MILLISECONDS, + id -> { + final String method = + ctx.get(ContextKey.REQUEST_BODY_AS_JSON_OBJECT.name()).toString(); + LOG.error("Timeout occurred in JSON-RPC executor for method {}", method); + handleErrorAndEndResponse(ctx, null, RpcErrorType.TIMEOUT_ERROR); + }); + + ctx.put("timerId", timerId); + try { createExecutor(jsonRpcExecutor, tracer, ctx, jsonRpcConfiguration) .ifPresentOrElse( @@ -58,18 +74,38 @@ public class JsonRpcExecutorHandler { } catch (IOException e) { final String method = executor.getRpcMethodName(ctx); LOG.error("{} - Error streaming JSON-RPC response", method, e); - handleJsonRpcError(ctx, null, RpcErrorType.INTERNAL_ERROR); + handleErrorAndEndResponse(ctx, null, RpcErrorType.INTERNAL_ERROR); + } finally { + cancelTimer(ctx); } }, - () -> handleJsonRpcError(ctx, null, RpcErrorType.PARSE_ERROR)); + () -> { + handleErrorAndEndResponse(ctx, null, RpcErrorType.PARSE_ERROR); + cancelTimer(ctx); + }); } catch (final RuntimeException e) { - final String method = ctx.get(ContextKey.REQUEST_BODY_AS_JSON_OBJECT.name()); + final String method = ctx.get(ContextKey.REQUEST_BODY_AS_JSON_OBJECT.name()).toString(); LOG.error("Unhandled exception in JSON-RPC executor for method {}", method, e); - handleJsonRpcError(ctx, null, RpcErrorType.INTERNAL_ERROR); + handleErrorAndEndResponse(ctx, null, RpcErrorType.INTERNAL_ERROR); + cancelTimer(ctx); } }; } + private static void cancelTimer(final RoutingContext ctx) { + Long timerId = ctx.get("timerId"); + if (timerId != null) { + ctx.vertx().cancelTimer(timerId); + } + } + + private static void handleErrorAndEndResponse( + final RoutingContext ctx, final Object id, final RpcErrorType errorType) { + if (!ctx.response().ended()) { + handleJsonRpcError(ctx, id, errorType); + } + } + private static Optional createExecutor( final JsonRpcExecutor jsonRpcExecutor, final Tracer tracer, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/execution/JsonRpcExecutor.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/execution/JsonRpcExecutor.java index 6fedcc70ca..b8786eb7a5 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/execution/JsonRpcExecutor.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/execution/JsonRpcExecutor.java @@ -104,9 +104,9 @@ public class JsonRpcExecutor { private Optional validateMethodAvailability(final JsonRpcRequest request) { final String name = request.getMethod(); - if (LOG.isDebugEnabled()) { + if (LOG.isTraceEnabled()) { final JsonArray params = JsonObject.mapFrom(request).getJsonArray("params"); - LOG.debug("JSON-RPC request -> {} {}", name, params); + LOG.trace("JSON-RPC request -> {} {}", name, params); } final JsonRpcMethod method = rpcMethods.get(name); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java index 7958f8e759..444fc8cf93 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java @@ -21,22 +21,41 @@ import org.hyperledger.besu.ethereum.ProtocolContext; 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.exception.InvalidJsonRpcParameters; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameterOrBlockHash; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; +import org.hyperledger.besu.ethereum.chain.MutableBlockchain; +import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.trie.diffbased.common.DiffBasedWorldStateProvider; import java.util.Optional; -public class DebugSetHead extends AbstractBlockParameterMethod { +import graphql.VisibleForTesting; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DebugSetHead extends AbstractBlockParameterOrBlockHashMethod { private final ProtocolContext protocolContext; + private static final Logger LOG = LoggerFactory.getLogger(DebugSetHead.class); + private static final int DEFAULT_MAX_TRIE_LOGS_TO_ROLL_AT_ONCE = 32; + + private final long maxTrieLogsToRollAtOnce; public DebugSetHead(final BlockchainQueries blockchain, final ProtocolContext protocolContext) { - super(blockchain); + this(blockchain, protocolContext, DEFAULT_MAX_TRIE_LOGS_TO_ROLL_AT_ONCE); + } + @VisibleForTesting + DebugSetHead( + final BlockchainQueries blockchain, + final ProtocolContext protocolContext, + final long maxTrieLogsToRollAtOnce) { + super(blockchain); this.protocolContext = protocolContext; + this.maxTrieLogsToRollAtOnce = Math.abs(maxTrieLogsToRollAtOnce); } @Override @@ -45,26 +64,108 @@ public class DebugSetHead extends AbstractBlockParameterMethod { } @Override - protected BlockParameter blockParameter(final JsonRpcRequestContext request) { + protected BlockParameterOrBlockHash blockParameterOrBlockHash( + final JsonRpcRequestContext requestContext) { try { - return request.getRequiredParameter(0, BlockParameter.class); + return requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class); } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( - "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block or block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } @Override - protected Object resultByBlockNumber( - final JsonRpcRequestContext request, final long blockNumber) { - final Optional maybeBlockHash = getBlockchainQueries().getBlockHashByNumber(blockNumber); + protected Object resultByBlockHash(final JsonRpcRequestContext request, final Hash blockHash) { + var blockchainQueries = getBlockchainQueries(); + var blockchain = protocolContext.getBlockchain(); + Optional maybeBlockHeader = blockchainQueries.getBlockHeaderByHash(blockHash); + Optional maybeMoveWorldstate = shouldMoveWorldstate(request); - if (maybeBlockHash.isEmpty()) { + if (maybeBlockHeader.isEmpty()) { return new JsonRpcErrorResponse(request.getRequest().getId(), UNKNOWN_BLOCK); } - protocolContext.getBlockchain().rewindToBlock(maybeBlockHash.get()); + // Optionally move the worldstate to the specified blockhash, if it is present in the chain + if (maybeMoveWorldstate.orElse(Boolean.FALSE)) { + var archive = blockchainQueries.getWorldStateArchive(); + + // Only DiffBasedWorldState's need to be moved: + if (archive instanceof DiffBasedWorldStateProvider diffBasedArchive) { + if (rollIncrementally(maybeBlockHeader.get(), blockchain, diffBasedArchive)) { + return JsonRpcSuccessResponse.SUCCESS_RESULT; + } + } + } + + // If we are not rolling incrementally or if there was an error incrementally rolling, + // move the blockchain to the requested hash: + blockchain.rewindToBlock(maybeBlockHeader.get().getBlockHash()); return JsonRpcSuccessResponse.SUCCESS_RESULT; } + + private boolean rollIncrementally( + final BlockHeader target, + final MutableBlockchain blockchain, + final DiffBasedWorldStateProvider archive) { + + try { + if (archive.isWorldStateAvailable(target.getStateRoot(), target.getBlockHash())) { + // WARNING, this can be dangerous for a DiffBasedWorldstate if a concurrent + // process attempts to move or modify the head worldstate. + // Ensure no block processing is occuring when using this feature. + // No engine-api, block import, sync, mining or other rpc calls should be running. + + Optional currentHead = + archive + .getWorldStateKeyValueStorage() + .getWorldStateBlockHash() + .flatMap(blockchain::getBlockHeader); + + while (currentHead.isPresent() + && !target.getStateRoot().equals(currentHead.get().getStateRoot())) { + long delta = currentHead.get().getNumber() - target.getNumber(); + + if (maxTrieLogsToRollAtOnce < Math.abs(delta)) { + // do we need to move forward or backward? + long distanceToMove = (delta > 0) ? -maxTrieLogsToRollAtOnce : maxTrieLogsToRollAtOnce; + + // Add distanceToMove to the current block number to get the interim target header + var interimHead = + blockchain.getBlockHeader(currentHead.get().getNumber() + distanceToMove); + + interimHead.ifPresent( + it -> { + blockchain.rewindToBlock(it.getBlockHash()); + archive.getMutable(it.getStateRoot(), it.getBlockHash()); + LOG.info("incrementally rolled worldstate to {}", it.toLogString()); + }); + currentHead = interimHead; + + } else { + blockchain.rewindToBlock(target.getBlockHash()); + archive.getMutable(target.getStateRoot(), target.getBlockHash()); + currentHead = Optional.of(target); + LOG.info("finished rolling worldstate to {}", target.toLogString()); + } + } + } + + return true; + } catch (Exception ex) { + LOG.error("Failed to incrementally roll blockchain to " + target.toLogString(), ex); + return false; + } + } + + private Optional shouldMoveWorldstate(final JsonRpcRequestContext request) { + try { + return request.getOptionalParameter(1, Boolean.class); + } catch (JsonRpcParameterException e) { + throw new InvalidJsonRpcParameters( + "Invalid should move worldstate boolean parameter (index 1)", + RpcErrorType.INVALID_PARAMS, + e); + } + } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java index 0e0318f9c2..ef5c8c7a6c 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java @@ -17,12 +17,14 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType.BLOCK_NOT_FOUND; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType.INTERNAL_ERROR; +import org.hyperledger.besu.datatypes.AccountOverrideMap; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcErrorConverter; 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.exception.InvalidJsonRpcParameters; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcRequestException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameterOrBlockHash; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; @@ -42,6 +44,10 @@ import org.hyperledger.besu.ethereum.transaction.TransactionSimulator; import org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult; import org.hyperledger.besu.evm.tracing.OperationTracer; +import java.util.Optional; + +import com.google.common.annotations.VisibleForTesting; + public class EthCall extends AbstractBlockParameterOrBlockHashMethod { private final TransactionSimulator transactionSimulator; @@ -81,10 +87,13 @@ public class EthCall extends AbstractBlockParameterOrBlockHashMethod { protected Object resultByBlockHeader( final JsonRpcRequestContext request, final BlockHeader header) { JsonCallParameter callParams = JsonCallParameterUtil.validateAndGetCallParams(request); + Optional maybeStateOverrides = getAddressAccountOverrideMap(request); + // TODO implement for block overrides return transactionSimulator .process( callParams, + maybeStateOverrides, buildTransactionValidationParams(header, callParams), OperationTracer.NO_TRACING, (mutableWorldState, transactionSimulatorResult) -> @@ -108,6 +117,17 @@ public class EthCall extends AbstractBlockParameterOrBlockHashMethod { .orElse(errorResponse(request, INTERNAL_ERROR)); } + @VisibleForTesting + protected Optional getAddressAccountOverrideMap( + final JsonRpcRequestContext request) { + try { + return request.getOptionalParameter(2, AccountOverrideMap.class); + } catch (JsonRpcParameterException e) { + throw new InvalidJsonRpcRequestException( + "Invalid account overrides parameter (index 2)", RpcErrorType.INVALID_CALL_PARAMS, e); + } + } + @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { return (JsonRpcResponse) handleParamTypes(requestContext); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java index c713ea20a7..2352a5a8c3 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java @@ -14,9 +14,12 @@ */ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods; +import org.hyperledger.besu.datatypes.AccountOverrideMap; 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.exception.InvalidJsonRpcRequestException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity; @@ -31,6 +34,7 @@ import org.hyperledger.besu.evm.tracing.EstimateGasOperationTracer; import java.util.Optional; +import com.google.common.annotations.VisibleForTesting; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,6 +59,8 @@ public class EthEstimateGas extends AbstractEstimateGas { final CallParameter modifiedCallParams = overrideGasLimitAndPrice(callParams, blockHeader.getGasLimit()); + Optional maybeStateOverrides = getAddressAccountOverrideMap(requestContext); + // TODO implement for block overrides final boolean isAllowExceedingBalance = !callParams.isMaybeStrict().orElse(Boolean.FALSE); @@ -68,7 +74,11 @@ public class EthEstimateGas extends AbstractEstimateGas { LOG.debug("Processing transaction with params: {}", modifiedCallParams); final var maybeResult = transactionSimulator.process( - modifiedCallParams, transactionValidationParams, operationTracer, blockHeader); + modifiedCallParams, + maybeStateOverrides, + transactionValidationParams, + operationTracer, + blockHeader); final Optional maybeErrorResponse = validateSimulationResult(requestContext, maybeResult); @@ -81,6 +91,7 @@ public class EthEstimateGas extends AbstractEstimateGas { final var lowResult = transactionSimulator.process( overrideGasLimitAndPrice(callParams, low), + maybeStateOverrides, transactionValidationParams, operationTracer, blockHeader); @@ -97,6 +108,7 @@ public class EthEstimateGas extends AbstractEstimateGas { var binarySearchResult = transactionSimulator.process( overrideGasLimitAndPrice(callParams, mid), + maybeStateOverrides, transactionValidationParams, operationTracer, blockHeader); @@ -127,4 +139,15 @@ public class EthEstimateGas extends AbstractEstimateGas { } return Optional.empty(); } + + @VisibleForTesting + protected Optional getAddressAccountOverrideMap( + final JsonRpcRequestContext request) { + try { + return request.getOptionalParameter(2, AccountOverrideMap.class); + } catch (JsonRpcParameter.JsonRpcParameterException e) { + throw new InvalidJsonRpcRequestException( + "Invalid account overrides parameter (index 2)", RpcErrorType.INVALID_CALL_PARAMS, e); + } + } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java index adacf01e76..16798160d8 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java @@ -25,7 +25,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcPara import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.flat.FlatTraceGenerator; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.flat.RewardTraceGenerator; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.api.util.ArrayNodeWrapper; @@ -41,12 +40,11 @@ import org.hyperledger.besu.ethereum.vm.DebugOperationTracer; import org.hyperledger.besu.evm.worldstate.WorldUpdater; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; -import org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem; +import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; import org.hyperledger.besu.services.pipeline.Pipeline; -import java.util.List; import java.util.Optional; import java.util.concurrent.ExecutionException; @@ -58,10 +56,21 @@ public class TraceBlock extends AbstractBlockParameterMethod { private static final Logger LOG = LoggerFactory.getLogger(TraceBlock.class); private static final ObjectMapper MAPPER = new ObjectMapper(); protected final ProtocolSchedule protocolSchedule; + private final LabelledMetric outputCounter; - public TraceBlock(final ProtocolSchedule protocolSchedule, final BlockchainQueries queries) { + public TraceBlock( + final ProtocolSchedule protocolSchedule, + final BlockchainQueries queries, + final MetricsSystem metricsSystem) { super(queries); this.protocolSchedule = protocolSchedule; + this.outputCounter = + metricsSystem.createLabelledCounter( + BesuMetricCategory.BLOCKCHAIN, + "transactions_traceblock_pipeline_processed_total", + "Number of transactions processed for each block", + "step", + "action"); } @Override @@ -115,14 +124,6 @@ public class TraceBlock extends AbstractBlockParameterMethod { final ChainUpdater chainUpdater = new ChainUpdater(traceableState); TransactionSource transactionSource = new TransactionSource(block); - final LabelledMetric outputCounter = - new PrometheusMetricsSystem(BesuMetricCategory.DEFAULT_METRIC_CATEGORIES, false) - .createLabelledCounter( - BesuMetricCategory.BLOCKCHAIN, - "transactions_traceblock_pipeline_processed_total", - "Number of transactions processed for each block", - "step", - "action"); DebugOperationTracer debugOperationTracer = new DebugOperationTracer(new TraceOptions(false, false, true), false); ExecuteTransactionStep executeTransactionStep = @@ -173,18 +174,6 @@ public class TraceBlock extends AbstractBlockParameterMethod { .orElse(emptyResult()); } - protected void generateTracesFromTransactionTraceAndBlock( - final Optional filterParameter, - final List transactionTraces, - final Block block, - final ArrayNodeWrapper resultArrayNode) { - transactionTraces.forEach( - transactionTrace -> - FlatTraceGenerator.generateFromTransactionTraceAndBlock( - protocolSchedule, transactionTrace, block) - .forEachOrdered(resultArrayNode::addPOJO)); - } - protected void generateRewardsFromBlock( final Optional maybeFilterParameter, final Block block, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java index 10d4018bce..1601241db6 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java @@ -160,7 +160,12 @@ public class TraceCallMany extends TraceCall implements JsonRpcMethod { new DebugOperationTracer(buildTraceOptions(traceTypes), false); final Optional maybeSimulatorResult = transactionSimulator.processWithWorldUpdater( - callParameter, buildTransactionValidationParams(), tracer, header, worldUpdater); + callParameter, + Optional.empty(), + buildTransactionValidationParams(), + tracer, + header, + worldUpdater); LOG.trace("Executing {} call for transaction {}", traceTypeParameter, callParameter); if (maybeSimulatorResult.isEmpty()) { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilter.java index 74bfec87c2..6be65149cb 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilter.java @@ -23,7 +23,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonR import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; @@ -45,7 +44,7 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.vm.DebugOperationTracer; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; -import org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem; +import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; import org.hyperledger.besu.services.pipeline.Pipeline; @@ -58,7 +57,6 @@ import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.function.Function; -import java.util.function.Supplier; import java.util.stream.Stream; import javax.annotation.Nonnull; @@ -68,17 +66,24 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class TraceFilter extends TraceBlock { - private static final Logger LOG = LoggerFactory.getLogger(TraceFilter.class); private final Long maxRange; + private final LabelledMetric outputCounter; public TraceFilter( - final Supplier blockTracerSupplier, final ProtocolSchedule protocolSchedule, final BlockchainQueries blockchainQueries, - final Long maxRange) { - super(protocolSchedule, blockchainQueries); + final Long maxRange, + final MetricsSystem metricsSystem) { + super(protocolSchedule, blockchainQueries, metricsSystem); this.maxRange = maxRange; + this.outputCounter = + metricsSystem.createLabelledCounter( + BesuMetricCategory.BLOCKCHAIN, + "transactions_tracefilter_pipeline_processed_total", + "Number of transactions processed for trace_filter", + "step", + "action"); } @Override @@ -157,15 +162,6 @@ public class TraceFilter extends TraceBlock { final MainnetTransactionProcessor transactionProcessor = protocolSpec.getTransactionProcessor(); final ChainUpdater chainUpdater = new ChainUpdater(traceableState); - final LabelledMetric outputCounter = - new PrometheusMetricsSystem( - BesuMetricCategory.DEFAULT_METRIC_CATEGORIES, false) - .createLabelledCounter( - BesuMetricCategory.BLOCKCHAIN, - "transactions_tracefilter_pipeline_processed_total", - "Number of transactions processed for trace_filter", - "step", - "action"); DebugOperationTracer debugOperationTracer = new DebugOperationTracer(new TraceOptions(false, false, true), false); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java index 202d2ddbbb..51eeebb959 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java @@ -39,7 +39,7 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.vm.DebugOperationTracer; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; -import org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem; +import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; import org.hyperledger.besu.services.pipeline.Pipeline; @@ -57,13 +57,23 @@ import org.slf4j.LoggerFactory; public class TraceReplayBlockTransactions extends AbstractBlockParameterMethod { private static final Logger LOG = LoggerFactory.getLogger(TraceReplayBlockTransactions.class); - private final ProtocolSchedule protocolSchedule; private static final ObjectMapper MAPPER = new ObjectMapper(); + private final ProtocolSchedule protocolSchedule; + private final LabelledMetric outputCounter; public TraceReplayBlockTransactions( - final ProtocolSchedule protocolSchedule, final BlockchainQueries queries) { + final ProtocolSchedule protocolSchedule, + final BlockchainQueries queries, + final MetricsSystem metricsSystem) { super(queries); this.protocolSchedule = protocolSchedule; + this.outputCounter = + metricsSystem.createLabelledCounter( + BesuMetricCategory.BLOCKCHAIN, + "transactions_tracereplayblock_pipeline_processed_total", + "Number of transactions processed for each block", + "step", + "action"); } @Override @@ -131,14 +141,7 @@ public class TraceReplayBlockTransactions extends AbstractBlockParameterMethod { final ChainUpdater chainUpdater = new ChainUpdater(traceableState); final TransactionSource transactionSource = new TransactionSource(block); - final LabelledMetric outputCounter = - new PrometheusMetricsSystem(BesuMetricCategory.DEFAULT_METRIC_CATEGORIES, false) - .createLabelledCounter( - BesuMetricCategory.BLOCKCHAIN, - "transactions_tracereplayblock_pipeline_processed_total", - "Number of transactions processed for each block", - "step", - "action"); + final DebugOperationTracer debugOperationTracer = new DebugOperationTracer(new TraceOptions(false, false, true), false); final ExecuteTransactionStep executeTransactionStep = diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2.java index 00b0f83054..8d6bd7e433 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2.java @@ -61,11 +61,11 @@ public class EngineNewPayloadV2 extends AbstractEngineNewPayload { final Optional> maybeRequestsParam) { if (payloadParameter.getBlobGasUsed() != null) { return ValidationResult.invalid( - RpcErrorType.INVALID_BLOB_GAS_USED_PARAMS, "Missing blob gas used field"); + RpcErrorType.INVALID_BLOB_GAS_USED_PARAMS, "Unexpected blob gas used field present"); } if (payloadParameter.getExcessBlobGas() != null) { return ValidationResult.invalid( - RpcErrorType.INVALID_EXCESS_BLOB_GAS_PARAMS, "Missing excess blob gas field"); + RpcErrorType.INVALID_EXCESS_BLOB_GAS_PARAMS, "Unexpected excess blob gas field present"); } return ValidationResult.valid(); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetExtraData.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetExtraData.java index b433ed0b6a..02d7bac98c 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetExtraData.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetExtraData.java @@ -19,13 +19,13 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; 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.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; public class MinerGetExtraData implements JsonRpcMethod { - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; - public MinerGetExtraData(final MiningParameters miningParameters) { - this.miningParameters = miningParameters; + public MinerGetExtraData(final MiningConfiguration miningConfiguration) { + this.miningConfiguration = miningConfiguration; } @Override @@ -36,6 +36,6 @@ public class MinerGetExtraData implements JsonRpcMethod { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { return new JsonRpcSuccessResponse( - requestContext.getRequest().getId(), miningParameters.getExtraData().toShortHexString()); + requestContext.getRequest().getId(), miningConfiguration.getExtraData().toShortHexString()); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinGasPrice.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinGasPrice.java index 07e8fdc9b6..353125f84c 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinGasPrice.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinGasPrice.java @@ -20,13 +20,13 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; 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.api.jsonrpc.internal.results.Quantity; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; public class MinerGetMinGasPrice implements JsonRpcMethod { - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; - public MinerGetMinGasPrice(final MiningParameters miningParameters) { - this.miningParameters = miningParameters; + public MinerGetMinGasPrice(final MiningConfiguration miningConfiguration) { + this.miningConfiguration = miningConfiguration; } @Override @@ -38,6 +38,6 @@ public class MinerGetMinGasPrice implements JsonRpcMethod { public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { return new JsonRpcSuccessResponse( requestContext.getRequest().getId(), - Quantity.create(miningParameters.getMinTransactionGasPrice())); + Quantity.create(miningConfiguration.getMinTransactionGasPrice())); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinPriorityFee.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinPriorityFee.java index d99d13de2c..e12810b30f 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinPriorityFee.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinPriorityFee.java @@ -20,13 +20,13 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; 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.api.jsonrpc.internal.results.Quantity; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; public class MinerGetMinPriorityFee implements JsonRpcMethod { - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; - public MinerGetMinPriorityFee(final MiningParameters miningParameters) { - this.miningParameters = miningParameters; + public MinerGetMinPriorityFee(final MiningConfiguration miningConfiguration) { + this.miningConfiguration = miningConfiguration; } @Override @@ -38,6 +38,6 @@ public class MinerGetMinPriorityFee implements JsonRpcMethod { public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { return new JsonRpcSuccessResponse( requestContext.getRequest().getId(), - Quantity.create(miningParameters.getMinPriorityFeePerGas())); + Quantity.create(miningConfiguration.getMinPriorityFeePerGas())); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetExtraData.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetExtraData.java index 51395e24f7..7d5fa5b2e0 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetExtraData.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetExtraData.java @@ -23,7 +23,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorR 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.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import java.nio.charset.StandardCharsets; @@ -35,10 +35,10 @@ import org.slf4j.LoggerFactory; public class MinerSetExtraData implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(MinerSetExtraData.class); - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; - public MinerSetExtraData(final MiningParameters miningParameters) { - this.miningParameters = miningParameters; + public MinerSetExtraData(final MiningConfiguration miningConfiguration) { + this.miningConfiguration = miningConfiguration; } @Override @@ -53,7 +53,7 @@ public class MinerSetExtraData implements JsonRpcMethod { Bytes32.fromHexStringLenient( rawParam); // done for validation, we want a hex string and max 32 bytes final var extraData = Bytes.fromHexStringLenient(rawParam); - miningParameters.setExtraData(extraData); + miningConfiguration.setExtraData(extraData); LOG.atDebug() .setMessage("set extra data, raw=[{}] parsed=[{}], UTF-8=[{}]") .addArgument(rawParam) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinGasPrice.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinGasPrice.java index 733ed3a8f3..e932669b00 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinGasPrice.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinGasPrice.java @@ -25,7 +25,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorR 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.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,10 +33,10 @@ import org.slf4j.LoggerFactory; public class MinerSetMinGasPrice implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(MinerSetMinGasPrice.class); - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; - public MinerSetMinGasPrice(final MiningParameters miningParameters) { - this.miningParameters = miningParameters; + public MinerSetMinGasPrice(final MiningConfiguration miningConfiguration) { + this.miningConfiguration = miningConfiguration; } @Override @@ -49,7 +49,7 @@ public class MinerSetMinGasPrice implements JsonRpcMethod { try { final Wei minGasPrice = Wei.fromHexString(requestContext.getRequiredParameter(0, String.class)); - miningParameters.setMinTransactionGasPrice(minGasPrice); + miningConfiguration.setMinTransactionGasPrice(minGasPrice); LOG.debug("min gas price changed to {}", minGasPrice.toHumanReadableString()); return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), true); } catch (final IllegalArgumentException invalidJsonRpcParameters) { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinPriorityFee.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinPriorityFee.java index b1bf4338f7..d296f28f92 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinPriorityFee.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinPriorityFee.java @@ -24,7 +24,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorR 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.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,10 +32,10 @@ import org.slf4j.LoggerFactory; public class MinerSetMinPriorityFee implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(MinerSetMinPriorityFee.class); - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; - public MinerSetMinPriorityFee(final MiningParameters miningParameters) { - this.miningParameters = miningParameters; + public MinerSetMinPriorityFee(final MiningConfiguration miningConfiguration) { + this.miningConfiguration = miningConfiguration; } @Override @@ -48,7 +48,7 @@ public class MinerSetMinPriorityFee implements JsonRpcMethod { try { final Wei minPriorityFeePerGas = Wei.fromHexString(requestContext.getRequiredParameter(0, String.class)); - miningParameters.setMinPriorityFeePerGas(minPriorityFeePerGas); + miningConfiguration.setMinPriorityFeePerGas(minPriorityFeePerGas); LOG.debug( "min priority fee per gas changed to {}", minPriorityFeePerGas.toHumanReadableString()); return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), true); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/DisabledPrivacyRpcMethod.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/DisabledPrivacyRpcMethod.java index d51d32a1d4..04e7dd4067 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/DisabledPrivacyRpcMethod.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/DisabledPrivacyRpcMethod.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorR import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; +@Deprecated(since = "24.11.0") public class DisabledPrivacyRpcMethod implements JsonRpcMethod { private final String methodName; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/MultiTenancyRpcMethodDecorator.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/MultiTenancyRpcMethodDecorator.java index 823c8b13cf..3f7a87c7f4 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/MultiTenancyRpcMethodDecorator.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/MultiTenancyRpcMethodDecorator.java @@ -27,6 +27,7 @@ import io.vertx.ext.auth.User; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class MultiTenancyRpcMethodDecorator implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(MultiTenancyRpcMethodDecorator.class); private final JsonRpcMethod rpcMethod; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/MultiTenancyUserUtil.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/MultiTenancyUserUtil.java index 871d3fa577..54daee347d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/MultiTenancyUserUtil.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/MultiTenancyUserUtil.java @@ -18,6 +18,7 @@ import java.util.Optional; import io.vertx.ext.auth.User; +@Deprecated(since = "24.11.0") public class MultiTenancyUserUtil { private static final String PRIVACY_USER_ID_CLAIM = "privacyUserId"; private static final String ENCLAVE_PRIVACY_PUBLIC_KEY_CLAIM = "privacyPublicKey"; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterChanges.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterChanges.java index 4ef7e0aa1c..9175464fe2 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterChanges.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterChanges.java @@ -31,6 +31,7 @@ import org.hyperledger.besu.ethereum.privacy.PrivacyController; import java.util.List; +@Deprecated(since = "24.11.0") public class PrivGetFilterChanges implements JsonRpcMethod { private final PrivacyController privacyController; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterLogs.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterLogs.java index ea6a5894a3..bf497d41aa 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterLogs.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterLogs.java @@ -31,6 +31,7 @@ import org.hyperledger.besu.ethereum.privacy.PrivacyController; import java.util.List; +@Deprecated(since = "24.11.0") public class PrivGetFilterLogs implements JsonRpcMethod { private final PrivacyController privacyController; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivUninstallFilter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivUninstallFilter.java index eb41a1dad4..aeaa2613b0 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivUninstallFilter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivUninstallFilter.java @@ -26,6 +26,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController; import org.hyperledger.besu.ethereum.privacy.PrivacyController; +@Deprecated(since = "24.11.0") public class PrivUninstallFilter implements JsonRpcMethod { private final FilterManager filterManager; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivacyIdProvider.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivacyIdProvider.java index 5f01bae059..d59a64b0ba 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivacyIdProvider.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivacyIdProvider.java @@ -23,6 +23,7 @@ import java.util.Optional; import io.vertx.ext.auth.User; @FunctionalInterface +@Deprecated(since = "24.11.0") public interface PrivacyIdProvider { String getPrivacyUserId(Optional user); 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 e96a08eb7d..b8e78621ef 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 @@ -48,6 +48,7 @@ import org.apache.tuweni.bytes.Bytes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public abstract class AbstractEeaSendRawTransaction implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(AbstractEeaSendRawTransaction.class); private final TransactionPool transactionPool; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/JsonRpcErrorResponseException.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/JsonRpcErrorResponseException.java index 79d006f48e..7b22ebcef1 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/JsonRpcErrorResponseException.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/JsonRpcErrorResponseException.java @@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.eea; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; +@Deprecated(since = "24.11.0") public class JsonRpcErrorResponseException extends RuntimeException { private final RpcErrorType jsonRpcError; 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 c81c0852e0..513d0fa351 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 @@ -33,6 +33,7 @@ import java.util.Optional; import io.vertx.ext.auth.User; import org.apache.tuweni.bytes.Bytes; +@Deprecated(since = "24.11.0") public class PluginEeaSendRawTransaction extends AbstractEeaSendRawTransaction { private final PrivacyController privacyController; private final PrivacyIdProvider privacyIdProvider; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedFlexibleEeaSendRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedFlexibleEeaSendRawTransaction.java index 3fa12563c0..6c300fbc30 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedFlexibleEeaSendRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedFlexibleEeaSendRawTransaction.java @@ -37,6 +37,7 @@ import java.util.Optional; import io.vertx.ext.auth.User; import org.apache.tuweni.bytes.Bytes; +@Deprecated(since = "24.11.0") public class RestrictedFlexibleEeaSendRawTransaction extends AbstractEeaSendRawTransaction { private final PrivacyController privacyController; 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 34b4697391..de467e31bc 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 @@ -35,6 +35,7 @@ import java.util.Optional; import io.vertx.ext.auth.User; import org.apache.tuweni.bytes.Bytes; +@Deprecated(since = "24.11.0") public class RestrictedOffchainEeaSendRawTransaction extends AbstractEeaSendRawTransaction { final PrivacyController privacyController; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/AbstractPrivateTraceByHash.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/AbstractPrivateTraceByHash.java index 0139886862..209d5bf3bf 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/AbstractPrivateTraceByHash.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/AbstractPrivateTraceByHash.java @@ -41,6 +41,7 @@ import java.util.Optional; import java.util.function.Supplier; import java.util.stream.Stream; +@Deprecated(since = "24.11.0") public abstract class AbstractPrivateTraceByHash implements JsonRpcMethod { protected final Supplier blockTracerSupplier; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java index 5d9edc63b9..5be9a9f2ab 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java @@ -33,6 +33,7 @@ import org.hyperledger.besu.ethereum.privacy.PrivacyController; import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason; +@Deprecated(since = "24.11.0") public class PrivCall extends AbstractBlockParameterMethod { private final PrivacyIdProvider privacyIdProvider; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java index 568125a276..09ff5b19f9 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java @@ -32,6 +32,7 @@ import org.hyperledger.besu.ethereum.privacy.PrivacyController; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class PrivCreatePrivacyGroup implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(PrivCreatePrivacyGroup.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java index dc0fc90f66..d8c411c085 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java @@ -39,6 +39,7 @@ import java.util.regex.Pattern; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class PrivDebugGetStateRoot extends AbstractBlockParameterMethod { private static final Logger LOG = LoggerFactory.getLogger(PrivDebugGetStateRoot.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDeletePrivacyGroup.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDeletePrivacyGroup.java index 61b7791b3c..73849eb92e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDeletePrivacyGroup.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDeletePrivacyGroup.java @@ -32,6 +32,7 @@ import org.hyperledger.besu.ethereum.privacy.PrivacyController; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class PrivDeletePrivacyGroup implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(PrivDeletePrivacyGroup.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDistributeRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDistributeRawTransaction.java index aac4df3d2c..7375590d55 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDistributeRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDistributeRawTransaction.java @@ -48,6 +48,7 @@ import org.apache.tuweni.bytes.Bytes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class PrivDistributeRawTransaction implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(PrivDistributeRawTransaction.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivFindPrivacyGroup.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivFindPrivacyGroup.java index 7e82323223..e41728b044 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivFindPrivacyGroup.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivFindPrivacyGroup.java @@ -37,6 +37,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; @SuppressWarnings("MockNotUsedInProduction") +@Deprecated(since = "24.11.0") public class PrivFindPrivacyGroup implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(PrivFindPrivacyGroup.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java index 7042d357f1..da3179834f 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java @@ -28,6 +28,7 @@ import org.hyperledger.besu.ethereum.privacy.PrivacyController; import org.apache.tuweni.bytes.Bytes; +@Deprecated(since = "24.11.0") public class PrivGetCode extends AbstractBlockParameterMethod { private final PrivacyController privacyController; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java index 9f231f41c0..e35ad79da7 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java @@ -42,6 +42,7 @@ import org.apache.tuweni.bytes.Bytes32; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class PrivGetEeaTransactionCount implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(PrivGetEeaTransactionCount.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetLogs.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetLogs.java index 6947ea5e54..735eb9bf9d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetLogs.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetLogs.java @@ -38,6 +38,7 @@ import java.util.Collections; import java.util.List; import java.util.Optional; +@Deprecated(since = "24.11.0") public class PrivGetLogs implements JsonRpcMethod { private final BlockchainQueries blockchainQueries; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetPrivacyPrecompileAddress.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetPrivacyPrecompileAddress.java index 816ed1c5da..46e52525be 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetPrivacyPrecompileAddress.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetPrivacyPrecompileAddress.java @@ -22,6 +22,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcRespon import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.core.PrivacyParameters; +@Deprecated(since = "24.11.0") public class PrivGetPrivacyPrecompileAddress implements JsonRpcMethod { private final Address privacyAddress; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetPrivateTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetPrivateTransaction.java index 8779181599..4419b82d50 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetPrivateTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetPrivateTransaction.java @@ -38,6 +38,7 @@ import java.util.Optional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class PrivGetPrivateTransaction implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(PrivGetPrivateTransaction.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java index d8757dc2fb..fc547e8864 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java @@ -34,6 +34,7 @@ import org.hyperledger.besu.ethereum.privacy.PrivacyController; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class PrivGetTransactionCount implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(PrivGetTransactionCount.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionReceipt.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionReceipt.java index 287793ddc0..b7c7f25b4d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionReceipt.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionReceipt.java @@ -43,6 +43,7 @@ import org.apache.tuweni.bytes.Bytes32; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class PrivGetTransactionReceipt implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(PrivGetTransactionReceipt.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivNewFilter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivNewFilter.java index 49fc11f4b8..bd2ece37b9 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivNewFilter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivNewFilter.java @@ -29,6 +29,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController; import org.hyperledger.besu.ethereum.privacy.PrivacyController; +@Deprecated(since = "24.11.0") public class PrivNewFilter implements JsonRpcMethod { private final FilterManager filterManager; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivTraceTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivTraceTransaction.java index 07d663bef5..f044b39f77 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivTraceTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivTraceTransaction.java @@ -43,6 +43,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class PrivTraceTransaction extends AbstractPrivateTraceByHash implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(TraceTransaction.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivUtil.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivUtil.java index 8db4b73bdb..a3ca662fd1 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivUtil.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivUtil.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.ethereum.privacy.PrivacyController; import java.util.Optional; +@Deprecated(since = "24.11.0") public class PrivUtil { public static void checkMembershipForAuthenticatedUser( diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindFlexiblePrivacyGroup.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindFlexiblePrivacyGroup.java index 0a66d1aa73..925dc4ec65 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindFlexiblePrivacyGroup.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindFlexiblePrivacyGroup.java @@ -36,6 +36,7 @@ import graphql.com.google.common.collect.Lists; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class PrivxFindFlexiblePrivacyGroup implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(PrivxFindFlexiblePrivacyGroup.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindOnchainPrivacyGroup.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindOnchainPrivacyGroup.java index e09c72464e..015c772859 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindOnchainPrivacyGroup.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindOnchainPrivacyGroup.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.Privac import org.hyperledger.besu.ethereum.privacy.PrivacyController; // Use PrivxFindFlexiblePrivacyGroup instead -@Deprecated +@Deprecated(since = "21.10.3") public class PrivxFindOnchainPrivacyGroup extends PrivxFindFlexiblePrivacyGroup { public PrivxFindOnchainPrivacyGroup( diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/parameters/CreatePrivacyGroupParameter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/parameters/CreatePrivacyGroupParameter.java index f826ef179d..c66f754d20 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/parameters/CreatePrivacyGroupParameter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/parameters/CreatePrivacyGroupParameter.java @@ -20,6 +20,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +@Deprecated(since = "24.11.0") public class CreatePrivacyGroupParameter { private final List addresses; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/proof/GetProofResult.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/proof/GetProofResult.java index f4adb7b0fe..e2ec8df4ba 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/proof/GetProofResult.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/proof/GetProofResult.java @@ -18,7 +18,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity; import org.hyperledger.besu.ethereum.proof.WorldStateProof; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import java.util.ArrayList; import java.util.List; @@ -64,7 +64,8 @@ public class GetProofResult { public static GetProofResult buildGetProofResult( final Address address, final WorldStateProof worldStateProof) { - final StateTrieAccountValue stateTrieAccountValue = worldStateProof.getStateTrieAccountValue(); + final PmtStateTrieAccountValue stateTrieAccountValue = + worldStateProof.getStateTrieAccountValue(); final List storageEntries = new ArrayList<>(); worldStateProof 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 cdf4440bde..2e68576fca 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 @@ -25,7 +25,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.RpcModules; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.manager.EthPeers; @@ -67,7 +67,7 @@ public class JsonRpcMethodsFactory { final ProtocolContext protocolContext, final FilterManager filterManager, final TransactionPool transactionPool, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final MiningCoordinator miningCoordinator, final ObservableMetricsSystem metricsSystem, final Set supportedCapabilities, @@ -139,7 +139,7 @@ public class JsonRpcMethodsFactory { webSocketConfiguration, metricsConfiguration, graphQLConfiguration), - new MinerJsonRpcMethods(miningParameters, miningCoordinator), + new MinerJsonRpcMethods(miningConfiguration, miningCoordinator), new PermJsonRpcMethods(accountsAllowlistController, nodeAllowlistController), new PrivJsonRpcMethods( blockchainQueries, @@ -151,7 +151,11 @@ public class JsonRpcMethodsFactory { blockchainQueries, protocolSchedule, transactionPool, privacyParameters), new Web3JsonRpcMethods(clientNodeName), new TraceJsonRpcMethods( - blockchainQueries, protocolSchedule, protocolContext, apiConfiguration), + blockchainQueries, + protocolSchedule, + protocolContext, + apiConfiguration, + metricsSystem), new TxPoolJsonRpcMethods(transactionPool), new PluginsJsonRpcMethods(namedPlugins)); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/MinerJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/MinerJsonRpcMethods.java index c799c23305..14e74767ee 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/MinerJsonRpcMethods.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/MinerJsonRpcMethods.java @@ -28,18 +28,18 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.miner.MinerSet import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.miner.MinerStart; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.miner.MinerStop; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import java.util.Map; public class MinerJsonRpcMethods extends ApiGroupJsonRpcMethods { private final MiningCoordinator miningCoordinator; - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; public MinerJsonRpcMethods( - final MiningParameters miningParameters, final MiningCoordinator miningCoordinator) { - this.miningParameters = miningParameters; + final MiningConfiguration miningConfiguration, final MiningCoordinator miningCoordinator) { + this.miningConfiguration = miningConfiguration; this.miningCoordinator = miningCoordinator; } @@ -57,11 +57,11 @@ public class MinerJsonRpcMethods extends ApiGroupJsonRpcMethods { minerSetCoinbase, new MinerSetEtherbase(minerSetCoinbase), new MinerChangeTargetGasLimit(miningCoordinator), - new MinerGetMinPriorityFee(miningParameters), - new MinerSetMinPriorityFee(miningParameters), - new MinerGetMinGasPrice(miningParameters), - new MinerSetMinGasPrice(miningParameters), - new MinerGetExtraData(miningParameters), - new MinerSetExtraData(miningParameters)); + new MinerGetMinPriorityFee(miningConfiguration), + new MinerSetMinPriorityFee(miningConfiguration), + new MinerGetMinGasPrice(miningConfiguration), + new MinerSetMinGasPrice(miningConfiguration), + new MinerGetExtraData(miningConfiguration), + new MinerSetExtraData(miningConfiguration)); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivJsonRpcMethods.java index 8ae62741b9..48d1dccee9 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivJsonRpcMethods.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivJsonRpcMethods.java @@ -46,6 +46,7 @@ import org.hyperledger.besu.plugin.services.privacy.PrivateMarkerTransactionFact import java.util.Map; +@Deprecated(since = "24.11.0") public class PrivJsonRpcMethods extends PrivacyApiGroupJsonRpcMethods { private final FilterManager filterManager; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivacyApiGroupJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivacyApiGroupJsonRpcMethods.java index 304a36a677..e648febc37 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivacyApiGroupJsonRpcMethods.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivacyApiGroupJsonRpcMethods.java @@ -42,6 +42,7 @@ import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; +@Deprecated(since = "24.11.0") public abstract class PrivacyApiGroupJsonRpcMethods extends ApiGroupJsonRpcMethods { private final BlockchainQueries blockchainQueries; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/TraceJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/TraceJsonRpcMethods.java index 6a36bebfcd..4638e90a62 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/TraceJsonRpcMethods.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/TraceJsonRpcMethods.java @@ -31,6 +31,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.transaction.TransactionSimulator; +import org.hyperledger.besu.plugin.services.MetricsSystem; import java.util.Map; @@ -38,19 +39,21 @@ public class TraceJsonRpcMethods extends ApiGroupJsonRpcMethods { private final BlockchainQueries blockchainQueries; private final ProtocolSchedule protocolSchedule; - private final ApiConfiguration apiConfiguration; private final ProtocolContext protocolContext; + private final MetricsSystem metricsSystem; TraceJsonRpcMethods( final BlockchainQueries blockchainQueries, final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, - final ApiConfiguration apiConfiguration) { + final ApiConfiguration apiConfiguration, + final MetricsSystem metricsSystem) { this.blockchainQueries = blockchainQueries; this.protocolSchedule = protocolSchedule; this.protocolContext = protocolContext; this.apiConfiguration = apiConfiguration; + this.metricsSystem = metricsSystem; } @Override @@ -63,16 +66,16 @@ public class TraceJsonRpcMethods extends ApiGroupJsonRpcMethods { final BlockReplay blockReplay = new BlockReplay(protocolSchedule, protocolContext, blockchainQueries.getBlockchain()); return mapOf( - new TraceReplayBlockTransactions(protocolSchedule, blockchainQueries), + new TraceReplayBlockTransactions(protocolSchedule, blockchainQueries, metricsSystem), new TraceFilter( - () -> new BlockTracer(blockReplay), protocolSchedule, blockchainQueries, - apiConfiguration.getMaxTraceFilterRange()), + apiConfiguration.getMaxTraceFilterRange(), + metricsSystem), new TraceGet(() -> new BlockTracer(blockReplay), blockchainQueries, protocolSchedule), new TraceTransaction( () -> new BlockTracer(blockReplay), protocolSchedule, blockchainQueries), - new TraceBlock(protocolSchedule, blockchainQueries), + new TraceBlock(protocolSchedule, blockchainQueries, metricsSystem), new TraceCall( blockchainQueries, protocolSchedule, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketConfiguration.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketConfiguration.java index e27f7f21ce..42905b96a7 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketConfiguration.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketConfiguration.java @@ -25,6 +25,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.Optional; import com.google.common.base.MoreObjects; @@ -49,6 +50,21 @@ public class WebSocketConfiguration { private int maxActiveConnections; private int maxFrameSize; + private boolean isSslEnabled = false; + private Optional keyStorePath = Optional.empty(); + private Optional keyStorePassword = Optional.empty(); + private Optional keyStoreType = Optional.of("JKS"); // Default to JKS + + private boolean clientAuthEnabled = false; + private Optional trustStorePath = Optional.empty(); + private Optional trustStorePassword = Optional.empty(); + private Optional trustStoreType = Optional.of("JKS"); // Default to JKS + + // For PEM format + private Optional keyPath = Optional.empty(); + private Optional certPath = Optional.empty(); + private Optional trustCertPath = Optional.empty(); + public static WebSocketConfiguration createDefault() { final WebSocketConfiguration config = new WebSocketConfiguration(); config.setEnabled(false); @@ -159,6 +175,102 @@ public class WebSocketConfiguration { this.timeoutSec = timeoutSec; } + public boolean isSslEnabled() { + return isSslEnabled; + } + + public void setSslEnabled(final boolean isSslEnabled) { + this.isSslEnabled = isSslEnabled; + } + + public Optional getKeyStorePath() { + return keyStorePath; + } + + public void setKeyStorePath(final String keyStorePath) { + this.keyStorePath = Optional.ofNullable(keyStorePath); + } + + public Optional getKeyStorePassword() { + return keyStorePassword; + } + + public void setKeyStorePassword(final String keyStorePassword) { + this.keyStorePassword = Optional.ofNullable(keyStorePassword); + } + + // Keystore Type + public Optional getKeyStoreType() { + return keyStoreType; + } + + public void setKeyStoreType(final String keyStoreType) { + this.keyStoreType = Optional.ofNullable(keyStoreType); + } + + // Key Path (for PEM) + public Optional getKeyPath() { + return keyPath; + } + + public void setKeyPath(final String keyPath) { + this.keyPath = Optional.ofNullable(keyPath); + } + + // Cert Path (for PEM) + public Optional getCertPath() { + return certPath; + } + + public void setCertPath(final String certPath) { + this.certPath = Optional.ofNullable(certPath); + } + + // Client Authentication Enabled + public boolean isClientAuthEnabled() { + return clientAuthEnabled; + } + + public void setClientAuthEnabled(final boolean clientAuthEnabled) { + this.clientAuthEnabled = clientAuthEnabled; + } + + // Truststore Path + public Optional getTrustStorePath() { + return trustStorePath; + } + + public void setTrustStorePath(final String trustStorePath) { + this.trustStorePath = Optional.ofNullable(trustStorePath); + } + + // Truststore Password + public Optional getTrustStorePassword() { + return trustStorePassword; + } + + public void setTrustStorePassword(final String trustStorePassword) { + this.trustStorePassword = Optional.ofNullable(trustStorePassword); + } + + // Truststore Type + public Optional getTrustStoreType() { + return trustStoreType; + } + + public void setTrustStoreType(final String trustStoreType) { + this.trustStoreType = Optional.ofNullable(trustStoreType); + } + + // Trust Cert Path (for PEM) + public Optional getTrustCertPath() { + return trustCertPath; + } + + public void setTrustCertPath(final String trustCertPath) { + this.trustCertPath = Optional.ofNullable(trustCertPath); + } + @Override public boolean equals(final Object o) { if (this == o) { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketService.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketService.java index 59742836ba..31c86b18d2 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketService.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketService.java @@ -25,6 +25,7 @@ import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.plugin.services.MetricsSystem; import java.net.InetSocketAddress; +import java.util.Locale; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicInteger; @@ -34,6 +35,7 @@ import io.vertx.core.AsyncResult; import io.vertx.core.Handler; import io.vertx.core.Vertx; import io.vertx.core.buffer.Buffer; +import io.vertx.core.http.ClientAuth; import io.vertx.core.http.HttpConnection; import io.vertx.core.http.HttpServer; import io.vertx.core.http.HttpServerOptions; @@ -41,6 +43,9 @@ import io.vertx.core.http.HttpServerRequest; import io.vertx.core.http.HttpServerResponse; import io.vertx.core.http.ServerWebSocket; import io.vertx.core.net.HostAndPort; +import io.vertx.core.net.JksOptions; +import io.vertx.core.net.PemKeyCertOptions; +import io.vertx.core.net.PemTrustOptions; import io.vertx.core.net.SocketAddress; import io.vertx.ext.web.Router; import io.vertx.ext.web.RoutingContext; @@ -103,18 +108,65 @@ public class WebSocketService { "Starting Websocket service on {}:{}", configuration.getHost(), configuration.getPort()); final CompletableFuture resultFuture = new CompletableFuture<>(); + HttpServerOptions serverOptions = + new HttpServerOptions() + .setHost(configuration.getHost()) + .setPort(configuration.getPort()) + .setHandle100ContinueAutomatically(true) + .setCompressionSupported(true) + .addWebSocketSubProtocol("undefined") + .setMaxWebSocketFrameSize(configuration.getMaxFrameSize()) + .setMaxWebSocketMessageSize(configuration.getMaxFrameSize() * 4) + .setRegisterWebSocketWriteHandlers(true); + + // Check if SSL/TLS is enabled in the configuration + if (configuration.isSslEnabled()) { + serverOptions.setSsl(true); + + String keystorePath = configuration.getKeyStorePath().orElse(null); + String keystorePassword = configuration.getKeyStorePassword().orElse(null); + String keyPath = configuration.getKeyPath().orElse(null); + String certPath = configuration.getCertPath().orElse(null); + + String keystoreType = configuration.getKeyStoreType().orElse("JKS"); + + switch (keystoreType.toUpperCase(Locale.getDefault())) { + case "PEM": + serverOptions.setKeyCertOptions( + new PemKeyCertOptions().setKeyPath(keyPath).setCertPath(certPath)); + break; + case "JKS": + default: + serverOptions.setKeyCertOptions( + new JksOptions().setPath(keystorePath).setPassword(keystorePassword)); + break; + } + } + + // Set up truststore for client authentication (mTLS) + if (configuration.isClientAuthEnabled()) { + serverOptions.setClientAuth(ClientAuth.REQUIRED); + + String truststorePath = configuration.getTrustStorePath().orElse(null); + String truststorePassword = configuration.getTrustStorePassword().orElse(""); + String truststoreType = configuration.getTrustStoreType().orElse("JKS"); + String trustCertPath = configuration.getTrustCertPath().orElse(null); + + switch (truststoreType.toUpperCase(Locale.getDefault())) { + case "PEM": + serverOptions.setTrustOptions(new PemTrustOptions().addCertPath(trustCertPath)); + break; + case "JKS": + default: + serverOptions.setTrustOptions( + new JksOptions().setPath(truststorePath).setPassword(truststorePassword)); + break; + } + } + httpServer = vertx - .createHttpServer( - new HttpServerOptions() - .setHost(configuration.getHost()) - .setPort(configuration.getPort()) - .setHandle100ContinueAutomatically(true) - .setCompressionSupported(true) - .addWebSocketSubProtocol("undefined") - .setMaxWebSocketFrameSize(configuration.getMaxFrameSize()) - .setMaxWebSocketMessageSize(configuration.getMaxFrameSize() * 4) - .setRegisterWebSocketWriteHandlers(true)) + .createHttpServer(serverOptions) .webSocketHandler(websocketHandler()) .connectionHandler(connectionHandler()) .requestHandler(httpHandler()) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java index c03bf124c4..7e5a7c6fe0 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java @@ -30,7 +30,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.LogWithMetadata; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; @@ -77,20 +77,20 @@ public class BlockchainQueries { private final Optional transactionLogBloomCacher; private final Optional ethScheduler; private final ApiConfiguration apiConfig; - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; public BlockchainQueries( final ProtocolSchedule protocolSchedule, final Blockchain blockchain, final WorldStateArchive worldStateArchive, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { this( protocolSchedule, blockchain, worldStateArchive, Optional.empty(), Optional.empty(), - miningParameters); + miningConfiguration); } public BlockchainQueries( @@ -98,14 +98,14 @@ public class BlockchainQueries { final Blockchain blockchain, final WorldStateArchive worldStateArchive, final EthScheduler scheduler, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { this( protocolSchedule, blockchain, worldStateArchive, Optional.empty(), Optional.ofNullable(scheduler), - miningParameters); + miningConfiguration); } public BlockchainQueries( @@ -114,7 +114,7 @@ public class BlockchainQueries { final WorldStateArchive worldStateArchive, final Optional cachePath, final Optional scheduler, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { this( protocolSchedule, blockchain, @@ -122,7 +122,7 @@ public class BlockchainQueries { cachePath, scheduler, ImmutableApiConfiguration.builder().build(), - miningParameters); + miningConfiguration); } public BlockchainQueries( @@ -132,7 +132,7 @@ public class BlockchainQueries { final Optional cachePath, final Optional scheduler, final ApiConfiguration apiConfig, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { this.protocolSchedule = protocolSchedule; this.blockchain = blockchain; this.worldStateArchive = worldStateArchive; @@ -144,7 +144,7 @@ public class BlockchainQueries { new TransactionLogBloomCacher(blockchain, cachePath.get(), scheduler.get())) : Optional.empty(); this.apiConfig = apiConfig; - this.miningParameters = miningParameters; + this.miningConfiguration = miningConfiguration; } public Blockchain getBlockchain() { @@ -1034,7 +1034,7 @@ public class BlockchainQueries { private Wei gasPriceLowerBound( final BlockHeader chainHeadHeader, final FeeMarket nextBlockFeeMarket) { - final var minGasPrice = miningParameters.getMinTransactionGasPrice(); + final var minGasPrice = miningConfiguration.getMinTransactionGasPrice(); if (nextBlockFeeMarket.implementsBaseFee()) { return UInt256s.max( @@ -1070,9 +1070,9 @@ public class BlockchainQueries { .toArray(Wei[]::new); return gasCollection.length == 0 - ? miningParameters.getMinPriorityFeePerGas() + ? miningConfiguration.getMinPriorityFeePerGas() : UInt256s.max( - miningParameters.getMinPriorityFeePerGas(), + miningConfiguration.getMinPriorityFeePerGas(), gasCollection[ Math.min( gasCollection.length - 1, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/StateBackupService.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/StateBackupService.java index 63f5101649..27d96a1be9 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/StateBackupService.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/StateBackupService.java @@ -29,9 +29,9 @@ import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.hyperledger.besu.ethereum.trie.Node; import org.hyperledger.besu.ethereum.trie.TrieIterator; import org.hyperledger.besu.ethereum.trie.TrieIterator.State; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.util.io.RollingFileWriter; import java.io.IOException; @@ -241,8 +241,8 @@ public class StateBackupService { backupStatus.currentAccount = nodeKey; final Bytes nodeValue = node.getValue().orElse(Hash.EMPTY); - final StateTrieAccountValue account = - StateTrieAccountValue.readFrom(new BytesValueRLPInput(nodeValue, false)); + final PmtStateTrieAccountValue account = + PmtStateTrieAccountValue.readFrom(new BytesValueRLPInput(nodeValue, false)); final Bytes code = worldStateKeyValueStorage.getCode(account.getCodeHash()).orElse(Bytes.EMPTY); backupStatus.codeSize.addAndGet(code.size()); 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 5a1c23d40e..08cfc3d7bd 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 @@ -19,6 +19,7 @@ import static org.mockito.Mockito.when; import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.ConsensusContext; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.ImmutableApiConfiguration; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -27,7 +28,7 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.core.DefaultSyncStatus; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -110,7 +111,10 @@ public abstract class AbstractEthGraphQLHttpServiceTest { final MutableBlockchain blockchain = blockchainSetupUtil.getBlockchain(); ProtocolContext context = new ProtocolContext( - blockchain, blockchainSetupUtil.getWorldArchive(), null, new BadBlockManager()); + blockchain, + blockchainSetupUtil.getWorldArchive(), + mock(ConsensusContext.class), + new BadBlockManager()); final BlockchainQueries blockchainQueries = new BlockchainQueries( blockchainSetupUtil.getProtocolSchedule(), @@ -119,7 +123,7 @@ public abstract class AbstractEthGraphQLHttpServiceTest { Optional.empty(), Optional.empty(), ImmutableApiConfiguration.builder().build(), - MiningParameters.newDefault().setMinTransactionGasPrice(Wei.ZERO)); + MiningConfiguration.newDefault().setMinTransactionGasPrice(Wei.ZERO)); final Set supportedCapabilities = new HashSet<>(); supportedCapabilities.add(EthProtocol.ETH62); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/handlers/JsonRpcExecutorHandlerTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/handlers/JsonRpcExecutorHandlerTest.java new file mode 100644 index 0000000000..ee00e433b2 --- /dev/null +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/handlers/JsonRpcExecutorHandlerTest.java @@ -0,0 +1,110 @@ +/* + * Copyright contributors to Hyperledger Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.api.handlers; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.contains; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration; +import org.hyperledger.besu.ethereum.api.jsonrpc.context.ContextKey; +import org.hyperledger.besu.ethereum.api.jsonrpc.execution.JsonRpcExecutor; + +import io.netty.handler.codec.http.HttpResponseStatus; +import io.opentelemetry.api.trace.Tracer; +import io.vertx.core.Handler; +import io.vertx.core.Vertx; +import io.vertx.core.http.HttpServerResponse; +import io.vertx.ext.web.RoutingContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +class JsonRpcExecutorHandlerTest { + + private JsonRpcExecutor mockExecutor; + private Tracer mockTracer; + private JsonRpcConfiguration mockConfig; + private RoutingContext mockContext; + private Vertx mockVertx; + private HttpServerResponse mockResponse; + + @BeforeEach + void setUp() { + mockExecutor = mock(JsonRpcExecutor.class); + mockTracer = mock(Tracer.class); + mockConfig = mock(JsonRpcConfiguration.class); + mockContext = mock(RoutingContext.class); + mockVertx = mock(Vertx.class); + mockResponse = mock(HttpServerResponse.class); + + when(mockContext.vertx()).thenReturn(mockVertx); + when(mockContext.response()).thenReturn(mockResponse); + when(mockResponse.ended()).thenReturn(false); + when(mockResponse.setStatusCode(anyInt())).thenReturn(mockResponse); + } + + @Test + void testTimeoutHandling() { + // Arrange + Handler handler = + JsonRpcExecutorHandler.handler(mockExecutor, mockTracer, mockConfig); + ArgumentCaptor delayCaptor = ArgumentCaptor.forClass(Long.class); + @SuppressWarnings("unchecked") + ArgumentCaptor> timerHandlerCaptor = ArgumentCaptor.forClass(Handler.class); + + when(mockContext.get(eq(ContextKey.REQUEST_BODY_AS_JSON_OBJECT.name()))).thenReturn("{}"); + when(mockVertx.setTimer(delayCaptor.capture(), timerHandlerCaptor.capture())).thenReturn(1L); + when(mockContext.get("timerId")).thenReturn(1L); + + // Act + handler.handle(mockContext); + + // Assert + verify(mockVertx).setTimer(eq(30000L), any()); + + // Simulate timeout + timerHandlerCaptor.getValue().handle(1L); + + // Verify timeout handling + verify(mockResponse, times(1)) + .setStatusCode(eq(HttpResponseStatus.REQUEST_TIMEOUT.code())); // Expect 408 Request Timeout + verify(mockResponse, times(1)).end(contains("Timeout expired")); + verify(mockVertx, times(1)).cancelTimer(1L); + } + + @Test + void testCancelTimerOnSuccessfulExecution() { + // Arrange + Handler handler = + JsonRpcExecutorHandler.handler(mockExecutor, mockTracer, mockConfig); + when(mockContext.get(eq(ContextKey.REQUEST_BODY_AS_JSON_OBJECT.name()))).thenReturn("{}"); + when(mockVertx.setTimer(anyLong(), any())).thenReturn(1L); + when(mockContext.get("timerId")).thenReturn(1L); + + // Act + handler.handle(mockContext); + + // Assert + verify(mockVertx).setTimer(anyLong(), any()); + verify(mockVertx).cancelTimer(1L); + } +} diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/AbstractJsonRpcHttpServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/AbstractJsonRpcHttpServiceTest.java index d504e3bb0d..db896a9485 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/AbstractJsonRpcHttpServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/AbstractJsonRpcHttpServiceTest.java @@ -35,7 +35,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguratio import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.core.Transaction; @@ -137,7 +137,7 @@ public abstract class AbstractJsonRpcHttpServiceTest { final Synchronizer synchronizerMock = mock(Synchronizer.class); final P2PNetwork peerDiscoveryMock = mock(P2PNetwork.class); final TransactionPool transactionPoolMock = mock(TransactionPool.class); - final MiningParameters miningParameters = mock(MiningParameters.class); + final MiningConfiguration miningConfiguration = mock(MiningConfiguration.class); final PoWMiningCoordinator miningCoordinatorMock = mock(PoWMiningCoordinator.class); when(transactionPoolMock.addTransactionViaApi(any(Transaction.class))) .thenReturn(ValidationResult.valid()); @@ -151,7 +151,7 @@ public abstract class AbstractJsonRpcHttpServiceTest { blockchainSetupUtil.getProtocolSchedule(), blockchainSetupUtil.getBlockchain(), blockchainSetupUtil.getWorldArchive(), - miningParameters); + miningConfiguration); final FilterIdGenerator filterIdGenerator = mock(FilterIdGenerator.class); final FilterRepository filterRepository = new FilterRepository(); when(filterIdGenerator.nextId()).thenReturn("0x1"); @@ -183,7 +183,7 @@ public abstract class AbstractJsonRpcHttpServiceTest { protocolContext, filterManager, transactionPoolMock, - miningParameters, + miningConfiguration, miningCoordinatorMock, new NoOpMetricsSystem(), supportedCapabilities, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceHostAllowlistTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceHostAllowlistTest.java index 022aa24422..9113e15a12 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceHostAllowlistTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceHostAllowlistTest.java @@ -30,7 +30,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguratio import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -113,14 +113,14 @@ public class JsonRpcHttpServiceHostAllowlistTest { synchronizer, MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID), - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()), mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), - mock(MiningParameters.class), + mock(MiningConfiguration.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java index f9dba0bc26..aacf115796 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java @@ -37,7 +37,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguratio import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -144,14 +144,14 @@ public class JsonRpcHttpServiceLoginTest { synchronizer, MainnetProtocolSchedule.fromConfig( genesisConfigOptions, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()), mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), - mock(MiningParameters.class), + mock(MiningConfiguration.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, 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 63ae1b8bfb..ae66f2ac76 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 @@ -36,7 +36,7 @@ import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; import org.hyperledger.besu.ethereum.core.Synchronizer; @@ -217,7 +217,7 @@ public class JsonRpcHttpServiceRpcApisTest { mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), - mock(MiningParameters.class), + mock(MiningConfiguration.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, @@ -328,7 +328,7 @@ public class JsonRpcHttpServiceRpcApisTest { mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), - mock(MiningParameters.class), + mock(MiningConfiguration.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTestBase.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTestBase.java index 5a439fa194..ec4f6c6e2b 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTestBase.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTestBase.java @@ -30,7 +30,7 @@ import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.ChainHead; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -122,14 +122,14 @@ public class JsonRpcHttpServiceTestBase { MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID), EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()), mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), - mock(MiningParameters.class), + mock(MiningConfiguration.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsClientAuthTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsClientAuthTest.java index 28474d3c53..fa336169b9 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsClientAuthTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsClientAuthTest.java @@ -37,7 +37,7 @@ import org.hyperledger.besu.ethereum.api.tls.SelfSignedP12Certificate; import org.hyperledger.besu.ethereum.api.tls.TlsConfiguration; import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -127,14 +127,14 @@ public class JsonRpcHttpServiceTlsClientAuthTest { synchronizer, MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID), - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()), mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), - mock(MiningParameters.class), + mock(MiningConfiguration.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsMisconfigurationTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsMisconfigurationTest.java index 15df60230b..b675430c49 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsMisconfigurationTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsMisconfigurationTest.java @@ -36,7 +36,7 @@ import org.hyperledger.besu.ethereum.api.tls.SelfSignedP12Certificate; import org.hyperledger.besu.ethereum.api.tls.TlsConfiguration; import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -115,14 +115,14 @@ class JsonRpcHttpServiceTlsMisconfigurationTest { synchronizer, MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID), - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()), mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), - mock(MiningParameters.class), + mock(MiningConfiguration.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsTest.java index 6f7ce4e1d6..de5683ad5c 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsTest.java @@ -36,7 +36,7 @@ import org.hyperledger.besu.ethereum.api.tls.SelfSignedP12Certificate; import org.hyperledger.besu.ethereum.api.tls.TlsConfiguration; import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -116,14 +116,14 @@ public class JsonRpcHttpServiceTlsTest { synchronizer, MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID), - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()), mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), - mock(MiningParameters.class), + mock(MiningConfiguration.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHeadTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHeadTest.java new file mode 100644 index 0000000000..8d552ee376 --- /dev/null +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHeadTest.java @@ -0,0 +1,198 @@ +/* + * Copyright contributors to Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods; + +import static java.lang.Boolean.FALSE; +import static java.lang.Boolean.TRUE; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +import org.hyperledger.besu.crypto.Hash; +import org.hyperledger.besu.ethereum.ProtocolContext; +import org.hyperledger.besu.ethereum.api.jsonrpc.AbstractJsonRpcHttpServiceTest; +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.parameters.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; +import org.hyperledger.besu.ethereum.chain.Blockchain; +import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; +import org.hyperledger.besu.plugin.services.rpc.RpcResponseType; + +import java.util.Optional; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.apache.tuweni.bytes.Bytes; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +/** + * This test only exercises bonsai worldstate since forest is essentially a no-op for moving the + * worldstate. + */ +public class DebugSetHeadTest extends AbstractJsonRpcHttpServiceTest { + + DebugSetHead debugSetHead; + Blockchain blockchain; + WorldStateArchive archive; + ProtocolContext protocolContext; + ProtocolSchedule protocolSchedule; + + @Override + @BeforeEach + public void setup() throws Exception { + setupBonsaiBlockchain(); + blockchain = blockchainSetupUtil.getBlockchain(); + protocolContext = blockchainSetupUtil.getProtocolContext(); + protocolSchedule = blockchainSetupUtil.getProtocolSchedule(); + ; + archive = blockchainSetupUtil.getWorldArchive(); + debugSetHead = + new DebugSetHead( + new BlockchainQueries( + protocolSchedule, blockchain, archive, MiningConfiguration.MINING_DISABLED), + protocolContext, + // a value of 2 here exercises all the state rolling code paths + 2); + startService(); + } + + @ParameterizedTest + @ValueSource( + strings = {"0x01", "0x4e9a67b663f9abe03e7e9fd5452c9497998337077122f44ee78a466f6a7358de"}) + public void assertOnlyChainHeadMovesWorldParameterAbsent(final String blockParam) { + var chainTip = blockchain.getChainHead().getBlockHeader(); + var blockOne = getBlockHeaderForHashOrNumber(blockParam).orElse(null); + + assertThat(blockOne).isNotNull(); + assertThat(blockOne).isNotEqualTo(chainTip); + + // move the head to param val, number or hash + debugSetHead.response(debugSetHead(blockParam, Optional.empty())); + + // get the new chainTip: + var newChainTip = blockchain.getChainHead().getBlockHeader(); + + // assert the chain moved, and the worldstate did not + assertThat(newChainTip).isEqualTo(blockOne); + assertThat(archive.getMutable().rootHash()).isEqualTo(chainTip.getStateRoot()); + } + + @ParameterizedTest + @ValueSource( + strings = { + "0x01", + "0x02", + "0x3d813a0ffc9cd04436e17e3e9c309f1e80df0407078e50355ce0d570b5424812", + "0x4e9a67b663f9abe03e7e9fd5452c9497998337077122f44ee78a466f6a7358de" + }) + public void assertOnlyChainHeadMoves(final String blockParam) { + var chainTip = blockchain.getChainHead().getBlockHeader(); + var blockOne = getBlockHeaderForHashOrNumber(blockParam).orElse(null); + + assertThat(blockOne).isNotNull(); + assertThat(blockOne).isNotEqualTo(chainTip); + + // move the head to param val, number or hash + debugSetHead.response(debugSetHead(blockParam, Optional.of(FALSE))); + + // get the new chainTip: + var newChainTip = blockchain.getChainHead().getBlockHeader(); + + // assert the chain moved, and the worldstate did not + assertThat(newChainTip).isEqualTo(blockOne); + assertThat(archive.getMutable().rootHash()).isEqualTo(chainTip.getStateRoot()); + } + + @ParameterizedTest + @ValueSource( + strings = { + "0x01", + "0x02", + "0x3d813a0ffc9cd04436e17e3e9c309f1e80df0407078e50355ce0d570b5424812", + "0x4e9a67b663f9abe03e7e9fd5452c9497998337077122f44ee78a466f6a7358de" + }) + public void assertBothChainHeadAndWorldStatByNumber(final String blockParam) { + var chainTip = blockchain.getChainHead().getBlockHeader(); + var blockOne = getBlockHeaderForHashOrNumber(blockParam).orElse(null); + + assertThat(blockOne).isNotNull(); + assertThat(blockOne).isNotEqualTo(chainTip); + + // move the head and worldstate to param val number or hash + debugSetHead.response(debugSetHead(blockParam, Optional.of(TRUE))); + + // get the new chainTip: + var newChainTip = blockchain.getChainHead().getBlockHeader(); + + // assert both the chain and worldstate moved to block one + assertThat(newChainTip).isEqualTo(blockOne); + assertThat(archive.getMutable().rootHash()).isEqualTo(blockOne.getStateRoot()); + } + + @Test + public void assertNotFound() { + var chainTip = blockchain.getChainHead().getBlockHeader(); + + // move the head to number just after chain head + var resp = + debugSetHead.response(debugSetHead("" + chainTip.getNumber() + 1, Optional.of(TRUE))); + assertThat(resp.getType()).isEqualTo(RpcResponseType.ERROR); + + // move the head to some arbitrary hash + var resp2 = + debugSetHead.response( + debugSetHead( + Hash.keccak256(Bytes.fromHexString("0xdeadbeef")).toHexString(), + Optional.of(TRUE))); + assertThat(resp2.getType()).isEqualTo(RpcResponseType.ERROR); + + // get the new chainTip: + var newChainTip = blockchain.getChainHead().getBlockHeader(); + + // assert neither the chain nor the worldstate moved + assertThat(newChainTip).isEqualTo(chainTip); + assertThat(archive.getMutable().rootHash()).isEqualTo(chainTip.getStateRoot()); + } + + private JsonRpcRequestContext debugSetHead( + final String numberOrHash, final Optional moveWorldState) { + if (moveWorldState.isPresent()) { + return new JsonRpcRequestContext( + new JsonRpcRequest( + "2.0", "debug_setHead", new Object[] {numberOrHash, moveWorldState.get()})); + } else { + return new JsonRpcRequestContext( + new JsonRpcRequest("2.0", "debug_setHead", new Object[] {numberOrHash})); + } + } + + private Optional getBlockHeaderForHashOrNumber(final String input) { + try { + var param = new BlockParameterOrBlockHash(input); + if (param.getHash().isPresent()) { + return blockchain.getBlockHeader(param.getHash().get()); + } else if (param.getNumber().isPresent()) { + return blockchain.getBlockHeader(param.getNumber().getAsLong()); + } + } catch (JsonProcessingException ignored) { + // meh + } + return Optional.empty(); + } +} diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java index 8b8ff67cd8..7de6f65aae 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java @@ -27,6 +27,8 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; +import org.hyperledger.besu.datatypes.AccountOverride; +import org.hyperledger.besu.datatypes.AccountOverrideMap; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; @@ -92,6 +94,33 @@ public class EthCallTest { assertThat(method.getName()).isEqualTo("eth_call"); } + @Test + public void noAccountOverrides() { + final JsonRpcRequestContext request = ethCallRequest(callParameter(), "latest"); + Optional overrideMap = method.getAddressAccountOverrideMap(request); + assertThat(overrideMap.isPresent()).isFalse(); + } + + @Test + public void someAccountOverrides() { + AccountOverrideMap expectedOverrides = new AccountOverrideMap(); + AccountOverride override = new AccountOverride.Builder().withNonce(88L).build(); + final Address address = Address.fromHexString("0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3"); + expectedOverrides.put(address, override); + + final JsonRpcRequestContext request = + ethCallRequestWithStateOverrides(callParameter(), "latest", expectedOverrides); + + Optional maybeOverrideMap = method.getAddressAccountOverrideMap(request); + assertThat(maybeOverrideMap.isPresent()).isTrue(); + AccountOverrideMap overrideMap = maybeOverrideMap.get(); + assertThat(overrideMap.keySet()).hasSize(1); + assertThat(overrideMap.values()).hasSize(1); + + assertThat(overrideMap).containsKey(address); + assertThat(overrideMap).containsValue(override); + } + @Test public void shouldReturnInternalErrorWhenProcessorReturnsEmpty() { final JsonRpcRequestContext request = ethCallRequest(callParameter(), "latest"); @@ -99,7 +128,7 @@ public class EthCallTest { when(blockchainQueries.getBlockchain()).thenReturn(blockchain); when(blockchain.getChainHead()).thenReturn(chainHead); - when(transactionSimulator.process(any(), any(), any(), any(), any())) + when(transactionSimulator.process(any(), any(), any(), any(), any(), any())) .thenReturn(Optional.empty()); final BlockHeader blockHeader = mock(BlockHeader.class); @@ -109,7 +138,7 @@ public class EthCallTest { final JsonRpcResponse response = method.response(request); assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse); - verify(transactionSimulator).process(any(), any(), any(), any(), any()); + verify(transactionSimulator).process(any(), any(), any(), any(), any(), any()); } @Test @@ -130,12 +159,13 @@ public class EthCallTest { when(result.isSuccessful()).thenReturn(true); when(result.getValidationResult()).thenReturn(ValidationResult.valid()); when(result.getOutput()).thenReturn(Bytes.of()); - verify(transactionSimulator).process(any(), any(), any(), mapperCaptor.capture(), any()); + verify(transactionSimulator) + .process( + eq(callParameter), eq(Optional.empty()), any(), any(), mapperCaptor.capture(), any()); assertThat(mapperCaptor.getValue().apply(mock(MutableWorldState.class), Optional.of(result))) .isEqualTo(Optional.of(expectedResponse)); assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse); - verify(transactionSimulator).process(eq(callParameter), any(), any(), any(), any()); } @Test @@ -158,7 +188,8 @@ public class EthCallTest { when(result.getValidationResult()).thenReturn(ValidationResult.valid()); when(result.getOutput()).thenReturn(Bytes.of(1)); verify(transactionSimulator) - .process(eq(callParameter()), any(), any(), mapperCaptor.capture(), any()); + .process( + eq(callParameter()), eq(Optional.empty()), any(), any(), mapperCaptor.capture(), any()); assertThat(mapperCaptor.getValue().apply(mock(MutableWorldState.class), Optional.of(result))) .isEqualTo(Optional.of(expectedResponse)); @@ -196,7 +227,8 @@ public class EthCallTest { when(result.isSuccessful()).thenReturn(false); when(result.getValidationResult()).thenReturn(ValidationResult.valid()); when(result.result()).thenReturn(processingResult); - verify(transactionSimulator).process(any(), any(), any(), mapperCaptor.capture(), any()); + verify(transactionSimulator) + .process(any(), eq(Optional.empty()), any(), any(), mapperCaptor.capture(), any()); assertThat(mapperCaptor.getValue().apply(mock(MutableWorldState.class), Optional.of(result))) .isEqualTo(Optional.of(expectedResponse)); @@ -235,7 +267,8 @@ public class EthCallTest { when(result.isSuccessful()).thenReturn(false); when(result.getValidationResult()).thenReturn(ValidationResult.valid()); when(result.result()).thenReturn(processingResult); - verify(transactionSimulator).process(any(), any(), any(), mapperCaptor.capture(), any()); + verify(transactionSimulator) + .process(any(), eq(Optional.empty()), any(), any(), mapperCaptor.capture(), any()); assertThat(mapperCaptor.getValue().apply(mock(MutableWorldState.class), Optional.of(result))) .isEqualTo(Optional.of(expectedResponse)); @@ -277,7 +310,8 @@ public class EthCallTest { when(result.getValidationResult()).thenReturn(ValidationResult.valid()); when(result.result()).thenReturn(processingResult); - verify(transactionSimulator).process(any(), any(), any(), mapperCaptor.capture(), any()); + verify(transactionSimulator) + .process(any(), eq(Optional.empty()), any(), any(), mapperCaptor.capture(), any()); assertThat(mapperCaptor.getValue().apply(mock(MutableWorldState.class), Optional.of(result))) .isEqualTo(Optional.of(expectedResponse)); @@ -291,7 +325,7 @@ public class EthCallTest { final JsonRpcRequestContext request = ethCallRequest(callParameter(), "latest"); when(blockchainQueries.getBlockchain()).thenReturn(blockchain); when(blockchain.getChainHead()).thenReturn(chainHead); - when(transactionSimulator.process(any(), any(), any(), any(), any())) + when(transactionSimulator.process(any(), eq(Optional.empty()), any(), any(), any(), any())) .thenReturn(Optional.empty()); final BlockHeader blockHeader = mock(BlockHeader.class); @@ -301,21 +335,22 @@ public class EthCallTest { method.response(request); verify(blockchainQueries, atLeastOnce()).getBlockchain(); - verify(transactionSimulator).process(any(), any(), any(), any(), any()); + verify(transactionSimulator).process(any(), eq(Optional.empty()), any(), any(), any(), any()); } @Test public void shouldUseCorrectBlockNumberWhenEarliest() { final JsonRpcRequestContext request = ethCallRequest(callParameter(), "earliest"); when(blockchainQueries.getBlockHashByNumber(anyLong())).thenReturn(Optional.of(Hash.ZERO)); - when(transactionSimulator.process(any(), any(), any(), any(), any())) + when(transactionSimulator.process( + any(), any(), any(TransactionValidationParams.class), any(), any(BlockHeader.class))) .thenReturn(Optional.empty()); when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO)) .thenReturn(Optional.of(mock(BlockHeader.class))); method.response(request); verify(blockchainQueries).getBlockHeaderByHash(eq(Hash.ZERO)); - verify(transactionSimulator).process(any(), any(), any(), any(), any()); + verify(transactionSimulator).process(any(), eq(Optional.empty()), any(), any(), any(), any()); } @Test @@ -323,13 +358,13 @@ public class EthCallTest { final JsonRpcRequestContext request = ethCallRequest(callParameter(), "safe"); when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO)).thenReturn(Optional.of(blockHeader)); when(blockchainQueries.safeBlockHeader()).thenReturn(Optional.of(blockHeader)); - when(transactionSimulator.process(any(), any(), any(), any(), any())) + when(transactionSimulator.process(any(), eq(Optional.empty()), any(), any(), any(), any())) .thenReturn(Optional.empty()); method.response(request); verify(blockchainQueries).getBlockHeaderByHash(Hash.ZERO); verify(blockchainQueries).safeBlockHeader(); - verify(transactionSimulator).process(any(), any(), any(), any(), any()); + verify(transactionSimulator).process(any(), eq(Optional.empty()), any(), any(), any(), any()); } @Test @@ -337,13 +372,13 @@ public class EthCallTest { final JsonRpcRequestContext request = ethCallRequest(callParameter(), "finalized"); when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO)).thenReturn(Optional.of(blockHeader)); when(blockchainQueries.finalizedBlockHeader()).thenReturn(Optional.of(blockHeader)); - when(transactionSimulator.process(any(), any(), any(), any(), any())) + when(transactionSimulator.process(any(), eq(Optional.empty()), any(), any(), any(), any())) .thenReturn(Optional.empty()); method.response(request); verify(blockchainQueries).getBlockHeaderByHash(Hash.ZERO); verify(blockchainQueries).finalizedBlockHeader(); - verify(transactionSimulator).process(any(), any(), any(), any(), any()); + verify(transactionSimulator).process(any(), eq(Optional.empty()), any(), any(), any(), any()); } @Test @@ -353,13 +388,13 @@ public class EthCallTest { when(blockchainQueries.getBlockHashByNumber(anyLong())).thenReturn(Optional.of(Hash.ZERO)); when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO)) .thenReturn(Optional.of(mock(BlockHeader.class))); - when(transactionSimulator.process(any(), any(), any(), any(), any())) + when(transactionSimulator.process(any(), eq(Optional.empty()), any(), any(), any(), any())) .thenReturn(Optional.empty()); method.response(request); verify(blockchainQueries).getBlockHeaderByHash(eq(Hash.ZERO)); - verify(transactionSimulator).process(any(), any(), any(), any(), any()); + verify(transactionSimulator).process(any(), eq(Optional.empty()), any(), any(), any(), any()); } @Test @@ -431,7 +466,7 @@ public class EthCallTest { .build(); verify(transactionSimulator) - .process(any(), eq(transactionValidationParams), any(), any(), any()); + .process(any(), eq(Optional.empty()), eq(transactionValidationParams), any(), any(), any()); } private JsonCallParameter callParameter() { @@ -458,8 +493,17 @@ public class EthCallTest { new JsonRpcRequest("2.0", "eth_call", new Object[] {callParameter, blockNumberInHex})); } + private JsonRpcRequestContext ethCallRequestWithStateOverrides( + final CallParameter callParameter, + final String blockNumberInHex, + final AccountOverrideMap overrides) { + return new JsonRpcRequestContext( + new JsonRpcRequest( + "2.0", "eth_call", new Object[] {callParameter, blockNumberInHex, overrides})); + } + private void mockTransactionProcessorSuccessResult(final JsonRpcResponse jsonRpcResponse) { - when(transactionSimulator.process(any(), any(), any(), any(), any())) + when(transactionSimulator.process(any(), eq(Optional.empty()), any(), any(), any(), any())) .thenReturn(Optional.of(jsonRpcResponse)); } } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java index f85a0813ef..7c770f08a2 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java @@ -21,6 +21,8 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import org.hyperledger.besu.datatypes.AccountOverride; +import org.hyperledger.besu.datatypes.AccountOverrideMap; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; @@ -99,12 +101,44 @@ public class EthEstimateGasTest { assertThat(method.getName()).isEqualTo("eth_estimateGas"); } + @Test + public void noAccountOverrides() { + final Wei gasPrice = Wei.of(1000); + final JsonRpcRequestContext request = + ethEstimateGasRequest(defaultLegacyTransactionCallParameter(gasPrice), "latest"); + Optional overrideMap = method.getAddressAccountOverrideMap(request); + assertThat(overrideMap.isPresent()).isFalse(); + } + + @Test + public void someAccountOverrides() { + AccountOverrideMap expectedOverrides = new AccountOverrideMap(); + AccountOverride override = new AccountOverride.Builder().withNonce(88L).build(); + final Address address = Address.fromHexString("0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3"); + expectedOverrides.put(address, override); + + final Wei gasPrice = Wei.of(1000); + final JsonRpcRequestContext request = + ethEstimateGasRequestWithStateOverrides( + defaultLegacyTransactionCallParameter(gasPrice), "latest", expectedOverrides); + + Optional maybeOverrideMap = method.getAddressAccountOverrideMap(request); + assertThat(maybeOverrideMap.isPresent()).isTrue(); + AccountOverrideMap overrideMap = maybeOverrideMap.get(); + assertThat(overrideMap.keySet()).hasSize(1); + assertThat(overrideMap.values()).hasSize(1); + + assertThat(overrideMap).containsKey(address); + assertThat(overrideMap).containsValue(override); + } + @Test public void shouldReturnErrorWhenTransientLegacyTransactionProcessorReturnsEmpty() { final JsonRpcRequestContext request = ethEstimateGasRequest(defaultLegacyTransactionCallParameter(Wei.ZERO)); when(transactionSimulator.process( eq(modifiedLegacyTransactionCallParameter(Wei.ZERO)), + eq(Optional.empty()), // no account overrides any(TransactionValidationParams.class), any(OperationTracer.class), eq(latestBlockHeader))) @@ -341,6 +375,7 @@ public class EthEstimateGasTest { verify(transactionSimulator) .process( eq(modifiedLegacyTransactionCallParameter(Wei.ZERO)), + eq(Optional.empty()), // no account overrides eq( ImmutableTransactionValidationParams.builder() .from(TransactionValidationParams.transactionSimulator()) @@ -361,6 +396,7 @@ public class EthEstimateGasTest { verify(transactionSimulator) .process( eq(modifiedLegacyTransactionCallParameter(Wei.ZERO)), + eq(Optional.empty()), // no account overrides eq( ImmutableTransactionValidationParams.builder() .from(TransactionValidationParams.transactionSimulator()) @@ -461,12 +497,14 @@ public class EthEstimateGasTest { final TransactionSimulatorResult mockTxSimResult = mock(TransactionSimulatorResult.class); when(transactionSimulator.process( eq(modifiedLegacyTransactionCallParameter(gasPrice)), + eq(Optional.empty()), // no account overrides any(TransactionValidationParams.class), any(OperationTracer.class), eq(blockHeader))) .thenReturn(Optional.of(mockTxSimResult)); when(transactionSimulator.process( eq(modifiedEip1559TransactionCallParameter()), + eq(Optional.empty()), // no account overrides any(TransactionValidationParams.class), any(OperationTracer.class), eq(blockHeader))) @@ -551,4 +589,13 @@ public class EthEstimateGasTest { return new JsonRpcRequestContext( new JsonRpcRequest("2.0", "eth_estimateGas", new Object[] {callParameter, blockParam})); } + + private JsonRpcRequestContext ethEstimateGasRequestWithStateOverrides( + final CallParameter callParameter, + final String blockParam, + final AccountOverrideMap overrides) { + return new JsonRpcRequestContext( + new JsonRpcRequest( + "2.0", "eth_estimateGas", new Object[] {callParameter, blockParam, overrides})); + } } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPriceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPriceTest.java index a6c0959cef..06930bbd79 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPriceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPriceTest.java @@ -39,7 +39,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; @@ -77,13 +77,13 @@ public class EthGasPriceTest { @Mock private ProtocolSchedule protocolSchedule; @Mock private Blockchain blockchain; private EthGasPrice method; - private MiningParameters miningParameters; + private MiningConfiguration miningConfiguration; @BeforeEach public void setUp() { ApiConfiguration apiConfig = createDefaultApiConfiguration(); - miningParameters = - MiningParameters.newDefault().setMinTransactionGasPrice(DEFAULT_MIN_GAS_PRICE); + miningConfiguration = + MiningConfiguration.newDefault().setMinTransactionGasPrice(DEFAULT_MIN_GAS_PRICE); method = createEthGasPriceMethod(apiConfig); } @@ -96,7 +96,7 @@ public class EthGasPriceTest { public void shouldReturnMinValueWhenNoTransactionsExist() { final JsonRpcRequestContext request = requestWithParams(); final String expectedWei = "0x4d2"; // minGasPrice > nextBlockBaseFee - miningParameters.setMinTransactionGasPrice(Wei.fromHexString(expectedWei)); + miningConfiguration.setMinTransactionGasPrice(Wei.fromHexString(expectedWei)); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), expectedWei); @@ -117,7 +117,7 @@ public class EthGasPriceTest { final JsonRpcRequestContext request = requestWithParams(); final String expectedWei = DEFAULT_BASE_FEE.toShortHexString(); // nextBlockBaseFee > minGasPrice - miningParameters.setMinTransactionGasPrice(Wei.fromHexString(expectedWei)); + miningConfiguration.setMinTransactionGasPrice(Wei.fromHexString(expectedWei)); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), expectedWei); @@ -234,7 +234,7 @@ public class EthGasPriceTest { @MethodSource("ethGasPriceAtGenesis") public void ethGasPriceAtGenesis( final Wei minGasPrice, final Optional maybeGenesisBaseFee, final Wei expectedGasPrice) { - miningParameters.setMinTransactionGasPrice(minGasPrice); + miningConfiguration.setMinTransactionGasPrice(minGasPrice); if (maybeGenesisBaseFee.isPresent()) { mockBaseFeeMarket(); @@ -267,7 +267,7 @@ public class EthGasPriceTest { final Long lowerBoundCoefficient, final Long upperBoundCoefficient, final long expectedGasPrice) { - miningParameters.setMinTransactionGasPrice(Wei.of(100)); + miningConfiguration.setMinTransactionGasPrice(Wei.of(100)); mockBaseFeeMarket(); @@ -424,7 +424,7 @@ public class EthGasPriceTest { Optional.empty(), Optional.empty(), apiConfig, - miningParameters), + miningConfiguration), apiConfig); } } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java index 254d0fbe9e..fd92b55ba4 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java @@ -35,7 +35,7 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -93,7 +93,7 @@ public class EthGetBlockByNumberTest { blockchainQueries = spy( new BlockchainQueries( - protocolSchedule, blockchain, worldStateArchive, MiningParameters.newDefault())); + protocolSchedule, blockchain, worldStateArchive, MiningConfiguration.newDefault())); method = new EthGetBlockByNumber(blockchainQueries, blockResult, synchronizer); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceiptsTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceiptsTest.java index 545b43a6e7..f25407c86e 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceiptsTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceiptsTest.java @@ -35,7 +35,7 @@ import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -86,7 +86,7 @@ public class EthGetBlockReceiptsTest { blockchainQueries = spy( new BlockchainQueries( - protocolSchedule, blockchain, worldStateArchive, MiningParameters.newDefault())); + protocolSchedule, blockchain, worldStateArchive, MiningConfiguration.newDefault())); protocolSchedule = mock(ProtocolSchedule.class); method = new EthGetBlockReceipts(blockchainQueries, protocolSchedule); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java index 06a4b9d0e7..69af2b85ac 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java @@ -39,10 +39,10 @@ import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.ChainHead; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.proof.WorldStateProof; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import java.util.Collections; @@ -89,7 +89,7 @@ class EthGetProofTest { blockchainQueries = spy( new BlockchainQueries( - protocolSchedule, blockchain, archive, MiningParameters.newDefault())); + protocolSchedule, blockchain, archive, MiningConfiguration.newDefault())); when(blockchainQueries.getBlockchain()).thenReturn(blockchain); when(blockchainQueries.headBlockNumber()).thenReturn(14L); when(blockchain.getChainHead()).thenReturn(chainHead); @@ -202,7 +202,7 @@ class EthGetProofTest { when(blockchainQueries.getWorldStateArchive()).thenReturn(archive); - final StateTrieAccountValue stateTrieAccountValue = mock(StateTrieAccountValue.class); + final PmtStateTrieAccountValue stateTrieAccountValue = mock(PmtStateTrieAccountValue.class); when(stateTrieAccountValue.getBalance()).thenReturn(balance); when(stateTrieAccountValue.getCodeHash()).thenReturn(codeHash); when(stateTrieAccountValue.getNonce()).thenReturn(nonce); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java index c747ffb5d0..fde54f86d5 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java @@ -42,7 +42,7 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.mainnet.ExecutionWitnessValidator; @@ -198,7 +198,7 @@ public class EthGetTransactionReceiptTest { protocolSchedule, blockchain, mock(WorldStateArchive.class), - MiningParameters.newDefault())); + MiningConfiguration.newDefault())); private final EthGetTransactionReceipt ethGetTransactionReceipt = new EthGetTransactionReceipt(blockchainQueries, protocolSchedule); private final String receiptString = diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthMaxPriorityFeePerGasTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthMaxPriorityFeePerGasTest.java index 20bdef13fe..6452e22011 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthMaxPriorityFeePerGasTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthMaxPriorityFeePerGasTest.java @@ -35,7 +35,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.feemarket.CancunFeeMarket; @@ -67,12 +67,12 @@ public class EthMaxPriorityFeePerGasTest { private EthMaxPriorityFeePerGas method; @Mock private ProtocolSchedule protocolSchedule; @Mock private Blockchain blockchain; - private MiningParameters miningParameters; + private MiningConfiguration miningConfiguration; @BeforeEach public void setUp() { - miningParameters = - MiningParameters.newDefault().setMinPriorityFeePerGas(DEFAULT_MIN_PRIORITY_FEE_PER_GAS); + miningConfiguration = + MiningConfiguration.newDefault().setMinPriorityFeePerGas(DEFAULT_MIN_PRIORITY_FEE_PER_GAS); method = createEthMaxPriorityFeePerGasMethod(); } @@ -85,7 +85,7 @@ public class EthMaxPriorityFeePerGasTest { public void whenNoTransactionsExistReturnMinPriorityFeePerGasPrice() { final JsonRpcRequestContext request = requestWithParams(); final Wei expectedWei = Wei.ONE; - miningParameters.setMinPriorityFeePerGas(expectedWei); + miningConfiguration.setMinPriorityFeePerGas(expectedWei); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), expectedWei.toShortHexString()); @@ -111,7 +111,7 @@ public class EthMaxPriorityFeePerGasTest { public void returnMinPriorityFeePerGasWhenMedianValueIsLower() { final JsonRpcRequestContext request = requestWithParams(); final Wei expectedWei = Wei.of(100_000); - miningParameters.setMinPriorityFeePerGas(expectedWei); + miningConfiguration.setMinPriorityFeePerGas(expectedWei); mockBlockchain(100, 1); @@ -128,7 +128,7 @@ public class EthMaxPriorityFeePerGasTest { public void atGenesisReturnMinPriorityFeePerGas() { final JsonRpcRequestContext request = requestWithParams(); final Wei expectedWei = Wei.ONE; - miningParameters.setMinPriorityFeePerGas(expectedWei); + miningConfiguration.setMinPriorityFeePerGas(expectedWei); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), expectedWei.toShortHexString()); @@ -236,6 +236,6 @@ public class EthMaxPriorityFeePerGasTest { Optional.empty(), Optional.empty(), ImmutableApiConfiguration.builder().build(), - miningParameters)); + miningConfiguration)); } } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilterTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilterTest.java index c5c03f6b11..8f64d2cb0b 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilterTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilterTest.java @@ -26,6 +26,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcRespon import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import java.util.function.Supplier; @@ -69,7 +70,8 @@ public class TraceFilterTest { new JsonRpcRequest("2.0", "trace_filter", new Object[] {filterParameter})); method = - new TraceFilter(blockTracerSupplier, protocolSchedule, blockchainQueries, maxFilterRange); + new TraceFilter( + protocolSchedule, blockchainQueries, maxFilterRange, new NoOpMetricsSystem()); final JsonRpcResponse response = method.response(request); assertThat(response).isInstanceOf(JsonRpcErrorResponse.class); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayloadTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayloadTest.java index d4980263d4..616f514521 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayloadTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayloadTest.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.ACCEPTED; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.INVALID; @@ -52,7 +53,6 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.Request; import org.hyperledger.besu.ethereum.core.Withdrawal; import org.hyperledger.besu.ethereum.eth.manager.EthPeers; import org.hyperledger.besu.ethereum.mainnet.BodyValidation; @@ -63,7 +63,6 @@ import org.hyperledger.besu.ethereum.trie.MerkleTrieException; import org.hyperledger.besu.plugin.services.exception.StorageException; import org.hyperledger.besu.plugin.services.rpc.RpcResponseType; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; @@ -124,12 +123,11 @@ public abstract class AbstractEngineNewPayloadTest extends AbstractScheduledApiT BlockHeader mockHeader = setupValidPayload( new BlockProcessingResult(Optional.of(new BlockProcessingOutputs(null, List.of()))), - Optional.empty(), Optional.empty()); lenient() .when(blockchain.getBlockHeader(mockHeader.getParentHash())) .thenReturn(Optional.of(mock(BlockHeader.class))); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); assertValidResponse(mockHeader, resp); } @@ -137,12 +135,11 @@ public abstract class AbstractEngineNewPayloadTest extends AbstractScheduledApiT @Test public void shouldReturnInvalidOnBlockExecutionError() { BlockHeader mockHeader = - setupValidPayload( - new BlockProcessingResult("error 42"), Optional.empty(), Optional.empty()); + setupValidPayload(new BlockProcessingResult("error 42"), Optional.empty()); lenient() .when(blockchain.getBlockHeader(mockHeader.getParentHash())) .thenReturn(Optional.of(mock(BlockHeader.class))); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); EnginePayloadStatusResult res = fromSuccessResp(resp); assertThat(res.getLatestValidHash().get()).isEqualTo(mockHash); @@ -153,14 +150,14 @@ public abstract class AbstractEngineNewPayloadTest extends AbstractScheduledApiT @Test public void shouldReturnAcceptedOnLatestValidAncestorEmpty() { - BlockHeader mockHeader = createBlockHeader(Optional.empty(), Optional.empty()); + BlockHeader mockHeader = createBlockHeader(Optional.empty()); when(blockchain.getBlockByHash(mockHeader.getHash())).thenReturn(Optional.empty()); when(blockchain.getBlockHeader(mockHeader.getParentHash())) .thenReturn(Optional.of(mock(BlockHeader.class))); when(mergeCoordinator.getLatestValidAncestor(any(BlockHeader.class))) .thenReturn(Optional.empty()); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); EnginePayloadStatusResult res = fromSuccessResp(resp); assertThat(res.getLatestValidHash()).isEmpty(); @@ -171,20 +168,19 @@ public abstract class AbstractEngineNewPayloadTest extends AbstractScheduledApiT @Test public void shouldReturnSuccessOnAlreadyPresent() { - BlockHeader mockHeader = createBlockHeader(Optional.empty(), Optional.empty()); - Block mockBlock = - new Block(mockHeader, new BlockBody(Collections.emptyList(), Collections.emptyList())); + BlockHeader mockHeader = createBlockHeader(Optional.empty()); + Block mockBlock = new Block(mockHeader, new BlockBody(emptyList(), emptyList())); when(blockchain.getBlockByHash(any())).thenReturn(Optional.of(mockBlock)); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); assertValidResponse(mockHeader, resp); } @Test public void shouldReturnInvalidWithLatestValidHashIsABadBlock() { - BlockHeader mockHeader = createBlockHeader(Optional.empty(), Optional.empty()); + BlockHeader mockHeader = createBlockHeader(Optional.empty()); Hash latestValidHash = Hash.hash(Bytes32.fromHexStringLenient("0xcafebabe")); when(blockchain.getBlockByHash(mockHeader.getHash())).thenReturn(Optional.empty()); @@ -192,7 +188,7 @@ public abstract class AbstractEngineNewPayloadTest extends AbstractScheduledApiT when(mergeCoordinator.getLatestValidHashOfBadBlock(mockHeader.getHash())) .thenReturn(Optional.of(latestValidHash)); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); EnginePayloadStatusResult res = fromSuccessResp(resp); assertThat(res.getLatestValidHash()).isEqualTo(Optional.of(latestValidHash)); @@ -205,12 +201,11 @@ public abstract class AbstractEngineNewPayloadTest extends AbstractScheduledApiT BlockHeader mockHeader = setupValidPayload( new BlockProcessingResult(Optional.empty(), new StorageException("database bedlam")), - Optional.empty(), Optional.empty()); lenient() .when(blockchain.getBlockHeader(mockHeader.getParentHash())) .thenReturn(Optional.of(mock(BlockHeader.class))); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); fromErrorResp(resp); verify(engineCallListener, times(1)).executionEngineCalled(); @@ -221,13 +216,12 @@ public abstract class AbstractEngineNewPayloadTest extends AbstractScheduledApiT BlockHeader mockHeader = setupValidPayload( new BlockProcessingResult(Optional.empty(), new MerkleTrieException("missing leaf")), - Optional.empty(), Optional.empty()); lenient() .when(blockchain.getBlockHeader(mockHeader.getParentHash())) .thenReturn(Optional.of(mock(BlockHeader.class))); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); verify(engineCallListener, times(1)).executionEngineCalled(); @@ -236,7 +230,7 @@ public abstract class AbstractEngineNewPayloadTest extends AbstractScheduledApiT @Test public void shouldNotReturnInvalidOnThrownMerkleTrieException() { - BlockHeader mockHeader = createBlockHeader(Optional.empty(), Optional.empty()); + BlockHeader mockHeader = createBlockHeader(Optional.empty()); when(blockchain.getBlockByHash(mockHeader.getHash())).thenReturn(Optional.empty()); when(blockchain.getBlockHeader(mockHeader.getParentHash())) .thenReturn(Optional.of(mock(BlockHeader.class))); @@ -244,7 +238,7 @@ public abstract class AbstractEngineNewPayloadTest extends AbstractScheduledApiT .thenReturn(Optional.of(mockHash)); when(mergeCoordinator.rememberBlock(any())).thenThrow(new MerkleTrieException("missing leaf")); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); verify(engineCallListener, times(1)).executionEngineCalled(); @@ -253,7 +247,7 @@ public abstract class AbstractEngineNewPayloadTest extends AbstractScheduledApiT @Test public void shouldReturnInvalidBlockHashOnBadHashParameter() { - BlockHeader mockHeader = spy(createBlockHeader(Optional.empty(), Optional.empty())); + BlockHeader mockHeader = spy(createBlockHeader(Optional.empty())); lenient() .when(mergeCoordinator.getLatestValidAncestor(mockHeader.getBlockHash())) .thenReturn(Optional.empty()); @@ -261,7 +255,7 @@ public abstract class AbstractEngineNewPayloadTest extends AbstractScheduledApiT .when(blockchain.getBlockHeader(mockHeader.getParentHash())) .thenReturn(Optional.of(mock(BlockHeader.class))); lenient().when(mockHeader.getHash()).thenReturn(Hash.fromHexStringLenient("0x1337")); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); EnginePayloadStatusResult res = fromSuccessResp(resp); assertThat(res.getStatusAsString()).isEqualTo(getExpectedInvalidBlockHashStatus().name()); @@ -270,11 +264,11 @@ public abstract class AbstractEngineNewPayloadTest extends AbstractScheduledApiT @Test public void shouldCheckBlockValidityBeforeCheckingByHashForExisting() { - BlockHeader realHeader = createBlockHeader(Optional.empty(), Optional.empty()); + BlockHeader realHeader = createBlockHeader(Optional.empty()); BlockHeader paramHeader = spy(realHeader); when(paramHeader.getHash()).thenReturn(Hash.fromHexStringLenient("0x1337")); - var resp = resp(mockEnginePayload(paramHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(paramHeader, emptyList())); EnginePayloadStatusResult res = fromSuccessResp(resp); assertThat(res.getLatestValidHash()).isEmpty(); @@ -284,7 +278,7 @@ public abstract class AbstractEngineNewPayloadTest extends AbstractScheduledApiT @Test public void shouldReturnInvalidOnMalformedTransactions() { - BlockHeader mockHeader = createBlockHeader(Optional.empty(), Optional.empty()); + BlockHeader mockHeader = createBlockHeader(Optional.empty()); when(mergeCoordinator.getLatestValidAncestor(any(Hash.class))) .thenReturn(Optional.of(mockHash)); @@ -299,9 +293,9 @@ public abstract class AbstractEngineNewPayloadTest extends AbstractScheduledApiT @Test public void shouldRespondWithSyncingDuringForwardSync() { - BlockHeader mockHeader = createBlockHeader(Optional.empty(), Optional.empty()); + BlockHeader mockHeader = createBlockHeader(Optional.empty()); when(mergeContext.isSyncing()).thenReturn(Boolean.TRUE); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); EnginePayloadStatusResult res = fromSuccessResp(resp); assertThat(res.getError()).isNull(); @@ -312,10 +306,10 @@ public abstract class AbstractEngineNewPayloadTest extends AbstractScheduledApiT @Test public void shouldRespondWithSyncingDuringBackwardsSync() { - BlockHeader mockHeader = createBlockHeader(Optional.empty(), Optional.empty()); + BlockHeader mockHeader = createBlockHeader(Optional.empty()); when(mergeCoordinator.appendNewPayloadToSync(any())) .thenReturn(CompletableFuture.completedFuture(null)); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); EnginePayloadStatusResult res = fromSuccessResp(resp); assertThat(res.getLatestValidHash()).isEmpty(); @@ -326,12 +320,12 @@ public abstract class AbstractEngineNewPayloadTest extends AbstractScheduledApiT @Test public void shouldRespondWithInvalidIfExtraDataIsNull() { - BlockHeader realHeader = createBlockHeader(Optional.empty(), Optional.empty()); + BlockHeader realHeader = createBlockHeader(Optional.empty()); BlockHeader paramHeader = spy(realHeader); when(paramHeader.getHash()).thenReturn(Hash.fromHexStringLenient("0x1337")); when(paramHeader.getExtraData().toHexString()).thenReturn(null); - var resp = resp(mockEnginePayload(paramHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(paramHeader, emptyList())); EnginePayloadStatusResult res = fromSuccessResp(resp); assertThat(res.getLatestValidHash()).isEmpty(); @@ -343,8 +337,8 @@ public abstract class AbstractEngineNewPayloadTest extends AbstractScheduledApiT @Test public void shouldReturnInvalidWhenBadBlock() { when(mergeCoordinator.isBadBlock(any(Hash.class))).thenReturn(true); - BlockHeader mockHeader = createBlockHeader(Optional.empty(), Optional.empty()); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + BlockHeader mockHeader = createBlockHeader(Optional.empty()); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); when(protocolSpec.getWithdrawalsValidator()) .thenReturn(new WithdrawalsValidator.AllowedWithdrawals()); EnginePayloadStatusResult res = fromSuccessResp(resp); @@ -360,12 +354,11 @@ public abstract class AbstractEngineNewPayloadTest extends AbstractScheduledApiT BlockHeader mockHeader = setupValidPayload( new BlockProcessingResult(Optional.of(new BlockProcessingOutputs(null, List.of()))), - Optional.empty(), Optional.empty()); lenient() .when(blockchain.getBlockHeader(mockHeader.getParentHash())) .thenReturn(Optional.of(mock(BlockHeader.class))); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); assertValidResponse(mockHeader, resp); } @@ -411,11 +404,9 @@ public abstract class AbstractEngineNewPayloadTest extends AbstractScheduledApiT } protected BlockHeader setupValidPayload( - final BlockProcessingResult value, - final Optional> maybeWithdrawals, - final Optional> maybeRequests) { + final BlockProcessingResult value, final Optional> maybeWithdrawals) { - BlockHeader mockHeader = createBlockHeader(maybeWithdrawals, maybeRequests); + BlockHeader mockHeader = createBlockHeader(maybeWithdrawals); when(blockchain.getBlockByHash(mockHeader.getHash())).thenReturn(Optional.empty()); when(mergeCoordinator.getLatestValidAncestor(any(BlockHeader.class))) .thenReturn(Optional.of(mockHash)); @@ -428,6 +419,11 @@ public abstract class AbstractEngineNewPayloadTest extends AbstractScheduledApiT } protected EnginePayloadStatusResult fromSuccessResp(final JsonRpcResponse resp) { + if (resp.getType().equals(RpcResponseType.ERROR)) { + final JsonRpcError jsonRpcError = fromErrorResp(resp); + throw new AssertionError( + "Expected success but was error with message: " + jsonRpcError.getMessage()); + } assertThat(resp.getType()).isEqualTo(RpcResponseType.SUCCESS); return Optional.of(resp) .map(JsonRpcSuccessResponse.class::cast) @@ -444,15 +440,12 @@ public abstract class AbstractEngineNewPayloadTest extends AbstractScheduledApiT .get(); } - protected BlockHeader createBlockHeader( - final Optional> maybeWithdrawals, - final Optional> maybeRequests) { - return createBlockHeaderFixture(maybeWithdrawals, maybeRequests).buildHeader(); + protected BlockHeader createBlockHeader(final Optional> maybeWithdrawals) { + return createBlockHeaderFixture(maybeWithdrawals).buildHeader(); } protected BlockHeaderTestFixture createBlockHeaderFixture( - final Optional> maybeWithdrawals, - final Optional> maybeRequests) { + final Optional> maybeWithdrawals) { BlockHeader parentBlockHeader = new BlockHeaderTestFixture().baseFeePerGas(Wei.ONE).buildHeader(); return new BlockHeaderTestFixture() @@ -461,8 +454,7 @@ public abstract class AbstractEngineNewPayloadTest extends AbstractScheduledApiT .number(parentBlockHeader.getNumber() + 1) .timestamp(parentBlockHeader.getTimestamp() + 1) .withdrawalsRoot(maybeWithdrawals.map(BodyValidation::withdrawalsRoot).orElse(null)) - .parentBeaconBlockRoot(maybeParentBeaconBlockRoot) - .requestsHash(maybeRequests.map(BodyValidation::requestsHash).orElse(null)); + .parentBeaconBlockRoot(maybeParentBeaconBlockRoot); } protected void assertValidResponse(final BlockHeader mockHeader, final JsonRpcResponse resp) { diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2Test.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2Test.java index 76f7c7dfae..899e2c9872 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2Test.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2Test.java @@ -82,8 +82,7 @@ public class EngineNewPayloadV2Test extends AbstractEngineNewPayloadTest { BlockHeader mockHeader = setupValidPayload( new BlockProcessingResult(Optional.of(new BlockProcessingOutputs(null, List.of()))), - Optional.of(withdrawals), - Optional.empty()); + Optional.of(withdrawals)); lenient() .when(blockchain.getBlockHeader(mockHeader.getParentHash())) .thenReturn(Optional.of(mock(BlockHeader.class))); @@ -100,7 +99,6 @@ public class EngineNewPayloadV2Test extends AbstractEngineNewPayloadTest { BlockHeader mockHeader = setupValidPayload( new BlockProcessingResult(Optional.of(new BlockProcessingOutputs(null, List.of()))), - Optional.empty(), Optional.empty()); lenient() .when(blockchain.getBlockHeader(mockHeader.getParentHash())) @@ -121,7 +119,7 @@ public class EngineNewPayloadV2Test extends AbstractEngineNewPayloadTest { var resp = resp( mockEnginePayload( - createBlockHeader(Optional.of(Collections.emptyList()), Optional.empty()), + createBlockHeader(Optional.of(Collections.emptyList())), Collections.emptyList(), withdrawals, null)); @@ -135,14 +133,14 @@ public class EngineNewPayloadV2Test extends AbstractEngineNewPayloadTest { public void shouldValidateBlobGasUsedCorrectly() { // V2 should return error if non-null blobGasUsed BlockHeader blockHeader = - createBlockHeaderFixture(Optional.of(Collections.emptyList()), Optional.empty()) + createBlockHeaderFixture(Optional.of(Collections.emptyList())) .blobGasUsed(100L) .buildHeader(); var resp = resp(mockEnginePayload(blockHeader, Collections.emptyList(), List.of(), null)); final JsonRpcError jsonRpcError = fromErrorResp(resp); assertThat(jsonRpcError.getCode()).isEqualTo(INVALID_BLOB_GAS_USED_PARAMS.getCode()); - assertThat(jsonRpcError.getData()).isEqualTo("Missing blob gas used field"); + assertThat(jsonRpcError.getData()).isEqualTo("Unexpected blob gas used field present"); verify(engineCallListener, times(1)).executionEngineCalled(); } @@ -150,7 +148,7 @@ public class EngineNewPayloadV2Test extends AbstractEngineNewPayloadTest { public void shouldValidateExcessBlobGasCorrectly() { // V2 should return error if non-null ExcessBlobGas BlockHeader blockHeader = - createBlockHeaderFixture(Optional.of(Collections.emptyList()), Optional.empty()) + createBlockHeaderFixture(Optional.of(Collections.emptyList())) .excessBlobGas(BlobGas.MAX_BLOB_GAS) .buildHeader(); @@ -158,23 +156,17 @@ public class EngineNewPayloadV2Test extends AbstractEngineNewPayloadTest { final JsonRpcError jsonRpcError = fromErrorResp(resp); assertThat(jsonRpcError.getCode()).isEqualTo(INVALID_PARAMS.getCode()); - assertThat(jsonRpcError.getData()).isEqualTo("Missing excess blob gas field"); + assertThat(jsonRpcError.getData()).isEqualTo("Unexpected excess blob gas field present"); verify(engineCallListener, times(1)).executionEngineCalled(); } @Test public void shouldReturnInvalidIfWithdrawalsIsNull_WhenWithdrawalsAllowed() { - final List withdrawals = null; when(protocolSpec.getWithdrawalsValidator()) .thenReturn(new WithdrawalsValidator.AllowedWithdrawals()); var resp = - resp( - mockEnginePayload( - createBlockHeader(Optional.empty(), Optional.empty()), - Collections.emptyList(), - withdrawals, - null)); + resp(mockEnginePayload(createBlockHeader(Optional.empty()), Collections.emptyList())); assertThat(fromErrorResp(resp).getCode()).isEqualTo(INVALID_PARAMS.getCode()); verify(engineCallListener, times(1)).executionEngineCalled(); @@ -185,7 +177,7 @@ public class EngineNewPayloadV2Test extends AbstractEngineNewPayloadTest { // Cancun starte at timestamp 30 final long blockTimestamp = 31L; BlockHeader blockHeader = - createBlockHeaderFixture(Optional.of(Collections.emptyList()), Optional.empty()) + createBlockHeaderFixture(Optional.of(Collections.emptyList())) .timestamp(blockTimestamp) .buildHeader(); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3Test.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3Test.java index 7ac4772ef9..241596f188 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3Test.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3Test.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.INVALID; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType.INVALID_PARAMS; @@ -44,7 +45,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EnginePayloadS import org.hyperledger.besu.ethereum.core.BlobTestFixture; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.Request; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; import org.hyperledger.besu.ethereum.core.Withdrawal; @@ -56,7 +56,6 @@ import org.hyperledger.besu.ethereum.mainnet.ValidationResult; import org.hyperledger.besu.evm.gascalculator.CancunGasCalculator; import java.math.BigInteger; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.function.Supplier; @@ -112,8 +111,18 @@ public class EngineNewPayloadV3Test extends EngineNewPayloadV2Test { when(payload.getExcessBlobGas()).thenReturn("99"); when(payload.getBlobGasUsed()).thenReturn(9l); + // TODO locking this as V3 otherwise this breaks the EngineNewPayloadV4Test subclass when method + // field is V4 + final EngineNewPayloadV3 methodV3 = + new EngineNewPayloadV3( + vertx, + protocolSchedule, + protocolContext, + mergeCoordinator, + ethPeers, + engineCallListener); final JsonRpcResponse badParam = - method.response( + methodV3.response( new JsonRpcRequestContext( new JsonRpcRequest( "2.0", @@ -133,24 +142,21 @@ public class EngineNewPayloadV3Test extends EngineNewPayloadV2Test { final BlockHeader mockHeader = setupValidPayload( new BlockProcessingResult(Optional.of(new BlockProcessingOutputs(null, List.of()))), - Optional.empty(), Optional.empty()); - final EnginePayloadParameter payload = - mockEnginePayload(mockHeader, Collections.emptyList(), null, null); + + final EnginePayloadParameter payload = mockEnginePayload(mockHeader, emptyList(), null, null); ValidationResult res = method.validateParameters( payload, Optional.of(List.of()), Optional.of("0x0000000000000000000000000000000000000000000000000000000000000000"), - Optional.empty()); + Optional.of(emptyList())); assertThat(res.isValid()).isTrue(); } @Override - protected BlockHeader createBlockHeader( - final Optional> maybeWithdrawals, - final Optional> maybeRequests) { + protected BlockHeader createBlockHeader(final Optional> maybeWithdrawals) { BlockHeader parentBlockHeader = new BlockHeaderTestFixture() .baseFeePerGas(Wei.ONE) @@ -186,12 +192,12 @@ public class EngineNewPayloadV3Test extends EngineNewPayloadV2Test { public void shouldValidateBlobGasUsedCorrectly() { // V3 must return error if null blobGasUsed BlockHeader blockHeader = - createBlockHeaderFixture(Optional.of(Collections.emptyList()), Optional.empty()) + createBlockHeaderFixture(Optional.of(emptyList())) .excessBlobGas(BlobGas.MAX_BLOB_GAS) .blobGasUsed(null) .buildHeader(); - var resp = resp(mockEnginePayload(blockHeader, Collections.emptyList(), List.of(), null)); + var resp = resp(mockEnginePayload(blockHeader, emptyList(), List.of(), null)); final JsonRpcError jsonRpcError = fromErrorResp(resp); assertThat(jsonRpcError.getCode()).isEqualTo(INVALID_PARAMS.getCode()); @@ -204,12 +210,12 @@ public class EngineNewPayloadV3Test extends EngineNewPayloadV2Test { public void shouldValidateExcessBlobGasCorrectly() { // V3 must return error if null excessBlobGas BlockHeader blockHeader = - createBlockHeaderFixture(Optional.of(Collections.emptyList()), Optional.empty()) + createBlockHeaderFixture(Optional.of(emptyList())) .excessBlobGas(null) .blobGasUsed(100L) .buildHeader(); - var resp = resp(mockEnginePayload(blockHeader, Collections.emptyList(), List.of(), null)); + var resp = resp(mockEnginePayload(blockHeader, emptyList(), List.of(), null)); final JsonRpcError jsonRpcError = fromErrorResp(resp); assertThat(jsonRpcError.getCode()).isEqualTo(INVALID_PARAMS.getCode()); @@ -229,7 +235,6 @@ public class EngineNewPayloadV3Test extends EngineNewPayloadV2Test { BlockHeader mockHeader = setupValidPayload( new BlockProcessingResult(Optional.of(new BlockProcessingOutputs(null, List.of()))), - Optional.empty(), Optional.empty()); var resp = resp(mockEnginePayload(mockHeader, transactions)); @@ -265,7 +270,7 @@ public class EngineNewPayloadV3Test extends EngineNewPayloadV2Test { protected JsonRpcResponse resp(final EnginePayloadParameter payload) { Object[] params = maybeParentBeaconBlockRoot - .map(bytes32 -> new Object[] {payload, Collections.emptyList(), bytes32.toHexString()}) + .map(bytes32 -> new Object[] {payload, emptyList(), bytes32.toHexString()}) .orElseGet(() -> new Object[] {payload}); return method.response( new JsonRpcRequestContext(new JsonRpcRequest("2.0", this.method.getName(), params))); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV4Test.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV4Test.java index 73bd1b8035..33f3e6ccd1 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV4Test.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV4Test.java @@ -14,8 +14,10 @@ */ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.ethereum.api.graphql.internal.response.GraphQLError.INVALID_PARAMS; +import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType.INVALID_EXECUTION_REQUESTS_PARAMS; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; @@ -42,7 +44,6 @@ import org.hyperledger.besu.ethereum.mainnet.requests.MainnetRequestsValidator; import org.hyperledger.besu.ethereum.mainnet.requests.ProhibitedRequestValidator; import org.hyperledger.besu.evm.gascalculator.PragueGasCalculator; -import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Optional; @@ -59,14 +60,19 @@ public class EngineNewPayloadV4Test extends EngineNewPayloadV3Test { public EngineNewPayloadV4Test() {} + private static final List VALID_REQUESTS = + List.of( + new Request(RequestType.DEPOSIT, Bytes.of(1)), + new Request(RequestType.WITHDRAWAL, Bytes.of(1)), + new Request(RequestType.CONSOLIDATION, Bytes.of(1))); + @BeforeEach @Override public void before() { super.before(); maybeParentBeaconBlockRoot = Optional.of(Bytes32.ZERO); - // TODO this should be using NewPayloadV4 this.method = - new EngineNewPayloadV3( + new EngineNewPayloadV4( vertx, protocolSchedule, protocolContext, @@ -75,94 +81,62 @@ public class EngineNewPayloadV4Test extends EngineNewPayloadV3Test { engineCallListener); lenient().when(protocolSchedule.hardforkFor(any())).thenReturn(Optional.of(pragueHardfork)); lenient().when(protocolSpec.getGasCalculator()).thenReturn(new PragueGasCalculator()); + mockAllowedRequestsValidator(); } @Override public void shouldReturnExpectedMethodName() { - assertThat(method.getName()).isEqualTo("engine_newPayloadV3"); - } - - @Test - public void shouldReturnValidIfRequestsIsNull_WhenRequestsProhibited() { - mockProhibitedRequestsValidator(); - - BlockHeader mockHeader = - setupValidPayload( - new BlockProcessingResult( - Optional.of(new BlockProcessingOutputs(null, List.of(), Optional.empty()))), - Optional.empty(), - Optional.empty()); - when(blockchain.getBlockHeader(mockHeader.getParentHash())) - .thenReturn(Optional.of(mock(BlockHeader.class))); - when(mergeCoordinator.getLatestValidAncestor(mockHeader)) - .thenReturn(Optional.of(mockHeader.getHash())); - - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); - - assertValidResponse(mockHeader, resp); + assertThat(method.getName()).isEqualTo("engine_newPayloadV4"); } @Test public void shouldReturnInvalidIfRequestsIsNull_WhenRequestsAllowed() { - mockAllowedRequestsValidator(); var resp = - resp( - mockEnginePayload( - createBlockHeader(Optional.empty(), Optional.empty()), Collections.emptyList())); + respWithInvalidRequests( + mockEnginePayload(createValidBlockHeaderForV4(Optional.empty()), emptyList())); assertThat(fromErrorResp(resp).getCode()).isEqualTo(INVALID_PARAMS.getCode()); + assertThat(fromErrorResp(resp).getMessage()) + .isEqualTo(INVALID_EXECUTION_REQUESTS_PARAMS.getMessage()); verify(engineCallListener, times(1)).executionEngineCalled(); } public void shouldReturnValidIfRequestsIsNotNull_WhenRequestsAllowed() { - final List requests = - List.of( - new Request(RequestType.DEPOSIT, Bytes.of(1)), - new Request(RequestType.WITHDRAWAL, Bytes.of(1)), - new Request(RequestType.CONSOLIDATION, Bytes.of(1))); - - mockAllowedRequestsValidator(); BlockHeader mockHeader = setupValidPayload( new BlockProcessingResult( - Optional.of(new BlockProcessingOutputs(null, List.of(), Optional.of(requests)))), - Optional.empty(), + Optional.of( + new BlockProcessingOutputs(null, List.of(), Optional.of(VALID_REQUESTS)))), Optional.empty()); when(blockchain.getBlockHeader(mockHeader.getParentHash())) .thenReturn(Optional.of(mock(BlockHeader.class))); when(mergeCoordinator.getLatestValidAncestor(mockHeader)) .thenReturn(Optional.of(mockHeader.getHash())); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList()), requests); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); assertValidResponse(mockHeader, resp); } @Test public void shouldReturnInvalidIfRequestsIsNotNull_WhenRequestsProhibited() { - final List requests = - List.of( - new Request(RequestType.DEPOSIT, Bytes.of(1)), - new Request(RequestType.WITHDRAWAL, Bytes.of(1)), - new Request(RequestType.CONSOLIDATION, Bytes.of(1))); - mockProhibitedRequestsValidator(); - var resp = - resp( - mockEnginePayload( - createBlockHeader(Optional.empty(), Optional.of(Collections.emptyList())), - Collections.emptyList()), - requests); + var resp = resp(mockEnginePayload(createValidBlockHeaderForV4(Optional.empty()), emptyList())); final JsonRpcError jsonRpcError = fromErrorResp(resp); assertThat(jsonRpcError.getCode()).isEqualTo(INVALID_PARAMS.getCode()); verify(engineCallListener, times(1)).executionEngineCalled(); } - @Override - protected BlockHeader createBlockHeader( - final Optional> maybeWithdrawals, - final Optional> maybeRequests) { + private BlockHeader createValidBlockHeaderForV4( + final Optional> maybeWithdrawals) { + return createBlockHeaderFixtureForV3(maybeWithdrawals) + .requestsHash(BodyValidation.requestsHash(VALID_REQUESTS)) + .buildHeader(); + } + + private BlockHeaderTestFixture createBlockHeaderFixtureForV3( + final Optional> maybeWithdrawals) { BlockHeader parentBlockHeader = new BlockHeaderTestFixture() .baseFeePerGas(Wei.ONE) @@ -171,48 +145,49 @@ public class EngineNewPayloadV4Test extends EngineNewPayloadV3Test { .blobGasUsed(0L) .buildHeader(); - BlockHeader mockHeader = - new BlockHeaderTestFixture() - .baseFeePerGas(Wei.ONE) - .parentHash(parentBlockHeader.getParentHash()) - .number(parentBlockHeader.getNumber() + 1) - .timestamp(parentBlockHeader.getTimestamp() + 1) - .withdrawalsRoot(maybeWithdrawals.map(BodyValidation::withdrawalsRoot).orElse(null)) - .excessBlobGas(BlobGas.ZERO) - .blobGasUsed(0L) - .requestsHash(maybeRequests.map(BodyValidation::requestsHash).orElse(null)) - .parentBeaconBlockRoot( - maybeParentBeaconBlockRoot.isPresent() ? maybeParentBeaconBlockRoot : null) - .buildHeader(); - return mockHeader; + return new BlockHeaderTestFixture() + .baseFeePerGas(Wei.ONE) + .parentHash(parentBlockHeader.getParentHash()) + .number(parentBlockHeader.getNumber() + 1) + .timestamp(parentBlockHeader.getTimestamp() + 1) + .withdrawalsRoot(maybeWithdrawals.map(BodyValidation::withdrawalsRoot).orElse(null)) + .excessBlobGas(BlobGas.ZERO) + .blobGasUsed(0L) + .parentBeaconBlockRoot( + maybeParentBeaconBlockRoot.isPresent() ? maybeParentBeaconBlockRoot : null); + } + + @Override + protected BlockHeader createBlockHeader(final Optional> maybeWithdrawals) { + return createValidBlockHeaderForV4(maybeWithdrawals); } @Override protected JsonRpcResponse resp(final EnginePayloadParameter payload) { + final List requestsWithoutRequestId = + VALID_REQUESTS.stream() + .sorted(Comparator.comparing(Request::getType)) + .map(r -> r.getData().toHexString()) + .toList(); Object[] params = maybeParentBeaconBlockRoot - .map(bytes32 -> new Object[] {payload, Collections.emptyList(), bytes32.toHexString()}) + .map( + bytes32 -> + new Object[] { + payload, emptyList(), bytes32.toHexString(), requestsWithoutRequestId + }) .orElseGet(() -> new Object[] {payload}); return method.response( new JsonRpcRequestContext(new JsonRpcRequest("2.0", this.method.getName(), params))); } - protected JsonRpcResponse resp( - final EnginePayloadParameter payload, final List requests) { - final List requestsWithoutRequestId = - requests.stream() - .sorted(Comparator.comparing(Request::getType)) - .map(r -> r.getData().toHexString()) - .toList(); + protected JsonRpcResponse respWithInvalidRequests(final EnginePayloadParameter payload) { Object[] params = maybeParentBeaconBlockRoot .map( bytes32 -> - new Object[] { - payload, - Collections.emptyList(), - bytes32.toHexString(), - requestsWithoutRequestId + new Object[] {payload, emptyList(), bytes32.toHexString() + // empty requests param is invalid }) .orElseGet(() -> new Object[] {payload}); return method.response( diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetExtraDataTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetExtraDataTest.java index ebaf817a47..882a071110 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetExtraDataTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetExtraDataTest.java @@ -20,8 +20,8 @@ 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.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Test; @@ -30,8 +30,8 @@ public class MinerGetExtraDataTest { @Test public void shouldReturnDefaultExtraData() { - final MiningParameters miningParameters = ImmutableMiningParameters.newDefault(); - final MinerGetExtraData method = new MinerGetExtraData(miningParameters); + final MiningConfiguration miningConfiguration = ImmutableMiningConfiguration.newDefault(); + final MinerGetExtraData method = new MinerGetExtraData(miningConfiguration); final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", method.getName(), new Object[] {})); @@ -43,12 +43,12 @@ public class MinerGetExtraDataTest { @Test public void shouldReturnSetAtRuntimeExtraData() { - final MiningParameters miningParameters = ImmutableMiningParameters.newDefault(); - final MinerGetExtraData method = new MinerGetExtraData(miningParameters); + final MiningConfiguration miningConfiguration = ImmutableMiningConfiguration.newDefault(); + final MinerGetExtraData method = new MinerGetExtraData(miningConfiguration); final var extraData = "0x123456"; final Bytes extraDataAtRuntime = Bytes.fromHexString(extraData); - miningParameters.setExtraData(extraDataAtRuntime); + miningConfiguration.setExtraData(extraDataAtRuntime); final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", method.getName(), new Object[] {})); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinGasPriceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinGasPriceTest.java index f73229f0e0..8e036d822d 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinGasPriceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinGasPriceTest.java @@ -22,8 +22,8 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; 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.api.jsonrpc.internal.results.Quantity; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.junit.jupiter.api.Test; @@ -31,15 +31,16 @@ public class MinerGetMinGasPriceTest { @Test public void shouldReturnDefaultMinGasPrice() { - final MiningParameters miningParameters = ImmutableMiningParameters.newDefault(); - final MinerGetMinGasPrice method = new MinerGetMinGasPrice(miningParameters); + final MiningConfiguration miningConfiguration = ImmutableMiningConfiguration.newDefault(); + final MinerGetMinGasPrice method = new MinerGetMinGasPrice(miningConfiguration); final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", method.getName(), new Object[] {})); final JsonRpcResponse expected = new JsonRpcSuccessResponse( request.getRequest().getId(), - Quantity.create(MiningParameters.MutableInitValues.DEFAULT_MIN_TRANSACTION_GAS_PRICE)); + Quantity.create( + MiningConfiguration.MutableInitValues.DEFAULT_MIN_TRANSACTION_GAS_PRICE)); final JsonRpcResponse actual = method.response(request); assertThat(actual).usingRecursiveComparison().isEqualTo(expected); @@ -47,12 +48,12 @@ public class MinerGetMinGasPriceTest { @Test public void shouldReturnSetAtRuntimeMinGasPrice() { - final MiningParameters miningParameters = ImmutableMiningParameters.newDefault(); - final MinerGetMinGasPrice method = new MinerGetMinGasPrice(miningParameters); + final MiningConfiguration miningConfiguration = ImmutableMiningConfiguration.newDefault(); + final MinerGetMinGasPrice method = new MinerGetMinGasPrice(miningConfiguration); final Wei minGasPriceAtRuntime = Wei.of(2000); - miningParameters.setMinTransactionGasPrice(minGasPriceAtRuntime); + miningConfiguration.setMinTransactionGasPrice(minGasPriceAtRuntime); final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", method.getName(), new Object[] {})); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinPriorityFeeTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinPriorityFeeTest.java index 78fb85b94b..07e3e5842f 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinPriorityFeeTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinPriorityFeeTest.java @@ -23,18 +23,18 @@ 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.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public class MinerGetMinPriorityFeeTest { - MiningParameters miningParameters = mock(MiningParameters.class); + MiningConfiguration miningConfiguration = mock(MiningConfiguration.class); private MinerGetMinPriorityFee method; @BeforeEach public void setUp() { - method = new MinerGetMinPriorityFee(miningParameters); + method = new MinerGetMinPriorityFee(miningConfiguration); } @Test @@ -44,7 +44,8 @@ public class MinerGetMinPriorityFeeTest { final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", method.getName(), new Object[] {})); - when(miningParameters.getMinPriorityFeePerGas()).thenReturn(Wei.fromHexString(minPriorityFee)); + when(miningConfiguration.getMinPriorityFeePerGas()) + .thenReturn(Wei.fromHexString(minPriorityFee)); final JsonRpcResponse expected = new JsonRpcSuccessResponse(request.getRequest().getId(), minPriorityFee); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetExtraDataTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetExtraDataTest.java index b3c7b45d07..e197964081 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetExtraDataTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetExtraDataTest.java @@ -23,7 +23,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorR 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.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import java.nio.charset.StandardCharsets; @@ -32,12 +32,12 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public class MinerSetExtraDataTest { - MiningParameters miningParameters = MiningParameters.newDefault(); + MiningConfiguration miningConfiguration = MiningConfiguration.newDefault(); private MinerSetExtraData method; @BeforeEach public void setUp() { - method = new MinerSetExtraData(miningParameters); + method = new MinerSetExtraData(miningConfiguration); } @Test @@ -49,7 +49,7 @@ public class MinerSetExtraDataTest { final JsonRpcResponse actual = method.response(request); assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - final var currExtraData = miningParameters.getExtraData(); + final var currExtraData = miningConfiguration.getExtraData(); assertThat(new String(currExtraData.toArray(), StandardCharsets.UTF_8)).isEqualTo(newExtraData); } @@ -67,7 +67,7 @@ public class MinerSetExtraDataTest { final JsonRpcResponse actual = method.response(request); assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - final var currExtraData = miningParameters.getExtraData(); + final var currExtraData = miningConfiguration.getExtraData(); assertThat(new String(currExtraData.toArray(), StandardCharsets.UTF_8)) .isEqualTo( new String( diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinGasPriceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinGasPriceTest.java index fb56b57307..860e1967d6 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinGasPriceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinGasPriceTest.java @@ -24,18 +24,18 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorR 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.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public class MinerSetMinGasPriceTest { - MiningParameters miningParameters = MiningParameters.newDefault(); + MiningConfiguration miningConfiguration = MiningConfiguration.newDefault(); private MinerSetMinGasPrice method; @BeforeEach public void setUp() { - method = new MinerSetMinGasPrice(miningParameters); + method = new MinerSetMinGasPrice(miningConfiguration); } @Test @@ -64,7 +64,7 @@ public class MinerSetMinGasPriceTest { final JsonRpcResponse actual = method.response(request); assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - assertThat(miningParameters.getMinTransactionGasPrice()) + assertThat(miningConfiguration.getMinTransactionGasPrice()) .isEqualTo(Wei.fromHexString(newMinGasPrice)); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinPriorityFeeTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinPriorityFeeTest.java index 7e564ac425..fb75788d4b 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinPriorityFeeTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinPriorityFeeTest.java @@ -24,18 +24,18 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorR 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.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public class MinerSetMinPriorityFeeTest { - MiningParameters miningParameters = MiningParameters.newDefault(); + MiningConfiguration miningConfiguration = MiningConfiguration.newDefault(); private MinerSetMinPriorityFee method; @BeforeEach public void setUp() { - method = new MinerSetMinPriorityFee(miningParameters); + method = new MinerSetMinPriorityFee(miningConfiguration); } @Test @@ -80,7 +80,7 @@ public class MinerSetMinPriorityFeeTest { final JsonRpcResponse expected = new JsonRpcSuccessResponse(request.getRequest().getId(), true); final JsonRpcResponse actual = method.response(request); assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - assertThat(miningParameters.getMinPriorityFeePerGas()) + assertThat(miningConfiguration.getMinPriorityFeePerGas()) .isEqualTo(Wei.fromHexString(newMinPriorityFee)); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketServiceLoginTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketServiceLoginTest.java index 47a16135ff..53785012d0 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketServiceLoginTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketServiceLoginTest.java @@ -44,7 +44,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.Subscrip import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -180,14 +180,14 @@ public class WebSocketServiceLoginTest { synchronizer, MainnetProtocolSchedule.fromConfig( genesisConfigOptions, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()), mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), - mock(MiningParameters.class), + mock(MiningConfiguration.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketServiceTLSTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketServiceTLSTest.java new file mode 100644 index 0000000000..9a227dc432 --- /dev/null +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketServiceTLSTest.java @@ -0,0 +1,444 @@ +/* + * Copyright contributors to Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.api.jsonrpc.websocket; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; + +import org.hyperledger.besu.ethereum.api.handlers.TimeoutOptions; +import org.hyperledger.besu.ethereum.api.jsonrpc.execution.BaseJsonRpcProcessor; +import org.hyperledger.besu.ethereum.api.jsonrpc.execution.JsonRpcExecutor; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.methods.WebSocketMethodsFactory; +import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.SubscriptionManager; +import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; +import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; + +import java.io.File; +import java.io.FileOutputStream; +import java.security.KeyStore; +import java.util.Base64; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import io.netty.handler.ssl.util.SelfSignedCertificate; +import io.vertx.core.Vertx; +import io.vertx.core.http.WebSocketClient; +import io.vertx.core.http.WebSocketClientOptions; +import io.vertx.core.net.JksOptions; +import io.vertx.core.net.PemTrustOptions; +import io.vertx.junit5.VertxExtension; +import io.vertx.junit5.VertxTestContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(VertxExtension.class) +public class WebSocketServiceTLSTest { + + private Vertx vertx; + private WebSocketConfiguration config; + private WebSocketMessageHandler webSocketMessageHandlerSpy; + + @BeforeEach + public void setUp() { + vertx = Vertx.vertx(); + config = WebSocketConfiguration.createDefault(); + Map websocketMethods; + config.setPort(0); // Use ephemeral port + config.setHost("localhost"); + websocketMethods = + new WebSocketMethodsFactory( + new SubscriptionManager(new NoOpMetricsSystem()), new HashMap<>()) + .methods(); + webSocketMessageHandlerSpy = + spy( + new WebSocketMessageHandler( + vertx, + new JsonRpcExecutor(new BaseJsonRpcProcessor(), websocketMethods), + mock(EthScheduler.class), + TimeoutOptions.defaultOptions().getTimeoutSeconds())); + } + + @Test + public void shouldAcceptSecureWebSocketConnection(final VertxTestContext testContext) + throws Throwable { + // Generate a self-signed certificate + SelfSignedCertificate ssc = new SelfSignedCertificate(); + + // Create a temporary keystore file + File keystoreFile = File.createTempFile("keystore", ".jks"); + keystoreFile.deleteOnExit(); + + // Create a PKCS12 keystore and load the self-signed certificate + KeyStore keyStore = KeyStore.getInstance("JKS"); + keyStore.load(null, null); + keyStore.setKeyEntry( + "alias", + ssc.key(), + "password".toCharArray(), + new java.security.cert.Certificate[] {ssc.cert()}); + + // Save the keystore to the temporary file + try (FileOutputStream fos = new FileOutputStream(keystoreFile)) { + keyStore.store(fos, "password".toCharArray()); + } + + // Configure WebSocket with SSL enabled + config.setSslEnabled(true); + config.setKeyStorePath(keystoreFile.getAbsolutePath()); + config.setKeyStorePassword("password"); + config.setKeyStoreType("JKS"); + + // Create and start WebSocketService + WebSocketService webSocketService = + new WebSocketService(vertx, config, webSocketMessageHandlerSpy, new NoOpMetricsSystem()); + webSocketService.start().join(); + + // Get the actual port + int port = webSocketService.socketAddress().getPort(); + + // Create a temporary truststore file + File truststoreFile = File.createTempFile("truststore", ".jks"); + truststoreFile.deleteOnExit(); + + // Create a PKCS12 truststore and load the server's certificate + KeyStore trustStore = KeyStore.getInstance("JKS"); + trustStore.load(null, null); + trustStore.setCertificateEntry("alias", ssc.cert()); + + // Save the truststore to the temporary file + try (FileOutputStream fos = new FileOutputStream(truststoreFile)) { + trustStore.store(fos, "password".toCharArray()); + } + + // Configure the HTTP client with the truststore + WebSocketClientOptions clientOptions = + new WebSocketClientOptions() + .setSsl(true) + .setTrustOptions( + new JksOptions().setPath(truststoreFile.getAbsolutePath()).setPassword("password")) + .setVerifyHost(true); + + WebSocketClient webSocketClient = vertx.createWebSocketClient(clientOptions); + webSocketClient + .connect(port, "localhost", "/") + .onSuccess( + ws -> { + assertThat(ws.isSsl()).isTrue(); + ws.close(); + testContext.completeNow(); + }) + .onFailure(testContext::failNow); + + assertThat(testContext.awaitCompletion(5, TimeUnit.SECONDS)).isTrue(); + if (testContext.failed()) { + throw testContext.causeOfFailure(); + } + + // Stop the WebSocketService after the test + webSocketService.stop().join(); + } + + @Test + public void shouldAcceptSecureWebSocketConnectionPEM(final VertxTestContext testContext) + throws Throwable { + // Generate a self-signed certificate + SelfSignedCertificate ssc = new SelfSignedCertificate(); + + // Create temporary PEM files for the certificate and key + File certFile = File.createTempFile("cert", ".pem"); + certFile.deleteOnExit(); + File keyFile = File.createTempFile("key", ".pem"); + keyFile.deleteOnExit(); + + // Write the certificate and key to the PEM files + try (FileOutputStream certOut = new FileOutputStream(certFile); + FileOutputStream keyOut = new FileOutputStream(keyFile)) { + certOut.write("-----BEGIN CERTIFICATE-----\n".getBytes(UTF_8)); + certOut.write( + Base64.getMimeEncoder(64, "\n".getBytes(UTF_8)).encode(ssc.cert().getEncoded())); + certOut.write("\n-----END CERTIFICATE-----\n".getBytes(UTF_8)); + + keyOut.write("-----BEGIN PRIVATE KEY-----\n".getBytes(UTF_8)); + keyOut.write(Base64.getMimeEncoder(64, "\n".getBytes(UTF_8)).encode(ssc.key().getEncoded())); + keyOut.write("\n-----END PRIVATE KEY-----\n".getBytes(UTF_8)); + } + + // Configure WebSocket with SSL enabled using PEM files + config.setSslEnabled(true); + config.setKeyPath(keyFile.getAbsolutePath()); + config.setCertPath(certFile.getAbsolutePath()); + config.setKeyStoreType("PEM"); + + // Create and start WebSocketService + WebSocketService webSocketService = + new WebSocketService(vertx, config, webSocketMessageHandlerSpy, new NoOpMetricsSystem()); + webSocketService.start().join(); + + // Get the actual port + int port = webSocketService.socketAddress().getPort(); + + // Create a temporary PEM file for the trust store + File trustCertFile = File.createTempFile("trust-cert", ".pem"); + trustCertFile.deleteOnExit(); + + // Write the server's certificate to the PEM file + try (FileOutputStream trustCertOut = new FileOutputStream(trustCertFile)) { + trustCertOut.write("-----BEGIN CERTIFICATE-----\n".getBytes(UTF_8)); + trustCertOut.write( + Base64.getMimeEncoder(64, "\n".getBytes(UTF_8)).encode(ssc.cert().getEncoded())); + trustCertOut.write("\n-----END CERTIFICATE-----\n".getBytes(UTF_8)); + } + + // Configure the HTTP client with the trust store using PEM files + WebSocketClientOptions clientOptions = + new WebSocketClientOptions() + .setSsl(true) + .setTrustOptions(new PemTrustOptions().addCertPath(trustCertFile.getAbsolutePath())) + .setVerifyHost(true); + + WebSocketClient webSocketClient = vertx.createWebSocketClient(clientOptions); + webSocketClient + .connect(port, "localhost", "/") + .onSuccess( + ws -> { + assertThat(ws.isSsl()).isTrue(); + ws.close(); + testContext.completeNow(); + }) + .onFailure(testContext::failNow); + + assertThat(testContext.awaitCompletion(5, TimeUnit.SECONDS)).isTrue(); + if (testContext.failed()) { + throw testContext.causeOfFailure(); + } + + // Stop the WebSocketService after the test + webSocketService.stop().join(); + } + + @Test + public void shouldFailConnectionWithWrongCertificateInTrustStore( + final VertxTestContext testContext) throws Throwable { + // Generate a self-signed certificate for the server + SelfSignedCertificate serverCert = new SelfSignedCertificate(); + + // Create a temporary keystore file for the server + File keystoreFile = File.createTempFile("keystore", ".p12"); + keystoreFile.deleteOnExit(); + + // Create a PKCS12 keystore and load the server's self-signed certificate + KeyStore keyStore = KeyStore.getInstance("PKCS12"); + keyStore.load(null, null); + keyStore.setKeyEntry( + "alias", + serverCert.key(), + "password".toCharArray(), + new java.security.cert.Certificate[] {serverCert.cert()}); + + // Save the keystore to the temporary file + try (FileOutputStream fos = new FileOutputStream(keystoreFile)) { + keyStore.store(fos, "password".toCharArray()); + } + + // Configure WebSocket with SSL enabled + config.setSslEnabled(true); + config.setKeyStorePath(keystoreFile.getAbsolutePath()); + config.setKeyStorePassword("password"); + config.setKeyStoreType("PKCS12"); + + // Create and start WebSocketService + WebSocketService webSocketService = + new WebSocketService(vertx, config, webSocketMessageHandlerSpy, new NoOpMetricsSystem()); + webSocketService.start().join(); + + // Get the actual port + int port = webSocketService.socketAddress().getPort(); + + // Generate a different self-signed certificate for the trust store + SelfSignedCertificate wrongCert = new SelfSignedCertificate(); + + // Create a temporary truststore file + File truststoreFile = File.createTempFile("truststore", ".p12"); + truststoreFile.deleteOnExit(); + + // Create a PKCS12 truststore and load the wrong certificate + KeyStore trustStore = KeyStore.getInstance("PKCS12"); + trustStore.load(null, null); + trustStore.setCertificateEntry("alias", wrongCert.cert()); + + // Save the truststore to the temporary file + try (FileOutputStream fos = new FileOutputStream(truststoreFile)) { + trustStore.store(fos, "password".toCharArray()); + } + + // Configure the HTTP client with the truststore containing the wrong certificate + WebSocketClientOptions clientOptions = + new WebSocketClientOptions() + .setSsl(true) + .setTrustOptions( + new JksOptions().setPath(truststoreFile.getAbsolutePath()).setPassword("password")) + .setVerifyHost(true); + + WebSocketClient webSocketClient = vertx.createWebSocketClient(clientOptions); + webSocketClient + .connect(port, "localhost", "/") + .onSuccess( + ws -> { + testContext.failNow(new AssertionError("Connection should have been rejected")); + }) + .onFailure( + throwable -> { + assertThat(throwable).isInstanceOf(Exception.class); + testContext.completeNow(); + }); + + assertThat(testContext.awaitCompletion(5, TimeUnit.SECONDS)).isTrue(); + if (testContext.failed()) { + throw testContext.causeOfFailure(); + } + + // Stop the WebSocketService after the test + webSocketService.stop().join(); + } + + @Test + public void shouldAuthenticateClient(final VertxTestContext testContext) throws Throwable { + // Generate a self-signed certificate for the server + SelfSignedCertificate serverCert = new SelfSignedCertificate(); + + // Generate a self-signed certificate for the client + SelfSignedCertificate clientCert = new SelfSignedCertificate(); + + // Create a temporary keystore file for the server + File serverKeystoreFile = File.createTempFile("keystore", ".p12"); + serverKeystoreFile.deleteOnExit(); + + // Create a temporary truststore file for the server + File serverTruststoreFile = File.createTempFile("truststore", ".p12"); + serverTruststoreFile.deleteOnExit(); + + // Create a temporary keystore file for the client + File clientKeystoreFile = File.createTempFile("client-keystore", ".p12"); + clientKeystoreFile.deleteOnExit(); + + // Create a temporary truststore file for the client + File clientTruststoreFile = File.createTempFile("truststore", ".p12"); + clientTruststoreFile.deleteOnExit(); + + // Create a PKCS12 keystore and load the server's self-signed certificate + KeyStore serverKeyStore = KeyStore.getInstance("PKCS12"); + serverKeyStore.load(null, null); + serverKeyStore.setKeyEntry( + "alias", + serverCert.key(), + "password".toCharArray(), + new java.security.cert.Certificate[] {serverCert.cert()}); + + // Save the keystore to the temporary file + try (FileOutputStream fos = new FileOutputStream(serverKeystoreFile)) { + serverKeyStore.store(fos, "password".toCharArray()); + } + + // Create a PKCS12 truststore and load the client's self-signed certificate + KeyStore serverTrustStore = KeyStore.getInstance("PKCS12"); + serverTrustStore.load(null, null); + serverTrustStore.setCertificateEntry("alias", clientCert.cert()); + + // Save the truststore to the temporary file + try (FileOutputStream fos = new FileOutputStream(serverTruststoreFile)) { + serverTrustStore.store(fos, "password".toCharArray()); + } + + // Create a PKCS12 keystore and load the client's self-signed certificate + KeyStore clientKeyStore = KeyStore.getInstance("PKCS12"); + clientKeyStore.load(null, null); + clientKeyStore.setKeyEntry( + "alias", + clientCert.key(), + "password".toCharArray(), + new java.security.cert.Certificate[] {clientCert.cert()}); + + // Save the client keystore to the temporary file + try (FileOutputStream fos = new FileOutputStream(clientKeystoreFile)) { + clientKeyStore.store(fos, "password".toCharArray()); + } + + // Create a PKCS12 truststore and load the server's self-signed certificate + KeyStore clientTrustStore = KeyStore.getInstance("PKCS12"); + clientTrustStore.load(null, null); + clientTrustStore.setCertificateEntry("alias", serverCert.cert()); + + // Save the truststore to the temporary file + try (FileOutputStream fos = new FileOutputStream(clientTruststoreFile)) { + clientTrustStore.store(fos, "password".toCharArray()); + } + + // Configure WebSocket with SSL and client authentication enabled + config.setSslEnabled(true); + config.setKeyStorePath(serverKeystoreFile.getAbsolutePath()); + config.setKeyStorePassword("password"); + config.setKeyStoreType("PKCS12"); + config.setClientAuthEnabled(true); + config.setTrustStorePath(serverTruststoreFile.getAbsolutePath()); + config.setTrustStorePassword("password"); + config.setTrustStoreType("PKCS12"); + + // Create and start WebSocketService + WebSocketService webSocketService = + new WebSocketService(vertx, config, webSocketMessageHandlerSpy, new NoOpMetricsSystem()); + webSocketService.start().join(); + + // Get the actual port + int port = webSocketService.socketAddress().getPort(); + + // Configure the HTTP client with the client certificate + WebSocketClientOptions clientOptions = + new WebSocketClientOptions() + .setSsl(true) + .setKeyStoreOptions( + new JksOptions() + .setPath(clientKeystoreFile.getAbsolutePath()) + .setPassword("password")) + .setTrustOptions( + new JksOptions() + .setPath(clientTruststoreFile.getAbsolutePath()) + .setPassword("password")) + .setVerifyHost(true); + + WebSocketClient webSocketClient = vertx.createWebSocketClient(clientOptions); + webSocketClient + .connect(port, "localhost", "/") + .onSuccess( + ws -> { + assertThat(ws.isSsl()).isTrue(); + ws.close(); + testContext.completeNow(); + }) + .onFailure(testContext::failNow); + + assertThat(testContext.awaitCompletion(5, TimeUnit.SECONDS)).isTrue(); + if (testContext.failed()) { + throw testContext.causeOfFailure(); + } + + // Stop the WebSocketService after the test + webSocketService.stop().join(); + } +} 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 8cb33fa714..aa69a239cc 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 @@ -32,7 +32,7 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockDataGenerator.BlockOptions; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -85,7 +85,7 @@ public class NewBlockHeadersSubscriptionServiceTest { protocolSchedule, blockchain, createInMemoryWorldStateArchive(), - MiningParameters.newDefault())); + MiningConfiguration.newDefault())); @BeforeEach public void before() { diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesLogCacheTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesLogCacheTest.java index 668d565db8..c91afb9fd8 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesLogCacheTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesLogCacheTest.java @@ -28,7 +28,7 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -137,7 +137,7 @@ public class BlockchainQueriesLogCacheTest { worldStateArchive, Optional.of(cacheDir), Optional.of(scheduler), - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); } /** 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 a49b290e4d..a0213a41a8 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 @@ -28,7 +28,7 @@ import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockDataGenerator.BlockOptions; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.LogWithMetadata; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; @@ -599,7 +599,7 @@ public class BlockchainQueriesTest { blockchain, worldStateArchive, scheduler, - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); } } diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_overrides_empty.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_overrides_empty.json new file mode 100644 index 0000000000..6280773f3d --- /dev/null +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_overrides_empty.json @@ -0,0 +1,24 @@ +{ + "request": { + "id": 3, + "jsonrpc": "2.0", + "method": "eth_call", + "params": [ + { + "to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f", + "from": "a94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "data": "0x12a7b914" + }, + "latest", + { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b": {} + } + ] + }, + "response": { + "jsonrpc": "2.0", + "id": 3, + "result": "0x0000000000000000000000000000000000000000000000000000000000000001" + }, + "statusCode": 200 +} \ No newline at end of file diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_stateOverride.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_stateOverride.json new file mode 100644 index 0000000000..762202f96b --- /dev/null +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_stateOverride.json @@ -0,0 +1,32 @@ +{ + "request": { + "id": 3, + "jsonrpc": "2.0", + "method": "eth_call", + "params": [ + { + "to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f", + "from": "a94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "data": "0x12a7b914" + }, + "latest", + { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0xde0b6b3a7640000", + "nonce": 88 + }, + "0xb9741079a300Cb3B8f324CdDB847c0d1d273a05E": { + "stateDiff": { + "0x1cf7945003fc5b59d2f6736f0704557aa805c4f2844084ccd1173b8d56946962": "0x000000000000000000000000000000000000000000000000000000110ed03bf7" + } + } + } + ] + }, + "response": { + "jsonrpc": "2.0", + "id": 3, + "result": "0x0000000000000000000000000000000000000000000000000000000000000001" + }, + "statusCode": 200 +} \ No newline at end of file diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_stateOverride_insufficientBalance.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_stateOverride_insufficientBalance.json new file mode 100644 index 0000000000..c3832c5689 --- /dev/null +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_stateOverride_insufficientBalance.json @@ -0,0 +1,34 @@ +{ + "request": { + "id": 3, + "jsonrpc": "2.0", + "method": "eth_call", + "params": [ + { + "to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f", + "from": "a94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "value": "0x000002" + }, + "latest", + { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x000001" + }, + "0xb9741079a300Cb3B8f324CdDB847c0d1d273a05E": { + "stateDiff": { + "0x1cf7945003fc5b59d2f6736f0704557aa805c4f2844084ccd1173b8d56946962": "0x000000000000000000000000000000000000000000000000000000110ed03bf7" + } + } + } + ] + }, + "response": { + "jsonrpc": "2.0", + "id": 3, + "error" : { + "code" : -32004, + "message" : "Upfront cost exceeds account balance" + } + }, + "statusCode": 200 +} \ No newline at end of file diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java index ad9489daf8..c4a3f89aaa 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java @@ -30,7 +30,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; import org.hyperledger.besu.ethereum.core.Request; @@ -84,7 +84,7 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator { private final MiningBeneficiaryCalculator miningBeneficiaryCalculator; private final ExtraDataCalculator extraDataCalculator; private final TransactionPool transactionPool; - protected final MiningParameters miningParameters; + protected final MiningConfiguration miningConfiguration; protected final ProtocolContext protocolContext; protected final ProtocolSchedule protocolSchedule; protected final BlockHeaderFunctions blockHeaderFunctions; @@ -92,14 +92,14 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator { private final AtomicBoolean isCancelled = new AtomicBoolean(false); protected AbstractBlockCreator( - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final MiningBeneficiaryCalculator miningBeneficiaryCalculator, final ExtraDataCalculator extraDataCalculator, final TransactionPool transactionPool, final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, final EthScheduler ethScheduler) { - this.miningParameters = miningParameters; + this.miningConfiguration = miningConfiguration; this.miningBeneficiaryCalculator = miningBeneficiaryCalculator; this.extraDataCalculator = extraDataCalculator; this.transactionPool = transactionPool; @@ -219,7 +219,7 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator { throwIfStopped(); final PluginTransactionSelector pluginTransactionSelector = - miningParameters.getTransactionSelectionService().createPluginTransactionSelector(); + miningConfiguration.getTransactionSelectionService().createPluginTransactionSelector(); final BlockAwareOperationTracer operationTracer = pluginTransactionSelector.getOperationTracer(); @@ -377,7 +377,7 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator { final BlockTransactionSelector selector = new BlockTransactionSelector( - miningParameters, + miningConfiguration, transactionProcessor, protocolContext.getBlockchain(), disposableWorldState, @@ -433,12 +433,11 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator { .getGasLimitCalculator() .nextGasLimit( parentHeader.getGasLimit(), - miningParameters.getTargetGasLimit().orElse(parentHeader.getGasLimit()), + miningConfiguration.getTargetGasLimit().orElse(parentHeader.getGasLimit()), newBlockNumber); final DifficultyCalculator difficultyCalculator = protocolSpec.getDifficultyCalculator(); - final BigInteger difficulty = - difficultyCalculator.nextDifficulty(timestamp, parentHeader, protocolContext); + final BigInteger difficulty = difficultyCalculator.nextDifficulty(timestamp, parentHeader); final Wei baseFee = Optional.of(protocolSpec.getFeeMarket()) @@ -457,7 +456,7 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator { final Bytes32 parentBeaconBlockRoot = maybeParentBeaconBlockRoot.orElse(null); return BlockHeaderBuilder.create() .parentHash(parentHeader.getHash()) - .coinbase(miningParameters.getCoinbase().orElseThrow()) + .coinbase(miningConfiguration.getCoinbase().orElseThrow()) .difficulty(Difficulty.of(difficulty)) .number(newBlockNumber) .gasLimit(gasLimit) diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMinerExecutor.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMinerExecutor.java index af71938d1d..4d2b1274c6 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMinerExecutor.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMinerExecutor.java @@ -20,7 +20,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.MinedBlockObserver; import org.hyperledger.besu.ethereum.chain.PoWObserver; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import org.hyperledger.besu.ethereum.mainnet.AbstractGasLimitSpecification; @@ -47,7 +47,7 @@ public abstract class AbstractMinerExecutor getCoinbase(); diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/NoopMiningCoordinator.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/NoopMiningCoordinator.java index 6eb4927226..8b5624f847 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/NoopMiningCoordinator.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/NoopMiningCoordinator.java @@ -18,7 +18,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import java.util.List; @@ -26,10 +26,10 @@ import java.util.Optional; public class NoopMiningCoordinator implements MiningCoordinator { - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; - public NoopMiningCoordinator(final MiningParameters miningParameters) { - this.miningParameters = miningParameters; + public NoopMiningCoordinator(final MiningConfiguration miningConfiguration) { + this.miningConfiguration = miningConfiguration; } @Override @@ -58,17 +58,17 @@ public class NoopMiningCoordinator implements MiningCoordinator { @Override public Wei getMinTransactionGasPrice() { - return miningParameters.getMinTransactionGasPrice(); + return miningConfiguration.getMinTransactionGasPrice(); } @Override public Wei getMinPriorityFeePerGas() { - return miningParameters.getMinPriorityFeePerGas(); + return miningConfiguration.getMinPriorityFeePerGas(); } @Override public Optional
getCoinbase() { - return miningParameters.getCoinbase(); + return miningConfiguration.getCoinbase(); } @Override diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreator.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreator.java index d0042a5ad9..173330568f 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreator.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreator.java @@ -17,7 +17,7 @@ package org.hyperledger.besu.ethereum.blockcreation; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.SealableBlockHeader; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; @@ -39,7 +39,7 @@ public class PoWBlockCreator extends AbstractBlockCreator { private final PoWSolver nonceSolver; public PoWBlockCreator( - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final ExtraDataCalculator extraDataCalculator, final TransactionPool transactionPool, final ProtocolContext protocolContext, @@ -47,8 +47,8 @@ public class PoWBlockCreator extends AbstractBlockCreator { final PoWSolver nonceSolver, final EthScheduler ethScheduler) { super( - miningParameters, - __ -> miningParameters.getCoinbase().orElseThrow(), + miningConfiguration, + __ -> miningConfiguration.getCoinbase().orElseThrow(), extraDataCalculator, transactionPool, protocolContext, diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutor.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutor.java index b14eb19340..f17b7989d2 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutor.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutor.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.MinedBlockObserver; import org.hyperledger.besu.ethereum.chain.PoWObserver; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import org.hyperledger.besu.ethereum.mainnet.EpochCalculator; @@ -40,7 +40,7 @@ public class PoWMinerExecutor extends AbstractMinerExecutor { final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, final TransactionPool transactionPool, - final MiningParameters miningParams, + final MiningConfiguration miningParams, final AbstractBlockScheduler blockScheduler, final EpochCalculator epochCalculator, final EthScheduler ethScheduler) { @@ -62,7 +62,7 @@ public class PoWMinerExecutor extends AbstractMinerExecutor { final Subscribers observers, final Subscribers ethHashObservers, final BlockHeader parentHeader) { - if (miningParameters.getCoinbase().isEmpty()) { + if (miningConfiguration.getCoinbase().isEmpty()) { throw new CoinbaseNotSetException("Unable to start mining without a coinbase."); } return super.startAsyncMining(observers, ethHashObservers, parentHeader); @@ -79,7 +79,7 @@ public class PoWMinerExecutor extends AbstractMinerExecutor { protocolSchedule.getForNextBlockHeader(parentHeader, 0); final PoWSolver solver = new PoWSolver( - miningParameters, + miningConfiguration, nextBlockProtocolSpec.getPoWHasher().get(), stratumMiningEnabled, ethHashObservers, @@ -87,8 +87,8 @@ public class PoWMinerExecutor extends AbstractMinerExecutor { final Function blockCreator = (header) -> new PoWBlockCreator( - miningParameters, - parent -> miningParameters.getExtraData(), + miningConfiguration, + parent -> miningConfiguration.getExtraData(), transactionPool, protocolContext, protocolSchedule, @@ -103,7 +103,7 @@ public class PoWMinerExecutor extends AbstractMinerExecutor { if (coinbase == null) { throw new IllegalArgumentException("Coinbase cannot be unset."); } else { - miningParameters.setCoinbase(Address.wrap(coinbase.copy())); + miningConfiguration.setCoinbase(Address.wrap(coinbase.copy())); } } @@ -113,7 +113,7 @@ public class PoWMinerExecutor extends AbstractMinerExecutor { @Override public Optional
getCoinbase() { - return miningParameters.getCoinbase(); + return miningConfiguration.getCoinbase(); } public EpochCalculator getEpochCalculator() { diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/BlockSelectionContext.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/BlockSelectionContext.java index f8bf6d50c5..99da62ca06 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/BlockSelectionContext.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/BlockSelectionContext.java @@ -17,7 +17,7 @@ package org.hyperledger.besu.ethereum.blockcreation.txselection; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.GasLimitCalculator; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import org.hyperledger.besu.ethereum.mainnet.blockhash.BlockHashProcessor; @@ -25,7 +25,7 @@ import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket; import org.hyperledger.besu.evm.gascalculator.GasCalculator; public record BlockSelectionContext( - MiningParameters miningParameters, + MiningConfiguration miningConfiguration, GasCalculator gasCalculator, GasLimitCalculator gasLimitCalculator, BlockHashProcessor blockHashProcessor, diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/BlockTransactionSelector.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/BlockTransactionSelector.java index 5370d2ec46..a9b57a697a 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/BlockTransactionSelector.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/BlockTransactionSelector.java @@ -31,7 +31,7 @@ import org.hyperledger.besu.ethereum.blockcreation.txselection.selectors.MinPrio import org.hyperledger.besu.ethereum.blockcreation.txselection.selectors.PriceTransactionSelector; import org.hyperledger.besu.ethereum.blockcreation.txselection.selectors.ProcessingResultTransactionSelector; import org.hyperledger.besu.ethereum.chain.Blockchain; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; import org.hyperledger.besu.ethereum.core.Transaction; @@ -108,7 +108,7 @@ public class BlockTransactionSelector { private volatile TransactionEvaluationContext currTxEvaluationContext; public BlockTransactionSelector( - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final MainnetTransactionProcessor transactionProcessor, final Blockchain blockchain, final MutableWorldState worldState, @@ -132,7 +132,7 @@ public class BlockTransactionSelector { this.ethScheduler = ethScheduler; this.blockSelectionContext = new BlockSelectionContext( - miningParameters, + miningConfiguration, gasCalculator, gasLimitCalculator, blockHashProcessor, @@ -146,7 +146,7 @@ public class BlockTransactionSelector { this.operationTracer = new InterruptibleOperationTracer(pluginTransactionSelector.getOperationTracer()); blockWorldStateUpdater = worldState.updater(); - blockTxsSelectionMaxTime = miningParameters.getBlockTxsSelectionMaxTime(); + blockTxsSelectionMaxTime = miningConfiguration.getBlockTxsSelectionMaxTime(); } private List createTransactionSelectors( @@ -315,7 +315,7 @@ public class BlockTransactionSelector { pendingTransaction, Stopwatch.createStarted(), transactionGasPriceInBlock, - blockSelectionContext.miningParameters().getMinTransactionGasPrice()); + blockSelectionContext.miningConfiguration().getMinTransactionGasPrice()); } /** diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/BlockSizeTransactionSelector.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/BlockSizeTransactionSelector.java index 2877c4ce13..0da2b1386d 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/BlockSizeTransactionSelector.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/BlockSizeTransactionSelector.java @@ -112,13 +112,13 @@ public class BlockSizeTransactionSelector extends AbstractTransactionSelector { LOG.trace( "Min block occupancy ratio {}, gas used {}, available {}, remaining {}, used/available {}", - context.miningParameters().getMinBlockOccupancyRatio(), + context.miningConfiguration().getMinBlockOccupancyRatio(), gasUsed, gasAvailable, gasRemaining, occupancyRatio); - return occupancyRatio >= context.miningParameters().getMinBlockOccupancyRatio(); + return occupancyRatio >= context.miningConfiguration().getMinBlockOccupancyRatio(); } /** diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/MinPriorityFeePerGasTransactionSelector.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/MinPriorityFeePerGasTransactionSelector.java index 5783c7e500..c6dae8a144 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/MinPriorityFeePerGasTransactionSelector.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/MinPriorityFeePerGasTransactionSelector.java @@ -69,7 +69,7 @@ public class MinPriorityFeePerGasTransactionSelector extends AbstractTransaction pendingTransaction .getTransaction() .getEffectivePriorityFeePerGas(context.pendingBlockHeader().getBaseFee()); - return priorityFeePerGas.lessThan(context.miningParameters().getMinPriorityFeePerGas()); + return priorityFeePerGas.lessThan(context.miningConfiguration().getMinPriorityFeePerGas()); } /** diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/PriceTransactionSelector.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/PriceTransactionSelector.java index 707b1c4863..d3c3047f68 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/PriceTransactionSelector.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/PriceTransactionSelector.java @@ -76,7 +76,7 @@ public class PriceTransactionSelector extends AbstractTransactionSelector { if (!pendingTransaction.hasPriority()) { if (context - .miningParameters() + .miningConfiguration() .getMinTransactionGasPrice() .compareTo(evaluationContext.getTransactionGasPrice()) > 0) { @@ -86,7 +86,7 @@ public class PriceTransactionSelector extends AbstractTransactionSelector { .addArgument(pendingTransaction::toTraceLog) .addArgument(evaluationContext.getTransactionGasPrice()::toHumanReadableString) .addArgument( - context.miningParameters().getMinTransactionGasPrice()::toHumanReadableString) + context.miningConfiguration().getMinTransactionGasPrice()::toHumanReadableString) .log(); return true; } diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java index d30349e3d0..b70c48ad02 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java @@ -47,9 +47,9 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Request; import org.hyperledger.besu.ethereum.core.SealableBlockHeader; @@ -304,12 +304,12 @@ abstract class AbstractBlockCreatorTest { .protocolSchedule( new ProtocolScheduleBuilder( genesisConfigFile.getConfigOptions(), - BigInteger.valueOf(42), + Optional.of(BigInteger.valueOf(42)), protocolSpecAdapters, PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) @@ -342,8 +342,8 @@ abstract class AbstractBlockCreatorTest { new BlobCache()); transactionPool.setEnabled(); - final MiningParameters miningParameters = - ImmutableMiningParameters.builder() + final MiningConfiguration miningConfiguration = + ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .extraData(Bytes.fromHexString("deadbeef")) @@ -355,7 +355,7 @@ abstract class AbstractBlockCreatorTest { return new CreateOn( new TestBlockCreator( - miningParameters, + miningConfiguration, __ -> Address.ZERO, __ -> Bytes.fromHexString("deadbeef"), transactionPool, @@ -368,7 +368,7 @@ abstract class AbstractBlockCreatorTest { static class TestBlockCreator extends AbstractBlockCreator { protected TestBlockCreator( - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final MiningBeneficiaryCalculator miningBeneficiaryCalculator, final ExtraDataCalculator extraDataCalculator, final TransactionPool transactionPool, @@ -376,7 +376,7 @@ abstract class AbstractBlockCreatorTest { final ProtocolSchedule protocolSchedule, final EthScheduler ethScheduler) { super( - miningParameters, + miningConfiguration, miningBeneficiaryCalculator, extraDataCalculator, transactionPool, diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java index 6eb03ece94..2787189ece 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java @@ -18,7 +18,7 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; import static org.awaitility.Awaitility.await; -import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME; import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.EXECUTION_INTERRUPTED; import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.NONCE_TOO_LOW; import static org.hyperledger.besu.plugin.data.TransactionSelectionResult.BLOCK_SELECTION_TIMEOUT; @@ -55,10 +55,10 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; import org.hyperledger.besu.ethereum.core.Transaction; @@ -138,7 +138,7 @@ public abstract class AbstractBlockTransactionSelectorTest { protected MutableWorldState worldState; protected ProtocolSchedule protocolSchedule; protected TransactionSelectionService transactionSelectionService; - protected MiningParameters defaultTestMiningParameters; + protected MiningConfiguration defaultTestMiningConfiguration; @Mock protected EthScheduler ethScheduler; @@ -155,7 +155,7 @@ public abstract class AbstractBlockTransactionSelectorTest { genesisConfigFile = getGenesisConfigFile(); protocolSchedule = createProtocolSchedule(); transactionSelectionService = new TransactionSelectionServiceImpl(); - defaultTestMiningParameters = + defaultTestMiningConfiguration = createMiningParameters( transactionSelectionService, Wei.ZERO, @@ -234,7 +234,7 @@ public abstract class AbstractBlockTransactionSelectorTest { FixedDifficultyProtocolSchedule.create( GenesisConfigFile.fromResource("/dev.json").getConfigOptions(), EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -248,7 +248,7 @@ public abstract class AbstractBlockTransactionSelectorTest { final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - defaultTestMiningParameters, + defaultTestMiningConfiguration, mainnetTransactionProcessor, blockHeader, miningBeneficiary, @@ -269,7 +269,7 @@ public abstract class AbstractBlockTransactionSelectorTest { final Address miningBeneficiary = AddressHelpers.ofValue(1); final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - defaultTestMiningParameters, + defaultTestMiningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -296,7 +296,7 @@ public abstract class AbstractBlockTransactionSelectorTest { final Address miningBeneficiary = AddressHelpers.ofValue(1); final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - defaultTestMiningParameters, + defaultTestMiningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -336,7 +336,7 @@ public abstract class AbstractBlockTransactionSelectorTest { final Address miningBeneficiary = AddressHelpers.ofValue(1); final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - defaultTestMiningParameters, + defaultTestMiningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -377,7 +377,7 @@ public abstract class AbstractBlockTransactionSelectorTest { final Address miningBeneficiary = AddressHelpers.ofValue(1); final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - defaultTestMiningParameters, + defaultTestMiningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -412,7 +412,7 @@ public abstract class AbstractBlockTransactionSelectorTest { final Address miningBeneficiary = AddressHelpers.ofValue(1); final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - defaultTestMiningParameters, + defaultTestMiningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -568,7 +568,7 @@ public abstract class AbstractBlockTransactionSelectorTest { final Address miningBeneficiary = AddressHelpers.ofValue(1); final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - defaultTestMiningParameters, + defaultTestMiningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -643,7 +643,7 @@ public abstract class AbstractBlockTransactionSelectorTest { final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - defaultTestMiningParameters, + defaultTestMiningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -757,7 +757,7 @@ public abstract class AbstractBlockTransactionSelectorTest { final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - defaultTestMiningParameters, + defaultTestMiningConfiguration, transactionProcessor, createBlock(300_000), AddressHelpers.ofValue(1), @@ -793,7 +793,7 @@ public abstract class AbstractBlockTransactionSelectorTest { final Address miningBeneficiary = AddressHelpers.ofValue(1); final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - defaultTestMiningParameters, + defaultTestMiningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -824,12 +824,12 @@ public abstract class AbstractBlockTransactionSelectorTest { final Address miningBeneficiary = AddressHelpers.ofValue(1); - final MiningParameters miningParameters = - ImmutableMiningParameters.builder().from(defaultTestMiningParameters).build(); + final MiningConfiguration miningConfiguration = + ImmutableMiningConfiguration.builder().from(defaultTestMiningConfiguration).build(); final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - miningParameters, + miningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -841,7 +841,7 @@ public abstract class AbstractBlockTransactionSelectorTest { ensureTransactionIsValid(transaction, 0, 5); // raise the minGasPrice at runtime from 1 wei to 10 wei - miningParameters.setMinTransactionGasPrice(Wei.of(10)); + miningConfiguration.setMinTransactionGasPrice(Wei.of(10)); final TransactionSelectionResults results = selector.buildTransactionListForBlock(); @@ -857,15 +857,15 @@ public abstract class AbstractBlockTransactionSelectorTest { @Test public void decreaseOfMinGasPriceAtRuntimeIncludeTxThatWasPreviouslyNotSelected() { final Transaction transaction = createTransaction(0, Wei.of(7L), 100_000); - final MiningParameters miningParameters = - ImmutableMiningParameters.builder().from(defaultTestMiningParameters).build(); + final MiningConfiguration miningConfiguration = + ImmutableMiningConfiguration.builder().from(defaultTestMiningConfiguration).build(); final ProcessableBlockHeader blockHeader = createBlock(500_000); final Address miningBeneficiary = AddressHelpers.ofValue(1); final BlockTransactionSelector selector1 = createBlockSelectorAndSetupTxPool( - miningParameters, + miningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -876,7 +876,7 @@ public abstract class AbstractBlockTransactionSelectorTest { ensureTransactionIsValid(transaction, 0, 5); // raise the minGasPrice at runtime from 1 wei to 10 wei - miningParameters.setMinTransactionGasPrice(Wei.of(10)); + miningConfiguration.setMinTransactionGasPrice(Wei.of(10)); final TransactionSelectionResults results1 = selector1.buildTransactionListForBlock(); @@ -889,11 +889,11 @@ public abstract class AbstractBlockTransactionSelectorTest { .containsOnly(transaction); // decrease the minGasPrice at runtime from 10 wei to 5 wei - miningParameters.setMinTransactionGasPrice(Wei.of(5)); + miningConfiguration.setMinTransactionGasPrice(Wei.of(5)); final BlockTransactionSelector selector2 = createBlockSelector( - miningParameters, + miningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -910,9 +910,9 @@ public abstract class AbstractBlockTransactionSelectorTest { @Test public void shouldNotSelectTransactionsWithPriorityFeeLessThanConfig() { ProcessableBlockHeader blockHeader = createBlock(5_000_000, Wei.ONE); - final MiningParameters miningParameters = - ImmutableMiningParameters.builder().from(defaultTestMiningParameters).build(); - miningParameters.setMinPriorityFeePerGas(Wei.of(7)); + final MiningConfiguration miningConfiguration = + ImmutableMiningConfiguration.builder().from(defaultTestMiningConfiguration).build(); + miningConfiguration.setMinPriorityFeePerGas(Wei.of(7)); final Transaction txSelected = createTransaction(1, Wei.of(8), 100_000); ensureTransactionIsValid(txSelected); // transaction txNotSelected should not be selected @@ -921,7 +921,7 @@ public abstract class AbstractBlockTransactionSelectorTest { final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - miningParameters, + miningConfiguration, transactionProcessor, blockHeader, AddressHelpers.ofValue(1), @@ -1259,7 +1259,7 @@ public abstract class AbstractBlockTransactionSelectorTest { } protected BlockTransactionSelector createBlockSelectorAndSetupTxPool( - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final MainnetTransactionProcessor transactionProcessor, final ProcessableBlockHeader blockHeader, final Address miningBeneficiary, @@ -1269,7 +1269,7 @@ public abstract class AbstractBlockTransactionSelectorTest { transactionPool = createTransactionPool(); return createBlockSelector( - miningParameters, + miningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -1278,7 +1278,7 @@ public abstract class AbstractBlockTransactionSelectorTest { } protected BlockTransactionSelector createBlockSelector( - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final MainnetTransactionProcessor transactionProcessor, final ProcessableBlockHeader blockHeader, final Address miningBeneficiary, @@ -1287,7 +1287,7 @@ public abstract class AbstractBlockTransactionSelectorTest { final BlockTransactionSelector selector = new BlockTransactionSelector( - miningParameters, + miningConfiguration, transactionProcessor, blockchain, worldState, @@ -1423,12 +1423,12 @@ public abstract class AbstractBlockTransactionSelectorTest { return new BlockHeaderTestFixture().number(number).buildHeader(); } - protected MiningParameters createMiningParameters( + protected MiningConfiguration createMiningParameters( final TransactionSelectionService transactionSelectionService, final Wei minGasPrice, final double minBlockOccupancyRatio, final PositiveNumber txsSelectionMaxTime) { - return ImmutableMiningParameters.builder() + return ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .minTransactionGasPrice(minGasPrice) @@ -1439,13 +1439,13 @@ public abstract class AbstractBlockTransactionSelectorTest { .build(); } - protected MiningParameters createMiningParameters( + protected MiningConfiguration createMiningParameters( final TransactionSelectionService transactionSelectionService, final Wei minGasPrice, final double minBlockOccupancyRatio, final int genesisBlockPeriodSeconds, final PositiveNumber minBlockTimePercentage) { - return ImmutableMiningParameters.builder() + return ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .minTransactionGasPrice(minGasPrice) 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 e5b46925aa..5b893d11f2 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 @@ -22,6 +22,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import org.hyperledger.besu.ethereum.ConsensusContext; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.blockcreation.BlockCreator.BlockCreationResult; import org.hyperledger.besu.ethereum.blockcreation.txselection.TransactionSelectionResults; @@ -58,7 +59,7 @@ public class BlockMinerTest { headerBuilder.buildHeader(), new BlockBody(Lists.newArrayList(), Lists.newArrayList())); final ProtocolContext protocolContext = - new ProtocolContext(null, null, null, new BadBlockManager()); + new ProtocolContext(null, null, mock(ConsensusContext.class), new BadBlockManager()); final PoWBlockCreator blockCreator = mock(PoWBlockCreator.class); final Function blockCreatorSupplier = @@ -102,7 +103,7 @@ public class BlockMinerTest { headerBuilder.buildHeader(), new BlockBody(Lists.newArrayList(), Lists.newArrayList())); final ProtocolContext protocolContext = - new ProtocolContext(null, null, null, new BadBlockManager()); + new ProtocolContext(null, null, mock(ConsensusContext.class), new BadBlockManager()); final PoWBlockCreator blockCreator = mock(PoWBlockCreator.class); final Function blockCreatorSupplier = @@ -150,7 +151,7 @@ public class BlockMinerTest { headerBuilder.buildHeader(), new BlockBody(Lists.newArrayList(), Lists.newArrayList())); final ProtocolContext protocolContext = - new ProtocolContext(null, null, null, new BadBlockManager()); + new ProtocolContext(null, null, mock(ConsensusContext.class), new BadBlockManager()); final PoWBlockCreator blockCreator = mock(PoWBlockCreator.class); final Function blockCreatorSupplier = diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LegacyFeeMarketBlockTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LegacyFeeMarketBlockTransactionSelectorTest.java index 940d076bbc..327d4bd37d 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LegacyFeeMarketBlockTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LegacyFeeMarketBlockTransactionSelectorTest.java @@ -22,7 +22,7 @@ import static org.mockito.Mockito.when; import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; @@ -42,6 +42,7 @@ import org.hyperledger.besu.testutil.TestClock; import org.hyperledger.besu.util.number.Fraction; import java.time.ZoneId; +import java.util.Optional; import java.util.function.Function; public class LegacyFeeMarketBlockTransactionSelectorTest @@ -56,12 +57,12 @@ public class LegacyFeeMarketBlockTransactionSelectorTest protected ProtocolSchedule createProtocolSchedule() { return new ProtocolScheduleBuilder( genesisConfigFile.getConfigOptions(), - CHAIN_ID, + Optional.of(CHAIN_ID), ProtocolSpecAdapters.create(0, Function.identity()), new PrivacyParameters(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java index 68d9a71de6..62eaf713c5 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java @@ -16,7 +16,7 @@ package org.hyperledger.besu.ethereum.blockcreation; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; -import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME; import static org.mockito.Mockito.mock; import org.hyperledger.besu.config.GenesisConfigFile; @@ -26,8 +26,8 @@ import org.hyperledger.besu.ethereum.blockcreation.txselection.BlockTransactionS import org.hyperledger.besu.ethereum.blockcreation.txselection.TransactionSelectionResults; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.AddressHelpers; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; import org.hyperledger.besu.ethereum.core.Transaction; @@ -51,6 +51,7 @@ import org.hyperledger.besu.util.number.Fraction; import java.time.ZoneId; import java.util.List; +import java.util.Optional; import java.util.function.Function; import org.junit.jupiter.api.Test; @@ -67,12 +68,12 @@ public class LondonFeeMarketBlockTransactionSelectorTest protected ProtocolSchedule createProtocolSchedule() { return new ProtocolScheduleBuilder( genesisConfigFile.getConfigOptions(), - CHAIN_ID, + Optional.of(CHAIN_ID), ProtocolSpecAdapters.create(0, Function.identity()), new PrivacyParameters(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) @@ -221,7 +222,7 @@ public class LondonFeeMarketBlockTransactionSelectorTest final Address miningBeneficiary = AddressHelpers.ofValue(1); final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - defaultTestMiningParameters, + defaultTestMiningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -241,9 +242,9 @@ public class LondonFeeMarketBlockTransactionSelectorTest @Override public void shouldNotSelectTransactionsWithPriorityFeeLessThanConfig() { ProcessableBlockHeader blockHeader = createBlock(5_000_000, Wei.ONE); - final MiningParameters miningParameters = - ImmutableMiningParameters.builder().from(defaultTestMiningParameters).build(); - miningParameters.setMinPriorityFeePerGas(Wei.of(7)); + final MiningConfiguration miningConfiguration = + ImmutableMiningConfiguration.builder().from(defaultTestMiningConfiguration).build(); + miningConfiguration.setMinPriorityFeePerGas(Wei.of(7)); final Transaction txSelected1 = createEIP1559Transaction(1, Wei.of(8), Wei.of(8), 100_000); ensureTransactionIsValid(txSelected1); @@ -262,7 +263,7 @@ public class LondonFeeMarketBlockTransactionSelectorTest final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - miningParameters, + miningConfiguration, transactionProcessor, blockHeader, AddressHelpers.ofValue(1), diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/MinPriorityFeePerGasTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/MinPriorityFeePerGasTransactionSelectorTest.java index 6f81f4df2c..29cea9d089 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/MinPriorityFeePerGasTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/MinPriorityFeePerGasTransactionSelectorTest.java @@ -24,7 +24,7 @@ import org.hyperledger.besu.ethereum.blockcreation.txselection.BlockSelectionCon import org.hyperledger.besu.ethereum.blockcreation.txselection.TransactionEvaluationContext; import org.hyperledger.besu.ethereum.blockcreation.txselection.selectors.AbstractTransactionSelector; import org.hyperledger.besu.ethereum.blockcreation.txselection.selectors.MinPriorityFeePerGasTransactionSelector; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.transactions.PendingTransaction; @@ -46,11 +46,11 @@ public class MinPriorityFeePerGasTransactionSelectorTest { @BeforeEach public void initialize() { - MiningParameters miningParameters = - MiningParameters.newDefault().setMinPriorityFeePerGas(Wei.of(minPriorityFeeParameter)); + MiningConfiguration miningConfiguration = + MiningConfiguration.newDefault().setMinPriorityFeePerGas(Wei.of(minPriorityFeeParameter)); BlockSelectionContext context = new BlockSelectionContext( - miningParameters, null, null, null, pendingBlockHeader, null, null, null, null); + miningConfiguration, null, null, null, pendingBlockHeader, null, null, null, null); transactionSelector = new MinPriorityFeePerGasTransactionSelector(context); } diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java index 509efd7b19..e8b9baa0a7 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java @@ -31,9 +31,9 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; @@ -62,6 +62,7 @@ import org.hyperledger.besu.util.Subscribers; import java.io.IOException; import java.math.BigInteger; import java.util.Collections; +import java.util.Optional; import java.util.function.Function; import com.google.common.collect.Lists; @@ -86,19 +87,19 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest { void createMainnetBlock1() throws IOException { final var genesisConfigFile = GenesisConfigFile.mainnet(); - final MiningParameters miningParameters = createMiningParameters(BLOCK_1_NONCE); + final MiningConfiguration miningConfiguration = createMiningParameters(BLOCK_1_NONCE); final ExecutionContextTestFixture executionContextTestFixture = ExecutionContextTestFixture.builder(genesisConfigFile) .protocolSchedule( new ProtocolScheduleBuilder( genesisConfigFile.getConfigOptions(), - BigInteger.valueOf(42), + Optional.of(BigInteger.valueOf(42)), ProtocolSpecAdapters.create(0, Function.identity()), PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) @@ -107,7 +108,7 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest { final PoWSolver solver = new PoWSolver( - miningParameters, + miningConfiguration, PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), @@ -117,7 +118,7 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest { final PoWBlockCreator blockCreator = new PoWBlockCreator( - miningParameters, + miningConfiguration, parent -> BLOCK_1_EXTRA_DATA, transactionPool, executionContextTestFixture.getProtocolContext(), @@ -145,14 +146,14 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest { final var genesisConfigFile = GenesisConfigFile.fromResource("/block-creation-fixed-difficulty-genesis.json"); - final MiningParameters miningParameters = createMiningParameters(FIXED_DIFFICULTY_NONCE); + final MiningConfiguration miningConfiguration = createMiningParameters(FIXED_DIFFICULTY_NONCE); final ExecutionContextTestFixture executionContextTestFixture = ExecutionContextTestFixture.builder(genesisConfigFile) .protocolSchedule( new ProtocolScheduleBuilder( genesisConfigFile.getConfigOptions(), - BigInteger.valueOf(42), + Optional.of(BigInteger.valueOf(42)), ProtocolSpecAdapters.create( 0, specBuilder -> @@ -162,7 +163,7 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest { PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) @@ -171,7 +172,7 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest { final PoWSolver solver = new PoWSolver( - miningParameters, + miningConfiguration, PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), @@ -181,7 +182,7 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest { final PoWBlockCreator blockCreator = new PoWBlockCreator( - miningParameters, + miningConfiguration, parent -> BLOCK_1_EXTRA_DATA, transactionPool, executionContextTestFixture.getProtocolContext(), @@ -203,12 +204,12 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest { final var genesisConfigFile = GenesisConfigFile.fromResource("/block-creation-fixed-difficulty-genesis.json"); - final MiningParameters miningParameters = createMiningParameters(FIXED_DIFFICULTY_NONCE); + final MiningConfiguration miningConfiguration = createMiningParameters(FIXED_DIFFICULTY_NONCE); ProtocolSchedule protocolSchedule = new ProtocolScheduleBuilder( genesisConfigFile.getConfigOptions(), - BigInteger.valueOf(42), + Optional.of(BigInteger.valueOf(42)), ProtocolSpecAdapters.create( 0, specBuilder -> @@ -218,7 +219,7 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest { PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) @@ -230,7 +231,7 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest { final PoWSolver solver = new PoWSolver( - miningParameters, + miningConfiguration, PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), @@ -240,7 +241,7 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest { final PoWBlockCreator blockCreator = new PoWBlockCreator( - miningParameters, + miningConfiguration, parent -> BLOCK_1_EXTRA_DATA, transactionPool, executionContextTestFixture.getProtocolContext(), @@ -280,12 +281,12 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest { final var genesisConfigFile = GenesisConfigFile.fromResource("/block-creation-fixed-difficulty-genesis.json"); - final MiningParameters miningParameters = createMiningParameters(FIXED_DIFFICULTY_NONCE); + final MiningConfiguration miningConfiguration = createMiningParameters(FIXED_DIFFICULTY_NONCE); ProtocolSchedule protocolSchedule = new ProtocolScheduleBuilder( genesisConfigFile.getConfigOptions(), - BigInteger.valueOf(42), + Optional.of(BigInteger.valueOf(42)), ProtocolSpecAdapters.create( 0, specBuilder -> @@ -295,7 +296,7 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest { PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) @@ -307,7 +308,7 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest { final PoWSolver solver = new PoWSolver( - miningParameters, + miningConfiguration, PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), @@ -317,7 +318,7 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest { final PoWBlockCreator blockCreator = new PoWBlockCreator( - miningParameters, + miningConfiguration, parent -> BLOCK_1_EXTRA_DATA, transactionPool, executionContextTestFixture.getProtocolContext(), @@ -381,8 +382,8 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest { return transactionPool; } - private MiningParameters createMiningParameters(final long nonce) { - return ImmutableMiningParameters.builder() + private MiningConfiguration createMiningParameters(final long nonce) { + return ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .nonceGenerator(Lists.newArrayList(nonce)) diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutorTest.java index 8c1e217d75..14e6b54374 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutorTest.java @@ -22,7 +22,7 @@ import static org.mockito.Mockito.when; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; @@ -51,7 +51,7 @@ public class PoWMinerExecutorTest { @Test public void startingMiningWithoutCoinbaseThrowsException() { - final MiningParameters miningParameters = MiningParameters.newDefault(); + final MiningConfiguration miningConfiguration = MiningConfiguration.newDefault(); final TransactionPool transactionPool = createTransactionPool(); @@ -60,7 +60,7 @@ public class PoWMinerExecutorTest { null, null, transactionPool, - miningParameters, + miningConfiguration, new DefaultBlockScheduler(1L, 10, TestClock.fixed()), new EpochCalculator.DefaultEpochCalculator(), ethScheduler); @@ -72,7 +72,7 @@ public class PoWMinerExecutorTest { @Test public void settingCoinbaseToNullThrowsException() { - final MiningParameters miningParameters = MiningParameters.newDefault(); + final MiningConfiguration miningConfiguration = MiningConfiguration.newDefault(); final TransactionPool transactionPool = createTransactionPool(); @@ -81,7 +81,7 @@ public class PoWMinerExecutorTest { null, null, transactionPool, - miningParameters, + miningConfiguration, new DefaultBlockScheduler(1, 10, TestClock.fixed()), new EpochCalculator.DefaultEpochCalculator(), ethScheduler); diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMiningCoordinatorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMiningCoordinatorTest.java index 6efd63fbae..6dd272473f 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMiningCoordinatorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMiningCoordinatorTest.java @@ -15,8 +15,8 @@ package org.hyperledger.besu.ethereum.blockcreation; import static org.assertj.core.api.Assertions.assertThat; -import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_REMOTE_SEALERS_LIMIT; -import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_REMOTE_SEALERS_TTL; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.Unstable.DEFAULT_REMOTE_SEALERS_LIMIT; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.Unstable.DEFAULT_REMOTE_SEALERS_TTL; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/ethereum/core/build.gradle b/ethereum/core/build.gradle index 3056a5e105..9ffca12176 100644 --- a/ethereum/core/build.gradle +++ b/ethereum/core/build.gradle @@ -67,8 +67,6 @@ dependencies { implementation 'org.immutables:value-annotations' implementation 'tech.pegasys:jc-kzg-4844' - implementation 'io.prometheus:simpleclient_guava' - implementation 'org.xerial.snappy:snappy-java' annotationProcessor 'org.immutables:value' @@ -109,6 +107,8 @@ dependencies { testSupportImplementation 'org.junit.jupiter:junit-jupiter' testSupportImplementation 'org.assertj:assertj-core' testSupportImplementation 'org.mockito:mockito-core' + testSupportImplementation 'com.google.dagger:dagger' + testSupportAnnotationProcessor 'com.google.dagger:dagger-compiler' jmhImplementation project(path: ':config', configuration: 'testSupportArtifacts') jmhImplementation project(':crypto:algorithms') diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ConsensusContextFactory.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ConsensusContextFactory.java deleted file mode 100644 index a9381fa199..0000000000 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ConsensusContextFactory.java +++ /dev/null @@ -1,38 +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.ethereum; - -import org.hyperledger.besu.ethereum.chain.Blockchain; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; -import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; - -/** The ConsensusContextFactory interface defines a method for creating a consensus context. */ -@FunctionalInterface -public interface ConsensusContextFactory { - - /** - * Creates a consensus context with the given blockchain, world state archive, and protocol - * schedule. - * - * @param blockchain the blockchain - * @param worldStateArchive the world state archive - * @param protocolSchedule the protocol schedule - * @return the created consensus context - */ - ConsensusContext create( - Blockchain blockchain, - WorldStateArchive worldStateArchive, - ProtocolSchedule protocolSchedule); -} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/MainnetBlockValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/MainnetBlockValidator.java index b218982c09..00766cdf57 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/MainnetBlockValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/MainnetBlockValidator.java @@ -171,7 +171,12 @@ public class MainnetBlockValidator implements BlockValidator { Optional> maybeRequests = result.getYield().flatMap(BlockProcessingOutputs::getRequests); if (!blockBodyValidator.validateBody( - context, block, receipts, worldState.rootHash(), ommerValidationMode)) { + context, + block, + receipts, + worldState.rootHash(), + ommerValidationMode, + BodyValidationMode.FULL)) { result = new BlockProcessingResult("failed to validate output of imported block"); handleFailedBlockProcessing(block, result, shouldRecordBadBlock); return result; @@ -181,7 +186,7 @@ public class MainnetBlockValidator implements BlockValidator { Optional.of(new BlockProcessingOutputs(worldState, receipts, maybeRequests))); } } catch (MerkleTrieException ex) { - context.getSynchronizer().healWorldState(ex.getMaybeAddress(), ex.getLocation()); + context.getWorldStateArchive().heal(ex.getMaybeAddress(), ex.getLocation()); return new BlockProcessingResult(Optional.empty(), ex); } catch (StorageException ex) { var retval = new BlockProcessingResult(Optional.empty(), ex); @@ -246,6 +251,12 @@ public class MainnetBlockValidator implements BlockValidator { final HeaderValidationMode headerValidationMode, final HeaderValidationMode ommerValidationMode, final BodyValidationMode bodyValidationMode) { + + if (bodyValidationMode == BodyValidationMode.FULL) { + throw new UnsupportedOperationException( + "Full body validation is not supported for syncing blocks"); + } + final BlockHeader header = block.getHeader(); if (!blockHeaderValidator.validateHeader(header, context, headerValidationMode)) { String description = String.format("Failed header validation (%s)", headerValidationMode); @@ -253,8 +264,11 @@ public class MainnetBlockValidator implements BlockValidator { return false; } - if (!blockBodyValidator.validateBodyLight( - context, block, receipts, ommerValidationMode, bodyValidationMode)) { + if (bodyValidationMode == BodyValidationMode.NONE) { + return true; + } + + if (!blockBodyValidator.validateBodyLight(context, block, receipts, ommerValidationMode)) { badBlockManager.addBadBlock( block, BadBlockCause.fromValidationFailure("Failed body validation (light)")); return false; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java index 4ca40bc0a9..33897c3e1e 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java @@ -16,8 +16,6 @@ package org.hyperledger.besu.ethereum; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; -import org.hyperledger.besu.ethereum.core.Synchronizer; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import java.util.Optional; @@ -30,9 +28,8 @@ import java.util.Optional; public class ProtocolContext { private final MutableBlockchain blockchain; private final WorldStateArchive worldStateArchive; - private final BadBlockManager badBlockManager; private final ConsensusContext consensusContext; - private Synchronizer synchronizer; + private final BadBlockManager badBlockManager; /** * Constructs a new ProtocolContext with the given blockchain, world state archive, consensus @@ -40,7 +37,7 @@ public class ProtocolContext { * * @param blockchain the blockchain of the protocol context * @param worldStateArchive the world state archive of the protocol context - * @param consensusContext the consensus context of the protocol context + * @param consensusContext the consensus context * @param badBlockManager the bad block manager of the protocol context */ public ProtocolContext( @@ -54,48 +51,6 @@ public class ProtocolContext { this.badBlockManager = badBlockManager; } - /** - * Initializes a new ProtocolContext with the given blockchain, world state archive, protocol - * schedule, consensus context factory, and bad block manager. - * - * @param blockchain the blockchain of the protocol context - * @param worldStateArchive the world state archive of the protocol context - * @param protocolSchedule the protocol schedule of the protocol context - * @param consensusContextFactory the consensus context factory of the protocol context - * @param badBlockManager the bad block manager of the protocol context - * @return the initialized ProtocolContext - */ - public static ProtocolContext init( - final MutableBlockchain blockchain, - final WorldStateArchive worldStateArchive, - final ProtocolSchedule protocolSchedule, - final ConsensusContextFactory consensusContextFactory, - final BadBlockManager badBlockManager) { - return new ProtocolContext( - blockchain, - worldStateArchive, - consensusContextFactory.create(blockchain, worldStateArchive, protocolSchedule), - badBlockManager); - } - - /** - * Gets the synchronizer of the protocol context. - * - * @return the synchronizer of the protocol context - */ - public Synchronizer getSynchronizer() { - return synchronizer; - } - - /** - * Sets the synchronizer of the protocol context. - * - * @param synchronizer the synchronizer to set - */ - public void setSynchronizer(final Synchronizer synchronizer) { - this.synchronizer = synchronizer; - } - /** * Gets the blockchain of the protocol context. * diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchain.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchain.java index bce94a1915..f6e06f82d2 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchain.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchain.java @@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static java.util.Collections.emptyList; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; +import static org.hyperledger.besu.metrics.BesuMetricCategory.BLOCKCHAIN; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.chain.BlockchainStorage.Updater; @@ -32,7 +33,6 @@ import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; -import org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; import org.hyperledger.besu.util.InvalidConfigurationException; @@ -56,7 +56,6 @@ import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.google.common.collect.Lists; import com.google.common.collect.Streams; -import io.prometheus.client.guava.cache.CacheMetricsCollector; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -134,13 +133,12 @@ public class DefaultBlockchain implements MutableBlockchain { totalDifficultyCache = Optional.of( CacheBuilder.newBuilder().recordStats().maximumSize(numberOfBlocksToCache).build()); - CacheMetricsCollector cacheMetrics = new CacheMetricsCollector(); - cacheMetrics.addCache("blockHeaders", blockHeadersCache.get()); - cacheMetrics.addCache("blockBodies", blockBodiesCache.get()); - cacheMetrics.addCache("transactionReceipts", transactionReceiptsCache.get()); - cacheMetrics.addCache("totalDifficulty", totalDifficultyCache.get()); - if (metricsSystem instanceof PrometheusMetricsSystem prometheusMetricsSystem) - prometheusMetricsSystem.addCollector(BesuMetricCategory.BLOCKCHAIN, () -> cacheMetrics); + metricsSystem.createGuavaCacheCollector(BLOCKCHAIN, "blockHeaders", blockHeadersCache.get()); + metricsSystem.createGuavaCacheCollector(BLOCKCHAIN, "blockBodies", blockBodiesCache.get()); + metricsSystem.createGuavaCacheCollector( + BLOCKCHAIN, "transactionReceipts", transactionReceiptsCache.get()); + metricsSystem.createGuavaCacheCollector( + BLOCKCHAIN, "totalDifficulty", totalDifficultyCache.get()); } else { blockHeadersCache = Optional.empty(); blockBodiesCache = Optional.empty(); @@ -155,11 +153,11 @@ public class DefaultBlockchain implements MutableBlockchain { private void createCounters(final MetricsSystem metricsSystem) { gasUsedCounter = metricsSystem.createCounter( - BesuMetricCategory.BLOCKCHAIN, "chain_head_gas_used_counter", "Counter for Gas used"); + BLOCKCHAIN, "chain_head_gas_used_counter", "Counter for Gas used"); numberOfTransactionsCounter = metricsSystem.createCounter( - BesuMetricCategory.BLOCKCHAIN, + BLOCKCHAIN, "chain_head_transaction_count_counter", "Counter for the number of transactions"); } @@ -184,37 +182,37 @@ public class DefaultBlockchain implements MutableBlockchain { this::getSafeBlockNumber); metricsSystem.createGauge( - BesuMetricCategory.BLOCKCHAIN, + BLOCKCHAIN, "difficulty_total", "Total difficulty of the chainhead", () -> this.getChainHead().getTotalDifficulty().toBigInteger().doubleValue()); metricsSystem.createLongGauge( - BesuMetricCategory.BLOCKCHAIN, + BLOCKCHAIN, "chain_head_timestamp", "Timestamp from the current chain head", () -> getChainHeadHeader().getTimestamp()); metricsSystem.createLongGauge( - BesuMetricCategory.BLOCKCHAIN, + BLOCKCHAIN, "chain_head_gas_used", "Gas used by the current chain head block", () -> getChainHeadHeader().getGasUsed()); metricsSystem.createLongGauge( - BesuMetricCategory.BLOCKCHAIN, + BLOCKCHAIN, "chain_head_gas_limit", "Block gas limit of the current chain head block", () -> getChainHeadHeader().getGasLimit()); metricsSystem.createIntegerGauge( - BesuMetricCategory.BLOCKCHAIN, + BLOCKCHAIN, "chain_head_transaction_count", "Number of transactions in the current chain head block", () -> chainHeadTransactionCount); metricsSystem.createIntegerGauge( - BesuMetricCategory.BLOCKCHAIN, + BLOCKCHAIN, "chain_head_ommer_count", "Number of ommers in the current chain head block", () -> chainHeadOmmerCount); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/components/ProtocolScheduleModule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/components/ProtocolScheduleModule.java new file mode 100644 index 0000000000..98575272c7 --- /dev/null +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/components/ProtocolScheduleModule.java @@ -0,0 +1,100 @@ +/* + * Copyright contributors to Hyperledger Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.components; + +import org.hyperledger.besu.config.GenesisConfigOptions; +import org.hyperledger.besu.ethereum.chain.BadBlockManager; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; +import org.hyperledger.besu.ethereum.core.PrivacyParameters; +import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecAdapters; +import org.hyperledger.besu.evm.internal.EvmConfiguration; +import org.hyperledger.besu.plugin.services.MetricsSystem; + +import java.math.BigInteger; +import java.util.Optional; +import javax.inject.Singleton; + +import dagger.Module; +import dagger.Provides; + +/** Provides the protocol schedule for the network. */ +@Module +public class ProtocolScheduleModule { + + /** Default constructor. */ + public ProtocolScheduleModule() {} + + /** + * Provides the protocol schedule builder. + * + * @param config the genesis config options + * @param protocolSpecAdapters the protocol spec adapters + * @param privacyParameters the privacy parameters + * @param isRevertReasonEnabled whether revert reason is enabled + * @param evmConfiguration the EVM configuration + * @param badBlockManager the bad block manager + * @param isParallelTxProcessingEnabled whether parallel tx processing is enabled + * @param metricsSystem the metrics system + * @param miningConfiguration the mining parameters + * @return the protocol schedule builder + */ + @Singleton + @Provides + public ProtocolScheduleBuilder provideProtocolScheduleBuilder( + final GenesisConfigOptions config, + final ProtocolSpecAdapters protocolSpecAdapters, + final PrivacyParameters privacyParameters, + final boolean isRevertReasonEnabled, + final EvmConfiguration evmConfiguration, + final BadBlockManager badBlockManager, + final boolean isParallelTxProcessingEnabled, + final MetricsSystem metricsSystem, + final MiningConfiguration miningConfiguration) { + + ProtocolScheduleBuilder builder = + new ProtocolScheduleBuilder( + config, + config.getChainId(), + protocolSpecAdapters, + privacyParameters, + isRevertReasonEnabled, + evmConfiguration, + miningConfiguration, + badBlockManager, + isParallelTxProcessingEnabled, + metricsSystem); + + return builder; + } + + /** + * Provides the protocol schedule. + * + * @param builder the protocol schedule builder + * @param config the genesis config options + * @return the protocol schedule + */ + @Provides + public ProtocolSchedule createProtocolSchedule( + final ProtocolScheduleBuilder builder, final GenesisConfigOptions config) { + final Optional chainId = config.getChainId().or(() -> builder.getDefaultChainId()); + DefaultProtocolSchedule protocolSchedule = new DefaultProtocolSchedule(chainId); + builder.initSchedule(protocolSchedule, chainId); + return protocolSchedule; + } +} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/components/ProtocolSpecModule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/components/ProtocolSpecModule.java new file mode 100644 index 0000000000..fe9b0f3fab --- /dev/null +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/components/ProtocolSpecModule.java @@ -0,0 +1,51 @@ +/* + * Copyright contributors to Hyperledger Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.components; + +import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSpecs; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecBuilder; +import org.hyperledger.besu.evm.internal.EvmConfiguration; +import org.hyperledger.besu.plugin.services.MetricsSystem; + +import javax.inject.Named; + +import dagger.Module; +import dagger.Provides; + +/** Provides protocol specs for network forks. */ +@Module +public class ProtocolSpecModule { + + /** Default constructor. */ + public ProtocolSpecModule() {} + + /** + * Provides the protocol spec for the frontier network fork. + * + * @param evmConfiguration the EVM configuration + * @param isParalleltxEnabled whether parallel tx processing is enabled + * @param metricsSystem the metrics system + * @return the protocol spec for the frontier network fork + */ + @Provides + @Named("frontier") + public ProtocolSpecBuilder frontierProtocolSpec( + final EvmConfiguration evmConfiguration, + final boolean isParalleltxEnabled, + final MetricsSystem metricsSystem) { + return MainnetProtocolSpecs.frontierDefinition( + evmConfiguration, isParalleltxEnabled, metricsSystem); + } +} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParameters.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningConfiguration.java similarity index 88% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParameters.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningConfiguration.java index 1921b3568b..fb39d164b7 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParameters.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningConfiguration.java @@ -34,27 +34,29 @@ import org.immutables.value.Value; @Value.Immutable @Value.Enclosing -public abstract class MiningParameters { +public abstract class MiningConfiguration { public static final PositiveNumber DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME = PositiveNumber.fromInt((int) Duration.ofSeconds(5).toMillis()); public static final PositiveNumber DEFAULT_POA_BLOCK_TXS_SELECTION_MAX_TIME = PositiveNumber.fromInt(75); - public static final MiningParameters MINING_DISABLED = - ImmutableMiningParameters.builder() + public static final MiningConfiguration MINING_DISABLED = + ImmutableMiningConfiguration.builder() .mutableInitValues( - ImmutableMiningParameters.MutableInitValues.builder().isMiningEnabled(false).build()) + ImmutableMiningConfiguration.MutableInitValues.builder() + .isMiningEnabled(false) + .build()) .build(); @VisibleForTesting - public static final MiningParameters newDefault() { - return ImmutableMiningParameters.builder().build(); + public static final MiningConfiguration newDefault() { + return ImmutableMiningConfiguration.builder().build(); } public boolean isMiningEnabled() { return getMutableRuntimeValues().miningEnabled; } - public MiningParameters setMiningEnabled(final boolean miningEnabled) { + public MiningConfiguration setMiningEnabled(final boolean miningEnabled) { getMutableRuntimeValues().miningEnabled = miningEnabled; return this; } @@ -63,7 +65,7 @@ public abstract class MiningParameters { return getMutableRuntimeValues().extraData; } - public MiningParameters setExtraData(final Bytes extraData) { + public MiningConfiguration setExtraData(final Bytes extraData) { getMutableRuntimeValues().extraData = extraData; return this; } @@ -72,7 +74,7 @@ public abstract class MiningParameters { return getMutableRuntimeValues().minTransactionGasPrice; } - public MiningParameters setMinTransactionGasPrice(final Wei minTransactionGasPrice) { + public MiningConfiguration setMinTransactionGasPrice(final Wei minTransactionGasPrice) { getMutableRuntimeValues().minTransactionGasPrice = minTransactionGasPrice; return this; } @@ -81,7 +83,7 @@ public abstract class MiningParameters { return getMutableRuntimeValues().minPriorityFeePerGas; } - public MiningParameters setMinPriorityFeePerGas(final Wei minPriorityFeePerGas) { + public MiningConfiguration setMinPriorityFeePerGas(final Wei minPriorityFeePerGas) { getMutableRuntimeValues().minPriorityFeePerGas = minPriorityFeePerGas; return this; } @@ -90,7 +92,7 @@ public abstract class MiningParameters { return getMutableRuntimeValues().coinbase; } - public MiningParameters setCoinbase(final Address coinbase) { + public MiningConfiguration setCoinbase(final Address coinbase) { getMutableRuntimeValues().coinbase = Optional.of(coinbase); return this; } @@ -99,7 +101,7 @@ public abstract class MiningParameters { return getMutableRuntimeValues().targetGasLimit; } - public MiningParameters setTargetGasLimit(final long targetGasLimit) { + public MiningConfiguration setTargetGasLimit(final long targetGasLimit) { getMutableRuntimeValues().targetGasLimit = OptionalLong.of(targetGasLimit); return this; } @@ -108,7 +110,7 @@ public abstract class MiningParameters { return getMutableRuntimeValues().minBlockOccupancyRatio; } - public MiningParameters setMinBlockOccupancyRatio(final double minBlockOccupancyRatio) { + public MiningConfiguration setMinBlockOccupancyRatio(final double minBlockOccupancyRatio) { getMutableRuntimeValues().minBlockOccupancyRatio = minBlockOccupancyRatio; return this; } @@ -117,7 +119,7 @@ public abstract class MiningParameters { return getMutableRuntimeValues().nonceGenerator; } - public MiningParameters setNonceGenerator(final Iterable nonceGenerator) { + public MiningConfiguration setNonceGenerator(final Iterable nonceGenerator) { getMutableRuntimeValues().nonceGenerator = Optional.of(nonceGenerator); return this; } @@ -126,12 +128,12 @@ public abstract class MiningParameters { return getMutableRuntimeValues().blockPeriodSeconds; } - public MiningParameters setBlockPeriodSeconds(final int blockPeriodSeconds) { + public MiningConfiguration setBlockPeriodSeconds(final int blockPeriodSeconds) { getMutableRuntimeValues().blockPeriodSeconds = OptionalInt.of(blockPeriodSeconds); return this; } - public MiningParameters setEmptyBlockPeriodSeconds(final int emptyBlockPeriodSeconds) { + public MiningConfiguration setEmptyBlockPeriodSeconds(final int emptyBlockPeriodSeconds) { getMutableRuntimeValues().emptyBlockPeriodSeconds = OptionalInt.of(emptyBlockPeriodSeconds); return this; } @@ -207,7 +209,7 @@ public abstract class MiningParameters { Wei DEFAULT_MIN_PRIORITY_FEE_PER_GAS = Wei.ZERO; double DEFAULT_MIN_BLOCK_OCCUPANCY_RATIO = 0.8; - MutableInitValues DEFAULT = ImmutableMiningParameters.MutableInitValues.builder().build(); + MutableInitValues DEFAULT = ImmutableMiningConfiguration.MutableInitValues.builder().build(); @Value.Default default boolean isMiningEnabled() { @@ -335,7 +337,7 @@ public abstract class MiningParameters { long DEFAULT_POS_BLOCK_CREATION_MAX_TIME = Duration.ofSeconds(12).toMillis(); long DEFAULT_POS_BLOCK_CREATION_REPETITION_MIN_DURATION = Duration.ofMillis(500).toMillis(); - MiningParameters.Unstable DEFAULT = ImmutableMiningParameters.Unstable.builder().build(); + MiningConfiguration.Unstable DEFAULT = ImmutableMiningConfiguration.Unstable.builder().build(); @Value.Default default int getRemoteSealersLimit() { diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParametersMetrics.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParametersMetrics.java index 3b3e3a28dc..8be0b621a3 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParametersMetrics.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParametersMetrics.java @@ -22,18 +22,18 @@ public class MiningParametersMetrics { public static final String MIN_PRIORITY_FEE_GAUGE = "min_priority_fee"; public MiningParametersMetrics( - final MetricsSystem metricsSystem, final MiningParameters miningParameters) { + final MetricsSystem metricsSystem, final MiningConfiguration miningConfiguration) { metricsSystem.createGauge( BesuMetricCategory.ETHEREUM, MIN_GAS_PRICE_GAUGE, "Gauge to measure the runtime value of min-gas-price", - () -> miningParameters.getMinTransactionGasPrice().toBigInteger().doubleValue()); + () -> miningConfiguration.getMinTransactionGasPrice().toBigInteger().doubleValue()); metricsSystem.createGauge( BesuMetricCategory.ETHEREUM, MIN_PRIORITY_FEE_GAUGE, "Gauge to measure the runtime value of min-priority-fee", - () -> miningParameters.getMinPriorityFeePerGas().toBigInteger().doubleValue()); + () -> miningConfiguration.getMinPriorityFeePerGas().toBigInteger().doubleValue()); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/CoinbaseModule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/CoinbaseModule.java new file mode 100644 index 0000000000..bb613b4e17 --- /dev/null +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/CoinbaseModule.java @@ -0,0 +1,31 @@ +/* + * Copyright contributors to Hyperledger Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.core.components; + +import org.hyperledger.besu.datatypes.Address; + +import javax.inject.Named; + +import dagger.Module; +import dagger.Provides; + +@Module +public class CoinbaseModule { + @Provides + @Named("emptyCoinbase") + Address provideEmptyCoinbase() { + return Address.fromHexString(String.format("%020x", 1)); + } +} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/EthereumCoreComponent.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/EthereumCoreComponent.java new file mode 100644 index 0000000000..84de2cef5d --- /dev/null +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/EthereumCoreComponent.java @@ -0,0 +1,32 @@ +/* + * Copyright contributors to Hyperledger Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.core.components; + +import org.hyperledger.besu.ethereum.components.ProtocolScheduleModule; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; + +import javax.inject.Singleton; + +import dagger.Subcomponent; + +@Singleton +@Subcomponent( + modules = { + MiningParametersModule.class, + ProtocolScheduleModule.class, + }) +public interface EthereumCoreComponent { + MiningConfiguration getMiningParameters(); +} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/MiningParametersModule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/MiningParametersModule.java new file mode 100644 index 0000000000..7a36e4d81a --- /dev/null +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/MiningParametersModule.java @@ -0,0 +1,64 @@ +/* + * Copyright contributors to Hyperledger Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.core.components; + +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; + +import javax.inject.Named; + +import dagger.Module; +import dagger.Provides; + +@Module +public class MiningParametersModule { + + @Provides + @Named("defaultMiningParameters") + protected MiningConfiguration createImmutableMiningParams() { + return ImmutableMiningConfiguration.builder().build(); + } + + @Provides + @Named("noMining") + protected MiningConfiguration createNoMining() { + return ImmutableMiningConfiguration.builder() + .mutableInitValues( + ImmutableMiningConfiguration.MutableInitValues.builder().isMiningEnabled(false).build()) + .build(); + } + + @Provides + @Named("zeroGas") + MiningConfiguration createZeroGasMining(final @Named("emptyCoinbase") Address coinbase) { + final MiningConfiguration miningConfiguration = + ImmutableMiningConfiguration.builder() + .mutableInitValues( + ImmutableMiningConfiguration.MutableInitValues.builder() + .isMiningEnabled(true) + .minTransactionGasPrice(Wei.ZERO) + .coinbase(coinbase) + .build()) + .build(); + return miningConfiguration; + } + + @Provides + MiningConfiguration provideMiningParameters() { + throw new IllegalStateException("unimplemented"); + } +} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyCalculators.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyCalculators.java index ceaf06e353..692d3810c3 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyCalculators.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyCalculators.java @@ -34,6 +34,6 @@ public class FixedDifficultyCalculators { public static DifficultyCalculator calculator(final GenesisConfigOptions config) { long difficulty = config.getEthashConfigOptions().getFixedDifficulty().getAsLong(); - return (time, parent, context) -> BigInteger.valueOf(difficulty); + return (time, parent) -> BigInteger.valueOf(difficulty); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java index b86b2b0de2..09ca09ff6a 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java @@ -16,7 +16,7 @@ package org.hyperledger.besu.ethereum.difficulty.fixed; import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder; @@ -24,7 +24,12 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecAdapters; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.plugin.services.MetricsSystem; -/** A ProtocolSchedule which behaves similarly to MainNet, but with a much reduced difficulty. */ +import java.util.Optional; + +/** + * A ProtocolSchedule which behaves similarly to pre-merge MainNet, but with a much reduced + * difficulty. + */ public class FixedDifficultyProtocolSchedule { public static ProtocolSchedule create( @@ -32,12 +37,13 @@ public class FixedDifficultyProtocolSchedule { final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { return new ProtocolScheduleBuilder( config, + Optional.empty(), ProtocolSpecAdapters.create( 0, builder -> @@ -45,7 +51,7 @@ public class FixedDifficultyProtocolSchedule { privacyParameters, isRevertReasonEnabled, evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem) @@ -56,7 +62,7 @@ public class FixedDifficultyProtocolSchedule { final GenesisConfigOptions config, final boolean isRevertReasonEnabled, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -65,7 +71,7 @@ public class FixedDifficultyProtocolSchedule { PrivacyParameters.DEFAULT, isRevertReasonEnabled, evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); @@ -74,7 +80,7 @@ public class FixedDifficultyProtocolSchedule { public static ProtocolSchedule create( final GenesisConfigOptions config, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -83,7 +89,7 @@ public class FixedDifficultyProtocolSchedule { PrivacyParameters.DEFAULT, false, evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BaseFeeBlockBodyValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BaseFeeBlockBodyValidator.java index 0d43a47022..62629dde66 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BaseFeeBlockBodyValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BaseFeeBlockBodyValidator.java @@ -41,11 +41,9 @@ public class BaseFeeBlockBodyValidator extends MainnetBlockBodyValidator { final ProtocolContext context, final Block block, final List receipts, - final HeaderValidationMode ommerValidationMode, - final BodyValidationMode bodyValidationMode) { + final HeaderValidationMode ommerValidationMode) { - return super.validateBodyLight( - context, block, receipts, ommerValidationMode, bodyValidationMode) + return super.validateBodyLight(context, block, receipts, ommerValidationMode) && validateTransactionGasPrice(block); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BlockBodyValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BlockBodyValidator.java index 32000d12b9..53fb0f4243 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BlockBodyValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BlockBodyValidator.java @@ -33,14 +33,16 @@ public interface BlockBodyValidator { * @param worldStateRootHash The rootHash defining the world state after processing this block and * all of its transactions. * @param ommerValidationMode The validation mode to use for ommer headers + * @param bodyValidationMode The validation mode to use for the body * @return {@code true} if valid; otherwise {@code false} */ boolean validateBody( - ProtocolContext context, - Block block, - List receipts, - Hash worldStateRootHash, - final HeaderValidationMode ommerValidationMode); + final ProtocolContext context, + final Block block, + final List receipts, + final Hash worldStateRootHash, + final HeaderValidationMode ommerValidationMode, + final BodyValidationMode bodyValidationMode); /** * Validates that the block body is valid, but skips state root validation. @@ -55,6 +57,5 @@ public interface BlockBodyValidator { ProtocolContext context, Block block, List receipts, - final HeaderValidationMode ommerValidationMode, - final BodyValidationMode bodyValidationMode); + final HeaderValidationMode ommerValidationMode); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidationMode.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidationMode.java index 344a950e36..b8f7ca6028 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidationMode.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidationMode.java @@ -21,6 +21,9 @@ public enum BodyValidationMode { /** Skip receipts and transactions root validation */ LIGHT, + /** Validate transactions, state, and receipts root */ + ROOT_ONLY, + /** Fully validate the body */ FULL; } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicDifficultyCalculators.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicDifficultyCalculators.java index 9a8f30d01f..6e15eb87e0 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicDifficultyCalculators.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicDifficultyCalculators.java @@ -32,7 +32,7 @@ public abstract class ClassicDifficultyCalculators { private static final long DELAY = (CONTINUE_BLOCK - PAUSE_BLOCK) / EXPONENTIAL_DIFF_PERIOD; public static DifficultyCalculator DIFFICULTY_BOMB_PAUSED = - (time, parent, protocolContext) -> { + (time, parent) -> { final BigInteger parentDifficulty = difficulty(parent.getDifficulty()); final BigInteger difficulty = ensureMinimumDifficulty( @@ -43,7 +43,7 @@ public abstract class ClassicDifficultyCalculators { }; public static DifficultyCalculator DIFFICULTY_BOMB_DELAYED = - (time, parent, protocolContext) -> { + (time, parent) -> { final BigInteger parentDifficulty = difficulty(parent.getDifficulty()); final BigInteger difficulty = ensureMinimumDifficulty( @@ -55,7 +55,7 @@ public abstract class ClassicDifficultyCalculators { }; public static DifficultyCalculator DIFFICULTY_BOMB_REMOVED = - (time, parent, protocolContext) -> { + (time, parent) -> { final BigInteger parentDifficulty = difficulty(parent.getDifficulty()); final BigInteger difficulty = ensureMinimumDifficulty( @@ -66,7 +66,7 @@ public abstract class ClassicDifficultyCalculators { }; public static DifficultyCalculator EIP100 = - (time, parent, protocolContext) -> { + (time, parent) -> { final BigInteger parentDifficulty = difficulty(parent.getDifficulty()); final boolean hasOmmers = !parent.getOmmersHash().equals(Hash.EMPTY_LIST_HASH); final BigInteger difficulty = diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClearEmptyAccountStrategy.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClearEmptyAccountStrategy.java index 004aab5921..92bfaac370 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClearEmptyAccountStrategy.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClearEmptyAccountStrategy.java @@ -26,11 +26,18 @@ public interface ClearEmptyAccountStrategy { void process(final WorldUpdater worldUpdater); + boolean clearEmptyAccountAllowed(final Address address); + class NotClearEmptyAccount implements ClearEmptyAccountStrategy { @Override public void process(final WorldUpdater worldUpdater) { // nothing to do in this case } + + @Override + public boolean clearEmptyAccountAllowed(final Address address) { + return false; + } } class ClearEmptyAccount implements ClearEmptyAccountStrategy { @@ -41,6 +48,10 @@ public interface ClearEmptyAccountStrategy { .filter(Account::isEmpty) .forEach(a -> worldUpdater.deleteAccount(a.getAddress())); } + @Override + public boolean clearEmptyAccountAllowed(final Address address) { + return true; + } } class ClearEmptyAccountWithException implements ClearEmptyAccountStrategy { @@ -59,5 +70,10 @@ public interface ClearEmptyAccountStrategy { .filter(Account::isEmpty) .forEach(a -> worldUpdater.deleteAccount(a.getAddress())); } + + @Override + public boolean clearEmptyAccountAllowed(final Address address) { + return !exceptionList.contains(address); + } } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculator.java index d03bede977..408f83cb51 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculator.java @@ -14,7 +14,6 @@ */ package org.hyperledger.besu.ethereum.mainnet; -import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockHeader; import java.math.BigInteger; @@ -28,8 +27,7 @@ public interface DifficultyCalculator { * * @param time the time the block was generated * @param parent the block's parent block header - * @param context the context in which the difficulty calculator should operate * @return the block difficulty */ - BigInteger nextDifficulty(long time, BlockHeader parent, ProtocolContext context); + BigInteger nextDifficulty(long time, BlockHeader parent); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidator.java index 1423183e94..ccb16a587a 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidator.java @@ -50,10 +50,39 @@ public class MainnetBlockBodyValidator implements BlockBodyValidator { final Block block, final List receipts, final Hash worldStateRootHash, - final HeaderValidationMode ommerValidationMode) { + final HeaderValidationMode ommerValidationMode, + final BodyValidationMode bodyValidationMode) { + if (bodyValidationMode == BodyValidationMode.NONE) { + return true; + } + + if (bodyValidationMode == BodyValidationMode.LIGHT + || bodyValidationMode == BodyValidationMode.FULL) { + if (!validateBodyLight(context, block, receipts, ommerValidationMode)) { + return false; + } + } + + if (bodyValidationMode == BodyValidationMode.ROOT_ONLY + || bodyValidationMode == BodyValidationMode.FULL) { + return validateBodyRoots(block, receipts, worldStateRootHash); + } + return true; + } + + @VisibleForTesting + protected boolean validateBodyRoots( + final Block block, final List receipts, final Hash worldStateRootHash) { + final BlockHeader header = block.getHeader(); + final BlockBody body = block.getBody(); + + final Bytes32 transactionsRoot = BodyValidation.transactionsRoot(body.getTransactions()); + if (!validateTransactionsRoot(header, header.getTransactionsRoot(), transactionsRoot)) { + return false; + } - if (!validateBodyLight( - context, block, receipts, ommerValidationMode, BodyValidationMode.FULL)) { + final Bytes32 receiptsRoot = BodyValidation.receiptsRoot(receipts); + if (!validateReceiptsRoot(header, header.getReceiptsRoot(), receiptsRoot)) { return false; } @@ -65,7 +94,6 @@ public class MainnetBlockBodyValidator implements BlockBodyValidator { LOG.warn("Transaction receipt found in the invalid block {}", receipt.toString())); return false; } - return true; } @@ -74,27 +102,9 @@ public class MainnetBlockBodyValidator implements BlockBodyValidator { final ProtocolContext context, final Block block, final List receipts, - final HeaderValidationMode ommerValidationMode, - final BodyValidationMode bodyValidationMode) { - if (bodyValidationMode == BodyValidationMode.NONE) { - return true; - } + final HeaderValidationMode ommerValidationMode) { final BlockHeader header = block.getHeader(); - final BlockBody body = block.getBody(); - - // these checks are only needed for full validation and can be skipped for light validation - if (bodyValidationMode == BodyValidationMode.FULL) { - final Bytes32 transactionsRoot = BodyValidation.transactionsRoot(body.getTransactions()); - if (!validateTransactionsRoot(header, header.getTransactionsRoot(), transactionsRoot)) { - return false; - } - - final Bytes32 receiptsRoot = BodyValidation.receiptsRoot(receipts); - if (!validateReceiptsRoot(header, header.getReceiptsRoot(), receiptsRoot)) { - return false; - } - } final long gasUsed = receipts.isEmpty() ? 0 : receipts.get(receipts.size() - 1).getCumulativeGasUsed(); @@ -113,15 +123,13 @@ public class MainnetBlockBodyValidator implements BlockBodyValidator { if (!validateWithdrawals(block)) { return false; } - return true; } - @VisibleForTesting - protected boolean validateTransactionsRoot( + private boolean validateTransactionsRoot( final BlockHeader header, final Bytes32 expected, final Bytes32 actual) { if (!expected.equals(actual)) { - LOG.info( + LOG.warn( "Invalid block {}: transaction root mismatch (expected={}, actual={})", header.toLogString(), expected, @@ -160,8 +168,7 @@ public class MainnetBlockBodyValidator implements BlockBodyValidator { return true; } - @VisibleForTesting - protected boolean validateReceiptsRoot( + private boolean validateReceiptsRoot( final BlockHeader header, final Bytes32 expected, final Bytes32 actual) { if (!expected.equals(actual)) { LOG.warn( @@ -175,7 +182,7 @@ public class MainnetBlockBodyValidator implements BlockBodyValidator { return true; } - private static boolean validateStateRoot( + private boolean validateStateRoot( final BlockHeader header, final Bytes32 expected, final Bytes32 actual) { if (!expected.equals(actual)) { LOG.warn( diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetDifficultyCalculators.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetDifficultyCalculators.java index 46f0a05e5d..2129b10d5d 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetDifficultyCalculators.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetDifficultyCalculators.java @@ -45,7 +45,7 @@ public abstract class MainnetDifficultyCalculators { private MainnetDifficultyCalculators() {} static final DifficultyCalculator FRONTIER = - (time, parent, protocolContext) -> { + (time, parent) -> { final BigInteger parentDifficulty = difficulty(parent.getDifficulty()); final BigInteger adjust = parentDifficulty.divide(DIFFICULTY_BOUND_DIVISOR); BigInteger difficulty; @@ -60,7 +60,7 @@ public abstract class MainnetDifficultyCalculators { }; static final DifficultyCalculator HOMESTEAD = - (time, parent, protocolContext) -> { + (time, parent) -> { final BigInteger parentDifficulty = difficulty(parent.getDifficulty()); final BigInteger difficulty = ensureMinimumDifficulty( @@ -72,35 +72,28 @@ public abstract class MainnetDifficultyCalculators { }; static final DifficultyCalculator BYZANTIUM = - (time, parent, protocolContext) -> - calculateThawedDifficulty(time, parent, BYZANTIUM_FAKE_BLOCK_OFFSET); + (time, parent) -> calculateThawedDifficulty(time, parent, BYZANTIUM_FAKE_BLOCK_OFFSET); static final DifficultyCalculator CONSTANTINOPLE = - (time, parent, protocolContext) -> - calculateThawedDifficulty(time, parent, CONSTANTINOPLE_FAKE_BLOCK_OFFSET); + (time, parent) -> calculateThawedDifficulty(time, parent, CONSTANTINOPLE_FAKE_BLOCK_OFFSET); static final DifficultyCalculator MUIR_GLACIER = - (time, parent, protocolContext) -> - calculateThawedDifficulty(time, parent, MUIR_GLACIER_FAKE_BLOCK_OFFSET); + (time, parent) -> calculateThawedDifficulty(time, parent, MUIR_GLACIER_FAKE_BLOCK_OFFSET); // As per https://eips.ethereum.org/EIPS/eip-3554 static final DifficultyCalculator LONDON = - (time, parent, protocolContext) -> - calculateThawedDifficulty(time, parent, LONDON_FAKE_BLOCK_OFFSET); + (time, parent) -> calculateThawedDifficulty(time, parent, LONDON_FAKE_BLOCK_OFFSET); // As per https://eips.ethereum.org/EIPS/eip-4345 static final DifficultyCalculator ARROW_GLACIER = - (time, parent, protocolContext) -> - calculateThawedDifficulty(time, parent, ARROW_GLACIER_FAKE_BLOCK_OFFSET); + (time, parent) -> calculateThawedDifficulty(time, parent, ARROW_GLACIER_FAKE_BLOCK_OFFSET); // As per https://eips.ethereum.org/EIPS/eip-5133 static final DifficultyCalculator GRAY_GLACIER = - (time, parent, protocolContext) -> - calculateThawedDifficulty(time, parent, GRAY_GLACIER_FAKE_BLOCK_OFFSET); + (time, parent) -> calculateThawedDifficulty(time, parent, GRAY_GLACIER_FAKE_BLOCK_OFFSET); // Proof-of-Stake difficulty must not be altered - static final DifficultyCalculator PROOF_OF_STAKE_DIFFICULTY = - (time, parent, protocolContext) -> BigInteger.ZERO; + static final DifficultyCalculator PROOF_OF_STAKE_DIFFICULTY = (time, parent) -> BigInteger.ZERO; private static BigInteger calculateThawedDifficulty( final long time, final BlockHeader parent, final long fakeBlockOffset) { diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSchedule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSchedule.java index 88b6a5ae1b..9528e2dfb8 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSchedule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSchedule.java @@ -16,7 +16,7 @@ package org.hyperledger.besu.ethereum.mainnet; import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyCalculators; import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule; @@ -24,6 +24,7 @@ import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.plugin.services.MetricsSystem; import java.math.BigInteger; +import java.util.Optional; import java.util.function.Function; /** Provides {@link ProtocolSpec} lookups for mainnet hard forks. */ @@ -39,7 +40,7 @@ public class MainnetProtocolSchedule { * @param privacyParameters the parameters set for private transactions * @param isRevertReasonEnabled whether storing the revert reason is for failed transactions * @param evmConfiguration how to configure the EVMs jumpdest cache - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled * @param metricsSystem A metricSystem instance to expose metrics in the underlying calls @@ -47,32 +48,32 @@ public class MainnetProtocolSchedule { */ public static ProtocolSchedule fromConfig( final GenesisConfigOptions config, - final PrivacyParameters privacyParameters, - final boolean isRevertReasonEnabled, - final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final Optional privacyParameters, + final Optional isRevertReasonEnabled, + final Optional evmConfiguration, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { if (FixedDifficultyCalculators.isFixedDifficultyInConfig(config)) { return FixedDifficultyProtocolSchedule.create( config, - privacyParameters, - isRevertReasonEnabled, - evmConfiguration, - miningParameters, + privacyParameters.orElse(PrivacyParameters.DEFAULT), + isRevertReasonEnabled.orElse(false), + evmConfiguration.orElse(EvmConfiguration.DEFAULT), + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); } return new ProtocolScheduleBuilder( config, - DEFAULT_CHAIN_ID, + Optional.of(DEFAULT_CHAIN_ID), ProtocolSpecAdapters.create(0, Function.identity()), - privacyParameters, - isRevertReasonEnabled, - evmConfiguration, - miningParameters, + privacyParameters.orElse(PrivacyParameters.DEFAULT), + isRevertReasonEnabled.orElse(false), + evmConfiguration.orElse(EvmConfiguration.DEFAULT), + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem) @@ -86,7 +87,7 @@ public class MainnetProtocolSchedule { * starting points * @param isRevertReasonEnabled whether storing the revert reason is for failed transactions * @param evmConfiguration how to configure the EVMs jumpdest cache - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled. * @return A configured mainnet protocol schedule @@ -95,16 +96,16 @@ public class MainnetProtocolSchedule { final GenesisConfigOptions config, final boolean isRevertReasonEnabled, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { return fromConfig( config, - PrivacyParameters.DEFAULT, - isRevertReasonEnabled, - evmConfiguration, - miningParameters, + Optional.empty(), + Optional.of(isRevertReasonEnabled), + Optional.of(evmConfiguration), + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); @@ -116,7 +117,7 @@ public class MainnetProtocolSchedule { * @param config {@link GenesisConfigOptions} containing the config options for the milestone * starting points * @param evmConfiguration size of - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled. * @return A configured mainnet protocol schedule @@ -124,16 +125,16 @@ public class MainnetProtocolSchedule { public static ProtocolSchedule fromConfig( final GenesisConfigOptions config, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { return fromConfig( config, - PrivacyParameters.DEFAULT, - false, - evmConfiguration, - miningParameters, + Optional.empty(), + Optional.empty(), + Optional.of(evmConfiguration), + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); @@ -144,23 +145,23 @@ public class MainnetProtocolSchedule { * * @param config {@link GenesisConfigOptions} containing the config options for the milestone * starting points - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled. * @return A configured mainnet protocol schedule */ public static ProtocolSchedule fromConfig( final GenesisConfigOptions config, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { return fromConfig( config, - PrivacyParameters.DEFAULT, - false, - EvmConfiguration.DEFAULT, - miningParameters, + Optional.empty(), + Optional.empty(), + Optional.empty(), + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecFactory.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecFactory.java index aa09948e7e..d22b367160 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecFactory.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecFactory.java @@ -15,7 +15,7 @@ package org.hyperledger.besu.ethereum.mainnet; import org.hyperledger.besu.config.GenesisConfigOptions; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.plugin.services.MetricsSystem; @@ -29,7 +29,7 @@ public class MainnetProtocolSpecFactory { private final boolean isRevertReasonEnabled; private final OptionalLong ecip1017EraRounds; private final EvmConfiguration evmConfiguration; - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; private final boolean isParallelTxProcessingEnabled; private final MetricsSystem metricsSystem; @@ -38,14 +38,14 @@ public class MainnetProtocolSpecFactory { final boolean isRevertReasonEnabled, final OptionalLong ecip1017EraRounds, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { this.chainId = chainId; this.isRevertReasonEnabled = isRevertReasonEnabled; this.ecip1017EraRounds = ecip1017EraRounds; this.evmConfiguration = evmConfiguration; - this.miningParameters = miningParameters; + this.miningConfiguration = miningConfiguration; this.isParallelTxProcessingEnabled = isParallelTxProcessingEnabled; this.metricsSystem = metricsSystem; } @@ -140,7 +140,7 @@ public class MainnetProtocolSpecFactory { isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } @@ -152,7 +152,7 @@ public class MainnetProtocolSpecFactory { isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } @@ -164,7 +164,7 @@ public class MainnetProtocolSpecFactory { isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } @@ -175,7 +175,7 @@ public class MainnetProtocolSpecFactory { isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } @@ -186,7 +186,7 @@ public class MainnetProtocolSpecFactory { isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } @@ -197,7 +197,7 @@ public class MainnetProtocolSpecFactory { isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } @@ -208,7 +208,7 @@ public class MainnetProtocolSpecFactory { isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } @@ -219,7 +219,7 @@ public class MainnetProtocolSpecFactory { isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } @@ -230,7 +230,7 @@ public class MainnetProtocolSpecFactory { isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } @@ -241,7 +241,7 @@ public class MainnetProtocolSpecFactory { isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } @@ -263,7 +263,7 @@ public class MainnetProtocolSpecFactory { isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } @@ -285,7 +285,7 @@ public class MainnetProtocolSpecFactory { isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java index 26c6d00716..03084b5fcc 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java @@ -25,7 +25,7 @@ import org.hyperledger.besu.ethereum.BlockProcessingResult; import org.hyperledger.besu.ethereum.MainnetBlockValidator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; @@ -450,7 +450,7 @@ public abstract class MainnetProtocolSpecs { final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { final long londonForkBlockNumber = @@ -461,7 +461,7 @@ public abstract class MainnetProtocolSpecs { } else if (genesisConfigOptions.isFixedBaseFee()) { londonFeeMarket = FeeMarket.fixedBaseFee( - londonForkBlockNumber, miningParameters.getMinTransactionGasPrice()); + londonForkBlockNumber, miningConfiguration.getMinTransactionGasPrice()); } else { londonFeeMarket = FeeMarket.london(londonForkBlockNumber, genesisConfigOptions.getBaseFeePerGas()); @@ -536,7 +536,7 @@ public abstract class MainnetProtocolSpecs { final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { return londonDefinition( @@ -544,7 +544,7 @@ public abstract class MainnetProtocolSpecs { enableRevertReason, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem) .difficultyCalculator(MainnetDifficultyCalculators.ARROW_GLACIER) @@ -556,7 +556,7 @@ public abstract class MainnetProtocolSpecs { final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { return arrowGlacierDefinition( @@ -564,7 +564,7 @@ public abstract class MainnetProtocolSpecs { enableRevertReason, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem) .difficultyCalculator(MainnetDifficultyCalculators.GRAY_GLACIER) @@ -576,7 +576,7 @@ public abstract class MainnetProtocolSpecs { final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -585,7 +585,7 @@ public abstract class MainnetProtocolSpecs { enableRevertReason, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem) .evmBuilder( @@ -604,7 +604,7 @@ public abstract class MainnetProtocolSpecs { final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -614,7 +614,7 @@ public abstract class MainnetProtocolSpecs { enableRevertReason, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem) // gas calculator has new code to support EIP-3860 limit and meter initcode @@ -665,7 +665,7 @@ public abstract class MainnetProtocolSpecs { final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { final long londonForkBlockNumber = genesisConfigOptions.getLondonBlockNumber().orElse(0L); @@ -675,7 +675,7 @@ public abstract class MainnetProtocolSpecs { } else if (genesisConfigOptions.isFixedBaseFee()) { cancunFeeMarket = FeeMarket.fixedBaseFee( - londonForkBlockNumber, miningParameters.getMinTransactionGasPrice()); + londonForkBlockNumber, miningConfiguration.getMinTransactionGasPrice()); } else { cancunFeeMarket = FeeMarket.cancun(londonForkBlockNumber, genesisConfigOptions.getBaseFeePerGas()); @@ -686,7 +686,7 @@ public abstract class MainnetProtocolSpecs { enableRevertReason, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem) .feeMarket(cancunFeeMarket) @@ -746,7 +746,7 @@ public abstract class MainnetProtocolSpecs { final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -756,7 +756,7 @@ public abstract class MainnetProtocolSpecs { enableRevertReason, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); return addEOF(chainId, evmConfiguration, protocolSpecBuilder).name("CancunEOF"); @@ -767,7 +767,7 @@ public abstract class MainnetProtocolSpecs { final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -779,7 +779,7 @@ public abstract class MainnetProtocolSpecs { enableRevertReason, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem) // EIP-3074 AUTH and AUTCALL gas @@ -825,7 +825,7 @@ public abstract class MainnetProtocolSpecs { final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -835,7 +835,7 @@ public abstract class MainnetProtocolSpecs { enableRevertReason, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); return addEOF(chainId, evmConfiguration, protocolSpecBuilder).name("Osaka"); @@ -868,7 +868,7 @@ public abstract class MainnetProtocolSpecs { final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { final ClearEmptyAccountStrategy clearEmptyAccountStrategy = @@ -879,7 +879,7 @@ public abstract class MainnetProtocolSpecs { enableRevertReason, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem) .gasCalculator(Eip4762GasCalculator::new) @@ -914,7 +914,7 @@ public abstract class MainnetProtocolSpecs { final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { return osakaDefinition( @@ -922,7 +922,7 @@ public abstract class MainnetProtocolSpecs { enableRevertReason, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem) // Use Future EIP configured EVM @@ -949,7 +949,7 @@ public abstract class MainnetProtocolSpecs { final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -958,7 +958,7 @@ public abstract class MainnetProtocolSpecs { enableRevertReason, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem) .evmBuilder( diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java index 2960ec7d3f..2948f6d722 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java @@ -546,12 +546,14 @@ public class MainnetTransactionProcessor { coinbaseCalculator.price(usedGas, transactionGasPrice, blockHeader.getBaseFee()); operationTracer.traceBeforeRewardTransaction(worldUpdater, transaction, coinbaseWeiDelta); - - final var coinbase = evmWorldUpdater.getOrCreate(miningBeneficiary); - coinbase.incrementBalance(coinbaseWeiDelta); + if (!coinbaseWeiDelta.isZero() + || !clearEmptyAccountStrategy.clearEmptyAccountAllowed(miningBeneficiary)) { + final var coinbase = evmWorldUpdater.getOrCreate(miningBeneficiary); + coinbase.incrementBalance(coinbaseWeiDelta); + } operationTracer.traceEndTransaction( - worldUpdater, + evmWorldUpdater.updater(), transaction, initialFrame.getState() == MessageFrame.State.COMPLETED_SUCCESS, initialFrame.getOutputData(), diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWSolver.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWSolver.java index 3161490478..aafc61e71d 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWSolver.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWSolver.java @@ -15,7 +15,7 @@ package org.hyperledger.besu.ethereum.mainnet; import org.hyperledger.besu.ethereum.chain.PoWObserver; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.util.Subscribers; import java.util.Optional; @@ -34,7 +34,7 @@ public class PoWSolver { private static final Logger LOG = LoggerFactory.getLogger(PoWSolver.class); - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; public static class PoWSolverJob { @@ -86,12 +86,12 @@ public class PoWSolver { private final ExpiringMap currentJobs = new ExpiringMap<>(); public PoWSolver( - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final PoWHasher poWHasher, final Boolean stratumMiningEnabled, final Subscribers ethHashObservers, final EpochCalculator epochCalculator) { - this.miningParameters = miningParameters; + this.miningConfiguration = miningConfiguration; this.poWHasher = poWHasher; this.stratumMiningEnabled = stratumMiningEnabled; this.ethHashObservers = ethHashObservers; @@ -105,7 +105,7 @@ public class PoWSolver { currentJobs.put( job.getInputs().getPrePowHash(), job, - System.currentTimeMillis() + miningParameters.getUnstable().getPowJobTimeToLive()); + System.currentTimeMillis() + miningConfiguration.getUnstable().getPowJobTimeToLive()); if (stratumMiningEnabled) { LOG.debug( "solving with stratum miner for {} observers", ethHashObservers.getSubscriberCount()); @@ -121,7 +121,7 @@ public class PoWSolver { final Stopwatch operationTimer = Stopwatch.createStarted(); final PoWSolverJob job = currentJob.get(); long hashesExecuted = 0; - for (final Long n : miningParameters.getNonceGenerator().get()) { + for (final Long n : miningConfiguration.getNonceGenerator().get()) { if (job.isDone()) { return; @@ -181,7 +181,7 @@ public class PoWSolver { solution.getPowHash(), ommerCandidate.getInputs().getBlockNumber(), distanceToHead); - if (distanceToHead <= miningParameters.getUnstable().getMaxOmmerDepth()) { + if (distanceToHead <= miningConfiguration.getUnstable().getMaxOmmerDepth()) { jobToTestWith = ommerCandidate; } else { LOG.debug("Discarded ommer solution as too far from head {}", distanceToHead); @@ -211,6 +211,6 @@ public class PoWSolver { } public Iterable getNonceGenerator() { - return miningParameters.getNonceGenerator().get(); + return miningConfiguration.getNonceGenerator().get(); } } 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 a2ceed2f5b..18cb7e9462 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 @@ -18,7 +18,7 @@ import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.datatypes.HardforkId; import org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.privacy.PrivateTransactionValidator; import org.hyperledger.besu.evm.internal.EvmConfiguration; @@ -48,66 +48,19 @@ public class ProtocolScheduleBuilder { private final PrivacyParameters privacyParameters; private final boolean isRevertReasonEnabled; private final EvmConfiguration evmConfiguration; - private final MiningParameters miningParameters; private final BadBlockManager badBlockManager; private final boolean isParallelTxProcessingEnabled; private final MetricsSystem metricsSystem; + private final MiningConfiguration miningConfiguration; public ProtocolScheduleBuilder( - final GenesisConfigOptions config, - final BigInteger defaultChainId, - final ProtocolSpecAdapters protocolSpecAdapters, - final PrivacyParameters privacyParameters, - final boolean isRevertReasonEnabled, - final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, - final BadBlockManager badBlockManager, - final boolean isParallelTxProcessingEnabled, - final MetricsSystem metricsSystem) { - this( - config, - Optional.of(defaultChainId), - protocolSpecAdapters, - privacyParameters, - isRevertReasonEnabled, - evmConfiguration, - miningParameters, - badBlockManager, - isParallelTxProcessingEnabled, - metricsSystem); - } - - public ProtocolScheduleBuilder( - final GenesisConfigOptions config, - final ProtocolSpecAdapters protocolSpecAdapters, - final PrivacyParameters privacyParameters, - final boolean isRevertReasonEnabled, - final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, - final BadBlockManager badBlockManager, - final boolean isParallelTxProcessingEnabled, - final MetricsSystem metricsSystem) { - this( - config, - Optional.empty(), - protocolSpecAdapters, - privacyParameters, - isRevertReasonEnabled, - evmConfiguration, - miningParameters, - badBlockManager, - isParallelTxProcessingEnabled, - metricsSystem); - } - - private ProtocolScheduleBuilder( final GenesisConfigOptions config, final Optional defaultChainId, final ProtocolSpecAdapters protocolSpecAdapters, final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -117,10 +70,10 @@ public class ProtocolScheduleBuilder { this.isRevertReasonEnabled = isRevertReasonEnabled; this.evmConfiguration = evmConfiguration; this.defaultChainId = defaultChainId; - this.miningParameters = miningParameters; this.badBlockManager = badBlockManager; this.isParallelTxProcessingEnabled = isParallelTxProcessingEnabled; this.metricsSystem = metricsSystem; + this.miningConfiguration = miningConfiguration; } public ProtocolSchedule createProtocolSchedule() { @@ -130,7 +83,7 @@ public class ProtocolScheduleBuilder { return protocolSchedule; } - private void initSchedule( + public void initSchedule( final ProtocolSchedule protocolSchedule, final Optional chainId) { final MainnetProtocolSpecFactory specFactory = @@ -140,7 +93,7 @@ public class ProtocolScheduleBuilder { config.getEcip1017EraRounds(), evmConfiguration.overrides( config.getContractSizeLimit(), OptionalInt.empty(), config.getEvmStackSize()), - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); @@ -562,4 +515,8 @@ public class ProtocolScheduleBuilder { TIMESTAMP } } + + public Optional getDefaultChainId() { + return defaultChainId; + } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/CalculatedDifficultyValidationRule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/CalculatedDifficultyValidationRule.java index bcc4e21358..1eb4f044c2 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/CalculatedDifficultyValidationRule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/CalculatedDifficultyValidationRule.java @@ -39,7 +39,7 @@ public class CalculatedDifficultyValidationRule implements AttachedBlockHeaderVa final BigInteger actualDifficulty = new BigInteger(1, header.getDifficulty().toArray()); final BigInteger expectedDifficulty = - difficultyCalculator.nextDifficulty(header.getTimestamp(), parent, context); + difficultyCalculator.nextDifficulty(header.getTimestamp(), parent); if (actualDifficulty.compareTo(expectedDifficulty) != 0) { LOG.info( diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/PrivacyPluginPrecompiledContract.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/PrivacyPluginPrecompiledContract.java index 723af2efa4..708aa118f0 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/PrivacyPluginPrecompiledContract.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/PrivacyPluginPrecompiledContract.java @@ -34,6 +34,7 @@ import org.apache.tuweni.bytes.Bytes32; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class PrivacyPluginPrecompiledContract extends PrivacyPrecompiledContract { private static final Logger LOG = LoggerFactory.getLogger(PrivacyPluginPrecompiledContract.class); private final PrivacyParameters privacyParameters; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/proof/WorldStateProof.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/proof/WorldStateProof.java index 91c492e69c..8853dc2371 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/proof/WorldStateProof.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/proof/WorldStateProof.java @@ -16,7 +16,7 @@ package org.hyperledger.besu.ethereum.proof; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.trie.Proof; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import java.util.ArrayList; import java.util.List; @@ -29,14 +29,14 @@ import org.apache.tuweni.units.bigints.UInt256; public class WorldStateProof { - private final StateTrieAccountValue stateTrieAccountValue; + private final PmtStateTrieAccountValue stateTrieAccountValue; private final Proof accountProof; private final Map> storageProofs; public WorldStateProof( - final StateTrieAccountValue stateTrieAccountValue, + final PmtStateTrieAccountValue stateTrieAccountValue, final Proof accountProof, final SortedMap> storageProofs) { this.stateTrieAccountValue = stateTrieAccountValue; @@ -44,7 +44,7 @@ public class WorldStateProof { this.storageProofs = storageProofs; } - public StateTrieAccountValue getStateTrieAccountValue() { + public PmtStateTrieAccountValue getStateTrieAccountValue() { return stateTrieAccountValue; } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/proof/WorldStateProofProvider.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/proof/WorldStateProofProvider.java index 3d8ed037d3..71254e7620 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/proof/WorldStateProofProvider.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/proof/WorldStateProofProvider.java @@ -22,10 +22,10 @@ import org.hyperledger.besu.ethereum.trie.InnerNodeDiscoveryManager.InnerNode; import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.MerkleTrieException; import org.hyperledger.besu.ethereum.trie.Proof; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.patricia.RemoveVisitor; import org.hyperledger.besu.ethereum.trie.patricia.SimpleMerklePatriciaTrie; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import java.util.Comparator; @@ -72,7 +72,7 @@ public class WorldStateProofProvider { return accountProof .getValue() .map(RLP::input) - .map(StateTrieAccountValue::readFrom) + .map(PmtStateTrieAccountValue::readFrom) .map( account -> { final SortedMap> storageProofs = @@ -84,7 +84,7 @@ public class WorldStateProofProvider { private SortedMap> getStorageProofs( final Hash accountHash, - final StateTrieAccountValue account, + final PmtStateTrieAccountValue account, final List accountStorageKeys) { final MerkleTrie storageTrie = newAccountStorageTrie(accountHash, account.getStorageRoot()); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java index 321dc965ec..1c6140f1d1 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java @@ -19,6 +19,8 @@ import static org.hyperledger.besu.ethereum.mainnet.feemarket.ExcessBlobGasCalcu import org.hyperledger.besu.crypto.SECPSignature; import org.hyperledger.besu.crypto.SignatureAlgorithm; import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; +import org.hyperledger.besu.datatypes.AccountOverride; +import org.hyperledger.besu.datatypes.AccountOverrideMap; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.BlobGas; import org.hyperledger.besu.datatypes.Hash; @@ -38,6 +40,7 @@ import org.hyperledger.besu.ethereum.vm.CachingBlockHashLookup; import org.hyperledger.besu.ethereum.vm.DebugOperationTracer; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.evm.account.Account; +import org.hyperledger.besu.evm.account.MutableAccount; import org.hyperledger.besu.evm.tracing.OperationTracer; import org.hyperledger.besu.evm.worldstate.WorldUpdater; @@ -46,8 +49,10 @@ import java.util.Optional; import java.util.function.Supplier; import javax.annotation.Nonnull; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Suppliers; import org.apache.tuweni.bytes.Bytes; +import org.apache.tuweni.units.bigints.UInt256; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -100,6 +105,7 @@ public class TransactionSimulator { final BlockHeader header = blockchain.getBlockHeader(blockNumber).orElse(null); return process( callParams, + Optional.empty(), transactionValidationParams, operationTracer, (mutableWorldState, transactionSimulatorResult) -> transactionSimulatorResult, @@ -113,6 +119,22 @@ public class TransactionSimulator { final BlockHeader blockHeader) { return process( callParams, + Optional.empty(), + transactionValidationParams, + operationTracer, + (mutableWorldState, transactionSimulatorResult) -> transactionSimulatorResult, + blockHeader); + } + + public Optional process( + final CallParameter callParams, + final Optional maybeStateOverrides, + final TransactionValidationParams transactionValidationParams, + final OperationTracer operationTracer, + final BlockHeader blockHeader) { + return process( + callParams, + maybeStateOverrides, transactionValidationParams, operationTracer, (mutableWorldState, transactionSimulatorResult) -> transactionSimulatorResult, @@ -152,6 +174,35 @@ public class TransactionSimulator { final OperationTracer operationTracer, final PreCloseStateHandler preWorldStateCloseGuard, final BlockHeader header) { + return process( + callParams, + Optional.empty(), + transactionValidationParams, + operationTracer, + preWorldStateCloseGuard, + header); + } + + /** + * Processes a transaction simulation with the provided parameters and executes pre-worldstate + * close actions. + * + * @param callParams The call parameters for the transaction. + * @param maybeStateOverrides The map of state overrides to apply to the state for this + * transaction. + * @param transactionValidationParams The validation parameters for the transaction. + * @param operationTracer The tracer for capturing operations during processing. + * @param preWorldStateCloseGuard The pre-worldstate close guard for executing pre-close actions. + * @param header The block header. + * @return An Optional containing the result of the processing. + */ + public Optional process( + final CallParameter callParams, + final Optional maybeStateOverrides, + final TransactionValidationParams transactionValidationParams, + final OperationTracer operationTracer, + final PreCloseStateHandler preWorldStateCloseGuard, + final BlockHeader header) { if (header == null) { return Optional.empty(); } @@ -169,7 +220,12 @@ public class TransactionSimulator { return preWorldStateCloseGuard.apply( ws, processWithWorldUpdater( - callParams, transactionValidationParams, operationTracer, header, updater)); + callParams, + maybeStateOverrides, + transactionValidationParams, + operationTracer, + header, + updater)); } catch (final Exception e) { return Optional.empty(); @@ -208,6 +264,7 @@ public class TransactionSimulator { @Nonnull public Optional processWithWorldUpdater( final CallParameter callParams, + final Optional maybeStateOverrides, final TransactionValidationParams transactionValidationParams, final OperationTracer operationTracer, final BlockHeader header, @@ -226,6 +283,12 @@ public class TransactionSimulator { .blockHeaderFunctions(protocolSpec.getBlockHeaderFunctions()) .buildBlockHeader(); } + if (maybeStateOverrides.isPresent()) { + for (Address accountToOverride : maybeStateOverrides.get().keySet()) { + final AccountOverride overrides = maybeStateOverrides.get().get(accountToOverride); + applyOverrides(updater.getOrCreate(accountToOverride), overrides); + } + } final Account sender = updater.get(senderAddress); final long nonce = sender != null ? sender.getNonce() : 0L; @@ -284,6 +347,24 @@ public class TransactionSimulator { return Optional.of(new TransactionSimulatorResult(transaction, result)); } + @VisibleForTesting + protected void applyOverrides(final MutableAccount account, final AccountOverride override) { + LOG.debug("applying overrides to state for account {}", account.getAddress()); + override.getNonce().ifPresent(account::setNonce); + if (override.getBalance().isPresent()) { + account.setBalance(override.getBalance().get()); + } + override.getCode().ifPresent(n -> account.setCode(Bytes.fromHexString(n))); + override + .getStateDiff() + .ifPresent( + d -> + d.forEach( + (key, value) -> + account.setStorageValue( + UInt256.fromHexString(key), UInt256.fromHexString(value)))); + } + private long calculateSimulationGasCap( final long userProvidedGasLimit, final long blockGasLimit) { final long simulationGasCap; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/common/AbstractStateTrieAccountValue.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/common/AbstractStateTrieAccountValue.java new file mode 100644 index 0000000000..805aef9b44 --- /dev/null +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/common/AbstractStateTrieAccountValue.java @@ -0,0 +1,81 @@ +/* + * 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.ethereum.trie.common; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.hyperledger.besu.datatypes.AccountValue; +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.rlp.RLPOutput; + +/** Represents the raw values associated with an account in the world state trie. */ +public abstract class AbstractStateTrieAccountValue implements AccountValue { + + protected final long nonce; + protected final Wei balance; + protected final Hash codeHash; + + public AbstractStateTrieAccountValue(final long nonce, final Wei balance, final Hash codeHash) { + checkNotNull(balance, "balance cannot be null"); + checkNotNull(codeHash, "codeHash cannot be null"); + this.nonce = nonce; + this.balance = balance; + this.codeHash = codeHash; + } + + /** + * The account nonce, that is the number of transactions sent from that account. + * + * @return the account nonce. + */ + @Override + public long getNonce() { + return nonce; + } + + /** + * The available balance of that account. + * + * @return the balance, in Wei, of the account. + */ + @Override + public Wei getBalance() { + return balance; + } + + /** + * The hash of the EVM bytecode associated with this account. + * + * @return the hash of the account code (which may be {@link Hash#EMPTY}). + */ + @Override + public Hash getCodeHash() { + return codeHash; + } + + /** + * The hash of the root of the storage trie associated with this account. + * + * @return the hash of the root node of the storage trie. + */ + @Override + public Hash getStorageRoot() { + return Hash.EMPTY_TRIE_HASH; + } + + @Override + public abstract void writeTo(final RLPOutput out); +} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/StateTrieAccountValue.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/common/PmtStateTrieAccountValue.java similarity index 64% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/StateTrieAccountValue.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/common/PmtStateTrieAccountValue.java index 40c420f751..5a291846ea 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/StateTrieAccountValue.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/common/PmtStateTrieAccountValue.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.worldstate; +package org.hyperledger.besu.ethereum.trie.common; import static com.google.common.base.Preconditions.checkNotNull; @@ -26,43 +26,17 @@ import java.util.Objects; import org.apache.tuweni.bytes.Bytes32; -/** Represents the raw values associated with an account in the world state trie. */ -public class StateTrieAccountValue implements AccountValue { +/** Represents the raw values associated with an account in the world state patricia merkle trie. */ +public class PmtStateTrieAccountValue extends AbstractStateTrieAccountValue + implements AccountValue { - protected final long nonce; - protected final Wei balance; protected final Hash storageRoot; - protected final Hash codeHash; - public StateTrieAccountValue( + public PmtStateTrieAccountValue( final long nonce, final Wei balance, final Hash storageRoot, final Hash codeHash) { - checkNotNull(balance, "balance cannot be null"); + super(nonce, balance, codeHash); checkNotNull(storageRoot, "storageRoot cannot be null"); - checkNotNull(codeHash, "codeHash cannot be null"); - this.nonce = nonce; - this.balance = balance; this.storageRoot = storageRoot; - this.codeHash = codeHash; - } - - /** - * The account nonce, that is the number of transactions sent from that account. - * - * @return the account nonce. - */ - @Override - public long getNonce() { - return nonce; - } - - /** - * The available balance of that account. - * - * @return the balance, in Wei, of the account. - */ - @Override - public Wei getBalance() { - return balance; } /** @@ -75,25 +49,15 @@ public class StateTrieAccountValue implements AccountValue { return storageRoot; } - /** - * The hash of the EVM bytecode associated with this account. - * - * @return the hash of the account code (which may be {@link Hash#EMPTY}). - */ - @Override - public Hash getCodeHash() { - return codeHash; - } - @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - final StateTrieAccountValue that = (StateTrieAccountValue) o; + PmtStateTrieAccountValue that = (PmtStateTrieAccountValue) o; return nonce == that.nonce - && balance.equals(that.balance) - && storageRoot.equals(that.storageRoot) - && codeHash.equals(that.codeHash); + && Objects.equals(balance, that.balance) + && Objects.equals(storageRoot, that.storageRoot) + && Objects.equals(codeHash, that.codeHash); } @Override @@ -109,11 +73,10 @@ public class StateTrieAccountValue implements AccountValue { out.writeUInt256Scalar(balance); out.writeBytes(storageRoot); out.writeBytes(codeHash); - out.endList(); } - public static StateTrieAccountValue readFrom(final RLPInput in) { + public static PmtStateTrieAccountValue readFrom(final RLPInput in) { in.enterList(); final long nonce = in.readLongScalar(); @@ -132,9 +95,9 @@ public class StateTrieAccountValue implements AccountValue { } else { codeHash = in.readBytes32(); } - in.leaveList(); - return new StateTrieAccountValue(nonce, balance, Hash.wrap(storageRoot), Hash.wrap(codeHash)); + return new PmtStateTrieAccountValue( + nonce, balance, Hash.wrap(storageRoot), Hash.wrap(codeHash)); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/common/VerkleStateTrieAccountValue.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/common/VerkleStateTrieAccountValue.java new file mode 100644 index 0000000000..cb4a071a25 --- /dev/null +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/common/VerkleStateTrieAccountValue.java @@ -0,0 +1,104 @@ +/* + * 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.ethereum.trie.common; + +import org.hyperledger.besu.datatypes.AccountValue; +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.rlp.RLPInput; +import org.hyperledger.besu.ethereum.rlp.RLPOutput; + +import java.util.Objects; +import java.util.Optional; + +import org.apache.tuweni.bytes.Bytes32; + +/** Represents the raw values associated with an account in the world state trie. */ +public class VerkleStateTrieAccountValue extends AbstractStateTrieAccountValue + implements AccountValue { + + protected final Optional codeSize; + + public VerkleStateTrieAccountValue( + final long nonce, final Wei balance, final Hash codeHash, final Optional codeSize) { + super(nonce, balance, codeHash); + this.codeSize = codeSize; + } + + @Override + public Hash getStorageRoot() { + return super.getStorageRoot(); + } + + /** + * The size of the EVM bytecode associated with this account. + * + * @return the size of the account code (which may be {@link Optional#empty()}). + */ + public Optional getCodeSize() { + return codeSize; + } + + @Override + public boolean equals(final Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + VerkleStateTrieAccountValue that = (VerkleStateTrieAccountValue) o; + return nonce == that.nonce + && Objects.equals(balance, that.balance) + && Objects.equals(codeHash, that.codeHash) + && Objects.equals(codeSize, that.codeSize); + } + + @Override + public int hashCode() { + return Objects.hash(nonce, balance, codeHash, codeSize); + } + + @Override + public void writeTo(final RLPOutput out) { + out.startList(); + + out.writeUInt256Scalar(balance); + out.writeLongScalar(nonce); + out.writeBytes(codeHash); + codeSize.ifPresent(out::writeLongScalar); + out.endList(); + } + + public static VerkleStateTrieAccountValue readFrom(final RLPInput in) { + in.enterList(); + + final Wei balance = Wei.of(in.readUInt256Scalar()); + final long nonce = in.readLongScalar(); + Bytes32 codeHash; + final Optional codeSize; + if (in.nextIsNull()) { + codeHash = Hash.EMPTY; + in.skipNext(); + } else { + codeHash = in.readBytes32(); + } + if (in.nextIsNull()) { + codeSize = Optional.empty(); + in.skipNext(); + } else { + codeSize = Optional.of(in.readLongScalar()); + } + in.leaveList(); + + return new VerkleStateTrieAccountValue(nonce, balance, Hash.wrap(codeHash), codeSize); + } +} \ No newline at end of file diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProvider.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProvider.java index 15513f987f..c2c892fb3e 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProvider.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProvider.java @@ -18,6 +18,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.rlp.RLP; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.cache.BonsaiCachedMerkleTrieLoader; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.cache.BonsaiCachedWorldStorageManager; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; @@ -25,15 +26,15 @@ import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.worldview.BonsaiWorld import org.hyperledger.besu.ethereum.trie.diffbased.common.DiffBasedWorldStateProvider; import org.hyperledger.besu.ethereum.trie.diffbased.common.trielog.TrieLogManager; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.evm.internal.EvmConfiguration; -import org.hyperledger.besu.plugin.BesuContext; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; import java.util.HashSet; import java.util.Optional; import java.util.Set; import java.util.function.Function; +import java.util.function.Supplier; import com.google.common.annotations.VisibleForTesting; import org.apache.tuweni.bytes.Bytes; @@ -44,14 +45,16 @@ public class BonsaiWorldStateProvider extends DiffBasedWorldStateProvider { private static final Logger LOG = LoggerFactory.getLogger(BonsaiWorldStateProvider.class); private final BonsaiCachedMerkleTrieLoader bonsaiCachedMerkleTrieLoader; + private final Supplier worldStateHealerSupplier; public BonsaiWorldStateProvider( final BonsaiWorldStateKeyValueStorage worldStateKeyValueStorage, final Blockchain blockchain, final Optional maxLayersToLoad, final BonsaiCachedMerkleTrieLoader bonsaiCachedMerkleTrieLoader, - final BesuContext pluginContext, - final EvmConfiguration evmConfiguration) { + final ServiceManager pluginContext, + final EvmConfiguration evmConfiguration, + final Supplier worldStateHealerSupplier) { super( DataStorageFormat.BONSAI, worldStateKeyValueStorage, @@ -59,6 +62,7 @@ public class BonsaiWorldStateProvider extends DiffBasedWorldStateProvider { maxLayersToLoad, pluginContext); this.bonsaiCachedMerkleTrieLoader = bonsaiCachedMerkleTrieLoader; + this.worldStateHealerSupplier = worldStateHealerSupplier; provideCachedWorldStorageManager( new BonsaiCachedWorldStorageManager( this, worldStateKeyValueStorage, this::cloneBonsaiWorldStateConfig)); @@ -74,9 +78,11 @@ public class BonsaiWorldStateProvider extends DiffBasedWorldStateProvider { final BonsaiWorldStateKeyValueStorage worldStateKeyValueStorage, final Blockchain blockchain, final BonsaiCachedMerkleTrieLoader bonsaiCachedMerkleTrieLoader, - final EvmConfiguration evmConfiguration) { + final EvmConfiguration evmConfiguration, + final Supplier worldStateHealerSupplier) { super(worldStateKeyValueStorage, blockchain, trieLogManager); this.bonsaiCachedMerkleTrieLoader = bonsaiCachedMerkleTrieLoader; + this.worldStateHealerSupplier = worldStateHealerSupplier; provideCachedWorldStorageManager(bonsaiCachedWorldStorageManager); loadPersistedState( new BonsaiWorldState( @@ -119,7 +125,7 @@ public class BonsaiWorldStateProvider extends DiffBasedWorldStateProvider { accountTrie .get(accountHash) .map(RLP::input) - .map(StateTrieAccountValue::readFrom) + .map(PmtStateTrieAccountValue::readFrom) .ifPresent( account -> { final StoredMerklePatriciaTrie storageTrie = @@ -152,4 +158,9 @@ public class BonsaiWorldStateProvider extends DiffBasedWorldStateProvider { getBonsaiWorldStateKeyValueStorage().downgradeToPartialFlatDbMode(); } + + @Override + public void heal(final Optional
maybeAccountToRepair, final Bytes location) { + worldStateHealerSupplier.get().heal(maybeAccountToRepair, location); + } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/cache/BonsaiCachedMerkleTrieLoader.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/cache/BonsaiCachedMerkleTrieLoader.java index 9b9960b5c6..402402bc06 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/cache/BonsaiCachedMerkleTrieLoader.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/cache/BonsaiCachedMerkleTrieLoader.java @@ -14,6 +14,8 @@ */ package org.hyperledger.besu.ethereum.trie.diffbased.bonsai.cache; +import static org.hyperledger.besu.metrics.BesuMetricCategory.BLOCKCHAIN; + import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.StorageSlotKey; @@ -22,9 +24,7 @@ import org.hyperledger.besu.ethereum.trie.MerkleTrieException; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.diffbased.common.StorageSubscriber; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; -import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.metrics.ObservableMetricsSystem; -import org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem; import java.util.Optional; import java.util.concurrent.CompletableFuture; @@ -33,7 +33,6 @@ import java.util.function.Function; import com.google.common.annotations.VisibleForTesting; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; -import io.prometheus.client.guava.cache.CacheMetricsCollector; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; @@ -47,12 +46,8 @@ public class BonsaiCachedMerkleTrieLoader implements StorageSubscriber { CacheBuilder.newBuilder().recordStats().maximumSize(STORAGE_CACHE_SIZE).build(); public BonsaiCachedMerkleTrieLoader(final ObservableMetricsSystem metricsSystem) { - - CacheMetricsCollector cacheMetrics = new CacheMetricsCollector(); - cacheMetrics.addCache("accountsNodes", accountNodes); - cacheMetrics.addCache("storageNodes", storageNodes); - if (metricsSystem instanceof PrometheusMetricsSystem prometheusMetricsSystem) - prometheusMetricsSystem.addCollector(BesuMetricCategory.BLOCKCHAIN, () -> cacheMetrics); + metricsSystem.createGuavaCacheCollector(BLOCKCHAIN, "accountsNodes", accountNodes); + metricsSystem.createGuavaCacheCollector(BLOCKCHAIN, "storageNodes", storageNodes); } public void preLoadAccount( diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/storage/BonsaiWorldStateKeyValueStorage.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/storage/BonsaiWorldStateKeyValueStorage.java index 07ded9ddf6..e712c66ead 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/storage/BonsaiWorldStateKeyValueStorage.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/storage/BonsaiWorldStateKeyValueStorage.java @@ -24,13 +24,13 @@ import org.hyperledger.besu.datatypes.StorageSlotKey; import org.hyperledger.besu.ethereum.storage.StorageProvider; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.flat.BonsaiFlatDbStrategy; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.flat.BonsaiFlatDbStrategyProvider; import org.hyperledger.besu.ethereum.trie.diffbased.common.storage.DiffBasedWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.diffbased.common.storage.flat.FlatDbStrategy; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; import org.hyperledger.besu.ethereum.worldstate.FlatDbMode; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateKeyValueStorage; import org.hyperledger.besu.evm.account.AccountStorageEntry; import org.hyperledger.besu.plugin.services.MetricsSystem; @@ -135,7 +135,7 @@ public class BonsaiWorldStateKeyValueStorage extends DiffBasedWorldStateKeyValue getAccount(accountHash) .map( b -> - StateTrieAccountValue.readFrom( + PmtStateTrieAccountValue.readFrom( org.hyperledger.besu.ethereum.rlp.RLP.input(b)) .getStorageRoot()), accountHash, diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/trielog/TrieLogFactoryImpl.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/trielog/TrieLogFactoryImpl.java index e99b510964..d528373d24 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/trielog/TrieLogFactoryImpl.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/trielog/TrieLogFactoryImpl.java @@ -22,9 +22,9 @@ import org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.hyperledger.besu.ethereum.rlp.RLPInput; import org.hyperledger.besu.ethereum.rlp.RLPOutput; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.common.DiffBasedValue; import org.hyperledger.besu.ethereum.trie.diffbased.common.trielog.TrieLogLayer; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.plugin.data.BlockHeader; import org.hyperledger.besu.plugin.services.trielogs.TrieLog; import org.hyperledger.besu.plugin.services.trielogs.TrieLogAccumulator; @@ -160,8 +160,10 @@ public class TrieLogFactoryImpl implements TrieLogFactory { input.skipNext(); } else { input.enterList(); - final StateTrieAccountValue oldValue = nullOrValue(input, StateTrieAccountValue::readFrom); - final StateTrieAccountValue newValue = nullOrValue(input, StateTrieAccountValue::readFrom); + final PmtStateTrieAccountValue oldValue = + nullOrValue(input, PmtStateTrieAccountValue::readFrom); + final PmtStateTrieAccountValue newValue = + nullOrValue(input, PmtStateTrieAccountValue::readFrom); final boolean isCleared = getOptionalIsCleared(input); input.leaveList(); newLayer diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/DiffBasedWorldStateProvider.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/DiffBasedWorldStateProvider.java index 87ab1b9f86..f33a72137c 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/DiffBasedWorldStateProvider.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/DiffBasedWorldStateProvider.java @@ -31,7 +31,7 @@ import org.hyperledger.besu.ethereum.trie.diffbased.common.worldview.accumulator import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.evm.worldstate.WorldState; -import org.hyperledger.besu.plugin.BesuContext; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; import org.hyperledger.besu.plugin.services.trielogs.TrieLog; @@ -63,7 +63,7 @@ public abstract class DiffBasedWorldStateProvider implements WorldStateArchive { final DiffBasedWorldStateKeyValueStorage worldStateKeyValueStorage, final Blockchain blockchain, final Optional maxLayersToLoad, - final BesuContext pluginContext) { + final ServiceManager pluginContext) { this.worldStateKeyValueStorage = worldStateKeyValueStorage; // TODO: de-dup constructors @@ -340,4 +340,9 @@ public abstract class DiffBasedWorldStateProvider implements WorldStateArchive { protected DiffBasedWorldStateConfig cloneBonsaiWorldStateConfig() { return new DiffBasedWorldStateConfig(defaultWorldStateConfig); } + + @Override + public void heal(final Optional
maybeAccountToRepair, final Bytes location) { + // by default no heal mechanism + } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/trielog/TrieLogManager.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/trielog/TrieLogManager.java index 91338d13ca..c3e8483317 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/trielog/TrieLogManager.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/trielog/TrieLogManager.java @@ -21,7 +21,7 @@ import org.hyperledger.besu.ethereum.trie.diffbased.common.storage.DiffBasedWorl import org.hyperledger.besu.ethereum.trie.diffbased.common.worldview.DiffBasedWorldState; import org.hyperledger.besu.ethereum.trie.diffbased.common.worldview.accumulator.DiffBasedWorldStateUpdateAccumulator; import org.hyperledger.besu.ethereum.trie.diffbased.verkle.trielog.TrieLogFactoryImpl; -import org.hyperledger.besu.plugin.BesuContext; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.TrieLogService; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; import org.hyperledger.besu.plugin.services.trielogs.TrieLog; @@ -55,7 +55,7 @@ public class TrieLogManager { final DataStorageFormat dataStorageFormat, final DiffBasedWorldStateKeyValueStorage worldStateKeyValueStorage, final long maxLayersToLoad, - final BesuContext pluginContext) { + final ServiceManager pluginContext) { this.blockchain = blockchain; this.rootWorldStateStorage = worldStateKeyValueStorage; this.maxLayersToLoad = maxLayersToLoad; @@ -136,7 +136,7 @@ public class TrieLogManager { } private TrieLogFactory setupTrieLogFactory( - final DataStorageFormat dataStorageFormat, final BesuContext pluginContext) { + final DataStorageFormat dataStorageFormat, final ServiceManager pluginContext) { // if we have a TrieLogService from pluginContext, use it. var trieLogServicez = Optional.ofNullable(pluginContext) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/verkle/VerkleWorldStateProvider.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/verkle/VerkleWorldStateProvider.java index 12fd5fe51c..9b332b31be 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/verkle/VerkleWorldStateProvider.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/verkle/VerkleWorldStateProvider.java @@ -21,7 +21,7 @@ import org.hyperledger.besu.ethereum.trie.diffbased.verkle.cache.VerkleCachedWor import org.hyperledger.besu.ethereum.trie.diffbased.verkle.storage.VerkleWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.diffbased.verkle.worldview.VerkleWorldState; import org.hyperledger.besu.evm.internal.EvmConfiguration; -import org.hyperledger.besu.plugin.BesuContext; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; import java.util.Optional; @@ -34,7 +34,7 @@ public class VerkleWorldStateProvider extends DiffBasedWorldStateProvider { final VerkleWorldStateKeyValueStorage worldStateKeyValueStorage, final Blockchain blockchain, final Optional maxLayersToLoad, - final BesuContext pluginContext, + final ServiceManager pluginContext, final EvmConfiguration evmConfiguration) { super( DataStorageFormat.VERKLE, @@ -63,4 +63,6 @@ public class VerkleWorldStateProvider extends DiffBasedWorldStateProvider { new VerkleWorldState( this, worldStateKeyValueStorage, evmConfiguration, defaultWorldStateConfig)); } + + } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/verkle/trielog/TrieLogFactoryImpl.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/verkle/trielog/TrieLogFactoryImpl.java index 436202ff3a..6db8f1fc42 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/verkle/trielog/TrieLogFactoryImpl.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/verkle/trielog/TrieLogFactoryImpl.java @@ -22,9 +22,9 @@ import org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.hyperledger.besu.ethereum.rlp.RLPInput; import org.hyperledger.besu.ethereum.rlp.RLPOutput; +import org.hyperledger.besu.ethereum.trie.common.VerkleStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.common.DiffBasedValue; import org.hyperledger.besu.ethereum.trie.diffbased.common.trielog.TrieLogLayer; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.plugin.data.BlockHeader; import org.hyperledger.besu.plugin.services.trielogs.TrieLog; import org.hyperledger.besu.plugin.services.trielogs.TrieLogAccumulator; @@ -162,8 +162,10 @@ public class TrieLogFactoryImpl implements TrieLogFactory { input.skipNext(); } else { input.enterList(); - final StateTrieAccountValue oldValue = nullOrValue(input, StateTrieAccountValue::readFrom); - final StateTrieAccountValue newValue = nullOrValue(input, StateTrieAccountValue::readFrom); + final VerkleStateTrieAccountValue oldValue = + nullOrValue(input, VerkleStateTrieAccountValue::readFrom); + final VerkleStateTrieAccountValue newValue = + nullOrValue(input, VerkleStateTrieAccountValue::readFrom); final boolean isCleared = getOptionalIsCleared(input); input.leaveList(); newLayer diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/ForestWorldStateArchive.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/ForestWorldStateArchive.java index 1cdd079e15..800d2c9834 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/ForestWorldStateArchive.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/ForestWorldStateArchive.java @@ -112,6 +112,11 @@ public class ForestWorldStateArchive implements WorldStateArchive { blockHeader.getStateRoot(), accountAddress, accountStorageKeys)); } + @Override + public void heal(final Optional
maybeAccountToRepair, final Bytes location) { + // no heal needed for Forest + } + @Override public void close() { // no op diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/worldview/ForestMutableWorldState.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/worldview/ForestMutableWorldState.java index d94f356412..360dabb0c6 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/worldview/ForestMutableWorldState.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/worldview/ForestMutableWorldState.java @@ -23,9 +23,9 @@ import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.rlp.RLPException; import org.hyperledger.besu.ethereum.rlp.RLPInput; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStatePreimageStorage; import org.hyperledger.besu.evm.account.Account; @@ -137,7 +137,7 @@ public class ForestMutableWorldState implements MutableWorldState { private WorldStateAccount deserializeAccount( final Address address, final Hash addressHash, final Bytes encoded) throws RLPException { final RLPInput in = RLP.input(encoded); - final StateTrieAccountValue accountValue = StateTrieAccountValue.readFrom(in); + final PmtStateTrieAccountValue accountValue = PmtStateTrieAccountValue.readFrom(in); return new WorldStateAccount(address, addressHash, accountValue); } @@ -224,13 +224,15 @@ public class ForestMutableWorldState implements MutableWorldState { private final Address address; private final Hash addressHash; - final StateTrieAccountValue accountValue; + final PmtStateTrieAccountValue accountValue; // Lazily initialized since we don't always access storage. private volatile MerkleTrie storageTrie; private WorldStateAccount( - final Address address, final Hash addressHash, final StateTrieAccountValue accountValue) { + final Address address, + final Hash addressHash, + final PmtStateTrieAccountValue accountValue) { this.address = address; this.addressHash = addressHash; @@ -454,8 +456,8 @@ public class ForestMutableWorldState implements MutableWorldState { private static Bytes serializeAccount( final long nonce, final Wei balance, final Hash storageRoot, final Hash codeHash) { - final StateTrieAccountValue accountValue = - new StateTrieAccountValue(nonce, balance, storageRoot, codeHash); + final PmtStateTrieAccountValue accountValue = + new PmtStateTrieAccountValue(nonce, balance, storageRoot, codeHash); return RLP.encode(accountValue::writeTo); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/WorldStateArchive.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/WorldStateArchive.java index 23859ac396..9856a200b2 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/WorldStateArchive.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/WorldStateArchive.java @@ -64,4 +64,24 @@ public interface WorldStateArchive extends Closeable { final Address accountAddress, final List accountStorageKeys, final Function, ? extends Optional> mapper); + + /** + * Heal the world state to fix inconsistency + * + * @param maybeAccountToRepair the optional account to repair + * @param location the location of the inconsistency + */ + void heal(Optional
maybeAccountToRepair, Bytes location); + + /** A world state healer */ + @FunctionalInterface + interface WorldStateHealer { + /** + * Heal the world state to fix inconsistency + * + * @param maybeAccountToRepair the optional account to repair + * @param location the location of the inconsistency + */ + void heal(Optional
maybeAccountToRepair, Bytes location); + } } 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 7be6ad12c4..3391a0e162 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,7 +21,6 @@ import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider import static org.mockito.Mockito.mock; import org.hyperledger.besu.config.GenesisConfigFile; -import org.hyperledger.besu.ethereum.ConsensusContext; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.Blockchain; @@ -152,7 +151,7 @@ public class BlockchainSetupUtil { return MainnetProtocolSchedule.fromConfig( genesisConfigFile.getConfigOptions(), EvmConfiguration.DEFAULT, - MiningParameters.newDefault(), + MiningConfiguration.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -161,15 +160,7 @@ public class BlockchainSetupUtil { private static ProtocolContext mainnetProtocolContextProvider( final MutableBlockchain blockchain, final WorldStateArchive worldStateArchive) { return new ProtocolContext( - blockchain, - worldStateArchive, - new ConsensusContext() { - @Override - public C as(final Class klass) { - return null; - } - }, - new BadBlockManager()); + blockchain, worldStateArchive, new ConsensusContextFixture(), new BadBlockManager()); } private static BlockchainSetupUtil create( @@ -194,7 +185,6 @@ public class BlockchainSetupUtil { genesisState.writeStateTo(worldArchive.getMutable()); final ProtocolContext protocolContext = protocolContextProvider.get(blockchain, worldArchive); - protocolContext.setSynchronizer(new DummySynchronizer()); final Path blocksPath = Path.of(chainResources.getBlocksURL().toURI()); final List blocks = new ArrayList<>(); diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethConfiguration.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ConsensusContextFixture.java similarity index 66% rename from ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethConfiguration.java rename to ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ConsensusContextFixture.java index bb4fa31a55..198b3ab813 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethConfiguration.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ConsensusContextFixture.java @@ -1,5 +1,5 @@ /* - * Copyright ConsenSys AG. + * Copyright contributors to Besu. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -12,19 +12,13 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.retesteth; +package org.hyperledger.besu.ethereum.core; -import java.nio.file.Path; +import org.hyperledger.besu.ethereum.ConsensusContext; -public class RetestethConfiguration { - - private final Path dataPath; - - public RetestethConfiguration(final Path dataPath) { - this.dataPath = dataPath; - } - - Path getDataPath() { - return dataPath; +public class ConsensusContextFixture implements ConsensusContext { + @Override + public C as(final Class klass) { + return klass.cast(this); } } 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 511b94d3ae..b4eaec04d3 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 @@ -76,7 +76,8 @@ public class ExecutionContextTestFixture { else this.stateArchive = createInMemoryWorldStateArchive(); this.protocolSchedule = protocolSchedule; this.protocolContext = - new ProtocolContext(blockchain, stateArchive, null, new BadBlockManager()); + new ProtocolContext( + blockchain, stateArchive, new ConsensusContextFixture(), new BadBlockManager()); genesisState.writeStateTo(stateArchive.getMutable()); } @@ -152,12 +153,12 @@ public class ExecutionContextTestFixture { protocolSchedule = new ProtocolScheduleBuilder( genesisConfigFile.getConfigOptions(), - BigInteger.valueOf(42), + Optional.of(BigInteger.valueOf(42)), ProtocolSpecAdapters.create(0, Function.identity()), new PrivacyParameters(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) 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 87ea0cd68d..08cce18c62 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,8 @@ */ package org.hyperledger.besu.ethereum.core; +import static org.hyperledger.besu.ethereum.core.WorldStateHealerHelper.throwingWorldStateHealerSupplier; + import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.DefaultBlockchain; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; @@ -110,7 +112,8 @@ public class InMemoryKeyValueStorageProvider extends KeyValueStorageProvider { Optional.empty(), bonsaiCachedMerkleTrieLoader, null, - evmConfiguration); + evmConfiguration, + throwingWorldStateHealerSupplier()); } public static VerkleWorldStateProvider createVerkleInMemoryWorldStateArchive( diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ProtocolScheduleFixture.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ProtocolScheduleFixture.java index e94c6b49fd..db1114e832 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ProtocolScheduleFixture.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ProtocolScheduleFixture.java @@ -22,10 +22,10 @@ import org.hyperledger.besu.config.JsonGenesisConfigOptions; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; -import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import java.io.IOException; +import java.util.Optional; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParser; @@ -36,10 +36,10 @@ public class ProtocolScheduleFixture { public static final ProtocolSchedule MAINNET = MainnetProtocolSchedule.fromConfig( getMainnetConfigOptions(), - PrivacyParameters.DEFAULT, - false, - EvmConfiguration.DEFAULT, - MiningParameters.newDefault(), + Optional.empty(), + Optional.empty(), + Optional.empty(), + MiningConfiguration.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/TrieGenerator.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/TrieGenerator.java index 9a9108aa04..3e416a2879 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/TrieGenerator.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/TrieGenerator.java @@ -20,9 +20,9 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; @@ -74,8 +74,9 @@ public class TrieGenerator { }); final Bytes code = Bytes32.leftPad(Bytes.of(i + 10)); final Hash codeHash = Hash.hash(code); - final StateTrieAccountValue accountValue = - new StateTrieAccountValue(1L, Wei.of(2L), Hash.wrap(storageTrie.getRootHash()), codeHash); + final PmtStateTrieAccountValue accountValue = + new PmtStateTrieAccountValue( + 1L, Wei.of(2L), Hash.wrap(storageTrie.getRootHash()), codeHash); accountStateTrie.put(accounts.get(i), RLP.encode(accountValue::writeTo)); applyForStrategy( updater, diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/WorldStateHealerHelper.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/WorldStateHealerHelper.java new file mode 100644 index 0000000000..a94ce24793 --- /dev/null +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/WorldStateHealerHelper.java @@ -0,0 +1,39 @@ +/* + * Copyright contributors to Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.core; + +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive.WorldStateHealer; + +import java.util.Optional; +import java.util.function.Supplier; + +import org.apache.tuweni.bytes.Bytes; + +public class WorldStateHealerHelper { + + public static WorldStateHealer throwingHealer( + final Optional
maybeAccountToRepair, final Bytes location) { + throw new RuntimeException( + "World state needs to be healed: " + + maybeAccountToRepair.map(address -> "account to repair: " + address).orElse("") + + " location: " + + location.toHexString()); + } + + public static Supplier throwingWorldStateHealerSupplier() { + return () -> WorldStateHealerHelper::throwingHealer; + } +} diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/BlockImportExceptionHandlingTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/BlockImportExceptionHandlingTest.java index f9a325f3d7..06580ad4de 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/BlockImportExceptionHandlingTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/BlockImportExceptionHandlingTest.java @@ -153,7 +153,8 @@ class BlockImportExceptionHandlingTest { eq(goodBlock), any(), any(), - eq(HeaderValidationMode.DETACHED_ONLY))) + eq(HeaderValidationMode.DETACHED_ONLY), + any())) .thenReturn(true); assertThat(badBlockManager.getBadBlocks()).isEmpty(); mainnetBlockValidator.validateAndProcessBlock( @@ -189,7 +190,8 @@ class BlockImportExceptionHandlingTest { eq(goodBlock), any(), any(), - eq(HeaderValidationMode.DETACHED_ONLY))) + eq(HeaderValidationMode.DETACHED_ONLY), + any())) .thenReturn(true); assertThat(badBlockManager.getBadBlocks()).isEmpty(); mainnetBlockValidator.validateAndProcessBlock( @@ -257,7 +259,8 @@ class BlockImportExceptionHandlingTest { eq(goodBlock), any(), any(), - eq(HeaderValidationMode.DETACHED_ONLY))) + eq(HeaderValidationMode.DETACHED_ONLY), + any())) .thenThrow(new StorageException("database problem")); assertThat(badBlockManager.getBadBlocks()).isEmpty(); mainnetBlockValidator.validateAndProcessBlock( diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/MainnetBlockValidatorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/MainnetBlockValidatorTest.java index 013adae51e..96e8cafe19 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/MainnetBlockValidatorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/MainnetBlockValidatorTest.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.ethereum; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.eq; @@ -31,7 +32,6 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.core.MutableWorldState; -import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.mainnet.BlockBodyValidator; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; import org.hyperledger.besu.ethereum.mainnet.BlockProcessor; @@ -91,7 +91,6 @@ public class MainnetBlockValidatorTest { when(protocolContext.getBlockchain()).thenReturn(blockchain); when(protocolContext.getWorldStateArchive()).thenReturn(worldStateArchive); - when(protocolContext.getSynchronizer()).thenReturn(mock(Synchronizer.class)); when(worldStateArchive.getMutable(any(BlockHeader.class), anyBoolean())) .thenReturn(Optional.of(worldState)); when(worldStateArchive.getMutable(any(Hash.class), any(Hash.class))) @@ -99,8 +98,9 @@ public class MainnetBlockValidatorTest { when(worldStateArchive.getMutable()).thenReturn(worldState); when(blockHeaderValidator.validateHeader(any(), any(), any())).thenReturn(true); when(blockHeaderValidator.validateHeader(any(), any(), any(), any())).thenReturn(true); - when(blockBodyValidator.validateBody(any(), any(), any(), any(), any())).thenReturn(true); - when(blockBodyValidator.validateBodyLight(any(), any(), any(), any(), any())).thenReturn(true); + when(blockBodyValidator.validateBody(any(), any(), any(), any(), any(), any())) + .thenReturn(true); + when(blockBodyValidator.validateBodyLight(any(), any(), any(), any())).thenReturn(true); when(blockProcessor.processBlock(any(), any(), any())).thenReturn(successfulProcessingResult); when(blockProcessor.processBlock(any(), any(), any(), any())) .thenReturn(successfulProcessingResult); @@ -165,7 +165,8 @@ public class MainnetBlockValidatorTest { @Test public void validateAndProcessBlock_whenBlockBodyInvalid() { - when(blockBodyValidator.validateBody(any(), eq(block), any(), any(), any())).thenReturn(false); + when(blockBodyValidator.validateBody(any(), eq(block), any(), any(), any(), any())) + .thenReturn(false); BlockProcessingResult result = mainnetBlockValidator.validateAndProcessBlock( @@ -352,7 +353,7 @@ public class MainnetBlockValidatorTest { Collections.emptyList(), HeaderValidationMode.FULL, HeaderValidationMode.FULL, - BodyValidationMode.FULL); + BodyValidationMode.LIGHT); assertThat(isValid).isTrue(); assertNoBadBlocks(); @@ -364,7 +365,6 @@ public class MainnetBlockValidatorTest { when(blockHeaderValidator.validateHeader( any(BlockHeader.class), eq(protocolContext), eq(headerValidationMode))) .thenReturn(false); - final BodyValidationMode bodyValidationMode = BodyValidationMode.FULL; final boolean isValid = mainnetBlockValidator.validateBlockForSyncing( @@ -373,7 +373,7 @@ public class MainnetBlockValidatorTest { Collections.emptyList(), headerValidationMode, headerValidationMode, - bodyValidationMode); + BodyValidationMode.LIGHT); assertThat(isValid).isFalse(); assertBadBlockIsTracked(block); @@ -382,13 +382,8 @@ public class MainnetBlockValidatorTest { @Test public void validateBlockValidation_onFailedBodyForSyncing() { final HeaderValidationMode headerValidationMode = HeaderValidationMode.FULL; - final BodyValidationMode bodyValidationMode = BodyValidationMode.FULL; when(blockBodyValidator.validateBodyLight( - eq(protocolContext), - eq(block), - any(), - eq(headerValidationMode), - eq(bodyValidationMode))) + eq(protocolContext), eq(block), any(), eq(headerValidationMode))) .thenReturn(false); final boolean isValid = @@ -398,12 +393,27 @@ public class MainnetBlockValidatorTest { Collections.emptyList(), headerValidationMode, headerValidationMode, - bodyValidationMode); + BodyValidationMode.LIGHT); assertThat(isValid).isFalse(); assertBadBlockIsTracked(block); } + @Test + public void shouldThrowIfValidateForSyncingWithFullBodyValidation() { + final HeaderValidationMode headerValidationMode = HeaderValidationMode.FULL; + assertThrows( + UnsupportedOperationException.class, + () -> + mainnetBlockValidator.validateBlockForSyncing( + protocolContext, + block, + Collections.emptyList(), + headerValidationMode, + headerValidationMode, + BodyValidationMode.FULL)); + } + private void assertNoBadBlocks() { assertThat(badBlockManager.getBadBlocks()).isEmpty(); } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java index 7969ab6824..9a6ddeaeb7 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java @@ -20,7 +20,7 @@ import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -36,7 +36,7 @@ public class FixedProtocolScheduleTest { FixedDifficultyProtocolSchedule.create( GenesisConfigFile.fromResource("/dev.json").getConfigOptions(), EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -49,21 +49,21 @@ public class FixedProtocolScheduleTest { schedule .getByBlockHeader(blockHeader(0)) .getDifficultyCalculator() - .nextDifficulty(1, parentHeader, null)) + .nextDifficulty(1, parentHeader)) .isEqualTo(FixedDifficultyCalculators.DEFAULT_DIFFICULTY); assertThat( schedule .getByBlockHeader(blockHeader(500)) .getDifficultyCalculator() - .nextDifficulty(1, parentHeader, null)) + .nextDifficulty(1, parentHeader)) .isEqualTo(FixedDifficultyCalculators.DEFAULT_DIFFICULTY); assertThat( schedule .getByBlockHeader(blockHeader(500_000)) .getDifficultyCalculator() - .nextDifficulty(1, parentHeader, null)) + .nextDifficulty(1, parentHeader)) .isEqualTo(FixedDifficultyCalculators.DEFAULT_DIFFICULTY); } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/DefaultProtocolScheduleTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/DefaultProtocolScheduleTest.java index 2d5dd2cee3..92818e31e7 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/DefaultProtocolScheduleTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/DefaultProtocolScheduleTest.java @@ -22,7 +22,7 @@ import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -56,12 +56,12 @@ public class DefaultProtocolScheduleTest { builder = new ProtocolScheduleBuilder( config, - DEFAULT_CHAIN_ID, + Optional.of(DEFAULT_CHAIN_ID), ProtocolSpecAdapters.create(FIRST_TIMESTAMP_FORK, modifier), privacyParameters, isRevertReasonEnabled, evmConfiguration, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidatorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidatorTest.java index 8c25d4f58e..8665cb70ac 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidatorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidatorTest.java @@ -95,11 +95,7 @@ class MainnetBlockBodyValidatorTest { assertThat( new MainnetBlockBodyValidator(protocolSchedule) .validateBodyLight( - blockchainSetupUtil.getProtocolContext(), - block, - emptyList(), - NONE, - BodyValidationMode.FULL)) + blockchainSetupUtil.getProtocolContext(), block, emptyList(), NONE)) .isTrue(); } @@ -123,11 +119,7 @@ class MainnetBlockBodyValidatorTest { assertThat( new MainnetBlockBodyValidator(protocolSchedule) .validateBodyLight( - blockchainSetupUtil.getProtocolContext(), - block, - emptyList(), - NONE, - BodyValidationMode.FULL)) + blockchainSetupUtil.getProtocolContext(), block, emptyList(), NONE)) .isFalse(); } @@ -151,11 +143,7 @@ class MainnetBlockBodyValidatorTest { assertThat( new MainnetBlockBodyValidator(protocolSchedule) .validateBodyLight( - blockchainSetupUtil.getProtocolContext(), - block, - emptyList(), - NONE, - BodyValidationMode.FULL)) + blockchainSetupUtil.getProtocolContext(), block, emptyList(), NONE)) .isFalse(); } @@ -168,10 +156,11 @@ class MainnetBlockBodyValidatorTest { final MainnetBlockBodyValidator bodyValidator = new MainnetBlockBodyValidator(protocolSchedule); assertThat( - bodyValidator.validateBodyLight( + bodyValidator.validateBody( blockchainSetupUtil.getProtocolContext(), block, receipts, + Hash.ZERO, NONE, BodyValidationMode.NONE)) .isTrue(); @@ -180,66 +169,79 @@ class MainnetBlockBodyValidatorTest { } @Test - public void lightValidationDoesNotCheckTransactionRootOrReceiptRoot() { - final Block block = - blockDataGenerator.block( - new BlockOptions() - .setBlockNumber(1) - .setGasUsed(0) - .hasTransactions(false) - .hasOmmers(false) - .setReceiptsRoot(BodyValidation.receiptsRoot(emptyList())) - .setLogsBloom(LogsBloomFilter.empty()) - .setParentHash(blockchainSetupUtil.getBlockchain().getChainHeadHash()) - .setWithdrawals(Optional.of(withdrawals))); - blockchainSetupUtil.getBlockchain().appendBlock(block, Collections.emptyList()); + public void lightValidationDoesNotCheckRoots() { + final Block block = setupBlock(); final MainnetBlockBodyValidator bodyValidator = new MainnetBlockBodyValidator(protocolSchedule); final MainnetBlockBodyValidator bodyValidatorSpy = spy(bodyValidator); assertThat( - bodyValidatorSpy.validateBodyLight( + bodyValidatorSpy.validateBody( blockchainSetupUtil.getProtocolContext(), block, emptyList(), + Hash.ZERO, NONE, BodyValidationMode.LIGHT)) .isTrue(); - verify(bodyValidatorSpy, never()).validateReceiptsRoot(any(), any(), any()); - verify(bodyValidatorSpy, never()).validateTransactionsRoot(any(), any(), any()); + verify(bodyValidatorSpy, times(1)).validateBodyLight(any(), any(), any(), any()); + verify(bodyValidatorSpy, never()).validateBodyRoots(any(), any(), any()); } @Test - public void fullValidationChecksTransactionRootAndReceiptRoot() { - final Block block = - blockDataGenerator.block( - new BlockOptions() - .setBlockNumber(1) - .setGasUsed(0) - .hasTransactions(false) - .hasOmmers(false) - .setReceiptsRoot(BodyValidation.receiptsRoot(emptyList())) - .setLogsBloom(LogsBloomFilter.empty()) - .setParentHash(blockchainSetupUtil.getBlockchain().getChainHeadHash()) - .setWithdrawals(Optional.of(withdrawals))); - blockchainSetupUtil.getBlockchain().appendBlock(block, Collections.emptyList()); + public void hashOnlyValidationChecksOnlyRoots() { + final Block block = setupBlock(); final MainnetBlockBodyValidator bodyValidator = new MainnetBlockBodyValidator(protocolSchedule); final MainnetBlockBodyValidator bodyValidatorSpy = spy(bodyValidator); assertThat( - bodyValidatorSpy.validateBodyLight( + bodyValidatorSpy.validateBody( blockchainSetupUtil.getProtocolContext(), block, emptyList(), + block.getHeader().getStateRoot(), + NONE, + BodyValidationMode.ROOT_ONLY)) + .isTrue(); + + verify(bodyValidatorSpy, never()).validateBodyLight(any(), any(), any(), any()); + verify(bodyValidatorSpy, times(1)).validateBodyRoots(any(), any(), any()); + } + + @Test + public void fullValidationChecksRootsAndContent() { + final Block block = setupBlock(); + + final MainnetBlockBodyValidator bodyValidator = new MainnetBlockBodyValidator(protocolSchedule); + final MainnetBlockBodyValidator bodyValidatorSpy = spy(bodyValidator); + + assertThat( + bodyValidatorSpy.validateBody( + blockchainSetupUtil.getProtocolContext(), + block, + emptyList(), + block.getHeader().getStateRoot(), NONE, BodyValidationMode.FULL)) .isTrue(); - final Hash receiptsRoot = BodyValidation.receiptsRoot(emptyList()); - final Hash transactionsRoot = BodyValidation.transactionsRoot(emptyList()); - verify(bodyValidatorSpy, times(1)) - .validateReceiptsRoot(block.getHeader(), receiptsRoot, receiptsRoot); - verify(bodyValidatorSpy, times(1)) - .validateTransactionsRoot(block.getHeader(), transactionsRoot, transactionsRoot); + verify(bodyValidatorSpy, times(1)).validateBodyLight(any(), any(), any(), any()); + verify(bodyValidatorSpy, times(1)).validateBodyRoots(any(), any(), any()); + } + + private Block setupBlock() { + Block block = + blockDataGenerator.block( + new BlockOptions() + .setBlockNumber(1) + .setGasUsed(0) + .hasTransactions(false) + .hasOmmers(false) + .setReceiptsRoot(BodyValidation.receiptsRoot(emptyList())) + .setLogsBloom(LogsBloomFilter.empty()) + .setParentHash(blockchainSetupUtil.getBlockchain().getChainHeadHash()) + .setWithdrawals(Optional.of(withdrawals))); + blockchainSetupUtil.getBlockchain().appendBlock(block, Collections.emptyList()); + return block; } } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolScheduleTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolScheduleTest.java index c63a9b5ccb..9ce20cb626 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolScheduleTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolScheduleTest.java @@ -18,7 +18,7 @@ import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -73,7 +73,7 @@ public class MainnetProtocolScheduleTest { MainnetProtocolSchedule.fromConfig( GenesisConfigFile.fromConfig("{}").getConfigOptions(), EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -90,7 +90,7 @@ public class MainnetProtocolScheduleTest { MainnetProtocolSchedule.fromConfig( GenesisConfigFile.fromConfig(json).getConfigOptions(), EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -124,7 +124,7 @@ public class MainnetProtocolScheduleTest { MainnetProtocolSchedule.fromConfig( GenesisConfigFile.fromConfig(json).getConfigOptions(), EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem())); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessorTest.java index 5d1ee2130f..ea09dacc12 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessorTest.java @@ -109,7 +109,6 @@ class MainnetTransactionProcessorTest { .thenReturn(ValidationResult.valid()); when(transactionValidatorFactory.get().validateForSender(any(), any(), any())) .thenReturn(ValidationResult.valid()); - when(worldState.getOrCreate(any())).thenReturn(senderAccount); when(worldState.getOrCreateSenderAccount(any())).thenReturn(senderAccount); when(worldState.updater()).thenReturn(worldState); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/PoWSolverTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/PoWSolverTest.java index 91553afed3..1f0b782825 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/PoWSolverTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/PoWSolverTest.java @@ -21,9 +21,9 @@ import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.util.Subscribers; import java.util.Arrays; @@ -530,12 +530,12 @@ public class PoWSolverTest { powThread1.interrupt(); } - private MiningParameters createMiningParameters( + private MiningConfiguration createMiningParameters( final List nonceToTry, final int powJobTimeToLive, final int maxOmmerDepth) { - return ImmutableMiningParameters.builder() + return ImmutableMiningConfiguration.builder() .mutableInitValues(MutableInitValues.builder().nonceGenerator(nonceToTry).build()) .unstable( - ImmutableMiningParameters.Unstable.builder() + ImmutableMiningConfiguration.Unstable.builder() .maxOmmerDepth(maxOmmerDepth) .powJobTimeToLive(powJobTimeToLive) .build()) diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilderTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilderTest.java index ad261abf47..8046d7e839 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilderTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilderTest.java @@ -31,7 +31,7 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -62,12 +62,12 @@ class ProtocolScheduleBuilderTest { builder = new ProtocolScheduleBuilder( configOptions, - CHAIN_ID, + Optional.of(CHAIN_ID), ProtocolSpecAdapters.create(0, Function.identity()), new PrivacyParameters(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -257,12 +257,12 @@ class ProtocolScheduleBuilderTest { final ProtocolScheduleBuilder builder = new ProtocolScheduleBuilder( configOptions, - CHAIN_ID, + Optional.of(CHAIN_ID), ProtocolSpecAdapters.create(blockNumber, modifier), new PrivacyParameters(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/proof/WorldStateProofProviderTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/proof/WorldStateProofProviderTest.java index 95b39197ea..f7085e31e9 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/proof/WorldStateProofProviderTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/proof/WorldStateProofProviderTest.java @@ -21,9 +21,9 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; @@ -82,8 +82,9 @@ public class WorldStateProofProviderTest { // Define account value final Hash codeHash = Hash.hash(Bytes.fromHexString("0x1122")); - final StateTrieAccountValue accountValue = - new StateTrieAccountValue(1L, Wei.of(2L), Hash.wrap(storageTrie.getRootHash()), codeHash); + final PmtStateTrieAccountValue accountValue = + new PmtStateTrieAccountValue( + 1L, Wei.of(2L), Hash.wrap(storageTrie.getRootHash()), codeHash); // Save to storage worldStateTrie.put(addressHash, RLP.encode(accountValue::writeTo)); worldStateTrie.commit((location, hash, value) -> updater.putAccountStateTrieNode(hash, value)); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorTest.java index c6c676c415..e0715e5847 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorTest.java @@ -20,11 +20,13 @@ import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import org.hyperledger.besu.crypto.SECPSignature; import org.hyperledger.besu.crypto.SignatureAlgorithm; import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; +import org.hyperledger.besu.datatypes.AccountOverride; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.BlobsWithCommitments; import org.hyperledger.besu.datatypes.Hash; @@ -49,15 +51,18 @@ import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult.Status; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.evm.account.Account; +import org.hyperledger.besu.evm.account.MutableAccount; import org.hyperledger.besu.evm.tracing.OperationTracer; import org.hyperledger.besu.evm.worldstate.WorldUpdater; import java.math.BigInteger; +import java.util.Map; import java.util.Optional; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import org.apache.tuweni.bytes.Bytes; +import org.apache.tuweni.units.bigints.UInt256; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -100,6 +105,42 @@ public class TransactionSimulatorTest { new TransactionSimulator(blockchain, worldStateArchive, protocolSchedule, GAS_CAP); } + @Test + public void testOverrides_whenNoOverrides_noUpdates() { + MutableAccount mutableAccount = mock(MutableAccount.class); + when(mutableAccount.getAddress()).thenReturn(DEFAULT_FROM); // called from logging + AccountOverride.Builder builder = new AccountOverride.Builder(); + AccountOverride override = builder.build(); + transactionSimulator.applyOverrides(mutableAccount, override); + verify(mutableAccount).getAddress(); + verifyNoMoreInteractions(mutableAccount); + } + + @Test + public void testOverrides_whenBalanceOverrides_balanceIsUpdated() { + MutableAccount mutableAccount = mock(MutableAccount.class); + when(mutableAccount.getAddress()).thenReturn(DEFAULT_FROM); + AccountOverride.Builder builder = new AccountOverride.Builder().withBalance(Wei.of(99)); + AccountOverride override = builder.build(); + transactionSimulator.applyOverrides(mutableAccount, override); + verify(mutableAccount).setBalance(eq(Wei.of(99))); + } + + @Test + public void testOverrides_whenStateDiffOverrides_stateIsUpdated() { + MutableAccount mutableAccount = mock(MutableAccount.class); + when(mutableAccount.getAddress()).thenReturn(DEFAULT_FROM); + final String storageKey = "0x01a2"; + final String storageValue = "0x00ff"; + AccountOverride.Builder builder = + new AccountOverride.Builder().withStateDiff(Map.of(storageKey, storageValue)); + AccountOverride override = builder.build(); + transactionSimulator.applyOverrides(mutableAccount, override); + verify(mutableAccount) + .setStorageValue( + eq(UInt256.fromHexString(storageKey)), eq(UInt256.fromHexString(storageValue))); + } + @Test public void shouldReturnEmptyWhenBlockDoesNotExist() { when(blockchain.getBlockHeader(eq(1L))).thenReturn(Optional.empty()); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/AbstractIsolationTests.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/AbstractIsolationTests.java index dd9257441e..275adc9ff4 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/AbstractIsolationTests.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/AbstractIsolationTests.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.ethereum.trie.diffbased.bonsai; import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain; +import static org.hyperledger.besu.ethereum.core.WorldStateHealerHelper.throwingWorldStateHealerSupplier; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; @@ -29,6 +30,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.BlockProcessingResult; +import org.hyperledger.besu.ethereum.ConsensusContext; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.blockcreation.AbstractBlockCreator; import org.hyperledger.besu.ethereum.chain.BadBlockManager; @@ -39,9 +41,9 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.SealableBlockHeader; import org.hyperledger.besu.ethereum.core.Transaction; @@ -104,7 +106,7 @@ public abstract class AbstractIsolationTests { protected final ProtocolSchedule protocolSchedule = MainnetProtocolSchedule.fromConfig( GenesisConfigFile.fromResource("/dev.json").getConfigOptions(), - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -138,7 +140,7 @@ public abstract class AbstractIsolationTests { txPoolMetrics, transactionReplacementTester, new BlobCache(), - MiningParameters.newDefault()), + MiningConfiguration.newDefault()), ethScheduler); protected final List accounts = @@ -167,10 +169,13 @@ public abstract class AbstractIsolationTests { Optional.of(16L), new BonsaiCachedMerkleTrieLoader(new NoOpMetricsSystem()), null, - EvmConfiguration.DEFAULT); + EvmConfiguration.DEFAULT, + throwingWorldStateHealerSupplier()); var ws = archive.getMutable(); genesisState.writeStateTo(ws); - protocolContext = new ProtocolContext(blockchain, archive, null, new BadBlockManager()); + protocolContext = + new ProtocolContext( + blockchain, archive, mock(ConsensusContext.class), new BadBlockManager()); ethContext = mock(EthContext.class, RETURNS_DEEP_STUBS); when(ethContext.getEthPeers().subscribeConnect(any())).thenReturn(1L); transactionPool = @@ -229,7 +234,7 @@ public abstract class AbstractIsolationTests { @Override public Wei getMinGasPrice() { - return MiningParameters.newDefault().getMinTransactionGasPrice(); + return MiningConfiguration.newDefault().getMinTransactionGasPrice(); } @Override @@ -254,7 +259,7 @@ public abstract class AbstractIsolationTests { static class TestBlockCreator extends AbstractBlockCreator { private TestBlockCreator( - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final MiningBeneficiaryCalculator miningBeneficiaryCalculator, final ExtraDataCalculator extraDataCalculator, final TransactionPool transactionPool, @@ -262,7 +267,7 @@ public abstract class AbstractIsolationTests { final ProtocolSchedule protocolSchedule, final EthScheduler ethScheduler) { super( - miningParameters, + miningConfiguration, miningBeneficiaryCalculator, extraDataCalculator, transactionPool, @@ -277,8 +282,8 @@ public abstract class AbstractIsolationTests { final TransactionPool transactionPool, final EthScheduler ethScheduler) { - final MiningParameters miningParameters = - ImmutableMiningParameters.builder() + final MiningConfiguration miningConfiguration = + ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .extraData(Bytes.fromHexString("deadbeef")) @@ -290,7 +295,7 @@ public abstract class AbstractIsolationTests { .build(); return new TestBlockCreator( - miningParameters, + miningConfiguration, __ -> Address.ZERO, __ -> Bytes.fromHexString("deadbeef"), transactionPool, diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiCachedMerkleTrieLoaderTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiCachedMerkleTrieLoaderTest.java index 06b377ad83..1552c341f3 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiCachedMerkleTrieLoaderTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiCachedMerkleTrieLoaderTest.java @@ -25,11 +25,11 @@ import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.storage.StorageProvider; import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.TrieIterator; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.cache.BonsaiCachedMerkleTrieLoader; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -96,8 +96,8 @@ class BonsaiCachedMerkleTrieLoaderTest { @Test void shouldAddStorageNodesInCacheDuringPreload() { final Hash hashAccountZero = accounts.get(0).addressHash(); - final StateTrieAccountValue stateTrieAccountValue = - StateTrieAccountValue.readFrom(RLP.input(trie.get(hashAccountZero).orElseThrow())); + final PmtStateTrieAccountValue stateTrieAccountValue = + PmtStateTrieAccountValue.readFrom(RLP.input(trie.get(hashAccountZero).orElseThrow())); final StoredMerklePatriciaTrie storageTrie = new StoredMerklePatriciaTrie<>( (location, hash) -> @@ -154,8 +154,8 @@ class BonsaiCachedMerkleTrieLoaderTest { @Test void shouldFallbackWhenStorageNodesIsNotInCache() { final Hash hashAccountZero = accounts.get(0).addressHash(); - final StateTrieAccountValue stateTrieAccountValue = - StateTrieAccountValue.readFrom(RLP.input(trie.get(hashAccountZero).orElseThrow())); + final PmtStateTrieAccountValue stateTrieAccountValue = + PmtStateTrieAccountValue.readFrom(RLP.input(trie.get(hashAccountZero).orElseThrow())); final StoredMerklePatriciaTrie storageTrie = new StoredMerklePatriciaTrie<>( (location, hash) -> diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProviderTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProviderTest.java index 4ac99377ef..87cc16c23c 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProviderTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProviderTest.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.ethereum.trie.diffbased.bonsai; import static org.assertj.core.api.Assertions.assertThat; +import static org.hyperledger.besu.ethereum.core.WorldStateHealerHelper.throwingWorldStateHealerSupplier; import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.BLOCKCHAIN; import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.TRIE_BRANCH_STORAGE; import static org.hyperledger.besu.ethereum.trie.diffbased.common.storage.DiffBasedWorldStateKeyValueStorage.WORLD_BLOCK_HASH_KEY; @@ -111,7 +112,8 @@ class BonsaiWorldStateProviderTest { DataStorageConfiguration.DEFAULT_BONSAI_CONFIG), blockchain, new BonsaiCachedMerkleTrieLoader(new NoOpMetricsSystem()), - EvmConfiguration.DEFAULT); + EvmConfiguration.DEFAULT, + throwingWorldStateHealerSupplier()); assertThat(bonsaiWorldStateArchive.getMutable(chainHead, true)) .containsInstanceOf(BonsaiWorldState.class); @@ -129,7 +131,8 @@ class BonsaiWorldStateProviderTest { Optional.of(512L), new BonsaiCachedMerkleTrieLoader(new NoOpMetricsSystem()), null, - EvmConfiguration.DEFAULT); + EvmConfiguration.DEFAULT, + throwingWorldStateHealerSupplier()); final BlockHeader blockHeader = blockBuilder.number(0).buildHeader(); final BlockHeader chainHead = blockBuilder.number(512).buildHeader(); when(blockchain.getChainHeadHeader()).thenReturn(chainHead); @@ -150,7 +153,8 @@ class BonsaiWorldStateProviderTest { DataStorageConfiguration.DEFAULT_BONSAI_CONFIG), blockchain, new BonsaiCachedMerkleTrieLoader(new NoOpMetricsSystem()), - EvmConfiguration.DEFAULT); + EvmConfiguration.DEFAULT, + throwingWorldStateHealerSupplier()); final BlockHeader blockHeader = blockBuilder.number(0).buildHeader(); final BlockHeader chainHead = blockBuilder.number(511).buildHeader(); final BonsaiWorldState mockWorldState = mock(BonsaiWorldState.class); @@ -185,7 +189,8 @@ class BonsaiWorldStateProviderTest { worldStateKeyValueStorage, blockchain, new BonsaiCachedMerkleTrieLoader(new NoOpMetricsSystem()), - EvmConfiguration.DEFAULT)); + EvmConfiguration.DEFAULT, + throwingWorldStateHealerSupplier())); final BlockHeader blockHeader = blockBuilder.number(0).buildHeader(); when(blockchain.getBlockHeader(blockHeader.getHash())).thenReturn(Optional.of(blockHeader)); @@ -214,7 +219,8 @@ class BonsaiWorldStateProviderTest { worldStateKeyValueStorage, blockchain, new BonsaiCachedMerkleTrieLoader(new NoOpMetricsSystem()), - EvmConfiguration.DEFAULT)); + EvmConfiguration.DEFAULT, + throwingWorldStateHealerSupplier())); final BlockHeader blockHeader = blockBuilder.number(0).buildHeader(); @@ -254,7 +260,8 @@ class BonsaiWorldStateProviderTest { worldStateKeyValueStorage, blockchain, new BonsaiCachedMerkleTrieLoader(new NoOpMetricsSystem()), - EvmConfiguration.DEFAULT)); + EvmConfiguration.DEFAULT, + throwingWorldStateHealerSupplier())); // initial persisted state hash key when(blockchain.getBlockHeader(Hash.ZERO)).thenReturn(Optional.of(blockHeaderChainA)); @@ -297,7 +304,8 @@ class BonsaiWorldStateProviderTest { DataStorageConfiguration.DEFAULT_BONSAI_CONFIG), blockchain, new BonsaiCachedMerkleTrieLoader(new NoOpMetricsSystem()), - EvmConfiguration.DEFAULT)); + EvmConfiguration.DEFAULT, + throwingWorldStateHealerSupplier())); // initial persisted state hash key when(blockchain.getBlockHeader(Hash.ZERO)).thenReturn(Optional.of(blockHeaderChainA)); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/storage/BonsaiWorldStateKeyValueStorageTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/storage/BonsaiWorldStateKeyValueStorageTest.java index 464f35bae7..81e158bef7 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/storage/BonsaiWorldStateKeyValueStorageTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/storage/BonsaiWorldStateKeyValueStorageTest.java @@ -36,12 +36,12 @@ import org.hyperledger.besu.ethereum.storage.StorageProvider; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier; import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.StorageEntriesCollector; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; import org.hyperledger.besu.ethereum.worldstate.FlatDbMode; import org.hyperledger.besu.ethereum.worldstate.ImmutableDataStorageConfiguration; import org.hyperledger.besu.ethereum.worldstate.ImmutableDiffBasedSubStorageConfiguration; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; @@ -316,8 +316,8 @@ public class BonsaiWorldStateKeyValueStorageTest { (TreeMap) trie.entriesFrom(root -> StorageEntriesCollector.collectEntries(root, Hash.ZERO, 1)); - final StateTrieAccountValue stateTrieAccountValue = - StateTrieAccountValue.readFrom(RLP.input(accounts.firstEntry().getValue())); + final PmtStateTrieAccountValue stateTrieAccountValue = + PmtStateTrieAccountValue.readFrom(RLP.input(accounts.firstEntry().getValue())); final StoredMerklePatriciaTrie storageTrie = new StoredMerklePatriciaTrie<>( diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/trielog/TrieLogFactoryTests.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/trielog/TrieLogFactoryTests.java index 5173df717f..ae685f0d00 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/trielog/TrieLogFactoryTests.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/trielog/TrieLogFactoryTests.java @@ -23,8 +23,8 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.common.trielog.TrieLogLayer; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; import org.hyperledger.besu.plugin.services.trielogs.TrieLog; import org.hyperledger.besu.plugin.services.trielogs.TrieLogFactory; @@ -54,7 +54,7 @@ public class TrieLogFactoryTests { .addAccountChange( accountFixture, null, - new StateTrieAccountValue(0, Wei.fromEth(1), Hash.EMPTY, Hash.EMPTY)) + new PmtStateTrieAccountValue(0, Wei.fromEth(1), Hash.EMPTY, Hash.EMPTY)) .addCodeChange( Address.ZERO, null, diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/common/trielog/TrieLogLayerTests.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/common/trielog/TrieLogLayerTests.java index 85534de1b0..0aa00160fd 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/common/trielog/TrieLogLayerTests.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/common/trielog/TrieLogLayerTests.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.StorageSlotKey; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import java.util.Optional; @@ -51,15 +51,16 @@ public class TrieLogLayerTests { @Test public void testAddAccountChange() { Address address = Address.fromHexString("0x00"); - StateTrieAccountValue oldValue = new StateTrieAccountValue(0, Wei.ZERO, Hash.EMPTY, Hash.EMPTY); - StateTrieAccountValue newValue = - new StateTrieAccountValue(1, Wei.fromEth(1), Hash.EMPTY, Hash.EMPTY); + PmtStateTrieAccountValue oldValue = + new PmtStateTrieAccountValue(0, Wei.ZERO, Hash.EMPTY, Hash.EMPTY); + PmtStateTrieAccountValue newValue = + new PmtStateTrieAccountValue(1, Wei.fromEth(1), Hash.EMPTY, Hash.EMPTY); Address otherAddress = Address.fromHexString("0x000000"); - StateTrieAccountValue otherOldValue = - new StateTrieAccountValue(0, Wei.ZERO, Hash.EMPTY, Hash.EMPTY); - StateTrieAccountValue otherNewValue = - new StateTrieAccountValue(1, Wei.fromEth(1), Hash.EMPTY, Hash.EMPTY); + PmtStateTrieAccountValue otherOldValue = + new PmtStateTrieAccountValue(0, Wei.ZERO, Hash.EMPTY, Hash.EMPTY); + PmtStateTrieAccountValue otherNewValue = + new PmtStateTrieAccountValue(1, Wei.fromEth(1), Hash.EMPTY, Hash.EMPTY); trieLogLayer.addAccountChange(address, oldValue, newValue); otherTrieLogLayer.addAccountChange(otherAddress, otherOldValue, otherNewValue); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/AccountOverrideParameterTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/AccountOverrideParameterTest.java new file mode 100644 index 0000000000..1b6d8c1cbe --- /dev/null +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/AccountOverrideParameterTest.java @@ -0,0 +1,190 @@ +/* + * Copyright contributors to Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.util; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.hyperledger.besu.datatypes.AccountOverride; +import org.hyperledger.besu.datatypes.AccountOverrideMap; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; + +import java.util.Optional; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; + +public class AccountOverrideParameterTest { + + private static final String ADDRESS_HEX1 = "0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3"; + private static final String ADDRESS_HEX2 = "0xd5E23607D5d73ff2293152f464C3caB005f87696"; + private static final String STORAGE_KEY = + "0x1cf7945003fc5b59d2f6736f0704557aa805c4f2844084ccd1173b8d56946962"; + private static final String STORAGE_VALUE = + "0x000000000000000000000000000000000000000000000000000000110ed03bf7"; + private static final String CODE_STRING = + "0xdbf4257000000000000000000000000000000000000000000000000000000000"; + + @Test + public void jsonDeserializesCorrectly() throws Exception { + final String json = + "{\"jsonrpc\":\"2.0\",\"method\":\"eth_call\",\"params\":[{" + + "\"from\":\"0x0\", \"to\": \"0x0\"}, " + + "\"latest\"," + + "{\"" + + ADDRESS_HEX1 + + "\":" + + "{" + + "\"balance\": \"0x01\"," + + "\"nonce\": 88" + + "}}],\"id\":1}"; + + final JsonRpcRequestContext request = new JsonRpcRequestContext(readJsonAsJsonRpcRequest(json)); + final AccountOverrideMap accountOverrideParam = + request.getRequiredParameter(2, AccountOverrideMap.class); + + final AccountOverride accountOverride = + accountOverrideParam.get(Address.fromHexString(ADDRESS_HEX1)); + + assertThat(accountOverride.getNonce()).isEqualTo(Optional.of(88L)); + assertThat(accountOverride.getBalance()).isEqualTo(Optional.of(Wei.of(1))); + assertFalse(accountOverride.getStateDiff().isPresent()); + } + + @Test + public void jsonWithCodeDeserializesCorrectly() throws Exception { + final String json = + "{\"jsonrpc\":\"2.0\",\"method\":\"eth_call\",\"params\":[{" + + "\"from\":\"0x0\", \"to\": \"0x0\"}, " + + "\"latest\"," + + "{\"" + + ADDRESS_HEX1 + + "\":" + + "{" + + "\"balance\": \"0x01\"," + + "\"code\": \"" + + CODE_STRING + + "\"" + + "}}],\"id\":1}"; + + final JsonRpcRequestContext request = new JsonRpcRequestContext(readJsonAsJsonRpcRequest(json)); + final AccountOverrideMap accountOverrideParam = + request.getRequiredParameter(2, AccountOverrideMap.class); + + final AccountOverride accountOverride = + accountOverrideParam.get(Address.fromHexString(ADDRESS_HEX1)); + + assertFalse(accountOverride.getNonce().isPresent()); + assertThat(accountOverride.getBalance()).isEqualTo(Optional.of(Wei.of(1))); + assertThat(accountOverride.getCode()).isEqualTo(Optional.of(CODE_STRING)); + assertFalse(accountOverride.getStateDiff().isPresent()); + } + + @Test + public void jsonWithStorageOverridesDeserializesCorrectly() throws Exception { + final String json = + "{\"jsonrpc\":\"2.0\",\"method\":\"eth_call\",\"params\":[{" + + "\"from\":\"0x0\", \"to\": \"0x0\"}, " + + "\"latest\"," + + "{\"" + + ADDRESS_HEX1 + + "\":" + + "{" + + "\"balance\": \"0x01\"," + + "\"nonce\": 88," + + "\"stateDiff\": {" + + "\"" + + STORAGE_KEY + + "\": \"" + + STORAGE_VALUE + + "\"" + + "}}}],\"id\":1}"; + + final JsonRpcRequestContext request = new JsonRpcRequestContext(readJsonAsJsonRpcRequest(json)); + + final AccountOverrideMap accountOverrideParam = + request.getRequiredParameter(2, AccountOverrideMap.class); + assertThat(accountOverrideParam.size()).isEqualTo(1); + + final AccountOverride accountOverride = + accountOverrideParam.get(Address.fromHexString(ADDRESS_HEX1)); + assertThat(accountOverride.getNonce()).isEqualTo(Optional.of(88L)); + + assertTrue(accountOverride.getStateDiff().isPresent()); + assertThat(accountOverride.getStateDiff().get().get(STORAGE_KEY)).isEqualTo(STORAGE_VALUE); + } + + @Test + public void jsonWithMultipleAccountOverridesDeserializesCorrectly() throws Exception { + final String json = + "{\"jsonrpc\":\"2.0\",\"method\":\"eth_call\",\"params\":[{" + + "\"from\":\"0x0\", \"to\": \"0x0\"}, " + + "\"latest\"," + + "{\"" + + ADDRESS_HEX1 + + "\":" + + "{" + + "\"balance\": \"0x01\"," + + "\"nonce\": 88," + + "\"stateDiff\": {" + + "\"" + + STORAGE_KEY + + "\": \"" + + STORAGE_VALUE + + "\"" + + "}}," + + "\"" + + ADDRESS_HEX2 + + "\":" + + "{" + + "\"balance\": \"0xFF\"," + + "\"nonce\": 99," + + "\"stateDiff\": {" + + "\"" + + STORAGE_KEY + + "\": \"" + + STORAGE_VALUE + + "\"" + + "}}}],\"id\":1}"; + + final JsonRpcRequestContext request = new JsonRpcRequestContext(readJsonAsJsonRpcRequest(json)); + + final AccountOverrideMap accountOverrideParam = + request.getRequiredParameter(2, AccountOverrideMap.class); + assertThat(accountOverrideParam.size()).isEqualTo(2); + + final AccountOverride accountOverride1 = + accountOverrideParam.get(Address.fromHexString(ADDRESS_HEX1)); + assertThat(accountOverride1.getNonce()).isEqualTo(Optional.of(88L)); + assertThat(accountOverride1.getBalance()).isEqualTo(Optional.of(Wei.fromHexString("0x01"))); + assertTrue(accountOverride1.getStateDiff().isPresent()); + assertThat(accountOverride1.getStateDiff().get().get(STORAGE_KEY)).isEqualTo(STORAGE_VALUE); + + final AccountOverride accountOverride2 = + accountOverrideParam.get(Address.fromHexString(ADDRESS_HEX2)); + assertThat(accountOverride2.getNonce()).isEqualTo(Optional.of(99L)); + assertThat(accountOverride2.getBalance()).isEqualTo(Optional.of(Wei.fromHexString("0xFF"))); + assertTrue(accountOverride2.getStateDiff().isPresent()); + assertThat(accountOverride2.getStateDiff().get().get(STORAGE_KEY)).isEqualTo(STORAGE_VALUE); + } + + private JsonRpcRequest readJsonAsJsonRpcRequest(final String json) throws java.io.IOException { + return new ObjectMapper().readValue(json, JsonRpcRequest.class); + } +} diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/StateTrieAccountValueTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/StateTrieAccountValueTest.java index 5ce385570c..827900ef0c 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/StateTrieAccountValueTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/StateTrieAccountValueTest.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.rlp.RLPInput; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Test; @@ -41,11 +42,11 @@ public class StateTrieAccountValueTest { private void roundTripMainNetAccountValue( final long nonce, final Wei balance, final Hash storageRoot, final Hash codeHash) { - StateTrieAccountValue accountValue = - new StateTrieAccountValue(nonce, balance, storageRoot, codeHash); + PmtStateTrieAccountValue accountValue = + new PmtStateTrieAccountValue(nonce, balance, storageRoot, codeHash); Bytes encoded = RLP.encode(accountValue::writeTo); final RLPInput in = RLP.input(encoded); - StateTrieAccountValue roundTripAccountValue = StateTrieAccountValue.readFrom(in); + PmtStateTrieAccountValue roundTripAccountValue = PmtStateTrieAccountValue.readFrom(in); assertThat(nonce).isEqualTo(roundTripAccountValue.getNonce()); assertThat(balance).isEqualTo(roundTripAccountValue.getBalance()); 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 58318f9611..30cd03c15c 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 @@ -337,7 +337,6 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver { public void handleNewConnection(final PeerConnection connection) { ethPeers.registerNewConnection(connection, peerValidators); final EthPeer peer = ethPeers.peer(connection); - final Capability cap = connection.capability(getSupportedProtocol()); final ForkId latestForkId = cap.getVersion() >= 64 ? forkIdManager.getForkIdForChainHead() : null; diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthScheduler.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthScheduler.java index 1e2f3eb6ab..8c90993c68 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthScheduler.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthScheduler.java @@ -145,7 +145,7 @@ public class EthScheduler { servicesExecutor.execute(command); } - public CompletableFuture scheduleServiceTask(final Runnable task) { + public CompletableFuture scheduleServiceTask(final Runnable task) { return CompletableFuture.runAsync(task, servicesExecutor); } @@ -156,6 +156,19 @@ public class EthScheduler { return serviceFuture; } + public CompletableFuture scheduleServiceTask(final Supplier> future) { + final CompletableFuture promise = new CompletableFuture<>(); + final Future workerFuture = servicesExecutor.submit(() -> propagateResult(future, promise)); + // If returned promise is cancelled, cancel the worker future + promise.whenComplete( + (r, t) -> { + if (t instanceof CancellationException) { + workerFuture.cancel(false); + } + }); + return promise; + } + public CompletableFuture startPipeline(final Pipeline pipeline) { final CompletableFuture pipelineFuture = pipeline.start(servicesExecutor); pendingFutures.add(pipelineFuture); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/MonitoredExecutors.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/MonitoredExecutors.java index bf2389c1a8..02514db1e7 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/MonitoredExecutors.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/MonitoredExecutors.java @@ -153,13 +153,13 @@ public class MonitoredExecutors { "Current number of threads in the thread pool", executor::getPoolSize); - metricsSystem.createLongGauge( + metricsSystem.createCounter( BesuMetricCategory.EXECUTORS, metricName + "_completed_tasks_total", "Total number of tasks executed", executor::getCompletedTaskCount); - metricsSystem.createLongGauge( + metricsSystem.createCounter( BesuMetricCategory.EXECUTORS, metricName + "_submitted_tasks_total", "Total number of tasks executed", diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTask.java index 1243846ac3..fed671d38d 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTask.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTask.java @@ -41,13 +41,13 @@ public interface PeerTask { MessageData getRequestMessage(); /** - * Parses the MessageData response from the EthPeer + * Parses and processes the MessageData response from the EthPeer * * @param messageData the response MessageData to be parsed * @return a T built from the response MessageData * @throws InvalidPeerTaskResponseException if the response messageData is invalid */ - T parseResponse(MessageData messageData) throws InvalidPeerTaskResponseException; + T processResponse(MessageData messageData) throws InvalidPeerTaskResponseException; /** * Gets the number of times this task may be attempted against other peers diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java index 984cedccec..c8eed6e1f1 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java @@ -20,8 +20,8 @@ import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; -import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; import org.hyperledger.besu.plugin.services.metrics.OperationTimer; import java.util.Collection; @@ -43,7 +43,7 @@ public class PeerTaskExecutor { private final LabelledMetric timeoutCounter; private final LabelledMetric invalidResponseCounter; private final LabelledMetric internalExceptionCounter; - private final LabelledGauge inflightRequestGauge; + private final LabelledSuppliedMetric inflightRequestGauge; private final Map inflightRequestCountByClassName; public PeerTaskExecutor( @@ -77,7 +77,7 @@ public class PeerTaskExecutor { "Counter of the number of internal exceptions occurred", "taskName"); inflightRequestGauge = - metricsSystem.createLabelledGauge( + metricsSystem.createLabelledSuppliedGauge( BesuMetricCategory.PEERS, "inflight_request_gauge", "Gauge of the number of inflight requests", @@ -133,7 +133,7 @@ public class PeerTaskExecutor { MessageData responseMessageData = requestSender.sendRequest(peerTask.getSubProtocol(), requestMessageData, peer); - result = peerTask.parseResponse(responseMessageData); + result = peerTask.processResponse(responseMessageData); } finally { inflightRequestCountForThisTaskClass.decrementAndGet(); } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTask.java new file mode 100644 index 0000000000..7d4b5d585e --- /dev/null +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTask.java @@ -0,0 +1,135 @@ +/* + * Copyright contributors to Hyperledger Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.eth.manager.peertask.task; + +import static java.util.Collections.emptyList; + +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.TransactionReceipt; +import org.hyperledger.besu.ethereum.eth.EthProtocol; +import org.hyperledger.besu.ethereum.eth.manager.EthPeer; +import org.hyperledger.besu.ethereum.eth.manager.peertask.InvalidPeerTaskResponseException; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTask; +import org.hyperledger.besu.ethereum.eth.messages.GetReceiptsMessage; +import org.hyperledger.besu.ethereum.eth.messages.ReceiptsMessage; +import org.hyperledger.besu.ethereum.mainnet.BodyValidation; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; +import org.hyperledger.besu.ethereum.p2p.rlpx.wire.SubProtocol; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Predicate; + +public class GetReceiptsFromPeerTask + implements PeerTask>> { + + private final Collection blockHeaders; + private final ProtocolSchedule protocolSchedule; + private final Map> receiptsByBlockHeader = new HashMap<>(); + private final Map> headersByReceiptsRoot = new HashMap<>(); + private final long requiredBlockchainHeight; + + public GetReceiptsFromPeerTask( + final Collection blockHeaders, final ProtocolSchedule protocolSchedule) { + this.blockHeaders = new ArrayList<>(blockHeaders); + this.protocolSchedule = protocolSchedule; + + // pre-fill any headers with an empty receipts root into the result map + this.blockHeaders.stream() + .filter(header -> header.getReceiptsRoot().equals(Hash.EMPTY_TRIE_HASH)) + .forEach(header -> receiptsByBlockHeader.put(header, emptyList())); + this.blockHeaders.removeAll(receiptsByBlockHeader.keySet()); + + // group headers by their receipts root hash to reduce total number of receipts hashes requested + // for + this.blockHeaders.forEach( + header -> + headersByReceiptsRoot + .computeIfAbsent(header.getReceiptsRoot(), key -> new ArrayList<>()) + .add(header)); + + // calculate the minimum required blockchain height a peer will need to be able to fulfil this + // request + requiredBlockchainHeight = + this.blockHeaders.stream() + .mapToLong(BlockHeader::getNumber) + .max() + .orElse(BlockHeader.GENESIS_BLOCK_NUMBER); + } + + @Override + public SubProtocol getSubProtocol() { + return EthProtocol.get(); + } + + @Override + public MessageData getRequestMessage() { + // Since we have to match up the data by receipt root, we only need to request receipts + // for one of the headers with each unique receipt root. + final List blockHashes = + headersByReceiptsRoot.values().stream() + .map(headers -> headers.getFirst().getHash()) + .toList(); + return GetReceiptsMessage.create(blockHashes); + } + + @Override + public Map> processResponse(final MessageData messageData) + throws InvalidPeerTaskResponseException { + if (messageData == null) { + throw new InvalidPeerTaskResponseException(); + } + final ReceiptsMessage receiptsMessage = ReceiptsMessage.readFrom(messageData); + final List> receiptsByBlock = receiptsMessage.receipts(); + // take a copy of the pre-filled receiptsByBlockHeader, to ensure idempotency of subsequent + // calls to processResponse + final Map> receiptsByHeader = + new HashMap<>(receiptsByBlockHeader); + if (!blockHeaders.isEmpty()) { + if (receiptsByBlock.isEmpty() || receiptsByBlock.size() > blockHeaders.size()) { + throw new InvalidPeerTaskResponseException(); + } + + for (final List receiptsInBlock : receiptsByBlock) { + final List blockHeaders = + headersByReceiptsRoot.get(BodyValidation.receiptsRoot(receiptsInBlock)); + if (blockHeaders == null) { + // Contains receipts that we didn't request, so mustn't be the response we're looking for. + throw new InvalidPeerTaskResponseException(); + } + blockHeaders.forEach(header -> receiptsByHeader.put(header, receiptsInBlock)); + } + } + return receiptsByHeader; + } + + @Override + public Predicate getPeerRequirementFilter() { + return (ethPeer) -> + ethPeer.getProtocolName().equals(getSubProtocol().getName()) + && (protocolSchedule.anyMatch((ps) -> ps.spec().isPoS()) + || ethPeer.chainState().getEstimatedHeight() >= requiredBlockchainHeight); + } + + @Override + public boolean isSuccess(final Map> result) { + return !result.isEmpty(); + } +} diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapProtocolManager.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapProtocolManager.java index ce639a7a9a..2e49eba353 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapProtocolManager.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapProtocolManager.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.ethereum.eth.manager.snap; import org.hyperledger.besu.ethereum.ProtocolContext; +import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.SnapProtocol; import org.hyperledger.besu.ethereum.eth.manager.EthMessage; import org.hyperledger.besu.ethereum.eth.manager.EthMessages; @@ -53,11 +54,13 @@ public class SnapProtocolManager implements ProtocolManager { final SnapSyncConfiguration snapConfig, final EthPeers ethPeers, final EthMessages snapMessages, - final ProtocolContext protocolContext) { + final ProtocolContext protocolContext, + final Synchronizer synchronizer) { this.ethPeers = ethPeers; this.snapMessages = snapMessages; this.supportedCapabilities = calculateCapabilities(); - new SnapServer(snapConfig, snapMessages, worldStateStorageCoordinator, protocolContext); + new SnapServer( + snapConfig, snapMessages, worldStateStorageCoordinator, protocolContext, synchronizer); } private List calculateCapabilities() { diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServer.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServer.java index 4490430699..64b81ab8e8 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServer.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServer.java @@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.eth.manager.snap; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.ProtocolContext; +import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.manager.EthMessages; import org.hyperledger.besu.ethereum.eth.messages.snap.AccountRangeMessage; import org.hyperledger.besu.ethereum.eth.messages.snap.ByteCodesMessage; @@ -99,7 +100,8 @@ class SnapServer implements BesuEvents.InitialSyncCompletionListener { final SnapSyncConfiguration snapConfig, final EthMessages snapMessages, final WorldStateStorageCoordinator worldStateStorageCoordinator, - final ProtocolContext protocolContext) { + final ProtocolContext protocolContext, + final Synchronizer synchronizer) { this.snapServerEnabled = Optional.ofNullable(snapConfig) .map(SnapSyncConfiguration::isSnapServerEnabled) @@ -111,7 +113,7 @@ class SnapServer implements BesuEvents.InitialSyncCompletionListener { // subscribe to initial sync completed events to start/stop snap server, // not saving the listenerId since we never need to unsubscribe. - protocolContext.getSynchronizer().subscribeInitialSync(this); + synchronizer.subscribeInitialSync(this); } /** diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/snap/AccountRangeMessage.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/snap/AccountRangeMessage.java index 71d0429592..9c6e1f9399 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/snap/AccountRangeMessage.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/snap/AccountRangeMessage.java @@ -20,7 +20,7 @@ import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.hyperledger.besu.ethereum.rlp.RLPInput; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import java.math.BigInteger; import java.util.List; @@ -121,7 +121,7 @@ public final class AccountRangeMessage extends AbstractSnapMessageData { @VisibleForTesting public static Bytes toFullAccount(final RLPInput rlpInput) { - final StateTrieAccountValue accountValue = StateTrieAccountValue.readFrom(rlpInput); + final PmtStateTrieAccountValue accountValue = PmtStateTrieAccountValue.readFrom(rlpInput); final BytesValueRLPOutput rlpOutput = new BytesValueRLPOutput(); rlpOutput.startList(); @@ -135,7 +135,7 @@ public final class AccountRangeMessage extends AbstractSnapMessageData { } public static Bytes toSlimAccount(final RLPInput rlpInput) { - StateTrieAccountValue accountValue = StateTrieAccountValue.readFrom(rlpInput); + PmtStateTrieAccountValue accountValue = PmtStateTrieAccountValue.readFrom(rlpInput); var rlpOutput = new BytesValueRLPOutput(); rlpOutput.startList(); rlpOutput.writeLongScalar(accountValue.getNonce()); 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 2384437299..66684ab787 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 @@ -22,6 +22,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.manager.EthContext; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.sync.checkpointsync.CheckpointDownloaderFactory; import org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncDownloader; import org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncState; @@ -82,6 +83,7 @@ public class DefaultSynchronizer implements Synchronizer, UnverifiedForkchoiceLi final WorldStateStorageCoordinator worldStateStorageCoordinator, final BlockBroadcaster blockBroadcaster, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final SyncState syncState, final Path dataDirectory, final StorageProvider storageProvider, @@ -147,6 +149,7 @@ public class DefaultSynchronizer implements Synchronizer, UnverifiedForkchoiceLi protocolContext, metricsSystem, ethContext, + peerTaskExecutor, worldStateStorageCoordinator, syncState, clock, @@ -163,6 +166,7 @@ public class DefaultSynchronizer implements Synchronizer, UnverifiedForkchoiceLi protocolContext, metricsSystem, ethContext, + peerTaskExecutor, worldStateStorageCoordinator, syncState, clock, @@ -179,6 +183,7 @@ public class DefaultSynchronizer implements Synchronizer, UnverifiedForkchoiceLi protocolContext, metricsSystem, ethContext, + peerTaskExecutor, worldStateStorageCoordinator, syncState, clock, diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloadBlockStep.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloadBlockStep.java index b4bdf58541..72f1fae764 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloadBlockStep.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloadBlockStep.java @@ -16,17 +16,23 @@ package org.hyperledger.besu.ethereum.eth.sync.checkpointsync; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.core.Block; +import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockWithReceipts; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResponseCode; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResult; +import org.hyperledger.besu.ethereum.eth.manager.peertask.task.GetReceiptsFromPeerTask; import org.hyperledger.besu.ethereum.eth.manager.task.AbstractPeerTask.PeerTaskResult; import org.hyperledger.besu.ethereum.eth.manager.task.GetBlockFromPeerTask; -import org.hyperledger.besu.ethereum.eth.manager.task.GetReceiptsFromPeerTask; +import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import org.hyperledger.besu.ethereum.eth.sync.fastsync.checkpoint.Checkpoint; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.plugin.services.MetricsSystem; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.concurrent.CompletableFuture; @@ -34,17 +40,23 @@ public class CheckpointDownloadBlockStep { private final ProtocolSchedule protocolSchedule; private final EthContext ethContext; + private final PeerTaskExecutor peerTaskExecutor; private final Checkpoint checkpoint; + private final SynchronizerConfiguration synchronizerConfiguration; private final MetricsSystem metricsSystem; public CheckpointDownloadBlockStep( final ProtocolSchedule protocolSchedule, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final Checkpoint checkpoint, + final SynchronizerConfiguration synchronizerConfiguration, final MetricsSystem metricsSystem) { this.protocolSchedule = protocolSchedule; this.ethContext = ethContext; + this.peerTaskExecutor = peerTaskExecutor; this.checkpoint = checkpoint; + this.synchronizerConfiguration = synchronizerConfiguration; this.metricsSystem = metricsSystem; } @@ -65,17 +77,52 @@ public class CheckpointDownloadBlockStep { private CompletableFuture> downloadReceipts( final PeerTaskResult peerTaskResult) { final Block block = peerTaskResult.getResult(); - final GetReceiptsFromPeerTask getReceiptsFromPeerTask = - GetReceiptsFromPeerTask.forHeaders(ethContext, List.of(block.getHeader()), metricsSystem); - return getReceiptsFromPeerTask - .run() - .thenCompose( - receiptTaskResult -> { - final Optional> transactionReceipts = - Optional.ofNullable(receiptTaskResult.getResult().get(block.getHeader())); - return CompletableFuture.completedFuture( - transactionReceipts.map(receipts -> new BlockWithReceipts(block, receipts))); - }) - .exceptionally(throwable -> Optional.empty()); + if (synchronizerConfiguration.isPeerTaskSystemEnabled()) { + return ethContext + .getScheduler() + .scheduleServiceTask( + () -> { + GetReceiptsFromPeerTask task = + new GetReceiptsFromPeerTask(List.of(block.getHeader()), protocolSchedule); + PeerTaskExecutorResult>> executorResult = + peerTaskExecutor.execute(task); + + if (executorResult.responseCode() == PeerTaskExecutorResponseCode.SUCCESS) { + List transactionReceipts = + executorResult + .result() + .map((map) -> map.get(block.getHeader())) + .orElseThrow( + () -> + new IllegalStateException( + "PeerTask response code was success, but empty")); + if (block.getBody().getTransactions().size() != transactionReceipts.size()) { + throw new IllegalStateException( + "PeerTask response code was success, but incorrect number of receipts returned"); + } + BlockWithReceipts blockWithReceipts = + new BlockWithReceipts(block, transactionReceipts); + return CompletableFuture.completedFuture(Optional.of(blockWithReceipts)); + } else { + return CompletableFuture.completedFuture(Optional.empty()); + } + }); + + } else { + final org.hyperledger.besu.ethereum.eth.manager.task.GetReceiptsFromPeerTask + getReceiptsFromPeerTask = + org.hyperledger.besu.ethereum.eth.manager.task.GetReceiptsFromPeerTask.forHeaders( + ethContext, List.of(block.getHeader()), metricsSystem); + return getReceiptsFromPeerTask + .run() + .thenCompose( + receiptTaskResult -> { + final Optional> transactionReceipts = + Optional.ofNullable(receiptTaskResult.getResult().get(block.getHeader())); + return CompletableFuture.completedFuture( + transactionReceipts.map(receipts -> new BlockWithReceipts(block, receipts))); + }) + .exceptionally(throwable -> Optional.empty()); + } } } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloaderFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloaderFactory.java index 03df47e440..30134d9f6c 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloaderFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloaderFactory.java @@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.eth.sync.checkpointsync; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.eth.manager.EthContext; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.sync.PivotBlockSelector; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; @@ -61,6 +62,7 @@ public class CheckpointDownloaderFactory extends SnapDownloaderFactory { final ProtocolContext protocolContext, final MetricsSystem metricsSystem, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final WorldStateStorageCoordinator worldStateStorageCoordinator, final SyncState syncState, final Clock clock, @@ -110,6 +112,7 @@ public class CheckpointDownloaderFactory extends SnapDownloaderFactory { protocolSchedule, protocolContext, ethContext, + peerTaskExecutor, syncState, pivotBlockSelector, metricsSystem); @@ -127,6 +130,7 @@ public class CheckpointDownloaderFactory extends SnapDownloaderFactory { protocolSchedule, protocolContext, ethContext, + peerTaskExecutor, syncState, pivotBlockSelector, metricsSystem); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncActions.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncActions.java index 5096b74e24..61b997e6c5 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncActions.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncActions.java @@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.eth.sync.checkpointsync; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.sync.ChainDownloader; import org.hyperledger.besu.ethereum.eth.sync.PivotBlockSelector; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; @@ -34,6 +35,7 @@ public class CheckpointSyncActions extends FastSyncActions { final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final SyncState syncState, final PivotBlockSelector pivotBlockSelector, final MetricsSystem metricsSystem) { @@ -43,6 +45,7 @@ public class CheckpointSyncActions extends FastSyncActions { protocolSchedule, protocolContext, ethContext, + peerTaskExecutor, syncState, pivotBlockSelector, metricsSystem); @@ -57,6 +60,7 @@ public class CheckpointSyncActions extends FastSyncActions { protocolSchedule, protocolContext, ethContext, + peerTaskExecutor, syncState, metricsSystem, currentState, diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncChainDownloader.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncChainDownloader.java index 5450b9e5a4..2590e4736a 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncChainDownloader.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncChainDownloader.java @@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.eth.sync.checkpointsync; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.sync.ChainDownloader; import org.hyperledger.besu.ethereum.eth.sync.PipelineChainDownloader; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; @@ -36,6 +37,7 @@ public class CheckpointSyncChainDownloader extends FastSyncChainDownloader { final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final SyncState syncState, final MetricsSystem metricsSystem, final FastSyncState fastSyncState, @@ -55,7 +57,13 @@ public class CheckpointSyncChainDownloader extends FastSyncChainDownloader { syncState, syncTargetManager, new CheckpointSyncDownloadPipelineFactory( - config, protocolSchedule, protocolContext, ethContext, fastSyncState, metricsSystem), + config, + protocolSchedule, + protocolContext, + ethContext, + peerTaskExecutor, + fastSyncState, + metricsSystem), ethContext.getScheduler(), metricsSystem, syncDurationMetrics); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncDownloadPipelineFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncDownloadPipelineFactory.java index 45f3f243d8..0be1086986 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncDownloadPipelineFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncDownloadPipelineFactory.java @@ -19,6 +19,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncDownloadPipelineFactory; import org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncState; @@ -40,9 +41,17 @@ public class CheckpointSyncDownloadPipelineFactory extends FastSyncDownloadPipel final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final FastSyncState fastSyncState, final MetricsSystem metricsSystem) { - super(syncConfig, protocolSchedule, protocolContext, ethContext, fastSyncState, metricsSystem); + super( + syncConfig, + protocolSchedule, + protocolContext, + ethContext, + peerTaskExecutor, + fastSyncState, + metricsSystem); } @Override @@ -76,7 +85,8 @@ public class CheckpointSyncDownloadPipelineFactory extends FastSyncDownloadPipel checkPointSource, checkpoint, protocolContext.getBlockchain()); final CheckpointDownloadBlockStep checkPointDownloadBlockStep = - new CheckpointDownloadBlockStep(protocolSchedule, ethContext, checkpoint, metricsSystem); + new CheckpointDownloadBlockStep( + protocolSchedule, ethContext, peerTaskExecutor, checkpoint, syncConfig, metricsSystem); return PipelineBuilder.createPipelineFrom( "fetchCheckpoints", diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStep.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStep.java index cd57de371d..876e96d107 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStep.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStep.java @@ -22,10 +22,16 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockWithReceipts; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResponseCode; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResult; +import org.hyperledger.besu.ethereum.eth.manager.peertask.task.GetReceiptsFromPeerTask; +import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import org.hyperledger.besu.ethereum.eth.sync.tasks.GetReceiptsForHeadersTask; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.plugin.services.MetricsSystem; -import org.hyperledger.besu.util.FutureUtils; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; @@ -33,24 +39,69 @@ import java.util.function.Function; public class DownloadReceiptsStep implements Function, CompletableFuture>> { + + private final ProtocolSchedule protocolSchedule; private final EthContext ethContext; + private final PeerTaskExecutor peerTaskExecutor; + private final SynchronizerConfiguration synchronizerConfiguration; private final MetricsSystem metricsSystem; - public DownloadReceiptsStep(final EthContext ethContext, final MetricsSystem metricsSystem) { + public DownloadReceiptsStep( + final ProtocolSchedule protocolSchedule, + final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, + final SynchronizerConfiguration synchronizerConfiguration, + final MetricsSystem metricsSystem) { + this.protocolSchedule = protocolSchedule; this.ethContext = ethContext; + this.peerTaskExecutor = peerTaskExecutor; + this.synchronizerConfiguration = synchronizerConfiguration; this.metricsSystem = metricsSystem; } @Override public CompletableFuture> apply(final List blocks) { final List headers = blocks.stream().map(Block::getHeader).collect(toList()); - final CompletableFuture>> getReceipts = - GetReceiptsForHeadersTask.forHeaders(ethContext, headers, metricsSystem).run(); - final CompletableFuture> combineWithBlocks = - getReceipts.thenApply( - receiptsByHeader -> combineBlocksAndReceipts(blocks, receiptsByHeader)); - FutureUtils.propagateCancellation(combineWithBlocks, getReceipts); - return combineWithBlocks; + if (synchronizerConfiguration.isPeerTaskSystemEnabled()) { + return ethContext + .getScheduler() + .scheduleServiceTask(() -> getReceiptsWithPeerTaskSystem(headers)) + .thenApply((receipts) -> combineBlocksAndReceipts(blocks, receipts)); + + } else { + return GetReceiptsForHeadersTask.forHeaders(ethContext, headers, metricsSystem) + .run() + .thenApply((receipts) -> combineBlocksAndReceipts(blocks, receipts)); + } + } + + private CompletableFuture>> + getReceiptsWithPeerTaskSystem(final List headers) { + Map> getReceipts = new HashMap<>(); + do { + GetReceiptsFromPeerTask task = new GetReceiptsFromPeerTask(headers, protocolSchedule); + PeerTaskExecutorResult>> getReceiptsResult = + peerTaskExecutor.execute(task); + if (getReceiptsResult.responseCode() == PeerTaskExecutorResponseCode.SUCCESS + && getReceiptsResult.result().isPresent()) { + Map> taskResult = getReceiptsResult.result().get(); + taskResult + .keySet() + .forEach( + (blockHeader) -> + getReceipts.merge( + blockHeader, + taskResult.get(blockHeader), + (initialReceipts, newReceipts) -> { + throw new IllegalStateException( + "Unexpectedly got receipts for block header already populated!"); + })); + // remove all the headers we found receipts for + headers.removeAll(getReceipts.keySet()); + } + // repeat until all headers have receipts + } while (!headers.isEmpty()); + return CompletableFuture.completedFuture(getReceipts); } private List combineBlocksAndReceipts( @@ -60,8 +111,17 @@ public class DownloadReceiptsStep block -> { final List receipts = receiptsByHeader.getOrDefault(block.getHeader(), emptyList()); + if (block.getBody().getTransactions().size() != receipts.size()) { + throw new IllegalStateException( + "PeerTask response code was success, but incorrect number of receipts returned. Header hash: " + + block.getHeader().getHash() + + ", Transactions: " + + block.getBody().getTransactions().size() + + ", receipts: " + + receipts.size()); + } return new BlockWithReceipts(block, receipts); }) - .collect(toList()); + .toList(); } } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActions.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActions.java index 7f6bbae3f3..58a64bd562 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActions.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActions.java @@ -19,6 +19,7 @@ import static java.util.concurrent.CompletableFuture.completedFuture; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.manager.task.WaitForPeersTask; import org.hyperledger.besu.ethereum.eth.sync.ChainDownloader; import org.hyperledger.besu.ethereum.eth.sync.PivotBlockSelector; @@ -48,6 +49,7 @@ public class FastSyncActions { protected final ProtocolSchedule protocolSchedule; protected final ProtocolContext protocolContext; protected final EthContext ethContext; + protected final PeerTaskExecutor peerTaskExecutor; protected final SyncState syncState; protected final PivotBlockSelector pivotBlockSelector; protected final MetricsSystem metricsSystem; @@ -60,6 +62,7 @@ public class FastSyncActions { final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final SyncState syncState, final PivotBlockSelector pivotBlockSelector, final MetricsSystem metricsSystem) { @@ -68,6 +71,7 @@ public class FastSyncActions { this.protocolSchedule = protocolSchedule; this.protocolContext = protocolContext; this.ethContext = ethContext; + this.peerTaskExecutor = peerTaskExecutor; this.syncState = syncState; this.pivotBlockSelector = pivotBlockSelector; this.metricsSystem = metricsSystem; @@ -164,6 +168,7 @@ public class FastSyncActions { protocolSchedule, protocolContext, ethContext, + peerTaskExecutor, syncState, metricsSystem, currentState, diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloader.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloader.java index c36ff7cb48..1bf55a3811 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloader.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloader.java @@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.eth.sync.fastsync; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.sync.ChainDownloader; import org.hyperledger.besu.ethereum.eth.sync.PipelineChainDownloader; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; @@ -35,6 +36,7 @@ public class FastSyncChainDownloader { final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final SyncState syncState, final MetricsSystem metricsSystem, final FastSyncState fastSyncState, @@ -53,7 +55,13 @@ public class FastSyncChainDownloader { syncState, syncTargetManager, new FastSyncDownloadPipelineFactory( - config, protocolSchedule, protocolContext, ethContext, fastSyncState, metricsSystem), + config, + protocolSchedule, + protocolContext, + ethContext, + peerTaskExecutor, + fastSyncState, + metricsSystem), ethContext.getScheduler(), metricsSystem, syncDurationMetrics); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java index 87032b76e5..67085252e8 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java @@ -26,6 +26,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthPeer; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.sync.DownloadBodiesStep; import org.hyperledger.besu.ethereum.eth.sync.DownloadHeadersStep; import org.hyperledger.besu.ethereum.eth.sync.DownloadPipelineFactory; @@ -37,7 +38,6 @@ import org.hyperledger.besu.ethereum.eth.sync.range.SyncTargetRange; import org.hyperledger.besu.ethereum.eth.sync.range.SyncTargetRangeSource; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.eth.sync.state.SyncTarget; -import org.hyperledger.besu.ethereum.mainnet.BodyValidationMode; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.plugin.services.MetricsSystem; @@ -58,6 +58,7 @@ public class FastSyncDownloadPipelineFactory implements DownloadPipelineFactory protected final ProtocolSchedule protocolSchedule; protected final ProtocolContext protocolContext; protected final EthContext ethContext; + protected final PeerTaskExecutor peerTaskExecutor; protected final FastSyncState fastSyncState; protected final MetricsSystem metricsSystem; protected final FastSyncValidationPolicy attachedValidationPolicy; @@ -69,12 +70,14 @@ public class FastSyncDownloadPipelineFactory implements DownloadPipelineFactory final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final FastSyncState fastSyncState, final MetricsSystem metricsSystem) { this.syncConfig = syncConfig; this.protocolSchedule = protocolSchedule; this.protocolContext = protocolContext; this.ethContext = ethContext; + this.peerTaskExecutor = peerTaskExecutor; this.fastSyncState = fastSyncState; this.metricsSystem = metricsSystem; final LabelledMetric fastSyncValidationCounter = @@ -118,10 +121,7 @@ public class FastSyncDownloadPipelineFactory implements DownloadPipelineFactory final int downloaderParallelism = syncConfig.getDownloaderParallelism(); final int headerRequestSize = syncConfig.getDownloaderHeaderRequestSize(); final int singleHeaderBufferSize = headerRequestSize * downloaderParallelism; - final BodyValidationMode bodyValidationMode = - protocolSchedule.anyMatch(scheduledProtocolSpec -> scheduledProtocolSpec.spec().isPoS()) - ? BodyValidationMode.NONE - : BodyValidationMode.LIGHT; + final SyncTargetRangeSource checkpointRangeSource = new SyncTargetRangeSource( new RangeHeadersFetcher( @@ -145,7 +145,8 @@ public class FastSyncDownloadPipelineFactory implements DownloadPipelineFactory final DownloadBodiesStep downloadBodiesStep = new DownloadBodiesStep(protocolSchedule, ethContext, metricsSystem); final DownloadReceiptsStep downloadReceiptsStep = - new DownloadReceiptsStep(ethContext, metricsSystem); + new DownloadReceiptsStep( + protocolSchedule, ethContext, peerTaskExecutor, syncConfig, metricsSystem); final ImportBlocksStep importBlockStep = new ImportBlocksStep( protocolSchedule, @@ -153,8 +154,7 @@ public class FastSyncDownloadPipelineFactory implements DownloadPipelineFactory attachedValidationPolicy, ommerValidationPolicy, ethContext, - fastSyncState.getPivotBlockHeader().get(), - bodyValidationMode); + fastSyncState.getPivotBlockHeader().get()); return PipelineBuilder.createPipelineFrom( "fetchCheckpoints", diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStep.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStep.java index 20b9d84916..4397ed011c 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStep.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStep.java @@ -54,15 +54,17 @@ public class ImportBlocksStep implements Consumer> { final ValidationPolicy headerValidationPolicy, final ValidationPolicy ommerValidationPolicy, final EthContext ethContext, - final BlockHeader pivotHeader, - final BodyValidationMode bodyValidationMode) { + final BlockHeader pivotHeader) { this.protocolSchedule = protocolSchedule; this.protocolContext = protocolContext; this.headerValidationPolicy = headerValidationPolicy; this.ommerValidationPolicy = ommerValidationPolicy; this.ethContext = ethContext; this.pivotHeader = pivotHeader; - this.bodyValidationMode = bodyValidationMode; + bodyValidationMode = + protocolSchedule.anyMatch(scheduledProtocolSpec -> scheduledProtocolSpec.spec().isPoS()) + ? BodyValidationMode.NONE + : BodyValidationMode.LIGHT; } @Override diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/AccountTrieNodeDataRequest.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/AccountTrieNodeDataRequest.java index 366cfd50f5..28ac75e52f 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/AccountTrieNodeDataRequest.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/AccountTrieNodeDataRequest.java @@ -21,7 +21,7 @@ import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.rlp.RLPOutput; import org.hyperledger.besu.ethereum.trie.CompactEncoding; import org.hyperledger.besu.ethereum.trie.MerkleTrie; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; @@ -73,7 +73,8 @@ class AccountTrieNodeDataRequest extends TrieNodeDataRequest { final Bytes path, final Bytes value) { final Stream.Builder builder = Stream.builder(); - final StateTrieAccountValue accountValue = StateTrieAccountValue.readFrom(RLP.input(value)); + final PmtStateTrieAccountValue accountValue = + PmtStateTrieAccountValue.readFrom(RLP.input(value)); final Optional accountHash = Optional.of( diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastDownloaderFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastDownloaderFactory.java index 8b71a57885..1d775cc80f 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastDownloaderFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastDownloaderFactory.java @@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.eth.sync.fastsync.worldstate; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.eth.manager.EthContext; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.sync.PivotBlockSelector; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; @@ -59,6 +60,7 @@ public class FastDownloaderFactory { final ProtocolContext protocolContext, final MetricsSystem metricsSystem, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final WorldStateStorageCoordinator worldStateStorageCoordinator, final SyncState syncState, final Clock clock, @@ -126,6 +128,7 @@ public class FastDownloaderFactory { protocolSchedule, protocolContext, ethContext, + peerTaskExecutor, syncState, pivotBlockSelector, metricsSystem), diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapDownloaderFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapDownloaderFactory.java index 5de8ceb984..6c5ce0b04e 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapDownloaderFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapDownloaderFactory.java @@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.eth.sync.snapsync; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.eth.manager.EthContext; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.sync.PivotBlockSelector; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; @@ -57,6 +58,7 @@ public class SnapDownloaderFactory extends FastDownloaderFactory { final ProtocolContext protocolContext, final MetricsSystem metricsSystem, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final WorldStateStorageCoordinator worldStateStorageCoordinator, final SyncState syncState, final Clock clock, @@ -121,6 +123,7 @@ public class SnapDownloaderFactory extends FastDownloaderFactory { protocolSchedule, protocolContext, ethContext, + peerTaskExecutor, syncState, pivotBlockSelector, metricsSystem), diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapSyncMetricsManager.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapSyncMetricsManager.java index 1091c766bd..ddd4f781b1 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapSyncMetricsManager.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapSyncMetricsManager.java @@ -91,37 +91,37 @@ public class SnapSyncMetricsManager { nbFlatAccountsHealed = new AtomicLong(0); nbFlatSlotsHealed = new AtomicLong(0); nbTrieNodesHealed = new AtomicLong(0); - metricsSystem.createLongGauge( + metricsSystem.createCounter( BesuMetricCategory.SYNCHRONIZER, "snap_world_state_generated_nodes_total", "Total number of data nodes generated as part of snap sync world state download", nbTrieNodesGenerated::get); - metricsSystem.createLongGauge( + metricsSystem.createCounter( BesuMetricCategory.SYNCHRONIZER, "snap_world_state_healed_nodes_total", "Total number of data nodes healed as part of snap sync world state heal process", nbTrieNodesHealed::get); - metricsSystem.createLongGauge( + metricsSystem.createCounter( BesuMetricCategory.SYNCHRONIZER, "snap_world_state_accounts_total", "Total number of accounts downloaded as part of snap sync world state", nbAccountsDownloaded::get); - metricsSystem.createLongGauge( + metricsSystem.createCounter( BesuMetricCategory.SYNCHRONIZER, "snap_world_state_slots_total", "Total number of slots downloaded as part of snap sync world state", nbSlotsDownloaded::get); - metricsSystem.createLongGauge( + metricsSystem.createCounter( BesuMetricCategory.SYNCHRONIZER, "snap_world_state_flat_accounts_healed_total", "Total number of accounts healed in the flat database as part of snap sync world state", nbFlatAccountsHealed::get); - metricsSystem.createLongGauge( + metricsSystem.createCounter( BesuMetricCategory.SYNCHRONIZER, "snap_world_state_flat_slots_healed_total", "Total number of slots healed in the flat database as part of snap sync world state", nbFlatSlotsHealed::get); - metricsSystem.createLongGauge( + metricsSystem.createCounter( BesuMetricCategory.SYNCHRONIZER, "snap_world_state_codes_total", "Total number of codes downloaded as part of snap sync world state", diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/AccountRangeDataRequest.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/AccountRangeDataRequest.java index 21a707e9a6..c7e76edc3f 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/AccountRangeDataRequest.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/AccountRangeDataRequest.java @@ -31,9 +31,9 @@ import org.hyperledger.besu.ethereum.proof.WorldStateProofProvider; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.rlp.RLPInput; import org.hyperledger.besu.ethereum.trie.NodeUpdater; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.FlatDbMode; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; @@ -210,8 +210,8 @@ public class AccountRangeDataRequest extends SnapDataRequest { // find missing storages and code for (Map.Entry account : taskElement.keys().entrySet()) { - final StateTrieAccountValue accountValue = - StateTrieAccountValue.readFrom(RLP.input(account.getValue())); + final PmtStateTrieAccountValue accountValue = + PmtStateTrieAccountValue.readFrom(RLP.input(account.getValue())); if (!accountValue.getStorageRoot().equals(Hash.EMPTY_TRIE_HASH)) { childRequests.add( createStorageRangeDataRequest( diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountFlatDatabaseHealingRangeRequest.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountFlatDatabaseHealingRangeRequest.java index 7e66fa7d88..195cd85a57 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountFlatDatabaseHealingRangeRequest.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountFlatDatabaseHealingRangeRequest.java @@ -31,9 +31,9 @@ import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.RangeManager; import org.hyperledger.besu.ethereum.trie.RangeStorageEntriesCollector; import org.hyperledger.besu.ethereum.trie.TrieIterator; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; @@ -104,8 +104,8 @@ public class AccountFlatDatabaseHealingRangeRequest extends SnapDataRequest { if (downloadState .getAccountsHealingList() .contains(CompactEncoding.bytesToPath(account.getKey()))) { - final StateTrieAccountValue accountValue = - StateTrieAccountValue.readFrom(RLP.input(account.getValue())); + final PmtStateTrieAccountValue accountValue = + PmtStateTrieAccountValue.readFrom(RLP.input(account.getValue())); childRequests.add( createStorageFlatHealingRangeRequest( getRootHash(), diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountTrieNodeHealingRequest.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountTrieNodeHealingRequest.java index be6060d52e..70929f7dd9 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountTrieNodeHealingRequest.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountTrieNodeHealingRequest.java @@ -25,8 +25,8 @@ import org.hyperledger.besu.ethereum.eth.sync.snapsync.request.SnapDataRequest; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.trie.CompactEncoding; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; @@ -120,7 +120,7 @@ public class AccountTrieNodeHealingRequest extends TrieNodeHealingRequest { getLocation().size(), account.size() - getLocation().size())) .map(RLP::input) - .map(StateTrieAccountValue::readFrom) + .map(PmtStateTrieAccountValue::readFrom) .filter( stateTrieAccountValue -> // We need to ensure that the accounts to be healed do not have empty storage. @@ -152,7 +152,8 @@ public class AccountTrieNodeHealingRequest extends TrieNodeHealingRequest { final Bytes path, final Bytes value) { final Stream.Builder builder = Stream.builder(); - final StateTrieAccountValue accountValue = StateTrieAccountValue.readFrom(RLP.input(value)); + final PmtStateTrieAccountValue accountValue = + PmtStateTrieAccountValue.readFrom(RLP.input(value)); // Retrieve account hash final Hash accountHash = diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionBroadcaster.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionBroadcaster.java index c60c064c4c..35f438d419 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionBroadcaster.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionBroadcaster.java @@ -37,7 +37,8 @@ import com.google.common.annotations.VisibleForTesting; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class TransactionBroadcaster implements TransactionBatchAddedListener { +public class TransactionBroadcaster + implements TransactionBatchAddedListener, PendingTransactionDroppedListener { private static final Logger LOG = LoggerFactory.getLogger(TransactionBroadcaster.class); private static final EnumSet ANNOUNCE_HASH_ONLY_TX_TYPES = EnumSet.of(BLOB); @@ -219,4 +220,9 @@ public class TransactionBroadcaster implements TransactionBatchAddedListener { destinationList.add(sourceList.remove(i)); } } + + @Override + public void onTransactionDropped(final Transaction transaction, final RemovalReason reason) { + transactionTracker.onTransactionDropped(transaction, reason); + } } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java index 19bcfe0b36..3acf49894a 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java @@ -139,6 +139,7 @@ public class TransactionPool implements BlockAddedObserver { subscribePendingTransactions(this::mapBlobsOnTransactionAdded); subscribeDroppedTransactions( (transaction, reason) -> unmapBlobsOnTransactionDropped(transaction)); + subscribeDroppedTransactions(transactionBroadcaster); } private void initLogForReplay() { 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 79b1298d27..9f13323630 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 @@ -17,7 +17,7 @@ package org.hyperledger.besu.ethereum.eth.transactions; import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LAYERED; import org.hyperledger.besu.ethereum.ProtocolContext; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.messages.EthPV62; @@ -56,7 +56,7 @@ public class TransactionPoolFactory { final SyncState syncState, final TransactionPoolConfiguration transactionPoolConfiguration, final BlobCache blobCache, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { final TransactionPoolMetrics metrics = new TransactionPoolMetrics(metricsSystem); @@ -80,7 +80,7 @@ public class TransactionPoolFactory { transactionsMessageSender, newPooledTransactionHashesMessageSender, blobCache, - miningParameters); + miningConfiguration); } static TransactionPool createTransactionPool( @@ -95,7 +95,7 @@ public class TransactionPoolFactory { final TransactionsMessageSender transactionsMessageSender, final NewPooledTransactionHashesMessageSender newPooledTransactionHashesMessageSender, final BlobCache blobCache, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { final TransactionPool transactionPool = new TransactionPool( @@ -108,7 +108,7 @@ public class TransactionPoolFactory { metrics, transactionPoolConfiguration, blobCache, - miningParameters), + miningConfiguration), protocolSchedule, protocolContext, new TransactionBroadcaster( @@ -241,7 +241,7 @@ public class TransactionPoolFactory { final TransactionPoolMetrics metrics, final TransactionPoolConfiguration transactionPoolConfiguration, final BlobCache blobCache, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { boolean isFeeMarketImplementBaseFee = protocolSchedule.anyMatch( @@ -256,7 +256,7 @@ public class TransactionPoolFactory { transactionPoolConfiguration, isFeeMarketImplementBaseFee, blobCache, - miningParameters); + miningConfiguration); } else { return createPendingTransactionSorter( protocolContext, @@ -296,7 +296,7 @@ public class TransactionPoolFactory { final TransactionPoolConfiguration transactionPoolConfiguration, final boolean isFeeMarketImplementBaseFee, final BlobCache blobCache, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { final TransactionPoolReplacementHandler transactionReplacementHandler = new TransactionPoolReplacementHandler( @@ -345,7 +345,7 @@ public class TransactionPoolFactory { transactionReplacementTester, feeMarket, blobCache, - miningParameters); + miningConfiguration); } else { pendingTransactionsSorter = new GasPricePrioritizedTransactions( @@ -355,7 +355,7 @@ public class TransactionPoolFactory { metrics, transactionReplacementTester, blobCache, - miningParameters); + miningConfiguration); } return new LayeredPendingTransactions( diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolMetrics.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolMetrics.java index fac9b3174d..6f116d3b88 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolMetrics.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolMetrics.java @@ -22,8 +22,8 @@ import org.hyperledger.besu.metrics.ReplaceableDoubleSupplier; import org.hyperledger.besu.metrics.RunnableCounter; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; -import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; import java.util.HashMap; import java.util.Map; @@ -47,10 +47,10 @@ public class TransactionPoolMetrics { private final LabelledMetric removedCounter; private final LabelledMetric rejectedCounter; private final LabelledMetric penalizedCounter; - private final LabelledGauge spaceUsed; - private final LabelledGauge transactionCount; - private final LabelledGauge transactionCountByType; - private final LabelledGauge uniqueSenderCount; + private final LabelledSuppliedMetric spaceUsed; + private final LabelledSuppliedMetric transactionCount; + private final LabelledSuppliedMetric transactionCountByType; + private final LabelledSuppliedMetric uniqueSenderCount; private final LabelledMetric expiredMessagesCounter; private final Map expiredMessagesRunnableCounters = new HashMap<>(); private final LabelledMetric alreadySeenTransactionsCounter; @@ -103,21 +103,21 @@ public class TransactionPoolMetrics { "layer"); spaceUsed = - metricsSystem.createLabelledGauge( + metricsSystem.createLabelledSuppliedGauge( BesuMetricCategory.TRANSACTION_POOL, "space_used", "The amount of space used by the transactions in the layer", "layer"); transactionCount = - metricsSystem.createLabelledGauge( + metricsSystem.createLabelledSuppliedGauge( BesuMetricCategory.TRANSACTION_POOL, "number_of_transactions", "The number of transactions currently present in the layer", "layer"); transactionCountByType = - metricsSystem.createLabelledGauge( + metricsSystem.createLabelledSuppliedGauge( BesuMetricCategory.TRANSACTION_POOL, "number_of_transactions_by_type", "The number of transactions, of a specified type, currently present in the layer", @@ -125,7 +125,7 @@ public class TransactionPoolMetrics { "type"); uniqueSenderCount = - metricsSystem.createLabelledGauge( + metricsSystem.createLabelledSuppliedGauge( BesuMetricCategory.TRANSACTION_POOL, "unique_senders", "The number of senders with at least one transaction currently present in the layer", diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/AbstractPrioritizedTransactions.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/AbstractPrioritizedTransactions.java index fce565a807..06db1b1edc 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/AbstractPrioritizedTransactions.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/AbstractPrioritizedTransactions.java @@ -16,7 +16,7 @@ package org.hyperledger.besu.ethereum.eth.transactions.layered; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.TransactionType; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; import org.hyperledger.besu.ethereum.eth.transactions.PendingTransaction; @@ -42,7 +42,7 @@ import java.util.stream.Collectors; */ public abstract class AbstractPrioritizedTransactions extends AbstractSequentialTransactionsLayer { protected final TreeSet orderByFee; - protected final MiningParameters miningParameters; + protected final MiningConfiguration miningConfiguration; public AbstractPrioritizedTransactions( final TransactionPoolConfiguration poolConfig, @@ -52,7 +52,7 @@ public abstract class AbstractPrioritizedTransactions extends AbstractSequential final BiFunction transactionReplacementTester, final BlobCache blobCache, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { super( poolConfig, ethScheduler, @@ -61,7 +61,7 @@ public abstract class AbstractPrioritizedTransactions extends AbstractSequential metrics, blobCache); this.orderByFee = new TreeSet<>(this::compareByFee); - this.miningParameters = miningParameters; + this.miningConfiguration = miningConfiguration; } @Override diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/BaseFeePrioritizedTransactions.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/BaseFeePrioritizedTransactions.java index df9b1537a3..b168babe63 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/BaseFeePrioritizedTransactions.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/BaseFeePrioritizedTransactions.java @@ -19,7 +19,7 @@ import static org.hyperledger.besu.ethereum.eth.transactions.layered.LayeredRemo import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; import org.hyperledger.besu.ethereum.eth.transactions.PendingTransaction; @@ -51,7 +51,7 @@ public class BaseFeePrioritizedTransactions extends AbstractPrioritizedTransacti transactionReplacementTester, final FeeMarket feeMarket, final BlobCache blobCache, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { super( poolConfig, ethScheduler, @@ -59,7 +59,7 @@ public class BaseFeePrioritizedTransactions extends AbstractPrioritizedTransacti metrics, transactionReplacementTester, blobCache, - miningParameters); + miningConfiguration); this.nextBlockBaseFee = Optional.of(calculateNextBlockBaseFee(feeMarket, chainHeadHeaderSupplier.get())); } @@ -174,15 +174,15 @@ public class BaseFeePrioritizedTransactions extends AbstractPrioritizedTransacti if (pendingTransaction .getTransaction() .getEffectiveGasPrice(nextBlockBaseFee) - .lessThan(miningParameters.getMinTransactionGasPrice())) { + .lessThan(miningConfiguration.getMinTransactionGasPrice())) { return false; } // check if enough priority fee is paid - if (!miningParameters.getMinPriorityFeePerGas().equals(Wei.ZERO)) { + if (!miningConfiguration.getMinPriorityFeePerGas().equals(Wei.ZERO)) { final Wei priorityFeePerGas = pendingTransaction.getTransaction().getEffectivePriorityFeePerGas(nextBlockBaseFee); - if (priorityFeePerGas.lessThan(miningParameters.getMinPriorityFeePerGas())) { + if (priorityFeePerGas.lessThan(miningConfiguration.getMinPriorityFeePerGas())) { return false; } } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/GasPricePrioritizedTransactions.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/GasPricePrioritizedTransactions.java index 504a453fa8..205c02f543 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/GasPricePrioritizedTransactions.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/GasPricePrioritizedTransactions.java @@ -17,7 +17,7 @@ package org.hyperledger.besu.ethereum.eth.transactions.layered; import static java.util.Comparator.comparing; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; import org.hyperledger.besu.ethereum.eth.transactions.PendingTransaction; @@ -43,7 +43,7 @@ public class GasPricePrioritizedTransactions extends AbstractPrioritizedTransact final BiFunction transactionReplacementTester, final BlobCache blobCache, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { super( poolConfig, ethScheduler, @@ -51,7 +51,7 @@ public class GasPricePrioritizedTransactions extends AbstractPrioritizedTransact metrics, transactionReplacementTester, blobCache, - miningParameters); + miningConfiguration); } @Override @@ -74,7 +74,7 @@ public class GasPricePrioritizedTransactions extends AbstractPrioritizedTransact || pendingTransaction .getTransaction() .getGasPrice() - .map(miningParameters.getMinTransactionGasPrice()::lessThan) + .map(miningConfiguration.getMinTransactionGasPrice()::lessThan) .orElse(false); } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java index 3a3331b568..b7c346af69 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java @@ -36,7 +36,7 @@ import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; @@ -1123,7 +1123,7 @@ public final class EthProtocolManagerTest { new SyncState(blockchain, ethManager.ethContext().getEthPeers()), TransactionPoolConfiguration.DEFAULT, new BlobCache(), - MiningParameters.newDefault()) + MiningConfiguration.newDefault()) .setEnabled(); // Send just a transaction message. diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/AbstractMessageTaskTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/AbstractMessageTaskTest.java index 6dbea259cc..b1691d0af5 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/AbstractMessageTaskTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/AbstractMessageTaskTest.java @@ -26,7 +26,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.EthProtocol; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthContext; @@ -144,7 +144,7 @@ public abstract class AbstractMessageTaskTest { syncState, TransactionPoolConfiguration.DEFAULT, new BlobCache(), - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); transactionPool.setEnabled(); ethProtocolManager = diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutorTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutorTest.java index 0262e276da..9639de154d 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutorTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutorTest.java @@ -72,7 +72,7 @@ public class PeerTaskExecutorTest { Mockito.when(subprotocol.getName()).thenReturn("subprotocol"); Mockito.when(requestSender.sendRequest(subprotocol, requestMessageData, ethPeer)) .thenReturn(responseMessageData); - Mockito.when(peerTask.parseResponse(responseMessageData)).thenReturn(responseObject); + Mockito.when(peerTask.processResponse(responseMessageData)).thenReturn(responseObject); Mockito.when(peerTask.isSuccess(responseObject)).thenReturn(true); PeerTaskExecutorResult result = peerTaskExecutor.executeAgainstPeer(peerTask, ethPeer); @@ -101,7 +101,7 @@ public class PeerTaskExecutorTest { Mockito.when(subprotocol.getName()).thenReturn("subprotocol"); Mockito.when(requestSender.sendRequest(subprotocol, requestMessageData, ethPeer)) .thenReturn(responseMessageData); - Mockito.when(peerTask.parseResponse(responseMessageData)).thenReturn(responseObject); + Mockito.when(peerTask.processResponse(responseMessageData)).thenReturn(responseObject); Mockito.when(peerTask.isSuccess(responseObject)).thenReturn(false); PeerTaskExecutorResult result = peerTaskExecutor.executeAgainstPeer(peerTask, ethPeer); @@ -130,7 +130,7 @@ public class PeerTaskExecutorTest { .thenThrow(new TimeoutException()) .thenReturn(responseMessageData); Mockito.when(requestMessageData.getCode()).thenReturn(requestMessageDataCode); - Mockito.when(peerTask.parseResponse(responseMessageData)).thenReturn(responseObject); + Mockito.when(peerTask.processResponse(responseMessageData)).thenReturn(responseObject); Mockito.when(peerTask.isSuccess(responseObject)).thenReturn(true); PeerTaskExecutorResult result = peerTaskExecutor.executeAgainstPeer(peerTask, ethPeer); @@ -204,7 +204,7 @@ public class PeerTaskExecutorTest { Mockito.when(subprotocol.getName()).thenReturn("subprotocol"); Mockito.when(requestSender.sendRequest(subprotocol, requestMessageData, ethPeer)) .thenReturn(responseMessageData); - Mockito.when(peerTask.parseResponse(responseMessageData)) + Mockito.when(peerTask.processResponse(responseMessageData)) .thenThrow(new InvalidPeerTaskResponseException()); PeerTaskExecutorResult result = peerTaskExecutor.executeAgainstPeer(peerTask, ethPeer); @@ -236,7 +236,7 @@ public class PeerTaskExecutorTest { Mockito.when(subprotocol.getName()).thenReturn("subprotocol"); Mockito.when(requestSender.sendRequest(subprotocol, requestMessageData, ethPeer)) .thenReturn(responseMessageData); - Mockito.when(peerTask.parseResponse(responseMessageData)).thenReturn(responseObject); + Mockito.when(peerTask.processResponse(responseMessageData)).thenReturn(responseObject); Mockito.when(peerTask.isSuccess(responseObject)).thenReturn(true); PeerTaskExecutorResult result = peerTaskExecutor.executeAgainstPeer(peerTask, ethPeer); @@ -274,7 +274,7 @@ public class PeerTaskExecutorTest { Mockito.when(requestMessageData.getCode()).thenReturn(requestMessageDataCode); Mockito.when(requestSender.sendRequest(subprotocol, requestMessageData, peer2)) .thenReturn(responseMessageData); - Mockito.when(peerTask.parseResponse(responseMessageData)).thenReturn(responseObject); + Mockito.when(peerTask.processResponse(responseMessageData)).thenReturn(responseObject); Mockito.when(peerTask.isSuccess(responseObject)).thenReturn(true); PeerTaskExecutorResult result = peerTaskExecutor.execute(peerTask); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTaskTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTaskTest.java new file mode 100644 index 0000000000..90e6f738fc --- /dev/null +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTaskTest.java @@ -0,0 +1,264 @@ +/* + * Copyright contributors to Hyperledger Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.eth.manager.peertask.task; + +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.TransactionReceipt; +import org.hyperledger.besu.ethereum.eth.EthProtocol; +import org.hyperledger.besu.ethereum.eth.manager.ChainState; +import org.hyperledger.besu.ethereum.eth.manager.EthPeer; +import org.hyperledger.besu.ethereum.eth.manager.peertask.InvalidPeerTaskResponseException; +import org.hyperledger.besu.ethereum.eth.messages.EthPV63; +import org.hyperledger.besu.ethereum.eth.messages.GetReceiptsMessage; +import org.hyperledger.besu.ethereum.eth.messages.ReceiptsMessage; +import org.hyperledger.besu.ethereum.mainnet.BodyValidation; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import org.apache.commons.lang3.StringUtils; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +public class GetReceiptsFromPeerTaskTest { + + @Test + public void testGetSubProtocol() { + GetReceiptsFromPeerTask task = new GetReceiptsFromPeerTask(Collections.emptyList(), null); + Assertions.assertEquals(EthProtocol.get(), task.getSubProtocol()); + } + + @Test + public void testGetRequestMessage() { + BlockHeader blockHeader1 = mockBlockHeader(1); + TransactionReceipt receiptForBlock1 = + new TransactionReceipt(1, 123, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader1.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock1))); + + BlockHeader blockHeader2 = mockBlockHeader(2); + TransactionReceipt receiptForBlock2 = + new TransactionReceipt(1, 456, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader2.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock2))); + + BlockHeader blockHeader3 = mockBlockHeader(3); + TransactionReceipt receiptForBlock3 = + new TransactionReceipt(1, 789, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader3.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock3))); + + GetReceiptsFromPeerTask task = + new GetReceiptsFromPeerTask(List.of(blockHeader1, blockHeader2, blockHeader3), null); + + MessageData messageData = task.getRequestMessage(); + GetReceiptsMessage getReceiptsMessage = GetReceiptsMessage.readFrom(messageData); + + Assertions.assertEquals(EthPV63.GET_RECEIPTS, getReceiptsMessage.getCode()); + Iterable hashesInMessage = getReceiptsMessage.hashes(); + List expectedHashes = + List.of( + Hash.fromHexString(StringUtils.repeat("00", 31) + "11"), + Hash.fromHexString(StringUtils.repeat("00", 31) + "21"), + Hash.fromHexString(StringUtils.repeat("00", 31) + "31")); + List actualHashes = new ArrayList<>(); + hashesInMessage.forEach(actualHashes::add); + + Assertions.assertEquals(3, actualHashes.size()); + Assertions.assertEquals( + expectedHashes.stream().sorted().toList(), actualHashes.stream().sorted().toList()); + } + + @Test + public void testParseResponseWithNullResponseMessage() { + GetReceiptsFromPeerTask task = new GetReceiptsFromPeerTask(Collections.emptyList(), null); + Assertions.assertThrows( + InvalidPeerTaskResponseException.class, () -> task.processResponse(null)); + } + + @Test + public void testParseResponseForInvalidResponse() { + BlockHeader blockHeader1 = mockBlockHeader(1); + TransactionReceipt receiptForBlock1 = + new TransactionReceipt(1, 123, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader1.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock1))); + + BlockHeader blockHeader2 = mockBlockHeader(2); + TransactionReceipt receiptForBlock2 = + new TransactionReceipt(1, 456, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader2.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock2))); + + BlockHeader blockHeader3 = mockBlockHeader(3); + TransactionReceipt receiptForBlock3 = + new TransactionReceipt(1, 789, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader3.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock3))); + GetReceiptsFromPeerTask task = + new GetReceiptsFromPeerTask(List.of(blockHeader1, blockHeader2, blockHeader3), null); + ReceiptsMessage receiptsMessage = + ReceiptsMessage.create( + List.of( + List.of(receiptForBlock1), + List.of(receiptForBlock2), + List.of(receiptForBlock3), + List.of( + new TransactionReceipt(1, 101112, Collections.emptyList(), Optional.empty())))); + + Assertions.assertThrows( + InvalidPeerTaskResponseException.class, () -> task.processResponse(receiptsMessage)); + } + + @Test + public void testParseResponse() throws InvalidPeerTaskResponseException { + BlockHeader blockHeader1 = mockBlockHeader(1); + TransactionReceipt receiptForBlock1 = + new TransactionReceipt(1, 123, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader1.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock1))); + + BlockHeader blockHeader2 = mockBlockHeader(2); + TransactionReceipt receiptForBlock2 = + new TransactionReceipt(1, 456, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader2.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock2))); + + BlockHeader blockHeader3 = mockBlockHeader(3); + TransactionReceipt receiptForBlock3 = + new TransactionReceipt(1, 789, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader3.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock3))); + + BlockHeader blockHeader4 = mockBlockHeader(4); + Mockito.when(blockHeader4.getReceiptsRoot()).thenReturn(Hash.EMPTY_TRIE_HASH); + + GetReceiptsFromPeerTask task = + new GetReceiptsFromPeerTask( + List.of(blockHeader1, blockHeader2, blockHeader3, blockHeader4), null); + + ReceiptsMessage receiptsMessage = + ReceiptsMessage.create( + List.of( + List.of(receiptForBlock1), List.of(receiptForBlock2), List.of(receiptForBlock3))); + + Map> resultMap = task.processResponse(receiptsMessage); + + Assertions.assertEquals(4, resultMap.size()); + Assertions.assertEquals(Collections.emptyList(), resultMap.get(blockHeader4)); + Assertions.assertEquals(List.of(receiptForBlock1), resultMap.get(blockHeader1)); + Assertions.assertEquals(List.of(receiptForBlock2), resultMap.get(blockHeader2)); + Assertions.assertEquals(List.of(receiptForBlock3), resultMap.get(blockHeader3)); + } + + @Test + public void testParseResponseForOnlyPrefilledEmptyTrieReceiptsRoots() + throws InvalidPeerTaskResponseException { + BlockHeader blockHeader1 = mockBlockHeader(1); + Mockito.when(blockHeader1.getReceiptsRoot()).thenReturn(Hash.EMPTY_TRIE_HASH); + + GetReceiptsFromPeerTask task = new GetReceiptsFromPeerTask(List.of(blockHeader1), null); + + ReceiptsMessage receiptsMessage = ReceiptsMessage.create(Collections.emptyList()); + + Map> resultMap = task.processResponse(receiptsMessage); + + Assertions.assertEquals(1, resultMap.size()); + Assertions.assertEquals(Collections.emptyList(), resultMap.get(blockHeader1)); + } + + @Test + public void testGetPeerRequirementFilter() { + BlockHeader blockHeader1 = mockBlockHeader(1); + TransactionReceipt receiptForBlock1 = + new TransactionReceipt(1, 123, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader1.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock1))); + + BlockHeader blockHeader2 = mockBlockHeader(2); + TransactionReceipt receiptForBlock2 = + new TransactionReceipt(1, 456, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader2.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock2))); + + BlockHeader blockHeader3 = mockBlockHeader(3); + TransactionReceipt receiptForBlock3 = + new TransactionReceipt(1, 789, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader3.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock3))); + + ProtocolSchedule protocolSchedule = Mockito.mock(ProtocolSchedule.class); + Mockito.when(protocolSchedule.anyMatch(Mockito.any())).thenReturn(false); + + GetReceiptsFromPeerTask task = + new GetReceiptsFromPeerTask( + List.of(blockHeader1, blockHeader2, blockHeader3), protocolSchedule); + + EthPeer failForIncorrectProtocol = mockPeer("incorrectProtocol", 5); + EthPeer failForShortChainHeight = mockPeer("incorrectProtocol", 1); + EthPeer successfulCandidate = mockPeer(EthProtocol.NAME, 5); + + Assertions.assertFalse(task.getPeerRequirementFilter().test(failForIncorrectProtocol)); + Assertions.assertFalse(task.getPeerRequirementFilter().test(failForShortChainHeight)); + Assertions.assertTrue(task.getPeerRequirementFilter().test(successfulCandidate)); + } + + @Test + public void testIsSuccessForPartialSuccess() { + GetReceiptsFromPeerTask task = new GetReceiptsFromPeerTask(Collections.emptyList(), null); + + Assertions.assertFalse(task.isSuccess(Collections.emptyMap())); + } + + @Test + public void testIsSuccessForFullSuccess() { + GetReceiptsFromPeerTask task = new GetReceiptsFromPeerTask(Collections.emptyList(), null); + + Map> map = new HashMap<>(); + map.put(mockBlockHeader(1), null); + + Assertions.assertTrue(task.isSuccess(map)); + } + + private BlockHeader mockBlockHeader(final long blockNumber) { + BlockHeader blockHeader = Mockito.mock(BlockHeader.class); + Mockito.when(blockHeader.getNumber()).thenReturn(blockNumber); + // second to last hex digit indicates the blockNumber, last hex digit indicates the usage of the + // hash + Mockito.when(blockHeader.getHash()) + .thenReturn(Hash.fromHexString(StringUtils.repeat("00", 31) + blockNumber + "1")); + + return blockHeader; + } + + private EthPeer mockPeer(final String protocol, final long chainHeight) { + EthPeer ethPeer = Mockito.mock(EthPeer.class); + ChainState chainState = Mockito.mock(ChainState.class); + + Mockito.when(ethPeer.getProtocolName()).thenReturn(protocol); + Mockito.when(ethPeer.chainState()).thenReturn(chainState); + Mockito.when(chainState.getEstimatedHeight()).thenReturn(chainHeight); + + return ethPeer; + } +} diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServerGetAccountRangeTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServerGetAccountRangeTest.java index 6d8180c8c0..eb97419967 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServerGetAccountRangeTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServerGetAccountRangeTest.java @@ -15,10 +15,12 @@ package org.hyperledger.besu.ethereum.eth.manager.snap; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.mockito.Mockito.mock; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; +import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.manager.EthMessages; import org.hyperledger.besu.ethereum.eth.messages.snap.AccountRangeMessage; import org.hyperledger.besu.ethereum.eth.messages.snap.GetAccountRangeMessage; @@ -70,7 +72,8 @@ public class SnapServerGetAccountRangeTest { snapSyncConfiguration, new EthMessages(), worldStateStorageCoordinator, - protocolContext) + protocolContext, + mock(Synchronizer.class)) .start(); initAccounts(); } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServerTest.java index 2844603429..1d43a5af9b 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServerTest.java @@ -37,13 +37,13 @@ import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.trie.CompactEncoding; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.flat.BonsaiFlatDbStrategyProvider; import org.hyperledger.besu.ethereum.trie.patricia.SimpleMerklePatriciaTrie; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; import org.hyperledger.besu.ethereum.worldstate.FlatDbMode; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.metrics.ObservableMetricsSystem; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -71,7 +71,7 @@ public class SnapServerTest { record SnapTestAccount( Hash addressHash, - StateTrieAccountValue accountValue, + PmtStateTrieAccountValue accountValue, MerkleTrie storage, Bytes code) { Bytes accountRLP() { @@ -722,7 +722,7 @@ public class SnapServerTest { static SnapTestAccount createTestAccount(final String hexAddr) { return new SnapTestAccount( Hash.wrap(Bytes32.rightPad(Bytes.fromHexString(hexAddr))), - new StateTrieAccountValue( + new PmtStateTrieAccountValue( rand.nextInt(0, 1), Wei.of(rand.nextLong(0L, 1L)), Hash.EMPTY_TRIE_HASH, Hash.EMPTY), new SimpleMerklePatriciaTrie<>(a -> a), Bytes.EMPTY); @@ -768,7 +768,7 @@ public class SnapServerTest { updater.commit(); return new SnapTestAccount( acctHash, - new StateTrieAccountValue( + new PmtStateTrieAccountValue( rand.nextInt(0, 1), Wei.of(rand.nextLong(0L, 1L)), Hash.wrap(trie.getRootHash()), Hash.hash(mockCode)), trie, diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/BlockBodiesMessageTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/BlockBodiesMessageTest.java index b11afeb4c5..2bb1394a1d 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/BlockBodiesMessageTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/BlockBodiesMessageTest.java @@ -21,7 +21,7 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; @@ -60,7 +60,7 @@ public final class BlockBodiesMessageTest { GenesisConfigFile.fromResource("/dev.json").getConfigOptions(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/BlockHeadersMessageTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/BlockHeadersMessageTest.java index 72f089a53e..9173a7af48 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/BlockHeadersMessageTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/BlockHeadersMessageTest.java @@ -17,7 +17,7 @@ package org.hyperledger.besu.ethereum.eth.messages; import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; @@ -67,7 +67,7 @@ public final class BlockHeadersMessageTest { GenesisConfigFile.fromResource("/dev.json").getConfigOptions(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem())); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/snap/AccountRangeMessageTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/snap/AccountRangeMessageTest.java index c7e5bf74c4..4c2bad0f63 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/snap/AccountRangeMessageTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/snap/AccountRangeMessageTest.java @@ -23,7 +23,7 @@ import org.hyperledger.besu.ethereum.p2p.rlpx.wire.RawMessage; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.rlp.RLPInput; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import java.util.ArrayList; import java.util.HashMap; @@ -39,8 +39,8 @@ public final class AccountRangeMessageTest { @Test public void roundTripTest() { final Map keys = new HashMap<>(); - final StateTrieAccountValue accountValue = - new StateTrieAccountValue(1L, Wei.of(2L), Hash.EMPTY_TRIE_HASH, Hash.EMPTY); + final PmtStateTrieAccountValue accountValue = + new PmtStateTrieAccountValue(1L, Wei.of(2L), Hash.EMPTY_TRIE_HASH, Hash.EMPTY); keys.put(Hash.wrap(Bytes32.leftPad(Bytes.of(1))), RLP.encode(accountValue::writeTo)); final List proofs = new ArrayList<>(); @@ -65,8 +65,8 @@ public final class AccountRangeMessageTest { Wei balance = Wei.of(2L); // Create a StateTrieAccountValue with the given nonce and balance - final StateTrieAccountValue accountValue = - new StateTrieAccountValue(nonce, balance, Hash.EMPTY_TRIE_HASH, Hash.EMPTY); + final PmtStateTrieAccountValue accountValue = + new PmtStateTrieAccountValue(nonce, balance, Hash.EMPTY_TRIE_HASH, Hash.EMPTY); // Encode the account value to RLP final BytesValueRLPOutput rlpOut = new BytesValueRLPOutput(); @@ -104,8 +104,8 @@ public final class AccountRangeMessageTest { Wei balance = Wei.of(2L); // Create a StateTrieAccountValue with the given nonce and balance - final StateTrieAccountValue accountValue = - new StateTrieAccountValue(nonce, balance, Hash.EMPTY_TRIE_HASH, Hash.EMPTY); + final PmtStateTrieAccountValue accountValue = + new PmtStateTrieAccountValue(nonce, balance, Hash.EMPTY_TRIE_HASH, Hash.EMPTY); // Encode the account value to RLP final BytesValueRLPOutput rlpOut = new BytesValueRLPOutput(); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTrackerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTrackerTest.java index 5f7baaff41..f97fe91c6f 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTrackerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTrackerTest.java @@ -23,7 +23,7 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule; import org.hyperledger.besu.ethereum.eth.manager.ChainState; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; @@ -58,7 +58,7 @@ public class ChainHeadTrackerTest { GenesisConfigFile.fromResource("/dev.json").getConfigOptions(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContextTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContextTest.java index cfc9f9dc12..4cd4d1c674 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContextTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContextTest.java @@ -36,7 +36,7 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; @@ -95,7 +95,7 @@ public class BackwardSyncContextTest { private ProtocolSchedule protocolSchedule = MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions(), - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncStepTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncStepTest.java index 6dc69ea274..696856c076 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncStepTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncStepTest.java @@ -29,7 +29,7 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; @@ -72,7 +72,7 @@ public class BackwardSyncStepTest { private final ProtocolSchedule protocolSchedule = MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions(), - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/ForwardSyncStepTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/ForwardSyncStepTest.java index a5d2cf6104..34479bf11f 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/ForwardSyncStepTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/ForwardSyncStepTest.java @@ -28,7 +28,7 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; @@ -75,7 +75,7 @@ public class ForwardSyncStepTest { private final ProtocolSchedule protocolSchedule = MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions(), - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckPointSyncChainDownloaderTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckPointSyncChainDownloaderTest.java index 43f03100a7..56e0461f70 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckPointSyncChainDownloaderTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckPointSyncChainDownloaderTest.java @@ -22,13 +22,19 @@ import static org.mockito.Mockito.when; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; +import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.core.Difficulty; +import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResponseCode; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResult; +import org.hyperledger.besu.ethereum.eth.manager.peertask.task.GetReceiptsFromPeerTask; import org.hyperledger.besu.ethereum.eth.sync.ChainDownloader; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncState; @@ -44,8 +50,15 @@ import org.hyperledger.besu.metrics.SyncDurationMetrics; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; +import java.lang.reflect.Field; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; import java.util.stream.Stream; import org.junit.jupiter.api.AfterEach; @@ -55,12 +68,16 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.ArgumentsProvider; import org.junit.jupiter.params.provider.ArgumentsSource; +import org.junit.platform.commons.util.ReflectionUtils; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; public class CheckPointSyncChainDownloaderTest { protected ProtocolSchedule protocolSchedule; protected EthProtocolManager ethProtocolManager; protected EthContext ethContext; + private PeerTaskExecutor peerTaskExecutor; protected ProtocolContext protocolContext; private SyncState syncState; @@ -100,6 +117,7 @@ public class CheckPointSyncChainDownloaderTest { localBlockchain = localBlockchainSetup.getBlockchain(); otherBlockchainSetup = BlockchainSetupUtil.forTesting(dataStorageFormat); otherBlockchain = otherBlockchainSetup.getBlockchain(); + otherBlockchainSetup.importFirstBlocks(30); protocolSchedule = localBlockchainSetup.getProtocolSchedule(); protocolContext = localBlockchainSetup.getProtocolContext(); ethProtocolManager = @@ -123,6 +141,41 @@ public class CheckPointSyncChainDownloaderTest { ethContext.getEthPeers(), true, Optional.of(checkpoint)); + + peerTaskExecutor = mock(PeerTaskExecutor.class); + + when(peerTaskExecutor.execute(any(GetReceiptsFromPeerTask.class))) + .thenAnswer( + new Answer>>>() { + @Override + public PeerTaskExecutorResult>> answer( + final InvocationOnMock invocationOnMock) throws Throwable { + GetReceiptsFromPeerTask task = + invocationOnMock.getArgument(0, GetReceiptsFromPeerTask.class); + + return processTask(task); + } + }); + } + + @SuppressWarnings("unchecked") + private PeerTaskExecutorResult>> processTask( + final GetReceiptsFromPeerTask task) throws IllegalAccessException { + Map> getReceiptsFromPeerTaskResult = new HashMap<>(); + List fields = + ReflectionUtils.findFields( + task.getClass(), + (field) -> field.getName().equals("blockHeaders"), + ReflectionUtils.HierarchyTraversalMode.TOP_DOWN); + fields.forEach((f) -> f.setAccessible(true)); + Collection blockHeaders = (Collection) fields.getFirst().get(task); + blockHeaders.forEach( + (bh) -> + getReceiptsFromPeerTaskResult.put( + bh, otherBlockchain.getTxReceipts(bh.getHash()).get())); + + return new PeerTaskExecutorResult<>( + Optional.of(getReceiptsFromPeerTaskResult), PeerTaskExecutorResponseCode.SUCCESS); } @AfterEach @@ -140,6 +193,7 @@ public class CheckPointSyncChainDownloaderTest { protocolSchedule, protocolContext, ethContext, + peerTaskExecutor, syncState, new NoOpMetricsSystem(), new FastSyncState(otherBlockchain.getBlockHeader(pivotBlockNumber).get()), @@ -148,9 +202,9 @@ public class CheckPointSyncChainDownloaderTest { @ParameterizedTest @ArgumentsSource(CheckPointSyncChainDownloaderTestArguments.class) - public void shouldSyncToPivotBlockInMultipleSegments(final DataStorageFormat storageFormat) { + public void shouldSyncToPivotBlockInMultipleSegments(final DataStorageFormat storageFormat) + throws IllegalAccessException { setup(storageFormat); - otherBlockchainSetup.importFirstBlocks(30); final RespondingEthPeer peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, otherBlockchain); @@ -161,6 +215,7 @@ public class CheckPointSyncChainDownloaderTest { SynchronizerConfiguration.builder() .downloaderChainSegmentSize(5) .downloaderHeadersRequestSize(3) + .isPeerTaskSystemEnabled(false) .build(); final long pivotBlockNumber = 25; ethContext @@ -184,9 +239,9 @@ public class CheckPointSyncChainDownloaderTest { @ParameterizedTest @ArgumentsSource(CheckPointSyncChainDownloaderTestArguments.class) - public void shouldSyncToPivotBlockInSingleSegment(final DataStorageFormat storageFormat) { + public void shouldSyncToPivotBlockInSingleSegment(final DataStorageFormat storageFormat) + throws IllegalAccessException { setup(storageFormat); - otherBlockchainSetup.importFirstBlocks(30); final RespondingEthPeer peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, otherBlockchain); @@ -194,7 +249,79 @@ public class CheckPointSyncChainDownloaderTest { RespondingEthPeer.blockchainResponder(otherBlockchain); final long pivotBlockNumber = 10; - final SynchronizerConfiguration syncConfig = SynchronizerConfiguration.builder().build(); + final SynchronizerConfiguration syncConfig = + SynchronizerConfiguration.builder().isPeerTaskSystemEnabled(false).build(); + ethContext + .getEthPeers() + .streamAvailablePeers() + .forEach( + ethPeer -> { + ethPeer.setCheckpointHeader( + otherBlockchainSetup.getBlocks().get((int) checkpoint.blockNumber()).getHeader()); + }); + final ChainDownloader downloader = downloader(syncConfig, pivotBlockNumber); + final CompletableFuture result = downloader.start(); + + peer.respondWhileOtherThreadsWork(responder, () -> !result.isDone()); + + assertThat(result).isCompleted(); + assertThat(localBlockchain.getChainHeadBlockNumber()).isEqualTo(pivotBlockNumber); + assertThat(localBlockchain.getChainHeadHeader()) + .isEqualTo(otherBlockchain.getBlockHeader(pivotBlockNumber).get()); + } + + @ParameterizedTest + @ArgumentsSource(CheckPointSyncChainDownloaderTestArguments.class) + public void shouldSyncToPivotBlockInMultipleSegmentsWithPeerTaskSystem( + final DataStorageFormat storageFormat) + throws IllegalAccessException, ExecutionException, InterruptedException, TimeoutException { + setup(storageFormat); + + final RespondingEthPeer peer = + EthProtocolManagerTestUtil.createPeer(ethProtocolManager, otherBlockchain); + final RespondingEthPeer.Responder responder = + RespondingEthPeer.blockchainResponder(otherBlockchain); + + final SynchronizerConfiguration syncConfig = + SynchronizerConfiguration.builder() + .downloaderChainSegmentSize(5) + .downloaderHeadersRequestSize(3) + .isPeerTaskSystemEnabled(true) + .build(); + final long pivotBlockNumber = 25; + ethContext + .getEthPeers() + .streamAvailablePeers() + .forEach( + ethPeer -> { + ethPeer.setCheckpointHeader( + otherBlockchainSetup.getBlocks().get((int) checkpoint.blockNumber()).getHeader()); + }); + final ChainDownloader downloader = downloader(syncConfig, pivotBlockNumber); + final CompletableFuture result = downloader.start(); + + peer.respondWhileOtherThreadsWork(responder, () -> !result.isDone()); + + assertThat(result).isCompleted(); + assertThat(localBlockchain.getChainHeadBlockNumber()).isEqualTo(pivotBlockNumber); + assertThat(localBlockchain.getChainHeadHeader()) + .isEqualTo(otherBlockchain.getBlockHeader(pivotBlockNumber).get()); + } + + @ParameterizedTest + @ArgumentsSource(CheckPointSyncChainDownloaderTestArguments.class) + public void shouldSyncToPivotBlockInSingleSegmentWithPeerTaskSystem( + final DataStorageFormat storageFormat) throws IllegalAccessException { + setup(storageFormat); + + final RespondingEthPeer peer = + EthProtocolManagerTestUtil.createPeer(ethProtocolManager, otherBlockchain); + final RespondingEthPeer.Responder responder = + RespondingEthPeer.blockchainResponder(otherBlockchain); + + final long pivotBlockNumber = 10; + final SynchronizerConfiguration syncConfig = + SynchronizerConfiguration.builder().isPeerTaskSystemEnabled(true).build(); ethContext .getEthPeers() .streamAvailablePeers() diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStepTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStepTest.java index c9cfeda119..4559b211e6 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStepTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStepTest.java @@ -18,47 +18,64 @@ import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; +import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; +import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockWithReceipts; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; +import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResponseCode; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResult; +import org.hyperledger.besu.ethereum.eth.manager.peertask.task.GetReceiptsFromPeerTask; +import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Optional; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.Mockito; public class DownloadReceiptsStepTest { private static ProtocolContext protocolContext; + private static ProtocolSchedule protocolSchedule; private static MutableBlockchain blockchain; + private PeerTaskExecutor peerTaskExecutor; private EthProtocolManager ethProtocolManager; - private DownloadReceiptsStep downloadReceiptsStep; @BeforeAll public static void setUpClass() { final BlockchainSetupUtil setupUtil = BlockchainSetupUtil.forTesting(DataStorageFormat.FOREST); setupUtil.importFirstBlocks(20); protocolContext = setupUtil.getProtocolContext(); + protocolSchedule = setupUtil.getProtocolSchedule(); blockchain = setupUtil.getBlockchain(); } @BeforeEach public void setUp() { + peerTaskExecutor = mock(PeerTaskExecutor.class); TransactionPool transactionPool = mock(TransactionPool.class); ethProtocolManager = EthProtocolManagerTestUtil.create( @@ -68,12 +85,17 @@ public class DownloadReceiptsStepTest { protocolContext.getWorldStateArchive(), transactionPool, EthProtocolConfiguration.defaultConfig()); - downloadReceiptsStep = - new DownloadReceiptsStep(ethProtocolManager.ethContext(), new NoOpMetricsSystem()); } @Test public void shouldDownloadReceiptsForBlocks() { + DownloadReceiptsStep downloadReceiptsStep = + new DownloadReceiptsStep( + protocolSchedule, + ethProtocolManager.ethContext(), + peerTaskExecutor, + SynchronizerConfiguration.builder().isPeerTaskSystemEnabled(false).build(), + new NoOpMetricsSystem()); final RespondingEthPeer peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, 1000); final List blocks = asList(block(1), block(2), block(3), block(4)); @@ -90,6 +112,39 @@ public class DownloadReceiptsStepTest { blockWithReceipts(4))); } + @Test + public void shouldDownloadReceiptsForBlocksUsingPeerTaskSystem() + throws ExecutionException, InterruptedException { + DownloadReceiptsStep downloadReceiptsStep = + new DownloadReceiptsStep( + protocolSchedule, + ethProtocolManager.ethContext(), + peerTaskExecutor, + SynchronizerConfiguration.builder().isPeerTaskSystemEnabled(true).build(), + new NoOpMetricsSystem()); + + final List blocks = asList(mockBlock(), mockBlock(), mockBlock(), mockBlock()); + Map> receiptsMap = new HashMap<>(); + blocks.forEach( + (b) -> receiptsMap.put(b.getHeader(), List.of(Mockito.mock(TransactionReceipt.class)))); + PeerTaskExecutorResult>> peerTaskResult = + new PeerTaskExecutorResult<>( + Optional.of(receiptsMap), PeerTaskExecutorResponseCode.SUCCESS); + Mockito.when(peerTaskExecutor.execute(Mockito.any(GetReceiptsFromPeerTask.class))) + .thenReturn(peerTaskResult); + + final CompletableFuture> result = downloadReceiptsStep.apply(blocks); + + assertThat(result.get().get(0).getBlock()).isEqualTo(blocks.get(0)); + assertThat(result.get().get(0).getReceipts().size()).isEqualTo(1); + assertThat(result.get().get(1).getBlock()).isEqualTo(blocks.get(1)); + assertThat(result.get().get(1).getReceipts().size()).isEqualTo(1); + assertThat(result.get().get(2).getBlock()).isEqualTo(blocks.get(2)); + assertThat(result.get().get(2).getReceipts().size()).isEqualTo(1); + assertThat(result.get().get(3).getBlock()).isEqualTo(blocks.get(3)); + assertThat(result.get().get(3).getReceipts().size()).isEqualTo(1); + } + private Block block(final long number) { final BlockHeader header = blockchain.getBlockHeader(number).get(); return new Block(header, blockchain.getBlockBody(header.getHash()).get()); @@ -100,4 +155,16 @@ public class DownloadReceiptsStepTest { final List receipts = blockchain.getTxReceipts(block.getHash()).get(); return new BlockWithReceipts(block, receipts); } + + private Block mockBlock() { + final Block block = Mockito.mock(Block.class); + final BlockHeader blockHeader = Mockito.mock(BlockHeader.class); + Mockito.when(block.getHeader()).thenAnswer((invocationOnMock) -> blockHeader); + Mockito.when(blockHeader.getReceiptsRoot()).thenReturn(Hash.fromHexStringLenient("DEADBEEF")); + final BlockBody blockBody = Mockito.mock(BlockBody.class); + Mockito.when(block.getBody()).thenAnswer((invocationOnMock) -> blockBody); + Mockito.when(blockBody.getTransactions()) + .thenAnswer((invocationOnMock) -> List.of(Mockito.mock(Transaction.class))); + return block; + } } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastDownloaderFactoryTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastDownloaderFactoryTest.java index 37ca5be2e9..bc493ebd03 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastDownloaderFactoryTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastDownloaderFactoryTest.java @@ -25,6 +25,7 @@ import static org.mockito.Mockito.when; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.eth.manager.EthContext; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.sync.PivotBlockSelector; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; @@ -71,6 +72,7 @@ public class FastDownloaderFactoryTest { @Mock private ProtocolContext protocolContext; @Mock private MetricsSystem metricsSystem; @Mock private EthContext ethContext; + @Mock private PeerTaskExecutor peerTaskExecutor; @Mock private SyncState syncState; @Mock private Clock clock; @Mock private Path dataDirectory; @@ -114,6 +116,7 @@ public class FastDownloaderFactoryTest { protocolContext, metricsSystem, ethContext, + peerTaskExecutor, worldStateStorageCoordinator, syncState, clock, @@ -139,6 +142,7 @@ public class FastDownloaderFactoryTest { protocolContext, metricsSystem, ethContext, + peerTaskExecutor, worldStateStorageCoordinator, syncState, clock, @@ -167,6 +171,7 @@ public class FastDownloaderFactoryTest { protocolContext, metricsSystem, ethContext, + peerTaskExecutor, worldStateStorageCoordinator, syncState, clock, @@ -202,6 +207,7 @@ public class FastDownloaderFactoryTest { protocolContext, metricsSystem, ethContext, + peerTaskExecutor, worldStateStorageCoordinator, syncState, clock, @@ -239,6 +245,7 @@ public class FastDownloaderFactoryTest { protocolContext, metricsSystem, ethContext, + peerTaskExecutor, worldStateStorageCoordinator, syncState, clock, diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActionsTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActionsTest.java index 68caf2182c..7af807c1c7 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActionsTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActionsTest.java @@ -34,6 +34,7 @@ import org.hyperledger.besu.ethereum.eth.manager.EthPeers; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator; import org.hyperledger.besu.ethereum.eth.sync.PivotBlockSelector; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; @@ -536,6 +537,7 @@ public class FastSyncActionsTest { protocolSchedule, protocolContext, ethContext, + new PeerTaskExecutor(null, null, new NoOpMetricsSystem()), new SyncState(blockchain, ethContext.getEthPeers(), true, Optional.empty()), pivotBlockSelector, new NoOpMetricsSystem()); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloaderTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloaderTest.java index 34014246d2..0e5b5ec2c7 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloaderTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloaderTest.java @@ -29,6 +29,7 @@ import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.messages.EthPV62; import org.hyperledger.besu.ethereum.eth.messages.GetBlockHeadersMessage; import org.hyperledger.besu.ethereum.eth.sync.ChainDownloader; @@ -110,6 +111,7 @@ public class FastSyncChainDownloaderTest { protocolSchedule, protocolContext, ethContext, + new PeerTaskExecutor(null, null, new NoOpMetricsSystem()), syncState, new NoOpMetricsSystem(), new FastSyncState(otherBlockchain.getBlockHeader(pivotBlockNumber).get()), diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStepTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStepTest.java index af4f45f690..c26e730aa3 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStepTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStepTest.java @@ -73,8 +73,7 @@ public class ImportBlocksStepTest { validationPolicy, ommerValidationPolicy, null, - pivotHeader, - BodyValidationMode.FULL); + pivotHeader); } @Test @@ -92,7 +91,7 @@ public class ImportBlocksStepTest { blockWithReceipts.getReceipts(), FULL, LIGHT, - BodyValidationMode.FULL)) + BodyValidationMode.LIGHT)) .thenReturn(new BlockImportResult(true)); } importBlocksStep.accept(blocksWithReceipts); @@ -114,7 +113,7 @@ public class ImportBlocksStepTest { blockWithReceipts.getReceipts(), FULL, LIGHT, - BodyValidationMode.FULL)) + BodyValidationMode.LIGHT)) .thenReturn(new BlockImportResult(false)); assertThatThrownBy(() -> importBlocksStep.accept(singletonList(blockWithReceipts))) .isInstanceOf(InvalidBlockException.class); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldStateDownloaderTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldStateDownloaderTest.java index 75fe892aeb..323f0ae9f1 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldStateDownloaderTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldStateDownloaderTest.java @@ -51,11 +51,11 @@ import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStatePreimageKeyValueStorage; import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.Node; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive; import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.trie.patricia.TrieNodeDecoder; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.ethereum.worldstate.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStatePreimageStorage; @@ -589,8 +589,8 @@ class FastWorldStateDownloaderTest { Function.identity()) .entriesFrom(Bytes32.ZERO, 5).values().stream() .map(RLP::input) - .map(StateTrieAccountValue::readFrom) - .map(StateTrieAccountValue::getStorageRoot) + .map(PmtStateTrieAccountValue::readFrom) + .map(PmtStateTrieAccountValue::getStorageRoot) .collect(Collectors.toList()); final Map allTrieNodes = new HashMap<>(); final Set knownNodes = new HashSet<>(); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java index 027bd270d2..9132842ccb 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java @@ -18,6 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import org.hyperledger.besu.ethereum.ConsensusContext; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.Blockchain; @@ -77,7 +78,8 @@ public class FullSyncTargetManagerTest { final ProtocolSchedule protocolSchedule = ProtocolScheduleFixture.MAINNET; final ProtocolContext protocolContext = - new ProtocolContext(localBlockchain, localWorldState, null, new BadBlockManager()); + new ProtocolContext( + localBlockchain, localWorldState, mock(ConsensusContext.class), new BadBlockManager()); ethProtocolManager = EthProtocolManagerTestUtil.create( protocolSchedule, diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/AccountHealingTrackingTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/AccountHealingTrackingTest.java index 8e4e40311f..ecb704ba89 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/AccountHealingTrackingTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/AccountHealingTrackingTest.java @@ -31,11 +31,11 @@ import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.RangeStorageEntriesCollector; import org.hyperledger.besu.ethereum.trie.TrieIterator; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.trie.patricia.StoredNodeFactory; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -82,8 +82,9 @@ public class AccountHealingTrackingTest { @Test void shouldMarkAccountForHealingWhenStorageProofIsReceived() { final Hash accountHash = Hash.hash(accounts.get(0)); - final StateTrieAccountValue stateTrieAccountValue = - StateTrieAccountValue.readFrom(RLP.input(accountStateTrie.get(accountHash).orElseThrow())); + final PmtStateTrieAccountValue stateTrieAccountValue = + PmtStateTrieAccountValue.readFrom( + RLP.input(accountStateTrie.get(accountHash).orElseThrow())); final StoredMerklePatriciaTrie storageTrie = new StoredMerklePatriciaTrie<>( @@ -130,8 +131,9 @@ public class AccountHealingTrackingTest { @Test void shouldNotMarkAccountForHealingWhenAllStorageIsReceivedWithoutProof() { final Hash accountHash = Hash.hash(accounts.get(0)); - final StateTrieAccountValue stateTrieAccountValue = - StateTrieAccountValue.readFrom(RLP.input(accountStateTrie.get(accountHash).orElseThrow())); + final PmtStateTrieAccountValue stateTrieAccountValue = + PmtStateTrieAccountValue.readFrom( + RLP.input(accountStateTrie.get(accountHash).orElseThrow())); final StoredMerklePatriciaTrie storageTrie = new StoredMerklePatriciaTrie<>( @@ -171,8 +173,9 @@ public class AccountHealingTrackingTest { @Test void shouldMarkAccountForHealingOnInvalidStorageProof() { final Hash accountHash = Hash.hash(accounts.get(0)); - final StateTrieAccountValue stateTrieAccountValue = - StateTrieAccountValue.readFrom(RLP.input(accountStateTrie.get(accountHash).orElseThrow())); + final PmtStateTrieAccountValue stateTrieAccountValue = + PmtStateTrieAccountValue.readFrom( + RLP.input(accountStateTrie.get(accountHash).orElseThrow())); final List proofs = List.of( @@ -197,8 +200,9 @@ public class AccountHealingTrackingTest { @Test void shouldMarkAccountForHealingOnInvalidStorageWithoutProof() { final Hash accountHash = Hash.hash(accounts.get(0)); - final StateTrieAccountValue stateTrieAccountValue = - StateTrieAccountValue.readFrom(RLP.input(accountStateTrie.get(accountHash).orElseThrow())); + final PmtStateTrieAccountValue stateTrieAccountValue = + PmtStateTrieAccountValue.readFrom( + RLP.input(accountStateTrie.get(accountHash).orElseThrow())); final StoredMerklePatriciaTrie storageTrie = new StoredMerklePatriciaTrie<>( @@ -236,8 +240,9 @@ public class AccountHealingTrackingTest { @Test void shouldMarkAccountForHealingOnPartialStorageRange() { final Hash accountHash = Hash.hash(accounts.get(0)); - final StateTrieAccountValue stateTrieAccountValue = - StateTrieAccountValue.readFrom(RLP.input(accountStateTrie.get(accountHash).orElseThrow())); + final PmtStateTrieAccountValue stateTrieAccountValue = + PmtStateTrieAccountValue.readFrom( + RLP.input(accountStateTrie.get(accountHash).orElseThrow())); final StoredMerklePatriciaTrie storageTrie = new StoredMerklePatriciaTrie<>( @@ -286,8 +291,9 @@ public class AccountHealingTrackingTest { @Test void shouldNotMarkAccountForHealingOnValidStorageTrieNodeDetection() { final Hash accountHash = Hash.hash(accounts.get(0)); - final StateTrieAccountValue stateTrieAccountValue = - StateTrieAccountValue.readFrom(RLP.input(accountStateTrie.get(accountHash).orElseThrow())); + final PmtStateTrieAccountValue stateTrieAccountValue = + PmtStateTrieAccountValue.readFrom( + RLP.input(accountStateTrie.get(accountHash).orElseThrow())); final StorageTrieNodeHealingRequest storageTrieNodeHealingRequest = SnapDataRequest.createStorageTrieNodeDataRequest( stateTrieAccountValue.getStorageRoot(), diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/TaskGenerator.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/TaskGenerator.java index 0b3a17cccf..2031e7a2a7 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/TaskGenerator.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/TaskGenerator.java @@ -27,10 +27,10 @@ import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.RangeManager; import org.hyperledger.besu.ethereum.trie.RangeStorageEntriesCollector; import org.hyperledger.besu.ethereum.trie.TrieIterator; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.services.tasks.Task; @@ -81,8 +81,8 @@ public class TaskGenerator { accountRangeDataRequest.addResponse(worldStateProofProvider, accounts, new ArrayDeque<>()); } - final StateTrieAccountValue stateTrieAccountValue = - StateTrieAccountValue.readFrom(RLP.input(accounts.firstEntry().getValue())); + final PmtStateTrieAccountValue stateTrieAccountValue = + PmtStateTrieAccountValue.readFrom(RLP.input(accounts.firstEntry().getValue())); final Hash accountHash = Hash.wrap(accounts.firstKey()); final StorageRangeDataRequest storageRangeDataRequest = diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageFlatDatabaseHealingRangeRequestTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageFlatDatabaseHealingRangeRequestTest.java index fb8dd74285..5eb88521ae 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageFlatDatabaseHealingRangeRequestTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageFlatDatabaseHealingRangeRequestTest.java @@ -31,10 +31,10 @@ import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.RangeManager; import org.hyperledger.besu.ethereum.trie.RangeStorageEntriesCollector; import org.hyperledger.besu.ethereum.trie.TrieIterator; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -97,8 +97,8 @@ class StorageFlatDatabaseHealingRangeRequestTest { account0StorageRoot = trie.get(account0Hash) .map(RLP::input) - .map(StateTrieAccountValue::readFrom) - .map(StateTrieAccountValue::getStorageRoot) + .map(PmtStateTrieAccountValue::readFrom) + .map(PmtStateTrieAccountValue::getStorageRoot) .orElseThrow(); } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageTrieNodeHealingRequestTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageTrieNodeHealingRequestTest.java index 4f8299f9ac..114399a66a 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageTrieNodeHealingRequestTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageTrieNodeHealingRequestTest.java @@ -23,10 +23,10 @@ import org.hyperledger.besu.ethereum.core.TrieGenerator; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.storage.StorageProvider; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; @@ -92,8 +92,8 @@ class StorageTrieNodeHealingRequestTest { account0StorageRoot = trie.get(account0Hash) .map(RLP::input) - .map(StateTrieAccountValue::readFrom) - .map(StateTrieAccountValue::getStorageRoot) + .map(PmtStateTrieAccountValue::readFrom) + .map(PmtStateTrieAccountValue::getStorageRoot) .orElseThrow(); } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java index 73d5e5138b..5686b4ae90 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java @@ -19,6 +19,7 @@ import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive; import static org.mockito.Mockito.mock; +import org.hyperledger.besu.ethereum.ConsensusContext; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; @@ -151,7 +152,11 @@ public class DetermineCommonAncestorTaskParameterizedTest { final EthContext ethContext = ethProtocolManager.ethContext(); final ProtocolContext protocolContext = - new ProtocolContext(localBlockchain, worldStateArchive, null, new BadBlockManager()); + new ProtocolContext( + localBlockchain, + worldStateArchive, + mock(ConsensusContext.class), + new BadBlockManager()); final EthTask task = DetermineCommonAncestorTask.create( diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java index 1b19a076d2..f85e4dd31c 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java @@ -27,6 +27,7 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import org.hyperledger.besu.ethereum.ConsensusContext; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.Blockchain; @@ -88,7 +89,11 @@ public class DetermineCommonAncestorTaskTest { EthProtocolConfiguration.defaultConfig()); ethContext = ethProtocolManager.ethContext(); protocolContext = - new ProtocolContext(localBlockchain, worldStateArchive, null, new BadBlockManager()); + new ProtocolContext( + localBlockchain, + worldStateArchive, + mock(ConsensusContext.class), + new BadBlockManager()); } @Test diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTestBase.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTestBase.java index c3ca24a4e1..e3e8046ba8 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTestBase.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTestBase.java @@ -49,7 +49,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; @@ -178,12 +178,12 @@ public abstract class AbstractTransactionPoolTestBase { final ProtocolSchedule protocolSchedule = new ProtocolScheduleBuilder( genesisConfigFile.getConfigOptions(), - BigInteger.valueOf(1), + Optional.of(BigInteger.valueOf(1)), ProtocolSpecAdapters.create(0, Function.identity()), new PrivacyParameters(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java index c679183b0f..d042996ce7 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java @@ -27,6 +27,7 @@ import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.cryptoservices.NodeKey; import org.hyperledger.besu.cryptoservices.NodeKeyUtils; +import org.hyperledger.besu.ethereum.ConsensusContext; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.GenesisState; @@ -34,7 +35,7 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -122,7 +123,7 @@ public class TestNode implements Closeable { GenesisConfigFile.fromResource("/dev.json").getConfigOptions(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -135,7 +136,8 @@ public class TestNode implements Closeable { final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); genesisState.writeStateTo(worldStateArchive.getMutable()); final ProtocolContext protocolContext = - new ProtocolContext(blockchain, worldStateArchive, null, new BadBlockManager()); + new ProtocolContext( + blockchain, worldStateArchive, mock(ConsensusContext.class), new BadBlockManager()); final SyncState syncState = mock(SyncState.class); final SynchronizerConfiguration syncConfig = mock(SynchronizerConfiguration.class); @@ -181,7 +183,7 @@ public class TestNode implements Closeable { syncState, TransactionPoolConfiguration.DEFAULT, new BlobCache(), - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); final EthProtocolManager ethProtocolManager = new EthProtocolManager( diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactoryTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactoryTest.java index 5742637c3e..612a1de9df 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactoryTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactoryTest.java @@ -36,7 +36,7 @@ import org.hyperledger.besu.ethereum.chain.BlockAddedObserver; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; @@ -373,12 +373,12 @@ public class TransactionPoolFactoryTest { schedule = new ProtocolScheduleBuilder( config, - DEFAULT_CHAIN_ID, + Optional.of(DEFAULT_CHAIN_ID), ProtocolSpecAdapters.create(0, Function.identity()), PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) @@ -413,7 +413,7 @@ public class TransactionPoolFactoryTest { transactionsMessageSender, newPooledTransactionHashesMessageSender, new BlobCache(), - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); } private TransactionPool createAndEnableTransactionPool( diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/AbstractPrioritizedTransactionsTestBase.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/AbstractPrioritizedTransactionsTestBase.java index 6a0005eec6..69db327013 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/AbstractPrioritizedTransactionsTestBase.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/AbstractPrioritizedTransactionsTestBase.java @@ -22,7 +22,7 @@ import static org.hyperledger.besu.ethereum.eth.transactions.layered.AddReason.N import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration; import org.hyperledger.besu.ethereum.eth.transactions.PendingTransaction; @@ -47,8 +47,8 @@ public abstract class AbstractPrioritizedTransactionsTestBase extends BaseTransa new EnumMap<>(Map.of(TransactionType.BLOB, 2)); protected final TransactionPoolMetrics txPoolMetrics = new TransactionPoolMetrics(metricsSystem); protected final EvictCollectorLayer evictCollector = new EvictCollectorLayer(txPoolMetrics); - protected final MiningParameters miningParameters = - MiningParameters.newDefault() + protected final MiningConfiguration miningConfiguration = + MiningConfiguration.newDefault() .setMinTransactionGasPrice(DEFAULT_MIN_GAS_PRICE) .setMinPriorityFeePerGas(DEFAULT_MIN_PRIORITY_FEE); protected AbstractPrioritizedTransactions transactions = @@ -58,16 +58,17 @@ public abstract class AbstractPrioritizedTransactionsTestBase extends BaseTransa .maxPrioritizedTransactionsByType(MAX_TRANSACTIONS_BY_TYPE) .maxFutureBySender(MAX_TRANSACTIONS) .build(), - miningParameters); + miningConfiguration); private AbstractPrioritizedTransactions getSorter( - final TransactionPoolConfiguration poolConfig, final MiningParameters miningParameters) { + final TransactionPoolConfiguration poolConfig, + final MiningConfiguration miningConfiguration) { return getSorter( poolConfig, evictCollector, txPoolMetrics, (pt1, pt2) -> transactionReplacementTester(poolConfig, pt1, pt2), - miningParameters); + miningConfiguration); } abstract AbstractPrioritizedTransactions getSorter( @@ -76,7 +77,7 @@ public abstract class AbstractPrioritizedTransactionsTestBase extends BaseTransa final TransactionPoolMetrics txPoolMetrics, final BiFunction transactionReplacementTester, - final MiningParameters miningParameters); + final MiningConfiguration miningConfiguration); abstract BlockHeader mockBlockHeader(); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/BaseFeePrioritizedTransactionsTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/BaseFeePrioritizedTransactionsTest.java index b9a675287f..8d01bd7397 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/BaseFeePrioritizedTransactionsTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/BaseFeePrioritizedTransactionsTest.java @@ -26,7 +26,7 @@ import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; @@ -60,7 +60,7 @@ public class BaseFeePrioritizedTransactionsTest extends AbstractPrioritizedTrans final TransactionPoolMetrics txPoolMetrics, final BiFunction transactionReplacementTester, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { return new BaseFeePrioritizedTransactions( poolConfig, @@ -71,7 +71,7 @@ public class BaseFeePrioritizedTransactionsTest extends AbstractPrioritizedTrans transactionReplacementTester, EIP1559_FEE_MARKET, new BlobCache(), - miningParameters); + miningConfiguration); } @Override @@ -164,7 +164,7 @@ public class BaseFeePrioritizedTransactionsTest extends AbstractPrioritizedTrans @Test public void txBelowCurrentMineableMinPriorityFeeIsNotPrioritized() { - miningParameters.setMinPriorityFeePerGas(Wei.of(5)); + miningConfiguration.setMinPriorityFeePerGas(Wei.of(5)); final PendingTransaction lowPriorityFeeTx = createRemotePendingTransaction( createTransaction(0, DEFAULT_MIN_GAS_PRICE.subtract(1), KEYS1)); @@ -175,7 +175,7 @@ public class BaseFeePrioritizedTransactionsTest extends AbstractPrioritizedTrans @Test public void txWithPriorityBelowCurrentMineableMinPriorityFeeIsPrioritized() { - miningParameters.setMinPriorityFeePerGas(Wei.of(5)); + miningConfiguration.setMinPriorityFeePerGas(Wei.of(5)); final PendingTransaction lowGasPriceTx = createRemotePendingTransaction( createTransaction(0, DEFAULT_MIN_GAS_PRICE.subtract(1), KEYS1), true); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/GasPricePrioritizedTransactionsTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/GasPricePrioritizedTransactionsTest.java index 66dcd3c721..a300ec23b4 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/GasPricePrioritizedTransactionsTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/GasPricePrioritizedTransactionsTest.java @@ -20,7 +20,7 @@ import static org.mockito.Mockito.when; import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; @@ -44,7 +44,7 @@ public class GasPricePrioritizedTransactionsTest extends AbstractPrioritizedTran final TransactionPoolMetrics txPoolMetrics, final BiFunction transactionReplacementTester, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { return new GasPricePrioritizedTransactions( poolConfig, @@ -53,7 +53,7 @@ public class GasPricePrioritizedTransactionsTest extends AbstractPrioritizedTran txPoolMetrics, transactionReplacementTester, new BlobCache(), - miningParameters); + miningConfiguration); } @Override diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredPendingTransactionsTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredPendingTransactionsTest.java index 5f6126326d..28814790a0 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredPendingTransactionsTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredPendingTransactionsTest.java @@ -42,7 +42,7 @@ import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration; @@ -158,7 +158,7 @@ public class LayeredPendingTransactionsTest extends BaseTransactionPoolTest { transactionReplacementTester, FeeMarket.london(0L), new BlobCache(), - MiningParameters.newDefault().setMinTransactionGasPrice(DEFAULT_MIN_GAS_PRICE)); + MiningConfiguration.newDefault().setMinTransactionGasPrice(DEFAULT_MIN_GAS_PRICE)); return new CreatedLayers( prioritizedTransactions, readyTransactions, sparseTransactions, evictCollector); } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredTransactionPoolBaseFeeTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredTransactionPoolBaseFeeTest.java index b3a840e706..c485ea7878 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredTransactionPoolBaseFeeTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredTransactionPoolBaseFeeTest.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; @@ -49,7 +49,7 @@ public class LayeredTransactionPoolBaseFeeTest extends AbstractLayeredTransactio transactionReplacementTester, FeeMarket.london(0L), new BlobCache(), - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); } @Override diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredTransactionPoolGasPriceTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredTransactionPoolGasPriceTest.java index 0c6f5f0bd2..305bd9959a 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredTransactionPoolGasPriceTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredTransactionPoolGasPriceTest.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; @@ -46,7 +46,7 @@ public class LayeredTransactionPoolGasPriceTest extends AbstractLayeredTransacti txPoolMetrics, transactionReplacementTester, new BlobCache(), - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); } @Override diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayersTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayersTest.java index 0decabaaaf..ee900e3dc4 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayersTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayersTest.java @@ -36,7 +36,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; @@ -1404,7 +1404,7 @@ public class LayersTest extends BaseTransactionPoolTest { (pt1, pt2) -> transactionReplacementTester(poolConfig, pt1, pt2), FeeMarket.london(0L), new BlobCache(), - MiningParameters.newDefault().setMinTransactionGasPrice(MIN_GAS_PRICE)); + MiningConfiguration.newDefault().setMinTransactionGasPrice(MIN_GAS_PRICE)); this.pending = new LayeredPendingTransactions(poolConfig, this.prio, ethScheduler); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/ReplayTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/ReplayTest.java index 847f5f2b91..760591a87c 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/ReplayTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/ReplayTest.java @@ -25,7 +25,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; @@ -232,7 +232,7 @@ public class ReplayTest { txReplacementTester, baseFeeMarket, new BlobCache(), - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); } // ToDo: commented since not always working, needs fix diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/MainnetGenesisFileModule.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/MainnetGenesisFileModule.java index 8dc8a74c1f..1addf8032e 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/MainnetGenesisFileModule.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/MainnetGenesisFileModule.java @@ -20,7 +20,7 @@ import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; import org.hyperledger.besu.crypto.SignatureAlgorithmType; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule; @@ -81,7 +81,7 @@ class MainnetGenesisFileModule extends GenesisFileModule { return MainnetProtocolSchedule.fromConfig( configOptions, evmConfiguration, - MiningParameters.newDefault(), + MiningConfiguration.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -187,12 +187,12 @@ class MainnetGenesisFileModule extends GenesisFileModule { return () -> new ProtocolScheduleBuilder( options, - options.getChainId().orElse(BigInteger.ONE), + options.getChainId(), ProtocolSpecAdapters.create(0, Function.identity()), PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) diff --git a/ethereum/p2p/build.gradle b/ethereum/p2p/build.gradle index 971504a25a..7cfcf2f8d5 100644 --- a/ethereum/p2p/build.gradle +++ b/ethereum/p2p/build.gradle @@ -43,7 +43,6 @@ dependencies { implementation 'com.google.guava:guava' implementation 'dnsjava:dnsjava' implementation 'io.netty:netty-transport-native-unix-common' - implementation 'io.prometheus:simpleclient' implementation 'io.vertx:vertx-core' implementation 'io.tmio:tuweni-bytes' diff --git a/ethereum/referencetests/build.gradle b/ethereum/referencetests/build.gradle index 99c5d8bc17..a4948597f7 100644 --- a/ethereum/referencetests/build.gradle +++ b/ethereum/referencetests/build.gradle @@ -224,6 +224,8 @@ dependencies { implementation 'io.tmio:tuweni-rlp' implementation 'com.fasterxml.jackson.core:jackson-databind' implementation 'com.google.guava:guava' + implementation 'com.google.dagger:dagger' + annotationProcessor 'com.google.dagger:dagger-compiler' referenceTestImplementation project(path: ':config') referenceTestImplementation project(path: ':datatypes') 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 c4c574b219..5f76f0ae1c 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 @@ -27,6 +27,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; +import org.hyperledger.besu.ethereum.core.ConsensusContextFixture; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; import org.hyperledger.besu.ethereum.core.MutableWorldState; @@ -110,7 +111,11 @@ public class BlockchainReferenceTestCaseSpec implements BlockchainReferenceTestC this.blockchain = buildBlockchain(genesisBlockHeader); this.sealEngine = sealEngine; this.protocolContext = - new ProtocolContext(this.blockchain, this.worldStateArchive, null, new BadBlockManager()); + new ProtocolContext( + this.blockchain, + this.worldStateArchive, + new ConsensusContextFixture(), + new BadBlockManager()); } @Override diff --git a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestEnv.java b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestEnv.java index 6d9090b333..865fff0e66 100644 --- a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestEnv.java +++ b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestEnv.java @@ -225,8 +225,7 @@ public class ReferenceTestEnv extends BlockHeader { BlockHeaderBuilder.createDefault() .difficulty(Difficulty.fromHexOrDecimalString(parentDifficulty)) .number(number - 1) - .buildBlockHeader(), - null))); + .buildBlockHeader()))); } if (parentExcessBlobGas != null && parentBlobGasUsed != null) { builder.excessBlobGas(BlobGas.of(Long.decode(parentExcessBlobGas))); diff --git a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java index 7fc7537f7b..adc392f522 100644 --- a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java +++ b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder; @@ -34,6 +34,7 @@ import java.util.Arrays; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Optional; import java.util.function.Function; import java.util.stream.Collectors; @@ -152,12 +153,12 @@ public class ReferenceTestProtocolSchedules { private static ProtocolSchedule createSchedule(final GenesisConfigOptions options) { return new ProtocolScheduleBuilder( options, - CHAIN_ID, + Optional.of(CHAIN_ID), ProtocolSpecAdapters.create(0, Function.identity()), PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) diff --git a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java index cfb56d1ebc..ea09a1eb98 100644 --- a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java +++ b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java @@ -18,7 +18,6 @@ package org.hyperledger.besu.ethereum.mainnet; import static org.assertj.core.api.Assertions.assertThat; -import org.checkerframework.checker.units.qual.N; import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.config.JsonUtil; import org.hyperledger.besu.config.StubGenesisConfigOptions; @@ -28,13 +27,12 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.log.LogsBloomFilter; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.stream.Stream; @@ -61,64 +59,64 @@ public class DifficultyCalculatorTests { MainnetProtocolSchedule.fromConfig( GenesisConfigFile.mainnet() .withOverrides(postMergeOverrides).getConfigOptions(), - EvmConfiguration.DEFAULT, MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem())), + EvmConfiguration.DEFAULT, MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem())), Arguments.of( "/DifficultyTests/dfGrayGlacier/difficultyGrayGlacierForkBlock.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().grayGlacierBlock(15050000), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + new StubGenesisConfigOptions().grayGlacierBlock(15050000), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfGrayGlacier/difficultyGrayGlacierTimeDiff1.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().grayGlacierBlock(15050000), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + new StubGenesisConfigOptions().grayGlacierBlock(15050000), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfGrayGlacier/difficultyGrayGlacierTimeDiff2.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().grayGlacierBlock(15050000), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + new StubGenesisConfigOptions().grayGlacierBlock(15050000), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfArrowGlacier/difficultyArrowGlacierForkBlock.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().arrowGlacierBlock(13773000), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + new StubGenesisConfigOptions().arrowGlacierBlock(13773000), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfArrowGlacier/difficultyArrowGlacierTimeDiff1.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().arrowGlacierBlock(13773000), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + new StubGenesisConfigOptions().arrowGlacierBlock(13773000), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfArrowGlacier/difficultyArrowGlacierTimeDiff2.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().arrowGlacierBlock(13773000), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + new StubGenesisConfigOptions().arrowGlacierBlock(13773000), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfByzantium/difficultyByzantium.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().byzantiumBlock(0), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().byzantiumBlock(0), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfConstantinople/difficultyConstantinople.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().constantinopleBlock(0), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().constantinopleBlock(0), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfEIP2384/difficultyEIP2384.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfEIP2384/difficultyEIP2384_random.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfEIP2384/difficultyEIP2384_random_to20M.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfFrontier/difficultyFrontier.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions(), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions(), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfHomestead/difficultyHomestead.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().homesteadBlock(0), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().homesteadBlock(0), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) )); } @@ -183,7 +181,7 @@ public class DifficultyCalculatorTests { UInt256.fromHexString(value.get("currentDifficulty").asText()); final var spec = protocolSchedule.getByBlockHeader(testHeader); final var calculator = spec.getDifficultyCalculator(); - assertThat(UInt256.valueOf(calculator.nextDifficulty(currentTime, testHeader, null))) + assertThat(UInt256.valueOf(calculator.nextDifficulty(currentTime, testHeader))) .describedAs("File %s Test %s", testFile, entry.getKey()) .isEqualTo(currentDifficulty); } diff --git a/ethereum/retesteth/build.gradle b/ethereum/retesteth/build.gradle deleted file mode 100644 index 484953a391..0000000000 --- a/ethereum/retesteth/build.gradle +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2019 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. - */ - -apply plugin: 'java-library' - -jar { - archiveBaseName = 'besu-retesteth' - manifest { - attributes( - 'Specification-Title': archiveBaseName, - 'Specification-Version': project.version, - 'Implementation-Title': archiveBaseName, - 'Implementation-Version': calculateVersion(), - 'Commit-Hash': getGitCommitDetails(40).hash - ) - } -} - -dependencies { - api 'org.slf4j:slf4j-api' - - implementation project(':config') - implementation project(':datatypes') - implementation project(':ethereum:api') - implementation project(':ethereum:api') - implementation project(':ethereum:blockcreation') - implementation project(':ethereum:core') - implementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts') - implementation project(':ethereum:eth') - implementation project(':ethereum:p2p') - implementation project(':ethereum:rlp') - implementation project(':evm') - implementation project(':metrics:core') - implementation project(':nat') - implementation project(':services:kvstore') - implementation project(':util') - - implementation 'com.google.guava:guava' - implementation 'io.vertx:vertx-core' - implementation 'io.vertx:vertx-web' - implementation 'com.fasterxml.jackson.core:jackson-databind' - implementation 'io.tmio:tuweni-bytes' - implementation 'io.tmio:tuweni-units' - - testImplementation 'org.assertj:assertj-core' - testImplementation 'org.junit.jupiter:junit-jupiter' - testImplementation 'org.mockito:mockito-core' -} diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethClock.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethClock.java deleted file mode 100644 index fdd22f42b0..0000000000 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethClock.java +++ /dev/null @@ -1,60 +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.ethereum.retesteth; - -import java.time.Clock; -import java.time.Instant; -import java.time.ZoneId; -import java.util.Optional; - -public class RetestethClock extends Clock { - - private Optional fixedInstant; - private final Clock delegateClock; - - RetestethClock() { - this(Clock.systemUTC()); - } - - private RetestethClock(final Clock delegateClock) { - fixedInstant = Optional.empty(); - this.delegateClock = delegateClock; - } - - @Override - public ZoneId getZone() { - return delegateClock.getZone(); - } - - @Override - public Clock withZone(final ZoneId zone) { - final RetestethClock zonedClock = new RetestethClock(delegateClock.withZone(zone)); - zonedClock.fixedInstant = fixedInstant; - return zonedClock; - } - - @Override - public Instant instant() { - return fixedInstant.orElseGet(delegateClock::instant); - } - - public void resetTime(final long time) { - fixedInstant = Optional.of(Instant.ofEpochSecond(time)); - } - - public void advanceSeconds(final long seconds) { - fixedInstant = Optional.of(Instant.ofEpochSecond(instant().getEpochSecond() + seconds)); - } -} 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 deleted file mode 100644 index 32d4e0bab1..0000000000 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java +++ /dev/null @@ -1,370 +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.ethereum.retesteth; - -import static org.hyperledger.besu.config.JsonUtil.normalizeKeys; - -import org.hyperledger.besu.config.JsonGenesisConfigOptions; -import org.hyperledger.besu.config.JsonUtil; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.ProtocolContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockReplay; -import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; -import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.chain.DefaultBlockchain; -import org.hyperledger.besu.ethereum.chain.GenesisState; -import org.hyperledger.besu.ethereum.chain.MutableBlockchain; -import org.hyperledger.besu.ethereum.chain.VariablesStorage; -import org.hyperledger.besu.ethereum.core.Block; -import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.Unstable; -import org.hyperledger.besu.ethereum.core.MiningParameters; -import org.hyperledger.besu.ethereum.core.MutableWorldState; -import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; -import org.hyperledger.besu.ethereum.eth.manager.EthContext; -import org.hyperledger.besu.ethereum.eth.manager.EthMessages; -import org.hyperledger.besu.ethereum.eth.manager.EthPeers; -import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; -import org.hyperledger.besu.ethereum.eth.sync.SyncMode; -import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; -import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; -import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration; -import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; -import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; -import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolFactory; -import org.hyperledger.besu.ethereum.forkid.ForkIdManager; -import org.hyperledger.besu.ethereum.mainnet.EpochCalculator; -import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; -import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; -import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule; -import org.hyperledger.besu.ethereum.mainnet.PoWHasher; -import org.hyperledger.besu.ethereum.mainnet.PoWSolution; -import org.hyperledger.besu.ethereum.mainnet.PoWSolver; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; -import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; -import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage; -import org.hyperledger.besu.ethereum.storage.keyvalue.VariablesKeyValueStorage; -import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStatePreimageKeyValueStorage; -import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive; -import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; -import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; -import org.hyperledger.besu.evm.internal.EvmConfiguration; -import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; -import org.hyperledger.besu.plugin.services.MetricsSystem; -import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; -import org.hyperledger.besu.util.Subscribers; -import org.hyperledger.besu.util.number.Fraction; - -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.locks.ReentrantLock; -import java.util.function.Supplier; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.units.bigints.UInt256; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class RetestethContext { - - private static final Logger LOG = LoggerFactory.getLogger(RetestethContext.class); - private static final PoWHasher NO_WORK_HASHER = - (final long nonce, final long number, EpochCalculator epochCalc, final Bytes headerHash) -> - new PoWSolution(nonce, Hash.ZERO, UInt256.ZERO, Hash.ZERO); - public static final int MAX_PEERS = 25; - - private final ReentrantLock contextLock = new ReentrantLock(); - private final BadBlockManager badBlockManager = new BadBlockManager(); - private Address coinbase; - private Bytes extraData; - private MutableBlockchain blockchain; - private ProtocolContext protocolContext; - private BlockchainQueries blockchainQueries; - private ProtocolSchedule protocolSchedule; - private BlockHeaderFunctions blockHeaderFunctions; - private HeaderValidationMode headerValidationMode; - private BlockReplay blockReplay; - private RetestethClock retestethClock; - private MiningParameters miningParameters; - private TransactionPool transactionPool; - private EthScheduler ethScheduler; - private PoWSolver poWSolver; - - private Optional terminalTotalDifficulty; - private Optional mixHash; - - public boolean resetContext( - final String genesisConfigString, final String sealEngine, final Optional clockTime) { - contextLock.lock(); - try { - tearDownContext(); - return buildContext(genesisConfigString, sealEngine, clockTime); - } catch (final Exception e) { - LOG.error("Error shutting down existing runner", e); - return false; - } finally { - contextLock.unlock(); - } - } - - private void tearDownContext() { - try { - if (ethScheduler != null) { - ethScheduler.stop(); - ethScheduler.awaitStop(); - } - } catch (final InterruptedException e) { - throw new RuntimeException(e); - } - } - - private boolean buildContext( - final String genesisConfigString, final String sealEngine, final Optional clockTime) { - final ObjectNode genesisConfig = - normalizeKeys(JsonUtil.objectNodeFromString(genesisConfigString)); - - retestethClock = new RetestethClock(); - clockTime.ifPresent(retestethClock::resetTime); - final MetricsSystem metricsSystem = new NoOpMetricsSystem(); - - terminalTotalDifficulty = - Optional.ofNullable(genesisConfig.get("params")) - .map(n -> n.get("terminaltotaldifficulty")) - .map(JsonNode::asText) - .map(Bytes::fromHexString); - - final JsonGenesisConfigOptions jsonGenesisConfigOptions = - JsonGenesisConfigOptions.fromJsonObject( - JsonUtil.getObjectNode(genesisConfig, "config").get()); - protocolSchedule = - MainnetProtocolSchedule.fromConfig( - jsonGenesisConfigOptions, - EvmConfiguration.DEFAULT, - miningParameters, - badBlockManager, - false, - new NoOpMetricsSystem()); - if ("NoReward".equalsIgnoreCase(sealEngine)) { - protocolSchedule = new NoRewardProtocolScheduleWrapper(protocolSchedule, badBlockManager); - } - blockHeaderFunctions = ScheduleBasedBlockHeaderFunctions.create(protocolSchedule); - - final GenesisState genesisState = GenesisState.fromJson(genesisConfigString, protocolSchedule); - coinbase = genesisState.getBlock().getHeader().getCoinbase(); - extraData = genesisState.getBlock().getHeader().getExtraData(); - mixHash = Optional.ofNullable(genesisState.getBlock().getHeader().getMixHashOrPrevRandao()); - - final WorldStateArchive worldStateArchive = - new ForestWorldStateArchive( - new WorldStateStorageCoordinator( - new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage())), - new WorldStatePreimageKeyValueStorage(new InMemoryKeyValueStorage()), - EvmConfiguration.DEFAULT); - final MutableWorldState worldState = worldStateArchive.getMutable(); - genesisState.writeStateTo(worldState); - - blockchain = createInMemoryBlockchain(genesisState.getBlock()); - protocolContext = new ProtocolContext(blockchain, worldStateArchive, null, badBlockManager); - - blockchainQueries = - new BlockchainQueries( - protocolSchedule, blockchain, worldStateArchive, ethScheduler, miningParameters); - - final String sealengine = JsonUtil.getString(genesisConfig, "sealengine", ""); - headerValidationMode = - "NoProof".equals(sealengine) || "NoReward".equals(sealEngine) - ? HeaderValidationMode.LIGHT - : HeaderValidationMode.FULL; - - miningParameters = - ImmutableMiningParameters.builder() - .mutableInitValues( - MutableInitValues.builder() - .coinbase(coinbase) - .extraData(extraData) - .targetGasLimit(blockchain.getChainHeadHeader().getGasLimit()) - .minBlockOccupancyRatio(0.0) - .minTransactionGasPrice(Wei.ZERO) - .build()) - .unstable(Unstable.builder().powJobTimeToLive(1000).maxOmmerDepth(8).build()) - .build(); - miningParameters.setMinTransactionGasPrice(Wei.ZERO); - poWSolver = - ("NoProof".equals(sealengine) || "NoReward".equals(sealEngine)) - ? new PoWSolver( - miningParameters, - NO_WORK_HASHER, - false, - Subscribers.none(), - new EpochCalculator.DefaultEpochCalculator()) - : new PoWSolver( - miningParameters, - PoWHasher.ETHASH_LIGHT, - false, - Subscribers.none(), - new EpochCalculator.DefaultEpochCalculator()); - - blockReplay = - new BlockReplay(protocolSchedule, protocolContext, blockchainQueries.getBlockchain()); - - final Bytes localNodeKey = Bytes.wrap(new byte[64]); - - // mining support - - final Supplier currentProtocolSpecSupplier = - () -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()); - final EthPeers ethPeers = - new EthPeers( - "reteseth", - currentProtocolSpecSupplier, - retestethClock, - metricsSystem, - EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE, - Collections.emptyList(), - localNodeKey, - MAX_PEERS, - MAX_PEERS, - false, - SyncMode.FAST, - new ForkIdManager(blockchain, List.of(), List.of(), false)); - final SyncState syncState = new SyncState(blockchain, ethPeers); - - ethScheduler = new EthScheduler(1, 1, 1, 1, metricsSystem); - final EthContext ethContext = new EthContext(ethPeers, new EthMessages(), ethScheduler); - - final TransactionPoolConfiguration transactionPoolConfiguration = - ImmutableTransactionPoolConfiguration.builder() - .txPoolLimitByAccountPercentage(Fraction.fromFloat(0.004f)) - .build(); - - transactionPool = - TransactionPoolFactory.createTransactionPool( - protocolSchedule, - protocolContext, - ethContext, - retestethClock, - metricsSystem, - syncState, - transactionPoolConfiguration, - new BlobCache(), - MiningParameters.newDefault()); - - if (LOG.isTraceEnabled()) { - LOG.trace("Genesis Block {} ", genesisState.getBlock()); - } - - return true; - } - - private static MutableBlockchain createInMemoryBlockchain(final Block genesisBlock) { - return createInMemoryBlockchain(genesisBlock, new MainnetBlockHeaderFunctions()); - } - - private static MutableBlockchain createInMemoryBlockchain( - final Block genesisBlock, final BlockHeaderFunctions blockHeaderFunctions) { - final InMemoryKeyValueStorage keyValueStorage = new InMemoryKeyValueStorage(); - final VariablesStorage variablesStorage = - new VariablesKeyValueStorage(new InMemoryKeyValueStorage()); - return DefaultBlockchain.createMutable( - genesisBlock, - new KeyValueStoragePrefixedKeyBlockchainStorage( - keyValueStorage, variablesStorage, blockHeaderFunctions, false), - new NoOpMetricsSystem(), - 100); - } - - public ProtocolSchedule getProtocolSchedule() { - return protocolSchedule; - } - - public BlockHeaderFunctions getBlockHeaderFunctions() { - return blockHeaderFunctions; - } - - public ProtocolContext getProtocolContext() { - return protocolContext; - } - - public EthScheduler getEthScheduler() { - return ethScheduler; - } - - public void setEthScheduler(final EthScheduler ethScheduler) { - this.ethScheduler = ethScheduler; - } - - public long getBlockHeight() { - return blockchain.getChainHeadBlockNumber(); - } - - public ProtocolSpec getProtocolSpec(final BlockHeader blockHeader) { - return getProtocolSchedule().getByBlockHeader(blockHeader); - } - - public BlockHeader getBlockHeader(final long blockNumber) { - return blockchain.getBlockHeader(blockNumber).get(); - } - - public BlockchainQueries getBlockchainQueries() { - return blockchainQueries; - } - - public HeaderValidationMode getHeaderValidationMode() { - return headerValidationMode; - } - - BlockReplay getBlockReplay() { - return blockReplay; - } - - public TransactionPool getTransactionPool() { - return transactionPool; - } - - public MiningParameters getMiningParameters() { - return miningParameters; - } - - public MutableBlockchain getBlockchain() { - return blockchain; - } - - public RetestethClock getRetestethClock() { - return retestethClock; - } - - public Optional getTerminalTotalDifficulty() { - return terminalTotalDifficulty; - } - - public Optional getMixHash() { - return mixHash; - } - - public PoWSolver getEthHashSolver() { - return poWSolver; - } -} 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 deleted file mode 100644 index 877c597686..0000000000 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethService.java +++ /dev/null @@ -1,122 +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.ethereum.retesteth; - -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; -import org.hyperledger.besu.ethereum.api.jsonrpc.health.LivenessCheck; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugAccountRange; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugStorageRangeAt; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthBlockNumber; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetBalance; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetBlockByHash; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetBlockByNumber; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetCode; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetTransactionCount; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthSendRawTransaction; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.Web3ClientVersion; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory; -import org.hyperledger.besu.ethereum.core.DummySynchronizer; -import org.hyperledger.besu.ethereum.core.Synchronizer; -import org.hyperledger.besu.ethereum.retesteth.methods.TestGetLogHash; -import org.hyperledger.besu.ethereum.retesteth.methods.TestImportRawBlock; -import org.hyperledger.besu.ethereum.retesteth.methods.TestMineBlocks; -import org.hyperledger.besu.ethereum.retesteth.methods.TestModifyTimestamp; -import org.hyperledger.besu.ethereum.retesteth.methods.TestRewindToBlock; -import org.hyperledger.besu.ethereum.retesteth.methods.TestSetChainParams; -import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; -import org.hyperledger.besu.nat.NatService; - -import java.util.Arrays; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; - -import io.vertx.core.Vertx; - -public class RetestethService { - - private final JsonRpcHttpService jsonRpcHttpService; - private final Vertx vertx; - - private final RetestethContext retestethContext; - - public RetestethService( - final String clientVersion, - final RetestethConfiguration retestethConfiguration, - final JsonRpcConfiguration jsonRpcConfiguration) { - vertx = Vertx.vertx(); - retestethContext = new RetestethContext(); - - final BlockResultFactory blockResult = new BlockResultFactory(); - final NatService natService = new NatService(Optional.empty()); - - // Synchronizer needed by RPC methods. Didn't wanna mock it, since this isn't the test module. - Synchronizer sync = new DummySynchronizer(); - - final Map jsonRpcMethods = - mapOf( - new Web3ClientVersion(clientVersion), - new TestSetChainParams(retestethContext), - new TestImportRawBlock(retestethContext), - new EthBlockNumber(retestethContext::getBlockchainQueries, true), - new EthGetBlockByNumber( - retestethContext::getBlockchainQueries, blockResult, sync, true), - new DebugAccountRange(retestethContext::getBlockchainQueries), - new EthGetBalance(retestethContext::getBlockchainQueries), - new EthGetBlockByHash(retestethContext::getBlockchainQueries, blockResult, true), - new EthGetCode(retestethContext::getBlockchainQueries), - new EthGetTransactionCount( - retestethContext::getBlockchainQueries, retestethContext::getTransactionPool), - new DebugStorageRangeAt( - retestethContext::getBlockchainQueries, retestethContext::getBlockReplay, true), - new TestModifyTimestamp(retestethContext), - new EthSendRawTransaction(retestethContext::getTransactionPool, true), - new TestMineBlocks(retestethContext), - new TestGetLogHash(retestethContext), - new TestRewindToBlock(retestethContext)); - - jsonRpcHttpService = - new JsonRpcHttpService( - vertx, - retestethConfiguration.getDataPath(), - jsonRpcConfiguration, - new NoOpMetricsSystem(), - natService, - jsonRpcMethods, - new HealthService(new LivenessCheck()), - HealthService.ALWAYS_HEALTHY); - } - - public void start() { - jsonRpcHttpService.start(); - } - - public void close() { - stop(); - } - - public void stop() { - jsonRpcHttpService.stop(); - vertx.close(); - } - - private static Map mapOf(final JsonRpcMethod... rpcMethods) { - return Arrays.stream(rpcMethods) - .collect(Collectors.toMap(JsonRpcMethod::getName, rpcMethod -> rpcMethod)); - } -} diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestGetLogHash.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestGetLogHash.java deleted file mode 100644 index 398d72d665..0000000000 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestGetLogHash.java +++ /dev/null @@ -1,73 +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.ethereum.retesteth.methods; - -import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; -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.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.api.query.TransactionReceiptWithMetadata; -import org.hyperledger.besu.ethereum.retesteth.RetestethContext; -import org.hyperledger.besu.ethereum.rlp.RLP; -import org.hyperledger.besu.evm.log.Log; - -import java.util.Optional; - -public class TestGetLogHash implements JsonRpcMethod { - private final RetestethContext context; - - public TestGetLogHash(final RetestethContext context) { - this.context = context; - } - - @Override - public String getName() { - return "test_getLogHash"; - } - - @Override - public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final Hash txHash; - try { - txHash = requestContext.getRequiredParameter(0, Hash.class); - } catch (JsonRpcParameterException e) { - throw new InvalidJsonRpcParameters( - "Invalid transaction hash parameter (index 0)", - RpcErrorType.INVALID_TRANSACTION_HASH_PARAMS, - e); - } - - final Optional receipt = - context - .getBlockchainQueries() - .transactionReceiptByTransactionHash(txHash, context.getProtocolSchedule()); - return new JsonRpcSuccessResponse( - requestContext.getRequest().getId(), - receipt.map(this::calculateLogHash).orElse(Hash.EMPTY_LIST_HASH).toString()); - } - - private Hash calculateLogHash( - final TransactionReceiptWithMetadata transactionReceiptWithMetadata) { - return Hash.hash( - RLP.encode( - out -> - out.writeList( - transactionReceiptWithMetadata.getReceipt().getLogsList(), Log::writeTo))); - } -} 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 deleted file mode 100644 index 580b107a8b..0000000000 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java +++ /dev/null @@ -1,107 +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.ethereum.retesteth.methods; - -import org.hyperledger.besu.ethereum.ProtocolContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; -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.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.core.Block; -import org.hyperledger.besu.ethereum.core.BlockImporter; -import org.hyperledger.besu.ethereum.mainnet.BlockImportResult; -import org.hyperledger.besu.ethereum.retesteth.RetestethContext; -import org.hyperledger.besu.ethereum.rlp.RLP; -import org.hyperledger.besu.ethereum.rlp.RLPException; - -import java.util.Collections; - -import org.apache.tuweni.bytes.Bytes; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class TestImportRawBlock implements JsonRpcMethod { - private static final Logger LOG = LoggerFactory.getLogger(TestImportRawBlock.class); - - public static final String METHOD_NAME = "test_importRawBlock"; - - private final RetestethContext context; - - public TestImportRawBlock(final RetestethContext context) { - this.context = context; - } - - @Override - public String getName() { - return METHOD_NAME; - } - - @Override - public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final String input; - try { - input = requestContext.getRequiredParameter(0, String.class); - } catch (JsonRpcParameterException e) { - throw new InvalidJsonRpcParameters( - "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); - } - final ProtocolContext protocolContext = this.context.getProtocolContext(); - - final Block block; - try { - block = - Block.readFrom(RLP.input(Bytes.fromHexString(input)), context.getBlockHeaderFunctions()); - } catch (final RLPException | IllegalArgumentException e) { - LOG.debug("Failed to parse block RLP", e); - return new JsonRpcErrorResponse( - requestContext.getRequest().getId(), RpcErrorType.BLOCK_RLP_IMPORT_ERROR); - } - - // retesteth expects test_rawImportBlock to not only import the block, but append it to head - if (context.getBlockchain().contains(block.getHash())) { - // if we already have the block but it is not head, append it: - context - .getBlockchain() - .appendBlock( - block, - context - .getBlockchain() - .getTxReceipts(block.getHash()) - .orElse(Collections.emptyList())); - } else { - // otherwise attempt to import the block - final BlockImporter blockImporter = - context.getProtocolSpec(block.getHeader()).getBlockImporter(); - final BlockImportResult result = - blockImporter.importBlock( - protocolContext, - block, - context.getHeaderValidationMode(), - context.getHeaderValidationMode()); - if (!result.isImported()) { - LOG.debug("Failed to import block."); - return new JsonRpcErrorResponse( - requestContext.getRequest().getId(), RpcErrorType.BLOCK_IMPORT_ERROR); - } - } - // return success on append or import - return new JsonRpcSuccessResponse( - requestContext.getRequest().getId(), block.getHash().toString()); - } -} diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java deleted file mode 100644 index 00a27bb7a8..0000000000 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java +++ /dev/null @@ -1,97 +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.ethereum.retesteth.methods; - -import org.hyperledger.besu.ethereum.ProtocolContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; -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.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.blockcreation.PoWBlockCreator; -import org.hyperledger.besu.ethereum.chain.MutableBlockchain; -import org.hyperledger.besu.ethereum.core.Block; -import org.hyperledger.besu.ethereum.core.BlockImporter; -import org.hyperledger.besu.ethereum.core.MiningParameters; -import org.hyperledger.besu.ethereum.mainnet.BlockImportResult; -import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; -import org.hyperledger.besu.ethereum.retesteth.RetestethClock; -import org.hyperledger.besu.ethereum.retesteth.RetestethContext; - -public class TestMineBlocks implements JsonRpcMethod { - private final RetestethContext context; - - public TestMineBlocks(final RetestethContext context) { - this.context = context; - } - - @Override - public String getName() { - return "test_mineBlocks"; - } - - @Override - public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - long blocksToMine = 0; - try { - blocksToMine = requestContext.getRequiredParameter(0, Long.class); - } catch (JsonRpcParameterException e) { - throw new InvalidJsonRpcParameters( - "Invalid blocks to mine (index 0)", RpcErrorType.INVALID_BLOCK_COUNT_PARAMS, e); - } - while (blocksToMine-- > 0) { - if (!mineNewBlock()) { - return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), false); - } - } - - return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), true); - } - - private boolean mineNewBlock() { - final RetestethClock retesethClock = context.getRetestethClock(); - final ProtocolSchedule protocolSchedule = context.getProtocolSchedule(); - final ProtocolContext protocolContext = context.getProtocolContext(); - final MutableBlockchain blockchain = context.getBlockchain(); - final HeaderValidationMode headerValidationMode = context.getHeaderValidationMode(); - final MiningParameters miningParameters = context.getMiningParameters(); - final PoWBlockCreator blockCreator = - new PoWBlockCreator( - miningParameters, - header -> miningParameters.getExtraData(), - context.getTransactionPool(), - protocolContext, - protocolSchedule, - context.getEthHashSolver(), - context.getEthScheduler()); - final Block block = - blockCreator - .createBlock(retesethClock.instant().getEpochSecond(), blockchain.getChainHeadHeader()) - .getBlock(); - - // advance clock so next mine won't hit the same timestamp - retesethClock.advanceSeconds(1); - - final BlockImporter blockImporter = - protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()).getBlockImporter(); - final BlockImportResult result = - blockImporter.importBlock( - protocolContext, block, headerValidationMode, headerValidationMode); - return result.isImported(); - } -} diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestModifyTimestamp.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestModifyTimestamp.java deleted file mode 100644 index 717cf41b45..0000000000 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestModifyTimestamp.java +++ /dev/null @@ -1,51 +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.ethereum.retesteth.methods; - -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; -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.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.retesteth.RetestethContext; - -public class TestModifyTimestamp implements JsonRpcMethod { - - private final RetestethContext context; - - public TestModifyTimestamp(final RetestethContext context) { - this.context = context; - } - - @Override - public String getName() { - return "test_modifyTimestamp"; - } - - @Override - public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final long epochSeconds; - try { - epochSeconds = requestContext.getRequiredParameter(0, Long.class); - } catch (JsonRpcParameterException e) { - throw new InvalidJsonRpcParameters( - "Invalid timestamp parameter (index 0)", RpcErrorType.INVALID_TIMESTAMP_PARAMS, e); - } - context.getRetestethClock().resetTime(epochSeconds); - return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), true); - } -} diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestRewindToBlock.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestRewindToBlock.java deleted file mode 100644 index d9b847af42..0000000000 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestRewindToBlock.java +++ /dev/null @@ -1,53 +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.ethereum.retesteth.methods; - -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; -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.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.retesteth.RetestethContext; - -public class TestRewindToBlock implements JsonRpcMethod { - private final RetestethContext context; - - public static final String METHOD_NAME = "test_rewindToBlock"; - - public TestRewindToBlock(final RetestethContext context) { - this.context = context; - } - - @Override - public String getName() { - return METHOD_NAME; - } - - @Override - public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final long blockNumber; - try { - blockNumber = requestContext.getRequiredParameter(0, Long.TYPE); - } catch (JsonRpcParameterException e) { - throw new InvalidJsonRpcParameters( - "Invalid block number parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); - } - - return new JsonRpcSuccessResponse( - requestContext.getRequest().getId(), context.getBlockchain().rewindToBlock(blockNumber)); - } -} diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParams.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParams.java deleted file mode 100644 index 1446fd939f..0000000000 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParams.java +++ /dev/null @@ -1,159 +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.ethereum.retesteth.methods; - -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; -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.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.retesteth.RetestethContext; - -import java.util.Iterator; -import java.util.Map; -import java.util.Optional; - -import io.vertx.core.json.JsonObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class TestSetChainParams implements JsonRpcMethod { - - private static final Logger LOG = LoggerFactory.getLogger(TestSetChainParams.class); - - public static final String METHOD_NAME = "test_setChainParams"; - private final RetestethContext context; - - public TestSetChainParams(final RetestethContext context) { - this.context = context; - } - - @Override - public String getName() { - return METHOD_NAME; - } - - @SuppressWarnings("unchecked") - @Override - public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - - try { - final JsonObject chainParamsAsJson = - new JsonObject((Map) requestContext.getRequest().getParams()[0]); - final String chainParamsAsString = chainParamsAsJson.encodePrettily(); - LOG.trace("ChainParams {}", chainParamsAsString); - final String genesisFileAsString = modifyGenesisFile(chainParamsAsString); - LOG.trace("Genesis {}", genesisFileAsString); - final boolean result = - context.resetContext( - genesisFileAsString, - chainParamsAsJson.getString("sealEngine", "NoProof"), - Optional.empty()); - - return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), result); - } catch (final Exception e) { - LOG.error("Unhandled error", e); - return new JsonRpcErrorResponse( - requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS); - } - } - - private static void maybeMove( - final JsonObject src, final String srcName, final JsonObject dest, final String destName) { - if (src.containsKey(srcName)) { - dest.put(destName, src.getValue(srcName)); - src.remove(srcName); - } - } - - private static void maybeMoveToNumber( - final JsonObject src, final String srcName, final JsonObject dest, final String destName) { - if (src.containsKey(srcName)) { - dest.put(destName, Long.decode(src.getString(srcName))); - src.remove(srcName); - } - } - - private static void maybeMoveToNumber( - final JsonObject src, - final String srcName, - final JsonObject dest, - final String destName, - final long defaultValue) { - if (src.containsKey(srcName)) { - dest.put(destName, Long.decode(src.getString(srcName))); - src.remove(srcName); - } else { - dest.put(destName, defaultValue); - } - } - - private static String modifyGenesisFile(final String initialGenesis) { - final JsonObject chainParamsJson = new JsonObject(initialGenesis); - final JsonObject config = new JsonObject(); - chainParamsJson.put("config", config); - final JsonObject params = chainParamsJson.getJsonObject("params"); - final JsonObject genesis = chainParamsJson.getJsonObject("genesis"); - - // Whether sealEngine is NoProof, Ethash, or NoReward the genesis file is the same - final JsonObject ethash = new JsonObject(); - config.put("ethash", ethash); - - maybeMoveToNumber(params, "homesteadForkBlock", config, "homesteadBlock"); - maybeMoveToNumber(params, "daoHardforkBlock", config, "daoForkBlock"); - maybeMoveToNumber(params, "EIP150ForkBlock", config, "eip150Block"); - maybeMoveToNumber(params, "EIP158ForkBlock", config, "eip158Block"); - maybeMoveToNumber(params, "byzantiumForkBlock", config, "byzantiumBlock"); - maybeMoveToNumber(params, "constantinopleForkBlock", config, "constantinopleBlock"); - maybeMoveToNumber(params, "constantinopleFixForkBlock", config, "petersburgBlock"); - maybeMoveToNumber(params, "istanbulForkBlock", config, "istanbulBlock"); - maybeMoveToNumber(params, "muirGlacierForkBlock", config, "muirGlacierBlock"); - maybeMoveToNumber(params, "berlinForkBlock", config, "berlinBlock"); - maybeMoveToNumber(params, "londonForkBlock", config, "londonBlock"); - maybeMoveToNumber(params, "arrowGlacierForkBlock", config, "arrowGlacierBlock"); - maybeMoveToNumber(params, "grayGlacierForkBlock", config, "grayGlacierBlock"); - maybeMoveToNumber(params, "mergeNetSplitForkBlock", config, "mergeNetSplitBlock"); - maybeMoveToNumber(params, "shanghaiForkTime", config, "shanghaiTime"); - maybeMoveToNumber(params, "cancunForkTime", config, "cancunTime"); - maybeMoveToNumber(params, "pragueForkTime", config, "pragueTime"); - maybeMoveToNumber(params, "futureEipsForkTime", config, "futureEipsTime"); - maybeMoveToNumber(params, "experimentalEipsForkTime", config, "experimentalEipsTime"); - maybeMoveToNumber(params, "chainID", config, "chainId", 1); - - maybeMove(genesis, "author", chainParamsJson, "coinbase"); - maybeMove(genesis, "difficulty", chainParamsJson, "difficulty"); - maybeMove(genesis, "extraData", chainParamsJson, "extraData"); - maybeMove(genesis, "gasLimit", chainParamsJson, "gasLimit"); - maybeMove(genesis, "mixHash", chainParamsJson, "mixHash"); - maybeMove(genesis, "nonce", chainParamsJson, "nonce"); - maybeMove(genesis, "timestamp", chainParamsJson, "timestamp"); - maybeMove(chainParamsJson, "accounts", chainParamsJson, "alloc"); - maybeMove(genesis, "baseFeePerGas", chainParamsJson, "baseFeePerGas"); - - // strip out precompiles with zero balance - final JsonObject alloc = chainParamsJson.getJsonObject("alloc"); - final Iterator fieldNamesIter = alloc.fieldNames().iterator(); - while (fieldNamesIter.hasNext()) { - final String address = fieldNamesIter.next(); - final JsonObject account = alloc.getJsonObject(address); - if (account.containsKey("precompiled") && !account.containsKey("balance")) { - fieldNamesIter.remove(); - } - } - - return chainParamsJson.encodePrettily(); - } -} diff --git a/ethereum/retesteth/src/test/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlockTest.java b/ethereum/retesteth/src/test/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlockTest.java deleted file mode 100644 index b156f2294d..0000000000 --- a/ethereum/retesteth/src/test/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlockTest.java +++ /dev/null @@ -1,129 +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.ethereum.retesteth.methods; - -import static org.assertj.core.api.Assertions.assertThat; - -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.JsonRpcErrorResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.retesteth.RetestethContext; -import org.hyperledger.besu.plugin.services.rpc.RpcResponseType; - -import java.io.IOException; - -import com.google.common.base.Charsets; -import com.google.common.io.Resources; -import io.vertx.core.json.JsonObject; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class TestImportRawBlockTest { - private TestImportRawBlock test_importRawBlock; - private TestRewindToBlock test_rewindToBlock; - private RetestethContext context; - - @BeforeEach - public void setupClass() throws IOException { - context = new RetestethContext(); - test_importRawBlock = new TestImportRawBlock(context); - test_rewindToBlock = new TestRewindToBlock(context); - final TestSetChainParams test_setChainParams = new TestSetChainParams(context); - final String chainParamsJsonString = - Resources.toString( - TestSetChainParamsTest.class.getResource("multimpleBalanceInstructionChainParams.json"), - Charsets.UTF_8); - final JsonObject chainParamsJson = new JsonObject(chainParamsJsonString); - - final JsonRpcRequestContext request = - new JsonRpcRequestContext( - new JsonRpcRequest( - "2.0", TestSetChainParams.METHOD_NAME, new Object[] {chainParamsJson.getMap()})); - - assertThat(test_setChainParams.response(request)) - .isEqualTo(new JsonRpcSuccessResponse(null, true)); - } - - @Test - public void testMissingParent() { - final String rawBlockRLPString = - "0xf9045df901f9a0e38bef3dadb98e856ea82c7e9813b76a6ec8d9cf60694dd65d800a1669c1a1fda03770bba814f8cc5534ab5e40bdb3fe51866b537805c5577888091766e621fc13948888f1f195afa192cfee860698584c030f4c9db1a019ce64082807650d3d01ac60cd16a583e9472dcc0ccb8f39dd867e317cf025dda09735e49acaddb4d8338ed33df8dd006449b20b85e89e47224ac8ec8f7ea26071a0056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200000483301fd28252088454c99c2142a00000000000000000000000000000000000000000000000000000000000000000880000000000000000f862f86003018304cb2f94095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba0a7b7f2fa93025fc1e6aa18c1aa07c32a456439754e196cb74f2f7d12cf3e840da02078cf840fb25fc3d858b2a85b622f21be0588b5c5d81d433427f6470e06a4a7f901faf901f7a0f88512d9e022357594866c44ecaa2fc9cb48f34d1987e401109400761aeb898da01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794bcde5374fce5edbc8e2a8697c15331677e6ebf0ba0fe87abb0d3ab38d4eb64405de03db5245b0d40c4b85d8a1b5028ada8643de2dba056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000002833007cf808454c9945142a00000000000000000000000000000000000000000000000000000000000000000880000000000000000"; - - final JsonRpcRequestContext request = - new JsonRpcRequestContext( - new JsonRpcRequest( - "2.0", TestImportRawBlock.METHOD_NAME, new Object[] {rawBlockRLPString})); - - final var response = test_importRawBlock.response(request); - assertThat(response.getType()).isEqualTo(RpcResponseType.ERROR); - assertThat(((JsonRpcErrorResponse) response).getErrorType()) - .isEqualTo(RpcErrorType.BLOCK_IMPORT_ERROR); - } - - @Test - public void testBadBlock() { - final String rawBlockRLPString = "0xf9045df901f9a08"; - - final JsonRpcRequestContext request = - new JsonRpcRequestContext( - new JsonRpcRequest( - "2.0", TestImportRawBlock.METHOD_NAME, new Object[] {rawBlockRLPString})); - - final var response = test_importRawBlock.response(request); - assertThat(response.getType()).isEqualTo(RpcResponseType.ERROR); - assertThat(((JsonRpcErrorResponse) response).getErrorType()) - .isEqualTo(RpcErrorType.BLOCK_RLP_IMPORT_ERROR); - } - - @Test - public void testGoodBlock() { - final String rawBlockRLPString = - "0xf90262f901faa0e38bef3dadb98e856ea82c7e9813b76a6ec8d9cf60694dd65d800a1669c1a1fda01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a06e6be3f633fe0399cb17a9d8238b988a39bd9ab3e0ac0820f4df705a1ee37536a06fb77a9ddaa64a8e161b643d05533a4093f2be900ad06279b1b56b3bcee3b979a04b33fa3c9c50b7b9a4500f5c0b1e71ab43362abc81c2cf31fd2b54acf7d750d8b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefba83016b66845db7320980a00000000000000000000000000000000000000000000000000000000000000000880000000000000000f862f860800a830249f094095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba0d42a045ac77a6d4676dd5fbc5104ed7471b6cef2465cfefaa52919b340f942a9a06e4d319aea79e45cde79d337e6edf849ceac505cab65dd41a572cab132d4dccac0"; - - final JsonRpcRequestContext request = - new JsonRpcRequestContext( - new JsonRpcRequest( - "2.0", TestImportRawBlock.METHOD_NAME, new Object[] {rawBlockRLPString})); - - final var response = test_importRawBlock.response(request); - assertThat(response.getType()).isEqualTo(RpcResponseType.SUCCESS); - } - - @Test - public void testReimportExistingBlock() { - final String rawBlockRLPString = - "0xf90262f901faa0e38bef3dadb98e856ea82c7e9813b76a6ec8d9cf60694dd65d800a1669c1a1fda01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a06e6be3f633fe0399cb17a9d8238b988a39bd9ab3e0ac0820f4df705a1ee37536a06fb77a9ddaa64a8e161b643d05533a4093f2be900ad06279b1b56b3bcee3b979a04b33fa3c9c50b7b9a4500f5c0b1e71ab43362abc81c2cf31fd2b54acf7d750d8b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefba83016b66845db7320980a00000000000000000000000000000000000000000000000000000000000000000880000000000000000f862f860800a830249f094095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba0d42a045ac77a6d4676dd5fbc5104ed7471b6cef2465cfefaa52919b340f942a9a06e4d319aea79e45cde79d337e6edf849ceac505cab65dd41a572cab132d4dccac0"; - - final JsonRpcRequestContext request = - new JsonRpcRequestContext( - new JsonRpcRequest( - "2.0", TestImportRawBlock.METHOD_NAME, new Object[] {rawBlockRLPString})); - - final JsonRpcRequestContext requestRewind = - new JsonRpcRequestContext( - new JsonRpcRequest("2.0", TestRewindToBlock.METHOD_NAME, new Object[] {0L})); - - final var response = test_importRawBlock.response(request); - assertThat(response.getType()).isEqualTo(RpcResponseType.SUCCESS); - final var rewindResponse = test_rewindToBlock.response(requestRewind); - assertThat(rewindResponse.getType()).isEqualTo(RpcResponseType.SUCCESS); - final var reimportResponse = test_importRawBlock.response(request); - assertThat(reimportResponse.getType()).isEqualTo(RpcResponseType.SUCCESS); - - assertThat(context.getBlockchain().getChainHead().getHeight()).isEqualTo(1L); - } -} diff --git a/ethereum/retesteth/src/test/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParamsTest.java b/ethereum/retesteth/src/test/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParamsTest.java deleted file mode 100644 index f376fa0c25..0000000000 --- a/ethereum/retesteth/src/test/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParamsTest.java +++ /dev/null @@ -1,115 +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.ethereum.retesteth.methods; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.hyperledger.besu.datatypes.Wei; -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.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.retesteth.RetestethContext; - -import java.io.IOException; - -import com.google.common.base.Charsets; -import com.google.common.io.Resources; -import io.vertx.core.json.JsonObject; -import org.apache.tuweni.units.bigints.UInt256; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -public class TestSetChainParamsTest { - - private static RetestethContext context; - private static TestSetChainParams test_setChainParams; - - @BeforeAll - public static void setupClass() { - context = new RetestethContext(); - test_setChainParams = new TestSetChainParams(context); - } - - @Test - public void testValidateGenesisImport() throws IOException { - final String chainParamsJsonString = - Resources.toString( - TestSetChainParamsTest.class.getResource("multimpleBalanceInstructionChainParams.json"), - Charsets.UTF_8); - final JsonObject chainParamsJson = new JsonObject(chainParamsJsonString); - - final JsonRpcRequestContext request = - new JsonRpcRequestContext( - new JsonRpcRequest( - "2.0", TestSetChainParams.METHOD_NAME, new Object[] {chainParamsJson.getMap()})); - - assertThat(test_setChainParams.response(request)) - .isEqualTo(new JsonRpcSuccessResponse(null, true)); - - final BlockHeader blockHeader = context.getBlockHeader(0); - - assertThat(blockHeader.getLogsBloom().toString()) - .isEqualTo( - "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); - assertThat(blockHeader.getCoinbase().toString()) - .isEqualTo("0x8888f1f195afa192cfee860698584c030f4c9db1"); - assertThat(blockHeader.getDifficulty()).isEqualTo(UInt256.fromHexString("0x20000")); - assertThat(blockHeader.getExtraData().toHexString()).isEqualTo("0x42"); - assertThat(blockHeader.getGasLimit()).isEqualTo(3141592); - assertThat(blockHeader.getGasUsed()).isEqualTo(0); - assertThat(blockHeader.getMixHash().toString()) - .isEqualTo("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"); - assertThat(blockHeader.getNonce()).isEqualTo(0x0102030405060708L); - assertThat(blockHeader.getNumber()).isEqualTo(0); - assertThat(blockHeader.getParentHash().toString()) - .isEqualTo("0x0000000000000000000000000000000000000000000000000000000000000000"); - assertThat(blockHeader.getReceiptsRoot().toString()) - .isEqualTo("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"); - assertThat(blockHeader.getStateRoot().toString()) - .isEqualTo("0xf403922bfd555a9223f68fc755564004e20d78bb42aae647e867e3b23c48beba"); - assertThat(blockHeader.getTimestamp()).isEqualTo(0x54c98c81); - assertThat(blockHeader.getTransactionsRoot().toString()) - .isEqualTo("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"); - assertThat(blockHeader.getOmmersHash().toString()) - .isEqualTo("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"); - } - - @Test - public void testValidate1559GenesisImport() throws IOException { - final String chainParamsJsonString = - Resources.toString( - TestSetChainParamsTest.class.getResource("1559ChainParams.json"), Charsets.UTF_8); - final JsonObject chainParamsJson = new JsonObject(chainParamsJsonString); - - final JsonRpcRequestContext request = - new JsonRpcRequestContext( - new JsonRpcRequest( - "2.0", TestSetChainParams.METHOD_NAME, new Object[] {chainParamsJson.getMap()})); - - assertThat(test_setChainParams.response(request)) - .isEqualTo(new JsonRpcSuccessResponse(null, true)); - - final BlockHeader blockHeader = context.getBlockHeader(0); - assertThat(blockHeader.getDifficulty()).isEqualTo(UInt256.fromHexString("0x20000")); - assertThat(blockHeader.getGasLimit()).isEqualTo(1234L); - assertThat(blockHeader.getBaseFee()).hasValue(Wei.of(12345L)); - assertThat(blockHeader.getExtraData().toHexString()).isEqualTo("0x00"); - assertThat(blockHeader.getTimestamp()).isEqualTo(0l); - assertThat(blockHeader.getNonce()).isEqualTo(0L); - assertThat(blockHeader.getMixHash().toHexString()) - .isEqualTo("0x0000000000000000000000000000000000000000000000000000000000000000"); - } -} diff --git a/ethereum/retesteth/src/test/resources/org/hyperledger/besu/ethereum/retesteth/methods/1559ChainParams.json b/ethereum/retesteth/src/test/resources/org/hyperledger/besu/ethereum/retesteth/methods/1559ChainParams.json deleted file mode 100644 index 95535e269f..0000000000 --- a/ethereum/retesteth/src/test/resources/org/hyperledger/besu/ethereum/retesteth/methods/1559ChainParams.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "genesis" : { - "author" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", - "difficulty" : "0x020000", - "gasLimit" : "0x04d2", - "baseFeePerGas" : "0x3039", - "extraData" : "0x00", - "timestamp" : "0x00", - "nonce" : "0x0000000000000000", - "mixHash" : "0x0000000000000000000000000000000000000000000000000000000000000000" - }, - "params": { - "EIP150ForkBlock": "0x00", - "EIP158ForkBlock": "0x00", - "byzantiumForkBlock": "0x00", - "homesteadForkBlock": "0x00", - "londonForkBlock": "0x00" - }, - "sealEngine": "NoProof", - "accounts": {} -} \ No newline at end of file diff --git a/ethereum/retesteth/src/test/resources/org/hyperledger/besu/ethereum/retesteth/methods/multimpleBalanceInstructionChainParams.json b/ethereum/retesteth/src/test/resources/org/hyperledger/besu/ethereum/retesteth/methods/multimpleBalanceInstructionChainParams.json deleted file mode 100644 index 0cb0cfc960..0000000000 --- a/ethereum/retesteth/src/test/resources/org/hyperledger/besu/ethereum/retesteth/methods/multimpleBalanceInstructionChainParams.json +++ /dev/null @@ -1,102 +0,0 @@ -{ - "accounts": { - "0x0000000000000000000000000000000000000001": { - "precompiled": { - "linear": { - "base": 3000, - "word": 0 - }, - "name": "ecrecover" - } - }, - "0x0000000000000000000000000000000000000002": { - "precompiled": { - "linear": { - "base": 60, - "word": 12 - }, - "name": "sha256" - } - }, - "0x0000000000000000000000000000000000000003": { - "precompiled": { - "linear": { - "base": 600, - "word": 120 - }, - "name": "sha256" - } - }, - "0x0000000000000000000000000000000000000004": { - "precompiled": { - "linear": { - "base": 15, - "word": 3 - }, - "name": "identity" - } - }, - "0x0000000000000000000000000000000000000005": { - "precompiled": { - "name": "modexp" - } - }, - "0x0000000000000000000000000000000000000006": { - "precompiled": { - "linear": { - "base": 500, - "word": 0 - }, - "name": "alt_bn128_G1_add" - } - }, - "0x0000000000000000000000000000000000000007": { - "precompiled": { - "linear": { - "base": 40000, - "word": 0 - }, - "name": "alt_bn128_G1_mul" - } - }, - "0x0000000000000000000000000000000000000008": { - "precompiled": { - "name": "alt_bn128_pairing_product" - } - }, - "0x095e7baea6a6c7c4c2dfeb977efac326af552d87": { - "balance": "0x0186a0", - "code": "0x73a94f5374fce5edbc8e2a8697c15331677e6ebf0b31600055738888f1f195afa192cfee860698584c030f4c9db13160015573a94f5374fce5edbc8e2a8697c15331677e6ebf0b31600255738888f1f195afa192cfee860698584c030f4c9db13160035573095e7baea6a6c7c4c2dfeb977efac326af552d8731600555", - "nonce": "0x00", - "storage": {} - }, - "0x195e7baea6a6c7c4c2dfeb977efac326af552d87": { - "balance": "0x0186a0", - "code": "0x73a94f5374fce5edbc8e2a8697c15331677e6ebf0b31600055738888f1f195afa192cfee860698584c030f4c9db13160015573a94f5374fce5edbc8e2a8697c15331677e6ebf0b31600255738888f1f195afa192cfee860698584c030f4c9db13160035573095e7baea6a6c7c4c2dfeb977efac326af552d873160045573195e7baea6a6c7c4c2dfeb977efac326af552d8731600555", - "nonce": "0x00", - "storage": {} - }, - "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { - "balance": "0x1748721582", - "code": "0x", - "nonce": "0x00", - "storage": {} - } - }, - "genesis": { - "author": "0x8888f1f195afa192cfee860698584c030f4c9db1", - "difficulty": "0x020000", - "extraData": "0x42", - "gasLimit": "0x2fefd8", - "mixHash": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "nonce": "0x0102030405060708", - "timestamp": "0x54c98c81" - }, - "params": { - "EIP150ForkBlock": "0x00", - "EIP158ForkBlock": "0x00", - "byzantiumForkBlock": "0x00", - "homesteadForkBlock": "0x00" - }, - "sealEngine": "NoProof" -} \ No newline at end of file diff --git a/evm/src/main/java/org/hyperledger/besu/evm/operation/PushOperation.java b/evm/src/main/java/org/hyperledger/besu/evm/operation/PushOperation.java index ab094b0e57..171b742f7c 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/operation/PushOperation.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/operation/PushOperation.java @@ -26,9 +26,6 @@ public class PushOperation extends AbstractOperation { /** The constant PUSH_BASE. */ public static final int PUSH_BASE = 0x5F; - /** The constant PUSH_MAX. */ - public static final int PUSH_MAX = 0x7F; - private final int length; /** @@ -44,18 +41,27 @@ public class PushOperation extends AbstractOperation { @Override public OperationResult execute(final MessageFrame frame, final EVM evm) { + final byte[] code = frame.getCode().getBytes().toArrayUnsafe(); int pc = frame.getPC(); - - int copyStart = pc + 1; + final int copyStart = pc + 1; long gasCost = gasCalculator().pushOperationGasCost(frame, copyStart, length, code.length); + Bytes push; if (code.length <= copyStart) { push = Bytes.EMPTY; } else { final int copyLength = Math.min(length, code.length - copyStart); - push = Bytes.wrap(code, copyStart, copyLength); + final int rightPad = length - copyLength; + if (rightPad == 0) { + push = Bytes.wrap(code, copyStart, copyLength); + } else { + // Right Pad the push with 0s up to pushSize if greater than the copyLength + var bytecodeLocal = new byte[length]; + System.arraycopy(code, copyStart, bytecodeLocal, 0, copyLength); + push = Bytes.wrap(bytecodeLocal); + } } frame.pushStackItem(push); frame.setPC(pc + length); diff --git a/evm/src/test/java/org/hyperledger/besu/evm/operation/PushOperationTest.java b/evm/src/test/java/org/hyperledger/besu/evm/operation/PushOperationTest.java new file mode 100644 index 0000000000..d303cc27d8 --- /dev/null +++ b/evm/src/test/java/org/hyperledger/besu/evm/operation/PushOperationTest.java @@ -0,0 +1,83 @@ +/* + * 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.evm.operation; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hyperledger.besu.evm.operation.PushOperation.staticOperation; + +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.evm.code.CodeV0; +import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.toy.ToyBlockValues; +import org.hyperledger.besu.evm.toy.ToyWorld; + +import org.apache.tuweni.bytes.Bytes; +import org.apache.tuweni.bytes.Bytes32; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +public class PushOperationTest { + + private static final byte[] byteCode = new byte[] {0x00, 0x01, 0x02, 0x03}; + private static final MessageFrame frame = + MessageFrame.builder() + .worldUpdater(new ToyWorld()) + .originator(Address.ZERO) + .gasPrice(Wei.ONE) + .blobGasPrice(Wei.ONE) + .blockValues(new ToyBlockValues()) + .miningBeneficiary(Address.ZERO) + .blockHashLookup((l) -> Hash.ZERO) + .type(MessageFrame.Type.MESSAGE_CALL) + .initialGas(1) + .address(Address.ZERO) + .contract(Address.ZERO) + .inputData(Bytes32.ZERO) + .sender(Address.ZERO) + .value(Wei.ZERO) + .apparentValue(Wei.ZERO) + .code(CodeV0.EMPTY_CODE) + .completer(messageFrame -> {}) + .build(); + ; + + @Test + void unpaddedPushDoesntReachEndCode() { + staticOperation(frame, byteCode, 0, byteCode.length - 2); + assertThat(frame.getStackItem(0).equals(Bytes.fromHexString("0x0102"))).isTrue(); + } + + @Test + void unpaddedPushUpReachesEndCode() { + staticOperation(frame, byteCode, 0, byteCode.length - 1); + assertThat(frame.getStackItem(0).equals(Bytes.fromHexString("0x010203"))).isTrue(); + } + + @Test + void paddedPush() { + staticOperation(frame, byteCode, 1, byteCode.length - 1); + assertThat(frame.getStackItem(0).equals(Bytes.fromHexString("0x020300"))).isTrue(); + } + + @Test + void oobPush() { + staticOperation(frame, byteCode, byteCode.length, byteCode.length - 1); + assertThat(frame.getStackItem(0).equals(Bytes.EMPTY)).isTrue(); + } +} diff --git a/metrics/core/build.gradle b/metrics/core/build.gradle index 1438a198ae..160093c749 100644 --- a/metrics/core/build.gradle +++ b/metrics/core/build.gradle @@ -57,6 +57,7 @@ dependencies { implementation 'io.prometheus:simpleclient' implementation 'io.prometheus:simpleclient_common' + implementation 'io.prometheus:simpleclient_guava' implementation 'io.prometheus:simpleclient_hotspot' implementation 'io.prometheus:simpleclient_pushgateway' implementation 'io.vertx:vertx-core' diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImpl.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImpl.java index b0a31793bc..43feef12ac 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImpl.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImpl.java @@ -14,31 +14,81 @@ */ package org.hyperledger.besu.metrics; +import static com.google.common.base.Preconditions.checkNotNull; + +import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.MetricCategoryRegistry; -import java.util.ArrayList; -import java.util.List; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; /** The Metric category registry implementation. */ public class MetricCategoryRegistryImpl implements MetricCategoryRegistry { - - private final List metricCategories = new ArrayList<>(); + private final Map metricCategories = new HashMap<>(); + private MetricsConfiguration metricsConfiguration; /** Default constructor */ public MetricCategoryRegistryImpl() {} /** - * Gets metric categories. + * Add Metrics categories. + * + * @param the type parameter + * @param categoryEnum the category enum + */ + public & MetricCategory> void addCategories(final Class categoryEnum) { + EnumSet.allOf(categoryEnum) + .forEach(category -> metricCategories.put(category.name(), category)); + } + + /** + * Add registry category. * - * @return the metric categories + * @param metricCategory the metric category */ - public List getMetricCategories() { - return metricCategories; + @Override + public void addMetricCategory(final MetricCategory metricCategory) { + metricCategories.put(metricCategory.getName().toUpperCase(Locale.ROOT), metricCategory); } @Override - public void addMetricCategory(final MetricCategory newMetricCategory) { - metricCategories.add(newMetricCategory); + public boolean isMetricCategoryEnabled(final MetricCategory metricCategory) { + checkNotNull( + metricsConfiguration, "Metrics configuration must be set before calling this method"); + return (metricsConfiguration.isEnabled() || metricsConfiguration.isPushEnabled()) + && metricsConfiguration.getMetricCategories().contains(metricCategory); + } + + /** + * Return true if a category with that name is already registered + * + * @param name the category name + * @return true if a category with that name is already registered + */ + public boolean containsMetricCategory(final String name) { + return metricCategories.containsKey(name.toUpperCase(Locale.ROOT)); + } + + /** + * Return a metric category by name + * + * @param name the category name + * @return the metric category or null if not registered + */ + public MetricCategory getMetricCategory(final String name) { + return metricCategories.get(name.toUpperCase(Locale.ROOT)); + } + + /** + * Set the metric configuration via a method since it is still not available when creating this + * object + * + * @param metricsConfiguration the metrics configuration + */ + public void setMetricsConfiguration(final MetricsConfiguration metricsConfiguration) { + this.metricsConfiguration = metricsConfiguration; } } diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/ObservableMetricsSystem.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/ObservableMetricsSystem.java index 8090d28fc1..98e7a8b634 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/ObservableMetricsSystem.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/ObservableMetricsSystem.java @@ -17,42 +17,25 @@ package org.hyperledger.besu.metrics; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; -import java.util.Set; import java.util.stream.Stream; -/** The interface Observable metrics system. */ +/** The observable metrics system is used to inspect metrics for debug reasons */ public interface ObservableMetricsSystem extends MetricsSystem { - /** - * Stream observations. + * Stream observations by category * * @param category the category - * @return the stream + * @return the observations stream */ Stream streamObservations(MetricCategory category); /** - * Stream observations. + * Stream observations * - * @return the stream + * @return the observations stream */ Stream streamObservations(); - /** - * Provides an immutable view into the metric categories enabled for metric collection. - * - * @return the set of enabled metric categories. - */ - Set getEnabledCategories(); - - /** - * Checks if a particular category of metrics is enabled. - * - * @param category the category to check - * @return true if the category is enabled, false otherwise - */ - default boolean isCategoryEnabled(final MetricCategory category) { - return getEnabledCategories().stream() - .anyMatch(metricCategory -> metricCategory.getName().equals(category.getName())); - } + /** Unregister all the collectors and perform other cleanup tasks */ + void shutdown(); } diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpMetricsSystem.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpMetricsSystem.java index 5f876fa4d8..68b5d52ffa 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpMetricsSystem.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpMetricsSystem.java @@ -17,8 +17,10 @@ package org.hyperledger.besu.metrics.noop; import org.hyperledger.besu.metrics.ObservableMetricsSystem; import org.hyperledger.besu.metrics.Observation; import org.hyperledger.besu.plugin.services.metrics.Counter; +import org.hyperledger.besu.plugin.services.metrics.ExternalSummary; import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.OperationTimer; @@ -27,9 +29,11 @@ import java.util.Collections; import java.util.List; import java.util.Set; import java.util.function.DoubleSupplier; +import java.util.function.Supplier; import java.util.stream.Stream; import com.google.common.base.Preconditions; +import com.google.common.cache.Cache; /** The NoOp metrics system. */ public class NoOpMetricsSystem implements ObservableMetricsSystem { @@ -38,7 +42,7 @@ public class NoOpMetricsSystem implements ObservableMetricsSystem { public static final Counter NO_OP_COUNTER = new NoOpCounter(); /** The constant NO_OP_GAUGE. */ - public static final LabelledGauge NO_OP_GAUGE = new NoOpValueCollector(); + public static final LabelledSuppliedMetric NO_OP_GAUGE = new NoOpValueCollector(); private static final OperationTimer.TimingContext NO_OP_TIMING_CONTEXT = () -> 0; @@ -62,16 +66,16 @@ public class NoOpMetricsSystem implements ObservableMetricsSystem { new LabelCountingNoOpMetric<>(1, NO_OP_OPERATION_TIMER); /** The constant NO_OP_LABELLED_1_GAUGE. */ - public static final LabelledGauge NO_OP_LABELLED_1_GAUGE = - new LabelledGaugeNoOpMetric(1, NO_OP_GAUGE); + public static final LabelledSuppliedMetric NO_OP_LABELLED_1_GAUGE = + new LabelledSuppliedNoOpMetric(1, NO_OP_GAUGE); /** The constant NO_OP_LABELLED_2_GAUGE. */ - public static final LabelledGauge NO_OP_LABELLED_2_GAUGE = - new LabelledGaugeNoOpMetric(2, NO_OP_GAUGE); + public static final LabelledSuppliedMetric NO_OP_LABELLED_2_GAUGE = + new LabelledSuppliedNoOpMetric(2, NO_OP_GAUGE); /** The constant NO_OP_LABELLED_3_GAUGE. */ - public static final LabelledGauge NO_OP_LABELLED_3_GAUGE = - new LabelledGaugeNoOpMetric(3, NO_OP_GAUGE); + public static final LabelledSuppliedMetric NO_OP_LABELLED_3_GAUGE = + new LabelledSuppliedNoOpMetric(3, NO_OP_GAUGE); /** Default constructor */ public NoOpMetricsSystem() {} @@ -113,6 +117,13 @@ public class NoOpMetricsSystem implements ObservableMetricsSystem { return getOperationTimerLabelledMetric(labelNames.length); } + @Override + public void trackExternalSummary( + final MetricCategory category, + final String name, + final String help, + final Supplier summarySupplier) {} + @Override public LabelledMetric createLabelledTimer( final MetricCategory category, @@ -145,12 +156,25 @@ public class NoOpMetricsSystem implements ObservableMetricsSystem { final DoubleSupplier valueSupplier) {} @Override - public LabelledGauge createLabelledGauge( + public void createGuavaCacheCollector( + final MetricCategory category, final String name, final Cache cache) {} + + @Override + public LabelledSuppliedMetric createLabelledSuppliedCounter( final MetricCategory category, final String name, final String help, final String... labelNames) { - return getLabelledGauge(labelNames.length); + return getLabelledSuppliedMetric(labelNames.length); + } + + @Override + public LabelledSuppliedMetric createLabelledSuppliedGauge( + final MetricCategory category, + final String name, + final String help, + final String... labelNames) { + return getLabelledSuppliedMetric(labelNames.length); } /** @@ -159,7 +183,7 @@ public class NoOpMetricsSystem implements ObservableMetricsSystem { * @param labelCount the label count * @return the labelled gauge */ - public static LabelledGauge getLabelledGauge(final int labelCount) { + public static LabelledSuppliedMetric getLabelledSuppliedMetric(final int labelCount) { switch (labelCount) { case 1: return NO_OP_LABELLED_1_GAUGE; @@ -168,7 +192,7 @@ public class NoOpMetricsSystem implements ObservableMetricsSystem { case 3: return NO_OP_LABELLED_3_GAUGE; default: - return new LabelledGaugeNoOpMetric(labelCount, NO_OP_GAUGE); + return new LabelledSuppliedNoOpMetric(labelCount, NO_OP_GAUGE); } } @@ -187,6 +211,9 @@ public class NoOpMetricsSystem implements ObservableMetricsSystem { return Collections.emptySet(); } + @Override + public void shutdown() {} + /** * The Label counting NoOp metric. * @@ -220,8 +247,9 @@ public class NoOpMetricsSystem implements ObservableMetricsSystem { } } - /** The Labelled gauge NoOp metric. */ - public static class LabelledGaugeNoOpMetric implements LabelledGauge { + /** The Labelled supplied NoOp metric. */ + @SuppressWarnings("removal") // remove when deprecated LabelledGauge is removed + public static class LabelledSuppliedNoOpMetric implements LabelledSuppliedMetric, LabelledGauge { /** The Label count. */ final int labelCount; @@ -234,13 +262,14 @@ public class NoOpMetricsSystem implements ObservableMetricsSystem { * @param labelCount the label count * @param fakeMetric the fake metric */ - public LabelledGaugeNoOpMetric(final int labelCount, final LabelledGauge fakeMetric) { + public LabelledSuppliedNoOpMetric( + final int labelCount, final LabelledSuppliedMetric fakeMetric) { this.labelCount = labelCount; this.fakeMetric = fakeMetric; } /** The Fake metric. */ - final LabelledGauge fakeMetric; + final LabelledSuppliedMetric fakeMetric; @Override public void labels(final DoubleSupplier valueSupplier, final String... labelValues) { @@ -253,14 +282,5 @@ public class NoOpMetricsSystem implements ObservableMetricsSystem { "The count of labels used must match the count of labels expected."); Preconditions.checkNotNull(valueSupplier, "No valueSupplier specified"); } - - @Override - public boolean isLabelsObserved(final String... labelValues) { - Preconditions.checkArgument( - labelValues.length == labelCount, - "The count of labels used must match the count of labels expected."); - final String labelValuesString = String.join(",", labelValues); - return labelValuesCache.contains(labelValuesString); - } } } diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpValueCollector.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpValueCollector.java index 6f36f10d2c..3db34babe4 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpValueCollector.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpValueCollector.java @@ -14,14 +14,14 @@ */ package org.hyperledger.besu.metrics.noop; -import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; import java.util.ArrayList; import java.util.List; import java.util.function.DoubleSupplier; /** The NoOp value collector. */ -public class NoOpValueCollector implements LabelledGauge { +public class NoOpValueCollector implements LabelledSuppliedMetric { private final List labelValuesCreated = new ArrayList<>(); /** Default constructor */ @@ -36,10 +36,4 @@ public class NoOpValueCollector implements LabelledGauge { } labelValuesCreated.add(labelValuesString); } - - @Override - public boolean isLabelsObserved(final String... labelValues) { - final String labelValuesString = String.join(",", labelValues); - return labelValuesCreated.contains(labelValuesString); - } } diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryGauge.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryGauge.java index e1d785c68e..4f250cbd92 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryGauge.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryGauge.java @@ -16,23 +16,14 @@ package org.hyperledger.besu.metrics.opentelemetry; import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; -import java.util.Arrays; import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.function.DoubleSupplier; -import com.google.common.base.Preconditions; -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.api.metrics.Meter; -import io.opentelemetry.api.metrics.ObservableDoubleMeasurement; /** The Open telemetry gauge. */ -public class OpenTelemetryGauge implements LabelledGauge { - private final List labelNames; - private final Map observationsMap = new ConcurrentHashMap<>(); - +@SuppressWarnings("removal") // remove when deprecated LabelledGauge is removed +public class OpenTelemetryGauge extends OpenTelemetryLabelledSuppliedMetric + implements LabelledGauge { /** * Instantiates a new Open telemetry gauge. * @@ -46,41 +37,8 @@ public class OpenTelemetryGauge implements LabelledGauge { final String help, final Meter meter, final List labelNames) { - this.labelNames = labelNames; + super(labelNames); meter.gaugeBuilder(metricName).setDescription(help).buildWithCallback(this::updater); } - - @Override - public void labels(final DoubleSupplier valueSupplier, final String... labelValues) { - Preconditions.checkArgument( - labelValues.length == labelNames.size(), - "label values and label names need the same number of elements"); - final Attributes labels = getLabels(labelValues); - if (observationsMap.putIfAbsent(labels, valueSupplier) != null) { - throw new IllegalStateException( - "Already registered a gauge with labels " + Arrays.toString(labelValues)); - } - } - - @Override - public boolean isLabelsObserved(final String... labelValues) { - Preconditions.checkArgument( - labelValues.length == labelNames.size(), - "label values and label names need the same number of elements"); - return observationsMap.containsKey(getLabels(labelValues)); - } - - private Attributes getLabels(final String... labelValues) { - final AttributesBuilder labelsBuilder = Attributes.builder(); - for (int i = 0; i < labelNames.size(); i++) { - labelsBuilder.put(labelNames.get(i), labelValues[i]); - } - return labelsBuilder.build(); - } - - private void updater(final ObservableDoubleMeasurement measurement) { - observationsMap.forEach( - (labels, valueSupplier) -> measurement.record(valueSupplier.getAsDouble(), labels)); - } } diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryLabelledSuppliedMetric.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryLabelledSuppliedMetric.java new file mode 100644 index 0000000000..db48ee9b31 --- /dev/null +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryLabelledSuppliedMetric.java @@ -0,0 +1,67 @@ +/* + * Copyright contributors to Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.metrics.opentelemetry; + +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.DoubleSupplier; + +import com.google.common.base.Preconditions; +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.api.metrics.ObservableDoubleMeasurement; + +abstract class OpenTelemetryLabelledSuppliedMetric implements LabelledSuppliedMetric { + private final List labelNames; + private final Map observationsMap = new ConcurrentHashMap<>(); + + public OpenTelemetryLabelledSuppliedMetric(final List labelNames) { + this.labelNames = labelNames; + } + + @Override + public void labels(final DoubleSupplier valueSupplier, final String... labelValues) { + Preconditions.checkArgument( + labelValues.length == labelNames.size(), + "label values and label names need the same number of elements"); + final Attributes labels = getLabels(labelValues); + if (observationsMap.putIfAbsent(labels, valueSupplier) != null) { + throw new IllegalStateException( + "Already registered a collector with label values " + Arrays.toString(labelValues)); + } + } + + private Attributes getLabels(final String... labelValues) { + final AttributesBuilder labelsBuilder = Attributes.builder(); + for (int i = 0; i < labelNames.size(); i++) { + labelsBuilder.put(labelNames.get(i), labelValues[i]); + } + return labelsBuilder.build(); + } + + /** + * Callback to record the supplied values + * + * @param measurement where to record the values + */ + protected void updater(final ObservableDoubleMeasurement measurement) { + observationsMap.forEach( + (labels, valueSupplier) -> measurement.record(valueSupplier.getAsDouble(), labels)); + } +} diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySuppliedCounter.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySuppliedCounter.java new file mode 100644 index 0000000000..7bfadcdc2d --- /dev/null +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySuppliedCounter.java @@ -0,0 +1,43 @@ +/* + * Copyright contributors to Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.metrics.opentelemetry; + +import java.util.List; + +import io.opentelemetry.api.metrics.Meter; + +/** The Open telemetry supplied counter. */ +public class OpenTelemetrySuppliedCounter extends OpenTelemetryLabelledSuppliedMetric { + /** + * Instantiates a new Open telemetry supplied counter. + * + * @param metricName the metric name + * @param help the help + * @param meter the meter + * @param labelNames the label names + */ + public OpenTelemetrySuppliedCounter( + final String metricName, + final String help, + final Meter meter, + final List labelNames) { + super(labelNames); + meter + .counterBuilder(metricName) + .setDescription(help) + .ofDoubles() + .buildWithCallback(this::updater); + } +} diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySystem.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySystem.java index a399b28373..cc2174dff5 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySystem.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySystem.java @@ -20,8 +20,9 @@ import org.hyperledger.besu.metrics.Observation; import org.hyperledger.besu.metrics.StandardMetricCategory; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; -import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; +import org.hyperledger.besu.plugin.services.metrics.ExternalSummary; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.OperationTimer; @@ -40,9 +41,11 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.function.DoubleSupplier; +import java.util.function.Supplier; import java.util.stream.Stream; import javax.inject.Singleton; +import com.google.common.cache.Cache; import com.google.common.collect.ImmutableSet; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; @@ -242,6 +245,13 @@ public class OpenTelemetrySystem implements ObservableMetricsSystem { return createLabelledTimer(category, name, help, labelNames); } + @Override + public void trackExternalSummary( + final MetricCategory category, + final String name, + final String help, + final Supplier summarySupplier) {} + @Override public LabelledMetric createLabelledTimer( final MetricCategory category, @@ -278,7 +288,25 @@ public class OpenTelemetrySystem implements ObservableMetricsSystem { } @Override - public LabelledGauge createLabelledGauge( + public void createGuavaCacheCollector( + final MetricCategory category, final String name, final Cache cache) {} + + @Override + public LabelledSuppliedMetric createLabelledSuppliedCounter( + final MetricCategory category, + final String name, + final String help, + final String... labelNames) { + LOG.trace("Creating a labelled supplied counter {}", name); + if (isCategoryEnabled(category)) { + return new OpenTelemetrySuppliedCounter( + name, help, sdkMeterProvider.get(category.getName()), List.of(labelNames)); + } + return NoOpMetricsSystem.getLabelledSuppliedMetric(labelNames.length); + } + + @Override + public LabelledSuppliedMetric createLabelledSuppliedGauge( final MetricCategory category, final String name, final String help, @@ -288,7 +316,7 @@ public class OpenTelemetrySystem implements ObservableMetricsSystem { return new OpenTelemetryGauge( name, help, sdkMeterProvider.get(category.getName()), List.of(labelNames)); } - return NoOpMetricsSystem.getLabelledGauge(labelNames.length); + return NoOpMetricsSystem.getLabelledSuppliedMetric(labelNames.length); } @Override @@ -376,6 +404,7 @@ public class OpenTelemetrySystem implements ObservableMetricsSystem { } /** Shuts down the OpenTelemetry exporters, blocking until they have completed orderly. */ + @Override public void shutdown() { final CompletableResultCode result = CompletableResultCode.ofAll( diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystem.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystem.java index 653f448311..9263383b8f 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystem.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystem.java @@ -18,8 +18,9 @@ import org.hyperledger.besu.metrics.ObservableMetricsSystem; import org.hyperledger.besu.metrics.Observation; import org.hyperledger.besu.metrics.StandardMetricCategory; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; -import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; +import org.hyperledger.besu.plugin.services.metrics.ExternalSummary; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.OperationTimer; @@ -34,6 +35,7 @@ import java.util.function.DoubleSupplier; import java.util.function.Supplier; import java.util.stream.Stream; +import com.google.common.cache.Cache; import com.google.common.collect.ImmutableSet; import io.prometheus.client.Collector; import io.prometheus.client.Collector.MetricFamilySamples; @@ -42,6 +44,7 @@ import io.prometheus.client.CollectorRegistry; import io.prometheus.client.Counter; import io.prometheus.client.Histogram; import io.prometheus.client.Summary; +import io.prometheus.client.guava.cache.CacheMetricsCollector; import io.prometheus.client.hotspot.BufferPoolsExports; import io.prometheus.client.hotspot.ClassLoadingExports; import io.prometheus.client.hotspot.GarbageCollectorExports; @@ -52,6 +55,7 @@ import io.vertx.core.impl.ConcurrentHashSet; /** The Prometheus metrics system. */ public class PrometheusMetricsSystem implements ObservableMetricsSystem { + private static final List EXTERNAL_SUMMARY_LABELS = List.of("quantile"); private final Map> collectors = new ConcurrentHashMap<>(); private final CollectorRegistry registry = new CollectorRegistry(true); @@ -60,6 +64,9 @@ public class PrometheusMetricsSystem implements ObservableMetricsSystem { private final Map> cachedTimers = new ConcurrentHashMap<>(); private final Set totalSuffixedCounters = new ConcurrentHashSet<>(); + private final Map guavaCacheCollectors = + new ConcurrentHashMap<>(); + private final Set guavaCacheNames = new ConcurrentHashSet<>(); private final Set enabledCategories; private final boolean timersEnabled; @@ -78,12 +85,16 @@ public class PrometheusMetricsSystem implements ObservableMetricsSystem { /** Init. */ public void init() { - addCollector(StandardMetricCategory.PROCESS, StandardExports::new); - addCollector(StandardMetricCategory.JVM, MemoryPoolsExports::new); - addCollector(StandardMetricCategory.JVM, BufferPoolsExports::new); - addCollector(StandardMetricCategory.JVM, GarbageCollectorExports::new); - addCollector(StandardMetricCategory.JVM, ThreadExports::new); - addCollector(StandardMetricCategory.JVM, ClassLoadingExports::new); + if (isCategoryEnabled(StandardMetricCategory.PROCESS)) { + registerCollector(StandardMetricCategory.PROCESS, new StandardExports()); + } + if (isCategoryEnabled(StandardMetricCategory.JVM)) { + registerCollector(StandardMetricCategory.JVM, new MemoryPoolsExports()); + registerCollector(StandardMetricCategory.JVM, new BufferPoolsExports()); + registerCollector(StandardMetricCategory.JVM, new GarbageCollectorExports()); + registerCollector(StandardMetricCategory.JVM, new ThreadExports()); + registerCollector(StandardMetricCategory.JVM, new ClassLoadingExports()); + } } @Override @@ -103,7 +114,7 @@ public class PrometheusMetricsSystem implements ObservableMetricsSystem { (k) -> { if (isCategoryEnabled(category)) { final Counter counter = Counter.build(metricName, help).labelNames(labelNames).create(); - addCollectorUnchecked(category, counter); + registerCollector(category, counter); return new PrometheusCounter(counter); } else { return NoOpMetricsSystem.getCounterLabelledMetric(labelNames.length); @@ -132,7 +143,7 @@ public class PrometheusMetricsSystem implements ObservableMetricsSystem { .quantile(1.0, 0) .labelNames(labelNames) .create(); - addCollectorUnchecked(category, summary); + registerCollector(category, summary); return new PrometheusTimer(summary); } else { return NoOpMetricsSystem.getOperationTimerLabelledMetric(labelNames.length); @@ -153,7 +164,7 @@ public class PrometheusMetricsSystem implements ObservableMetricsSystem { if (timersEnabled && isCategoryEnabled(category)) { final Histogram histogram = Histogram.build(metricName, help).labelNames(labelNames).buckets(1D).create(); - addCollectorUnchecked(category, histogram); + registerCollector(category, histogram); return new PrometheusSimpleTimer(histogram); } else { return NoOpMetricsSystem.getOperationTimerLabelledMetric(labelNames.length); @@ -170,59 +181,119 @@ public class PrometheusMetricsSystem implements ObservableMetricsSystem { final String metricName = convertToPrometheusName(category, name); if (isCategoryEnabled(category)) { final Collector collector = new CurrentValueCollector(metricName, help, valueSupplier); - addCollectorUnchecked(category, collector); + registerCollector(category, collector); } } @Override - public LabelledGauge createLabelledGauge( + public void trackExternalSummary( final MetricCategory category, final String name, final String help, - final String... labelNames) { - final String metricName = convertToPrometheusName(category, name); + final Supplier summarySupplier) { if (isCategoryEnabled(category)) { - final PrometheusGauge gauge = new PrometheusGauge(metricName, help, List.of(labelNames)); - addCollectorUnchecked(category, gauge); - return gauge; + final var externalSummaryCollector = + new Collector() { + @Override + public List collect() { + final var externalSummary = summarySupplier.get(); + + final var quantileValues = + externalSummary.quantiles().stream() + .map( + quantile -> + new Sample( + name, + EXTERNAL_SUMMARY_LABELS, + List.of(Double.toString(quantile.quantile())), + quantile.value())) + .toList(); + + return List.of( + new MetricFamilySamples( + name, Type.SUMMARY, "RocksDB histogram for " + name, quantileValues)); + } + }; + + registerCollector(category, externalSummaryCollector); } - return NoOpMetricsSystem.getLabelledGauge(labelNames.length); } - /** - * Add collector. - * - * @param category the category - * @param metricSupplier the metric supplier - */ - public void addCollector( - final MetricCategory category, final Supplier metricSupplier) { + @Override + public void createGuavaCacheCollector( + final MetricCategory category, final String name, final Cache cache) { + if (isCategoryEnabled(category)) { + if (guavaCacheNames.contains(name)) { + throw new IllegalStateException("Cache already registered: " + name); + } + guavaCacheNames.add(name); + final var guavaCacheCollector = + guavaCacheCollectors.computeIfAbsent( + category, + unused -> { + final var cmc = new CacheMetricsCollector(); + registerCollector(category, cmc); + return cmc; + }); + guavaCacheCollector.addCache(name, cache); + } + } + + @Override + public LabelledSuppliedMetric createLabelledSuppliedCounter( + final MetricCategory category, + final String name, + final String help, + final String... labelNames) { + return createLabelledSuppliedMetric(category, Collector.Type.COUNTER, name, help, labelNames); + } + + @Override + public LabelledSuppliedMetric createLabelledSuppliedGauge( + final MetricCategory category, + final String name, + final String help, + final String... labelNames) { + return createLabelledSuppliedMetric(category, Collector.Type.GAUGE, name, help, labelNames); + } + + private LabelledSuppliedMetric createLabelledSuppliedMetric( + final MetricCategory category, + final Collector.Type type, + final String name, + final String help, + final String... labelNames) { + final String metricName = convertToPrometheusName(category, name); if (isCategoryEnabled(category)) { - addCollectorUnchecked(category, metricSupplier.get()); + final PrometheusSuppliedValueCollector suppliedValueCollector = + new PrometheusSuppliedValueCollector(type, metricName, help, List.of(labelNames)); + registerCollector(category, suppliedValueCollector); + return suppliedValueCollector; } + return NoOpMetricsSystem.getLabelledSuppliedMetric(labelNames.length); } - private void addCollectorUnchecked(final MetricCategory category, final Collector metric) { - final Collection metrics = + private void registerCollector(final MetricCategory category, final Collector collector) { + final Collection categoryCollectors = this.collectors.computeIfAbsent( category, key -> Collections.newSetFromMap(new ConcurrentHashMap<>())); final List newSamples = - metric.collect().stream().map(metricFamilySamples -> metricFamilySamples.name).toList(); + collector.collect().stream().map(metricFamilySamples -> metricFamilySamples.name).toList(); - metrics.stream() + categoryCollectors.stream() .filter( - collector -> - collector.collect().stream() + c -> + c.collect().stream() .anyMatch(metricFamilySamples -> newSamples.contains(metricFamilySamples.name))) .findFirst() .ifPresent( - collector -> { - metrics.remove(collector); - registry.unregister(collector); + c -> { + categoryCollectors.remove(c); + registry.unregister(c); }); - metrics.add(metric.register(registry)); + categoryCollectors.add(collector.register(registry)); } @Override @@ -237,6 +308,16 @@ public class PrometheusMetricsSystem implements ObservableMetricsSystem { return collectors.keySet().stream().flatMap(this::streamObservations); } + @Override + public void shutdown() { + registry.clear(); + collectors.clear(); + cachedCounters.clear(); + cachedTimers.clear(); + guavaCacheCollectors.clear(); + guavaCacheNames.clear(); + } + private Stream convertSamplesToObservations( final MetricCategory category, final MetricFamilySamples familySamples) { return familySamples.samples.stream() diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusGauge.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusSuppliedValueCollector.java similarity index 76% rename from metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusGauge.java rename to metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusSuppliedValueCollector.java index b69e3f9062..47394ffed4 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusGauge.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusSuppliedValueCollector.java @@ -1,5 +1,5 @@ /* - * Copyright ConsenSys AG. + * Copyright contributors to Besu. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -15,6 +15,7 @@ package org.hyperledger.besu.metrics.prometheus; import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; import java.util.ArrayList; import java.util.List; @@ -24,22 +25,27 @@ import java.util.function.DoubleSupplier; import io.prometheus.client.Collector; -/** The Prometheus gauge. */ -public class PrometheusGauge extends Collector implements LabelledGauge { +/** The Prometheus supplied value collector. */ +@SuppressWarnings("removal") // remove when deprecated LabelledGauge is removed +public class PrometheusSuppliedValueCollector extends Collector + implements LabelledSuppliedMetric, LabelledGauge { + private final Type type; private final String metricName; private final String help; private final List labelNames; private final Map, DoubleSupplier> observationsMap = new ConcurrentHashMap<>(); /** - * Instantiates a new Prometheus gauge. + * Instantiates a new Prometheus supplied value collector. * + * @param type the type of the collector * @param metricName the metric name * @param help the help * @param labelNames the label names */ - public PrometheusGauge( - final String metricName, final String help, final List labelNames) { + public PrometheusSuppliedValueCollector( + final Type type, final String metricName, final String help, final List labelNames) { + this.type = type; this.metricName = metricName; this.help = help; this.labelNames = labelNames; @@ -55,12 +61,6 @@ public class PrometheusGauge extends Collector implements LabelledGauge { } } - @Override - public boolean isLabelsObserved(final String... labelValues) { - validateLabelsCardinality(labelValues); - return observationsMap.containsKey(List.of(labelValues)); - } - @Override public List collect() { final List samples = new ArrayList<>(); @@ -69,7 +69,7 @@ public class PrometheusGauge extends Collector implements LabelledGauge { samples.add( new MetricFamilySamples.Sample( metricName, labelNames, labels, valueSupplier.getAsDouble()))); - return List.of(new MetricFamilySamples(metricName, Type.GAUGE, help, samples)); + return List.of(new MetricFamilySamples(metricName, type, help, samples)); } private void validateLabelsCardinality(final String... labelValues) { diff --git a/metrics/core/src/test-support/java/org/hyperledger/besu/metrics/StubMetricsSystem.java b/metrics/core/src/test-support/java/org/hyperledger/besu/metrics/StubMetricsSystem.java index 2e0ea006db..c10c62132c 100644 --- a/metrics/core/src/test-support/java/org/hyperledger/besu/metrics/StubMetricsSystem.java +++ b/metrics/core/src/test-support/java/org/hyperledger/besu/metrics/StubMetricsSystem.java @@ -18,8 +18,9 @@ import static java.util.Arrays.asList; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; -import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; +import org.hyperledger.besu.plugin.services.metrics.ExternalSummary; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.OperationTimer; @@ -29,8 +30,11 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.DoubleSupplier; +import java.util.function.Supplier; import java.util.stream.Stream; +import com.google.common.cache.Cache; + public class StubMetricsSystem implements ObservableMetricsSystem { private final Map counters = new HashMap<>(); @@ -46,12 +50,21 @@ public class StubMetricsSystem implements ObservableMetricsSystem { } @Override - public LabelledGauge createLabelledGauge( + public LabelledSuppliedMetric createLabelledSuppliedCounter( final MetricCategory category, final String name, final String help, final String... labelNames) { - return NoOpMetricsSystem.getLabelledGauge(labelNames.length); + return NoOpMetricsSystem.getLabelledSuppliedMetric(labelNames.length); + } + + @Override + public LabelledSuppliedMetric createLabelledSuppliedGauge( + final MetricCategory category, + final String name, + final String help, + final String... labelNames) { + return NoOpMetricsSystem.getLabelledSuppliedMetric(labelNames.length); } public long getCounterValue(final String name, final String... labels) { @@ -84,6 +97,13 @@ public class StubMetricsSystem implements ObservableMetricsSystem { return labelValues -> NoOpMetricsSystem.NO_OP_OPERATION_TIMER; } + @Override + public void trackExternalSummary( + final MetricCategory category, + final String name, + final String help, + final Supplier summarySupplier) {} + @Override public void createGauge( final MetricCategory category, @@ -93,6 +113,10 @@ public class StubMetricsSystem implements ObservableMetricsSystem { gauges.put(name, valueSupplier); } + @Override + public void createGuavaCacheCollector( + final MetricCategory category, final String name, final Cache cache) {} + public double getGaugeValue(final String name) { final DoubleSupplier gauge = gauges.get(name); if (gauge == null) { @@ -116,6 +140,12 @@ public class StubMetricsSystem implements ObservableMetricsSystem { return Collections.emptySet(); } + @Override + public void shutdown() { + counters.clear(); + gauges.clear(); + } + public static class StubLabelledCounter implements LabelledMetric { private final Map, StubCounter> metrics = new HashMap<>(); diff --git a/metrics/core/src/test/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImplTest.java b/metrics/core/src/test/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImplTest.java new file mode 100644 index 0000000000..b2da02f480 --- /dev/null +++ b/metrics/core/src/test/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImplTest.java @@ -0,0 +1,66 @@ +/* + * Copyright contributors to Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.metrics; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; + +import java.util.Set; + +import org.junit.jupiter.api.Test; + +class MetricCategoryRegistryImplTest { + + @Test + void metricCategoryIsEnabledAndMetricsAreEnabled() { + final var registry = new MetricCategoryRegistryImpl(); + registry.addMetricCategory(BesuMetricCategory.BLOCKCHAIN); + final var metricsConfiguration = + MetricsConfiguration.builder() + .enabled(true) + .metricCategories(Set.of(BesuMetricCategory.BLOCKCHAIN)) + .build(); + registry.setMetricsConfiguration(metricsConfiguration); + assertTrue(registry.isMetricCategoryEnabled(BesuMetricCategory.BLOCKCHAIN)); + } + + @Test + void metricCategoryIsDisabledAndMetricsAreEnabled() { + final var registry = new MetricCategoryRegistryImpl(); + registry.addMetricCategory(BesuMetricCategory.ETHEREUM); + final var metricsConfiguration = + MetricsConfiguration.builder() + .enabled(true) + .metricCategories(Set.of(BesuMetricCategory.ETHEREUM)) + .build(); + registry.setMetricsConfiguration(metricsConfiguration); + assertFalse(registry.isMetricCategoryEnabled(BesuMetricCategory.BLOCKCHAIN)); + } + + @Test + void metricCategoryNotEnabledWhenMetricsAreDisabled() { + final var registry = new MetricCategoryRegistryImpl(); + registry.addMetricCategory(BesuMetricCategory.BLOCKCHAIN); + final var metricsConfiguration = + MetricsConfiguration.builder() + .enabled(false) + .metricCategories(Set.of(BesuMetricCategory.BLOCKCHAIN)) + .build(); + registry.setMetricsConfiguration(metricsConfiguration); + assertFalse(registry.isMetricCategoryEnabled(BesuMetricCategory.BLOCKCHAIN)); + } +} diff --git a/metrics/core/src/test/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryMetricsSystemTest.java b/metrics/core/src/test/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryMetricsSystemTest.java index f1bff33e55..8c6dd8261d 100644 --- a/metrics/core/src/test/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryMetricsSystemTest.java +++ b/metrics/core/src/test/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryMetricsSystemTest.java @@ -31,8 +31,8 @@ import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; -import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; import org.hyperledger.besu.plugin.services.metrics.OperationTimer; import java.util.Collections; @@ -231,8 +231,8 @@ public class OpenTelemetryMetricsSystemTest { @Test public void shouldCreateLabelledGauge() { - LabelledGauge labelledGauge = - metricsSystem.createLabelledGauge(RPC, "gaugeName", "help", "a", "b"); + LabelledSuppliedMetric labelledGauge = + metricsSystem.createLabelledSuppliedGauge(RPC, "gaugeName", "help", "a", "b"); labelledGauge.labels(() -> 1.0, "a1", "b1"); labelledGauge.labels(() -> 11.0, "a2", "b2"); labelledGauge.labels(() -> 21.0, "a3", "b3"); diff --git a/metrics/core/src/test/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystemTest.java b/metrics/core/src/test/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystemTest.java index 2ddf86d347..ba875ab79b 100644 --- a/metrics/core/src/test/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystemTest.java +++ b/metrics/core/src/test/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystemTest.java @@ -33,8 +33,8 @@ import org.hyperledger.besu.metrics.Observation; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; -import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; import org.hyperledger.besu.plugin.services.metrics.OperationTimer; import java.util.Collections; @@ -129,8 +129,8 @@ public class PrometheusMetricsSystemTest { @Test public void shouldCreateSeparateObservationsForEachLabelledGaugeValue() { - final LabelledGauge gauge = - metricsSystem.createLabelledGauge(PEERS, "test", "test help", "a", "b", "c"); + final LabelledSuppliedMetric gauge = + metricsSystem.createLabelledSuppliedGauge(PEERS, "test", "test help", "a", "b", "c"); final double value1 = 1.0; final double value2 = 11.0; @@ -145,8 +145,8 @@ public class PrometheusMetricsSystemTest { @Test public void shouldNotUseSameLabelsTwiceOnSameGauge() { - final LabelledGauge gauge = - metricsSystem.createLabelledGauge(PEERS, "test", "test help", "a", "b", "c"); + final LabelledSuppliedMetric gauge = + metricsSystem.createLabelledSuppliedGauge(PEERS, "test", "test help", "a", "b", "c"); final double value1 = 1.0; gauge.labels(() -> value1, "a1", "b1", "c1"); diff --git a/metrics/rocksdb/build.gradle b/metrics/rocksdb/build.gradle index d46488daf8..de312ab708 100644 --- a/metrics/rocksdb/build.gradle +++ b/metrics/rocksdb/build.gradle @@ -40,7 +40,5 @@ dependencies { implementation project(':metrics:core') implementation project(':plugin-api') - implementation 'com.google.guava:guava' - implementation 'io.prometheus:simpleclient' implementation 'org.rocksdb:rocksdbjni' } diff --git a/metrics/rocksdb/src/main/java/org/hyperledger/besu/metrics/rocksdb/RocksDBStats.java b/metrics/rocksdb/src/main/java/org/hyperledger/besu/metrics/rocksdb/RocksDBStats.java index edb837985d..3af876945d 100644 --- a/metrics/rocksdb/src/main/java/org/hyperledger/besu/metrics/rocksdb/RocksDBStats.java +++ b/metrics/rocksdb/src/main/java/org/hyperledger/besu/metrics/rocksdb/RocksDBStats.java @@ -16,15 +16,14 @@ package org.hyperledger.besu.metrics.rocksdb; import static org.hyperledger.besu.metrics.BesuMetricCategory.KVSTORE_ROCKSDB_STATS; -import org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem; +import org.hyperledger.besu.plugin.services.MetricsSystem; +import org.hyperledger.besu.plugin.services.metrics.ExternalSummary; +import org.hyperledger.besu.plugin.services.metrics.ExternalSummary.Quantile; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Locale; -import io.prometheus.client.Collector; import org.rocksdb.HistogramData; import org.rocksdb.HistogramType; import org.rocksdb.Statistics; @@ -32,22 +31,9 @@ import org.rocksdb.TickerType; /** The Rocks db stats. */ public class RocksDBStats { - - /** The Labels. */ - static final List LABELS = Collections.singletonList("quantile"); - - /** The Label 50. */ - static final List LABEL_50 = Collections.singletonList("0.5"); - - /** The Label 95. */ - static final List LABEL_95 = Collections.singletonList("0.95"); - - /** The Label 99. */ - static final List LABEL_99 = Collections.singletonList("0.99"); - - /** The constant TICKERS. */ + /** The constant TICKER_TYPES. */ // Tickers - RocksDB equivalent of counters - static final TickerType[] TICKERS = { + static final TickerType[] TICKER_TYPES = { TickerType.BLOCK_CACHE_ADD, TickerType.BLOCK_CACHE_HIT, TickerType.BLOCK_CACHE_ADD_FAILURES, @@ -121,7 +107,6 @@ public class RocksDBStats { TickerType.NUMBER_SUPERVERSION_CLEANUPS, TickerType.NUMBER_BLOCK_COMPRESSED, TickerType.NUMBER_BLOCK_DECOMPRESSED, - TickerType.NUMBER_BLOCK_NOT_COMPRESSED, TickerType.MERGE_OPERATION_TOTAL_TIME, TickerType.FILTER_OPERATION_TOTAL_TIME, TickerType.ROW_CACHE_HIT, @@ -133,9 +118,9 @@ public class RocksDBStats { TickerType.NUMBER_MULTIGET_KEYS_FOUND, }; - /** The constant HISTOGRAMS. */ + /** The constant HISTOGRAM_TYPES. */ // Histograms - treated as prometheus summaries - static final HistogramType[] HISTOGRAMS = { + static final HistogramType[] HISTOGRAM_TYPES = { HistogramType.DB_GET, HistogramType.DB_WRITE, HistogramType.COMPACTION_TIME, @@ -157,8 +142,6 @@ public class RocksDBStats { HistogramType.BYTES_PER_READ, HistogramType.BYTES_PER_WRITE, HistogramType.BYTES_PER_MULTIGET, - HistogramType.BYTES_COMPRESSED, - HistogramType.BYTES_DECOMPRESSED, HistogramType.COMPRESSION_TIMES_NANOS, HistogramType.DECOMPRESSION_TIMES_NANOS, HistogramType.READ_NUM_MERGE_OPERANDS, @@ -175,47 +158,40 @@ public class RocksDBStats { * @param category the category */ public static void registerRocksDBMetrics( - final Statistics stats, - final PrometheusMetricsSystem metricsSystem, - final MetricCategory category) { - if (!metricsSystem.isCategoryEnabled(category)) { - return; - } - for (final TickerType ticker : TICKERS) { - final String promCounterName = ticker.name().toLowerCase(Locale.ROOT); + final Statistics stats, final MetricsSystem metricsSystem, final MetricCategory category) { + + for (final var tickerType : TICKER_TYPES) { + final String promCounterName = tickerType.name().toLowerCase(Locale.ROOT); metricsSystem.createLongGauge( category, promCounterName, - "RocksDB reported statistics for " + ticker.name(), - () -> stats.getTickerCount(ticker)); + "RocksDB reported statistics for " + tickerType.name(), + () -> stats.getTickerCount(tickerType)); } - for (final HistogramType histogram : HISTOGRAMS) { - metricsSystem.addCollector(category, () -> histogramToCollector(stats, histogram)); + for (final var histogramType : HISTOGRAM_TYPES) { + + metricsSystem.trackExternalSummary( + KVSTORE_ROCKSDB_STATS, + KVSTORE_ROCKSDB_STATS.getName() + "_" + histogramType.name().toLowerCase(Locale.ROOT), + "RocksDB histogram for " + histogramType.name(), + () -> provideExternalSummary(stats, histogramType)); } } - private static Collector histogramToCollector( - final Statistics stats, final HistogramType histogram) { - return new Collector() { - final String metricName = - KVSTORE_ROCKSDB_STATS.getName() + "_" + histogram.name().toLowerCase(Locale.ROOT); + private static ExternalSummary provideExternalSummary( + final Statistics stats, final HistogramType histogramType) { + + final HistogramData data = stats.getHistogramData(histogramType); - @Override - public List collect() { - final HistogramData data = stats.getHistogramData(histogram); - return Collections.singletonList( - new MetricFamilySamples( - metricName, - Type.SUMMARY, - "RocksDB histogram for " + metricName, - Arrays.asList( - new MetricFamilySamples.Sample(metricName, LABELS, LABEL_50, data.getMedian()), - new MetricFamilySamples.Sample( - metricName, LABELS, LABEL_95, data.getPercentile95()), - new MetricFamilySamples.Sample( - metricName, LABELS, LABEL_99, data.getPercentile99())))); - } - }; + return new ExternalSummary( + data.getCount(), + data.getSum(), + List.of( + new Quantile(0.0, data.getMin()), + new Quantile(0.5, data.getMedian()), + new Quantile(0.95, data.getPercentile95()), + new Quantile(0.99, data.getPercentile99()), + new Quantile(1.0, data.getMax()))); } } diff --git a/platform/build.gradle b/platform/build.gradle index 581b6e4771..f396eb2a06 100644 --- a/platform/build.gradle +++ b/platform/build.gradle @@ -28,7 +28,7 @@ javaPlatform { dependencies { api platform('com.fasterxml.jackson:jackson-bom:2.18.0') api platform('io.grpc:grpc-bom:1.68.0') - api platform('io.netty:netty-bom:4.1.114.Final') + api platform('io.netty:netty-bom:4.1.115.Final') api platform('io.opentelemetry:opentelemetry-bom:1.43.0') api platform('io.prometheus:simpleclient_bom:0.16.0') api platform('io.vertx:vertx-stack-depchain:4.5.10') @@ -43,8 +43,14 @@ dependencies { api project(':acceptance-tests:dsl') api project(':besu') api project(':config') + api project(':consensus:clique') + api project(':consensus:common') + api project(':consensus:ibft') + api project(':consensus:merge') + api project(':consensus:qbft') api project(':crypto:algorithms') api project(':crypto:services') + api project(':datatypes') api project(':ethereum:api') api project(':ethereum:blockcreation') api project(':ethereum:core') @@ -53,9 +59,12 @@ dependencies { api project(':ethereum:permissioning') api project(':ethereum:referencetests') api project(':ethereum:rlp') + api project(':ethereum:trie') api project(':evm') - api project(':datatypes') + api project(':metrics:core') api project(':plugin-api') + api project(':testutil') + api project(':util') api 'com.github.ben-manes.caffeine:caffeine:3.1.8' @@ -154,7 +163,7 @@ dependencies { api 'org.owasp.encoder:encoder:1.3.1' - api 'org.rocksdb:rocksdbjni:8.3.2' + api 'org.rocksdb:rocksdbjni:9.7.3' api 'org.springframework.security:spring-security-crypto:6.3.3' diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index c58e74d9fd..b4cc9ce71e 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -71,7 +71,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'cvmMMf7nUP2AFMnV65lPH/YXnaBJ9vqL2V0Do7GWMCI=' + knownHash = '3DEeEv1YPoZvRCrmkUygP1tuXZ5YKnY0mIRFNhHPUoc=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/BesuContext.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/BesuContext.java index 71b3612e51..2f1d0e9ac3 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/BesuContext.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/BesuContext.java @@ -14,42 +14,6 @@ */ package org.hyperledger.besu.plugin; -import org.hyperledger.besu.plugin.services.BesuService; - -import java.util.Optional; - -/** Allows plugins to access Besu services. */ -public interface BesuContext { - - /** - * Add service. - * - * @param the type parameter - * @param serviceType the service type - * @param service the service - */ - void addService(final Class serviceType, final T service); - - /** - * Get the requested service, if it is available. There are a number of reasons that a service may - * not be available: - * - *
    - *
  • The service may not have started yet. Most services are not available before the {@link - * BesuPlugin#start()} method is called - *
  • The service is not supported by this version of Besu - *
  • The service may not be applicable to the current configuration. For example some services - * may only be available when a proof of authority network is in use - *
- * - *

Since plugins are automatically loaded, unless the user has specifically requested - * functionality provided by the plugin, no error should be raised if required services are - * unavailable. - * - * @param serviceType the class defining the requested service. - * @param the service type - * @return an optional containing the instance of the requested service, or empty if the service - * is unavailable - */ - Optional getService(Class serviceType); -} +/** Deprecated in favor of the more precisely named ServiceManager interface. */ +@Deprecated(since = "24.11.0", forRemoval = true) +public interface BesuContext extends ServiceManager {} diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/BesuPlugin.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/BesuPlugin.java index 1d7acf3a3e..b05fbf83c0 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/BesuPlugin.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/BesuPlugin.java @@ -48,7 +48,7 @@ public interface BesuPlugin { * * @param context the context that provides access to Besu services. */ - void register(BesuContext context); + void register(ServiceManager context); /** * Called once when besu has loaded configuration but before external services have been started diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/ServiceManager.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/ServiceManager.java new file mode 100644 index 0000000000..99630f2739 --- /dev/null +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/ServiceManager.java @@ -0,0 +1,55 @@ +/* + * 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.plugin; + +import org.hyperledger.besu.plugin.services.BesuService; + +import java.util.Optional; + +/** Adds and accesses BesuServices for plugins to provide or use. */ +public interface ServiceManager { + + /** + * Add service. Used by core besu or other plugins to add services to the service manager. + * + * @param the type parameter + * @param serviceType the service type + * @param service the service + */ + void addService(final Class serviceType, final T service); + + /** + * Get the requested service, if it is available. There are a number of reasons that a service may + * not be available: + * + *

    + *
  • The service may not have started yet. Most services are not available before the {@link + * BesuPlugin#start()} method is called + *
  • The service is not supported by this version of Besu + *
  • The service may not be applicable to the current configuration. For example some services + * may only be available when a proof of authority network is in use, or when user provided. + *
+ * + *

Since plugins are automatically loaded, unless the user has specifically requested + * functionality provided by the plugin, no error should be raised if required services are + * unavailable. + * + * @param serviceType the class defining the requested service. + * @param the service type + * @return an optional containing the instance of the requested service, or empty if the service + * is unavailable + */ + Optional getService(Class serviceType); +} diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BesuService.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BesuService.java index 62340dd59d..bb9c5e1cda 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BesuService.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BesuService.java @@ -14,10 +14,10 @@ */ package org.hyperledger.besu.plugin.services; -import org.hyperledger.besu.plugin.BesuContext; +import org.hyperledger.besu.plugin.ServiceManager; /** - * All services that can be resolved via {@link BesuContext#getService(Class)} must implement {@link - * BesuService} + * All services that can be resolved via {@link ServiceManager#getService(Class)} must implement + * {@link BesuService} */ public interface BesuService {} diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/MetricsSystem.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/MetricsSystem.java index 80e02a6dba..f3d3f91d0a 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/MetricsSystem.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/MetricsSystem.java @@ -15,14 +15,20 @@ package org.hyperledger.besu.plugin.services; import org.hyperledger.besu.plugin.services.metrics.Counter; +import org.hyperledger.besu.plugin.services.metrics.ExternalSummary; import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.OperationTimer; +import java.util.Set; import java.util.function.DoubleSupplier; import java.util.function.IntSupplier; import java.util.function.LongSupplier; +import java.util.function.Supplier; + +import com.google.common.cache.Cache; /** An interface for creating various Metrics components. */ public interface MetricsSystem extends BesuService { @@ -40,6 +46,23 @@ public interface MetricsSystem extends BesuService { return createLabelledCounter(category, name, help, new String[0]).labels(); } + /** + * Creates a Counter that gets its value from the specified supplier. To be used when the value of + * the counter is calculated outside the metric system. + * + * @param category The {@link MetricCategory} this counter is assigned to. + * @param name A name for this metric. + * @param help A human readable description of the metric. + * @param valueSupplier The supplier of the value. + */ + default void createCounter( + final MetricCategory category, + final String name, + final String help, + final DoubleSupplier valueSupplier) { + createLabelledSuppliedCounter(category, name, help).labels(valueSupplier); + } + /** * Creates a Counter with assigned labels. * @@ -53,7 +76,42 @@ public interface MetricsSystem extends BesuService { MetricCategory category, String name, String help, String... labelNames); /** - * Creates a Gauge with assigned labels. + * Creates a Counter with assigned labels, that gets its values from suppliers. To be used when + * the values of the counter are calculated outside the metric system. + * + * @param category The {@link MetricCategory} this counter is assigned to. + * @param name A name for this metric. + * @param help A human readable description of the metric. + * @param labelNames An array of labels to assign to the Counter. + * @return The created LabelledSupplierMetric instance. + */ + LabelledSuppliedMetric createLabelledSuppliedCounter( + MetricCategory category, String name, String help, String... labelNames); + + /** + * Creates a Gauge with assigned labels, that gets its values from suppliers. To be used when the + * values of the gauge are calculated outside the metric system. + * + * @param category The {@link MetricCategory} this gauge is assigned to. + * @param name A name for this metric. + * @param help A human readable description of the metric. + * @param labelNames An array of labels to assign to the Gauge. + * @return The created LabelledGauge instance. + * @deprecated Use {@link #createLabelledSuppliedGauge(MetricCategory, String, String, String...)} + */ + @Deprecated(forRemoval = true) + @SuppressWarnings("removal") // remove when deprecated LabelledGauge is removed + default LabelledGauge createLabelledGauge( + final MetricCategory category, + final String name, + final String help, + final String... labelNames) { + return (LabelledGauge) createLabelledSuppliedGauge(category, name, help, labelNames); + } + + /** + * Creates a Gauge with assigned labels, that gets its values from suppliers. To be used when the + * values of the gauge are calculated outside the metric system. * * @param category The {@link MetricCategory} this gauge is assigned to. * @param name A name for this metric. @@ -61,7 +119,7 @@ public interface MetricsSystem extends BesuService { * @param labelNames An array of labels to assign to the Gauge. * @return The created LabelledGauge instance. */ - LabelledGauge createLabelledGauge( + LabelledSuppliedMetric createLabelledSuppliedGauge( MetricCategory category, String name, String help, String... labelNames); /** @@ -159,4 +217,45 @@ public interface MetricsSystem extends BesuService { final LongSupplier valueSupplier) { createGauge(category, name, help, () -> (double) valueSupplier.getAsLong()); } + + /** + * Track a summary that is computed externally to this metric system. Useful when existing + * libraries calculate the summary data on their own, and we want to export that summary via the + * configured metric system. A notable example are RocksDB statistics. + * + * @param category The {@link MetricCategory} this external summary is assigned to. + * @param name A name for the metric. + * @param help A human readable description of the metric. + * @param summarySupplier A supplier to retrieve the summary data when needed. + */ + void trackExternalSummary( + MetricCategory category, String name, String help, Supplier summarySupplier); + + /** + * Collect metrics from Guava cache. + * + * @param category The {@link MetricCategory} this Guava cache is assigned to. + * @param name the name to identify this Guava cache, must be unique. + * @param cache the Guava cache + */ + void createGuavaCacheCollector(MetricCategory category, String name, Cache cache); + + /** + * Provides an immutable view into the metric categories enabled for metric collection. + * + * @return the set of enabled metric categories. + */ + Set getEnabledCategories(); + + /** + * Checks if a particular category of metrics is enabled. + * + * @param category the category to check + * @return true if the category is enabled, false otherwise + */ + default boolean isCategoryEnabled(final MetricCategory category) { + return getEnabledCategories().stream() + .map(MetricCategory::getName) + .anyMatch(category.getName()::equals); + } } diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PrivacyPluginService.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PrivacyPluginService.java index 7652e3ade9..52c43cb6b4 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PrivacyPluginService.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PrivacyPluginService.java @@ -26,6 +26,7 @@ import org.hyperledger.besu.plugin.services.privacy.PrivateMarkerTransactionFact * optionally register a {@link PrivateMarkerTransactionFactory} and a {@link * PrivacyGroupGenesisProvider}* */ +@Deprecated(since = "24.11.0") public interface PrivacyPluginService extends BesuService { /** diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/TransactionSimulationService.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/TransactionSimulationService.java index dffdb0cfe5..d5fc0a3497 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/TransactionSimulationService.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/TransactionSimulationService.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.plugin.services; +import org.hyperledger.besu.datatypes.AccountOverrideMap; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.tracing.OperationTracer; @@ -39,4 +40,21 @@ public interface TransactionSimulationService extends BesuService { Hash blockHash, OperationTracer operationTracer, boolean isAllowExceedingBalance); + + /** + * Simulate transaction execution at the block identified by the hash + * + * @param transaction tx + * @param accountOverrides state overrides to apply to this simulation + * @param blockHash the hash of the block + * @param operationTracer the tracer + * @param isAllowExceedingBalance should ignore the sender balance during the simulation? + * @return the result of the simulation + */ + Optional simulate( + Transaction transaction, + Optional accountOverrides, + Hash blockHash, + OperationTracer operationTracer, + boolean isAllowExceedingBalance); } diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/ExternalSummary.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/ExternalSummary.java new file mode 100644 index 0000000000..5e7e38b76a --- /dev/null +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/ExternalSummary.java @@ -0,0 +1,36 @@ +/* + * Copyright contributors to Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.plugin.services.metrics; + +import java.util.List; + +/** + * Record of summary data the is kept outside the metric system. Useful when existing libraries + * calculate the summary data on their own, and we want to export that summary via the configured + * metric system. A notable example are RocksDB statistics. + * + * @param count the number of observations + * @param sum the sum of all the observations + * @param quantiles a list of quantiles with values + */ +public record ExternalSummary(long count, double sum, List quantiles) { + /** + * Represent a single quantile and its value + * + * @param quantile the quantile + * @param value the value + */ + public record Quantile(double quantile, double value) {} +} diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/LabelledGauge.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/LabelledGauge.java index 5357c6505a..f94e523184 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/LabelledGauge.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/LabelledGauge.java @@ -14,26 +14,10 @@ */ package org.hyperledger.besu.plugin.services.metrics; -import java.util.function.DoubleSupplier; - -/** The interface Labelled gauge. */ -public interface LabelledGauge { - /** - * Labels. - * - * @param valueSupplier the value supplier - * @param labelValues the label values - */ - void labels(final DoubleSupplier valueSupplier, final String... labelValues); - - /** - * Checks whether the supplied labelValues are already observed by this LabelledGauge - * - * @param labelValues The labelValues to check - * @return true if the supplied labelValues are already observed by this LabelledGauge, false - * otherwise - */ - default boolean isLabelsObserved(final String... labelValues) { - return false; - } -} +/** + * The interface Labelled gauge. + * + * @deprecated Use {@link LabelledSuppliedMetric} + */ +@Deprecated(forRemoval = true) +public interface LabelledGauge extends LabelledSuppliedMetric {} diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/LabelledSuppliedMetric.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/LabelledSuppliedMetric.java new file mode 100644 index 0000000000..755bd6787e --- /dev/null +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/LabelledSuppliedMetric.java @@ -0,0 +1,28 @@ +/* + * Copyright contributors to Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.plugin.services.metrics; + +import java.util.function.DoubleSupplier; + +/** The interface Labelled gauge. */ +public interface LabelledSuppliedMetric { + /** + * Labels. + * + * @param valueSupplier the value supplier + * @param labelValues the label values + */ + void labels(final DoubleSupplier valueSupplier, final String... labelValues); +} diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/MetricCategoryRegistry.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/MetricCategoryRegistry.java index d6e460aa2f..1f84953460 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/MetricCategoryRegistry.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/MetricCategoryRegistry.java @@ -29,5 +29,13 @@ public interface MetricCategoryRegistry extends BesuService { * * @param newMetricCategory The {@link MetricCategory} that is being registered. */ - public void addMetricCategory(final MetricCategory newMetricCategory); + void addMetricCategory(final MetricCategory newMetricCategory); + + /** + * Return true if the metrics are enabled and the metric category is enabled + * + * @param metricCategory the metric category + * @return true if the metrics are enabled and the metric category is enabled + */ + boolean isMetricCategoryEnabled(final MetricCategory metricCategory); } diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/mining/MiningService.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/mining/MiningService.java new file mode 100644 index 0000000000..396d011cb0 --- /dev/null +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/mining/MiningService.java @@ -0,0 +1,27 @@ +/* + * Copyright contributors to Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.plugin.services.mining; + +import org.hyperledger.besu.plugin.services.BesuService; + +/** The MiningService interface provides methods to start and stop the mining process. */ +public interface MiningService extends BesuService { + + /** Starts the mining process. */ + void start(); + + /** Stops the mining process. */ + void stop(); +} diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/privacy/PrivacyPluginPayloadProvider.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/privacy/PrivacyPluginPayloadProvider.java index 6604cba8b5..babbf8fd72 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/privacy/PrivacyPluginPayloadProvider.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/privacy/PrivacyPluginPayloadProvider.java @@ -25,6 +25,7 @@ import org.apache.tuweni.bytes.Bytes; * Allows you to register a provider that will dictate how the payload of a privacy marker * transaction is handled. */ +@Deprecated(since = "24.11.0") public interface PrivacyPluginPayloadProvider { /** diff --git a/plugins/rocksdb/build.gradle b/plugins/rocksdb/build.gradle index d487cf9824..a2315398e1 100644 --- a/plugins/rocksdb/build.gradle +++ b/plugins/rocksdb/build.gradle @@ -46,7 +46,6 @@ dependencies { implementation 'com.google.guava:guava' implementation 'info.picocli:picocli' implementation 'io.opentelemetry:opentelemetry-api' - implementation 'io.prometheus:simpleclient' implementation 'io.tmio:tuweni-bytes' implementation 'org.rocksdb:rocksdbjni' implementation project(path: ':ethereum:core') diff --git a/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBMetricsFactory.java b/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBMetricsFactory.java index bf781d300a..f5c666184b 100644 --- a/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBMetricsFactory.java +++ b/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBMetricsFactory.java @@ -15,7 +15,6 @@ package org.hyperledger.besu.plugin.services.storage.rocksdb; import org.hyperledger.besu.metrics.BesuMetricCategory; -import org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem; import org.hyperledger.besu.metrics.rocksdb.RocksDBStats; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; @@ -107,10 +106,7 @@ public class RocksDBMetricsFactory { "database") .labels(rocksDbConfiguration.getLabel()); - if (metricsSystem instanceof PrometheusMetricsSystem) { - RocksDBStats.registerRocksDBMetrics( - stats, (PrometheusMetricsSystem) metricsSystem, statsDbMetricCategory); - } + RocksDBStats.registerRocksDBMetrics(stats, metricsSystem, statsDbMetricCategory); metricsSystem.createLongGauge( rocksDbMetricCategory, diff --git a/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBPlugin.java b/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBPlugin.java index 9e11bd634b..91e6e427bc 100644 --- a/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBPlugin.java +++ b/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBPlugin.java @@ -14,8 +14,8 @@ */ package org.hyperledger.besu.plugin.services.storage.rocksdb; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.PicoCLIOptions; import org.hyperledger.besu.plugin.services.StorageService; import org.hyperledger.besu.plugin.services.storage.SegmentIdentifier; @@ -40,7 +40,7 @@ public class RocksDBPlugin implements BesuPlugin { private final RocksDBCLIOptions options; private final List ignorableSegments = new ArrayList<>(); - private BesuContext context; + private ServiceManager context; private RocksDBKeyValueStorageFactory factory; private RocksDBKeyValuePrivacyStorageFactory privacyFactory; @@ -59,7 +59,7 @@ public class RocksDBPlugin implements BesuPlugin { } @Override - public void register(final BesuContext context) { + public void register(final ServiceManager context) { LOG.debug("Registering plugin"); this.context = context; diff --git a/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBColumnarKeyValueStorageTest.java b/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBColumnarKeyValueStorageTest.java index e28828c396..4800e82abc 100644 --- a/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBColumnarKeyValueStorageTest.java +++ b/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBColumnarKeyValueStorageTest.java @@ -264,7 +264,7 @@ public abstract class RocksDBColumnarKeyValueStorageTest extends AbstractKeyValu List.of()); store.close(); - // Create new db without ignoring experimental colum family will add column to db + // Create new db without ignoring experimental column family will add column to db store = createSegmentedStore( testPath, diff --git a/services/kvstore/src/main/java/org/hyperledger/besu/services/kvstore/InMemoryStoragePlugin.java b/services/kvstore/src/main/java/org/hyperledger/besu/services/kvstore/InMemoryStoragePlugin.java index 6783a82c1c..11e7656dfb 100644 --- a/services/kvstore/src/main/java/org/hyperledger/besu/services/kvstore/InMemoryStoragePlugin.java +++ b/services/kvstore/src/main/java/org/hyperledger/besu/services/kvstore/InMemoryStoragePlugin.java @@ -14,8 +14,8 @@ */ package org.hyperledger.besu.services.kvstore; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.BesuConfiguration; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.StorageService; @@ -36,7 +36,7 @@ import org.slf4j.LoggerFactory; public class InMemoryStoragePlugin implements BesuPlugin { private static final Logger LOG = LoggerFactory.getLogger(InMemoryStoragePlugin.class); - private BesuContext context; + private ServiceManager context; private InMemoryKeyValueStorageFactory factory; private InMemoryKeyValueStorageFactory privacyFactory; @@ -44,7 +44,7 @@ public class InMemoryStoragePlugin implements BesuPlugin { public InMemoryStoragePlugin() {} @Override - public void register(final BesuContext context) { + public void register(final ServiceManager context) { LOG.debug("Registering plugin"); this.context = context; diff --git a/settings.gradle b/settings.gradle index 2860c666d9..83363f70e4 100644 --- a/settings.gradle +++ b/settings.gradle @@ -51,7 +51,6 @@ include 'ethereum:mock-p2p' include 'ethereum:p2p' include 'ethereum:permissioning' include 'ethereum:referencetests' -include 'ethereum:retesteth' include 'ethereum:rlp' include 'ethereum:stratum' include 'ethereum:ethstats' diff --git a/testfuzz/src/main/java/org/hyperledger/besu/testfuzz/javafuzz/FuzzTarget.java b/testfuzz/src/main/java/org/hyperledger/besu/testfuzz/javafuzz/FuzzTarget.java index 26f3522e11..bee6bca776 100644 --- a/testfuzz/src/main/java/org/hyperledger/besu/testfuzz/javafuzz/FuzzTarget.java +++ b/testfuzz/src/main/java/org/hyperledger/besu/testfuzz/javafuzz/FuzzTarget.java @@ -25,7 +25,7 @@ public interface FuzzTarget { /** * The target to fuzz * - * @param data data proviced by the fuzzer + * @param data data provided by the fuzzer */ void fuzz(byte[] data); }