From 13fdfa0770f279c801672d188aa9ef9a837f792c Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Tue, 24 Dec 2024 14:17:10 +0800 Subject: [PATCH 1/7] Remove unnecessary member From 3632be471c4c03e8705c087f9360c6ab680fe935 Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Mon, 23 Dec 2024 15:44:34 +0800 Subject: [PATCH 2/7] Gonna take can compile --- .../Nethermind.Api/NethermindApi.cs | 3 +-- .../RegisterAuRaRpcModules.cs | 4 ++-- .../Processing/OverridableTxProcessingEnv.cs | 9 ++++---- .../OverridableTxProcessingScope.cs | 2 +- .../BlockchainBridgeTests.cs | 16 +++++-------- .../Modules/TestRpcBlockchain.cs | 2 +- .../Modules/TraceRpcModuleTests.cs | 2 +- .../Modules/DebugModule/DebugModuleFactory.cs | 2 +- .../Modules/Trace/TraceModuleFactory.cs | 6 ++--- .../OptimismOverridableTxProcessingEnv.cs | 2 +- .../Rpc/OptimismTraceModuleFactory.cs | 4 ++-- .../Nethermind.State/IWorldStateManager.cs | 16 +++++++++++++ .../OverlayWorldStateManager.cs | 5 ++++ .../Nethermind.State/OverridableWorldState.cs | 2 +- .../OverridableWorldStateManager.cs | 23 ++++--------------- .../ReadOnlyWorldStateManager.cs | 7 ++++++ .../Nethermind.State/WorldStateManager.cs | 8 +++++++ .../Rpc/TaikoTraceModuleFactory.cs | 2 +- .../TaikoReadOnlyTxProcessingEnv.cs | 2 +- 19 files changed, 66 insertions(+), 51 deletions(-) diff --git a/src/Nethermind/Nethermind.Api/NethermindApi.cs b/src/Nethermind/Nethermind.Api/NethermindApi.cs index 5e9e0618b91..1e7ad8cfdd4 100644 --- a/src/Nethermind/Nethermind.Api/NethermindApi.cs +++ b/src/Nethermind/Nethermind.Api/NethermindApi.cs @@ -76,11 +76,10 @@ public NethermindApi(IConfigProvider configProvider, IJsonSerializer jsonSeriali public IBlockchainBridge CreateBlockchainBridge() { ReadOnlyBlockTree readOnlyTree = BlockTree!.AsReadOnly(); - OverridableWorldStateManager overridableWorldStateManager = new(DbProvider!, WorldStateManager!.TrieStore, LogManager); // TODO: reuse the same trie cache here OverridableTxProcessingEnv txProcessingEnv = new( - overridableWorldStateManager, + WorldStateManager!.CreateOverridableWorldScope(), readOnlyTree, SpecProvider!, LogManager); diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/RegisterAuRaRpcModules.cs b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/RegisterAuRaRpcModules.cs index a227a5a25ad..24cf04cab40 100644 --- a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/RegisterAuRaRpcModules.cs +++ b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/RegisterAuRaRpcModules.cs @@ -96,7 +96,7 @@ protected class AuRaTraceModuleFactory( : TraceModuleFactory(trieStore, dbProvider, blockTree, jsonRpcConfig, recoveryStep, rewardCalculatorSource, receiptFinder, specProvider, poSSwitcher, logManager) { - protected override ReadOnlyChainProcessingEnv CreateChainProcessingEnv(OverridableWorldStateManager worldStateManager, + protected override ReadOnlyChainProcessingEnv CreateChainProcessingEnv(IOverridableWorldScope worldStateManager, IBlockProcessor.IBlockTransactionsExecutor transactionsExecutor, IReadOnlyTxProcessingScope scope, IRewardCalculator rewardCalculator) { @@ -244,7 +244,7 @@ protected class AuRaDebugModuleFactory( badBlockStore, fileSystem, logManager) { protected override ReadOnlyChainProcessingEnv CreateReadOnlyChainProcessingEnv(IReadOnlyTxProcessingScope scope, - OverridableWorldStateManager worldStateManager, BlockProcessor.BlockValidationTransactionsExecutor transactionsExecutor) + IOverridableWorldScope worldStateManager, BlockProcessor.BlockValidationTransactionsExecutor transactionsExecutor) { return new AuRaReadOnlyChainProcessingEnv( scope, diff --git a/src/Nethermind/Nethermind.Consensus/Processing/OverridableTxProcessingEnv.cs b/src/Nethermind/Nethermind.Consensus/Processing/OverridableTxProcessingEnv.cs index 4b520f42ab5..eed81454245 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/OverridableTxProcessingEnv.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/OverridableTxProcessingEnv.cs @@ -22,25 +22,24 @@ public class OverridableTxProcessingEnv : IOverridableTxProcessorSource protected ILogManager LogManager { get; } private readonly Lazy _transactionProcessorLazy; - protected OverridableWorldState StateProvider { get; } + protected IOverridableWorldState StateProvider { get; } protected OverridableCodeInfoRepository CodeInfoRepository { get; } protected IVirtualMachine Machine { get; } protected ITransactionProcessor TransactionProcessor => _transactionProcessorLazy.Value; public OverridableTxProcessingEnv( - OverridableWorldStateManager worldStateManager, + IOverridableWorldScope overridableScope, IReadOnlyBlockTree readOnlyBlockTree, ISpecProvider specProvider, ILogManager? logManager ) { SpecProvider = specProvider; - StateReader = worldStateManager.GlobalStateReader; + StateReader = overridableScope.GlobalStateReader; BlockTree = readOnlyBlockTree; IBlockhashProvider blockhashProvider = new BlockhashProvider(BlockTree, specProvider, StateProvider, logManager); LogManager = logManager; - - StateProvider = (OverridableWorldState)worldStateManager.CreateResettableWorldState(); + StateProvider = overridableScope.WorldState; CodeInfoRepository = new(new CodeInfoRepository()); Machine = new VirtualMachine(blockhashProvider, specProvider, CodeInfoRepository, logManager); diff --git a/src/Nethermind/Nethermind.Consensus/Processing/OverridableTxProcessingScope.cs b/src/Nethermind/Nethermind.Consensus/Processing/OverridableTxProcessingScope.cs index b168b1c1e93..057f75e92c3 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/OverridableTxProcessingScope.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/OverridableTxProcessingScope.cs @@ -11,7 +11,7 @@ namespace Nethermind.Consensus.Processing; public class OverridableTxProcessingScope( IOverridableCodeInfoRepository codeInfoRepository, ITransactionProcessor transactionProcessor, - OverridableWorldState worldState, + IOverridableWorldState worldState, Hash256 originalStateRoot ) : IOverridableTxProcessingScope { diff --git a/src/Nethermind/Nethermind.Facade.Test/BlockchainBridgeTests.cs b/src/Nethermind/Nethermind.Facade.Test/BlockchainBridgeTests.cs index beb29a04702..078b924abcf 100644 --- a/src/Nethermind/Nethermind.Facade.Test/BlockchainBridgeTests.cs +++ b/src/Nethermind/Nethermind.Facade.Test/BlockchainBridgeTests.cs @@ -48,7 +48,7 @@ public class BlockchainBridgeTests private IDbProvider _dbProvider; private class TestReadOnlyTxProcessingEnv( - OverridableWorldStateManager worldStateManager, + IOverridableWorldScope worldStateManager, IReadOnlyBlockTree blockTree, ISpecProvider specProvider, ILogManager logManager, @@ -72,13 +72,12 @@ public async Task SetUp() _ethereumEcdsa = Substitute.For(); _specProvider = MainnetSpecProvider.Instance; - IReadOnlyTrieStore trieStore = new TrieStore(_dbProvider.StateDb, LimboLogs.Instance).AsReadOnly(); - - OverridableWorldStateManager worldStateManager = new(_dbProvider, trieStore, LimboLogs.Instance); + WorldStateManager worldStateManager = WorldStateManager.CreateForTest(_dbProvider, LimboLogs.Instance); + IOverridableWorldScope overridableWorldScope = worldStateManager.CreateOverridableWorldScope(); IReadOnlyBlockTree readOnlyBlockTree = _blockTree.AsReadOnly(); TestReadOnlyTxProcessingEnv processingEnv = new( - worldStateManager, + overridableWorldScope, readOnlyBlockTree, _specProvider, LimboLogs.Instance, @@ -207,13 +206,10 @@ public void Call_uses_valid_beneficiary() [TestCase(0)] public void Bridge_head_is_correct(long headNumber) { - IReadOnlyTrieStore trieStore = new TrieStore(_dbProvider.StateDb, LimboLogs.Instance).AsReadOnly(); - - OverridableWorldStateManager worldStateManager = - new(_dbProvider, trieStore, LimboLogs.Instance); + WorldStateManager worldStateManager = WorldStateManager.CreateForTest(_dbProvider, LimboLogs.Instance); IReadOnlyBlockTree roBlockTree = _blockTree.AsReadOnly(); OverridableTxProcessingEnv processingEnv = new( - worldStateManager, + worldStateManager.CreateOverridableWorldScope(), roBlockTree, _specProvider, LimboLogs.Instance); diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TestRpcBlockchain.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TestRpcBlockchain.cs index d5d9aaf4e6a..be7741fe101 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TestRpcBlockchain.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TestRpcBlockchain.cs @@ -48,7 +48,7 @@ public class TestRpcBlockchain : TestBlockchain public ITxSender TxSender { get; private set; } = null!; public IReceiptFinder ReceiptFinder { get; private set; } = null!; public IGasPriceOracle GasPriceOracle { get; private set; } = null!; - public OverridableWorldStateManager OverridableWorldStateManager { get; private set; } = null!; + public IOverridableWorldScope OverridableWorldStateManager { get; private set; } = null!; public IKeyStore KeyStore { get; } = new MemKeyStore(TestItem.PrivateKeys, Path.Combine("testKeyStoreDir", Path.GetRandomFileName())); public IWallet TestWallet { get; } = diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TraceRpcModuleTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TraceRpcModuleTests.cs index 446c7743efe..8b535bbf194 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TraceRpcModuleTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TraceRpcModuleTests.cs @@ -63,7 +63,7 @@ public async Task Build(ISpecProvider? specProvider = null, bool isAura = false) } Factory = new( - Blockchain.OverridableWorldStateManager.TrieStore, + Blockchain.WorldStateManager.TrieStore, Blockchain.DbProvider, Blockchain.BlockTree, JsonRpcConfig, diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/DebugModuleFactory.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/DebugModuleFactory.cs index 953b5c4be1d..9133c29c12c 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/DebugModuleFactory.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/DebugModuleFactory.cs @@ -111,7 +111,7 @@ public override IDebugRpcModule Create() } protected virtual ReadOnlyChainProcessingEnv CreateReadOnlyChainProcessingEnv(IReadOnlyTxProcessingScope scope, - OverridableWorldStateManager worldStateManager, BlockProcessor.BlockValidationTransactionsExecutor transactionsExecutor) + IOverridableWorldScope worldStateManager, BlockProcessor.BlockValidationTransactionsExecutor transactionsExecutor) { return new ReadOnlyChainProcessingEnv( scope, diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/Trace/TraceModuleFactory.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/Trace/TraceModuleFactory.cs index 11a2ce1ba68..b460655e872 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/Trace/TraceModuleFactory.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/Trace/TraceModuleFactory.cs @@ -41,9 +41,9 @@ public class TraceModuleFactory( protected readonly IRewardCalculatorSource _rewardCalculatorSource = rewardCalculatorSource ?? throw new ArgumentNullException(nameof(rewardCalculatorSource)); protected readonly IPoSSwitcher _poSSwitcher = poSSwitcher ?? throw new ArgumentNullException(nameof(poSSwitcher)); - protected virtual OverridableTxProcessingEnv CreateTxProcessingEnv(OverridableWorldStateManager worldStateManager) => new(worldStateManager, _blockTree, _specProvider, _logManager); + protected virtual OverridableTxProcessingEnv CreateTxProcessingEnv(IOverridableWorldScope worldScope) => new(worldScope, _blockTree, _specProvider, _logManager); - protected virtual ReadOnlyChainProcessingEnv CreateChainProcessingEnv(OverridableWorldStateManager worldStateManager, IBlockProcessor.IBlockTransactionsExecutor transactionsExecutor, IReadOnlyTxProcessingScope scope, IRewardCalculator rewardCalculator) => new( + protected virtual ReadOnlyChainProcessingEnv CreateChainProcessingEnv(IOverridableWorldScope worldScope, IBlockProcessor.IBlockTransactionsExecutor transactionsExecutor, IReadOnlyTxProcessingScope scope, IRewardCalculator rewardCalculator) => new( scope, Always.Valid, _recoveryStep, @@ -51,7 +51,7 @@ public class TraceModuleFactory( _receiptStorage, _specProvider, _blockTree, - worldStateManager.GlobalStateReader, + worldScope.GlobalStateReader, _logManager, transactionsExecutor); diff --git a/src/Nethermind/Nethermind.Optimism/OptimismOverridableTxProcessingEnv.cs b/src/Nethermind/Nethermind.Optimism/OptimismOverridableTxProcessingEnv.cs index 76ff5c8e5c2..d6ce36e8290 100644 --- a/src/Nethermind/Nethermind.Optimism/OptimismOverridableTxProcessingEnv.cs +++ b/src/Nethermind/Nethermind.Optimism/OptimismOverridableTxProcessingEnv.cs @@ -13,7 +13,7 @@ namespace Nethermind.Optimism; public class OptimismOverridableTxProcessingEnv( - OverridableWorldStateManager worldStateManager, + IOverridableWorldScope worldStateManager, IReadOnlyBlockTree readOnlyBlockTree, ISpecProvider specProvider, ILogManager logManager, diff --git a/src/Nethermind/Nethermind.Optimism/Rpc/OptimismTraceModuleFactory.cs b/src/Nethermind/Nethermind.Optimism/Rpc/OptimismTraceModuleFactory.cs index bf5b837c883..f55a1062632 100644 --- a/src/Nethermind/Nethermind.Optimism/Rpc/OptimismTraceModuleFactory.cs +++ b/src/Nethermind/Nethermind.Optimism/Rpc/OptimismTraceModuleFactory.cs @@ -45,10 +45,10 @@ public class OptimismTraceModuleFactory( poSSwitcher, logManager) { - protected override OverridableTxProcessingEnv CreateTxProcessingEnv(OverridableWorldStateManager worldStateManager) => + protected override OverridableTxProcessingEnv CreateTxProcessingEnv(IOverridableWorldScope worldStateManager) => new OptimismOverridableTxProcessingEnv(worldStateManager, _blockTree, _specProvider, _logManager, l1CostHelper, opSpecHelper); - protected override ReadOnlyChainProcessingEnv CreateChainProcessingEnv(OverridableWorldStateManager worldStateManager, IBlockProcessor.IBlockTransactionsExecutor transactionsExecutor, IReadOnlyTxProcessingScope scope, IRewardCalculator rewardCalculator) => new OptimismReadOnlyChainProcessingEnv( + protected override ReadOnlyChainProcessingEnv CreateChainProcessingEnv(IOverridableWorldScope worldStateManager, IBlockProcessor.IBlockTransactionsExecutor transactionsExecutor, IReadOnlyTxProcessingScope scope, IRewardCalculator rewardCalculator) => new OptimismReadOnlyChainProcessingEnv( scope, Always.Valid, _recoveryStep, diff --git a/src/Nethermind/Nethermind.State/IWorldStateManager.cs b/src/Nethermind/Nethermind.State/IWorldStateManager.cs index 79f9f0c3279..31c9df9201a 100644 --- a/src/Nethermind/Nethermind.State/IWorldStateManager.cs +++ b/src/Nethermind/Nethermind.State/IWorldStateManager.cs @@ -21,4 +21,20 @@ public interface IWorldStateManager IWorldState CreateResettableWorldState(IWorldState? forWarmup = null); event EventHandler? ReorgBoundaryReached; + + IOverridableWorldScope CreateOverridableWorldScope(); +} + +public interface IOverridableWorldScope +{ + IOverridableWorldState WorldState { get; } + IStateReader GlobalStateReader { get; } + + // WTF! you may be thinking. Yea, me to. + IReadOnlyTrieStore TrieStore { get; } +} + +public interface IOverridableWorldState : IWorldState +{ + void ResetOverrides(); } diff --git a/src/Nethermind/Nethermind.State/OverlayWorldStateManager.cs b/src/Nethermind/Nethermind.State/OverlayWorldStateManager.cs index 852cccd716f..4e5dc28d741 100644 --- a/src/Nethermind/Nethermind.State/OverlayWorldStateManager.cs +++ b/src/Nethermind/Nethermind.State/OverlayWorldStateManager.cs @@ -42,4 +42,9 @@ public event EventHandler? ReorgBoundaryReached add => overlayTrieStore.ReorgBoundaryReached += value; remove => overlayTrieStore.ReorgBoundaryReached -= value; } + + public IOverridableWorldScope CreateOverridableWorldScope() + { + throw new InvalidOperationException("Cannot create overridable world scope from overlay works state manager"); + } } diff --git a/src/Nethermind/Nethermind.State/OverridableWorldState.cs b/src/Nethermind/Nethermind.State/OverridableWorldState.cs index 70a1bfc0afb..6fab49ccfc6 100644 --- a/src/Nethermind/Nethermind.State/OverridableWorldState.cs +++ b/src/Nethermind/Nethermind.State/OverridableWorldState.cs @@ -13,7 +13,7 @@ public class OverridableWorldState( ILogManager? logManager, PreBlockCaches? preBlockCaches = null, bool populatePreBlockCache = true) - : WorldState(trieStore, dbProvider.GetDb(DbNames.Code), logManager, preBlockCaches, populatePreBlockCache) + : WorldState(trieStore, dbProvider.GetDb(DbNames.Code), logManager, preBlockCaches, populatePreBlockCache), IOverridableWorldState { /// diff --git a/src/Nethermind/Nethermind.State/OverridableWorldStateManager.cs b/src/Nethermind/Nethermind.State/OverridableWorldStateManager.cs index d88525f856f..c80fadda57b 100644 --- a/src/Nethermind/Nethermind.State/OverridableWorldStateManager.cs +++ b/src/Nethermind/Nethermind.State/OverridableWorldStateManager.cs @@ -8,11 +8,10 @@ namespace Nethermind.State; -public class OverridableWorldStateManager : IWorldStateManager +public class OverridableWorldStateManager : IOverridableWorldScope { private readonly ReadOnlyDbProvider _readOnlyDbProvider; private readonly StateReader _reader; - private readonly WorldState _state; private readonly OverlayTrieStore _overlayTrieStore; private readonly ILogManager? _logManager; @@ -24,26 +23,12 @@ public OverridableWorldStateManager(IDbProvider dbProvider, IReadOnlyTrieStore t _logManager = logManager; _reader = new(overlayTrieStore, dbProvider.GetDb(DbNames.Code), logManager); - _state = new(overlayTrieStore, dbProvider.GetDb(DbNames.Code), logManager); _overlayTrieStore = overlayTrieStore; + + WorldState = new OverridableWorldState(_overlayTrieStore, _readOnlyDbProvider, _logManager); } - public IWorldState GlobalWorldState => _state; + public IOverridableWorldState WorldState { get; } public IStateReader GlobalStateReader => _reader; public IReadOnlyTrieStore TrieStore => _overlayTrieStore.AsReadOnly(); - public bool SupportHashLookup => _overlayTrieStore.Scheme == INodeStorage.KeyScheme.Hash; - - public IWorldState CreateResettableWorldState(IWorldState? forWarmup = null) - { - if (forWarmup is not null) - throw new NotSupportedException("Overridable world state with warm up is not supported."); - - return new OverridableWorldState(_overlayTrieStore, _readOnlyDbProvider, _logManager); - } - - public event EventHandler? ReorgBoundaryReached - { - add => _overlayTrieStore.ReorgBoundaryReached += value; - remove => _overlayTrieStore.ReorgBoundaryReached -= value; - } } diff --git a/src/Nethermind/Nethermind.State/ReadOnlyWorldStateManager.cs b/src/Nethermind/Nethermind.State/ReadOnlyWorldStateManager.cs index e2c139b9914..bbc25063d7d 100644 --- a/src/Nethermind/Nethermind.State/ReadOnlyWorldStateManager.cs +++ b/src/Nethermind/Nethermind.State/ReadOnlyWorldStateManager.cs @@ -17,6 +17,7 @@ public class ReadOnlyWorldStateManager : IWorldStateManager private readonly IReadOnlyTrieStore _readOnlyTrieStore; private readonly ILogManager _logManager; private readonly ReadOnlyDb _codeDb; + private readonly IDbProvider _dbProvider; public ReadOnlyWorldStateManager( IDbProvider dbProvider, @@ -24,6 +25,7 @@ public ReadOnlyWorldStateManager( ILogManager logManager ) { + _dbProvider = dbProvider; _readOnlyTrieStore = readOnlyTrieStore; _logManager = logManager; @@ -59,4 +61,9 @@ public virtual event EventHandler? ReorgBoundaryReached add => throw new InvalidOperationException("Unsupported operation"); remove => throw new InvalidOperationException("Unsupported operation"); } + + public IOverridableWorldScope CreateOverridableWorldScope() + { + return new OverridableWorldStateManager(_dbProvider, _readOnlyTrieStore, _logManager); + } } diff --git a/src/Nethermind/Nethermind.State/WorldStateManager.cs b/src/Nethermind/Nethermind.State/WorldStateManager.cs index 807db3ab54f..d40aad09c5a 100644 --- a/src/Nethermind/Nethermind.State/WorldStateManager.cs +++ b/src/Nethermind/Nethermind.State/WorldStateManager.cs @@ -15,6 +15,14 @@ public class WorldStateManager( ILogManager logManager) : ReadOnlyWorldStateManager(dbProvider, trieStore.AsReadOnly(), logManager) { + public static WorldStateManager CreateForTest(IDbProvider dbProvider, ILogManager logManager) + { + ITrieStore trieStore = new TrieStore(dbProvider.StateDb, logManager); + IWorldState worldState = new WorldState(trieStore, dbProvider.CodeDb, logManager); + + return new WorldStateManager(worldState, trieStore, dbProvider, logManager); + } + public override IWorldState GlobalWorldState => worldState; public override event EventHandler? ReorgBoundaryReached diff --git a/src/Nethermind/Nethermind.Taiko/Rpc/TaikoTraceModuleFactory.cs b/src/Nethermind/Nethermind.Taiko/Rpc/TaikoTraceModuleFactory.cs index e7045d4e609..a8f184841d3 100644 --- a/src/Nethermind/Nethermind.Taiko/Rpc/TaikoTraceModuleFactory.cs +++ b/src/Nethermind/Nethermind.Taiko/Rpc/TaikoTraceModuleFactory.cs @@ -22,5 +22,5 @@ class TaikoTraceModuleFactory( ISpecProvider specProvider, IPoSSwitcher poSSwitcher, ILogManager logManager) : TraceModuleFactory(trieStore, dbProvider, blockTree, jsonRpcConfig, recoveryStep, rewardCalculatorSource, receiptFinder, specProvider, poSSwitcher, logManager) { - protected override OverridableTxProcessingEnv CreateTxProcessingEnv(OverridableWorldStateManager worldStateManager) => new TaikoReadOnlyTxProcessingEnv(worldStateManager, _blockTree, _specProvider, _logManager); + protected override OverridableTxProcessingEnv CreateTxProcessingEnv(IOverridableWorldScope worldStateManager) => new TaikoReadOnlyTxProcessingEnv(worldStateManager, _blockTree, _specProvider, _logManager); } diff --git a/src/Nethermind/Nethermind.Taiko/TaikoReadOnlyTxProcessingEnv.cs b/src/Nethermind/Nethermind.Taiko/TaikoReadOnlyTxProcessingEnv.cs index faf0a5242dd..883ee47a18f 100644 --- a/src/Nethermind/Nethermind.Taiko/TaikoReadOnlyTxProcessingEnv.cs +++ b/src/Nethermind/Nethermind.Taiko/TaikoReadOnlyTxProcessingEnv.cs @@ -11,7 +11,7 @@ namespace Nethermind.Taiko; public class TaikoReadOnlyTxProcessingEnv( - OverridableWorldStateManager worldStateManager, + IOverridableWorldScope worldStateManager, IReadOnlyBlockTree readOnlyBlockTree, ISpecProvider specProvider, ILogManager logManager) : OverridableTxProcessingEnv( From d9e76a160274630f6c6295ed9c5eed2e7f9bdb96 Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Tue, 24 Dec 2024 13:26:55 +0800 Subject: [PATCH 3/7] Isolate overridable world state manager --- .../InitializationSteps/RegisterAuRaRpcModules.cs | 14 ++++++-------- .../Nethermind.Init/Steps/RegisterRpcModules.cs | 5 ++--- .../Modules/DebugRpcModuleTests.cs | 2 +- .../Modules/TestRpcBlockchain.cs | 4 ++-- .../Modules/TraceRpcModuleTests.cs | 3 +-- .../Modules/DebugModule/DebugModuleFactory.cs | 8 ++++---- .../Modules/Trace/TraceModuleFactory.cs | 14 +++++--------- .../Rpc/OptimismTraceModuleFactory.cs | 8 ++------ .../Rpc/RegisterOptimismRpcModules.cs | 3 +-- .../Rpc/RegisterTaikoRpcModules.cs | 3 +-- .../Rpc/TaikoTraceModuleFactory.cs | 7 +++---- src/Nethermind/Nethermind.Taiko/TaikoPlugin.cs | 4 +--- 12 files changed, 29 insertions(+), 46 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/RegisterAuRaRpcModules.cs b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/RegisterAuRaRpcModules.cs index 24cf04cab40..18022b96fe3 100644 --- a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/RegisterAuRaRpcModules.cs +++ b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/RegisterAuRaRpcModules.cs @@ -66,8 +66,7 @@ protected override void RegisterTraceRpcModule(IRpcModuleProvider rpcModuleProvi StepDependencyException.ThrowIfNull(_api.SpecProvider); AuRaTraceModuleFactory traceModuleFactory = new( - _api.WorldStateManager.TrieStore, - _api.DbProvider, + _api.WorldStateManager, _api.BlockTree, _jsonRpcConfig, _api.BlockPreprocessor, @@ -82,8 +81,7 @@ protected override void RegisterTraceRpcModule(IRpcModuleProvider rpcModuleProvi } protected class AuRaTraceModuleFactory( - IReadOnlyTrieStore trieStore, - IDbProvider dbProvider, + IWorldStateManager worldStateManager, IBlockTree blockTree, IJsonRpcConfig jsonRpcConfig, IBlockPreprocessorStep recoveryStep, @@ -93,7 +91,7 @@ protected class AuRaTraceModuleFactory( IPoSSwitcher poSSwitcher, ILogManager logManager, IAuRaBlockProcessorFactory factory) - : TraceModuleFactory(trieStore, dbProvider, blockTree, jsonRpcConfig, recoveryStep, rewardCalculatorSource, + : TraceModuleFactory(worldStateManager, blockTree, jsonRpcConfig, recoveryStep, rewardCalculatorSource, receiptFinder, specProvider, poSSwitcher, logManager) { protected override ReadOnlyChainProcessingEnv CreateChainProcessingEnv(IOverridableWorldScope worldStateManager, @@ -202,7 +200,7 @@ protected override void RegisterDebugRpcModule(IRpcModuleProvider rpcModuleProvi StepDependencyException.ThrowIfNull(_api.SpecProvider); AuRaDebugModuleFactory debugModuleFactory = new( - _api.WorldStateManager.TrieStore, + _api.WorldStateManager, _api.DbProvider, _api.BlockTree, _jsonRpcConfig, @@ -223,7 +221,7 @@ protected override void RegisterDebugRpcModule(IRpcModuleProvider rpcModuleProvi } protected class AuRaDebugModuleFactory( - IReadOnlyTrieStore trieStore, + IWorldStateManager worldStateManager, IDbProvider dbProvider, IBlockTree blockTree, IJsonRpcConfig jsonRpcConfig, @@ -239,7 +237,7 @@ protected class AuRaDebugModuleFactory( IFileSystem fileSystem, ILogManager logManager, IAuRaBlockProcessorFactory factory) - : DebugModuleFactory(trieStore, dbProvider, blockTree, jsonRpcConfig, blockValidator, recoveryStep, + : DebugModuleFactory(worldStateManager, dbProvider, blockTree, jsonRpcConfig, blockValidator, recoveryStep, rewardCalculator, receiptStorage, receiptsMigration, configProvider, specProvider, syncModeSelector, badBlockStore, fileSystem, logManager) { diff --git a/src/Nethermind/Nethermind.Init/Steps/RegisterRpcModules.cs b/src/Nethermind/Nethermind.Init/Steps/RegisterRpcModules.cs index 6bfc89b87e6..daa7ce6fc7d 100644 --- a/src/Nethermind/Nethermind.Init/Steps/RegisterRpcModules.cs +++ b/src/Nethermind/Nethermind.Init/Steps/RegisterRpcModules.cs @@ -214,7 +214,7 @@ protected virtual void RegisterDebugRpcModule(IRpcModuleProvider rpcModuleProvid StepDependencyException.ThrowIfNull(_api.SpecProvider); DebugModuleFactory debugModuleFactory = new( - _api.WorldStateManager.TrieStore, + _api.WorldStateManager, _api.DbProvider, _api.BlockTree, _jsonRpcConfig, @@ -285,8 +285,7 @@ protected ModuleFactoryBase CreateTraceModuleFactory() StepDependencyException.ThrowIfNull(_api.SpecProvider); return new TraceModuleFactory( - _api.WorldStateManager.TrieStore, - _api.DbProvider, + _api.WorldStateManager, _api.BlockTree, _jsonRpcConfig, _api.BlockPreprocessor, diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/DebugRpcModuleTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/DebugRpcModuleTests.cs index 2c78136b61b..e7da233ff0f 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/DebugRpcModuleTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/DebugRpcModuleTests.cs @@ -49,7 +49,7 @@ public static async Task Create(ISpecProvider? specProvider = null, boo IReceiptsMigration receiptsMigration = Substitute.For(); ISyncModeSelector syncModeSelector = Substitute.For(); var factory = new DebugModuleFactory( - blockchain.WorldStateManager.TrieStore, + blockchain.WorldStateManager, blockchain.DbProvider, blockchain.BlockTree, blockchain.RpcConfig, diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TestRpcBlockchain.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TestRpcBlockchain.cs index be7741fe101..f0ada6657ee 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TestRpcBlockchain.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TestRpcBlockchain.cs @@ -150,9 +150,9 @@ protected override async Task Build( IFilterManager filterManager = new FilterManager(filterStore, BlockProcessor, TxPool, LimboLogs.Instance); var dbProvider = new ReadOnlyDbProvider(DbProvider, false); IReadOnlyBlockTree? roBlockTree = BlockTree!.AsReadOnly(); - OverridableWorldStateManager overridableWorldStateManager = new(DbProvider, WorldStateManager.TrieStore, LogManager); + IOverridableWorldScope overridableWorldStateManager = WorldStateManager.CreateOverridableWorldScope(); OverridableTxProcessingEnv processingEnv = new( - overridableWorldStateManager, + WorldStateManager.CreateOverridableWorldScope(), roBlockTree, SpecProvider, LimboLogs.Instance); diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TraceRpcModuleTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TraceRpcModuleTests.cs index 8b535bbf194..25e6c76a10f 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TraceRpcModuleTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/TraceRpcModuleTests.cs @@ -63,8 +63,7 @@ public async Task Build(ISpecProvider? specProvider = null, bool isAura = false) } Factory = new( - Blockchain.WorldStateManager.TrieStore, - Blockchain.DbProvider, + Blockchain.WorldStateManager, Blockchain.BlockTree, JsonRpcConfig, Blockchain.BlockPreprocessorStep, diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/DebugModuleFactory.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/DebugModuleFactory.cs index 9133c29c12c..bf3ec5d4ff6 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/DebugModuleFactory.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/DebugModuleFactory.cs @@ -24,7 +24,6 @@ namespace Nethermind.JsonRpc.Modules.DebugModule; public class DebugModuleFactory : ModuleFactoryBase { - private readonly IReadOnlyTrieStore _trieStore; private readonly IJsonRpcConfig _jsonRpcConfig; private readonly IBlockValidator _blockValidator; protected readonly IRewardCalculatorSource _rewardCalculatorSource; @@ -39,9 +38,10 @@ public class DebugModuleFactory : ModuleFactoryBase private readonly ISyncModeSelector _syncModeSelector; private readonly IBadBlockStore _badBlockStore; private readonly IFileSystem _fileSystem; + private readonly IWorldStateManager _worldStateManager; public DebugModuleFactory( - IReadOnlyTrieStore trieStore, + IWorldStateManager worldStateManager, IDbProvider dbProvider, IBlockTree blockTree, IJsonRpcConfig jsonRpcConfig, @@ -57,7 +57,7 @@ public DebugModuleFactory( IFileSystem fileSystem, ILogManager logManager) { - _trieStore = trieStore; + _worldStateManager = worldStateManager; _dbProvider = dbProvider.AsReadOnly(false); _blockTree = blockTree.AsReadOnly(); _jsonRpcConfig = jsonRpcConfig ?? throw new ArgumentNullException(nameof(jsonRpcConfig)); @@ -76,7 +76,7 @@ public DebugModuleFactory( public override IDebugRpcModule Create() { - OverridableWorldStateManager worldStateManager = new(_dbProvider, _trieStore, _logManager); + IOverridableWorldScope worldStateManager = _worldStateManager.CreateOverridableWorldScope(); OverridableTxProcessingEnv txEnv = new(worldStateManager, _blockTree, _specProvider, _logManager); IReadOnlyTxProcessingScope scope = txEnv.Build(Keccak.EmptyTreeHash); diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/Trace/TraceModuleFactory.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/Trace/TraceModuleFactory.cs index b460655e872..166de6fb581 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/Trace/TraceModuleFactory.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/Trace/TraceModuleFactory.cs @@ -11,17 +11,14 @@ using Nethermind.Consensus.Validators; using Nethermind.Core.Crypto; using Nethermind.Core.Specs; -using Nethermind.Db; using Nethermind.Evm.TransactionProcessing; using Nethermind.Logging; using Nethermind.State; -using Nethermind.Trie.Pruning; namespace Nethermind.JsonRpc.Modules.Trace; public class TraceModuleFactory( - IReadOnlyTrieStore trieStore, - IDbProvider dbProvider, + IWorldStateManager worldStateManager, IBlockTree blockTree, IJsonRpcConfig jsonRpcConfig, IBlockPreprocessorStep recoveryStep, @@ -31,7 +28,6 @@ public class TraceModuleFactory( IPoSSwitcher poSSwitcher, ILogManager logManager) : ModuleFactoryBase { - protected readonly IReadOnlyTrieStore _trieStore = trieStore; protected readonly IReadOnlyBlockTree _blockTree = blockTree.AsReadOnly(); protected readonly IJsonRpcConfig _jsonRpcConfig = jsonRpcConfig ?? throw new ArgumentNullException(nameof(jsonRpcConfig)); protected readonly IReceiptStorage _receiptStorage = receiptFinder ?? throw new ArgumentNullException(nameof(receiptFinder)); @@ -57,8 +53,8 @@ public class TraceModuleFactory( public override ITraceRpcModule Create() { - OverridableWorldStateManager worldStateManager = new(dbProvider, _trieStore, logManager); - OverridableTxProcessingEnv txProcessingEnv = CreateTxProcessingEnv(worldStateManager); + IOverridableWorldScope overridableScope = worldStateManager.CreateOverridableWorldScope(); + OverridableTxProcessingEnv txProcessingEnv = CreateTxProcessingEnv(overridableScope); IReadOnlyTxProcessingScope scope = txProcessingEnv.Build(Keccak.EmptyTreeHash); IRewardCalculator rewardCalculator = @@ -68,8 +64,8 @@ public override ITraceRpcModule Create() RpcBlockTransactionsExecutor rpcBlockTransactionsExecutor = new(scope.TransactionProcessor, scope.WorldState); BlockProcessor.BlockValidationTransactionsExecutor executeBlockTransactionsExecutor = new(scope.TransactionProcessor, scope.WorldState); - ReadOnlyChainProcessingEnv traceProcessingEnv = CreateChainProcessingEnv(worldStateManager, rpcBlockTransactionsExecutor, scope, rewardCalculator); - ReadOnlyChainProcessingEnv executeProcessingEnv = CreateChainProcessingEnv(worldStateManager, executeBlockTransactionsExecutor, scope, rewardCalculator); + ReadOnlyChainProcessingEnv traceProcessingEnv = CreateChainProcessingEnv(overridableScope, rpcBlockTransactionsExecutor, scope, rewardCalculator); + ReadOnlyChainProcessingEnv executeProcessingEnv = CreateChainProcessingEnv(overridableScope, executeBlockTransactionsExecutor, scope, rewardCalculator); Tracer tracer = new(scope.WorldState, traceProcessingEnv.ChainProcessor, executeProcessingEnv.ChainProcessor, traceOptions: ProcessingOptions.TraceTransactions); diff --git a/src/Nethermind/Nethermind.Optimism/Rpc/OptimismTraceModuleFactory.cs b/src/Nethermind/Nethermind.Optimism/Rpc/OptimismTraceModuleFactory.cs index f55a1062632..d2658eb974d 100644 --- a/src/Nethermind/Nethermind.Optimism/Rpc/OptimismTraceModuleFactory.cs +++ b/src/Nethermind/Nethermind.Optimism/Rpc/OptimismTraceModuleFactory.cs @@ -9,19 +9,16 @@ using Nethermind.Consensus.Validators; using Nethermind.Consensus.Withdrawals; using Nethermind.Core.Specs; -using Nethermind.Db; using Nethermind.Evm.TransactionProcessing; using Nethermind.JsonRpc; using Nethermind.JsonRpc.Modules.Trace; using Nethermind.Logging; using Nethermind.State; -using Nethermind.Trie.Pruning; namespace Nethermind.Optimism.Rpc; public class OptimismTraceModuleFactory( - IReadOnlyTrieStore trieStore, - IDbProvider dbProvider, + IWorldStateManager worldStateManager, IBlockTree blockTree, IJsonRpcConfig jsonRpcConfig, IBlockPreprocessorStep recoveryStep, @@ -34,8 +31,7 @@ public class OptimismTraceModuleFactory( IOptimismSpecHelper opSpecHelper, Create2DeployerContractRewriter contractRewriter, IWithdrawalProcessor withdrawalProcessor) : TraceModuleFactory( - trieStore, - dbProvider, + worldStateManager, blockTree, jsonRpcConfig, recoveryStep, diff --git a/src/Nethermind/Nethermind.Optimism/Rpc/RegisterOptimismRpcModules.cs b/src/Nethermind/Nethermind.Optimism/Rpc/RegisterOptimismRpcModules.cs index 80dac97f0a2..bb034599ee5 100644 --- a/src/Nethermind/Nethermind.Optimism/Rpc/RegisterOptimismRpcModules.cs +++ b/src/Nethermind/Nethermind.Optimism/Rpc/RegisterOptimismRpcModules.cs @@ -100,8 +100,7 @@ protected override void RegisterTraceRpcModule(IRpcModuleProvider rpcModuleProvi StepDependencyException.ThrowIfNull(_api.SpecHelper); OptimismTraceModuleFactory traceModuleFactory = new( - _api.WorldStateManager.TrieStore, - _api.DbProvider, + _api.WorldStateManager, _api.BlockTree, _jsonRpcConfig, _api.BlockPreprocessor, diff --git a/src/Nethermind/Nethermind.Taiko/Rpc/RegisterTaikoRpcModules.cs b/src/Nethermind/Nethermind.Taiko/Rpc/RegisterTaikoRpcModules.cs index 4166d0e4cdc..b17c1ebe526 100644 --- a/src/Nethermind/Nethermind.Taiko/Rpc/RegisterTaikoRpcModules.cs +++ b/src/Nethermind/Nethermind.Taiko/Rpc/RegisterTaikoRpcModules.cs @@ -83,8 +83,7 @@ protected override void RegisterTraceRpcModule(IRpcModuleProvider rpcModuleProvi StepDependencyException.ThrowIfNull(_api.WorldState); TaikoTraceModuleFactory traceModuleFactory = new( - _api.WorldStateManager.TrieStore, - _api.DbProvider, + _api.WorldStateManager, _api.BlockTree, _jsonRpcConfig, _api.BlockPreprocessor, diff --git a/src/Nethermind/Nethermind.Taiko/Rpc/TaikoTraceModuleFactory.cs b/src/Nethermind/Nethermind.Taiko/Rpc/TaikoTraceModuleFactory.cs index a8f184841d3..f5d50f57c78 100644 --- a/src/Nethermind/Nethermind.Taiko/Rpc/TaikoTraceModuleFactory.cs +++ b/src/Nethermind/Nethermind.Taiko/Rpc/TaikoTraceModuleFactory.cs @@ -7,20 +7,19 @@ using Nethermind.Consensus.Processing; using Nethermind.Consensus.Rewards; using Nethermind.Core.Specs; -using Nethermind.Db; using Nethermind.JsonRpc; using Nethermind.JsonRpc.Modules.Trace; using Nethermind.Logging; using Nethermind.State; -using Nethermind.Trie.Pruning; namespace Nethermind.Taiko.Rpc; class TaikoTraceModuleFactory( - IReadOnlyTrieStore trieStore, IDbProvider dbProvider, IBlockTree blockTree, IJsonRpcConfig jsonRpcConfig, + IWorldStateManager worldStateManager, + IBlockTree blockTree, IJsonRpcConfig jsonRpcConfig, IBlockPreprocessorStep recoveryStep, IRewardCalculatorSource rewardCalculatorSource, IReceiptStorage receiptFinder, ISpecProvider specProvider, IPoSSwitcher poSSwitcher, ILogManager logManager) : - TraceModuleFactory(trieStore, dbProvider, blockTree, jsonRpcConfig, recoveryStep, rewardCalculatorSource, receiptFinder, specProvider, poSSwitcher, logManager) + TraceModuleFactory(worldStateManager, blockTree, jsonRpcConfig, recoveryStep, rewardCalculatorSource, receiptFinder, specProvider, poSSwitcher, logManager) { protected override OverridableTxProcessingEnv CreateTxProcessingEnv(IOverridableWorldScope worldStateManager) => new TaikoReadOnlyTxProcessingEnv(worldStateManager, _blockTree, _specProvider, _logManager); } diff --git a/src/Nethermind/Nethermind.Taiko/TaikoPlugin.cs b/src/Nethermind/Nethermind.Taiko/TaikoPlugin.cs index cb9fb700e37..6dcf7db3c65 100644 --- a/src/Nethermind/Nethermind.Taiko/TaikoPlugin.cs +++ b/src/Nethermind/Nethermind.Taiko/TaikoPlugin.cs @@ -155,10 +155,8 @@ public async Task InitRpcModules() ReadOnlyBlockTree readonlyBlockTree = _api.BlockTree.AsReadOnly(); - OverridableWorldStateManager overridableWorldStateManager = new(_api.DbProvider!, _api.WorldStateManager!.TrieStore, _api.LogManager); - TaikoReadOnlyTxProcessingEnv txProcessingEnv = - new(overridableWorldStateManager, readonlyBlockTree, _api.SpecProvider, _api.LogManager); + new(_api.WorldStateManager!.CreateOverridableWorldScope(), readonlyBlockTree, _api.SpecProvider, _api.LogManager); IReadOnlyTxProcessingScope scope = txProcessingEnv.Build(Keccak.EmptyTreeHash); From d85c0a74169d05fed1e0031bf52c2e25f234d905 Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Tue, 24 Dec 2024 14:04:01 +0800 Subject: [PATCH 4/7] Thankfully unnecessary --- src/Nethermind/Nethermind.State/IWorldStateManager.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Nethermind/Nethermind.State/IWorldStateManager.cs b/src/Nethermind/Nethermind.State/IWorldStateManager.cs index 31c9df9201a..c4551957c69 100644 --- a/src/Nethermind/Nethermind.State/IWorldStateManager.cs +++ b/src/Nethermind/Nethermind.State/IWorldStateManager.cs @@ -29,9 +29,6 @@ public interface IOverridableWorldScope { IOverridableWorldState WorldState { get; } IStateReader GlobalStateReader { get; } - - // WTF! you may be thinking. Yea, me to. - IReadOnlyTrieStore TrieStore { get; } } public interface IOverridableWorldState : IWorldState From 292698d444376340040d226f748c75e4d973fef4 Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Tue, 24 Dec 2024 14:51:57 +0800 Subject: [PATCH 5/7] Move simulate world state also --- ...ulateReadOnlyBlocksProcessingEnvFactory.cs | 5 +- .../Nethermind.State/IWorldStateManager.cs | 5 +- .../OverlayWorldStateManager.cs | 50 ------------------- .../ReadOnlyWorldStateManager.cs | 8 ++- 4 files changed, 12 insertions(+), 56 deletions(-) delete mode 100644 src/Nethermind/Nethermind.State/OverlayWorldStateManager.cs diff --git a/src/Nethermind/Nethermind.Facade/Simulate/SimulateReadOnlyBlocksProcessingEnvFactory.cs b/src/Nethermind/Nethermind.Facade/Simulate/SimulateReadOnlyBlocksProcessingEnvFactory.cs index f54e75c53c9..cfbb63bee82 100644 --- a/src/Nethermind/Nethermind.Facade/Simulate/SimulateReadOnlyBlocksProcessingEnvFactory.cs +++ b/src/Nethermind/Nethermind.Facade/Simulate/SimulateReadOnlyBlocksProcessingEnvFactory.cs @@ -11,7 +11,6 @@ using Nethermind.Logging; using Nethermind.State; using Nethermind.State.Repositories; -using Nethermind.Trie.Pruning; namespace Nethermind.Facade.Simulate; @@ -25,9 +24,7 @@ public class SimulateReadOnlyBlocksProcessingEnvFactory( public SimulateReadOnlyBlocksProcessingEnv Create(bool validate) { IReadOnlyDbProvider editableDbProvider = new ReadOnlyDbProvider(dbProvider, true); - OverlayTrieStore overlayTrieStore = new(editableDbProvider.StateDb, worldStateManager.TrieStore, logManager); - OverlayWorldStateManager overlayWorldStateManager = new(editableDbProvider, overlayTrieStore, logManager); - IWorldState worldState = overlayWorldStateManager.GlobalWorldState; + IWorldState worldState = worldStateManager.CreateOverlayWorldState(editableDbProvider.StateDb, editableDbProvider.CodeDb); BlockTree tempBlockTree = CreateTempBlockTree(editableDbProvider, specProvider, logManager, editableDbProvider); return new SimulateReadOnlyBlocksProcessingEnv( diff --git a/src/Nethermind/Nethermind.State/IWorldStateManager.cs b/src/Nethermind/Nethermind.State/IWorldStateManager.cs index c4551957c69..b1b8e6ec06c 100644 --- a/src/Nethermind/Nethermind.State/IWorldStateManager.cs +++ b/src/Nethermind/Nethermind.State/IWorldStateManager.cs @@ -2,6 +2,8 @@ // SPDX-License-Identifier: LGPL-3.0-only using System; +using Nethermind.Core; +using Nethermind.Db; using Nethermind.Trie.Pruning; namespace Nethermind.State; @@ -10,7 +12,6 @@ public interface IWorldStateManager { IWorldState GlobalWorldState { get; } IStateReader GlobalStateReader { get; } - IReadOnlyTrieStore TrieStore { get; } bool SupportHashLookup { get; } /// @@ -23,6 +24,8 @@ public interface IWorldStateManager event EventHandler? ReorgBoundaryReached; IOverridableWorldScope CreateOverridableWorldScope(); + + IWorldState CreateOverlayWorldState(IKeyValueStoreWithBatching overlayState, IKeyValueStore overlayCode); } public interface IOverridableWorldScope diff --git a/src/Nethermind/Nethermind.State/OverlayWorldStateManager.cs b/src/Nethermind/Nethermind.State/OverlayWorldStateManager.cs deleted file mode 100644 index 4e5dc28d741..00000000000 --- a/src/Nethermind/Nethermind.State/OverlayWorldStateManager.cs +++ /dev/null @@ -1,50 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited -// SPDX-License-Identifier: LGPL-3.0-only - -using System; -using Nethermind.Db; -using Nethermind.Logging; -using Nethermind.Trie; -using Nethermind.Trie.Pruning; - -namespace Nethermind.State; - -public class OverlayWorldStateManager( - IReadOnlyDbProvider dbProvider, - OverlayTrieStore overlayTrieStore, - ILogManager? logManager) - : IWorldStateManager -{ - private readonly IDb _codeDb = dbProvider.GetDb(DbNames.Code); - - private readonly StateReader _reader = new(overlayTrieStore, dbProvider.GetDb(DbNames.Code), logManager); - - private readonly WorldState _state = new(overlayTrieStore, dbProvider.GetDb(DbNames.Code), logManager); - - public IWorldState GlobalWorldState => _state; - - public IStateReader GlobalStateReader => _reader; - - public IReadOnlyTrieStore TrieStore { get; } = overlayTrieStore.AsReadOnly(); - public bool SupportHashLookup => overlayTrieStore.Scheme == INodeStorage.KeyScheme.Hash; - - public IWorldState CreateResettableWorldState(IWorldState? forWarmup = null) - { - ITrieStore trieStore = forWarmup is IPreBlockCaches { Caches: { } preBlockCaches } - ? new PreCachedTrieStore(overlayTrieStore, preBlockCaches.RlpCache) - : overlayTrieStore; - - return new WorldState(trieStore, _codeDb, logManager); - } - - public event EventHandler? ReorgBoundaryReached - { - add => overlayTrieStore.ReorgBoundaryReached += value; - remove => overlayTrieStore.ReorgBoundaryReached -= value; - } - - public IOverridableWorldScope CreateOverridableWorldScope() - { - throw new InvalidOperationException("Cannot create overridable world scope from overlay works state manager"); - } -} diff --git a/src/Nethermind/Nethermind.State/ReadOnlyWorldStateManager.cs b/src/Nethermind/Nethermind.State/ReadOnlyWorldStateManager.cs index bbc25063d7d..5cd51dc6d75 100644 --- a/src/Nethermind/Nethermind.State/ReadOnlyWorldStateManager.cs +++ b/src/Nethermind/Nethermind.State/ReadOnlyWorldStateManager.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only using System; +using Nethermind.Core; using Nethermind.Db; using Nethermind.Logging; using Nethermind.Trie; @@ -38,7 +39,6 @@ ILogManager logManager public IStateReader GlobalStateReader { get; } - public IReadOnlyTrieStore TrieStore => _readOnlyTrieStore; public bool SupportHashLookup => _readOnlyTrieStore.Scheme == INodeStorage.KeyScheme.Hash; public IWorldState CreateResettableWorldState(IWorldState? forWarmup = null) @@ -66,4 +66,10 @@ public IOverridableWorldScope CreateOverridableWorldScope() { return new OverridableWorldStateManager(_dbProvider, _readOnlyTrieStore, _logManager); } + + public IWorldState CreateOverlayWorldState(IKeyValueStoreWithBatching overlayState, IKeyValueStore overlayCode) + { + OverlayTrieStore overlayTrieStore = new(overlayState, _readOnlyTrieStore, _logManager); + return new WorldState(overlayTrieStore, overlayCode, _logManager); + } } From 8439c49106c60e9fd0091d647f34d85c4a8741a8 Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Tue, 24 Dec 2024 14:59:26 +0800 Subject: [PATCH 6/7] Minor cleanup --- .../Nethermind.State/IWorldStateManager.cs | 2 +- .../OverridableWorldStateManager.cs | 15 ++++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/Nethermind/Nethermind.State/IWorldStateManager.cs b/src/Nethermind/Nethermind.State/IWorldStateManager.cs index b1b8e6ec06c..bb7817f8893 100644 --- a/src/Nethermind/Nethermind.State/IWorldStateManager.cs +++ b/src/Nethermind/Nethermind.State/IWorldStateManager.cs @@ -3,7 +3,6 @@ using System; using Nethermind.Core; -using Nethermind.Db; using Nethermind.Trie.Pruning; namespace Nethermind.State; @@ -23,6 +22,7 @@ public interface IWorldStateManager event EventHandler? ReorgBoundaryReached; + // TODO: These two method can be combined IOverridableWorldScope CreateOverridableWorldScope(); IWorldState CreateOverlayWorldState(IKeyValueStoreWithBatching overlayState, IKeyValueStore overlayCode); diff --git a/src/Nethermind/Nethermind.State/OverridableWorldStateManager.cs b/src/Nethermind/Nethermind.State/OverridableWorldStateManager.cs index c80fadda57b..b4a5c631d25 100644 --- a/src/Nethermind/Nethermind.State/OverridableWorldStateManager.cs +++ b/src/Nethermind/Nethermind.State/OverridableWorldStateManager.cs @@ -10,25 +10,18 @@ namespace Nethermind.State; public class OverridableWorldStateManager : IOverridableWorldScope { - private readonly ReadOnlyDbProvider _readOnlyDbProvider; private readonly StateReader _reader; - private readonly OverlayTrieStore _overlayTrieStore; - private readonly ILogManager? _logManager; - public OverridableWorldStateManager(IDbProvider dbProvider, IReadOnlyTrieStore trieStore, ILogManager? logManager) { - dbProvider = _readOnlyDbProvider = new(dbProvider, true); - OverlayTrieStore overlayTrieStore = new(dbProvider.StateDb, trieStore, logManager); + IReadOnlyDbProvider readOnlyDbProvider = new ReadOnlyDbProvider(dbProvider, true); + OverlayTrieStore overlayTrieStore = new(readOnlyDbProvider.StateDb, trieStore, logManager); - _logManager = logManager; - _reader = new(overlayTrieStore, dbProvider.GetDb(DbNames.Code), logManager); - _overlayTrieStore = overlayTrieStore; + _reader = new(overlayTrieStore, readOnlyDbProvider.CodeDb, logManager); - WorldState = new OverridableWorldState(_overlayTrieStore, _readOnlyDbProvider, _logManager); + WorldState = new OverridableWorldState(overlayTrieStore, readOnlyDbProvider, logManager); } public IOverridableWorldState WorldState { get; } public IStateReader GlobalStateReader => _reader; - public IReadOnlyTrieStore TrieStore => _overlayTrieStore.AsReadOnly(); } From a9fe7f5c0e5b2f09d6d10836108011348b4ac531 Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Sat, 28 Dec 2024 11:35:33 +0800 Subject: [PATCH 7/7] Fix build --- .../Nethermind.JsonRpc.Benchmark/EthModuleBenchmarks.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.JsonRpc.Benchmark/EthModuleBenchmarks.cs b/src/Nethermind/Nethermind.JsonRpc.Benchmark/EthModuleBenchmarks.cs index 997a4107c2a..86f446d973d 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Benchmark/EthModuleBenchmarks.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Benchmark/EthModuleBenchmarks.cs @@ -68,7 +68,8 @@ public void GlobalSetup() stateProvider.Commit(spec); stateProvider.CommitTree(0); - OverridableWorldStateManager stateManager = new(dbProvider, trieStore.AsReadOnly(), LimboLogs.Instance); + WorldStateManager stateManager = new(stateProvider, trieStore, dbProvider, LimboLogs.Instance); + OverridableWorldStateManager overridableScope = new(dbProvider, trieStore.AsReadOnly(), LimboLogs.Instance); StateReader stateReader = new(trieStore, codeDb, LimboLogs.Instance); @@ -138,7 +139,7 @@ TransactionProcessor transactionProcessor BlockchainBridge bridge = new( new OverridableTxProcessingEnv( - stateManager, + overridableScope, new ReadOnlyBlockTree(blockTree), specProvider, LimboLogs.Instance),