-
Notifications
You must be signed in to change notification settings - Fork 713
Expand file tree
/
Copy pathFlatWorldStateModule.cs
More file actions
149 lines (134 loc) · 6.45 KB
/
Copy pathFlatWorldStateModule.cs
File metadata and controls
149 lines (134 loc) · 6.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only
using System;
using System.IO;
using Autofac;
using Nethermind.Api.Steps;
using Nethermind.Blockchain;
using Nethermind.Blockchain.FullPruning;
using Nethermind.Blockchain.Synchronization;
using Nethermind.Config;
using Nethermind.Core;
using Nethermind.Db;
using Nethermind.Db.Rocks.Config;
using Nethermind.Init.Steps;
using Nethermind.JsonRpc;
using Nethermind.JsonRpc.Modules.Admin;
using Nethermind.Logging;
using Nethermind.Monitoring.Config;
using Nethermind.Api;
using Nethermind.State.Flat;
using Nethermind.State.Flat.Persistence;
using Nethermind.State.Flat.PersistedSnapshots;
using Nethermind.State.Flat.ScopeProvider;
using Nethermind.State.Flat.PersistedSnapshots.Storage;
using Nethermind.State.Flat.Sync;
using Nethermind.State.Flat.Sync.Snap;
namespace Nethermind.Init.Modules;
public class FlatWorldStateModule(IFlatDbConfig flatDbConfig) : Module
{
protected override void Load(ContainerBuilder builder)
{
builder
// Implementation of nethermind interfaces
.AddSingleton<FlatStateReader>()
.AddSingleton<FlatWorldStateManager>()
.AddSingleton<FlatStateBoundary>()
// Stub out the pruning trie store admin RPC with a disabled response.
.AddSingleton<PruningTrieStateAdminRpcModuleStub>()
// The actual flatDb components
.AddSingleton<IFlatDbManager>((ctx) => new FlatDbManager(
ctx.Resolve<IResourcePool>(),
ctx.Resolve<IProcessExitSource>(),
ctx.Resolve<ITrieNodeCache>(),
ctx.Resolve<ISnapshotCompactor>(),
ctx.Resolve<ISnapshotRepository>(),
ctx.Resolve<IPersistenceManager>(),
ctx.Resolve<IPersistedSnapshotLoader>(),
ctx.Resolve<IFlatDbConfig>(),
ctx.Resolve<IBlocksConfig>(),
ctx.Resolve<ILogManager>(),
ctx.Resolve<IMetricsConfig>().EnableDetailedMetric))
.AddSingleton<IResourcePool, ResourcePool>()
.AddSingleton<ITrieNodeCache, TrieNodeCache>()
.AddSingleton<ICompactionSchedule, CompactionSchedule>()
.AddSingleton<ISnapshotCompactor, SnapshotCompactor>()
.AddSingleton<IPersistenceManager, PersistenceManager>()
.AddSingleton<IArenaManager, IFlatDbConfig, IInitConfig, ILogManager>((cfg, initConfig, logManager) =>
{
string basePath = Path.Combine(initConfig.BaseDbPath, "persistedSnapshot");
return new ArenaManager(Path.Combine(basePath, "arena"), cfg, logManager);
})
.AddSingleton<BlobArenaManager, IFlatDbConfig, IInitConfig>((cfg, initConfig) =>
{
string basePath = Path.Combine(initConfig.BaseDbPath, "persistedSnapshot");
return new BlobArenaManager(
Path.Combine(basePath, "blob"),
cfg.ArenaFileSizeBytes);
})
.AddSingleton<IPersistedSnapshotCompactor, PersistedSnapshotCompactor>()
.AddSingleton<ISnapshotRepository, SnapshotRepository>()
.AddSingleton<IPersistedSnapshotLoader, PersistedSnapshotLoader>()
.AddSingleton<ITrieWarmer>(flatDbConfig.TrieWarmerWorkerCount == 0
? _ => new NoopTrieWarmer()
: ctx => ctx.Resolve<TrieWarmer>())
.AddSingleton<TrieWarmer>()
.Add<FlatOverridableWorldScope>()
// Sync components
.AddSingleton<FlatSnapTrieFactory>()
.AddSingleton<IFlatStateRootIndex>((ctx) => new FlatStateRootIndex(
ctx.Resolve<IBlockTree>(),
ctx.Resolve<ISyncConfig>().SnapServingMaxDepth))
.AddSingleton<FlatTreeSyncStore>()
.AddSingleton<FlatFullStateFinder>()
// Persistences
.AddColumnDatabase<FlatDbColumns>(DbNames.Flat)
.AddKeyedSingleton<IDb>(DbNames.PersistedSnapshotCatalog, ctx => ctx
.Resolve<IDbFactory>()
.CreateDb(new DbSettings(
nameof(DbNames.PersistedSnapshotCatalog),
Path.Combine("persistedSnapshot", "catalog"))))
.AddSingleton<SnapshotCatalog>()
.AddSingleton<ISnapshotCatalog>(ctx => ctx.Resolve<SnapshotCatalog>())
.AddSingleton<RocksDbPersistence>()
.AddSingleton<FlatInTriePersistence>()
.AddDecorator<IRocksDbConfigFactory, FlatRocksDbConfigAdjuster>()
.AddSingleton<PreimageRocksdbPersistence>()
.AddDatabase(DbNames.Preimage)
.AddSingleton<IPersistence, IFlatDbConfig, IProcessExitSource, ILogManager, IComponentContext>((flatDbConfig, exitSource, logManager, ctx) =>
{
IPersistence persistence = flatDbConfig.Layout switch
{
FlatLayout.Flat => ctx.Resolve<RocksDbPersistence>(),
FlatLayout.FlatInTrie => ctx.Resolve<FlatInTriePersistence>(),
FlatLayout.PreimageFlat => ctx.Resolve<PreimageRocksdbPersistence>(),
_ => throw new NotSupportedException($"Unsupported layout {flatDbConfig.Layout}")
};
if (flatDbConfig.EnablePreimageRecording)
{
IDb preimageDb = ctx.ResolveKeyed<IDb>(DbNames.Preimage);
persistence = new PreimageRecordingPersistence(persistence, preimageDb);
}
IPersistence cachedReader = new CachedReaderPersistence(persistence, exitSource, logManager);
return new CarryForwardCachingPersistence(cachedReader);
})
;
if (!flatDbConfig.EnableLongFinality)
{
builder
.AddSingleton<ISnapshotCatalog>(NullSnapshotCatalog.Instance)
.AddSingleton<IPersistedSnapshotLoader>(NullPersistedSnapshotLoader.Instance)
.AddSingleton<IPersistedSnapshotCompactor>(NullPersistedSnapshotCompactor.Instance);
}
if (flatDbConfig.ImportFromPruningTrieState)
{
builder
.AddSingleton<Importer>()
.AddStep(typeof(ImportFlatDb));
}
}
internal class PruningTrieStateAdminRpcModuleStub : IPruningTrieStateAdminRpcModule
{
public ResultWrapper<PruningStatus> admin_prune() => ResultWrapper<PruningStatus>.Success(PruningStatus.Disabled);
}
}