Skip to content

Commit

Permalink
pass worldState to BeaconBlockRootHandler constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
yerke26 committed Oct 20, 2024
1 parent e6b5585 commit c8f0aba
Show file tree
Hide file tree
Showing 32 changed files with 50 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<IBlockTree>(),
new WithdrawalProcessor(stateProvider, LimboLogs.Instance),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Setup()
{
_worldState = Substitute.For<IWorldState>();
_transactionProcessor = Substitute.For<ITransactionProcessor>();
_beaconBlockRootHandler = new BeaconBlockRootHandler(_transactionProcessor);
_beaconBlockRootHandler = new BeaconBlockRootHandler(_transactionProcessor, _worldState);
}

[Test]
Expand All @@ -40,7 +40,7 @@ public void Test_BeaconRootsAccessList_IsBeaconBlockRootAvailableFalse()
_worldState.AccountExists(Arg.Any<Address>()).Returns(true);

(Address? toAddress, AccessList? accessList) result = _beaconBlockRootHandler
.BeaconRootsAccessList(block, Shanghai.Instance, _worldState);
.BeaconRootsAccessList(block, Shanghai.Instance);

Assert.That(result.accessList, Is.Null);
Assert.That(result.toAddress, Is.Null);
Expand All @@ -54,7 +54,7 @@ public void Test_BeaconRootsAccessList_HeaderIsGenesis()
_worldState.AccountExists(Arg.Any<Address>()).Returns(true);

(Address? toAddress, AccessList? accessList) result = _beaconBlockRootHandler
.BeaconRootsAccessList(block, Cancun.Instance, _worldState);
.BeaconRootsAccessList(block, Cancun.Instance);

Assert.That(result.accessList, Is.Null);
Assert.That(result.toAddress, Is.Null);
Expand All @@ -68,7 +68,7 @@ public void Test_BeaconRootsAccessList_ParentBeaconBlockRootIsNull()
_worldState.AccountExists(Arg.Any<Address>()).Returns(true);

(Address? toAddress, AccessList? accessList) result = _beaconBlockRootHandler
.BeaconRootsAccessList(block, Cancun.Instance, _worldState);
.BeaconRootsAccessList(block, Cancun.Instance);

Assert.That(result.accessList, Is.Null);
Assert.That(result.toAddress, Is.Null);
Expand All @@ -82,7 +82,7 @@ public void Test_BeaconRootsAccessList_canInsertBeaconRootIsTrue_AccountNotExist
_worldState.AccountExists(Arg.Any<Address>()).Returns(false);

(Address? toAddress, AccessList? accessList) result = _beaconBlockRootHandler
.BeaconRootsAccessList(block, Cancun.Instance, _worldState);
.BeaconRootsAccessList(block, Cancun.Instance);

Assert.That(result.accessList, Is.Null);
Assert.That(result.toAddress, Is.Null);
Expand All @@ -96,7 +96,7 @@ public void Test_BeaconRootsAccessList_canInsertBeaconRootIsTrue_AccountExists()
_worldState.AccountExists(Arg.Any<Address>()).Returns(true);

(Address? toAddress, AccessList? accessList) result = _beaconBlockRootHandler
.BeaconRootsAccessList(block, Cancun.Instance, _worldState);
.BeaconRootsAccessList(block, Cancun.Instance);

Assert.That(result.accessList, Is.Not.Null);
Assert.That(result.accessList.Count.AddressesCount, Is.EqualTo(1));
Expand All @@ -111,7 +111,7 @@ public void Test_BeaconRootsAccessList_canInsertBeaconRootIsTrue_AccountExists_I
_worldState.AccountExists(Arg.Any<Address>()).Returns(true);

(Address? toAddress, AccessList? accessList) result = _beaconBlockRootHandler
.BeaconRootsAccessList(block, Cancun.Instance, _worldState, false);
.BeaconRootsAccessList(block, Cancun.Instance, false);

Assert.That(result.accessList, Is.Not.Null);
Assert.That(result.accessList.Count.AddressesCount, Is.EqualTo(1));
Expand All @@ -124,7 +124,7 @@ public void Test_StoreBeaconRoot_AccessListIsNull()
BlockHeader header = Build.A.BlockHeader.TestObject;
Block block = Build.A.Block.WithHeader(header).TestObject;

_beaconBlockRootHandler.StoreBeaconRoot(block, Cancun.Instance, _worldState);
_beaconBlockRootHandler.StoreBeaconRoot(block, Cancun.Instance);

_transactionProcessor.DidNotReceive().Execute(Arg.Any<Transaction>(), Arg.Any<BlockExecutionContext>(), Arg.Any<ITxTracer>());
}
Expand All @@ -136,7 +136,7 @@ public void Test_StoreBeaconRoot_AccessListNotNull()
Block block = Build.A.Block.WithHeader(header).TestObject;
_worldState.AccountExists(Arg.Any<Address>()).Returns(true);

_beaconBlockRootHandler.StoreBeaconRoot(block, Cancun.Instance, _worldState);
_beaconBlockRootHandler.StoreBeaconRoot(block, Cancun.Instance);

Transaction transaction = new()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void Prepared_block_contains_author_field()
stateProvider,
NullReceiptStorage.Instance,
transactionProcessor,
new BeaconBlockRootHandler(transactionProcessor),
new BeaconBlockRootHandler(transactionProcessor, stateProvider),
Substitute.For<IBlockhashStore>(),
LimboLogs.Instance);

Expand Down Expand Up @@ -81,7 +81,7 @@ public void Recovers_state_on_cancel()
stateProvider,
NullReceiptStorage.Instance,
transactionProcessor,
new BeaconBlockRootHandler(transactionProcessor),
new BeaconBlockRootHandler(transactionProcessor, stateProvider),
Substitute.For<IBlockhashStore>(),
LimboLogs.Instance);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
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;

public (Address? toAddress, AccessList? accessList) BeaconRootsAccessList(Block block, IReleaseSpec spec, IWorldState stateProvider, bool includeStorageCells = true)
public (Address? toAddress, AccessList? accessList) BeaconRootsAccessList(Block block, IReleaseSpec spec, bool includeStorageCells = true)
{
BlockHeader? header = block.Header;
bool canInsertBeaconRoot = spec.IsBeaconBlockRootAvailable
Expand All @@ -42,9 +42,9 @@ public class BeaconBlockRootHandler(ITransactionProcessor processor) : IBeaconBl
return (eip4788ContractAddress, builder.Build());
}

public void StoreBeaconRoot(Block block, IReleaseSpec spec, IWorldState stateProvider)
public void StoreBeaconRoot(Block block, IReleaseSpec spec)
{
(Address? toAddress, AccessList? accessList) = BeaconRootsAccessList(block, spec, stateProvider, includeStorageCells: false);
(Address? toAddress, AccessList? accessList) = BeaconRootsAccessList(block, spec, includeStorageCells: false);

if (toAddress is not null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
namespace Nethermind.Blockchain.BeaconBlockRoot;
public interface IBeaconBlockRootHandler
{
(Address? toAddress, AccessList? accessList) BeaconRootsAccessList(Block block, IReleaseSpec spec, IWorldState stateProvider, bool includeStorageCells = true);
void StoreBeaconRoot(Block block, IReleaseSpec spec, IWorldState stateProvider);
(Address? toAddress, AccessList? accessList) BeaconRootsAccessList(Block block, IReleaseSpec spec, bool includeStorageCells = true);
void StoreBeaconRoot(Block block, IReleaseSpec spec);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ the previous head state.*/
if (!skipPrewarming)
{
using CancellationTokenSource cancellationTokenSource = new();
(_, AccessList? accessList) = _beaconBlockRootHandler.BeaconRootsAccessList(suggestedBlock, _specProvider.GetSpec(suggestedBlock.Header), _stateProvider);
(_, AccessList? accessList) = _beaconBlockRootHandler.BeaconRootsAccessList(suggestedBlock, _specProvider.GetSpec(suggestedBlock.Header));
preWarmTask = preWarmer.PreWarmCaches(suggestedBlock, preBlockStateRoot, accessList, cancellationTokenSource.Token);
(processedBlock, receipts) = ProcessOne(suggestedBlock, options, blockTracer);
// Block is processed, we can cancel the prewarm task
Expand Down Expand Up @@ -345,7 +345,7 @@ private void StoreBeaconRoot(Block block, IReleaseSpec spec)
{
try
{
_beaconBlockRootHandler.StoreBeaconRoot(block, spec, _stateProvider);
_beaconBlockRootHandler.StoreBeaconRoot(block, spec);
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ protected virtual async Task<TestBlockchain> 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),
Expand All @@ -216,7 +216,6 @@ protected virtual async Task<TestBlockchain> 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);
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void Setup()
stateProvider,
NullReceiptStorage.Instance,
transactionProcessor,
new BeaconBlockRootHandler(transactionProcessor),
new BeaconBlockRootHandler(transactionProcessor, stateProvider),
new BlockhashStore(specProvider, stateProvider),
LimboLogs.Instance);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ protected override IBlockProcessor CreateBlockProcessor()
State,
ReceiptStorage,
TxProcessor,
new BeaconBlockRootHandler(TxProcessor),
new BeaconBlockRootHandler(TxProcessor, State),
new BlockhashStore(SpecProvider, State),
LogManager,
WithdrawalProcessor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Loading

0 comments on commit c8f0aba

Please sign in to comment.