Skip to content

Commit

Permalink
small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishqjasoria committed Aug 20, 2024
1 parent fe3d85a commit fce32a4
Show file tree
Hide file tree
Showing 18 changed files with 29 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected async Task<EthereumTestResult> RunTest(BlockchainTest test, Stopwatch?

TrieStore trieStore = new(stateDb, _logManager);
IWorldState stateProvider = new WorldState(trieStore, codeDb, _logManager);
var worldStateManager = new WorldStateManager(stateProvider, trieStore, dbProvider, null, _logManager);
var worldStateManager = new WorldStateManager(stateProvider, trieStore, dbProvider, _logManager);
IBlockTree blockTree = Build.A.BlockTree()
.WithSpecProvider(specProvider)
.WithoutSettingHead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void Process(AuRaBlockProcessor auRaBlockProcessor, int blockNumber, Hash256 sta
TrieStore trieStore = new(dbProvider.StateDb, LimboLogs.Instance);
IWorldState stateProvider = new WorldState(trieStore, dbProvider.CodeDb, LimboLogs.Instance);
var worldStateManager =
new WorldStateManager(stateProvider, trieStore, dbProvider, null, LimboLogs.Instance);
new WorldStateManager(stateProvider, trieStore, dbProvider, LimboLogs.Instance);
ITransactionProcessor transactionProcessor = Substitute.For<ITransactionProcessor>();
AuRaBlockProcessor processor = new AuRaBlockProcessor(
HoleskySpecProvider.Instance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void Prepared_block_contains_author_field()
TrieStore trieStore = new(dbProvider.StateDb, LimboLogs.Instance);
IWorldState stateProvider = new WorldState(trieStore, dbProvider.CodeDb, LimboLogs.Instance);
var worldStateManger =
new WorldStateManager(stateProvider, trieStore, dbProvider, null, LimboLogs.Instance);
new WorldStateManager(stateProvider, trieStore, dbProvider, LimboLogs.Instance);

ITransactionProcessor transactionProcessor = Substitute.For<ITransactionProcessor>();
BlockProcessor processor = new(
Expand Down Expand Up @@ -72,7 +72,7 @@ public void Recovers_state_on_cancel()
TrieStore trieStore = new(dbProvider.StateDb, LimboLogs.Instance);
IWorldState stateProvider = new WorldState(trieStore, dbProvider.CodeDb, LimboLogs.Instance);
var worldStateManger =
new WorldStateManager(stateProvider, trieStore, dbProvider, null, LimboLogs.Instance);
new WorldStateManager(stateProvider, trieStore, dbProvider, LimboLogs.Instance);
ITransactionProcessor transactionProcessor = Substitute.For<ITransactionProcessor>();
BlockProcessor processor = new(
HoleskySpecProvider.Instance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private static IWorldStateManager CreateWorldStateManager()
var worldState = new WorldState(trieStore, dbProvider.CodeDb, LimboLogs.Instance);
worldState.CreateAccount(Eip2935Constants.BlockHashHistoryAddress, 0, 1);
worldState.Commit(Frontier.Instance);
return new WorldStateManager(worldState, trieStore, dbProvider, null, LimboLogs.Instance);
return new WorldStateManager(worldState, trieStore, dbProvider, LimboLogs.Instance);
}

private static BlockhashProvider CreateBlockHashProvider(IBlockFinder tree, IReleaseSpec spec)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void Test()
dbProvider.RegisteredDbs[DbNames.Code],
LimboLogs.Instance);
var worldStateManager =
new WorldStateManager(stateProvider, trieStore, dbProvider, null, LimboLogs.Instance);
new WorldStateManager(stateProvider, trieStore, dbProvider, LimboLogs.Instance);
StateReader stateReader = new(trieStore, dbProvider.GetDb<IDb>(DbNames.State), LimboLogs.Instance);
BlockhashProvider blockhashProvider = new(blockTree, specProvider, worldStateManager, LimboLogs.Instance);
CodeInfoRepository codeInfoRepository = 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 @@ -39,7 +39,7 @@ public void Setup()
WorldState stateProvider = new(trieStore, memDbProvider.CodeDb, LimboLogs.Instance);
StateReader stateReader = new(trieStore, memDbProvider.CodeDb, LimboLogs.Instance);
var worldStateManager =
new WorldStateManager(stateProvider, trieStore, memDbProvider, null, LimboLogs.Instance);
new WorldStateManager(stateProvider, trieStore, memDbProvider, LimboLogs.Instance);
ISpecProvider specProvider = MainnetSpecProvider.Instance;
EthereumEcdsa ecdsa = new(1);
ITransactionComparerProvider transactionComparerProvider =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public On CreateNode(PrivateKey privateKey, bool withGenesisAlreadyProcessed = f
stateProvider.Commit(goerliSpecProvider.GenesisSpec);
stateProvider.CommitTree(0);
var worldStateManager =
new WorldStateManager(stateProvider, trieStore, dbProvider, null, LimboLogs.Instance);
new WorldStateManager(stateProvider, trieStore, dbProvider, LimboLogs.Instance);

BlockTree blockTree = Build.A.BlockTree()
.WithSpecProvider(goerliSpecProvider)
Expand Down Expand Up @@ -149,7 +149,7 @@ public On CreateNode(PrivateKey privateKey, bool withGenesisAlreadyProcessed = f
IReadOnlyTrieStore minerTrieStore = trieStore.AsReadOnly();

WorldState minerStateProvider = new(minerTrieStore, dbProvider.CodeDb, nodeLogManager);
var minerWorldStateManager = new WorldStateManager(minerStateProvider, minerTrieStore, dbProvider, null,
var minerWorldStateManager = new WorldStateManager(minerStateProvider, minerTrieStore, dbProvider,
LimboLogs.Instance);
VirtualMachine minerVirtualMachine = new(blockhashProvider, specProvider, codeInfoRepository, nodeLogManager);
TransactionProcessor minerTransactionProcessor = new(goerliSpecProvider, minerVirtualMachine, codeInfoRepository, nodeLogManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ protected virtual async Task<TestBlockchain> Build(ISpecProvider? specProvider =
State.CommitTree(0);

ReadOnlyTrieStore = TrieStore.AsReadOnly(new NodeStorage(StateDb));
WorldStateManager = new WorldStateManager(State, TrieStore, DbProvider, null, LimboLogs.Instance);
WorldStateManager = new WorldStateManager(State, TrieStore, DbProvider, LimboLogs.Instance);
StateReader = new StateReader(ReadOnlyTrieStore, CodeDb, LogManager);

ChainLevelInfoRepository = new ChainLevelInfoRepository(this.DbProvider.BlockInfosDb);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public async Task SetUp()
IReadOnlyTrieStore trieStore = new TrieStore(_dbProvider.StateDb, LimboLogs.Instance).AsReadOnly();

IWorldStateManager readOnlyWorldStateManager =
new ReadOnlyWorldStateManager(dbProvider, trieStore, null, LimboLogs.Instance);
new ReadOnlyWorldStateManager(dbProvider, trieStore, LimboLogs.Instance);

IReadOnlyBlockTree readOnlyBlockTree = _blockTree.AsReadOnly();
ReadOnlyTxProcessingEnv processingEnv = new TestReadOnlyTxProcessingEnv(
Expand Down Expand Up @@ -221,7 +221,7 @@ public void Bridge_head_is_correct(long headNumber)
IReadOnlyTrieStore trieStore = new TrieStore(_dbProvider.StateDb, LimboLogs.Instance).AsReadOnly();

IWorldStateManager readOnlyWorldStateManager =
new ReadOnlyWorldStateManager(dbProvider, trieStore, null, LimboLogs.Instance);
new ReadOnlyWorldStateManager(dbProvider, trieStore, LimboLogs.Instance);
IReadOnlyBlockTree roBlockTree = _blockTree.AsReadOnly();
ReadOnlyTxProcessingEnv processingEnv = new(
readOnlyWorldStateManager,
Expand Down
3 changes: 1 addition & 2 deletions src/Nethermind/Nethermind.Init/InitializeStateDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ public Task Execute(CancellationToken cancellationToken)
worldState,
trieStore,
getApi.DbProvider,
preBlockCaches,
getApi.LogManager);
getApi.LogManager, preBlockCaches);

// TODO: Don't forget this
TrieStoreBoundaryWatcher trieStoreBoundaryWatcher = new(stateManager, _api.BlockTree!, _api.LogManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public async Task Setup()
.OfChainLength(10)
.TestObject;

_worldStateManager = new WorldStateManager(worldState, trieStore, _dbProvider, null, LimboLogs.Instance);
_worldStateManager = new WorldStateManager(worldState, trieStore, _dbProvider, LimboLogs.Instance);
ProofModuleFactory moduleFactory = new(
_worldStateManager,
_blockTree,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task Setup()
_stateReader = new StateReader(trieStore, _dbProvider.CodeDb, LimboLogs.Instance);

var worldStateManager =
new WorldStateManager(stateProvider, trieStore, _dbProvider, null, LimboLogs.Instance);
new WorldStateManager(stateProvider, trieStore, _dbProvider, LimboLogs.Instance);

BlockhashProvider blockhashProvider = new(_blockTree, specProvider, worldStateManager, LimboLogs.Instance);
CodeInfoRepository codeInfoRepository = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static NethermindApi ContextWithMocks()
BadBlocksStore = Substitute.For<IBlockStore>()
};

api.WorldStateManager = new ReadOnlyWorldStateManager(api.DbProvider, Substitute.For<IReadOnlyTrieStore>(), null, LimboLogs.Instance);
api.WorldStateManager = new ReadOnlyWorldStateManager(api.DbProvider, Substitute.For<IReadOnlyTrieStore>(), LimboLogs.Instance);
api.NodeStorageFactory = new NodeStorageFactory(INodeStorage.KeyScheme.HalfPath, LimboLogs.Instance);
return api;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void ShouldProxyGlobalWorldState()
IWorldState worldState = Substitute.For<IWorldState>();
ITrieStore trieStore = Substitute.For<ITrieStore>();
IDbProvider dbProvider = TestMemDbProvider.Init();
WorldStateManager worldStateManager = new WorldStateManager(worldState, trieStore, dbProvider, null, LimboLogs.Instance);
WorldStateManager worldStateManager = new WorldStateManager(worldState, trieStore, dbProvider, LimboLogs.Instance);

worldStateManager.GlobalWorldState.Should().Be(worldState);
}
Expand All @@ -34,7 +34,7 @@ public void ShouldProxyReorgBoundaryEvent()
IWorldState worldState = Substitute.For<IWorldState>();
ITrieStore trieStore = Substitute.For<ITrieStore>();
IDbProvider dbProvider = TestMemDbProvider.Init();
WorldStateManager worldStateManager = new WorldStateManager(worldState, trieStore, dbProvider, null, LimboLogs.Instance);
WorldStateManager worldStateManager = new WorldStateManager(worldState, trieStore, dbProvider, LimboLogs.Instance);

bool gotEvent = false;
worldStateManager.ReorgBoundaryReached += (sender, reached) => gotEvent = true;
Expand Down
5 changes: 3 additions & 2 deletions src/Nethermind/Nethermind.State/OverlayWorldStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ namespace Nethermind.State;
public class OverlayWorldStateManager(
IReadOnlyDbProvider dbProvider,
OverlayTrieStore overlayTrieStore,
ILogManager? logManager)
ILogManager? logManager,
PreBlockCaches? caches = null)
: IWorldStateManager
{
public PreBlockCaches Caches { get; }
public PreBlockCaches? Caches { get; } = caches;

private readonly IDb _codeDb = dbProvider.GetDb<IDb>(DbNames.Code);

Expand Down
8 changes: 3 additions & 5 deletions src/Nethermind/Nethermind.State/ReadOnlyWorldStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ public class ReadOnlyWorldStateManager : IWorldStateManager

public PreBlockCaches? Caches { get; }

public ReadOnlyWorldStateManager(
IDbProvider dbProvider,
public ReadOnlyWorldStateManager(IDbProvider dbProvider,
IReadOnlyTrieStore readOnlyTrieStore,
PreBlockCaches? preBlockCaches,
ILogManager logManager
)
ILogManager logManager,
PreBlockCaches? preBlockCaches = null)
{
_readOnlyTrieStore = readOnlyTrieStore;
_logManager = logManager;
Expand Down
6 changes: 3 additions & 3 deletions src/Nethermind/Nethermind.State/WorldStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class WorldStateManager(
IWorldState worldState,
ITrieStore trieStore,
IDbProvider dbProvider,
PreBlockCaches? preBlockCaches,
ILogManager logManager)
: ReadOnlyWorldStateManager(dbProvider, trieStore.AsReadOnly(), preBlockCaches, logManager)
ILogManager logManager,
PreBlockCaches? preBlockCaches = null)
: ReadOnlyWorldStateManager(dbProvider, trieStore.AsReadOnly(), logManager, preBlockCaches)
{
public override IWorldState GlobalWorldState => worldState;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ private SyncTestContext CreateSyncManager(int index)
stateProvider.CommitTree(0);
stateProvider.RecalculateStateRoot();
var worldStateManager =
new WorldStateManager(stateProvider, trieStore, dbProvider, null, LimboLogs.Instance);
new WorldStateManager(stateProvider, trieStore, dbProvider, LimboLogs.Instance);

InMemoryReceiptStorage receiptStorage = new();

Expand Down Expand Up @@ -315,7 +315,7 @@ private SyncTestContext CreateSyncManager(int index)
SyncPeerPool syncPeerPool = new(tree, nodeStatsManager, new TotalDifficultyBetterPeerStrategy(LimboLogs.Instance), logManager, 25);

WorldState devState = new(trieStore, codeDb, logManager);
var devWorldStateManager = new WorldStateManager(devState, trieStore, dbProvider, null, LimboLogs.Instance);
var devWorldStateManager = new WorldStateManager(devState, trieStore, dbProvider, LimboLogs.Instance);
VirtualMachine devEvm = new(blockhashProvider, specProvider, codeInfoRepository, logManager);
TransactionProcessor devTxProcessor = new(specProvider, devEvm, codeInfoRepository, logManager);

Expand Down

0 comments on commit fce32a4

Please sign in to comment.