@aztec/world-state 0.0.1-commit.2ed92850 → 0.0.1-commit.2f68f620
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/instrumentation/instrumentation.d.ts +4 -3
- package/dest/instrumentation/instrumentation.d.ts.map +1 -1
- package/dest/instrumentation/instrumentation.js +13 -11
- package/dest/native/fork_checkpoint.d.ts +7 -1
- package/dest/native/fork_checkpoint.d.ts.map +1 -1
- package/dest/native/fork_checkpoint.js +15 -3
- package/dest/native/ipc_world_state_instance.d.ts +87 -0
- package/dest/native/ipc_world_state_instance.d.ts.map +1 -0
- package/dest/native/ipc_world_state_instance.js +660 -0
- package/dest/native/merkle_trees_facade.d.ts +12 -8
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +63 -115
- package/dest/native/message.d.ts +14 -221
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/message.js +0 -42
- package/dest/native/native_world_state.d.ts +20 -8
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +116 -60
- package/dest/native/native_world_state_instance.d.ts +58 -41
- package/dest/native/native_world_state_instance.d.ts.map +1 -1
- package/dest/native/native_world_state_instance.js +5 -202
- package/dest/native/world_state_operation.d.ts +7 -0
- package/dest/native/world_state_operation.d.ts.map +1 -0
- package/dest/native/world_state_operation.js +5 -0
- package/dest/synchronizer/config.d.ts +3 -3
- package/dest/synchronizer/config.d.ts.map +1 -1
- package/dest/synchronizer/config.js +15 -13
- package/dest/synchronizer/factory.d.ts +6 -5
- package/dest/synchronizer/factory.d.ts.map +1 -1
- package/dest/synchronizer/factory.js +7 -6
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +4 -4
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +95 -21
- package/dest/testing.d.ts +4 -3
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +10 -6
- package/dest/world-state-db/merkle_tree_db.d.ts +1 -10
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/package.json +14 -11
- package/src/instrumentation/instrumentation.ts +15 -19
- package/src/native/fork_checkpoint.ts +19 -3
- package/src/native/ipc_world_state_instance.ts +830 -0
- package/src/native/merkle_trees_facade.ts +89 -109
- package/src/native/message.ts +13 -286
- package/src/native/native_world_state.ts +136 -94
- package/src/native/native_world_state_instance.ts +96 -278
- package/src/native/world_state_operation.ts +33 -0
- package/src/synchronizer/config.ts +21 -15
- package/src/synchronizer/factory.ts +18 -11
- package/src/synchronizer/server_world_state_synchronizer.ts +99 -22
- package/src/testing.ts +8 -9
- package/src/world-state-db/merkle_tree_db.ts +0 -10
- package/dest/native/world_state_ops_queue.d.ts +0 -19
- package/dest/native/world_state_ops_queue.d.ts.map +0 -1
- package/dest/native/world_state_ops_queue.js +0 -146
- package/src/native/world_state_ops_queue.ts +0 -190
|
@@ -3,10 +3,9 @@ import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
|
3
3
|
import { fromEntries, padArrayEnd } from '@aztec/foundation/collection';
|
|
4
4
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
5
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
|
-
import {
|
|
7
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
6
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
8
7
|
import type { L2Block } from '@aztec/stdlib/block';
|
|
9
|
-
import { DatabaseVersionManager } from '@aztec/stdlib/database-version';
|
|
8
|
+
import { DatabaseVersionManager } from '@aztec/stdlib/database-version/manager';
|
|
10
9
|
import type {
|
|
11
10
|
IndexedTreeId,
|
|
12
11
|
MerkleTreeReadOperations,
|
|
@@ -14,21 +13,21 @@ import type {
|
|
|
14
13
|
} from '@aztec/stdlib/interfaces/server';
|
|
15
14
|
import type { SnapshotDataKeys } from '@aztec/stdlib/snapshots';
|
|
16
15
|
import { MerkleTreeId, NullifierLeaf, type NullifierLeafPreimage, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
17
|
-
import { BlockHeader, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
|
|
18
|
-
import { WorldStateRevision } from '@aztec/stdlib/world-state';
|
|
16
|
+
import { BlockHeader, GlobalVariables, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
|
|
17
|
+
import { EMPTY_GENESIS_DATA, type GenesisData, WorldStateRevision } from '@aztec/stdlib/world-state';
|
|
19
18
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
20
19
|
|
|
21
20
|
import assert from 'assert/strict';
|
|
22
|
-
import { mkdtemp, rm } from 'fs/promises';
|
|
21
|
+
import { mkdir, mkdtemp, rm } from 'fs/promises';
|
|
23
22
|
import { tmpdir } from 'os';
|
|
24
23
|
import { join } from 'path';
|
|
25
24
|
|
|
26
25
|
import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
|
|
27
26
|
import type { WorldStateTreeMapSizes } from '../synchronizer/factory.js';
|
|
28
27
|
import type { MerkleTreeAdminDatabase as MerkleTreeDatabase } from '../world-state-db/merkle_tree_db.js';
|
|
28
|
+
import { IpcWorldState } from './ipc_world_state_instance.js';
|
|
29
29
|
import { MerkleTreesFacade, MerkleTreesForkFacade, serializeLeaf } from './merkle_trees_facade.js';
|
|
30
30
|
import {
|
|
31
|
-
WorldStateMessageType,
|
|
32
31
|
type WorldStateStatusFull,
|
|
33
32
|
type WorldStateStatusSummary,
|
|
34
33
|
blockStateReference,
|
|
@@ -36,7 +35,7 @@ import {
|
|
|
36
35
|
sanitizeSummary,
|
|
37
36
|
treeStateReferenceToSnapshot,
|
|
38
37
|
} from './message.js';
|
|
39
|
-
import {
|
|
38
|
+
import type { NativeWorldStateInstance } from './native_world_state_instance.js';
|
|
40
39
|
|
|
41
40
|
// The current version of the world state database schema
|
|
42
41
|
// Increment this when making incompatible changes to the database schema
|
|
@@ -50,34 +49,49 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
50
49
|
private cachedStatusSummary: WorldStateStatusSummary | undefined;
|
|
51
50
|
|
|
52
51
|
protected constructor(
|
|
53
|
-
protected instance:
|
|
52
|
+
protected instance: NativeWorldStateInstance,
|
|
54
53
|
protected readonly worldStateInstrumentation: WorldStateInstrumentation,
|
|
55
|
-
protected readonly log: Logger
|
|
54
|
+
protected readonly log: Logger,
|
|
55
|
+
private readonly genesis: GenesisData = EMPTY_GENESIS_DATA,
|
|
56
56
|
private readonly cleanup = () => Promise.resolve(),
|
|
57
|
+
/** Factory to recreate a fresh IpcWorldState after clear(). */
|
|
58
|
+
private readonly recreateInstance?: () => Promise<NativeWorldStateInstance>,
|
|
57
59
|
) {}
|
|
58
60
|
|
|
59
61
|
static async new(
|
|
60
62
|
rollupAddress: EthAddress,
|
|
61
63
|
dataDir: string,
|
|
62
64
|
wsTreeMapSizes: WorldStateTreeMapSizes,
|
|
63
|
-
|
|
65
|
+
genesis: GenesisData = EMPTY_GENESIS_DATA,
|
|
64
66
|
instrumentation = new WorldStateInstrumentation(getTelemetryClient()),
|
|
65
|
-
|
|
67
|
+
bindings?: LoggerBindings,
|
|
66
68
|
cleanup = () => Promise.resolve(),
|
|
67
69
|
): Promise<NativeWorldStateService> {
|
|
70
|
+
for (const [key, value] of Object.entries(wsTreeMapSizes)) {
|
|
71
|
+
if (value <= 0) {
|
|
72
|
+
throw new Error(`Map size must be a positive number, got ${value} for ${key}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const log = createLogger('world-state:database', bindings);
|
|
68
77
|
const worldStateDirectory = join(dataDir, WORLD_STATE_DIR);
|
|
69
|
-
|
|
78
|
+
|
|
70
79
|
const versionManager = new DatabaseVersionManager({
|
|
71
80
|
schemaVersion: WORLD_STATE_DB_VERSION,
|
|
72
81
|
rollupAddress,
|
|
73
82
|
dataDirectory: worldStateDirectory,
|
|
74
|
-
onOpen: (dir
|
|
75
|
-
return Promise.resolve(new NativeWorldState(dir, wsTreeMapSizes, prefilledPublicData, instrumentation));
|
|
76
|
-
},
|
|
83
|
+
onOpen: dir => IpcWorldState.spawn(dir, wsTreeMapSizes, genesis, instrumentation, bindings),
|
|
77
84
|
});
|
|
78
85
|
|
|
79
86
|
const [instance] = await versionManager.open();
|
|
80
|
-
|
|
87
|
+
|
|
88
|
+
const recreateInstance = async () => {
|
|
89
|
+
await rm(worldStateDirectory, { recursive: true, force: true, maxRetries: 3 });
|
|
90
|
+
await mkdir(worldStateDirectory, { recursive: true });
|
|
91
|
+
return IpcWorldState.spawn(worldStateDirectory, wsTreeMapSizes, genesis, instrumentation, bindings);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const worldState = new this(instance, instrumentation, log, genesis, cleanup, recreateInstance);
|
|
81
95
|
try {
|
|
82
96
|
await worldState.init();
|
|
83
97
|
} catch (e) {
|
|
@@ -89,14 +103,18 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
89
103
|
}
|
|
90
104
|
|
|
91
105
|
static async tmp(
|
|
92
|
-
rollupAddress = EthAddress.ZERO,
|
|
93
106
|
cleanupTmpDir = true,
|
|
94
|
-
|
|
107
|
+
genesis: GenesisData = EMPTY_GENESIS_DATA,
|
|
95
108
|
instrumentation = new WorldStateInstrumentation(getTelemetryClient()),
|
|
109
|
+
bindings?: LoggerBindings,
|
|
96
110
|
): Promise<NativeWorldStateService> {
|
|
97
|
-
const log = createLogger('world-state:database');
|
|
111
|
+
const log = createLogger('world-state:database', bindings);
|
|
98
112
|
const dataDir = await mkdtemp(join(tmpdir(), 'aztec-world-state-'));
|
|
99
|
-
|
|
113
|
+
// Temporary (test/dev) world states are small and short-lived. Keep the LMDB
|
|
114
|
+
// map sizes in the MB range: with the IPC backend each tmp() spawns a separate
|
|
115
|
+
// aztec-wsdb that maps these per tree, and oversized maps add real cold-start
|
|
116
|
+
// I/O under parallel CI load. 256 MB/tree is ample for tests.
|
|
117
|
+
const dbMapSizeKb = 256 * 1024;
|
|
100
118
|
const worldStateTreeMapSizes: WorldStateTreeMapSizes = {
|
|
101
119
|
archiveTreeMapSizeKb: dbMapSizeKb,
|
|
102
120
|
nullifierTreeMapSizeKb: dbMapSizeKb,
|
|
@@ -106,7 +124,8 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
106
124
|
};
|
|
107
125
|
log.debug(`Created temporary world state database at: ${dataDir} with tree map size: ${dbMapSizeKb}`);
|
|
108
126
|
|
|
109
|
-
|
|
127
|
+
const instance = await IpcWorldState.spawn(dataDir, worldStateTreeMapSizes, genesis, instrumentation, bindings);
|
|
128
|
+
|
|
110
129
|
const cleanup = async () => {
|
|
111
130
|
if (cleanupTmpDir) {
|
|
112
131
|
await rm(dataDir, { recursive: true, force: true, maxRetries: 3 });
|
|
@@ -116,7 +135,43 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
116
135
|
}
|
|
117
136
|
};
|
|
118
137
|
|
|
119
|
-
|
|
138
|
+
const recreateInstance = async () => {
|
|
139
|
+
await rm(dataDir, { recursive: true, force: true, maxRetries: 3 });
|
|
140
|
+
await mkdir(dataDir, { recursive: true });
|
|
141
|
+
return IpcWorldState.spawn(dataDir, worldStateTreeMapSizes, genesis, instrumentation, bindings);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const worldState = new this(instance, instrumentation, log, genesis, cleanup, recreateInstance);
|
|
145
|
+
try {
|
|
146
|
+
await worldState.init();
|
|
147
|
+
} catch (e) {
|
|
148
|
+
log.error(`Error initializing tmp world state: ${e}`);
|
|
149
|
+
throw e;
|
|
150
|
+
}
|
|
151
|
+
return worldState;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
static ephemeral(
|
|
155
|
+
genesis: GenesisData = EMPTY_GENESIS_DATA,
|
|
156
|
+
instrumentation = new WorldStateInstrumentation(getTelemetryClient()),
|
|
157
|
+
bindings?: LoggerBindings,
|
|
158
|
+
): Promise<NativeWorldStateService> {
|
|
159
|
+
return this.tmp(/*cleanupTmpDir=*/ true, genesis, instrumentation, bindings);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
static async fromIpc(
|
|
163
|
+
wsdbBackend: ConstructorParameters<typeof IpcWorldState>[0],
|
|
164
|
+
instrumentation = new WorldStateInstrumentation(getTelemetryClient()),
|
|
165
|
+
bindings?: LoggerBindings,
|
|
166
|
+
genesis: GenesisData = EMPTY_GENESIS_DATA,
|
|
167
|
+
cleanup = () => Promise.resolve(),
|
|
168
|
+
recreateInstance?: () => Promise<NativeWorldStateInstance>,
|
|
169
|
+
): Promise<NativeWorldStateService> {
|
|
170
|
+
const log = createLogger('world-state:database', bindings);
|
|
171
|
+
const instance = new IpcWorldState(wsdbBackend, instrumentation, bindings);
|
|
172
|
+
const worldState = new this(instance, instrumentation, log, genesis, cleanup, recreateInstance);
|
|
173
|
+
await worldState.init();
|
|
174
|
+
return worldState;
|
|
120
175
|
}
|
|
121
176
|
|
|
122
177
|
protected async init() {
|
|
@@ -135,18 +190,29 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
135
190
|
|
|
136
191
|
// the initial header _must_ be the first element in the archive tree
|
|
137
192
|
// if this assertion fails, check that the hashing done in Header in yarn-project matches the initial header hash done in world_state.cpp
|
|
138
|
-
const indices = await committed.findLeafIndices(MerkleTreeId.ARCHIVE, [
|
|
139
|
-
(await this.initialHeader.hash()).toField(),
|
|
140
|
-
]);
|
|
193
|
+
const indices = await committed.findLeafIndices(MerkleTreeId.ARCHIVE, [await this.initialHeader.hash()]);
|
|
141
194
|
const initialHeaderIndex = indices[0];
|
|
142
195
|
assert.strictEqual(initialHeaderIndex, 0n, 'Invalid initial archive state');
|
|
143
196
|
}
|
|
144
197
|
|
|
145
|
-
public async clear() {
|
|
198
|
+
public async clear(): Promise<void> {
|
|
199
|
+
if (!this.recreateInstance) {
|
|
200
|
+
throw new Error('clear() is not available for externally-managed IPC backends');
|
|
201
|
+
}
|
|
202
|
+
this.log.warn('Clearing world state: shutting down WSDB, deleting data, and recreating');
|
|
146
203
|
await this.instance.close();
|
|
147
204
|
this.cachedStatusSummary = undefined;
|
|
148
|
-
|
|
149
|
-
|
|
205
|
+
this.instance = await this.recreateInstance();
|
|
206
|
+
await this.init();
|
|
207
|
+
this.log.info('World state cleared and reinitialized from genesis');
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** Returns the IPC path of the underlying IPC backend, if available. */
|
|
211
|
+
public getIpcPath(): string {
|
|
212
|
+
if (this.instance instanceof IpcWorldState) {
|
|
213
|
+
return this.instance.getIpcPath();
|
|
214
|
+
}
|
|
215
|
+
throw new Error('getIpcPath() is only available with IPC world state');
|
|
150
216
|
}
|
|
151
217
|
|
|
152
218
|
public getCommitted(): MerkleTreeReadOperations {
|
|
@@ -165,17 +231,16 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
165
231
|
blockNumber?: BlockNumber,
|
|
166
232
|
opts: { closeDelayMs?: number } = {},
|
|
167
233
|
): Promise<MerkleTreeWriteOperations> {
|
|
168
|
-
const
|
|
234
|
+
const forkId = await this.instance.createFork({
|
|
169
235
|
latest: blockNumber === undefined,
|
|
170
236
|
blockNumber: blockNumber ?? BlockNumber.ZERO,
|
|
171
|
-
canonical: true,
|
|
172
237
|
});
|
|
173
238
|
return new MerkleTreesForkFacade(
|
|
174
239
|
this.instance,
|
|
175
240
|
this.initialHeader!,
|
|
176
241
|
new WorldStateRevision(
|
|
177
|
-
/*forkId=*/
|
|
178
|
-
/* blockNumber=*/
|
|
242
|
+
/*forkId=*/ forkId,
|
|
243
|
+
/* blockNumber=*/ WorldStateRevision.LATEST,
|
|
179
244
|
/* includeUncommitted=*/ true,
|
|
180
245
|
),
|
|
181
246
|
opts,
|
|
@@ -218,35 +283,41 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
218
283
|
});
|
|
219
284
|
|
|
220
285
|
try {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
canonical: true,
|
|
232
|
-
},
|
|
233
|
-
this.sanitizeAndCacheSummaryFromFull.bind(this),
|
|
234
|
-
this.deleteCachedSummary.bind(this),
|
|
235
|
-
);
|
|
286
|
+
const status = await this.instance.syncBlock({
|
|
287
|
+
blockNumber: l2Block.number,
|
|
288
|
+
blockHeaderHash: (await l2Block.hash()).toBuffer(),
|
|
289
|
+
paddedL1ToL2Messages: paddedL1ToL2Messages.map(serializeLeaf),
|
|
290
|
+
paddedNoteHashes: paddedNoteHashes.map(serializeLeaf),
|
|
291
|
+
paddedNullifiers: paddedNullifiers.map(serializeLeaf),
|
|
292
|
+
publicDataWrites: publicDataWrites.map(serializeLeaf),
|
|
293
|
+
blockStateRef: blockStateReference(l2Block.header.state),
|
|
294
|
+
});
|
|
295
|
+
return this.sanitizeAndCacheSummaryFromFull(status);
|
|
236
296
|
} catch (err) {
|
|
297
|
+
this.deleteCachedSummary();
|
|
237
298
|
this.worldStateInstrumentation.incCriticalErrors('synch_pending_block');
|
|
238
299
|
throw err;
|
|
239
300
|
}
|
|
240
301
|
}
|
|
241
302
|
|
|
242
303
|
public async close(): Promise<void> {
|
|
243
|
-
|
|
244
|
-
|
|
304
|
+
try {
|
|
305
|
+
await this.instance.close();
|
|
306
|
+
} finally {
|
|
307
|
+
await this.cleanup();
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
async [Symbol.asyncDispose](): Promise<void> {
|
|
312
|
+
await this.close();
|
|
245
313
|
}
|
|
246
314
|
|
|
247
315
|
private async buildInitialHeader(): Promise<BlockHeader> {
|
|
248
316
|
const state = await this.getInitialStateReference();
|
|
249
|
-
return BlockHeader.empty({
|
|
317
|
+
return BlockHeader.empty({
|
|
318
|
+
state,
|
|
319
|
+
globalVariables: GlobalVariables.empty({ timestamp: this.genesis.genesisTimestamp }),
|
|
320
|
+
});
|
|
250
321
|
}
|
|
251
322
|
|
|
252
323
|
private sanitizeAndCacheSummaryFromFull(response: WorldStateStatusFull) {
|
|
@@ -261,7 +332,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
261
332
|
return sanitized;
|
|
262
333
|
}
|
|
263
334
|
|
|
264
|
-
private deleteCachedSummary(
|
|
335
|
+
private deleteCachedSummary() {
|
|
265
336
|
this.cachedStatusSummary = undefined;
|
|
266
337
|
}
|
|
267
338
|
|
|
@@ -272,16 +343,9 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
272
343
|
*/
|
|
273
344
|
public async setFinalized(toBlockNumber: BlockNumber) {
|
|
274
345
|
try {
|
|
275
|
-
await this.instance.
|
|
276
|
-
WorldStateMessageType.FINALIZE_BLOCKS,
|
|
277
|
-
{
|
|
278
|
-
toBlockNumber,
|
|
279
|
-
canonical: true,
|
|
280
|
-
},
|
|
281
|
-
this.sanitizeAndCacheSummary.bind(this),
|
|
282
|
-
this.deleteCachedSummary.bind(this),
|
|
283
|
-
);
|
|
346
|
+
this.sanitizeAndCacheSummary(await this.instance.finalizeBlocks(toBlockNumber));
|
|
284
347
|
} catch (err) {
|
|
348
|
+
this.deleteCachedSummary();
|
|
285
349
|
this.worldStateInstrumentation.incCriticalErrors('finalize_block');
|
|
286
350
|
throw err;
|
|
287
351
|
}
|
|
@@ -295,16 +359,9 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
295
359
|
*/
|
|
296
360
|
public async removeHistoricalBlocks(toBlockNumber: BlockNumber) {
|
|
297
361
|
try {
|
|
298
|
-
return await this.instance.
|
|
299
|
-
WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS,
|
|
300
|
-
{
|
|
301
|
-
toBlockNumber,
|
|
302
|
-
canonical: true,
|
|
303
|
-
},
|
|
304
|
-
this.sanitizeAndCacheSummaryFromFull.bind(this),
|
|
305
|
-
this.deleteCachedSummary.bind(this),
|
|
306
|
-
);
|
|
362
|
+
return this.sanitizeAndCacheSummaryFromFull(await this.instance.removeHistoricalBlocks(toBlockNumber));
|
|
307
363
|
} catch (err) {
|
|
364
|
+
this.deleteCachedSummary();
|
|
308
365
|
this.worldStateInstrumentation.incCriticalErrors('prune_historical_block');
|
|
309
366
|
throw err;
|
|
310
367
|
}
|
|
@@ -317,16 +374,9 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
317
374
|
*/
|
|
318
375
|
public async unwindBlocks(toBlockNumber: BlockNumber) {
|
|
319
376
|
try {
|
|
320
|
-
return await this.instance.
|
|
321
|
-
WorldStateMessageType.UNWIND_BLOCKS,
|
|
322
|
-
{
|
|
323
|
-
toBlockNumber,
|
|
324
|
-
canonical: true,
|
|
325
|
-
},
|
|
326
|
-
this.sanitizeAndCacheSummaryFromFull.bind(this),
|
|
327
|
-
this.deleteCachedSummary.bind(this),
|
|
328
|
-
);
|
|
377
|
+
return this.sanitizeAndCacheSummaryFromFull(await this.instance.unwindBlocks(toBlockNumber));
|
|
329
378
|
} catch (err) {
|
|
379
|
+
this.deleteCachedSummary();
|
|
330
380
|
this.worldStateInstrumentation.incCriticalErrors('prune_pending_block');
|
|
331
381
|
throw err;
|
|
332
382
|
}
|
|
@@ -336,11 +386,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
336
386
|
if (this.cachedStatusSummary !== undefined) {
|
|
337
387
|
return { ...this.cachedStatusSummary };
|
|
338
388
|
}
|
|
339
|
-
return await this.instance.
|
|
340
|
-
WorldStateMessageType.GET_STATUS,
|
|
341
|
-
{ canonical: true },
|
|
342
|
-
this.sanitizeAndCacheSummary.bind(this),
|
|
343
|
-
);
|
|
389
|
+
return this.sanitizeAndCacheSummary(await this.instance.getStatus());
|
|
344
390
|
}
|
|
345
391
|
|
|
346
392
|
updateLeaf<ID extends IndexedTreeId>(
|
|
@@ -352,14 +398,14 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
352
398
|
}
|
|
353
399
|
|
|
354
400
|
private async getInitialStateReference(): Promise<StateReference> {
|
|
355
|
-
const
|
|
401
|
+
const state = await this.instance.getInitialStateReference();
|
|
356
402
|
|
|
357
403
|
return new StateReference(
|
|
358
|
-
treeStateReferenceToSnapshot(
|
|
404
|
+
treeStateReferenceToSnapshot(state[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]),
|
|
359
405
|
new PartialStateReference(
|
|
360
|
-
treeStateReferenceToSnapshot(
|
|
361
|
-
treeStateReferenceToSnapshot(
|
|
362
|
-
treeStateReferenceToSnapshot(
|
|
406
|
+
treeStateReferenceToSnapshot(state[MerkleTreeId.NOTE_HASH_TREE]),
|
|
407
|
+
treeStateReferenceToSnapshot(state[MerkleTreeId.NULLIFIER_TREE]),
|
|
408
|
+
treeStateReferenceToSnapshot(state[MerkleTreeId.PUBLIC_DATA_TREE]),
|
|
363
409
|
),
|
|
364
410
|
);
|
|
365
411
|
}
|
|
@@ -368,11 +414,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
368
414
|
dstPath: string,
|
|
369
415
|
compact: boolean = true,
|
|
370
416
|
): Promise<Record<Exclude<SnapshotDataKeys, 'archiver'>, string>> {
|
|
371
|
-
await this.instance.
|
|
372
|
-
dstPath,
|
|
373
|
-
compact,
|
|
374
|
-
canonical: true,
|
|
375
|
-
});
|
|
417
|
+
await this.instance.copyStores(dstPath, compact);
|
|
376
418
|
return fromEntries(NATIVE_WORLD_STATE_DBS.map(([name, dir]) => [name, join(dstPath, dir, 'data.mdb')] as const));
|
|
377
419
|
}
|
|
378
420
|
}
|