From 7c883830b14122c505065280ab11159aaa3c0e26 Mon Sep 17 00:00:00 2001 From: "core-repository-dispatch-app[bot]" <173070810+core-repository-dispatch-app[bot]@users.noreply.github.com> Date: Sun, 8 Sep 2024 01:25:36 +0100 Subject: [PATCH 1/2] Update Fast Sync configuration in Nethermind repository (#7401) Co-authored-by: LukaszRozmej --- src/Nethermind/Nethermind.Runner/configs/chiado.cfg | 4 ++-- src/Nethermind/Nethermind.Runner/configs/energyweb.cfg | 6 +++--- src/Nethermind/Nethermind.Runner/configs/exosama.cfg | 6 +++--- src/Nethermind/Nethermind.Runner/configs/gnosis.cfg | 4 ++-- src/Nethermind/Nethermind.Runner/configs/joc-mainnet.cfg | 6 +++--- src/Nethermind/Nethermind.Runner/configs/joc-testnet.cfg | 6 +++--- src/Nethermind/Nethermind.Runner/configs/mainnet.cfg | 4 ++-- src/Nethermind/Nethermind.Runner/configs/sepolia.cfg | 4 ++-- src/Nethermind/Nethermind.Runner/configs/volta.cfg | 6 +++--- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/Nethermind/Nethermind.Runner/configs/chiado.cfg b/src/Nethermind/Nethermind.Runner/configs/chiado.cfg index a5759f613fc..063329376f5 100644 --- a/src/Nethermind/Nethermind.Runner/configs/chiado.cfg +++ b/src/Nethermind/Nethermind.Runner/configs/chiado.cfg @@ -16,8 +16,8 @@ "Sync": { "FastSync": true, "SnapSync": true, - "PivotNumber": 11560000, - "PivotHash": "0x494d1e447b6e3e232ce5e3546a0aa523f2f5685b514cf155ecf06d256a9eafb3", + "PivotNumber": 11680000, + "PivotHash": "0x8dc08befcac4ed4f8770b74af45ef0cf0110fc0eba6664a0b5496146d5832044", "PivotTotalDifficulty": "231708131825107706987652208063906496124457284", "FastSyncCatchUpHeightDelta": "10000000000", "UseGethLimitsInFastBlocks": false diff --git a/src/Nethermind/Nethermind.Runner/configs/energyweb.cfg b/src/Nethermind/Nethermind.Runner/configs/energyweb.cfg index e96e81359df..c542f12694c 100644 --- a/src/Nethermind/Nethermind.Runner/configs/energyweb.cfg +++ b/src/Nethermind/Nethermind.Runner/configs/energyweb.cfg @@ -11,9 +11,9 @@ }, "Sync": { "FastSync": true, - "PivotNumber": 31620000, - "PivotHash": "0x7227c2165b426326520350507c570ac4384d940c8c8176ee8121a780eda9acb5", - "PivotTotalDifficulty": "10759728442040074214711905086992510845862220300", + "PivotNumber": 31740000, + "PivotHash": "0xef7d4930d209fde12f8f874d42f7cef7ff5c26a153a7be90dd44848e3d03da8a", + "PivotTotalDifficulty": "10800562326070586830327510039884323031236690394", "UseGethLimitsInFastBlocks": false, "FastSyncCatchUpHeightDelta": 10000000000 }, diff --git a/src/Nethermind/Nethermind.Runner/configs/exosama.cfg b/src/Nethermind/Nethermind.Runner/configs/exosama.cfg index 06bce3d7afa..ad7c2288ac5 100644 --- a/src/Nethermind/Nethermind.Runner/configs/exosama.cfg +++ b/src/Nethermind/Nethermind.Runner/configs/exosama.cfg @@ -11,9 +11,9 @@ }, "Sync": { "FastSync": true, - "PivotNumber": 11740000, - "PivotHash": "0xc1f9872c9a2e917f65d6d09aa527e385a2c9b1e37a8e80fcb9ea449fb0141e9c", - "PivotTotalDifficulty": "3994914987651817561060017891248958802136813285", + "PivotNumber": 11860000, + "PivotHash": "0x73fe5d99cb0c11f5bc89356e47dbf4cb6716e14063b13aaeb53998f079787f31", + "PivotTotalDifficulty": "4035748871682330176675622844140770987511293285", "UseGethLimitsInFastBlocks": false, "FastSyncCatchUpHeightDelta": 10000000000 }, diff --git a/src/Nethermind/Nethermind.Runner/configs/gnosis.cfg b/src/Nethermind/Nethermind.Runner/configs/gnosis.cfg index 6672623e61e..b828d7affd2 100644 --- a/src/Nethermind/Nethermind.Runner/configs/gnosis.cfg +++ b/src/Nethermind/Nethermind.Runner/configs/gnosis.cfg @@ -13,8 +13,8 @@ "Sync": { "FastSync": true, "SnapSync": true, - "PivotNumber": 35760000, - "PivotHash": "0xc58982687352c2ba3a818abf7e65f5e3b274b29136673deed85e2845f5701dc5", + "PivotNumber": 35870000, + "PivotHash": "0x37e4a9f028d674377e16ce3ea4ca4ef0cd7474fde33200fe8c944a73c900c3c6", "PivotTotalDifficulty": "8626000110427538733349499292577475819600160930", "UseGethLimitsInFastBlocks": false, "FastSyncCatchUpHeightDelta": 10000000000 diff --git a/src/Nethermind/Nethermind.Runner/configs/joc-mainnet.cfg b/src/Nethermind/Nethermind.Runner/configs/joc-mainnet.cfg index 0c6c8a39543..8b6526c91b7 100644 --- a/src/Nethermind/Nethermind.Runner/configs/joc-mainnet.cfg +++ b/src/Nethermind/Nethermind.Runner/configs/joc-mainnet.cfg @@ -11,9 +11,9 @@ "Sync": { "FastSync": true, "SnapSync": true, - "PivotNumber": 13100000, - "PivotHash": "0x6cc042124e9659f08e6686293fa115ba012fdbd7d637ef4ead0f8eec473b1054", - "PivotTotalDifficulty": "26078305" + "PivotNumber": 13220000, + "PivotHash": "0xde8589a868bd8eb13e9073cae9746d26dfafb1d9cab660968f49422f43a5e0bf", + "PivotTotalDifficulty": "26287111" }, "Metrics": { "NodeName": "JOC-Mainnet" diff --git a/src/Nethermind/Nethermind.Runner/configs/joc-testnet.cfg b/src/Nethermind/Nethermind.Runner/configs/joc-testnet.cfg index 1d78ba2fc73..27d3b94cb4f 100644 --- a/src/Nethermind/Nethermind.Runner/configs/joc-testnet.cfg +++ b/src/Nethermind/Nethermind.Runner/configs/joc-testnet.cfg @@ -11,9 +11,9 @@ "Sync": { "FastSync": true, "SnapSync": true, - "PivotNumber": 6710000, - "PivotHash": "0x0a3736e3f6df43c743a14f69c33cdcdd403427cb646ff0d5d5cbe86b3784e62d", - "PivotTotalDifficulty": "12605413" + "PivotNumber": 6830000, + "PivotHash": "0x6badab4d5bf7a34b908022f09280c1ca99ce9b23c7332e43960fd3ebc65e5ba4", + "PivotTotalDifficulty": "12796646" }, "Metrics": { "NodeName": "JOC-Testnet" diff --git a/src/Nethermind/Nethermind.Runner/configs/mainnet.cfg b/src/Nethermind/Nethermind.Runner/configs/mainnet.cfg index 3451c37baa3..9595eb08bad 100644 --- a/src/Nethermind/Nethermind.Runner/configs/mainnet.cfg +++ b/src/Nethermind/Nethermind.Runner/configs/mainnet.cfg @@ -9,8 +9,8 @@ "Sync": { "FastSync": true, "SnapSync": true, - "PivotNumber": 20651000, - "PivotHash": "0x1ca2913d5bded888225fbea3b08c0e4916ececd6abb52a7f7becc4058ac531da", + "PivotNumber": 20701000, + "PivotHash": "0x823f8bc86daa1a1fdeb6abfe793fce6a269072b31feac20310873610dac6ecfb", "PivotTotalDifficulty": "58750003716598352816469", "FastSyncCatchUpHeightDelta": "10000000000" }, diff --git a/src/Nethermind/Nethermind.Runner/configs/sepolia.cfg b/src/Nethermind/Nethermind.Runner/configs/sepolia.cfg index a48392ad826..66acfce2e24 100644 --- a/src/Nethermind/Nethermind.Runner/configs/sepolia.cfg +++ b/src/Nethermind/Nethermind.Runner/configs/sepolia.cfg @@ -17,8 +17,8 @@ "FastSync": true, "SnapSync": true, "UseGethLimitsInFastBlocks": true, - "PivotNumber": 6608000, - "PivotHash": "0x22a653172e994f219b103b5acd9c886fb605cc3afce47527c92535e143a15e4d", + "PivotNumber": 6651000, + "PivotHash": "0x7778040c3b649871b6d987685633d78b44ab14ff0de2759258a6296325993b95", "PivotTotalDifficulty": "17000018015853232", "FastSyncCatchUpHeightDelta": "10000000000" }, diff --git a/src/Nethermind/Nethermind.Runner/configs/volta.cfg b/src/Nethermind/Nethermind.Runner/configs/volta.cfg index f41df4796d4..9c246791f48 100644 --- a/src/Nethermind/Nethermind.Runner/configs/volta.cfg +++ b/src/Nethermind/Nethermind.Runner/configs/volta.cfg @@ -15,9 +15,9 @@ }, "Sync": { "FastSync": true, - "PivotNumber": 29130000, - "PivotHash": "0x33a9d3df9a045019a280bd9d607773c436c9ddba9be6d218fb934e731639f137", - "PivotTotalDifficulty": "9912425348406937440688102314487407999339265468", + "PivotNumber": 29210000, + "PivotHash": "0x515eba2255b858fb08054da66d45c7812ce2283e85a3afe9ab4cf7c4fdbab285", + "PivotTotalDifficulty": "9939647937760612517765172283081949456255551917", "UseGethLimitsInFastBlocks": false, "FastSyncCatchUpHeightDelta": 10000000000 }, From 268625bad2e1e73d4e0e9331bb3fa564bfe43f6d Mon Sep 17 00:00:00 2001 From: Lukasz Rozmej Date: Mon, 9 Sep 2024 11:53:14 +0200 Subject: [PATCH 2/2] Feature/geth like system tx (#7252) Co-authored-by: MarekM25 Co-authored-by: Ahmad Bitar --- .../Ethereum.Test.Base/BlockchainTestBase.cs | 18 +- .../AuraBlockProcessorTests.cs | 5 +- .../AuRaContractGasLimitOverrideTests.cs | 2 + .../Contract/TestContractBlockchain.cs | 2 +- .../Contract/TxPriorityContractTests.cs | 2 +- .../Transactions/PermissionTxComparerTests.cs | 1 - .../Transactions/TxCertifierFilterTests.cs | 3 +- .../Transactions/TxPermissionFilterTest.cs | 9 +- .../BlockProcessorTests.cs | 3 + .../Find/LogFinderTests.cs | 1 - .../GenesisLoaderTests.cs | 1 - .../Producers/DevBlockproducerTests.cs | 2 + .../Nethermind.Blockchain.Test/ReorgTests.cs | 2 + .../TransactionGasPriceComparisonTests.cs | 6 +- .../TransactionSelectorTests.cs | 2 - .../TransactionsExecutorTests.cs | 2 - .../BeaconBlockRoot/BeaconBlockRootHandler.cs | 63 ++++--- .../IBeaconBlockRootHandler.cs | 7 +- .../Nethermind.Blockchain/GenesisLoader.cs | 29 +-- .../Spec/ChainHeadSpecProvider.cs | 20 +- .../CliqueBlockProducerTests.cs | 3 + .../AuRaBlockProcessor.cs | 6 +- .../NullBeaconBlockRootHandler.cs | 17 -- .../InitializeBlockchainAuRa.cs | 2 + .../StartBlockProducerAuRa.cs | 2 + .../CliquePlugin.cs | 2 + .../NethDevPlugin.cs | 2 + ...sor.BlockProductionTransactionsExecutor.cs | 34 ++-- .../Processing/BlockProcessor.cs | 92 +++++---- .../Processing/IBlockProcessor.cs | 1 + .../Processing/ReadOnlyChainProcessingEnv.cs | 2 + .../Processing/ReadOnlyTxProcessingEnv.cs | 6 +- .../TransactionProcessorAdapterExtensions.cs | 2 +- .../Producers/BlockProducerEnvFactory.cs | 5 +- .../Blockchain/TestBlockchain.cs | 12 +- .../FixedBlockChainHeadSpecProvider.cs | 38 ++-- .../Nethermind.Core/Eip4788Constants.cs | 5 - .../Nethermind.Core/Specs/AuraSpecProvider.cs | 11 ++ .../Nethermind.Core/Specs/ForkActivation.cs | 13 +- .../Nethermind.Core/Specs/IReleaseSpec.cs | 2 +- .../Nethermind.Core/Specs/ISpecProvider.cs | 24 ++- .../Specs/ReleaseSpecDecorator.cs | 78 ++++++++ .../DifficultyCalculatorTests.cs | 10 - .../Nethermind.Evm/Tracing/ITxTracer.cs | 2 +- .../Tracing/Proofs/ProofTxTracer.cs | 10 - .../Nethermind.Evm/TransactionExtensions.cs | 8 +- ...llAndRestoreTransactionProcessorAdapter.cs | 12 +- .../ExecuteTransactionProcessorAdapter.cs | 12 +- .../SystemTransactionProcessor.cs | 71 +++++++ .../TraceTransactionProcessorAdapter.cs | 12 +- .../TransactionProcessor.cs | 175 ++++++++++-------- .../SimulateReadOnlyBlocksProcessingEnv.cs | 4 +- .../Simulate/SimulateTransactionProcessor.cs | 4 +- .../Steps/InitializeBlockchain.cs | 2 + .../Steps/InitializePrecompiles.cs | 1 + .../EthModuleBenchmarks.cs | 13 +- .../Modules/Eth/EthRpcModuleTests.cs | 6 +- .../Modules/SubscribeModuleTests.cs | 2 - .../Modules/Trace/ParityStyleTracerTests.cs | 2 + .../Modules/TraceRpcModuleTests.cs | 2 +- .../Modules/RpcBlockTransactionsExecutor.cs | 10 +- .../AuRaMergeEngineModuleTests.cs | 9 + .../AuRaMergeBlockProcessor.cs | 66 ++++--- .../AuRaMergeBlockProducerEnvFactory.cs | 2 + .../InitializeBlockchainAuRaMerge.cs | 9 +- .../EngineModuleTests.HelperFunctions.cs | 3 - .../EngineModuleTests.Setup.cs | 2 + .../MinGasPriceTests.cs | 10 - .../InitializeBlockchainOptimism.cs | 17 +- .../OptimismBlockProcessor.cs | 18 +- .../OptimismBlockProducerEnvFactory.cs | 2 + .../OptimismReadOnlyTxProcessingEnv.cs | 2 +- .../OptimismTransactionProcessor.cs | 12 +- .../ReadOnlyChainProcessingEnv.cs | 2 + .../OverridableReleaseSpec.cs | 7 +- .../OverridableSpecProvider.cs | 1 + .../ChainSpecBasedSpecProvider.cs | 1 + .../ChainSpecStyle/ChainSpecLoader.cs | 7 +- .../Nethermind.Specs/ChiadoSpecProvider.cs | 1 + .../Nethermind.Specs/Forks/00_Olympic.cs | 1 - .../Nethermind.Specs/GnosisSpecProvider.cs | 1 + .../Nethermind.Specs/GoerliSpecProvider.cs | 1 + .../Nethermind.Specs/ReleaseSpec.cs | 6 +- .../Nethermind.Specs/SepoliaSpecProvider.cs | 2 + .../SingleReleaseSpecProvider.cs | 11 +- .../SystemTransactionReleaseSpec.cs | 129 +------------ .../SyncThreadTests.cs | 3 + src/Nethermind/Nethermind.Trie/TreeDumper.cs | 2 +- .../Nethermind.TxPool.Test/TxPoolTests.cs | 4 +- 89 files changed, 621 insertions(+), 607 deletions(-) delete mode 100644 src/Nethermind/Nethermind.Consensus.AuRa/BeaconBlockRoot/NullBeaconBlockRootHandler.cs create mode 100644 src/Nethermind/Nethermind.Core/Specs/AuraSpecProvider.cs create mode 100644 src/Nethermind/Nethermind.Core/Specs/ReleaseSpecDecorator.cs create mode 100644 src/Nethermind/Nethermind.Evm/TransactionProcessing/SystemTransactionProcessor.cs diff --git a/src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs b/src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs index 8ef9df33603..e2a090fa996 100644 --- a/src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs +++ b/src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs @@ -9,6 +9,7 @@ using System.Threading; using System.Threading.Tasks; using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Blockchain.Find; using Nethermind.Blockchain.Receipts; @@ -155,21 +156,22 @@ protected async Task RunTest(BlockchainTest test, Stopwatch? codeInfoRepository, _logManager); + TransactionProcessor transactionProcessor = new( + specProvider, + stateProvider, + virtualMachine, + codeInfoRepository, + _logManager); + IBlockProcessor blockProcessor = new BlockProcessor( specProvider, blockValidator, rewardCalculator, - new BlockProcessor.BlockValidationTransactionsExecutor( - new TransactionProcessor( - specProvider, - stateProvider, - virtualMachine, - codeInfoRepository, - _logManager), - stateProvider), + new BlockProcessor.BlockValidationTransactionsExecutor(transactionProcessor, stateProvider), stateProvider, receiptStorage, new BlockhashStore(specProvider, stateProvider), + new BeaconBlockRootHandler(transactionProcessor), _logManager); IBlockchainProcessor blockchainProcessor = new BlockchainProcessor( diff --git a/src/Nethermind/Nethermind.AuRa.Test/AuraBlockProcessorTests.cs b/src/Nethermind/Nethermind.AuRa.Test/AuraBlockProcessorTests.cs index cfbfb9cb9d7..383d0d6da6d 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/AuraBlockProcessorTests.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/AuraBlockProcessorTests.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using FluentAssertions; using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Receipts; using Nethermind.Blockchain.Test.Validators; using Nethermind.Consensus.AuRa; @@ -157,11 +158,11 @@ void Process(AuRaBlockProcessor auRaBlockProcessor, int blockNumber, Hash256 sta new BlockProcessor.BlockValidationTransactionsExecutor(transactionProcessor, stateProvider), stateProvider, NullReceiptStorage.Instance, + new BeaconBlockRootHandler(transactionProcessor), LimboLogs.Instance, Substitute.For(), new WithdrawalProcessor(stateProvider, LimboLogs.Instance), - null, - txFilter, + txFilter: txFilter, contractRewriter: contractRewriter); return (processor, stateProvider); diff --git a/src/Nethermind/Nethermind.AuRa.Test/Contract/AuRaContractGasLimitOverrideTests.cs b/src/Nethermind/Nethermind.AuRa.Test/Contract/AuRaContractGasLimitOverrideTests.cs index 3e05e43fde1..ea6880f55f6 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/Contract/AuRaContractGasLimitOverrideTests.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/Contract/AuRaContractGasLimitOverrideTests.cs @@ -7,6 +7,7 @@ using FluentAssertions; using Nethermind.Abi; using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Consensus; using Nethermind.Consensus.AuRa; using Nethermind.Consensus.AuRa.Contracts; @@ -96,6 +97,7 @@ protected override BlockProcessor CreateBlockProcessor() new BlockProcessor.BlockValidationTransactionsExecutor(TxProcessor, State), State, ReceiptStorage, + new BeaconBlockRootHandler(TxProcessor), LimboLogs.Instance, BlockTree, NullWithdrawalProcessor.Instance, diff --git a/src/Nethermind/Nethermind.AuRa.Test/Contract/TestContractBlockchain.cs b/src/Nethermind/Nethermind.AuRa.Test/Contract/TestContractBlockchain.cs index bde491cbd4f..0dfd5420027 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/Contract/TestContractBlockchain.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/Contract/TestContractBlockchain.cs @@ -21,7 +21,7 @@ protected TestContractBlockchain() SealEngineType = Nethermind.Core.SealEngineType.AuRa; } - public static async Task ForTest(string testSuffix = null) where TTest : TestContractBlockchain, new() + public static async Task ForTest(string? testSuffix = null) where TTest : TestContractBlockchain, new() { (ChainSpec ChainSpec, ISpecProvider SpecProvider) GetSpecProvider() { diff --git a/src/Nethermind/Nethermind.AuRa.Test/Contract/TxPriorityContractTests.cs b/src/Nethermind/Nethermind.AuRa.Test/Contract/TxPriorityContractTests.cs index d1554f7b638..17a0bad2438 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/Contract/TxPriorityContractTests.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/Contract/TxPriorityContractTests.cs @@ -299,7 +299,7 @@ protected override async Task AddBlocksOnStart() EthereumEcdsa ecdsa = new(ChainSpec.ChainId); await AddBlock( - SignTransactions(ecdsa, TestItem.PrivateKeyA, 0, + SignTransactions(ecdsa, TestItem.PrivateKeyA, 1, TxPriorityContract.SetPriority(TestItem.AddressA, FnSignature2, UInt256.One), TxPriorityContract.SetPriority(TestItem.AddressB, FnSignature, 10), TxPriorityContract.SetPriority(TestItem.AddressB, FnSignature2, 4), diff --git a/src/Nethermind/Nethermind.AuRa.Test/Transactions/PermissionTxComparerTests.cs b/src/Nethermind/Nethermind.AuRa.Test/Transactions/PermissionTxComparerTests.cs index ddf72060de7..621a177664f 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/Transactions/PermissionTxComparerTests.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/Transactions/PermissionTxComparerTests.cs @@ -261,7 +261,6 @@ public void order_is_correct(Func, IEnumerable(); var spec = new ReleaseSpec() { IsEip1559Enabled = false }; - specProvider.GetSpec(Arg.Any()).Returns(spec); specProvider.GetSpec(Arg.Any()).Returns(spec); TransactionComparerProvider transactionComparerProvider = new(specProvider, blockTree); IComparer defaultComparer = transactionComparerProvider.GetDefaultComparer(); diff --git a/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxCertifierFilterTests.cs b/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxCertifierFilterTests.cs index 92a33ae4941..849711461bb 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxCertifierFilterTests.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxCertifierFilterTests.cs @@ -7,6 +7,7 @@ using Nethermind.Abi; using Nethermind.AuRa.Test.Contract; using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Consensus.AuRa; using Nethermind.Consensus.AuRa.Contracts; using Nethermind.Consensus.AuRa.Transactions; @@ -154,10 +155,10 @@ protected override BlockProcessor CreateBlockProcessor() new BlockProcessor.BlockValidationTransactionsExecutor(TxProcessor, State), State, ReceiptStorage, + new BeaconBlockRootHandler(TxProcessor), LimboLogs.Instance, BlockTree, NullWithdrawalProcessor.Instance, - null, preWarmer: CreateBlockCachePreWarmer()); } diff --git a/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxPermissionFilterTest.cs b/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxPermissionFilterTest.cs index dbaa774b2ff..3afab033df9 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxPermissionFilterTest.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxPermissionFilterTest.cs @@ -9,6 +9,7 @@ using Nethermind.Abi; using Nethermind.AuRa.Test.Contract; using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Consensus.AuRa; using Nethermind.Consensus.AuRa.Contracts; using Nethermind.Consensus.AuRa.Transactions; @@ -295,14 +296,12 @@ protected override BlockProcessor CreateBlockProcessor() new BlockProcessor.BlockValidationTransactionsExecutor(TxProcessor, State), State, ReceiptStorage, + new BeaconBlockRootHandler(TxProcessor), LimboLogs.Instance, BlockTree, NullWithdrawalProcessor.Instance, - null, - PermissionBasedTxFilter, - null, - null, - CreateBlockCachePreWarmer()); + txFilter: PermissionBasedTxFilter, + preWarmer: CreateBlockCachePreWarmer()); } protected override async Task AddBlocksOnStart() diff --git a/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs index 58b3d0317bf..f4ca94b9304 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs @@ -23,6 +23,7 @@ using System.Threading.Tasks; using System.Threading; using FluentAssertions; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Rewards; @@ -50,6 +51,7 @@ public void Prepared_block_contains_author_field() stateProvider, NullReceiptStorage.Instance, Substitute.For(), + new BeaconBlockRootHandler(transactionProcessor), LimboLogs.Instance); BlockHeader header = Build.A.BlockHeader.WithAuthor(TestItem.AddressD).TestObject; @@ -79,6 +81,7 @@ public void Recovers_state_on_cancel() stateProvider, NullReceiptStorage.Instance, Substitute.For(), + new BeaconBlockRootHandler(transactionProcessor), LimboLogs.Instance); BlockHeader header = Build.A.BlockHeader.WithNumber(1).WithAuthor(TestItem.AddressD).TestObject; diff --git a/src/Nethermind/Nethermind.Blockchain.Test/Find/LogFinderTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/Find/LogFinderTests.cs index ad39a53138e..2d7ea7a3ae4 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/Find/LogFinderTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/Find/LogFinderTests.cs @@ -47,7 +47,6 @@ public void SetUp() private void SetUp(bool allowReceiptIterator) { var specProvider = Substitute.For(); - specProvider.GetSpec(Arg.Any()).IsEip155Enabled.Returns(true); specProvider.GetSpec(Arg.Any()).IsEip155Enabled.Returns(true); _receiptStorage = new InMemoryReceiptStorage(allowReceiptIterator); _rawBlockTree = Build.A.BlockTree() diff --git a/src/Nethermind/Nethermind.Blockchain.Test/GenesisLoaderTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/GenesisLoaderTests.cs index 539e2505405..47f983dcbab 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/GenesisLoaderTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/GenesisLoaderTests.cs @@ -61,7 +61,6 @@ private Block GetGenesisBlock(string chainspecPath) TrieStore trieStore = new(stateDb, LimboLogs.Instance); IWorldState stateProvider = new WorldState(trieStore, codeDb, LimboLogs.Instance); ISpecProvider specProvider = Substitute.For(); - specProvider.GetSpec(Arg.Any()).Returns(Berlin.Instance); specProvider.GetSpec(Arg.Any()).Returns(Berlin.Instance); ITransactionProcessor transactionProcessor = Substitute.For(); GenesisLoader genesisLoader = new(chainSpec, specProvider, stateProvider, transactionProcessor); diff --git a/src/Nethermind/Nethermind.Blockchain.Test/Producers/DevBlockproducerTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/Producers/DevBlockproducerTests.cs index 3afe77c9aa6..7f4b9d2bb2b 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/Producers/DevBlockproducerTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/Producers/DevBlockproducerTests.cs @@ -3,6 +3,7 @@ using System.Threading; using FluentAssertions; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Blockchain.Receipts; using Nethermind.Config; @@ -78,6 +79,7 @@ public void Test() stateProvider, NullReceiptStorage.Instance, new BlockhashStore(specProvider, stateProvider), + new BeaconBlockRootHandler(txProcessor), LimboLogs.Instance); BlockchainProcessor blockchainProcessor = new( blockTree, diff --git a/src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs index f48be888945..a7c40c63652 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using FluentAssertions; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Blockchain.Receipts; using Nethermind.Consensus.Comparers; @@ -78,6 +79,7 @@ public void Setup() stateProvider, NullReceiptStorage.Instance, new BlockhashStore(MainnetSpecProvider.Instance, stateProvider), + new BeaconBlockRootHandler(transactionProcessor), LimboLogs.Instance); _blockchainProcessor = new BlockchainProcessor( _blockTree, diff --git a/src/Nethermind/Nethermind.Blockchain.Test/TransactionGasPriceComparisonTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/TransactionGasPriceComparisonTests.cs index 60e373f4445..ca342190624 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/TransactionGasPriceComparisonTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/TransactionGasPriceComparisonTests.cs @@ -160,10 +160,8 @@ public TestingContext(bool isEip1559Enabled = false, long eip1559TransitionBlock ReleaseSpec releaseSpec = new(); ReleaseSpec eip1559ReleaseSpec = new() { IsEip1559Enabled = isEip1559Enabled, Eip1559TransitionBlock = eip1559TransitionBlock }; ISpecProvider specProvider = Substitute.For(); - specProvider.GetSpecFor1559(Arg.Is(x => x >= eip1559TransitionBlock)).Returns(eip1559ReleaseSpec); - specProvider.GetSpecFor1559(Arg.Is(x => x < eip1559TransitionBlock)).Returns(releaseSpec); - specProvider.GetSpec(Arg.Is(x => x.Number >= eip1559TransitionBlock)).Returns(eip1559ReleaseSpec); - specProvider.GetSpec(Arg.Is(x => x.Number < eip1559TransitionBlock)).Returns(releaseSpec); + specProvider.GetSpec(Arg.Is(x => x.BlockNumber >= eip1559TransitionBlock)).Returns(eip1559ReleaseSpec); + specProvider.GetSpec(Arg.Is(x => x.BlockNumber < eip1559TransitionBlock)).Returns(releaseSpec); _blockTree = Substitute.For(); UpdateBlockTreeHead(); _transactionComparerProvider = diff --git a/src/Nethermind/Nethermind.Blockchain.Test/TransactionSelectorTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/TransactionSelectorTests.cs index 6b833e60048..4ba502850e1 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/TransactionSelectorTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/TransactionSelectorTests.cs @@ -222,8 +222,6 @@ void SetAccountStates(IEnumerable
missingAddresses) Block block = Build.A.Block.WithNumber(0).TestObject; blockTree.Head.Returns(block); IReleaseSpec spec = testCase.ReleaseSpec; - specProvider.GetSpec(Arg.Any(), Arg.Any()).Returns(spec); - specProvider.GetSpec(Arg.Any()).Returns(spec); specProvider.GetSpec(Arg.Any()).Returns(spec); TransactionComparerProvider transactionComparerProvider = new(specProvider, blockTree); diff --git a/src/Nethermind/Nethermind.Blockchain.Test/TransactionsExecutorTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/TransactionsExecutorTests.cs index 8799490191a..ceca5d5b060 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/TransactionsExecutorTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/TransactionsExecutorTests.cs @@ -266,8 +266,6 @@ public void Proper_transactions_selected(TransactionSelectorTests.ProperTransact ISpecProvider specProvider = Substitute.For(); IReleaseSpec spec = testCase.ReleaseSpec; - specProvider.GetSpec(Arg.Any(), Arg.Any()).Returns(spec); - specProvider.GetSpec(Arg.Any()).Returns(spec); specProvider.GetSpec(Arg.Any()).Returns(spec); ITransactionProcessor transactionProcessor = Substitute.For(); diff --git a/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs b/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs index 89276e3c7f8..78e482250b6 100644 --- a/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs +++ b/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs @@ -1,39 +1,44 @@ // SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only -using Nethermind.Core.Specs; +using System; using Nethermind.Core; +using Nethermind.Core.Eip2930; +using Nethermind.Core.Specs; +using Nethermind.Crypto; +using Nethermind.Evm.Tracing; +using Nethermind.Evm.TransactionProcessing; using Nethermind.Int256; -using Nethermind.State; -using Nethermind.Core.Crypto; -using Nethermind.Core.Extensions; - -namespace Nethermind.Consensus.BeaconBlockRoot; -public class BeaconBlockRootHandler : IBeaconBlockRootHandler +namespace Nethermind.Blockchain.BeaconBlockRoot; +public class BeaconBlockRootHandler(ITransactionProcessor processor) : IBeaconBlockRootHandler { - public void ApplyContractStateChanges(Block block, IReleaseSpec spec, IWorldState stateProvider) - { - if (!spec.IsBeaconBlockRootAvailable || - block.IsGenesis || - block.Header.ParentBeaconBlockRoot is null) - return; - - Address eip4788Account = spec.Eip4788ContractAddress ?? Eip4788Constants.BeaconRootsAddress; + private const long GasLimit = 30_000_000L; - if (!stateProvider.AccountExists(eip4788Account)) - return; - - UInt256 timestamp = (UInt256)block.Timestamp; - Hash256 parentBeaconBlockRoot = block.ParentBeaconBlockRoot; - - UInt256.Mod(timestamp, Eip4788Constants.HistoryBufferLength, out UInt256 timestampReduced); - UInt256 rootIndex = timestampReduced + Eip4788Constants.HistoryBufferLength; - - StorageCell tsStorageCell = new(eip4788Account, timestampReduced); - StorageCell brStorageCell = new(eip4788Account, rootIndex); - - stateProvider.Set(tsStorageCell, Bytes.WithoutLeadingZeros(timestamp.ToBigEndian()).ToArray()); - stateProvider.Set(brStorageCell, Bytes.WithoutLeadingZeros(parentBeaconBlockRoot.Bytes).ToArray()); + public void StoreBeaconRoot(Block block, IReleaseSpec spec) + { + BlockHeader? header = block.Header; + var canInsertBeaconRoot = spec.IsBeaconBlockRootAvailable + && !header.IsGenesis + && header.ParentBeaconBlockRoot is not null; + + if (canInsertBeaconRoot) + { + Address beaconRootsAddress = spec.Eip4788ContractAddress ?? Eip4788Constants.BeaconRootsAddress; + Transaction transaction = new() + { + Value = UInt256.Zero, + Data = header.ParentBeaconBlockRoot.Bytes.ToArray(), + To = beaconRootsAddress, + SenderAddress = Address.SystemUser, + GasLimit = GasLimit, + GasPrice = UInt256.Zero, + AccessList = new AccessList.Builder().AddAddress(beaconRootsAddress).Build() + }; + + transaction.Hash = transaction.CalculateHash(); + + processor.Execute(transaction, header, NullTxTracer.Instance); + } } } diff --git a/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/IBeaconBlockRootHandler.cs b/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/IBeaconBlockRootHandler.cs index d30074fc4cc..047af4ffb99 100644 --- a/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/IBeaconBlockRootHandler.cs +++ b/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/IBeaconBlockRootHandler.cs @@ -1,12 +1,11 @@ // SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only -using Nethermind.Core.Specs; using Nethermind.Core; -using Nethermind.State; +using Nethermind.Core.Specs; -namespace Nethermind.Consensus.BeaconBlockRoot; +namespace Nethermind.Blockchain.BeaconBlockRoot; public interface IBeaconBlockRootHandler { - void ApplyContractStateChanges(Block block, IReleaseSpec spec, IWorldState state); + void StoreBeaconRoot(Block block, IReleaseSpec spec); } diff --git a/src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs b/src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs index 28f4979bafe..2c94e4d7c6d 100644 --- a/src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs +++ b/src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs @@ -14,30 +14,19 @@ using Nethermind.Evm.TransactionProcessing; using Nethermind.Specs.ChainSpecStyle; using Nethermind.State; -using Nethermind.Consensus.BeaconBlockRoot; namespace Nethermind.Blockchain { - public class GenesisLoader + public class GenesisLoader( + ChainSpec chainSpec, + ISpecProvider specProvider, + IWorldState stateProvider, + ITransactionProcessor transactionProcessor) { - private readonly ChainSpec _chainSpec; - private readonly ISpecProvider _specProvider; - private readonly IWorldState _stateProvider; - private readonly ITransactionProcessor _transactionProcessor; - private readonly BeaconBlockRootHandler _beaconBlockRootHandler; - - public GenesisLoader( - ChainSpec chainSpec, - ISpecProvider specProvider, - IWorldState stateProvider, - ITransactionProcessor transactionProcessor) - { - _chainSpec = chainSpec ?? throw new ArgumentNullException(nameof(chainSpec)); - _specProvider = specProvider ?? throw new ArgumentNullException(nameof(specProvider)); - _stateProvider = stateProvider ?? throw new ArgumentNullException(nameof(stateProvider)); - _transactionProcessor = transactionProcessor ?? throw new ArgumentNullException(nameof(transactionProcessor)); - _beaconBlockRootHandler = new BeaconBlockRootHandler(); - } + private readonly ChainSpec _chainSpec = chainSpec ?? throw new ArgumentNullException(nameof(chainSpec)); + private readonly ISpecProvider _specProvider = specProvider ?? throw new ArgumentNullException(nameof(specProvider)); + private readonly IWorldState _stateProvider = stateProvider ?? throw new ArgumentNullException(nameof(stateProvider)); + private readonly ITransactionProcessor _transactionProcessor = transactionProcessor ?? throw new ArgumentNullException(nameof(transactionProcessor)); public Block Load() { diff --git a/src/Nethermind/Nethermind.Blockchain/Spec/ChainHeadSpecProvider.cs b/src/Nethermind/Nethermind.Blockchain/Spec/ChainHeadSpecProvider.cs index da843c2ad06..f1d38e94778 100644 --- a/src/Nethermind/Nethermind.Blockchain/Spec/ChainHeadSpecProvider.cs +++ b/src/Nethermind/Nethermind.Blockchain/Spec/ChainHeadSpecProvider.cs @@ -9,20 +9,14 @@ namespace Nethermind.Blockchain.Spec { - public class ChainHeadSpecProvider : IChainHeadSpecProvider + public class ChainHeadSpecProvider(ISpecProvider specProvider, IBlockFinder blockFinder) : IChainHeadSpecProvider { - private readonly ISpecProvider _specProvider; - private readonly IBlockFinder _blockFinder; + private readonly ISpecProvider _specProvider = specProvider ?? throw new ArgumentNullException(nameof(specProvider)); + private readonly IBlockFinder _blockFinder = blockFinder ?? throw new ArgumentNullException(nameof(blockFinder)); private long _lastHeader = -1; - private IReleaseSpec? _headerSpec = null; + private IReleaseSpec? _headerSpec; private readonly object _lock = new(); - public ChainHeadSpecProvider(ISpecProvider specProvider, IBlockFinder blockFinder) - { - _specProvider = specProvider ?? throw new ArgumentNullException(nameof(specProvider)); - _blockFinder = blockFinder ?? throw new ArgumentNullException(nameof(blockFinder)); - } - public void UpdateMergeTransitionInfo(long? blockNumber, UInt256? terminalTotalDifficulty = null) { _specProvider.UpdateMergeTransitionInfo(blockNumber, terminalTotalDifficulty); @@ -67,9 +61,9 @@ public IReleaseSpec GetCurrentHeadSpec() lock (_lock) { _lastHeader = headerNumber; - if (header is not null) - return _headerSpec = _specProvider.GetSpec(header); - return _headerSpec = GetSpec((ForkActivation)headerNumber); + return _headerSpec = header is not null + ? _specProvider.GetSpec(header) + : GetSpec((ForkActivation)headerNumber); } } } diff --git a/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs b/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs index 04c64ea3eaf..dbb56948e14 100644 --- a/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs +++ b/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using FluentAssertions; using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Blockchain.Receipts; using Nethermind.Consensus; @@ -141,6 +142,7 @@ public On CreateNode(PrivateKey privateKey, bool withGenesisAlreadyProcessed = f stateProvider, NullReceiptStorage.Instance, new BlockhashStore(goerliSpecProvider, stateProvider), + new BeaconBlockRootHandler(transactionProcessor), nodeLogManager); BlockchainProcessor processor = new(blockTree, blockProcessor, new AuthorRecoveryStep(snapshotManager), stateReader, nodeLogManager, BlockchainProcessor.Options.NoReceipts); @@ -160,6 +162,7 @@ public On CreateNode(PrivateKey privateKey, bool withGenesisAlreadyProcessed = f minerStateProvider, NullReceiptStorage.Instance, new BlockhashStore(goerliSpecProvider, minerStateProvider), + new BeaconBlockRootHandler(minerTransactionProcessor), nodeLogManager); BlockchainProcessor minerProcessor = new(blockTree, minerBlockProcessor, new AuthorRecoveryStep(snapshotManager), stateReader, nodeLogManager, BlockchainProcessor.Options.NoReceipts); diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/AuRaBlockProcessor.cs b/src/Nethermind/Nethermind.Consensus.AuRa/AuRaBlockProcessor.cs index 51190c3dd7e..2661da25d01 100644 --- a/src/Nethermind/Nethermind.Consensus.AuRa/AuRaBlockProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus.AuRa/AuRaBlockProcessor.cs @@ -3,6 +3,7 @@ using System; using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Blockchain.Find; using Nethermind.Blockchain.Receipts; @@ -19,6 +20,7 @@ using Nethermind.Evm.Tracing; using Nethermind.Logging; using Nethermind.State; +using Nethermind.Trie; using Nethermind.TxPool; namespace Nethermind.Consensus.AuRa @@ -39,10 +41,11 @@ public AuRaBlockProcessor( IBlockProcessor.IBlockTransactionsExecutor blockTransactionsExecutor, IWorldState stateProvider, IReceiptStorage receiptStorage, + IBeaconBlockRootHandler beaconBlockRootHandler, ILogManager logManager, IBlockFinder blockTree, IWithdrawalProcessor withdrawalProcessor, - IAuRaValidator? auRaValidator, + IAuRaValidator? auRaValidator = null, ITxFilter? txFilter = null, AuRaContractGasLimitOverride? gasLimitOverride = null, ContractRewriter? contractRewriter = null, @@ -55,6 +58,7 @@ public AuRaBlockProcessor( stateProvider, receiptStorage, new BlockhashStore(specProvider, stateProvider), + beaconBlockRootHandler, logManager, withdrawalProcessor, preWarmer: preWarmer) diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/BeaconBlockRoot/NullBeaconBlockRootHandler.cs b/src/Nethermind/Nethermind.Consensus.AuRa/BeaconBlockRoot/NullBeaconBlockRootHandler.cs deleted file mode 100644 index 96138999814..00000000000 --- a/src/Nethermind/Nethermind.Consensus.AuRa/BeaconBlockRoot/NullBeaconBlockRootHandler.cs +++ /dev/null @@ -1,17 +0,0 @@ -// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited -// SPDX-License-Identifier: LGPL-3.0-only - -using Nethermind.Consensus.BeaconBlockRoot; -using Nethermind.Core; -using Nethermind.Core.Specs; -using Nethermind.State; - -namespace Nethermind.Consensus.AuRa.BeaconBlockRoot; -internal class NullBeaconBlockRootHandler : IBeaconBlockRootHandler -{ - public void ApplyContractStateChanges(Block block, IReleaseSpec spec, IWorldState state) - { - } - - public static IBeaconBlockRootHandler Instance { get; } = new NullBeaconBlockRootHandler(); -} diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/InitializeBlockchainAuRa.cs b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/InitializeBlockchainAuRa.cs index 63b74023691..9e3e849e4af 100644 --- a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/InitializeBlockchainAuRa.cs +++ b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/InitializeBlockchainAuRa.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Nethermind.Api; using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Data; using Nethermind.Blockchain.Services; using Nethermind.Config; @@ -106,6 +107,7 @@ protected virtual AuRaBlockProcessor NewAuraBlockProcessor(ITxFilter txFilter, B new BlockProcessor.BlockValidationTransactionsExecutor(_api.TransactionProcessor, worldState), worldState, _api.ReceiptStorage!, + new BeaconBlockRootHandler(_api.TransactionProcessor!), _api.LogManager, _api.BlockTree!, NullWithdrawalProcessor.Instance, diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/StartBlockProducerAuRa.cs b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/StartBlockProducerAuRa.cs index 948eaef9a97..b55a38265e6 100644 --- a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/StartBlockProducerAuRa.cs +++ b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/StartBlockProducerAuRa.cs @@ -8,6 +8,7 @@ using Nethermind.Abi; using Nethermind.Api; using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Data; using Nethermind.Config; using Nethermind.Consensus.AuRa.Config; @@ -154,6 +155,7 @@ private BlockProcessor CreateBlockProcessor(IReadOnlyTxProcessingScope changeabl _api.BlockProducerEnvFactory.TransactionsExecutorFactory.Create(changeableTxProcessingEnv), changeableTxProcessingEnv.WorldState, _api.ReceiptStorage, + new BeaconBlockRootHandler(changeableTxProcessingEnv.TransactionProcessor), _api.LogManager, _api.BlockTree, NullWithdrawalProcessor.Instance, diff --git a/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs b/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs index e8dbbcf0175..32d2616aca1 100644 --- a/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs +++ b/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs @@ -6,6 +6,7 @@ using Nethermind.Api; using Nethermind.Api.Extensions; using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Blockchain.Receipts; using Nethermind.Config; @@ -112,6 +113,7 @@ public IBlockProducer InitBlockProducer(ITxSource? additionalTxSource = null) scope.WorldState, NullReceiptStorage.Instance, new BlockhashStore(getFromApi.SpecProvider, scope.WorldState), + new BeaconBlockRootHandler(scope.TransactionProcessor), getFromApi.LogManager, new BlockProductionWithdrawalProcessor(new WithdrawalProcessor(scope.WorldState, getFromApi.LogManager))); diff --git a/src/Nethermind/Nethermind.Consensus.Ethash/NethDevPlugin.cs b/src/Nethermind/Nethermind.Consensus.Ethash/NethDevPlugin.cs index 4297e243a42..93a485fabff 100644 --- a/src/Nethermind/Nethermind.Consensus.Ethash/NethDevPlugin.cs +++ b/src/Nethermind/Nethermind.Consensus.Ethash/NethDevPlugin.cs @@ -6,6 +6,7 @@ using Nethermind.Api; using Nethermind.Api.Extensions; using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Blockchain.Receipts; using Nethermind.Config; @@ -82,6 +83,7 @@ public IBlockProducer InitBlockProducer(ITxSource? additionalTxSource = null) scope.WorldState, NullReceiptStorage.Instance, new BlockhashStore(getFromApi.SpecProvider, scope.WorldState), + new BeaconBlockRootHandler(scope.TransactionProcessor), getFromApi.LogManager); IBlockchainProcessor producerChainProcessor = new BlockchainProcessor( diff --git a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.BlockProductionTransactionsExecutor.cs b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.BlockProductionTransactionsExecutor.cs index bd8740c7c2f..9725e29b7fd 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.BlockProductionTransactionsExecutor.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.BlockProductionTransactionsExecutor.cs @@ -18,12 +18,15 @@ namespace Nethermind.Consensus.Processing { public partial class BlockProcessor { - public class BlockProductionTransactionsExecutor : IBlockProductionTransactionsExecutor + public class BlockProductionTransactionsExecutor( + ITransactionProcessor txProcessor, + IWorldState stateProvider, + IBlockProductionTransactionPicker txPicker, + ILogManager logManager) + : IBlockProductionTransactionsExecutor { - private readonly ITransactionProcessorAdapter _transactionProcessor; - private readonly IWorldState _stateProvider; - private readonly IBlockProductionTransactionPicker _blockProductionTransactionPicker; - private readonly ILogger _logger; + private readonly ITransactionProcessorAdapter _transactionProcessor = new BuildUpTransactionProcessorAdapter(txProcessor); + private readonly ILogger _logger = logManager.GetClassLogger(); public BlockProductionTransactionsExecutor( IReadOnlyTxProcessingScope readOnlyTxProcessingEnv, @@ -46,15 +49,6 @@ public BlockProductionTransactionsExecutor( { } - public BlockProductionTransactionsExecutor(ITransactionProcessor txProcessor, IWorldState stateProvider, - IBlockProductionTransactionPicker txPicker, ILogManager logManager) - { - _transactionProcessor = new BuildUpTransactionProcessorAdapter(txProcessor); - _stateProvider = stateProvider; - _blockProductionTransactionPicker = txPicker; - _logger = logManager.GetClassLogger(); - } - protected EventHandler? _transactionProcessed; event EventHandler? IBlockProcessor.IBlockTransactionsExecutor.TransactionProcessed @@ -65,8 +59,8 @@ event EventHandler? IBlockProcessor.IBlockTransactionsExec event EventHandler? IBlockProductionTransactionsExecutor.AddingTransaction { - add => _blockProductionTransactionPicker.AddingTransaction += value; - remove => _blockProductionTransactionPicker.AddingTransaction -= value; + add => txPicker.AddingTransaction += value; + remove => txPicker.AddingTransaction -= value; } public virtual TxReceipt[] ProcessTransactions(Block block, ProcessingOptions processingOptions, @@ -83,7 +77,7 @@ public virtual TxReceipt[] ProcessTransactions(Block block, ProcessingOptions pr if (action == TxAction.Stop) break; } - _stateProvider.Commit(spec, receiptsTracer); + stateProvider.Commit(spec, receiptsTracer); SetTransactions(block, transactionsInBlock); return receiptsTracer.TxReceipts.ToArray(); @@ -99,9 +93,7 @@ protected TxAction ProcessTransaction( LinkedHashSet transactionsInBlock, bool addToBlock = true) { - AddingTxEventArgs args = - _blockProductionTransactionPicker.CanAddTransaction(block, currentTx, transactionsInBlock, - _stateProvider); + AddingTxEventArgs args = txPicker.CanAddTransaction(block, currentTx, transactionsInBlock, stateProvider); if (args.Action != TxAction.Add) { @@ -109,7 +101,7 @@ protected TxAction ProcessTransaction( } else { - TransactionResult result = _transactionProcessor.ProcessTransaction(in blkCtx, currentTx, receiptsTracer, processingOptions, _stateProvider); + TransactionResult result = _transactionProcessor.ProcessTransaction(in blkCtx, currentTx, receiptsTracer, processingOptions, stateProvider); if (result) { diff --git a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs index 0908e40db32..7a2b7a6dfa9 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs @@ -9,10 +9,10 @@ using System.Threading; using System.Threading.Tasks; using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Blockchain.Find; using Nethermind.Blockchain.Receipts; -using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Rewards; using Nethermind.Consensus.Validators; using Nethermind.Consensus.Withdrawals; @@ -30,57 +30,40 @@ namespace Nethermind.Consensus.Processing; -public partial class BlockProcessor : IBlockProcessor +public partial class BlockProcessor( + ISpecProvider? specProvider, + IBlockValidator? blockValidator, + IRewardCalculator? rewardCalculator, + IBlockProcessor.IBlockTransactionsExecutor? blockTransactionsExecutor, + IWorldState? stateProvider, + IReceiptStorage? receiptStorage, + IBlockhashStore? blockHashStore, + IBeaconBlockRootHandler? beaconBlockRootHandler, + ILogManager? logManager, + IWithdrawalProcessor? withdrawalProcessor = null, + IReceiptsRootCalculator? receiptsRootCalculator = null, + IBlockCachePreWarmer? preWarmer = null) + : IBlockProcessor { - private readonly ILogger _logger; - private readonly ISpecProvider _specProvider; - protected readonly IWorldState _stateProvider; - private readonly IReceiptStorage _receiptStorage; - private readonly IReceiptsRootCalculator _receiptsRootCalculator; - private readonly IWithdrawalProcessor _withdrawalProcessor; - private readonly IBeaconBlockRootHandler _beaconBlockRootHandler; - private readonly IBlockValidator _blockValidator; - private readonly IRewardCalculator _rewardCalculator; - private readonly IBlockProcessor.IBlockTransactionsExecutor _blockTransactionsExecutor; - private readonly IBlockhashStore _blockhashStore; - private readonly IBlockCachePreWarmer? _preWarmer; + private readonly ILogger _logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager)); + private readonly ISpecProvider _specProvider = specProvider ?? throw new ArgumentNullException(nameof(specProvider)); + protected readonly IWorldState _stateProvider = stateProvider ?? throw new ArgumentNullException(nameof(stateProvider)); + private readonly IReceiptStorage _receiptStorage = receiptStorage ?? throw new ArgumentNullException(nameof(receiptStorage)); + private readonly IReceiptsRootCalculator _receiptsRootCalculator = receiptsRootCalculator ?? ReceiptsRootCalculator.Instance; + private readonly IWithdrawalProcessor _withdrawalProcessor = withdrawalProcessor ?? new WithdrawalProcessor(stateProvider, logManager); + private readonly IBeaconBlockRootHandler _beaconBlockRootHandler = beaconBlockRootHandler ?? throw new ArgumentNullException(nameof(beaconBlockRootHandler)); + private readonly IBlockValidator _blockValidator = blockValidator ?? throw new ArgumentNullException(nameof(blockValidator)); + private readonly IRewardCalculator _rewardCalculator = rewardCalculator ?? throw new ArgumentNullException(nameof(rewardCalculator)); + private readonly IBlockProcessor.IBlockTransactionsExecutor _blockTransactionsExecutor = blockTransactionsExecutor ?? throw new ArgumentNullException(nameof(blockTransactionsExecutor)); + private readonly IBlockhashStore _blockhashStore = blockHashStore ?? throw new ArgumentNullException(nameof(blockHashStore)); private const int MaxUncommittedBlocks = 64; + private readonly Func _clearCaches = _ => preWarmer.ClearCachesInBackground(); /// /// We use a single receipt tracer for all blocks. Internally receipt tracer forwards most of the calls /// to any block-specific tracers. /// - protected BlockReceiptsTracer ReceiptsTracer { get; set; } - private readonly Func _clearCaches; - - public BlockProcessor( - ISpecProvider? specProvider, - IBlockValidator? blockValidator, - IRewardCalculator? rewardCalculator, - IBlockProcessor.IBlockTransactionsExecutor? blockTransactionsExecutor, - IWorldState? stateProvider, - IReceiptStorage? receiptStorage, - IBlockhashStore? blockHashStore, - ILogManager? logManager, - IWithdrawalProcessor? withdrawalProcessor = null, - IReceiptsRootCalculator? receiptsRootCalculator = null, - IBlockCachePreWarmer? preWarmer = null) - { - _logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager)); - _specProvider = specProvider ?? throw new ArgumentNullException(nameof(specProvider)); - _blockValidator = blockValidator ?? throw new ArgumentNullException(nameof(blockValidator)); - _stateProvider = stateProvider ?? throw new ArgumentNullException(nameof(stateProvider)); - _receiptStorage = receiptStorage ?? throw new ArgumentNullException(nameof(receiptStorage)); - _withdrawalProcessor = withdrawalProcessor ?? new WithdrawalProcessor(stateProvider, logManager); - _rewardCalculator = rewardCalculator ?? throw new ArgumentNullException(nameof(rewardCalculator)); - _blockTransactionsExecutor = blockTransactionsExecutor ?? throw new ArgumentNullException(nameof(blockTransactionsExecutor)); - _receiptsRootCalculator = receiptsRootCalculator ?? ReceiptsRootCalculator.Instance; - _blockhashStore = blockHashStore ?? throw new ArgumentNullException(nameof(blockHashStore)); - _preWarmer = preWarmer; - _beaconBlockRootHandler = new BeaconBlockRootHandler(); - ReceiptsTracer = new BlockReceiptsTracer(); - _clearCaches = _ => _preWarmer.ClearCachesInBackground(); - } + protected BlockReceiptsTracer ReceiptsTracer { get; set; } = new(); public event EventHandler? BlockProcessed; @@ -122,7 +105,7 @@ the previous head state.*/ using CancellationTokenSource cancellationTokenSource = new(); Task? preWarmTask = suggestedBlock.Transactions.Length < 3 ? null - : _preWarmer?.PreWarmCaches(suggestedBlock, preBlockStateRoot!, cancellationTokenSource.Token); + : preWarmer?.PreWarmCaches(suggestedBlock, preBlockStateRoot!, cancellationTokenSource.Token); (Block processedBlock, TxReceipt[] receipts) = ProcessOne(suggestedBlock, options, blockTracer); // Block is processed, we can cancel the prewarm task if (preWarmTask is not null) @@ -173,7 +156,7 @@ the previous head state.*/ } finally { - _preWarmer?.ClearCaches(); + preWarmer?.ClearCaches(); } } @@ -264,9 +247,8 @@ protected virtual TxReceipt[] ProcessBlock( ReceiptsTracer.SetOtherTracer(blockTracer); ReceiptsTracer.StartNewBlockTrace(block); - _beaconBlockRootHandler.ApplyContractStateChanges(block, spec, _stateProvider); + StoreBeaconRoot(block, spec); _blockhashStore.ApplyBlockhashStateChanges(block.Header); - _stateProvider.Commit(spec, commitStorageRoots: false); TxReceipt[] receipts = _blockTransactionsExecutor.ProcessTransactions(block, options, ReceiptsTracer, spec); @@ -300,6 +282,18 @@ protected virtual TxReceipt[] ProcessBlock( return receipts; } + private void StoreBeaconRoot(Block block, IReleaseSpec spec) + { + try + { + _beaconBlockRootHandler.StoreBeaconRoot(block, spec); + } + catch (Exception e) + { + if (_logger.IsWarn) _logger.Warn($"Storing beacon block root for block {block.ToString(Block.Format.FullHashAndNumber)} failed: {e}"); + } + } + // TODO: block processor pipeline private void StoreTxReceipts(Block block, TxReceipt[] txReceipts) { diff --git a/src/Nethermind/Nethermind.Consensus/Processing/IBlockProcessor.cs b/src/Nethermind/Nethermind.Consensus/Processing/IBlockProcessor.cs index 88aba737926..8b2af1574b7 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/IBlockProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/IBlockProcessor.cs @@ -7,6 +7,7 @@ using Nethermind.Core.Crypto; using Nethermind.Core.Specs; using Nethermind.Evm.Tracing; +using Nethermind.Evm.TransactionProcessing; namespace Nethermind.Consensus.Processing { diff --git a/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyChainProcessingEnv.cs b/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyChainProcessingEnv.cs index f4bc42832c2..48d1c0a22fa 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyChainProcessingEnv.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyChainProcessingEnv.cs @@ -3,6 +3,7 @@ using System; using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Blockchain.Receipts; using Nethermind.Consensus.Rewards; @@ -68,6 +69,7 @@ IBlockProcessor.IBlockTransactionsExecutor transactionsExecutor scope.WorldState, receiptStorage, new BlockhashStore(specProvider, scope.WorldState), + new BeaconBlockRootHandler(scope.TransactionProcessor), logManager); } diff --git a/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyTxProcessingEnv.cs b/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyTxProcessingEnv.cs index 183a594d6d0..5e7d4ea28da 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyTxProcessingEnv.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyTxProcessingEnv.cs @@ -56,10 +56,8 @@ public ReadOnlyTxProcessingEnv( _logManager = logManager; } - protected virtual TransactionProcessor CreateTransactionProcessor() - { - return new TransactionProcessor(SpecProvider, StateProvider, Machine, CodeInfoRepository, _logManager); - } + protected virtual ITransactionProcessor CreateTransactionProcessor() => + new TransactionProcessor(SpecProvider, StateProvider, Machine, CodeInfoRepository, _logManager); public IReadOnlyTxProcessingScope Build(Hash256 stateRoot) { diff --git a/src/Nethermind/Nethermind.Consensus/Processing/TransactionProcessorAdapterExtensions.cs b/src/Nethermind/Nethermind.Consensus/Processing/TransactionProcessorAdapterExtensions.cs index bd569caf479..f0dbbdcd45e 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/TransactionProcessorAdapterExtensions.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/TransactionProcessorAdapterExtensions.cs @@ -18,7 +18,7 @@ public static TransactionResult ProcessTransaction(this ITransactionProcessorAda ProcessingOptions processingOptions, IWorldState stateProvider) { - if (processingOptions.ContainsFlag(ProcessingOptions.DoNotVerifyNonce)) + if (processingOptions.ContainsFlag(ProcessingOptions.DoNotVerifyNonce) && currentTx.SenderAddress != Address.SystemUser) { currentTx.Nonce = stateProvider.GetNonce(currentTx.SenderAddress!); } diff --git a/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerEnvFactory.cs b/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerEnvFactory.cs index a2c71caa342..01561beb4ce 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerEnvFactory.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerEnvFactory.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Blockchain.Receipts; using Nethermind.Config; @@ -141,7 +142,8 @@ protected virtual BlockProcessor CreateBlockProcessor( IBlockValidator blockValidator, IRewardCalculatorSource rewardCalculatorSource, IReceiptStorage receiptStorage, - ILogManager logManager, IBlocksConfig blocksConfig) => + ILogManager logManager, + IBlocksConfig blocksConfig) => new(specProvider, blockValidator, rewardCalculatorSource.Get(readOnlyTxProcessingEnv.TransactionProcessor), @@ -149,6 +151,7 @@ protected virtual BlockProcessor CreateBlockProcessor( readOnlyTxProcessingEnv.WorldState, receiptStorage, new BlockhashStore(_specProvider, readOnlyTxProcessingEnv.WorldState), + new BeaconBlockRootHandler(readOnlyTxProcessingEnv.TransactionProcessor), logManager, new BlockProductionWithdrawalProcessor(new WithdrawalProcessor(readOnlyTxProcessingEnv.WorldState, logManager))); diff --git a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs index 97978d42447..f93aa06571f 100644 --- a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs +++ b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs @@ -6,6 +6,7 @@ using System.Threading; using System.Threading.Tasks; using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Blockchain.Find; using Nethermind.Blockchain.FullPruning; @@ -14,7 +15,6 @@ using Nethermind.Blockchain.Synchronization; using Nethermind.Config; using Nethermind.Consensus; -using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Comparers; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Producers; @@ -159,7 +159,7 @@ protected virtual async Task Build(ISpecProvider? specProvider = State.CommitTree(0); ReadOnlyTrieStore = TrieStore.AsReadOnly(new NodeStorage(StateDb)); - WorldStateManager = new WorldStateManager(State, TrieStore, DbProvider, LimboLogs.Instance); + WorldStateManager = new WorldStateManager(State, TrieStore, DbProvider, LogManager); StateReader = new StateReader(ReadOnlyTrieStore, CodeDb, LogManager); ChainLevelInfoRepository = new ChainLevelInfoRepository(this.DbProvider.BlockInfosDb); @@ -172,7 +172,7 @@ protected virtual async Task Build(ISpecProvider? specProvider = SpecProvider, NullBloomStorage.Instance, new SyncConfig(), - LimboLogs.Instance); + LogManager); ReadOnlyState = new ChainHeadReadOnlyStateProvider(BlockTree, StateReader); TransactionComparerProvider = new TransactionComparerProvider(SpecProvider, BlockTree); @@ -208,7 +208,7 @@ protected virtual async Task Build(ISpecProvider? specProvider = BloomStorage bloomStorage = new(new BloomConfig(), new MemDb(), new InMemoryDictionaryFileStoreFactory()); ReceiptsRecovery receiptsRecovery = new(new EthereumEcdsa(SpecProvider.ChainId), SpecProvider); LogFinder = new LogFinder(BlockTree, ReceiptStorage, ReceiptStorage, bloomStorage, LimboLogs.Instance, receiptsRecovery); - BeaconBlockRootHandler = new BeaconBlockRootHandler(); + BeaconBlockRootHandler = new BeaconBlockRootHandler(TxProcessor); BlockProcessor = CreateBlockProcessor(); BlockchainProcessor chainProcessor = new(BlockTree, BlockProcessor, BlockPreprocessorStep, StateReader, LogManager, Consensus.Processing.BlockchainProcessor.Options.Default); @@ -325,8 +325,7 @@ protected virtual TxPoolTxSource CreateTxPoolTxSource() { MinGasPrice = 0 }; - ITxFilterPipeline txFilterPipeline = TxFilterPipelineBuilder.CreateStandardFilteringPipeline(LimboLogs.Instance, - SpecProvider, blocksConfig); + ITxFilterPipeline txFilterPipeline = TxFilterPipelineBuilder.CreateStandardFilteringPipeline(LogManager, SpecProvider, blocksConfig); return new TxPoolTxSource(TxPool, SpecProvider, TransactionComparerProvider, LogManager, txFilterPipeline); } @@ -377,6 +376,7 @@ protected virtual IBlockProcessor CreateBlockProcessor() => State, ReceiptStorage, new BlockhashStore(SpecProvider, State), + new BeaconBlockRootHandler(TxProcessor), LogManager, preWarmer: CreateBlockCachePreWarmer()); diff --git a/src/Nethermind/Nethermind.Core.Test/FixedBlockChainHeadSpecProvider.cs b/src/Nethermind/Nethermind.Core.Test/FixedBlockChainHeadSpecProvider.cs index 4fd8524bcca..7030287b6ef 100644 --- a/src/Nethermind/Nethermind.Core.Test/FixedBlockChainHeadSpecProvider.cs +++ b/src/Nethermind/Nethermind.Core.Test/FixedBlockChainHeadSpecProvider.cs @@ -6,38 +6,32 @@ namespace Nethermind.Core.Test { - public class FixedForkActivationChainHeadSpecProvider : IChainHeadSpecProvider + public class FixedForkActivationChainHeadSpecProvider( + ISpecProvider specProvider, + long fixedBlock = 10_000_000, + ulong? timestamp = null) + : IChainHeadSpecProvider { public void UpdateMergeTransitionInfo(long? blockNumber, UInt256? terminalTotalDifficulty = null) { - _specProvider.UpdateMergeTransitionInfo(blockNumber, terminalTotalDifficulty); + specProvider.UpdateMergeTransitionInfo(blockNumber, terminalTotalDifficulty); } - public ForkActivation? MergeBlockNumber => _specProvider.MergeBlockNumber; - public ulong TimestampFork => _specProvider.TimestampFork; - public UInt256? TerminalTotalDifficulty => _specProvider.TerminalTotalDifficulty; - private readonly ISpecProvider _specProvider; - private readonly long _fixedBlock; - private readonly ulong? _timestamp; + public ForkActivation? MergeBlockNumber => specProvider.MergeBlockNumber; + public ulong TimestampFork => specProvider.TimestampFork; + public UInt256? TerminalTotalDifficulty => specProvider.TerminalTotalDifficulty; - public FixedForkActivationChainHeadSpecProvider(ISpecProvider specProvider, long fixedBlock = 10_000_000, ulong? timestamp = null) - { - _specProvider = specProvider; - _fixedBlock = fixedBlock; - _timestamp = timestamp; - } - - public IReleaseSpec GenesisSpec => _specProvider.GenesisSpec; + public IReleaseSpec GenesisSpec => specProvider.GenesisSpec; - public IReleaseSpec GetSpec(ForkActivation forkActivation) => _specProvider.GetSpec(forkActivation); + public IReleaseSpec GetSpec(ForkActivation forkActivation) => specProvider.GetSpec(forkActivation); - public long? DaoBlockNumber => _specProvider.DaoBlockNumber; + public long? DaoBlockNumber => specProvider.DaoBlockNumber; - public ulong NetworkId => _specProvider.NetworkId; - public ulong ChainId => _specProvider.ChainId; + public ulong NetworkId => specProvider.NetworkId; + public ulong ChainId => specProvider.ChainId; - public ForkActivation[] TransitionActivations => _specProvider.TransitionActivations; + public ForkActivation[] TransitionActivations => specProvider.TransitionActivations; - public IReleaseSpec GetCurrentHeadSpec() => GetSpec((_fixedBlock, _timestamp)); + public IReleaseSpec GetCurrentHeadSpec() => GetSpec((fixedBlock, timestamp)); } } diff --git a/src/Nethermind/Nethermind.Core/Eip4788Constants.cs b/src/Nethermind/Nethermind.Core/Eip4788Constants.cs index 6b74dd2a245..9097397d58f 100644 --- a/src/Nethermind/Nethermind.Core/Eip4788Constants.cs +++ b/src/Nethermind/Nethermind.Core/Eip4788Constants.cs @@ -14,9 +14,4 @@ public static class Eip4788Constants /// Gets the BEACON_ROOTS_ADDRESS parameter. /// public static readonly Address BeaconRootsAddress = new("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02"); - - /// - /// Gets the HISTORY_BUFFER_LENGTH parameter. - /// - public static readonly UInt256 HistoryBufferLength = 8191; } diff --git a/src/Nethermind/Nethermind.Core/Specs/AuraSpecProvider.cs b/src/Nethermind/Nethermind.Core/Specs/AuraSpecProvider.cs new file mode 100644 index 00000000000..0fa1f8a7dfd --- /dev/null +++ b/src/Nethermind/Nethermind.Core/Specs/AuraSpecProvider.cs @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using Nethermind.Int256; + +namespace Nethermind.Core.Specs; + +public class AuraSpecProvider(IReleaseSpec spec) : ReleaseSpecDecorator(spec) +{ + public override bool IsEip158IgnoredAccount(Address address) => address == Address.SystemUser; +} diff --git a/src/Nethermind/Nethermind.Core/Specs/ForkActivation.cs b/src/Nethermind/Nethermind.Core/Specs/ForkActivation.cs index 4ebb6f02460..7965f6390b2 100644 --- a/src/Nethermind/Nethermind.Core/Specs/ForkActivation.cs +++ b/src/Nethermind/Nethermind.Core/Specs/ForkActivation.cs @@ -5,18 +5,13 @@ namespace Nethermind.Core.Specs; -public readonly struct ForkActivation : IEquatable, IComparable +public readonly struct ForkActivation(long blockNumber, ulong? timestamp = null) + : IEquatable, IComparable { - public long BlockNumber { get; } - public ulong? Timestamp { get; } + public long BlockNumber { get; } = blockNumber; + public ulong? Timestamp { get; } = timestamp; public ulong Activation => Timestamp ?? (ulong)BlockNumber; - public ForkActivation(long blockNumber, ulong? timestamp = null) - { - BlockNumber = blockNumber; - Timestamp = timestamp; - } - /// /// Fork activation for forks past The Merge/Paris /// diff --git a/src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs b/src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs index 2762f4c0460..a2e7a87cec3 100644 --- a/src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs +++ b/src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs @@ -202,7 +202,7 @@ public interface IReleaseSpec : IEip1559Spec, IReceiptSpec /// THis is needed for SystemUser account compatibility with Parity. /// /// - bool IsEip158IgnoredAccount(Address address); + bool IsEip158IgnoredAccount(Address address) => false; /// /// BaseFee opcode diff --git a/src/Nethermind/Nethermind.Core/Specs/ISpecProvider.cs b/src/Nethermind/Nethermind.Core/Specs/ISpecProvider.cs index 3374e4c1733..15b13965d91 100644 --- a/src/Nethermind/Nethermind.Core/Specs/ISpecProvider.cs +++ b/src/Nethermind/Nethermind.Core/Specs/ISpecProvider.cs @@ -62,6 +62,11 @@ public interface ISpecProvider /// ulong ChainId { get; } + /// + /// Original engine of the chain + /// + string SealEngine => SealEngineType.Ethash; + /// /// All block numbers at which a change in spec (a fork) happens. /// @@ -72,17 +77,26 @@ public interface ISpecProvider /// /// /// A spec that is valid at the given chain height - IReleaseSpec GetSpec(ForkActivation forkActivation); - IReleaseSpec GetSpec(long blockNumber, ulong? timestamp) => GetSpec((blockNumber, timestamp)); - IReleaseSpec GetSpec(BlockHeader blockHeader) => GetSpec((blockHeader.Number, blockHeader.Timestamp)); + protected internal IReleaseSpec GetSpec(ForkActivation forkActivation); + } + + public static class SpecProviderExtensions + { + public static IReleaseSpec GetSpec(this ISpecProvider specProvider, ForkActivation forkActivation) + => specProvider.SealEngine == SealEngineType.AuRa + ? new AuraSpecProvider(specProvider.GetSpec(forkActivation)) + : specProvider.GetSpec(forkActivation); + + public static IReleaseSpec GetSpec(this ISpecProvider specProvider, long blockNumber, ulong? timestamp) => specProvider.GetSpec(new ForkActivation(blockNumber, timestamp)); + public static IReleaseSpec GetSpec(this ISpecProvider specProvider, BlockHeader blockHeader) => specProvider.GetSpec(new ForkActivation(blockHeader.Number, blockHeader.Timestamp)); /// /// Resolves a spec for all planned forks applied. /// - /// A spec for all planned forks appliedA spec for all planned forks applied /// The default value is long.MaxValue for block numbers and ulong.MaxValue for timestamps /// for every new not yet scheduled EIP. Because of that we can't use long.MaxValue and /// ulong.MaxValue for GetFinalSpec that is why we have long.MaxValue-1, ulong.MaxValue-1 - IReleaseSpec GetFinalSpec() => GetSpec(long.MaxValue - 1, ulong.MaxValue - 1); + public static IReleaseSpec GetFinalSpec(this ISpecProvider specProvider) => specProvider.GetSpec(long.MaxValue - 1, ulong.MaxValue - 1); } } diff --git a/src/Nethermind/Nethermind.Core/Specs/ReleaseSpecDecorator.cs b/src/Nethermind/Nethermind.Core/Specs/ReleaseSpecDecorator.cs new file mode 100644 index 00000000000..3ef10dc0c72 --- /dev/null +++ b/src/Nethermind/Nethermind.Core/Specs/ReleaseSpecDecorator.cs @@ -0,0 +1,78 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using Nethermind.Int256; + +namespace Nethermind.Core.Specs; + +public class ReleaseSpecDecorator(IReleaseSpec spec) : IReleaseSpec +{ + public virtual bool IsEip1559Enabled => spec.IsEip1559Enabled; + public virtual long Eip1559TransitionBlock => spec.Eip1559TransitionBlock; + public virtual UInt256 ForkBaseFee => spec.ForkBaseFee; + public virtual UInt256 BaseFeeMaxChangeDenominator => spec.BaseFeeMaxChangeDenominator; + public virtual long ElasticityMultiplier => spec.ElasticityMultiplier; + public virtual bool IsEip658Enabled => spec.IsEip658Enabled; + public virtual string Name => spec.Name; + public virtual long MaximumExtraDataSize => spec.MaximumExtraDataSize; + public virtual long MaxCodeSize => spec.MaxCodeSize; + public virtual long MinGasLimit => spec.MinGasLimit; + public virtual long GasLimitBoundDivisor => spec.GasLimitBoundDivisor; + public virtual UInt256 BlockReward => spec.BlockReward; + public virtual long DifficultyBombDelay => spec.DifficultyBombDelay; + public virtual long DifficultyBoundDivisor => spec.DifficultyBoundDivisor; + public virtual long? FixedDifficulty => spec.FixedDifficulty; + public virtual int MaximumUncleCount => spec.MaximumUncleCount; + public virtual bool IsTimeAdjustmentPostOlympic => spec.IsTimeAdjustmentPostOlympic; + public virtual bool IsEip2Enabled => spec.IsEip2Enabled; + public virtual bool IsEip7Enabled => spec.IsEip7Enabled; + public virtual bool IsEip100Enabled => spec.IsEip100Enabled; + public virtual bool IsEip140Enabled => spec.IsEip140Enabled; + public virtual bool IsEip150Enabled => spec.IsEip150Enabled; + public virtual bool IsEip155Enabled => spec.IsEip155Enabled; + public virtual bool IsEip158Enabled => spec.IsEip158Enabled; + public virtual bool IsEip160Enabled => spec.IsEip160Enabled; + public virtual bool IsEip170Enabled => spec.IsEip170Enabled; + public virtual bool IsEip196Enabled => spec.IsEip196Enabled; + public virtual bool IsEip197Enabled => spec.IsEip197Enabled; + public virtual bool IsEip198Enabled => spec.IsEip198Enabled; + public virtual bool IsEip211Enabled => spec.IsEip211Enabled; + public virtual bool IsEip214Enabled => spec.IsEip214Enabled; + public virtual bool IsEip649Enabled => spec.IsEip649Enabled; + public virtual bool IsEip145Enabled => spec.IsEip145Enabled; + public virtual bool IsEip1014Enabled => spec.IsEip1014Enabled; + public virtual bool IsEip1052Enabled => spec.IsEip1052Enabled; + public virtual bool IsEip1283Enabled => spec.IsEip1283Enabled; + public virtual bool IsEip1234Enabled => spec.IsEip1234Enabled; + public virtual bool IsEip1344Enabled => spec.IsEip1344Enabled; + public virtual bool IsEip2028Enabled => spec.IsEip2028Enabled; + public virtual bool IsEip152Enabled => spec.IsEip152Enabled; + public virtual bool IsEip1108Enabled => spec.IsEip1108Enabled; + public virtual bool IsEip1884Enabled => spec.IsEip1884Enabled; + public virtual bool IsEip2200Enabled => spec.IsEip2200Enabled; + public virtual bool IsEip2537Enabled => spec.IsEip2537Enabled; + public virtual bool IsEip2565Enabled => spec.IsEip2565Enabled; + public virtual bool IsEip2929Enabled => spec.IsEip2929Enabled; + public virtual bool IsEip2930Enabled => spec.IsEip2930Enabled; + public virtual bool IsEip3198Enabled => spec.IsEip3198Enabled; + public virtual bool IsEip3529Enabled => spec.IsEip3529Enabled; + public virtual bool IsEip3541Enabled => spec.IsEip3541Enabled; + public virtual bool IsEip3607Enabled => spec.IsEip3607Enabled; + public virtual bool IsEip3651Enabled => spec.IsEip3651Enabled; + public virtual bool IsEip1153Enabled => spec.IsEip1153Enabled; + public virtual bool IsEip3855Enabled => spec.IsEip3855Enabled; + public virtual bool IsEip5656Enabled => spec.IsEip5656Enabled; + public virtual bool IsEip3860Enabled => spec.IsEip3860Enabled; + public virtual bool IsEip4895Enabled => spec.IsEip4895Enabled; + public virtual bool IsEip4844Enabled => spec.IsEip4844Enabled; + public virtual bool IsEip4788Enabled => spec.IsEip4788Enabled; + public virtual Address Eip4788ContractAddress => spec.Eip4788ContractAddress; + public virtual bool IsEip2935Enabled => spec.IsEip2935Enabled; + public virtual bool IsEip7709Enabled => spec.IsEip7709Enabled; + public virtual Address Eip2935ContractAddress => spec.Eip2935ContractAddress; + public virtual bool IsEip6780Enabled => spec.IsEip6780Enabled; + public virtual bool IsRip7212Enabled => spec.IsRip7212Enabled; + public virtual ulong WithdrawalTimestamp => spec.WithdrawalTimestamp; + public virtual ulong Eip4844TransitionTimestamp => spec.Eip4844TransitionTimestamp; + public virtual bool IsEip158IgnoredAccount(Address address) => spec.IsEip158IgnoredAccount(address); +} diff --git a/src/Nethermind/Nethermind.Ethash.Test/DifficultyCalculatorTests.cs b/src/Nethermind/Nethermind.Ethash.Test/DifficultyCalculatorTests.cs index 5266141b0bc..a07299cd280 100644 --- a/src/Nethermind/Nethermind.Ethash.Test/DifficultyCalculatorTests.cs +++ b/src/Nethermind/Nethermind.Ethash.Test/DifficultyCalculatorTests.cs @@ -23,8 +23,6 @@ public void Calculate_should_returns_expected_results() releaseSpec.IsEip100Enabled.Returns(true); releaseSpec.IsTimeAdjustmentPostOlympic.Returns(true); ISpecProvider specProvider = Substitute.For(); - specProvider.GetSpec(Arg.Any(), Arg.Any()).Returns(releaseSpec); - specProvider.GetSpec(Arg.Any()).Returns(releaseSpec); specProvider.GetSpec(Arg.Any()).Returns(releaseSpec); EthashDifficultyCalculator difficultyCalculator = new(specProvider); UInt256 result = difficultyCalculator.Calculate(0x55f78f7, 1613570258, 0x602d20d2, 200000, false); @@ -36,8 +34,6 @@ public void Calculate_should_returns_expected_results() public void CalculateOlympic_should_returns_expected_results() { ISpecProvider specProvider = Substitute.For(); - specProvider.GetSpec(Arg.Any(), Arg.Any()).Returns(Olympic.Instance); - specProvider.GetSpec(Arg.Any()).Returns(Olympic.Instance); specProvider.GetSpec(Arg.Any()).Returns(Olympic.Instance); EthashDifficultyCalculator difficultyCalculator = new(specProvider); UInt256 result = difficultyCalculator.Calculate(0x55f78f7, 1613570258, 0x602d20d2, 200000, false); @@ -48,8 +44,6 @@ public void CalculateOlympic_should_returns_expected_results() public void CalculateBerlin_should_returns_expected_results() { ISpecProvider specProvider = Substitute.For(); - specProvider.GetSpec(Arg.Any(), Arg.Any()).Returns(Berlin.Instance); - specProvider.GetSpec(Arg.Any()).Returns(Berlin.Instance); specProvider.GetSpec(Arg.Any()).Returns(Berlin.Instance); EthashDifficultyCalculator difficultyCalculator = new(specProvider); UInt256 result = difficultyCalculator.Calculate(0x55f78f7, 1613570258, 0x602d20d2, 200000, false); @@ -93,15 +87,11 @@ private void Calculation_should_not_be_equal_on_different_difficulty_hard_forks( ulong parentTimestamp = 1613570258; ulong currentTimestamp = 0x602d20d2; ISpecProvider firstHardForkSpecProvider = Substitute.For(); - firstHardForkSpecProvider.GetSpec(Arg.Any(), Arg.Any()).Returns(firstHardfork); - firstHardForkSpecProvider.GetSpec(Arg.Any()).Returns(firstHardfork); firstHardForkSpecProvider.GetSpec(Arg.Any()).Returns(firstHardfork); EthashDifficultyCalculator firstHardforkDifficultyCalculator = new(firstHardForkSpecProvider); UInt256 firstHardforkResult = firstHardforkDifficultyCalculator.Calculate(parentDifficulty, parentTimestamp, currentTimestamp, blocksAbove, false); ISpecProvider secondHardforkSpecProvider = Substitute.For(); - secondHardforkSpecProvider.GetSpec(Arg.Any(), Arg.Any()).Returns(secondHardfork); - secondHardforkSpecProvider.GetSpec(Arg.Any()).Returns(secondHardfork); secondHardforkSpecProvider.GetSpec(Arg.Any()).Returns(secondHardfork); EthashDifficultyCalculator secondHardforkDifficultyCalculator = new(secondHardforkSpecProvider); UInt256 secondHardforkResult = secondHardforkDifficultyCalculator.Calculate(parentDifficulty, parentTimestamp, currentTimestamp, blocksAbove, false); diff --git a/src/Nethermind/Nethermind.Evm/Tracing/ITxTracer.cs b/src/Nethermind/Nethermind.Evm/Tracing/ITxTracer.cs index 4552b43b2d1..500b83e8e0c 100644 --- a/src/Nethermind/Nethermind.Evm/Tracing/ITxTracer.cs +++ b/src/Nethermind/Nethermind.Evm/Tracing/ITxTracer.cs @@ -169,7 +169,7 @@ public interface ITxTracer : IWorldStateTracer, IDisposable /// Error that failed the transaction /// State root after transaction, depends on EIP-658 /// Depends on - void MarkAsFailed(Address recipient, long gasSpent, byte[] output, string error, Hash256? stateRoot = null); + void MarkAsFailed(Address recipient, long gasSpent, byte[] output, string? error, Hash256? stateRoot = null); /// /// diff --git a/src/Nethermind/Nethermind.Evm/Tracing/Proofs/ProofTxTracer.cs b/src/Nethermind/Nethermind.Evm/Tracing/Proofs/ProofTxTracer.cs index 79b6de32165..3fcc82c3bdf 100644 --- a/src/Nethermind/Nethermind.Evm/Tracing/Proofs/ProofTxTracer.cs +++ b/src/Nethermind/Nethermind.Evm/Tracing/Proofs/ProofTxTracer.cs @@ -80,18 +80,8 @@ public override void ReportStorageRead(in StorageCell storageCell) Storages.Add(storageCell); } - private bool _wasSystemAccountAccessedOnceAlready; - public override void ReportAccountRead(Address address) { - if (_treatSystemAccountDifferently && !_wasSystemAccountAccessedOnceAlready && address == Address.SystemUser) - { - // we want to ignore the system account the first time only - // TODO: I think this should only be done if the system account should be treated differently? - _wasSystemAccountAccessedOnceAlready = true; - return; - } - Accounts.Add(address); } diff --git a/src/Nethermind/Nethermind.Evm/TransactionExtensions.cs b/src/Nethermind/Nethermind.Evm/TransactionExtensions.cs index 5bba6aace32..831fdd67d64 100644 --- a/src/Nethermind/Nethermind.Evm/TransactionExtensions.cs +++ b/src/Nethermind/Nethermind.Evm/TransactionExtensions.cs @@ -10,11 +10,9 @@ namespace Nethermind.Evm public static class TransactionExtensions { public static Address? GetRecipient(this Transaction tx, in UInt256 nonce) => - tx.To is not null - ? tx.To - : tx.IsSystem() - ? tx.SenderAddress - : ContractAddress.From(tx.SenderAddress, nonce > 0 ? nonce - 1 : nonce); + tx.To ?? (tx.IsSystem() + ? tx.SenderAddress + : ContractAddress.From(tx.SenderAddress, nonce > 0 ? nonce - 1 : nonce)); public static TxGasInfo GetGasInfo(this Transaction tx, bool is1559Enabled, BlockHeader header) { diff --git a/src/Nethermind/Nethermind.Evm/TransactionProcessing/CallAndRestoreTransactionProcessorAdapter.cs b/src/Nethermind/Nethermind.Evm/TransactionProcessing/CallAndRestoreTransactionProcessorAdapter.cs index 31232e3b7c6..46316db20c8 100644 --- a/src/Nethermind/Nethermind.Evm/TransactionProcessing/CallAndRestoreTransactionProcessorAdapter.cs +++ b/src/Nethermind/Nethermind.Evm/TransactionProcessing/CallAndRestoreTransactionProcessorAdapter.cs @@ -6,16 +6,10 @@ namespace Nethermind.Evm.TransactionProcessing { - public class CallAndRestoreTransactionProcessorAdapter : ITransactionProcessorAdapter + public class CallAndRestoreTransactionProcessorAdapter(ITransactionProcessor transactionProcessor) + : ITransactionProcessorAdapter { - private readonly ITransactionProcessor _transactionProcessor; - - public CallAndRestoreTransactionProcessorAdapter(ITransactionProcessor transactionProcessor) - { - _transactionProcessor = transactionProcessor; - } - public TransactionResult Execute(Transaction transaction, in BlockExecutionContext blkCtx, ITxTracer txTracer) => - _transactionProcessor.CallAndRestore(transaction, in blkCtx, txTracer); + transactionProcessor.CallAndRestore(transaction, in blkCtx, txTracer); } } diff --git a/src/Nethermind/Nethermind.Evm/TransactionProcessing/ExecuteTransactionProcessorAdapter.cs b/src/Nethermind/Nethermind.Evm/TransactionProcessing/ExecuteTransactionProcessorAdapter.cs index 729db62505e..8dc2274bc54 100644 --- a/src/Nethermind/Nethermind.Evm/TransactionProcessing/ExecuteTransactionProcessorAdapter.cs +++ b/src/Nethermind/Nethermind.Evm/TransactionProcessing/ExecuteTransactionProcessorAdapter.cs @@ -6,16 +6,10 @@ namespace Nethermind.Evm.TransactionProcessing { - public class ExecuteTransactionProcessorAdapter : ITransactionProcessorAdapter + public class ExecuteTransactionProcessorAdapter(ITransactionProcessor transactionProcessor) + : ITransactionProcessorAdapter { - private readonly ITransactionProcessor _transactionProcessor; - - public ExecuteTransactionProcessorAdapter(ITransactionProcessor transactionProcessor) - { - _transactionProcessor = transactionProcessor; - } - public TransactionResult Execute(Transaction transaction, in BlockExecutionContext blkCtx, ITxTracer txTracer) => - _transactionProcessor.Execute(transaction, in blkCtx, txTracer); + transactionProcessor.Execute(transaction, in blkCtx, txTracer); } } diff --git a/src/Nethermind/Nethermind.Evm/TransactionProcessing/SystemTransactionProcessor.cs b/src/Nethermind/Nethermind.Evm/TransactionProcessing/SystemTransactionProcessor.cs new file mode 100644 index 00000000000..1110dd289a1 --- /dev/null +++ b/src/Nethermind/Nethermind.Evm/TransactionProcessing/SystemTransactionProcessor.cs @@ -0,0 +1,71 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using Nethermind.Core; +using Nethermind.Core.Specs; +using Nethermind.Evm.Tracing; +using Nethermind.Int256; +using Nethermind.Logging; +using Nethermind.Specs; +using Nethermind.State; + +namespace Nethermind.Evm.TransactionProcessing; + +public sealed class SystemTransactionProcessor : TransactionProcessorBase +{ + private readonly bool _isAura; + + /// + /// Hacky flag to execution options, to pass information how original validate should behave. + /// Needed to decide if we need to subtract transaction value. + /// + private const int OriginalValidate = 2 << 30; + + public SystemTransactionProcessor(ISpecProvider? specProvider, + IWorldState? worldState, + IVirtualMachine? virtualMachine, + ICodeInfoRepository? codeInfoRepository, + ILogManager? logManager) + : base(specProvider, worldState, virtualMachine, codeInfoRepository, logManager) + { + _isAura = SpecProvider.SealEngine == SealEngineType.AuRa; + } + + protected override TransactionResult Execute(Transaction tx, in BlockExecutionContext blCtx, ITxTracer tracer, ExecutionOptions opts) + { + if (_isAura && !blCtx.Header.IsGenesis) + { + WorldState.CreateAccountIfNotExists(Address.SystemUser, UInt256.Zero, UInt256.Zero); + } + + return base.Execute(tx, in blCtx, tracer, !opts.HasFlag(ExecutionOptions.NoValidation) + ? opts | (ExecutionOptions)OriginalValidate | ExecutionOptions.NoValidation + : opts); + } + + + protected override IReleaseSpec GetSpec(Transaction tx, BlockHeader header) => new SystemTransactionReleaseSpec(base.GetSpec(tx, header), _isAura, header.IsGenesis); + + protected override TransactionResult ValidateGas(Transaction tx, BlockHeader header, long intrinsicGas, bool validate) => TransactionResult.Ok; + + protected override TransactionResult IncrementNonce(Transaction tx, BlockHeader header, IReleaseSpec spec, ITxTracer tracer, ExecutionOptions opts) => TransactionResult.Ok; + + protected override void DecrementNonce(Transaction tx) { } + + protected override void PayFees(Transaction tx, BlockHeader header, IReleaseSpec spec, ITxTracer tracer, in TransactionSubstate substate, in long spentGas, in UInt256 premiumPerGas, in byte statusCode) { } + + protected override void PayValue(Transaction tx, IReleaseSpec spec, ExecutionOptions opts) + { + if (opts.HasFlag((ExecutionOptions)OriginalValidate)) + { + base.PayValue(tx, spec, opts); + } + } + + protected override bool RecoverSenderIfNeeded(Transaction tx, IReleaseSpec spec, ExecutionOptions opts, in UInt256 effectiveGasPrice) + { + Address? sender = tx.SenderAddress; + return (sender is null || (spec.IsEip158IgnoredAccount(sender) && !WorldState.AccountExists(sender))) + && base.RecoverSenderIfNeeded(tx, spec, opts, in effectiveGasPrice); + } +} diff --git a/src/Nethermind/Nethermind.Evm/TransactionProcessing/TraceTransactionProcessorAdapter.cs b/src/Nethermind/Nethermind.Evm/TransactionProcessing/TraceTransactionProcessorAdapter.cs index f272308db25..12f2daf3168 100644 --- a/src/Nethermind/Nethermind.Evm/TransactionProcessing/TraceTransactionProcessorAdapter.cs +++ b/src/Nethermind/Nethermind.Evm/TransactionProcessing/TraceTransactionProcessorAdapter.cs @@ -6,16 +6,10 @@ namespace Nethermind.Evm.TransactionProcessing { - public class TraceTransactionProcessorAdapter : ITransactionProcessorAdapter + public class TraceTransactionProcessorAdapter(ITransactionProcessor transactionProcessor) + : ITransactionProcessorAdapter { - private readonly ITransactionProcessor _transactionProcessor; - - public TraceTransactionProcessorAdapter(ITransactionProcessor transactionProcessor) - { - _transactionProcessor = transactionProcessor; - } - public TransactionResult Execute(Transaction transaction, in BlockExecutionContext blkCtx, ITxTracer txTracer) => - _transactionProcessor.Trace(transaction, in blkCtx, txTracer); + transactionProcessor.Trace(transaction, in blkCtx, txTracer); } } diff --git a/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs b/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs index f01be3bfdeb..3e4a8c2fe4d 100644 --- a/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs +++ b/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs @@ -15,7 +15,6 @@ using Nethermind.Evm.Tracing; using Nethermind.Int256; using Nethermind.Logging; -using Nethermind.Specs; using Nethermind.State; using Nethermind.State.Tracing; using static Nethermind.Core.Extensions.MemoryExtensions; @@ -24,14 +23,24 @@ namespace Nethermind.Evm.TransactionProcessing { - public class TransactionProcessor : ITransactionProcessor + public sealed class TransactionProcessor( + ISpecProvider? specProvider, + IWorldState? worldState, + IVirtualMachine? virtualMachine, + ICodeInfoRepository? codeInfoRepository, + ILogManager? logManager) + : TransactionProcessorBase(specProvider, worldState, virtualMachine, codeInfoRepository, logManager); + + public abstract class TransactionProcessorBase : ITransactionProcessor { - protected EthereumEcdsa Ecdsa { get; private init; } - protected ILogger Logger { get; private init; } - protected ISpecProvider SpecProvider { get; private init; } - protected IWorldState WorldState { get; private init; } - protected IVirtualMachine VirtualMachine { get; private init; } + protected EthereumEcdsa Ecdsa { get; } + protected ILogger Logger { get; } + protected ISpecProvider SpecProvider { get; } + protected IWorldState WorldState { get; } + protected IVirtualMachine VirtualMachine { get; } private readonly ICodeInfoRepository _codeInfoRepository; + private SystemTransactionProcessor? _systemTransactionProcessor; + private readonly ILogManager _logManager; [Flags] protected enum ExecutionOptions @@ -62,7 +71,7 @@ protected enum ExecutionOptions CommitAndRestore = Commit | Restore | NoValidation } - public TransactionProcessor( + protected TransactionProcessorBase( ISpecProvider? specProvider, IWorldState? worldState, IVirtualMachine? virtualMachine, @@ -82,31 +91,41 @@ public TransactionProcessor( _codeInfoRepository = codeInfoRepository; Ecdsa = new EthereumEcdsa(specProvider.ChainId); + _logManager = logManager; } public TransactionResult CallAndRestore(Transaction transaction, in BlockExecutionContext blCtx, ITxTracer txTracer) => - Execute(transaction, in blCtx, txTracer, ExecutionOptions.CommitAndRestore); + ExecuteCore(transaction, in blCtx, txTracer, ExecutionOptions.CommitAndRestore); public TransactionResult BuildUp(Transaction transaction, in BlockExecutionContext blCtx, ITxTracer txTracer) { // we need to treat the result of previous transaction as the original value of next transaction // when we do not commit WorldState.TakeSnapshot(true); - return Execute(transaction, in blCtx, txTracer, ExecutionOptions.None); + return ExecuteCore(transaction, in blCtx, txTracer, ExecutionOptions.None); } public TransactionResult Execute(Transaction transaction, in BlockExecutionContext blCtx, ITxTracer txTracer) => - Execute(transaction, in blCtx, txTracer, ExecutionOptions.Commit); + ExecuteCore(transaction, in blCtx, txTracer, ExecutionOptions.Commit); public TransactionResult Trace(Transaction transaction, in BlockExecutionContext blCtx, ITxTracer txTracer) => - Execute(transaction, in blCtx, txTracer, ExecutionOptions.NoValidation); + ExecuteCore(transaction, in blCtx, txTracer, ExecutionOptions.NoValidation); + + private TransactionResult ExecuteCore(Transaction tx, in BlockExecutionContext blCtx, ITxTracer tracer, ExecutionOptions opts) + { + if (tx.IsSystem()) + { + _systemTransactionProcessor ??= new SystemTransactionProcessor(SpecProvider, WorldState, VirtualMachine, _codeInfoRepository, _logManager); + return _systemTransactionProcessor.Execute(tx, blCtx.Header, tracer, opts); + } + + return Execute(tx, in blCtx, tracer, opts); + } protected virtual TransactionResult Execute(Transaction tx, in BlockExecutionContext blCtx, ITxTracer tracer, ExecutionOptions opts) { BlockHeader header = blCtx.Header; - IReleaseSpec spec = SpecProvider.GetSpec(header); - if (tx.IsSystem()) - spec = new SystemTransactionReleaseSpec(spec); + IReleaseSpec spec = GetSpec(tx, header); // restore is CallAndRestore - previous call, we will restore state after the execution bool restore = opts.HasFlag(ExecutionOptions.Restore); @@ -116,7 +135,7 @@ protected virtual TransactionResult Execute(Transaction tx, in BlockExecutionCon bool commit = opts.HasFlag(ExecutionOptions.Commit) || !spec.IsEip658Enabled; TransactionResult result; - if (!(result = ValidateStatic(tx, header, spec, tracer, opts, out long intrinsicGas))) return result; + if (!(result = ValidateStatic(tx, header, spec, opts, out long intrinsicGas))) return result; UInt256 effectiveGasPrice = tx.CalculateEffectiveGasPrice(spec.IsEip1559Enabled, header.BaseFeePerGas); @@ -142,15 +161,13 @@ protected virtual TransactionResult Execute(Transaction tx, in BlockExecutionCon WorldState.Reset(); if (deleteCallerAccount) { - WorldState.DeleteAccount(tx.SenderAddress); + WorldState.DeleteAccount(tx.SenderAddress!); } else { if (!opts.HasFlag(ExecutionOptions.NoValidation)) - WorldState.AddToBalance(tx.SenderAddress, senderReservedGasPayment, spec); - if (!tx.IsSystem()) - WorldState.DecrementNonce(tx.SenderAddress); - + WorldState.AddToBalance(tx.SenderAddress!, senderReservedGasPayment, spec); + DecrementNonce(tx); WorldState.Commit(spec); } } @@ -183,6 +200,8 @@ protected virtual TransactionResult Execute(Transaction tx, in BlockExecutionCon return TransactionResult.Ok; } + protected virtual IReleaseSpec GetSpec(Transaction tx, BlockHeader header) => SpecProvider.GetSpec(header); + private static void UpdateMetrics(ExecutionOptions opts, UInt256 effectiveGasPrice) { if (opts is ExecutionOptions.Commit or ExecutionOptions.None && (effectiveGasPrice[2] | effectiveGasPrice[3]) == 0) @@ -214,11 +233,15 @@ private static void UpdateMetrics(ExecutionOptions opts, UInt256 effectiveGasPri /// The transaction to validate /// The block containing the transaction. Only BaseFee is being used from the block atm. /// The release spec with which the transaction will be executed - /// The transaction tracer /// Options (Flags) to use for execution - /// Computed premium per gas + /// Calculated intrinsic gas /// - protected virtual TransactionResult ValidateStatic(Transaction tx, BlockHeader header, IReleaseSpec spec, ITxTracer tracer, ExecutionOptions opts, out long intrinsicGas) + protected TransactionResult ValidateStatic( + Transaction tx, + BlockHeader header, + IReleaseSpec spec, + ExecutionOptions opts, + out long intrinsicGas) { intrinsicGas = IntrinsicGasCalculator.Calculate(tx, spec); @@ -247,36 +270,37 @@ protected virtual TransactionResult ValidateStatic(Transaction tx, BlockHeader h return "EIP-3860 - transaction size over max init code size"; } - if (!tx.IsSystem()) + return ValidateGas(tx, header, intrinsicGas, validate); + } + + protected virtual TransactionResult ValidateGas(Transaction tx, BlockHeader header, long intrinsicGas, bool validate) + { + if (tx.GasLimit < intrinsicGas) { - if (tx.GasLimit < intrinsicGas) - { - TraceLogInvalidTx(tx, $"GAS_LIMIT_BELOW_INTRINSIC_GAS {tx.GasLimit} < {intrinsicGas}"); - return "gas limit below intrinsic gas"; - } + TraceLogInvalidTx(tx, $"GAS_LIMIT_BELOW_INTRINSIC_GAS {tx.GasLimit} < {intrinsicGas}"); + return "gas limit below intrinsic gas"; + } - if (validate && tx.GasLimit > header.GasLimit - header.GasUsed) - { - TraceLogInvalidTx(tx, $"BLOCK_GAS_LIMIT_EXCEEDED {tx.GasLimit} > {header.GasLimit} - {header.GasUsed}"); - return "block gas limit exceeded"; - } + if (validate && tx.GasLimit > header.GasLimit - header.GasUsed) + { + TraceLogInvalidTx(tx, $"BLOCK_GAS_LIMIT_EXCEEDED {tx.GasLimit} > {header.GasLimit} - {header.GasUsed}"); + return "block gas limit exceeded"; } return TransactionResult.Ok; } // TODO Should we remove this already - protected bool RecoverSenderIfNeeded(Transaction tx, IReleaseSpec spec, ExecutionOptions opts, in UInt256 effectiveGasPrice) + protected virtual bool RecoverSenderIfNeeded(Transaction tx, IReleaseSpec spec, ExecutionOptions opts, in UInt256 effectiveGasPrice) { - bool commit = opts.HasFlag(ExecutionOptions.Commit) || !spec.IsEip658Enabled; - bool restore = opts.HasFlag(ExecutionOptions.Restore); - bool noValidation = opts.HasFlag(ExecutionOptions.NoValidation); - bool deleteCallerAccount = false; - - Address sender = tx.SenderAddress; + Address? sender = tx.SenderAddress; if (sender is null || !WorldState.AccountExists(sender)) { + bool commit = opts.HasFlag(ExecutionOptions.Commit) || !spec.IsEip658Enabled; + bool restore = opts.HasFlag(ExecutionOptions.Restore); + bool noValidation = opts.HasFlag(ExecutionOptions.NoValidation); + if (Logger.IsDebug) Logger.Debug($"TX sender account does not exist {sender} - trying to recover it"); // hacky fix for the potential recovery issue @@ -285,8 +309,7 @@ protected bool RecoverSenderIfNeeded(Transaction tx, IReleaseSpec spec, Executio if (sender != tx.SenderAddress) { - if (Logger.IsWarn) - Logger.Warn($"TX recovery issue fixed - tx was coming with sender {sender} and the now it recovers to {tx.SenderAddress}"); + if (Logger.IsWarn) Logger.Warn($"TX recovery issue fixed - tx was coming with sender {sender} and the now it recovers to {tx.SenderAddress}"); sender = tx.SenderAddress; } else @@ -313,7 +336,7 @@ protected virtual TransactionResult ValidateSender(Transaction tx, BlockHeader h { bool validate = !opts.HasFlag(ExecutionOptions.NoValidation); - if (validate && WorldState.IsInvalidContractSender(spec, tx.SenderAddress)) + if (validate && WorldState.IsInvalidContractSender(spec, tx.SenderAddress!)) { TraceLogInvalidTx(tx, "SENDER_IS_CONTRACT"); return "sender has deployed code"; @@ -329,7 +352,7 @@ protected virtual TransactionResult BuyGas(Transaction tx, BlockHeader header, I senderReservedGasPayment = UInt256.Zero; bool validate = !opts.HasFlag(ExecutionOptions.NoValidation); - if (!tx.IsSystem() && validate) + if (validate) { if (!tx.TryCalculatePremiumPerGas(header.BaseFeePerGas, out premiumPerGas)) { @@ -337,7 +360,7 @@ protected virtual TransactionResult BuyGas(Transaction tx, BlockHeader header, I return "miner premium is negative"; } - UInt256 senderBalance = WorldState.GetBalance(tx.SenderAddress); + UInt256 senderBalance = WorldState.GetBalance(tx.SenderAddress!); if (UInt256.SubtractUnderflow(senderBalance, tx.Value, out UInt256 balanceLeft)) { TraceLogInvalidTx(tx, $"INSUFFICIENT_SENDER_BALANCE: ({tx.SenderAddress})_BALANCE = {senderBalance}"); @@ -355,7 +378,7 @@ protected virtual TransactionResult BuyGas(Transaction tx, BlockHeader header, I } if (tx.SupportsBlobs) { - overflows = UInt256.MultiplyOverflow(BlobGasCalculator.CalculateBlobGas(tx), (UInt256)tx.MaxFeePerBlobGas, out UInt256 maxBlobGasFee); + overflows = UInt256.MultiplyOverflow(BlobGasCalculator.CalculateBlobGas(tx), (UInt256)tx.MaxFeePerBlobGas!, out UInt256 maxBlobGasFee); if (overflows || UInt256.AddOverflow(maxGasFee, maxBlobGasFee, out UInt256 multidimGasFee) || multidimGasFee > balanceLeft) { TraceLogInvalidTx(tx, $"INSUFFICIENT_MAX_FEE_PER_BLOB_GAS_FOR_SENDER_BALANCE: ({tx.SenderAddress})_BALANCE = {senderBalance}"); @@ -388,9 +411,7 @@ protected virtual TransactionResult BuyGas(Transaction tx, BlockHeader header, I protected virtual TransactionResult IncrementNonce(Transaction tx, BlockHeader header, IReleaseSpec spec, ITxTracer tracer, ExecutionOptions opts) { - if (tx.IsSystem()) return TransactionResult.Ok; - - if (tx.Nonce != WorldState.GetNonce(tx.SenderAddress)) + if (tx.Nonce != WorldState.GetNonce(tx.SenderAddress!)) { TraceLogInvalidTx(tx, $"WRONG_TRANSACTION_NONCE: {tx.Nonce} (expected {WorldState.GetNonce(tx.SenderAddress)})"); return "wrong transaction nonce"; @@ -400,16 +421,21 @@ protected virtual TransactionResult IncrementNonce(Transaction tx, BlockHeader h return TransactionResult.Ok; } - protected ExecutionEnvironment BuildExecutionEnvironment( + protected virtual void DecrementNonce(Transaction tx) + { + WorldState.DecrementNonce(tx.SenderAddress!); + } + + private ExecutionEnvironment BuildExecutionEnvironment( Transaction tx, in BlockExecutionContext blCtx, IReleaseSpec spec, in UInt256 effectiveGasPrice) { - Address recipient = tx.GetRecipient(tx.IsContractCreation ? WorldState.GetNonce(tx.SenderAddress) : 0); + Address recipient = tx.GetRecipient(tx.IsContractCreation ? WorldState.GetNonce(tx.SenderAddress!) : 0); if (recipient is null) ThrowInvalidDataException("Recipient has not been resolved properly before tx execution"); - TxExecutionContext executionContext = new(in blCtx, tx.SenderAddress, effectiveGasPrice, tx.BlobVersionedHashes); + TxExecutionContext executionContext = new(in blCtx, tx.SenderAddress!, effectiveGasPrice, tx.BlobVersionedHashes!); CodeInfo codeInfo = tx.IsContractCreation ? new(tx.Data ?? Memory.Empty) @@ -434,7 +460,7 @@ protected ExecutionEnvironment BuildExecutionEnvironment( protected virtual bool ShouldValidate(ExecutionOptions opts) => !opts.HasFlag(ExecutionOptions.NoValidation); - protected void ExecuteEvmCall( + protected virtual void ExecuteEvmCall( Transaction tx, BlockHeader header, IReleaseSpec spec, @@ -456,10 +482,7 @@ protected void ExecuteEvmCall( Snapshot snapshot = WorldState.TakeSnapshot(); - // Fixes eth_estimateGas. - // If sender is SystemUser subtracting value will cause InsufficientBalanceException - if (validate || !tx.IsSystem()) - WorldState.SubtractFromBalance(tx.SenderAddress, tx.Value, spec); + PayValue(tx, spec, opts); try { @@ -480,13 +503,13 @@ protected void ExecuteEvmCall( if (spec.UseHotAndColdStorage) { - state.WarmUp(tx.SenderAddress); // eip-2929 + state.WarmUp(tx.SenderAddress!); // eip-2929 state.WarmUp(env.ExecutingAccount); // eip-2929 } if (spec.AddCoinbaseToTxAccessList) { - state.WarmUp(header.GasBeneficiary); + state.WarmUp(header.GasBeneficiary!); } substate = !tracer.IsTracingActions @@ -556,28 +579,30 @@ protected void ExecuteEvmCall( WorldState.Restore(snapshot); } - if (validate && !tx.IsSystem()) + if (!opts.HasFlag(ExecutionOptions.NoValidation)) header.GasUsed += spentGas; } + protected virtual void PayValue(Transaction tx, IReleaseSpec spec, ExecutionOptions opts) + { + WorldState.SubtractFromBalance(tx.SenderAddress!, tx.Value, spec); + } + protected virtual void PayFees(Transaction tx, BlockHeader header, IReleaseSpec spec, ITxTracer tracer, in TransactionSubstate substate, in long spentGas, in UInt256 premiumPerGas, in byte statusCode) { - if (!tx.IsSystem()) + bool gasBeneficiaryNotDestroyed = substate?.DestroyList.Contains(header.GasBeneficiary) != true; + if (statusCode == StatusCode.Failure || gasBeneficiaryNotDestroyed) { - bool gasBeneficiaryNotDestroyed = substate?.DestroyList.Contains(header.GasBeneficiary) != true; - if (statusCode == StatusCode.Failure || gasBeneficiaryNotDestroyed) - { - UInt256 fees = (UInt256)spentGas * premiumPerGas; - UInt256 burntFees = !tx.IsFree() ? (UInt256)spentGas * header.BaseFeePerGas : 0; + UInt256 fees = (UInt256)spentGas * premiumPerGas; + UInt256 burntFees = !tx.IsFree() ? (UInt256)spentGas * header.BaseFeePerGas : 0; - WorldState.AddToBalanceAndCreateIfNotExists(header.GasBeneficiary, fees, spec); + WorldState.AddToBalanceAndCreateIfNotExists(header.GasBeneficiary!, fees, spec); - if (spec.IsEip1559Enabled && spec.Eip1559FeeCollector is not null && !burntFees.IsZero) - WorldState.AddToBalanceAndCreateIfNotExists(spec.Eip1559FeeCollector, burntFees, spec); + if (spec.IsEip1559Enabled && spec.Eip1559FeeCollector is not null && !burntFees.IsZero) + WorldState.AddToBalanceAndCreateIfNotExists(spec.Eip1559FeeCollector, burntFees, spec); - if (tracer.IsTracingFees) - tracer.ReportFees(fees, burntFees); - } + if (tracer.IsTracingFees) + tracer.ReportFees(fees, burntFees); } } @@ -613,7 +638,7 @@ protected virtual long Refund(Transaction tx, BlockHeader header, IReleaseSpec s Logger.Trace("Refunding unused gas of " + unspentGas + " and refund of " + refund); // If noValidation we didn't charge for gas, so do not refund if (!opts.HasFlag(ExecutionOptions.NoValidation)) - WorldState.AddToBalance(tx.SenderAddress, (ulong)(unspentGas + refund) * gasPrice, spec); + WorldState.AddToBalance(tx.SenderAddress!, (ulong)(unspentGas + refund) * gasPrice, spec); spentGas -= refund; } diff --git a/src/Nethermind/Nethermind.Facade/Simulate/SimulateReadOnlyBlocksProcessingEnv.cs b/src/Nethermind/Nethermind.Facade/Simulate/SimulateReadOnlyBlocksProcessingEnv.cs index 3f70c14789f..907b7a10d17 100644 --- a/src/Nethermind/Nethermind.Facade/Simulate/SimulateReadOnlyBlocksProcessingEnv.cs +++ b/src/Nethermind/Nethermind.Facade/Simulate/SimulateReadOnlyBlocksProcessingEnv.cs @@ -3,6 +3,7 @@ using System; using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Blockchain.Receipts; using Nethermind.Consensus.Processing; @@ -47,7 +48,7 @@ public class SimulateReadOnlyBlocksProcessingEnv : ReadOnlyTxProcessingEnvBase, { private readonly IBlockValidator _blockValidator; private readonly ILogManager? _logManager; - private readonly TransactionProcessor _transactionProcessor; + private readonly ITransactionProcessor _transactionProcessor; public IWorldState WorldState => StateProvider; public SimulateReadOnlyBlocksProcessingEnv( @@ -114,5 +115,6 @@ public IBlockProcessor GetProcessor(bool validate, UInt256? blobBaseFeeOverride) StateProvider, NullReceiptStorage.Instance, new BlockhashStore(SpecProvider, StateProvider), + new BeaconBlockRootHandler(_transactionProcessor), _logManager); } diff --git a/src/Nethermind/Nethermind.Facade/Simulate/SimulateTransactionProcessor.cs b/src/Nethermind/Nethermind.Facade/Simulate/SimulateTransactionProcessor.cs index 9b6ebb52192..705a68ec071 100644 --- a/src/Nethermind/Nethermind.Facade/Simulate/SimulateTransactionProcessor.cs +++ b/src/Nethermind/Nethermind.Facade/Simulate/SimulateTransactionProcessor.cs @@ -12,14 +12,14 @@ namespace Nethermind.Facade.Simulate; -public class SimulateTransactionProcessor( +public sealed class SimulateTransactionProcessor( ISpecProvider? specProvider, IWorldState? worldState, IVirtualMachine? virtualMachine, ICodeInfoRepository? codeInfoRepository, ILogManager? logManager, bool validate) - : TransactionProcessor(specProvider, worldState, virtualMachine, codeInfoRepository, logManager), ITransactionProcessor + : TransactionProcessorBase(specProvider, worldState, virtualMachine, codeInfoRepository, logManager), ITransactionProcessor { protected override bool ShouldValidate(ExecutionOptions opts) => true; diff --git a/src/Nethermind/Nethermind.Init/Steps/InitializeBlockchain.cs b/src/Nethermind/Nethermind.Init/Steps/InitializeBlockchain.cs index 21189802d53..5bbdd17de96 100644 --- a/src/Nethermind/Nethermind.Init/Steps/InitializeBlockchain.cs +++ b/src/Nethermind/Nethermind.Init/Steps/InitializeBlockchain.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Nethermind.Api; using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Blockchain.Filters; using Nethermind.Blockchain.FullPruning; @@ -238,6 +239,7 @@ protected virtual BlockProcessor CreateBlockProcessor(BlockCachePreWarmer? preWa worldState, _api.ReceiptStorage, new BlockhashStore(_api.SpecProvider!, worldState), + new BeaconBlockRootHandler(_api.TransactionProcessor), _api.LogManager, preWarmer: preWarmer ); diff --git a/src/Nethermind/Nethermind.Init/Steps/InitializePrecompiles.cs b/src/Nethermind/Nethermind.Init/Steps/InitializePrecompiles.cs index 2369dcc5923..37b1706f28e 100644 --- a/src/Nethermind/Nethermind.Init/Steps/InitializePrecompiles.cs +++ b/src/Nethermind/Nethermind.Init/Steps/InitializePrecompiles.cs @@ -5,6 +5,7 @@ using System.Threading; using System.Threading.Tasks; using Nethermind.Api; +using Nethermind.Core.Specs; using Nethermind.Crypto; using Nethermind.Logging; diff --git a/src/Nethermind/Nethermind.JsonRpc.Benchmark/EthModuleBenchmarks.cs b/src/Nethermind/Nethermind.JsonRpc.Benchmark/EthModuleBenchmarks.cs index 4d3ee0b8392..6e2270e2446 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Benchmark/EthModuleBenchmarks.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Benchmark/EthModuleBenchmarks.cs @@ -3,6 +3,7 @@ using BenchmarkDotNet.Attributes; using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Blockchain.Filters; using Nethermind.Blockchain.Find; @@ -94,8 +95,16 @@ TransactionProcessor transactionProcessor = new(MainnetSpecProvider.Instance, stateProvider, _virtualMachine, codeInfoRepository, LimboLogs.Instance); IBlockProcessor.IBlockTransactionsExecutor transactionsExecutor = new BlockProcessor.BlockValidationTransactionsExecutor(transactionProcessor, stateProvider); - BlockProcessor blockProcessor = new(specProvider, Always.Valid, new RewardCalculator(specProvider), transactionsExecutor, - stateProvider, NullReceiptStorage.Instance, new BlockhashStore(specProvider, stateProvider), LimboLogs.Instance); + BlockProcessor blockProcessor = new( + specProvider, + Always.Valid, + new RewardCalculator(specProvider), + transactionsExecutor, + stateProvider, + NullReceiptStorage.Instance, + new BlockhashStore(specProvider, stateProvider), + new BeaconBlockRootHandler(transactionProcessor), + LimboLogs.Instance); EthereumEcdsa ecdsa = new(specProvider.ChainId); BlockchainProcessor blockchainProcessor = new( diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Eth/EthRpcModuleTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Eth/EthRpcModuleTests.cs index c5b2ae5db1a..46033f3ed70 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Eth/EthRpcModuleTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Eth/EthRpcModuleTests.cs @@ -314,17 +314,17 @@ void handleNewBlock(object? sender, BlockEventArgs e) string getFilterLogsSerialized1 = await test.TestEthRpc("eth_getFilterChanges", (newFilterResp as JsonRpcSuccessResponse)!.Result?.ToString() ?? "0x0"); //expect empty - no changes so far - Assert.That(getFilterLogsSerialized1, Is.EqualTo("{\"jsonrpc\":\"2.0\",\"result\":[],\"id\":67}")); + getFilterLogsSerialized1.Should().Be("{\"jsonrpc\":\"2.0\",\"result\":[],\"id\":67}"); await test.AddBlock(createCodeTx); //expect new transaction logs string getFilterLogsSerialized2 = await test.TestEthRpc("eth_getFilterChanges", (newFilterResp as JsonRpcSuccessResponse)!.Result?.ToString() ?? "0x0"); - Assert.That(getFilterLogsSerialized2, Is.EqualTo("{\"jsonrpc\":\"2.0\",\"result\":[{\"address\":\"0x0ffd3e46594919c04bcfd4e146203c8255670828\",\"blockHash\":\"0x2eb166ba88c43f96f980a573aebcee792fda4d34ad4c353dfd3d08cdf80adfae\",\"blockNumber\":\"0x4\",\"data\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"logIndex\":\"0x0\",\"removed\":false,\"topics\":[],\"transactionHash\":\"0x8c9c109bff7969c8aed8e51ab4ea35c6f835a0c3266bc5c5721821a38cbf5445\",\"transactionIndex\":\"0x0\",\"transactionLogIndex\":\"0x0\"}],\"id\":67}")); + getFilterLogsSerialized2.Should().Be("{\"jsonrpc\":\"2.0\",\"result\":[{\"address\":\"0x0ffd3e46594919c04bcfd4e146203c8255670828\",\"blockHash\":\"0xf9fc52a47b7da4e8227cd60e9c368fa7d44df7f3226d5163005eec015588d64b\",\"blockNumber\":\"0x4\",\"data\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"logIndex\":\"0x0\",\"removed\":false,\"topics\":[],\"transactionHash\":\"0x8c9c109bff7969c8aed8e51ab4ea35c6f835a0c3266bc5c5721821a38cbf5445\",\"transactionIndex\":\"0x0\",\"transactionLogIndex\":\"0x0\"}],\"id\":67}"); //expect empty - previous call cleans logs string getFilterLogsSerialized3 = await test.TestEthRpc("eth_getFilterChanges", (newFilterResp as JsonRpcSuccessResponse)!.Result?.ToString() ?? "0x0"); - Assert.That(getFilterLogsSerialized3, Is.EqualTo("{\"jsonrpc\":\"2.0\",\"result\":[],\"id\":67}")); + getFilterLogsSerialized3.Should().Be("{\"jsonrpc\":\"2.0\",\"result\":[],\"id\":67}"); } [Test] diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/SubscribeModuleTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/SubscribeModuleTests.cs index 5134da7c20b..1d132d4bf33 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/SubscribeModuleTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/SubscribeModuleTests.cs @@ -917,8 +917,6 @@ public async Task MultipleSubscriptions_concurrent_fast_messages(int messages) [Test] public void NewHeadSubscription_with_baseFeePerGas_test() { - _specProvider.GetSpec(Arg.Any(), Arg.Any()).IsEip1559Enabled.Returns(true); - _specProvider.GetSpec(Arg.Any()).IsEip1559Enabled.Returns(true); _specProvider.GetSpec(Arg.Any()).IsEip1559Enabled.Returns(true); Block block = Build.A.Block.Genesis.WithTotalDifficulty(0L).WithBaseFeePerGas(10000).TestObject; BlockReplacementEventArgs blockReplacementEventArgs = new(block); diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Trace/ParityStyleTracerTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Trace/ParityStyleTracerTests.cs index e45f59a631b..901c35bdbd0 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Trace/ParityStyleTracerTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Trace/ParityStyleTracerTests.cs @@ -4,6 +4,7 @@ using System.Linq; using FluentAssertions; using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Blockchain.Find; using Nethermind.Blockchain.Receipts; @@ -76,6 +77,7 @@ public void Setup() stateProvider, NullReceiptStorage.Instance, new BlockhashStore(specProvider, stateProvider), + new BeaconBlockRootHandler(transactionProcessor), LimboLogs.Instance); RecoverSignatures txRecovery = new(new EthereumEcdsa(TestBlockchainIds.ChainId), NullTxPool.Instance, specProvider, LimboLogs.Instance); diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TraceRpcModuleTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TraceRpcModuleTests.cs index 1fab4d08e2b..165cc9310c6 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TraceRpcModuleTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TraceRpcModuleTests.cs @@ -541,7 +541,7 @@ public async Task Trace_transaction_with_error_reverted() traces.Data.ElementAt(0).TransactionHash.Should().Be(transaction2.Hash!); string serialized = new EthereumJsonSerializer().Serialize(traces.Data); - Assert.That(serialized, Is.EqualTo("[{\"action\":{\"creationMethod\":\"create\",\"from\":\"0x942921b14f1b1c385cd7e0cc2ef7abe5598c8358\",\"gas\":\"0x9a6c\",\"init\":\"0x60006000600060006000736b5887043de753ecfa6269f947129068263ffbe261c350f160006000600060006000736b5887043de753ecfa6269f947129068263ffbe261c350f1fd\",\"value\":\"0x1\"},\"blockHash\":\"0xfa74e932520ee416ecb12171c115b3ad14112ffd2d612646ceaff69e54e06a94\",\"blockNumber\":18,\"subtraces\":2,\"traceAddress\":[],\"transactionHash\":\"0x787616b8756424622f162fc3817331517ef941366f28db452defc0214bc36b22\",\"transactionPosition\":0,\"type\":\"create\",\"error\":\"Reverted\"},{\"action\":{\"callType\":\"call\",\"from\":\"0xd6a48bcd4c5ad5adacfab677519c25ce7b2805a5\",\"gas\":\"0x2dcd\",\"input\":\"0x\",\"to\":\"0x6b5887043de753ecfa6269f947129068263ffbe2\",\"value\":\"0x0\"},\"blockHash\":\"0xfa74e932520ee416ecb12171c115b3ad14112ffd2d612646ceaff69e54e06a94\",\"blockNumber\":18,\"result\":{\"gasUsed\":\"0x0\",\"output\":\"0x\"},\"subtraces\":0,\"traceAddress\":[0],\"transactionHash\":\"0x787616b8756424622f162fc3817331517ef941366f28db452defc0214bc36b22\",\"transactionPosition\":0,\"type\":\"call\"},{\"action\":{\"callType\":\"call\",\"from\":\"0xd6a48bcd4c5ad5adacfab677519c25ce7b2805a5\",\"gas\":\"0x2d56\",\"input\":\"0x\",\"to\":\"0x6b5887043de753ecfa6269f947129068263ffbe2\",\"value\":\"0x0\"},\"blockHash\":\"0xfa74e932520ee416ecb12171c115b3ad14112ffd2d612646ceaff69e54e06a94\",\"blockNumber\":18,\"result\":{\"gasUsed\":\"0x0\",\"output\":\"0x\"},\"subtraces\":0,\"traceAddress\":[1],\"transactionHash\":\"0x787616b8756424622f162fc3817331517ef941366f28db452defc0214bc36b22\",\"transactionPosition\":0,\"type\":\"call\"}]"), serialized.Replace("\"", "\\\"")); + Assert.That(serialized, Is.EqualTo("[{\"action\":{\"creationMethod\":\"create\",\"from\":\"0x942921b14f1b1c385cd7e0cc2ef7abe5598c8358\",\"gas\":\"0x9a6c\",\"init\":\"0x60006000600060006000736b5887043de753ecfa6269f947129068263ffbe261c350f160006000600060006000736b5887043de753ecfa6269f947129068263ffbe261c350f1fd\",\"value\":\"0x1\"},\"blockHash\":\"0xeb0d05efb43e565c4a677e64dde4cd1339459310afe8f578acab57ad45dd8f44\",\"blockNumber\":18,\"subtraces\":2,\"traceAddress\":[],\"transactionHash\":\"0x787616b8756424622f162fc3817331517ef941366f28db452defc0214bc36b22\",\"transactionPosition\":0,\"type\":\"create\",\"error\":\"Reverted\"},{\"action\":{\"callType\":\"call\",\"from\":\"0xd6a48bcd4c5ad5adacfab677519c25ce7b2805a5\",\"gas\":\"0x8def\",\"input\":\"0x\",\"to\":\"0x6b5887043de753ecfa6269f947129068263ffbe2\",\"value\":\"0x0\"},\"blockHash\":\"0xeb0d05efb43e565c4a677e64dde4cd1339459310afe8f578acab57ad45dd8f44\",\"blockNumber\":18,\"result\":{\"gasUsed\":\"0x0\",\"output\":\"0x\"},\"subtraces\":0,\"traceAddress\":[0],\"transactionHash\":\"0x787616b8756424622f162fc3817331517ef941366f28db452defc0214bc36b22\",\"transactionPosition\":0,\"type\":\"call\"},{\"action\":{\"callType\":\"call\",\"from\":\"0xd6a48bcd4c5ad5adacfab677519c25ce7b2805a5\",\"gas\":\"0x8d78\",\"input\":\"0x\",\"to\":\"0x6b5887043de753ecfa6269f947129068263ffbe2\",\"value\":\"0x0\"},\"blockHash\":\"0xeb0d05efb43e565c4a677e64dde4cd1339459310afe8f578acab57ad45dd8f44\",\"blockNumber\":18,\"result\":{\"gasUsed\":\"0x0\",\"output\":\"0x\"},\"subtraces\":0,\"traceAddress\":[1],\"transactionHash\":\"0x787616b8756424622f162fc3817331517ef941366f28db452defc0214bc36b22\",\"transactionPosition\":0,\"type\":\"call\"}]"), serialized.Replace("\"", "\\\"")); } [Test] public async Task trace_timeout_is_separate_for_rpc_calls() diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/RpcBlockTransactionsExecutor.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/RpcBlockTransactionsExecutor.cs index 63dbf44dc05..38b04afb218 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/RpcBlockTransactionsExecutor.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/RpcBlockTransactionsExecutor.cs @@ -7,11 +7,7 @@ namespace Nethermind.JsonRpc.Modules { - public class RpcBlockTransactionsExecutor : BlockProcessor.BlockValidationTransactionsExecutor - { - public RpcBlockTransactionsExecutor(ITransactionProcessor transactionProcessor, IWorldState stateProvider) - : base(new TraceTransactionProcessorAdapter(transactionProcessor), stateProvider) - { - } - } + public class RpcBlockTransactionsExecutor(ITransactionProcessor transactionProcessor, IWorldState stateProvider) + : BlockProcessor.BlockValidationTransactionsExecutor(new TraceTransactionProcessorAdapter(transactionProcessor), + stateProvider); } diff --git a/src/Nethermind/Nethermind.Merge.AuRa.Test/AuRaMergeEngineModuleTests.cs b/src/Nethermind/Nethermind.Merge.AuRa.Test/AuRaMergeEngineModuleTests.cs index 1b2c2b804d6..698f42f8877 100644 --- a/src/Nethermind/Nethermind.Merge.AuRa.Test/AuRaMergeEngineModuleTests.cs +++ b/src/Nethermind/Nethermind.Merge.AuRa.Test/AuRaMergeEngineModuleTests.cs @@ -3,6 +3,7 @@ using System; using System.Threading.Tasks; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Blockchain.Synchronization; using Nethermind.Config; @@ -18,6 +19,7 @@ using Nethermind.Core; using Nethermind.Core.Crypto; using Nethermind.Core.Specs; +using Nethermind.Core.Test.Blockchain; using Nethermind.Core.Timers; using Nethermind.Facade.Eth; using Nethermind.Int256; @@ -97,6 +99,12 @@ public MergeAuRaTestBlockchain(IMergeConfig? mergeConfig = null, IPayloadPrepara SealEngineType = Core.SealEngineType.AuRa; } + protected override Task Build(ISpecProvider? specProvider = null, UInt256? initialValues = null, bool addBlockOnStart = true) + { + if (specProvider is TestSingleReleaseSpecProvider provider) provider.SealEngine = SealEngineType; + return base.Build(specProvider, initialValues, addBlockOnStart); + } + protected override IBlockProcessor CreateBlockProcessor() { _api = new(new ConfigProvider(), new EthereumJsonSerializer(), LogManager, @@ -132,6 +140,7 @@ protected override IBlockProcessor CreateBlockProcessor() State, ReceiptStorage, new BlockhashStore(SpecProvider, State), + new BeaconBlockRootHandler(TxProcessor), LogManager, WithdrawalProcessor, preWarmer: CreateBlockCachePreWarmer()); diff --git a/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProcessor.cs b/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProcessor.cs index 1a55b725abd..e07a4709bbe 100644 --- a/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProcessor.cs +++ b/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProcessor.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Receipts; using Nethermind.Consensus.AuRa; using Nethermind.Consensus.AuRa.Validators; @@ -18,41 +19,38 @@ namespace Nethermind.Merge.AuRa; -public class AuRaMergeBlockProcessor : AuRaBlockProcessor +public class AuRaMergeBlockProcessor( + ISpecProvider specProvider, + IBlockValidator blockValidator, + IRewardCalculator rewardCalculator, + IBlockProcessor.IBlockTransactionsExecutor blockTransactionsExecutor, + IWorldState stateProvider, + IReceiptStorage receiptStorage, + IBeaconBlockRootHandler beaconBlockRootHandler, + ILogManager logManager, + IBlockTree blockTree, + IWithdrawalProcessor withdrawalProcessor, + IAuRaValidator? validator, + ITxFilter? txFilter = null, + AuRaContractGasLimitOverride? gasLimitOverride = null, + ContractRewriter? contractRewriter = null, + IBlockCachePreWarmer? preWarmer = null) + : AuRaBlockProcessor(specProvider, + blockValidator, + rewardCalculator, + blockTransactionsExecutor, + stateProvider, + receiptStorage, + beaconBlockRootHandler, + logManager, + blockTree, + withdrawalProcessor, + validator, + txFilter, + gasLimitOverride, + contractRewriter, + preWarmer) { - public AuRaMergeBlockProcessor( - ISpecProvider specProvider, - IBlockValidator blockValidator, - IRewardCalculator rewardCalculator, - IBlockProcessor.IBlockTransactionsExecutor blockTransactionsExecutor, - IWorldState stateProvider, - IReceiptStorage receiptStorage, - ILogManager logManager, - IBlockTree blockTree, - IWithdrawalProcessor withdrawalProcessor, - IAuRaValidator? validator, - ITxFilter? txFilter = null, - AuRaContractGasLimitOverride? gasLimitOverride = null, - ContractRewriter? contractRewriter = null, - IBlockCachePreWarmer? preWarmer = null - ) : base( - specProvider, - blockValidator, - rewardCalculator, - blockTransactionsExecutor, - stateProvider, - receiptStorage, - logManager, - blockTree, - withdrawalProcessor, - validator, - txFilter, - gasLimitOverride, - contractRewriter, - preWarmer - ) - { } - protected override TxReceipt[] ProcessBlock(Block block, IBlockTracer blockTracer, ProcessingOptions options) => block.IsPostMerge ? PostMergeProcessBlock(block, blockTracer, options) diff --git a/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProducerEnvFactory.cs b/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProducerEnvFactory.cs index f91dac19352..c725e7164ff 100644 --- a/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProducerEnvFactory.cs +++ b/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProducerEnvFactory.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Receipts; using Nethermind.Config; using Nethermind.Consensus.AuRa.Config; @@ -71,6 +72,7 @@ protected override BlockProcessor CreateBlockProcessor( TransactionsExecutorFactory.Create(readOnlyTxProcessingEnv), readOnlyTxProcessingEnv.WorldState, receiptStorage, + new BeaconBlockRootHandler(readOnlyTxProcessingEnv.TransactionProcessor), logManager, _blockTree, new Consensus.Withdrawals.BlockProductionWithdrawalProcessor( diff --git a/src/Nethermind/Nethermind.Merge.AuRa/InitializationSteps/InitializeBlockchainAuRaMerge.cs b/src/Nethermind/Nethermind.Merge.AuRa/InitializationSteps/InitializeBlockchainAuRaMerge.cs index cf4b4d4b6be..cb0bbe3c4c8 100644 --- a/src/Nethermind/Nethermind.Merge.AuRa/InitializationSteps/InitializeBlockchainAuRaMerge.cs +++ b/src/Nethermind/Nethermind.Merge.AuRa/InitializationSteps/InitializeBlockchainAuRaMerge.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only using System.Collections.Generic; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Consensus.AuRa; using Nethermind.Consensus.AuRa.InitializationSteps; using Nethermind.Consensus.AuRa.Validators; @@ -36,14 +37,14 @@ protected override AuRaBlockProcessor NewAuraBlockProcessor(ITxFilter txFilter, return new AuRaMergeBlockProcessor( _api.SpecProvider!, _api.BlockValidator!, - _api.RewardCalculatorSource!.Get(_api.TransactionProcessor!), - new BlockProcessor.BlockValidationTransactionsExecutor(transactionProcessor!, worldState), + _api.RewardCalculatorSource!.Get(transactionProcessor), + new BlockProcessor.BlockValidationTransactionsExecutor(transactionProcessor, worldState), worldState, _api.ReceiptStorage!, + new BeaconBlockRootHandler(transactionProcessor), _api.LogManager, _api.BlockTree!, - new AuraWithdrawalProcessor( - withdrawalContractFactory.Create(transactionProcessor!), _api.LogManager), + new AuraWithdrawalProcessor(withdrawalContractFactory.Create(transactionProcessor), _api.LogManager), CreateAuRaValidator(), txFilter, GetGasLimitCalculator(), diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs index dd4de68d98d..9db79267ba9 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs @@ -20,7 +20,6 @@ using Nethermind.Specs; using Nethermind.Specs.Forks; using Nethermind.State; -using Nethermind.Consensus.BeaconBlockRoot; namespace Nethermind.Merge.Plugin.Test { @@ -28,7 +27,6 @@ namespace Nethermind.Merge.Plugin.Test public partial class EngineModuleTests { private static readonly DateTime Timestamp = DateTimeOffset.FromUnixTimeSeconds(1000).UtcDateTime; - private static readonly IBeaconBlockRootHandler _beaconBlockRootHandler = new BeaconBlockRootHandler(); private ITimestamper Timestamper { get; } = new ManualTimestamper(Timestamp); private void AssertExecutionStatusChanged(IBlockFinder blockFinder, Hash256 headBlockHash, Hash256 finalizedBlockHash, Hash256 safeBlockHash) @@ -124,7 +122,6 @@ private static ExecutionPayloadV3 CreateBlockRequestV3(MergeTestBlockchain chain blockRequestV3.TryGetBlock(out Block? block); Snapshot before = chain.State.TakeSnapshot(); - _beaconBlockRootHandler.ApplyContractStateChanges(block!, chain.SpecProvider.GenesisSpec, chain.State); var blockHashStore = new BlockhashStore(chain.SpecProvider, chain.State); blockHashStore.ApplyBlockhashStateChanges(block!.Header); chain.WithdrawalProcessor?.ProcessWithdrawals(block!, chain.SpecProvider.GenesisSpec); diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs index e07ca73d3e3..0cc6b0a5338 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Nethermind.Api; using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Blockchain.Synchronization; using Nethermind.Config; @@ -236,6 +237,7 @@ protected override IBlockProcessor CreateBlockProcessor() State, ReceiptStorage, new BlockhashStore(SpecProvider, State), + new BeaconBlockRootHandler(TxProcessor), LogManager, WithdrawalProcessor, preWarmer: CreateBlockCachePreWarmer()); diff --git a/src/Nethermind/Nethermind.Mining.Test/MinGasPriceTests.cs b/src/Nethermind/Nethermind.Mining.Test/MinGasPriceTests.cs index bd1e9e4db65..fc464fbfa2d 100644 --- a/src/Nethermind/Nethermind.Mining.Test/MinGasPriceTests.cs +++ b/src/Nethermind/Nethermind.Mining.Test/MinGasPriceTests.cs @@ -51,22 +51,12 @@ public void Test(long minimum, long actual, bool expectedResult) public void Test1559(long minimum, long maxFeePerGas, long maxPriorityFeePerGas, bool expectedResult) { ISpecProvider specProvider = Substitute.For(); - specProvider.GetSpec(Arg.Any(), Arg.Any()).IsEip1559Enabled.Returns(true); - specProvider.GetSpec(Arg.Any()).IsEip1559Enabled.Returns(true); specProvider.GetSpec(Arg.Any()).IsEip1559Enabled.Returns(true); specProvider.GetSpec(Arg.Any()).ForkBaseFee.Returns(Eip1559Constants.DefaultForkBaseFee); specProvider.GetSpec(Arg.Any()).BaseFeeMaxChangeDenominator.Returns(Eip1559Constants.DefaultBaseFeeMaxChangeDenominator); specProvider.GetSpec(Arg.Any()).ElasticityMultiplier.Returns(Eip1559Constants.DefaultElasticityMultiplier); - specProvider.GetSpec(Arg.Any(), Arg.Any()).ForkBaseFee.Returns(Eip1559Constants.DefaultForkBaseFee); - specProvider.GetSpec(Arg.Any(), Arg.Any()).BaseFeeMaxChangeDenominator.Returns(Eip1559Constants.DefaultBaseFeeMaxChangeDenominator); - specProvider.GetSpec(Arg.Any(), Arg.Any()).ElasticityMultiplier.Returns(Eip1559Constants.DefaultElasticityMultiplier); - - specProvider.GetSpec(Arg.Any()).ForkBaseFee.Returns(Eip1559Constants.DefaultForkBaseFee); - specProvider.GetSpec(Arg.Any()).BaseFeeMaxChangeDenominator.Returns(Eip1559Constants.DefaultBaseFeeMaxChangeDenominator); - specProvider.GetSpec(Arg.Any()).ElasticityMultiplier.Returns(Eip1559Constants.DefaultElasticityMultiplier); - BlocksConfig blocksConfig = new() { MinGasPrice = (UInt256)minimum diff --git a/src/Nethermind/Nethermind.Optimism/InitializeBlockchainOptimism.cs b/src/Nethermind/Nethermind.Optimism/InitializeBlockchainOptimism.cs index 6c42963e032..80c7f2d7e98 100644 --- a/src/Nethermind/Nethermind.Optimism/InitializeBlockchainOptimism.cs +++ b/src/Nethermind/Nethermind.Optimism/InitializeBlockchainOptimism.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Nethermind.Api; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Blockchain.Services; using Nethermind.Config; @@ -13,6 +14,7 @@ using Nethermind.Evm; using Nethermind.Evm.TransactionProcessing; using Nethermind.Init.Steps; +using Nethermind.Logging; using Nethermind.Merge.Plugin.InvalidChainTracker; namespace Nethermind.Optimism; @@ -85,26 +87,29 @@ protected override IBlockValidator CreateBlockValidator() protected override BlockProcessor CreateBlockProcessor(BlockCachePreWarmer? preWarmer) { + ITransactionProcessor? apiTransactionProcessor = _api.TransactionProcessor; + ILogManager? apiLogManager = _api.LogManager; + if (_api.DbProvider is null) throw new StepDependencyException(nameof(_api.DbProvider)); if (_api.RewardCalculatorSource is null) throw new StepDependencyException(nameof(_api.RewardCalculatorSource)); - if (_api.TransactionProcessor is null) throw new StepDependencyException(nameof(_api.TransactionProcessor)); + if (apiTransactionProcessor is null) throw new StepDependencyException(nameof(apiTransactionProcessor)); if (_api.SpecHelper is null) throw new StepDependencyException(nameof(_api.SpecHelper)); if (_api.SpecProvider is null) throw new StepDependencyException(nameof(_api.SpecProvider)); if (_api.BlockTree is null) throw new StepDependencyException(nameof(_api.BlockTree)); if (_api.WorldState is null) throw new StepDependencyException(nameof(_api.WorldState)); - Create2DeployerContractRewriter contractRewriter = - new(_api.SpecHelper, _api.SpecProvider, _api.BlockTree); + Create2DeployerContractRewriter contractRewriter = new(_api.SpecHelper, _api.SpecProvider, _api.BlockTree); return new OptimismBlockProcessor( _api.SpecProvider, _api.BlockValidator, - _api.RewardCalculatorSource.Get(_api.TransactionProcessor!), - new BlockProcessor.BlockValidationTransactionsExecutor(_api.TransactionProcessor, _api.WorldState), + _api.RewardCalculatorSource.Get(apiTransactionProcessor!), + new BlockProcessor.BlockValidationTransactionsExecutor(apiTransactionProcessor, _api.WorldState), _api.WorldState, _api.ReceiptStorage, new BlockhashStore(_api.SpecProvider, _api.WorldState), - _api.LogManager, + new BeaconBlockRootHandler(apiTransactionProcessor), + apiLogManager, _api.SpecHelper, contractRewriter, new BlockProductionWithdrawalProcessor(new NullWithdrawalProcessor()), diff --git a/src/Nethermind/Nethermind.Optimism/OptimismBlockProcessor.cs b/src/Nethermind/Nethermind.Optimism/OptimismBlockProcessor.cs index 385e7217e3c..1e05b0fe50b 100644 --- a/src/Nethermind/Nethermind.Optimism/OptimismBlockProcessor.cs +++ b/src/Nethermind/Nethermind.Optimism/OptimismBlockProcessor.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only using System; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Blockchain.Receipts; using Nethermind.Consensus.Processing; @@ -28,14 +29,25 @@ public OptimismBlockProcessor( IWorldState? stateProvider, IReceiptStorage? receiptStorage, IBlockhashStore? blockhashStore, + IBeaconBlockRootHandler? beaconBlockRootHandler, ILogManager? logManager, IOptimismSpecHelper opSpecHelper, Create2DeployerContractRewriter contractRewriter, IWithdrawalProcessor? withdrawalProcessor = null, IBlockCachePreWarmer? preWarmer = null) - : base(specProvider, blockValidator, rewardCalculator, blockTransactionsExecutor, - stateProvider, receiptStorage, blockhashStore, logManager, withdrawalProcessor, - ReceiptsRootCalculator.Instance, preWarmer) + : base( + specProvider, + blockValidator, + rewardCalculator, + blockTransactionsExecutor, + stateProvider, + receiptStorage, + blockhashStore, + beaconBlockRootHandler, + logManager, + withdrawalProcessor, + ReceiptsRootCalculator.Instance, + preWarmer) { ArgumentNullException.ThrowIfNull(stateProvider); _contractRewriter = contractRewriter; diff --git a/src/Nethermind/Nethermind.Optimism/OptimismBlockProducerEnvFactory.cs b/src/Nethermind/Nethermind.Optimism/OptimismBlockProducerEnvFactory.cs index f60c6638468..a72d1d9e4cb 100644 --- a/src/Nethermind/Nethermind.Optimism/OptimismBlockProducerEnvFactory.cs +++ b/src/Nethermind/Nethermind.Optimism/OptimismBlockProducerEnvFactory.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Blockchain.Receipts; using Nethermind.Config; @@ -87,6 +88,7 @@ protected override BlockProcessor CreateBlockProcessor( readOnlyTxProcessingEnv.WorldState, receiptStorage, new BlockhashStore(specProvider, readOnlyTxProcessingEnv.WorldState), + new BeaconBlockRootHandler(readOnlyTxProcessingEnv.TransactionProcessor), logManager, _specHelper, new Create2DeployerContractRewriter(_specHelper, _specProvider, _blockTree), diff --git a/src/Nethermind/Nethermind.Optimism/OptimismReadOnlyTxProcessingEnv.cs b/src/Nethermind/Nethermind.Optimism/OptimismReadOnlyTxProcessingEnv.cs index 499a0c9883f..b374b105bed 100644 --- a/src/Nethermind/Nethermind.Optimism/OptimismReadOnlyTxProcessingEnv.cs +++ b/src/Nethermind/Nethermind.Optimism/OptimismReadOnlyTxProcessingEnv.cs @@ -27,7 +27,7 @@ public class OptimismReadOnlyTxProcessingEnv( worldStateToWarmUp ) { - protected override TransactionProcessor CreateTransactionProcessor() + protected override ITransactionProcessor CreateTransactionProcessor() { ArgumentNullException.ThrowIfNull(LogManager); diff --git a/src/Nethermind/Nethermind.Optimism/OptimismTransactionProcessor.cs b/src/Nethermind/Nethermind.Optimism/OptimismTransactionProcessor.cs index aa71d1fae45..d21a3350ed3 100644 --- a/src/Nethermind/Nethermind.Optimism/OptimismTransactionProcessor.cs +++ b/src/Nethermind/Nethermind.Optimism/OptimismTransactionProcessor.cs @@ -13,7 +13,7 @@ namespace Nethermind.Optimism; -public class OptimismTransactionProcessor( +public sealed class OptimismTransactionProcessor( ISpecProvider specProvider, IWorldState worldState, IVirtualMachine virtualMachine, @@ -21,7 +21,7 @@ public class OptimismTransactionProcessor( IL1CostHelper l1CostHelper, IOptimismSpecHelper opSpecHelper, ICodeInfoRepository? codeInfoRepository - ) : TransactionProcessor(specProvider, worldState, virtualMachine, codeInfoRepository, logManager) + ) : TransactionProcessorBase(specProvider, worldState, virtualMachine, codeInfoRepository, logManager) { private UInt256? _currentTxL1Cost; @@ -64,14 +64,6 @@ protected override TransactionResult Execute(Transaction tx, in BlockExecutionCo return result; } - protected override TransactionResult ValidateStatic(Transaction tx, BlockHeader header, IReleaseSpec spec, ITxTracer tracer, ExecutionOptions opts, - out long intrinsicGas) - { - TransactionResult result = base.ValidateStatic(tx, header, spec, tracer, opts, out intrinsicGas); - - return result; - } - protected override TransactionResult BuyGas(Transaction tx, BlockHeader header, IReleaseSpec spec, ITxTracer tracer, ExecutionOptions opts, in UInt256 effectiveGasPrice, out UInt256 premiumPerGas, out UInt256 senderReservedGasPayment) { diff --git a/src/Nethermind/Nethermind.Optimism/ReadOnlyChainProcessingEnv.cs b/src/Nethermind/Nethermind.Optimism/ReadOnlyChainProcessingEnv.cs index 96ee2ae5a7d..c07db6d5c56 100644 --- a/src/Nethermind/Nethermind.Optimism/ReadOnlyChainProcessingEnv.cs +++ b/src/Nethermind/Nethermind.Optimism/ReadOnlyChainProcessingEnv.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Blockchain.Receipts; using Nethermind.Consensus.Processing; @@ -63,6 +64,7 @@ IBlockProcessor.IBlockTransactionsExecutor transactionsExecutor scope.WorldState, receiptStorage, new BlockhashStore(specProvider, scope.WorldState), + new BeaconBlockRootHandler(scope.TransactionProcessor), logManager, opSpecHelper, contractRewriter, diff --git a/src/Nethermind/Nethermind.Specs.Test/OverridableReleaseSpec.cs b/src/Nethermind/Nethermind.Specs.Test/OverridableReleaseSpec.cs index 09ee4bc81cd..1fcbe5d6b7c 100644 --- a/src/Nethermind/Nethermind.Specs.Test/OverridableReleaseSpec.cs +++ b/src/Nethermind/Nethermind.Specs.Test/OverridableReleaseSpec.cs @@ -55,7 +55,7 @@ public OverridableReleaseSpec(IReleaseSpec spec) public bool IsEip155Enabled => _spec.IsEip155Enabled; - public bool IsEip158Enabled => _spec.IsEip1559Enabled; + public bool IsEip158Enabled => _spec.IsEip158Enabled; public bool IsEip160Enabled => _spec.IsEip160Enabled; @@ -114,10 +114,7 @@ public OverridableReleaseSpec(IReleaseSpec spec) public bool IsRip7212Enabled => _spec.IsRip7212Enabled; public bool IsEip3607Enabled { get; set; } - public bool IsEip158IgnoredAccount(Address address) - { - return _spec.IsEip158IgnoredAccount(address); - } + public bool IsEip158IgnoredAccount(Address address) => _spec.IsEip158IgnoredAccount(address); private long? _overridenEip1559TransitionBlock; public long Eip1559TransitionBlock diff --git a/src/Nethermind/Nethermind.Specs.Test/OverridableSpecProvider.cs b/src/Nethermind/Nethermind.Specs.Test/OverridableSpecProvider.cs index 817d91feb34..fa2fbe346a2 100644 --- a/src/Nethermind/Nethermind.Specs.Test/OverridableSpecProvider.cs +++ b/src/Nethermind/Nethermind.Specs.Test/OverridableSpecProvider.cs @@ -38,6 +38,7 @@ public void UpdateMergeTransitionInfo(long? blockNumber, UInt256? terminalTotalD public ulong NetworkId => _specProvider.NetworkId; public ulong ChainId => _specProvider.ChainId; + public string SealEngine => _specProvider.SealEngine; public ForkActivation[] TransitionActivations => _specProvider.TransitionActivations; } diff --git a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs index d0b3805a52f..57da659f9bb 100644 --- a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs +++ b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs @@ -279,5 +279,6 @@ public void UpdateMergeTransitionInfo(long? blockNumber, UInt256? terminalTotalD public ulong NetworkId => _chainSpec.NetworkId; public ulong ChainId => _chainSpec.ChainId; + public string SealEngine => _chainSpec.SealEngineType; } } diff --git a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs index 068c4d19365..c1ced60f803 100644 --- a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs +++ b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs @@ -432,10 +432,9 @@ private static void LoadGenesis(ChainSpecJson chainSpecJson, ChainSpec chainSpec genesisHeader.AuRaStep = step; genesisHeader.AuRaSignature = auRaSignature; - if (withdrawalsEnabled) - chainSpec.Genesis = new Block(genesisHeader, Array.Empty(), Array.Empty(), Array.Empty()); - else - chainSpec.Genesis = new Block(genesisHeader); + chainSpec.Genesis = withdrawalsEnabled + ? new Block(genesisHeader, Array.Empty(), Array.Empty(), Array.Empty()) + : new Block(genesisHeader); } private static void LoadAllocations(ChainSpecJson chainSpecJson, ChainSpec chainSpec) diff --git a/src/Nethermind/Nethermind.Specs/ChiadoSpecProvider.cs b/src/Nethermind/Nethermind.Specs/ChiadoSpecProvider.cs index afdfab47a4c..023778e5096 100644 --- a/src/Nethermind/Nethermind.Specs/ChiadoSpecProvider.cs +++ b/src/Nethermind/Nethermind.Specs/ChiadoSpecProvider.cs @@ -42,6 +42,7 @@ public void UpdateMergeTransitionInfo(long? blockNumber, UInt256? terminalTotalD public long? DaoBlockNumber => null; public ulong NetworkId => BlockchainIds.Chiado; public ulong ChainId => BlockchainIds.Chiado; + public string SealEngine => SealEngineType.AuRa; public ForkActivation[] TransitionActivations { get; } public static ChiadoSpecProvider Instance { get; } = new(); diff --git a/src/Nethermind/Nethermind.Specs/Forks/00_Olympic.cs b/src/Nethermind/Nethermind.Specs/Forks/00_Olympic.cs index 4180bb4cd52..4fa61f4abbc 100644 --- a/src/Nethermind/Nethermind.Specs/Forks/00_Olympic.cs +++ b/src/Nethermind/Nethermind.Specs/Forks/00_Olympic.cs @@ -29,6 +29,5 @@ protected Olympic() } public static IReleaseSpec Instance => LazyInitializer.EnsureInitialized(ref _instance, () => new Olympic()); - public override bool IsEip158IgnoredAccount(Address address) => false; } } diff --git a/src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs b/src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs index e79bf4fe228..38ce4fd2552 100644 --- a/src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs +++ b/src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs @@ -55,6 +55,7 @@ public void UpdateMergeTransitionInfo(long? blockNumber, UInt256? terminalTotalD public long? DaoBlockNumber => null; public ulong NetworkId => BlockchainIds.Gnosis; public ulong ChainId => BlockchainIds.Gnosis; + public string SealEngine => SealEngineType.AuRa; public ForkActivation[] TransitionActivations { get; } public static GnosisSpecProvider Instance { get; } = new(); diff --git a/src/Nethermind/Nethermind.Specs/GoerliSpecProvider.cs b/src/Nethermind/Nethermind.Specs/GoerliSpecProvider.cs index 14a04d2ff14..4408c603aa5 100644 --- a/src/Nethermind/Nethermind.Specs/GoerliSpecProvider.cs +++ b/src/Nethermind/Nethermind.Specs/GoerliSpecProvider.cs @@ -45,6 +45,7 @@ public void UpdateMergeTransitionInfo(long? blockNumber, UInt256? terminalTotalD public ulong NetworkId => BlockchainIds.Goerli; public ulong ChainId => BlockchainIds.Goerli; + public string SealEngine => SealEngineType.Clique; public long? DaoBlockNumber => null; public ForkActivation? MergeBlockNumber { get; private set; } public ulong TimestampFork => ShanghaiTimestamp; diff --git a/src/Nethermind/Nethermind.Specs/ReleaseSpec.cs b/src/Nethermind/Nethermind.Specs/ReleaseSpec.cs index 249fbd2a200..7db782213af 100644 --- a/src/Nethermind/Nethermind.Specs/ReleaseSpec.cs +++ b/src/Nethermind/Nethermind.Specs/ReleaseSpec.cs @@ -51,13 +51,9 @@ public class ReleaseSpec : IReleaseSpec public bool IsEip2565Enabled { get; set; } public bool IsEip2929Enabled { get; set; } public bool IsEip2930Enabled { get; set; } - public virtual bool IsEip158IgnoredAccount(Address address) => address == Address.SystemUser; // used only in testing - public ReleaseSpec Clone() - { - return (ReleaseSpec)MemberwiseClone(); - } + public ReleaseSpec Clone() => (ReleaseSpec)MemberwiseClone(); public bool IsEip1559Enabled { get; set; } public bool IsEip3198Enabled { get; set; } diff --git a/src/Nethermind/Nethermind.Specs/SepoliaSpecProvider.cs b/src/Nethermind/Nethermind.Specs/SepoliaSpecProvider.cs index 739eea9d2cf..561ec1728c0 100644 --- a/src/Nethermind/Nethermind.Specs/SepoliaSpecProvider.cs +++ b/src/Nethermind/Nethermind.Specs/SepoliaSpecProvider.cs @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only +using Nethermind.Core; using Nethermind.Core.Specs; using Nethermind.Int256; using Nethermind.Specs.Forks; @@ -33,6 +34,7 @@ public void UpdateMergeTransitionInfo(long? blockNumber, UInt256? terminalTotalD public ulong NetworkId => Core.BlockchainIds.Sepolia; public ulong ChainId => NetworkId; + public string SealEngine => SealEngineType.Clique; public long? DaoBlockNumber => null; public ForkActivation? MergeBlockNumber { get; private set; } = null; public ulong TimestampFork => ISpecProvider.TimestampForkNever; diff --git a/src/Nethermind/Nethermind.Specs/SingleReleaseSpecProvider.cs b/src/Nethermind/Nethermind.Specs/SingleReleaseSpecProvider.cs index 8e6213ec749..ff963a3f420 100644 --- a/src/Nethermind/Nethermind.Specs/SingleReleaseSpecProvider.cs +++ b/src/Nethermind/Nethermind.Specs/SingleReleaseSpecProvider.cs @@ -45,13 +45,10 @@ public SingleReleaseSpecProvider(IReleaseSpec releaseSpec, ulong networkId, ulon public IReleaseSpec GetSpec(ForkActivation forkActivation) => _releaseSpec; public long? DaoBlockNumber { get; } - } - public class TestSingleReleaseSpecProvider : SingleReleaseSpecProvider - { - public TestSingleReleaseSpecProvider(IReleaseSpec releaseSpec) - : base(releaseSpec, TestBlockchainIds.NetworkId, TestBlockchainIds.ChainId) - { - } + public string SealEngine { get; set; } = SealEngineType.Ethash; } + + public class TestSingleReleaseSpecProvider(IReleaseSpec releaseSpec) + : SingleReleaseSpecProvider(releaseSpec, TestBlockchainIds.NetworkId, TestBlockchainIds.ChainId); } diff --git a/src/Nethermind/Nethermind.Specs/SystemTransactionReleaseSpec.cs b/src/Nethermind/Nethermind.Specs/SystemTransactionReleaseSpec.cs index 9d1e6bc0670..b09ad342b62 100644 --- a/src/Nethermind/Nethermind.Specs/SystemTransactionReleaseSpec.cs +++ b/src/Nethermind/Nethermind.Specs/SystemTransactionReleaseSpec.cs @@ -7,133 +7,8 @@ namespace Nethermind.Specs { - public class SystemTransactionReleaseSpec : IReleaseSpec + public class SystemTransactionReleaseSpec(IReleaseSpec spec, bool isAura, bool isGenesis) : ReleaseSpecDecorator(spec) { - private readonly IReleaseSpec _spec; - - public SystemTransactionReleaseSpec(IReleaseSpec spec) - { - _spec = spec; - } - public bool IsEip4844Enabled => _spec.IsEip4844Enabled; - public bool IsRip7212Enabled => _spec.IsRip7212Enabled; - - public string Name => "System"; - - public long MaximumExtraDataSize => _spec.MaximumExtraDataSize; - - public long MaxCodeSize => _spec.MaxCodeSize; - - public long MinGasLimit => _spec.MinGasLimit; - - public long GasLimitBoundDivisor => _spec.GasLimitBoundDivisor; - - public UInt256 BlockReward => _spec.BlockReward; - - public long DifficultyBombDelay => _spec.DifficultyBombDelay; - - public long DifficultyBoundDivisor => _spec.DifficultyBoundDivisor; - - public long? FixedDifficulty => _spec.FixedDifficulty; - - public int MaximumUncleCount => _spec.MaximumUncleCount; - - public bool IsTimeAdjustmentPostOlympic => _spec.IsTimeAdjustmentPostOlympic; - - public bool IsEip2Enabled => _spec.IsEip2Enabled; - - public bool IsEip7Enabled => _spec.IsEip7Enabled; - - public bool IsEip100Enabled => _spec.IsEip100Enabled; - - public bool IsEip140Enabled => _spec.IsEip140Enabled; - - public bool IsEip150Enabled => _spec.IsEip150Enabled; - - public bool IsEip155Enabled => _spec.IsEip155Enabled; - - public bool IsEip158Enabled => false; - - public bool IsEip160Enabled => _spec.IsEip160Enabled; - - public bool IsEip170Enabled => _spec.IsEip170Enabled; - - public bool IsEip196Enabled => _spec.IsEip196Enabled; - - public bool IsEip197Enabled => _spec.IsEip197Enabled; - - public bool IsEip198Enabled => _spec.IsEip198Enabled; - - public bool IsEip211Enabled => _spec.IsEip211Enabled; - - public bool IsEip214Enabled => _spec.IsEip214Enabled; - - public bool IsEip649Enabled => _spec.IsEip649Enabled; - - public bool IsEip658Enabled => _spec.IsEip658Enabled; - - public bool IsEip145Enabled => _spec.IsEip145Enabled; - - public bool IsEip1014Enabled => _spec.IsEip1014Enabled; - - public bool IsEip1052Enabled => _spec.IsEip1052Enabled; - - public bool IsEip1283Enabled => _spec.IsEip1283Enabled; - - public bool IsEip1234Enabled => _spec.IsEip1234Enabled; - - public bool IsEip1344Enabled => _spec.IsEip1344Enabled; - - public bool IsEip2028Enabled => _spec.IsEip2028Enabled; - - public bool IsEip152Enabled => _spec.IsEip152Enabled; - - public bool IsEip1108Enabled => _spec.IsEip1108Enabled; - - public bool IsEip1884Enabled => _spec.IsEip1884Enabled; - - public bool IsEip2200Enabled => _spec.IsEip2200Enabled; - - public bool IsEip2537Enabled => _spec.IsEip2537Enabled; - - public bool IsEip2565Enabled => _spec.IsEip2565Enabled; - - public bool IsEip2929Enabled => _spec.IsEip2929Enabled; - - public bool IsEip2930Enabled => _spec.IsEip2930Enabled; - - public bool IsEip1559Enabled => _spec.IsEip1559Enabled; - public bool IsEip3198Enabled => _spec.IsEip3198Enabled; - public bool IsEip3529Enabled => _spec.IsEip3529Enabled; - - public bool IsEip3541Enabled => _spec.IsEip3541Enabled; - public bool IsEip3607Enabled => _spec.IsEip3607Enabled; - - public bool IsEip158IgnoredAccount(Address address) - { - return _spec.IsEip158IgnoredAccount(address); - } - - public long Eip1559TransitionBlock => _spec.Eip1559TransitionBlock; - public ulong WithdrawalTimestamp => _spec.WithdrawalTimestamp; - - public ulong Eip4844TransitionTimestamp => _spec.Eip4844TransitionTimestamp; - - public Address Eip1559FeeCollector => _spec.Eip1559FeeCollector; - public bool IsEip1153Enabled => _spec.IsEip1153Enabled; - public bool IsEip3651Enabled => _spec.IsEip3651Enabled; - public bool IsEip3855Enabled => _spec.IsEip3855Enabled; - public bool IsEip3860Enabled => _spec.IsEip3860Enabled; - public bool IsEip4895Enabled => _spec.IsEip4895Enabled; - public bool IsEip5656Enabled => _spec.IsEip5656Enabled; - public bool IsEip6780Enabled => _spec.IsEip6780Enabled; - public bool IsEip4788Enabled => _spec.IsEip4788Enabled; - public Address Eip4788ContractAddress => _spec.Eip4788ContractAddress; - public bool IsEip2935Enabled => _spec.IsEip2935Enabled; - public bool IsEip7709Enabled => _spec.IsEip7709Enabled; - public Address Eip2935ContractAddress => _spec.Eip2935ContractAddress; - public UInt256 ForkBaseFee => _spec.ForkBaseFee; - public UInt256 BaseFeeMaxChangeDenominator => _spec.BaseFeeMaxChangeDenominator; - public long ElasticityMultiplier => _spec.ElasticityMultiplier; + public override bool IsEip158Enabled => !isAura && isGenesis && base.IsEip158Enabled; } } diff --git a/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs b/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs index 1a0ba7d72ee..d2d4a552603 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs @@ -6,6 +6,7 @@ using System.Threading; using System.Threading.Tasks; using Nethermind.Blockchain; +using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Blockchain.Blocks; using Nethermind.Blockchain.Receipts; using Nethermind.Blockchain.Synchronization; @@ -302,6 +303,7 @@ private SyncTestContext CreateSyncManager(int index) stateProvider, receiptStorage, new BlockhashStore(specProvider, stateProvider), + new BeaconBlockRootHandler(txProcessor), logManager); RecoverSignatures step = new(ecdsa, txPool, specProvider, logManager); @@ -324,6 +326,7 @@ private SyncTestContext CreateSyncManager(int index) devState, receiptStorage, new BlockhashStore(specProvider, devState), + new BeaconBlockRootHandler(devTxProcessor), logManager); BlockchainProcessor devChainProcessor = new(tree, devBlockProcessor, step, stateReader, logManager, diff --git a/src/Nethermind/Nethermind.Trie/TreeDumper.cs b/src/Nethermind/Nethermind.Trie/TreeDumper.cs index c7199c09877..c2c03cc695e 100644 --- a/src/Nethermind/Nethermind.Trie/TreeDumper.cs +++ b/src/Nethermind/Nethermind.Trie/TreeDumper.cs @@ -19,7 +19,7 @@ public void Reset() _builder.Clear(); } - public bool IsFullDbScan => true; + public bool IsFullDbScan { get; init; } = true; public bool ShouldVisit(Hash256 nextNode) { diff --git a/src/Nethermind/Nethermind.TxPool.Test/TxPoolTests.cs b/src/Nethermind/Nethermind.TxPool.Test/TxPoolTests.cs index 2510d106826..289e4604bec 100644 --- a/src/Nethermind/Nethermind.TxPool.Test/TxPoolTests.cs +++ b/src/Nethermind/Nethermind.TxPool.Test/TxPoolTests.cs @@ -183,7 +183,7 @@ public void should_accept_1559_transactions_only_when_eip1559_enabled([Values(fa if (eip1559Enabled) { specProvider = Substitute.For(); - specProvider.GetSpec(Arg.Any()).Returns(London.Instance); + specProvider.GetSpec(Arg.Any()).Returns(London.Instance); } var txPool = CreatePool(null, specProvider); Transaction tx = Build.A.Transaction @@ -1743,7 +1743,6 @@ private static ISpecProvider GetLondonSpecProvider() { var specProvider = Substitute.For(); specProvider.GetSpec(Arg.Any()).Returns(London.Instance); - specProvider.GetSpec(Arg.Any()).Returns(London.Instance); return specProvider; } @@ -1751,7 +1750,6 @@ private static ISpecProvider GetCancunSpecProvider() { var specProvider = Substitute.For(); specProvider.GetSpec(Arg.Any()).Returns(Cancun.Instance); - specProvider.GetSpec(Arg.Any()).Returns(Cancun.Instance); return specProvider; }