diff --git a/src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs b/src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs index fe5fb25c019..66df7e618ee 100644 --- a/src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs +++ b/src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs @@ -171,7 +171,7 @@ protected async Task RunTest(BlockchainTest test, Stopwatch? stateProvider, receiptStorage, transactionProcessor, - new BeaconBlockRootHandler(transactionProcessor), + new BeaconBlockRootHandler(transactionProcessor, stateProvider), new BlockhashStore(specProvider, stateProvider), _logManager); diff --git a/src/Nethermind/Nethermind.AuRa.Test/AuraBlockProcessorTests.cs b/src/Nethermind/Nethermind.AuRa.Test/AuraBlockProcessorTests.cs index 5ca0f63f74d..2da9aabbc1c 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/AuraBlockProcessorTests.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/AuraBlockProcessorTests.cs @@ -158,7 +158,7 @@ void Process(AuRaBlockProcessor auRaBlockProcessor, int blockNumber, Hash256 sta new BlockProcessor.BlockValidationTransactionsExecutor(transactionProcessor, stateProvider), stateProvider, NullReceiptStorage.Instance, - new BeaconBlockRootHandler(transactionProcessor), + new BeaconBlockRootHandler(transactionProcessor, stateProvider), LimboLogs.Instance, Substitute.For(), new WithdrawalProcessor(stateProvider, LimboLogs.Instance), diff --git a/src/Nethermind/Nethermind.AuRa.Test/Contract/AuRaContractGasLimitOverrideTests.cs b/src/Nethermind/Nethermind.AuRa.Test/Contract/AuRaContractGasLimitOverrideTests.cs index bcbe3b8be48..6f2f7b13d6d 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/Contract/AuRaContractGasLimitOverrideTests.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/Contract/AuRaContractGasLimitOverrideTests.cs @@ -97,7 +97,7 @@ protected override BlockProcessor CreateBlockProcessor() new BlockProcessor.BlockValidationTransactionsExecutor(TxProcessor, State), State, ReceiptStorage, - new BeaconBlockRootHandler(TxProcessor), + new BeaconBlockRootHandler(TxProcessor, State), LimboLogs.Instance, BlockTree, NullWithdrawalProcessor.Instance, diff --git a/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxCertifierFilterTests.cs b/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxCertifierFilterTests.cs index c754ce285f8..cda399944da 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxCertifierFilterTests.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxCertifierFilterTests.cs @@ -154,7 +154,7 @@ protected override BlockProcessor CreateBlockProcessor() new BlockProcessor.BlockValidationTransactionsExecutor(TxProcessor, State), State, ReceiptStorage, - new BeaconBlockRootHandler(TxProcessor), + new BeaconBlockRootHandler(TxProcessor, State), LimboLogs.Instance, BlockTree, NullWithdrawalProcessor.Instance, diff --git a/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxPermissionFilterTest.cs b/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxPermissionFilterTest.cs index de6de6eb464..da04745095f 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxPermissionFilterTest.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxPermissionFilterTest.cs @@ -296,7 +296,7 @@ protected override BlockProcessor CreateBlockProcessor() new BlockProcessor.BlockValidationTransactionsExecutor(TxProcessor, State), State, ReceiptStorage, - new BeaconBlockRootHandler(TxProcessor), + new BeaconBlockRootHandler(TxProcessor, State), LimboLogs.Instance, BlockTree, NullWithdrawalProcessor.Instance, diff --git a/src/Nethermind/Nethermind.Blockchain.Test/BeaconBlockRootHandlerTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/BeaconBlockRootHandlerTests.cs new file mode 100644 index 00000000000..8f3e5461c7d --- /dev/null +++ b/src/Nethermind/Nethermind.Blockchain.Test/BeaconBlockRootHandlerTests.cs @@ -0,0 +1,156 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using Nethermind.Blockchain.BeaconBlockRoot; +using Nethermind.Core; +using Nethermind.Core.Crypto; +using Nethermind.Core.Eip2930; +using Nethermind.Core.Test.Builders; +using Nethermind.Crypto; +using Nethermind.Evm; +using Nethermind.Evm.Tracing; +using Nethermind.Evm.TransactionProcessing; +using Nethermind.Int256; +using Nethermind.Specs.Forks; +using Nethermind.State; +using NSubstitute; +using NUnit.Framework; + +namespace Nethermind.Blockchain.Test; + +public class BeaconBlockRootHandlerTests +{ + private BeaconBlockRootHandler _beaconBlockRootHandler; + private ITransactionProcessor _transactionProcessor; + private IWorldState _worldState; + + [SetUp] + public void Setup() + { + _worldState = Substitute.For(); + _transactionProcessor = Substitute.For(); + _beaconBlockRootHandler = new BeaconBlockRootHandler(_transactionProcessor, _worldState); + } + + [Test] + public void Test_BeaconRootsAccessList_IsBeaconBlockRootAvailableFalse() + { + BlockHeader header = Build.A.BlockHeader.WithNumber(1).WithParentBeaconBlockRoot(Hash256.Zero).TestObject; + Block block = Build.A.Block.WithHeader(header).TestObject; + _worldState.AccountExists(Arg.Any
()).Returns(true); + + (Address? toAddress, AccessList? accessList) result = _beaconBlockRootHandler + .BeaconRootsAccessList(block, Shanghai.Instance); + + Assert.That(result.accessList, Is.Null); + Assert.That(result.toAddress, Is.Null); + } + + [Test] + public void Test_BeaconRootsAccessList_HeaderIsGenesis() + { + BlockHeader header = Build.A.BlockHeader.WithParentBeaconBlockRoot(Hash256.Zero).TestObject; + Block block = Build.A.Block.WithHeader(header).TestObject; + _worldState.AccountExists(Arg.Any
()).Returns(true); + + (Address? toAddress, AccessList? accessList) result = _beaconBlockRootHandler + .BeaconRootsAccessList(block, Cancun.Instance); + + Assert.That(result.accessList, Is.Null); + Assert.That(result.toAddress, Is.Null); + } + + [Test] + public void Test_BeaconRootsAccessList_ParentBeaconBlockRootIsNull() + { + BlockHeader header = Build.A.BlockHeader.WithNumber(1).TestObject; + Block block = Build.A.Block.WithHeader(header).TestObject; + _worldState.AccountExists(Arg.Any
()).Returns(true); + + (Address? toAddress, AccessList? accessList) result = _beaconBlockRootHandler + .BeaconRootsAccessList(block, Cancun.Instance); + + Assert.That(result.accessList, Is.Null); + Assert.That(result.toAddress, Is.Null); + } + + [Test] + public void Test_BeaconRootsAccessList_canInsertBeaconRootIsTrue_AccountNotExist() + { + BlockHeader header = Build.A.BlockHeader.WithNumber(1).WithParentBeaconBlockRoot(Hash256.Zero).TestObject; + Block block = Build.A.Block.WithHeader(header).TestObject; + _worldState.AccountExists(Arg.Any
()).Returns(false); + + (Address? toAddress, AccessList? accessList) result = _beaconBlockRootHandler + .BeaconRootsAccessList(block, Cancun.Instance); + + Assert.That(result.accessList, Is.Null); + Assert.That(result.toAddress, Is.Null); + } + + [Test] + public void Test_BeaconRootsAccessList_canInsertBeaconRootIsTrue_AccountExists() + { + BlockHeader header = Build.A.BlockHeader.WithNumber(1).WithParentBeaconBlockRoot(Hash256.Zero).TestObject; + Block block = Build.A.Block.WithHeader(header).TestObject; + _worldState.AccountExists(Arg.Any
()).Returns(true); + + (Address? toAddress, AccessList? accessList) result = _beaconBlockRootHandler + .BeaconRootsAccessList(block, Cancun.Instance); + + Assert.That(result.accessList, Is.Not.Null); + Assert.That(result.accessList.Count.AddressesCount, Is.EqualTo(1)); + Assert.That(result.accessList.Count.StorageKeysCount, Is.EqualTo(1)); + } + + [Test] + public void Test_BeaconRootsAccessList_canInsertBeaconRootIsTrue_AccountExists_IncludeStorageCellsIsFalse() + { + BlockHeader header = Build.A.BlockHeader.WithNumber(1).WithParentBeaconBlockRoot(Hash256.Zero).TestObject; + Block block = Build.A.Block.WithHeader(header).TestObject; + _worldState.AccountExists(Arg.Any
()).Returns(true); + + (Address? toAddress, AccessList? accessList) result = _beaconBlockRootHandler + .BeaconRootsAccessList(block, Cancun.Instance, false); + + Assert.That(result.accessList, Is.Not.Null); + Assert.That(result.accessList.Count.AddressesCount, Is.EqualTo(1)); + Assert.That(result.accessList.Count.StorageKeysCount, Is.EqualTo(0)); + } + + [Test] + public void Test_StoreBeaconRoot_AccessListIsNull() + { + BlockHeader header = Build.A.BlockHeader.TestObject; + Block block = Build.A.Block.WithHeader(header).TestObject; + + _beaconBlockRootHandler.StoreBeaconRoot(block, Cancun.Instance); + + _transactionProcessor.DidNotReceive().Execute(Arg.Any(), Arg.Any(), Arg.Any()); + } + + [Test] + public void Test_StoreBeaconRoot_AccessListNotNull() + { + BlockHeader header = Build.A.BlockHeader.WithNumber(1).WithParentBeaconBlockRoot(Hash256.Zero).TestObject; + Block block = Build.A.Block.WithHeader(header).TestObject; + _worldState.AccountExists(Arg.Any
()).Returns(true); + + _beaconBlockRootHandler.StoreBeaconRoot(block, Cancun.Instance); + + Transaction transaction = new() + { + Value = UInt256.Zero, + Data = header.ParentBeaconBlockRoot!.Bytes.ToArray(), + To = Eip4788Constants.BeaconRootsAddress, + SenderAddress = Address.SystemUser, + GasLimit = 30_000_000L, + GasPrice = UInt256.Zero, + AccessList = new AccessList.Builder().AddAddress(Eip4788Constants.BeaconRootsAddress).Build() + }; + + transaction.Hash = transaction.CalculateHash(); + _transactionProcessor.Received().Execute(Arg.Is(t => + t.Hash == transaction.Hash), header, NullTxTracer.Instance); + } +} diff --git a/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs index 60c7c37b66e..a9c11d23a2d 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs @@ -50,7 +50,7 @@ public void Prepared_block_contains_author_field() stateProvider, NullReceiptStorage.Instance, transactionProcessor, - new BeaconBlockRootHandler(transactionProcessor), + new BeaconBlockRootHandler(transactionProcessor, stateProvider), Substitute.For(), LimboLogs.Instance); @@ -81,7 +81,7 @@ public void Recovers_state_on_cancel() stateProvider, NullReceiptStorage.Instance, transactionProcessor, - new BeaconBlockRootHandler(transactionProcessor), + new BeaconBlockRootHandler(transactionProcessor, stateProvider), Substitute.For(), LimboLogs.Instance); diff --git a/src/Nethermind/Nethermind.Blockchain.Test/Producers/DevBlockproducerTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/Producers/DevBlockproducerTests.cs index 096dcd6db9a..1453c55dadd 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/Producers/DevBlockproducerTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/Producers/DevBlockproducerTests.cs @@ -76,7 +76,7 @@ public void Test() stateProvider, NullReceiptStorage.Instance, txProcessor, - new BeaconBlockRootHandler(txProcessor), + new BeaconBlockRootHandler(txProcessor, stateProvider), new BlockhashStore(specProvider, stateProvider), LimboLogs.Instance); BlockchainProcessor blockchainProcessor = new( diff --git a/src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs index 88274cfd17b..0f87b9ea846 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs @@ -78,7 +78,7 @@ public void Setup() stateProvider, NullReceiptStorage.Instance, transactionProcessor, - new BeaconBlockRootHandler(transactionProcessor), + new BeaconBlockRootHandler(transactionProcessor, stateProvider), new BlockhashStore(MainnetSpecProvider.Instance, stateProvider), LimboLogs.Instance); _blockchainProcessor = new BlockchainProcessor( diff --git a/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs b/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs index c464091ba49..a9a519e4492 100644 --- a/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs +++ b/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs @@ -1,7 +1,6 @@ // SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only -using System; using Nethermind.Core; using Nethermind.Core.Eip2930; using Nethermind.Core.Specs; @@ -9,9 +8,10 @@ using Nethermind.Evm.Tracing; using Nethermind.Evm.TransactionProcessing; using Nethermind.Int256; +using Nethermind.State; namespace Nethermind.Blockchain.BeaconBlockRoot; -public class BeaconBlockRootHandler(ITransactionProcessor processor) : IBeaconBlockRootHandler +public class BeaconBlockRootHandler(ITransactionProcessor processor, IWorldState stateProvider) : IBeaconBlockRootHandler { private const long GasLimit = 30_000_000L; @@ -26,7 +26,7 @@ public class BeaconBlockRootHandler(ITransactionProcessor processor) : IBeaconBl spec.Eip4788ContractAddress ?? Eip4788Constants.BeaconRootsAddress : null; - if (eip4788ContractAddress is null) + if (eip4788ContractAddress is null || !stateProvider.AccountExists(eip4788ContractAddress)) { return (null, null); } diff --git a/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/IBeaconBlockRootHandler.cs b/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/IBeaconBlockRootHandler.cs index d6e3ec0f5ed..05aea2133ea 100644 --- a/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/IBeaconBlockRootHandler.cs +++ b/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/IBeaconBlockRootHandler.cs @@ -4,6 +4,7 @@ using Nethermind.Core; using Nethermind.Core.Eip2930; using Nethermind.Core.Specs; +using Nethermind.State; namespace Nethermind.Blockchain.BeaconBlockRoot; public interface IBeaconBlockRootHandler diff --git a/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs b/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs index 83e2f3b5372..1a56439105b 100644 --- a/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs +++ b/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs @@ -140,7 +140,7 @@ public On CreateNode(PrivateKey privateKey, bool withGenesisAlreadyProcessed = f stateProvider, NullReceiptStorage.Instance, transactionProcessor, - new BeaconBlockRootHandler(transactionProcessor), + new BeaconBlockRootHandler(transactionProcessor, stateProvider), new BlockhashStore(goerliSpecProvider, stateProvider), nodeLogManager); @@ -161,7 +161,7 @@ public On CreateNode(PrivateKey privateKey, bool withGenesisAlreadyProcessed = f minerStateProvider, NullReceiptStorage.Instance, minerTransactionProcessor, - new BeaconBlockRootHandler(minerTransactionProcessor), + new BeaconBlockRootHandler(minerTransactionProcessor, minerStateProvider), new BlockhashStore(goerliSpecProvider, minerStateProvider), nodeLogManager); diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/InitializeBlockchainAuRa.cs b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/InitializeBlockchainAuRa.cs index d2a3952e8f0..cf7ac81bbc7 100644 --- a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/InitializeBlockchainAuRa.cs +++ b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/InitializeBlockchainAuRa.cs @@ -108,7 +108,7 @@ protected virtual AuRaBlockProcessor NewAuraBlockProcessor(ITxFilter txFilter, B new BlockProcessor.BlockValidationTransactionsExecutor(_api.TransactionProcessor, worldState), worldState, _api.ReceiptStorage!, - new BeaconBlockRootHandler(_api.TransactionProcessor!), + new BeaconBlockRootHandler(_api.TransactionProcessor!, worldState), _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 5fa09b539d8..2b3d2d5578e 100644 --- a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/StartBlockProducerAuRa.cs +++ b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/StartBlockProducerAuRa.cs @@ -155,7 +155,7 @@ private BlockProcessor CreateBlockProcessor(IReadOnlyTxProcessingScope changeabl _api.BlockProducerEnvFactory.TransactionsExecutorFactory.Create(changeableTxProcessingEnv), changeableTxProcessingEnv.WorldState, _api.ReceiptStorage, - new BeaconBlockRootHandler(changeableTxProcessingEnv.TransactionProcessor), + new BeaconBlockRootHandler(changeableTxProcessingEnv.TransactionProcessor, changeableTxProcessingEnv.WorldState), _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 9167e80f900..153a2941487 100644 --- a/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs +++ b/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs @@ -113,7 +113,7 @@ public IBlockProducer InitBlockProducer(ITxSource? additionalTxSource = null) scope.WorldState, NullReceiptStorage.Instance, getFromApi.TransactionProcessor, - new BeaconBlockRootHandler(scope.TransactionProcessor), + new BeaconBlockRootHandler(scope.TransactionProcessor, scope.WorldState), new BlockhashStore(getFromApi.SpecProvider, scope.WorldState), 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 215ae44e976..7c1be4c3c90 100644 --- a/src/Nethermind/Nethermind.Consensus.Ethash/NethDevPlugin.cs +++ b/src/Nethermind/Nethermind.Consensus.Ethash/NethDevPlugin.cs @@ -83,7 +83,7 @@ public IBlockProducer InitBlockProducer(ITxSource? additionalTxSource = null) scope.WorldState, NullReceiptStorage.Instance, scope.TransactionProcessor, - new BeaconBlockRootHandler(scope.TransactionProcessor), + new BeaconBlockRootHandler(scope.TransactionProcessor, scope.WorldState), new BlockhashStore(getFromApi.SpecProvider, scope.WorldState), getFromApi.LogManager); diff --git a/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyChainProcessingEnv.cs b/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyChainProcessingEnv.cs index 0b278165205..97954e1ed5c 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyChainProcessingEnv.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyChainProcessingEnv.cs @@ -69,7 +69,7 @@ IBlockProcessor.IBlockTransactionsExecutor transactionsExecutor scope.WorldState, receiptStorage, scope.TransactionProcessor, - new BeaconBlockRootHandler(scope.TransactionProcessor), + new BeaconBlockRootHandler(scope.TransactionProcessor, scope.WorldState), new BlockhashStore(specProvider, scope.WorldState), logManager); } diff --git a/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerEnvFactory.cs b/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerEnvFactory.cs index f896766bfbd..85e5697a8be 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerEnvFactory.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerEnvFactory.cs @@ -155,7 +155,7 @@ protected virtual BlockProcessor CreateBlockProcessor( readOnlyTxProcessingEnv.WorldState, receiptStorage, readOnlyTxProcessingEnv.TransactionProcessor, - new BeaconBlockRootHandler(readOnlyTxProcessingEnv.TransactionProcessor), + new BeaconBlockRootHandler(readOnlyTxProcessingEnv.TransactionProcessor, readOnlyTxProcessingEnv.WorldState), new BlockhashStore(_specProvider, readOnlyTxProcessingEnv.WorldState), 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 2af6892ee13..fb5118b4861 100644 --- a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs +++ b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs @@ -200,7 +200,7 @@ protected virtual async Task Build(ISpecProvider? specProvider = HeaderValidator = new HeaderValidator(BlockTree, Always.Valid, SpecProvider, LogManager); _canonicalityMonitor ??= new ReceiptCanonicalityMonitor(ReceiptStorage, LogManager); - BeaconBlockRootHandler = new BeaconBlockRootHandler(TxProcessor); + BeaconBlockRootHandler = new BeaconBlockRootHandler(TxProcessor, State); BlockValidator = new BlockValidator( new TxValidator(SpecProvider.ChainId), @@ -216,7 +216,6 @@ 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(TxProcessor); BlockProcessor = CreateBlockProcessor(); BlockchainProcessor chainProcessor = new(BlockTree, BlockProcessor, BlockPreprocessorStep, StateReader, LogManager, Consensus.Processing.BlockchainProcessor.Options.Default); @@ -390,7 +389,7 @@ protected virtual IBlockProcessor CreateBlockProcessor() => State, ReceiptStorage, TxProcessor, - new BeaconBlockRootHandler(TxProcessor), + new BeaconBlockRootHandler(TxProcessor, State), new BlockhashStore(SpecProvider, State), LogManager, preWarmer: CreateBlockCachePreWarmer(), diff --git a/src/Nethermind/Nethermind.Facade/Simulate/SimulateReadOnlyBlocksProcessingEnv.cs b/src/Nethermind/Nethermind.Facade/Simulate/SimulateReadOnlyBlocksProcessingEnv.cs index 5196c1850ac..c86b147817e 100644 --- a/src/Nethermind/Nethermind.Facade/Simulate/SimulateReadOnlyBlocksProcessingEnv.cs +++ b/src/Nethermind/Nethermind.Facade/Simulate/SimulateReadOnlyBlocksProcessingEnv.cs @@ -115,7 +115,7 @@ public IBlockProcessor GetProcessor(bool validate, UInt256? blobBaseFeeOverride) StateProvider, NullReceiptStorage.Instance, _transactionProcessor, - new BeaconBlockRootHandler(_transactionProcessor), + new BeaconBlockRootHandler(_transactionProcessor, StateProvider), new BlockhashStore(SpecProvider, StateProvider), _logManager); } diff --git a/src/Nethermind/Nethermind.Init/Steps/InitializeBlockchain.cs b/src/Nethermind/Nethermind.Init/Steps/InitializeBlockchain.cs index 92aea789e83..630809f8b53 100644 --- a/src/Nethermind/Nethermind.Init/Steps/InitializeBlockchain.cs +++ b/src/Nethermind/Nethermind.Init/Steps/InitializeBlockchain.cs @@ -238,7 +238,7 @@ protected virtual BlockProcessor CreateBlockProcessor(BlockCachePreWarmer? preWa worldState, _api.ReceiptStorage, _api.TransactionProcessor, - new BeaconBlockRootHandler(_api.TransactionProcessor), + new BeaconBlockRootHandler(_api.TransactionProcessor, worldState), new BlockhashStore(_api.SpecProvider!, worldState), _api.LogManager, preWarmer: preWarmer diff --git a/src/Nethermind/Nethermind.JsonRpc.Benchmark/EthModuleBenchmarks.cs b/src/Nethermind/Nethermind.JsonRpc.Benchmark/EthModuleBenchmarks.cs index 885496c6812..02a8abacccd 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Benchmark/EthModuleBenchmarks.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Benchmark/EthModuleBenchmarks.cs @@ -104,7 +104,7 @@ TransactionProcessor transactionProcessor stateProvider, NullReceiptStorage.Instance, transactionProcessor, - new BeaconBlockRootHandler(transactionProcessor), + new BeaconBlockRootHandler(transactionProcessor, stateProvider), new BlockhashStore(specProvider, stateProvider), LimboLogs.Instance); diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Trace/ParityStyleTracerTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Trace/ParityStyleTracerTests.cs index f9b10675107..1c4023f547f 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Trace/ParityStyleTracerTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Trace/ParityStyleTracerTests.cs @@ -73,7 +73,7 @@ public void Setup() stateProvider, NullReceiptStorage.Instance, transactionProcessor, - new BeaconBlockRootHandler(transactionProcessor), + new BeaconBlockRootHandler(transactionProcessor, stateProvider), new BlockhashStore(specProvider, stateProvider), LimboLogs.Instance); diff --git a/src/Nethermind/Nethermind.Merge.AuRa.Test/AuRaMergeEngineModuleTests.cs b/src/Nethermind/Nethermind.Merge.AuRa.Test/AuRaMergeEngineModuleTests.cs index b2d1e4c26ab..663c941b485 100644 --- a/src/Nethermind/Nethermind.Merge.AuRa.Test/AuRaMergeEngineModuleTests.cs +++ b/src/Nethermind/Nethermind.Merge.AuRa.Test/AuRaMergeEngineModuleTests.cs @@ -153,7 +153,7 @@ protected override IBlockProcessor CreateBlockProcessor() State, ReceiptStorage, TxProcessor, - new BeaconBlockRootHandler(TxProcessor), + new BeaconBlockRootHandler(TxProcessor, State), new BlockhashStore(SpecProvider, State), LogManager, WithdrawalProcessor, diff --git a/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProducerEnvFactory.cs b/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProducerEnvFactory.cs index 741930723bf..faf77f16d32 100644 --- a/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProducerEnvFactory.cs +++ b/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProducerEnvFactory.cs @@ -75,7 +75,7 @@ protected override BlockProcessor CreateBlockProcessor( TransactionsExecutorFactory.Create(readOnlyTxProcessingEnv), readOnlyTxProcessingEnv.WorldState, receiptStorage, - new BeaconBlockRootHandler(readOnlyTxProcessingEnv.TransactionProcessor), + new BeaconBlockRootHandler(readOnlyTxProcessingEnv.TransactionProcessor, readOnlyTxProcessingEnv.WorldState), 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 d37d4fb9b1a..6fec278699c 100644 --- a/src/Nethermind/Nethermind.Merge.AuRa/InitializationSteps/InitializeBlockchainAuRaMerge.cs +++ b/src/Nethermind/Nethermind.Merge.AuRa/InitializationSteps/InitializeBlockchainAuRaMerge.cs @@ -43,7 +43,7 @@ protected override AuRaBlockProcessor NewAuraBlockProcessor(ITxFilter txFilter, new BlockProcessor.BlockValidationTransactionsExecutor(transactionProcessor, worldState), worldState, _api.ReceiptStorage!, - new BeaconBlockRootHandler(transactionProcessor), + new BeaconBlockRootHandler(transactionProcessor, worldState), _api.LogManager, _api.BlockTree!, new AuraWithdrawalProcessor(withdrawalContractFactory.Create(transactionProcessor), _api.LogManager), diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs index 2de5457185a..abfce411741 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs @@ -153,7 +153,7 @@ private static ExecutionPayloadV4 CreateBlockRequestV4(MergeTestBlockchain chain ExecutionPayloadV4 blockRequestV4 = CreateBlockRequestInternal(parent, miner, withdrawals, blobGasUsed, excessBlobGas, transactions: transactions, parentBeaconBlockRoot: parentBeaconBlockRoot, requests: requests); blockRequestV4.TryGetBlock(out Block? block); - var beaconBlockRootHandler = new BeaconBlockRootHandler(chain.TxProcessor); + var beaconBlockRootHandler = new BeaconBlockRootHandler(chain.TxProcessor, chain.WorldStateManager.GlobalWorldState); beaconBlockRootHandler.StoreBeaconRoot(block!, chain.SpecProvider.GetSpec(block!.Header)); Snapshot before = chain.State.TakeSnapshot(); var blockHashStore = new BlockhashStore(chain.SpecProvider, chain.State); diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs index a95d1a9479b..cffbfafb516 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs @@ -255,7 +255,7 @@ protected override IBlockProcessor CreateBlockProcessor() State, ReceiptStorage, TxProcessor, - new BeaconBlockRootHandler(TxProcessor), + new BeaconBlockRootHandler(TxProcessor, State), new BlockhashStore(SpecProvider, State), LogManager, WithdrawalProcessor, diff --git a/src/Nethermind/Nethermind.Optimism/InitializeBlockchainOptimism.cs b/src/Nethermind/Nethermind.Optimism/InitializeBlockchainOptimism.cs index 5f53d0f31eb..f7ce6c9b833 100644 --- a/src/Nethermind/Nethermind.Optimism/InitializeBlockchainOptimism.cs +++ b/src/Nethermind/Nethermind.Optimism/InitializeBlockchainOptimism.cs @@ -100,7 +100,7 @@ protected override BlockProcessor CreateBlockProcessor(BlockCachePreWarmer? preW api.ReceiptStorage, transactionProcessor, new BlockhashStore(api.SpecProvider, api.WorldState), - new BeaconBlockRootHandler(transactionProcessor), + new BeaconBlockRootHandler(transactionProcessor, api.WorldState), api.LogManager, api.SpecHelper, contractRewriter, diff --git a/src/Nethermind/Nethermind.Optimism/OptimismBlockProducerEnvFactory.cs b/src/Nethermind/Nethermind.Optimism/OptimismBlockProducerEnvFactory.cs index 88ee38dd5e3..3056aa4fbad 100644 --- a/src/Nethermind/Nethermind.Optimism/OptimismBlockProducerEnvFactory.cs +++ b/src/Nethermind/Nethermind.Optimism/OptimismBlockProducerEnvFactory.cs @@ -89,7 +89,7 @@ protected override BlockProcessor CreateBlockProcessor( receiptStorage, readOnlyTxProcessingEnv.TransactionProcessor, new BlockhashStore(specProvider, readOnlyTxProcessingEnv.WorldState), - new BeaconBlockRootHandler(readOnlyTxProcessingEnv.TransactionProcessor), + new BeaconBlockRootHandler(readOnlyTxProcessingEnv.TransactionProcessor, readOnlyTxProcessingEnv.WorldState), logManager, _specHelper, new Create2DeployerContractRewriter(_specHelper, _specProvider, _blockTree), diff --git a/src/Nethermind/Nethermind.Optimism/ReadOnlyChainProcessingEnv.cs b/src/Nethermind/Nethermind.Optimism/ReadOnlyChainProcessingEnv.cs index 3e1e3cbe011..05e6b898ffe 100644 --- a/src/Nethermind/Nethermind.Optimism/ReadOnlyChainProcessingEnv.cs +++ b/src/Nethermind/Nethermind.Optimism/ReadOnlyChainProcessingEnv.cs @@ -65,7 +65,7 @@ IBlockProcessor.IBlockTransactionsExecutor transactionsExecutor receiptStorage, scope.TransactionProcessor, new BlockhashStore(specProvider, scope.WorldState), - new BeaconBlockRootHandler(scope.TransactionProcessor), + new BeaconBlockRootHandler(scope.TransactionProcessor, scope.WorldState), logManager, opSpecHelper, contractRewriter, diff --git a/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs b/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs index 33e43446a69..ada2c15efb3 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs @@ -307,7 +307,7 @@ private SyncTestContext CreateSyncManager(int index) stateProvider, receiptStorage, txProcessor, - new BeaconBlockRootHandler(txProcessor), + new BeaconBlockRootHandler(txProcessor, stateProvider), new BlockhashStore(specProvider, stateProvider), logManager); @@ -331,7 +331,7 @@ private SyncTestContext CreateSyncManager(int index) devState, receiptStorage, devTxProcessor, - new BeaconBlockRootHandler(devTxProcessor), + new BeaconBlockRootHandler(devTxProcessor, devState), new BlockhashStore(specProvider, devState), logManager);