@aztec/world-state 0.0.1-commit.4d3c002 → 0.0.1-commit.4d9804df
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/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/instrumentation/instrumentation.d.ts +4 -3
- package/dest/instrumentation/instrumentation.d.ts.map +1 -1
- package/dest/instrumentation/instrumentation.js +4 -9
- package/dest/native/index.d.ts +2 -1
- package/dest/native/index.d.ts.map +1 -1
- package/dest/native/index.js +1 -0
- package/dest/native/ipc_world_state_instance.d.ts +89 -0
- package/dest/native/ipc_world_state_instance.d.ts.map +1 -0
- package/dest/native/ipc_world_state_instance.js +661 -0
- package/dest/native/merkle_trees_facade.d.ts +8 -4
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +60 -115
- package/dest/native/message.d.ts +14 -230
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/message.js +0 -42
- package/dest/native/native_world_state.d.ts +19 -7
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +120 -58
- package/dest/native/native_world_state_instance.d.ts +56 -42
- package/dest/native/native_world_state_instance.d.ts.map +1 -1
- package/dest/native/native_world_state_instance.js +1 -203
- 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 +1 -1
- package/dest/synchronizer/config.d.ts.map +1 -1
- package/dest/synchronizer/config.js +9 -10
- package/dest/synchronizer/errors.d.ts +8 -1
- package/dest/synchronizer/errors.d.ts.map +1 -1
- package/dest/synchronizer/errors.js +8 -1
- package/dest/synchronizer/factory.d.ts +4 -4
- package/dest/synchronizer/factory.d.ts.map +1 -1
- package/dest/synchronizer/factory.js +7 -6
- package/dest/synchronizer/index.d.ts +2 -1
- package/dest/synchronizer/index.d.ts.map +1 -1
- package/dest/synchronizer/index.js +1 -0
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +11 -6
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +64 -49
- package/dest/test/utils.d.ts +1 -1
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +6 -1
- package/dest/testing.d.ts +4 -3
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +14 -7
- package/package.json +13 -10
- package/src/index.ts +1 -0
- package/src/instrumentation/instrumentation.ts +6 -18
- package/src/native/index.ts +1 -0
- package/src/native/ipc_world_state_instance.ts +834 -0
- package/src/native/merkle_trees_facade.ts +85 -112
- package/src/native/message.ts +13 -297
- package/src/native/native_world_state.ts +144 -97
- package/src/native/native_world_state_instance.ts +94 -281
- package/src/native/world_state_operation.ts +33 -0
- package/src/synchronizer/config.ts +14 -10
- package/src/synchronizer/errors.ts +8 -0
- package/src/synchronizer/factory.ts +11 -10
- package/src/synchronizer/index.ts +1 -0
- package/src/synchronizer/server_world_state_synchronizer.ts +70 -39
- package/src/test/utils.ts +10 -1
- package/src/testing.ts +12 -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
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { GENESIS_BLOCK_HEADER_HASH, INITIAL_CHECKPOINT_NUMBER, INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
2
1
|
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
3
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
3
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
5
4
|
import { elapsed } from '@aztec/foundation/timer';
|
|
6
|
-
import {
|
|
5
|
+
import { EventDrivenL2BlockStream } from '@aztec/stdlib/block';
|
|
7
6
|
import { WorldStateRunningState } from '@aztec/stdlib/interfaces/server';
|
|
8
7
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
9
8
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
@@ -47,6 +46,39 @@ import { WorldStateSynchronizerError } from './errors.js';
|
|
|
47
46
|
getSnapshot(blockNumber) {
|
|
48
47
|
return this.merkleTreeDb.getSnapshot(blockNumber);
|
|
49
48
|
}
|
|
49
|
+
async getVerifiedSnapshot(blockNumber, blockHash) {
|
|
50
|
+
const snapshot = this.merkleTreeDb.getSnapshot(blockNumber);
|
|
51
|
+
// Block 0's snapshot is the pre-genesis archive view (size 0), so archive leaf 0 is not visible from it;
|
|
52
|
+
// verify against the initial header hash instead. For later blocks, read archive leaf `blockNumber` from the
|
|
53
|
+
// snapshot's own view so the exact handle we return is validated against the requested fork.
|
|
54
|
+
const actualHash = blockNumber === BlockNumber.ZERO ? (await this.merkleTreeCommitted.getInitialHeader().hash()).toString() : (await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber)))?.toString();
|
|
55
|
+
if (actualHash === undefined) {
|
|
56
|
+
// A missing archive leaf means either the block's history has been pruned away (permanent: the block predates
|
|
57
|
+
// the oldest historical block kept by world state) or a reorg flipped the fork between the sync and this read
|
|
58
|
+
// (transient). Only the latter is worth retrying, so it alone surfaces as WorldStateSynchronizerError.
|
|
59
|
+
const { oldestHistoricalBlock } = await this.merkleTreeDb.getStatusSummary();
|
|
60
|
+
if (blockNumber < oldestHistoricalBlock) {
|
|
61
|
+
throw new Error(`Unable to find leaf for block ${blockNumber} in the archive tree: world state history has been pruned to block ${oldestHistoricalBlock}`);
|
|
62
|
+
}
|
|
63
|
+
throw new WorldStateSynchronizerError(`Unable to read block hash at block ${blockNumber} to verify snapshot`, {
|
|
64
|
+
cause: {
|
|
65
|
+
reason: 'block_not_available',
|
|
66
|
+
targetBlockNumber: blockNumber
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
if (actualHash !== blockHash.toString()) {
|
|
71
|
+
throw new WorldStateSynchronizerError(`Block hash mismatch at block ${blockNumber} (expected ${blockHash} but got ${actualHash})`, {
|
|
72
|
+
cause: {
|
|
73
|
+
reason: 'block_hash_mismatch',
|
|
74
|
+
targetBlockNumber: blockNumber,
|
|
75
|
+
expectedHash: blockHash.toString(),
|
|
76
|
+
actualHash
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return snapshot;
|
|
81
|
+
}
|
|
50
82
|
fork(blockNumber, opts) {
|
|
51
83
|
return this.merkleTreeDb.fork(blockNumber, opts);
|
|
52
84
|
}
|
|
@@ -83,7 +115,7 @@ import { WorldStateSynchronizerError } from './errors.js';
|
|
|
83
115
|
}
|
|
84
116
|
createBlockStream() {
|
|
85
117
|
const logger = createLogger('world-state:block_stream');
|
|
86
|
-
return new
|
|
118
|
+
return new EventDrivenL2BlockStream(this.l2BlockSource, this, this, logger, {
|
|
87
119
|
pollIntervalMS: this.config.worldStateBlockCheckIntervalMS,
|
|
88
120
|
batchSize: this.config.worldStateBlockRequestBatchSize,
|
|
89
121
|
ignoreCheckpoints: true
|
|
@@ -198,7 +230,11 @@ import { WorldStateSynchronizerError } from './errors.js';
|
|
|
198
230
|
}
|
|
199
231
|
return this.merkleTreeCommitted.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(number)).then((leaf)=>leaf?.toString());
|
|
200
232
|
}
|
|
201
|
-
/**
|
|
233
|
+
/**
|
|
234
|
+
* Returns the proposed, proven, and finalized block tips of the chain. World state drives its block stream with
|
|
235
|
+
* `ignoreCheckpoints`, so it does not track checkpointed blocks or checkpoints and omits `checkpointed` from the tips
|
|
236
|
+
* it reports.
|
|
237
|
+
*/ async getL2Tips() {
|
|
202
238
|
const status = await this.merkleTreeDb.getStatusSummary();
|
|
203
239
|
const unfinalizedBlockHashPromise = this.getL2BlockHash(status.unfinalizedBlockNumber);
|
|
204
240
|
const finalizedBlockHashPromise = this.getL2BlockHash(status.finalizedBlockNumber);
|
|
@@ -209,54 +245,21 @@ import { WorldStateSynchronizerError } from './errors.js';
|
|
|
209
245
|
finalizedBlockHashPromise,
|
|
210
246
|
provenBlockHashPromise
|
|
211
247
|
]);
|
|
212
|
-
const latestBlockId = {
|
|
213
|
-
number: status.unfinalizedBlockNumber,
|
|
214
|
-
hash: unfinalizedBlockHash
|
|
215
|
-
};
|
|
216
|
-
// World state doesn't track checkpointed blocks or checkpoints themselves.
|
|
217
|
-
// but we use a block stream so we need to provide 'local' L2Tips.
|
|
218
|
-
// We configure the block stream to ignore checkpoints and set checkpoint values to genesis here.
|
|
219
|
-
const genesisCheckpointHeaderHash = GENESIS_CHECKPOINT_HEADER_HASH.toString();
|
|
220
248
|
return {
|
|
221
|
-
proposed:
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
number: INITIAL_L2_BLOCK_NUM,
|
|
225
|
-
hash: GENESIS_BLOCK_HEADER_HASH.toString()
|
|
226
|
-
},
|
|
227
|
-
checkpoint: {
|
|
228
|
-
number: INITIAL_CHECKPOINT_NUMBER,
|
|
229
|
-
hash: genesisCheckpointHeaderHash
|
|
230
|
-
}
|
|
231
|
-
},
|
|
232
|
-
proposedCheckpoint: {
|
|
233
|
-
block: {
|
|
234
|
-
number: INITIAL_L2_BLOCK_NUM,
|
|
235
|
-
hash: GENESIS_BLOCK_HEADER_HASH.toString()
|
|
236
|
-
},
|
|
237
|
-
checkpoint: {
|
|
238
|
-
number: INITIAL_CHECKPOINT_NUMBER,
|
|
239
|
-
hash: genesisCheckpointHeaderHash
|
|
240
|
-
}
|
|
249
|
+
proposed: {
|
|
250
|
+
number: status.unfinalizedBlockNumber,
|
|
251
|
+
hash: unfinalizedBlockHash
|
|
241
252
|
},
|
|
242
253
|
finalized: {
|
|
243
254
|
block: {
|
|
244
255
|
number: status.finalizedBlockNumber,
|
|
245
|
-
hash: finalizedBlockHash
|
|
246
|
-
},
|
|
247
|
-
checkpoint: {
|
|
248
|
-
number: INITIAL_CHECKPOINT_NUMBER,
|
|
249
|
-
hash: genesisCheckpointHeaderHash
|
|
256
|
+
hash: finalizedBlockHash
|
|
250
257
|
}
|
|
251
258
|
},
|
|
252
259
|
proven: {
|
|
253
260
|
block: {
|
|
254
261
|
number: provenBlockNumber,
|
|
255
|
-
hash: provenBlockHash
|
|
256
|
-
},
|
|
257
|
-
checkpoint: {
|
|
258
|
-
number: INITIAL_CHECKPOINT_NUMBER,
|
|
259
|
-
hash: genesisCheckpointHeaderHash
|
|
262
|
+
hash: provenBlockHash
|
|
260
263
|
}
|
|
261
264
|
}
|
|
262
265
|
};
|
|
@@ -275,6 +278,16 @@ import { WorldStateSynchronizerError } from './errors.js';
|
|
|
275
278
|
case 'chain-finalized':
|
|
276
279
|
await this.handleChainFinalized(event.block.number);
|
|
277
280
|
break;
|
|
281
|
+
// World state runs in block mode with ignoreCheckpoints: it tracks tips via blocks-added/pruned/proven/finalized
|
|
282
|
+
// and ignores the thin tip events (it never anchors on them).
|
|
283
|
+
case 'chain-proposed':
|
|
284
|
+
case 'chain-checkpointed':
|
|
285
|
+
break;
|
|
286
|
+
default:
|
|
287
|
+
{
|
|
288
|
+
const _ = event;
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
278
291
|
}
|
|
279
292
|
}
|
|
280
293
|
/**
|
|
@@ -343,24 +356,26 @@ import { WorldStateSynchronizerError } from './errors.js';
|
|
|
343
356
|
if (this.historyToKeep === undefined) {
|
|
344
357
|
return;
|
|
345
358
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
359
|
+
const finalisedBlockData = await this.l2BlockSource.getBlockData({
|
|
360
|
+
number: summary.finalizedBlockNumber
|
|
361
|
+
});
|
|
362
|
+
if (finalisedBlockData === undefined) {
|
|
349
363
|
this.log.warn(`Failed to retrieve checkpointed block for finalized block number: ${summary.finalizedBlockNumber}`);
|
|
350
364
|
return;
|
|
351
365
|
}
|
|
352
366
|
// Compute the required historic checkpoint number
|
|
353
|
-
const newHistoricCheckpointNumber =
|
|
367
|
+
const newHistoricCheckpointNumber = finalisedBlockData.checkpointNumber - this.historyToKeep + 1;
|
|
354
368
|
if (newHistoricCheckpointNumber <= 1) {
|
|
355
369
|
return;
|
|
356
370
|
}
|
|
357
371
|
// Retrieve the historic checkpoint
|
|
358
|
-
const
|
|
359
|
-
|
|
372
|
+
const historicCheckpoint = await this.l2BlockSource.getCheckpoint({
|
|
373
|
+
number: CheckpointNumber(newHistoricCheckpointNumber)
|
|
374
|
+
});
|
|
375
|
+
if (!historicCheckpoint) {
|
|
360
376
|
this.log.warn(`Failed to retrieve checkpoint number ${newHistoricCheckpointNumber} from Archiver`);
|
|
361
377
|
return;
|
|
362
378
|
}
|
|
363
|
-
const historicCheckpoint = historicCheckpoints[0];
|
|
364
379
|
if (historicCheckpoint.checkpoint.blocks.length === 0 || historicCheckpoint.checkpoint.blocks[0] === undefined) {
|
|
365
380
|
this.log.warn(`Retrieved checkpoint number ${newHistoricCheckpointNumber} has no blocks!`);
|
|
366
381
|
return;
|
package/dest/test/utils.d.ts
CHANGED
|
@@ -23,4 +23,4 @@ export declare function mockCheckpoint(checkpointNumber: CheckpointNumber, fork:
|
|
|
23
23
|
}>;
|
|
24
24
|
export declare function assertSameState(forkA: MerkleTreeReadOperations, forkB: MerkleTreeReadOperations): Promise<void>;
|
|
25
25
|
export declare function compareChains(left: MerkleTreeReadOperations, right: MerkleTreeReadOperations): Promise<void>;
|
|
26
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
26
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0L3V0aWxzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQU9BLE9BQU8sRUFBRSxXQUFXLEVBQUUsS0FBSyxnQkFBZ0IsRUFBeUIsTUFBTSxpQ0FBaUMsQ0FBQztBQUU1RyxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDcEQsT0FBTyxFQUFFLE9BQU8sRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBQzlDLE9BQU8sS0FBSyxFQUVWLHdCQUF3QixFQUN4Qix5QkFBeUIsRUFDMUIsTUFBTSxpQ0FBaUMsQ0FBQztBQUN6QyxPQUFPLEVBQUUseUJBQXlCLEVBQXNCLE1BQU0sdUJBQXVCLENBQUM7QUFJdEYsT0FBTyxLQUFLLEVBQUUsdUJBQXVCLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUUvRSx3QkFBc0IsZ0JBQWdCLENBQUMsS0FBSyxFQUFFLE9BQU8sRUFBRSxjQUFjLEVBQUUsRUFBRSxFQUFFLEVBQUUsSUFBSSxFQUFFLHlCQUF5QixpQkF1RDNHO0FBRUQsd0JBQXNCLFNBQVMsQ0FDN0IsUUFBUSxFQUFFLFdBQVcsRUFDckIsSUFBSSxFQUFFLE1BQU0sRUFDWixJQUFJLEVBQUUseUJBQXlCLEVBQy9CLFVBQVUsR0FBRSxNQUFNLEdBQUcsU0FBZ0IsRUFDckMsaUJBQWlCLEdBQUUsTUFBNEMsRUFDL0Qsd0JBQXdCLEdBQUUsT0FBYzs7O0dBZXpDO0FBRUQsd0JBQXNCLGNBQWMsQ0FBQyxRQUFRLEVBQUUsV0FBVyxFQUFFLElBQUksRUFBRSx5QkFBeUI7OztHQVkxRjtBQUVELHdCQUFzQixVQUFVLENBQzlCLElBQUksRUFBRSxXQUFXLEVBQ2pCLEtBQUssRUFBRSxNQUFNLEVBQ2IsTUFBTSxFQUFFLE1BQU0sRUFDZCxVQUFVLEVBQUUsdUJBQXVCOzs7R0FlcEM7QUFFRCx3QkFBc0IsY0FBYyxDQUNsQyxnQkFBZ0IsRUFBRSxnQkFBZ0IsRUFDbEMsSUFBSSxFQUFFLHlCQUF5QixFQUMvQixPQUFPLEdBQUUsT0FBTyxDQUFDLFVBQVUsQ0FBQyxPQUFPLHlCQUF5QixDQUFDLENBQUMsQ0FBQyxDQUFDLENBQU07OztHQU92RTtBQUVELHdCQUFzQixlQUFlLENBQUMsS0FBSyxFQUFFLHdCQUF3QixFQUFFLEtBQUssRUFBRSx3QkFBd0IsaUJBUXJHO0FBRUQsd0JBQXNCLGFBQWEsQ0FBQyxJQUFJLEVBQUUsd0JBQXdCLEVBQUUsS0FBSyxFQUFFLHdCQUF3QixpQkFZbEcifQ==
|
package/dest/test/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/test/utils.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAyB,MAAM,iCAAiC,CAAC;AAE5G,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,KAAK,EAEV,wBAAwB,EACxB,yBAAyB,EAC1B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,yBAAyB,EAAsB,MAAM,uBAAuB,CAAC;AAItF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE/E,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,yBAAyB,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/test/utils.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAyB,MAAM,iCAAiC,CAAC;AAE5G,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,KAAK,EAEV,wBAAwB,EACxB,yBAAyB,EAC1B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,yBAAyB,EAAsB,MAAM,uBAAuB,CAAC;AAItF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE/E,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,yBAAyB,iBAuD3G;AAED,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,WAAW,EACrB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,yBAAyB,EAC/B,UAAU,GAAE,MAAM,GAAG,SAAgB,EACrC,iBAAiB,GAAE,MAA4C,EAC/D,wBAAwB,GAAE,OAAc;;;GAezC;AAED,wBAAsB,cAAc,CAAC,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,yBAAyB;;;GAY1F;AAED,wBAAsB,UAAU,CAC9B,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,uBAAuB;;;GAepC;AAED,wBAAsB,cAAc,CAClC,gBAAgB,EAAE,gBAAgB,EAClC,IAAI,EAAE,yBAAyB,EAC/B,OAAO,GAAE,OAAO,CAAC,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC,CAAC,CAAC,CAAM;;;GAOvE;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,wBAAwB,EAAE,KAAK,EAAE,wBAAwB,iBAQrG;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE,wBAAwB,EAAE,KAAK,EAAE,wBAAwB,iBAYlG"}
|
package/dest/test/utils.js
CHANGED
|
@@ -26,9 +26,14 @@ export async function updateBlockState(block, l1ToL2Messages, fork) {
|
|
|
26
26
|
messageInsert
|
|
27
27
|
]);
|
|
28
28
|
const state = await fork.getStateReference();
|
|
29
|
+
// Capture the archive root *before* appending this block so the header's lastArchive chains off the previous block.
|
|
30
|
+
// sync_block now verifies lastArchive against the committed archive root, so a block carrying an unchained value
|
|
31
|
+
// (e.g. the random lastArchive from L2Block.random) would be rejected as a divergence from the canonical chain.
|
|
32
|
+
const previousArchive = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
29
33
|
block.header = BlockHeader.from({
|
|
30
34
|
...block.header,
|
|
31
|
-
state
|
|
35
|
+
state,
|
|
36
|
+
lastArchive: new AppendOnlyTreeSnapshot(Fr.fromBuffer(previousArchive.root), Number(previousArchive.size))
|
|
32
37
|
});
|
|
33
38
|
await fork.updateArchive(block.header);
|
|
34
39
|
const archiveState = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
package/dest/testing.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
3
|
import { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
4
|
+
import type { GenesisData } from '@aztec/stdlib/world-state';
|
|
4
5
|
export declare const defaultInitialAccountFeeJuice: Fr;
|
|
5
|
-
export declare function getGenesisValues(initialAccounts: AztecAddress[], initialAccountFeeJuice?: Fr, genesisPublicData?: PublicDataTreeLeaf[]): Promise<{
|
|
6
|
+
export declare function getGenesisValues(initialAccounts: AztecAddress[], initialAccountFeeJuice?: Fr, genesisPublicData?: PublicDataTreeLeaf[], genesisTimestamp?: bigint): Promise<{
|
|
6
7
|
genesisArchiveRoot: Fr;
|
|
7
|
-
|
|
8
|
+
genesis: GenesisData;
|
|
8
9
|
fundingNeeded: bigint;
|
|
9
10
|
}>;
|
|
10
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
11
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdGluZy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3Rlc3RpbmcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBRXBELE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQ2hFLE9BQU8sRUFBZ0Isa0JBQWtCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUN2RSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSwyQkFBMkIsQ0FBQztBQXdCN0QsZUFBTyxNQUFNLDZCQUE2QixJQUFxQixDQUFDO0FBRWhFLHdCQUFzQixnQkFBZ0IsQ0FDcEMsZUFBZSxFQUFFLFlBQVksRUFBRSxFQUMvQixzQkFBc0IsS0FBZ0MsRUFDdEQsaUJBQWlCLEdBQUUsa0JBQWtCLEVBQU8sRUFDNUMsZ0JBQWdCLEdBQUUsTUFBVzs7OztHQXNCOUIifQ==
|
package/dest/testing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAgB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAgB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAwB7D,eAAO,MAAM,6BAA6B,IAAqB,CAAC;AAEhE,wBAAsB,gBAAgB,CACpC,eAAe,EAAE,YAAY,EAAE,EAC/B,sBAAsB,KAAgC,EACtD,iBAAiB,GAAE,kBAAkB,EAAO,EAC5C,gBAAgB,GAAE,MAAW;;;;GAsB9B"}
|
package/dest/testing.js
CHANGED
|
@@ -3,14 +3,17 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
3
3
|
import { computeFeePayerBalanceLeafSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
4
4
|
import { MerkleTreeId, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
5
5
|
import { NativeWorldStateService } from './native/index.js';
|
|
6
|
-
async function generateGenesisValues(
|
|
7
|
-
if (!prefilledPublicData.length) {
|
|
6
|
+
async function generateGenesisValues(genesis) {
|
|
7
|
+
if (!genesis.prefilledPublicData.length && genesis.genesisTimestamp === 0n) {
|
|
8
8
|
return {
|
|
9
9
|
genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT)
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
|
-
//
|
|
13
|
-
|
|
12
|
+
// Compute the genesis values on a throwaway world state. The archive root derives only from the
|
|
13
|
+
// prefilled public data and the genesis timestamp, so the fsync-off ephemeral store (no version
|
|
14
|
+
// manager, no crash-recoverability) produces an identical root while skipping the fsync overhead
|
|
15
|
+
// that `tmp` pays. close() removes the tmpdir.
|
|
16
|
+
const ws = await NativeWorldStateService.ephemeral(genesis);
|
|
14
17
|
const genesisArchiveRoot = new Fr((await ws.getCommitted().getTreeInfo(MerkleTreeId.ARCHIVE)).root);
|
|
15
18
|
await ws.close();
|
|
16
19
|
return {
|
|
@@ -18,16 +21,20 @@ async function generateGenesisValues(prefilledPublicData) {
|
|
|
18
21
|
};
|
|
19
22
|
}
|
|
20
23
|
export const defaultInitialAccountFeeJuice = new Fr(10n ** 22n);
|
|
21
|
-
export async function getGenesisValues(initialAccounts, initialAccountFeeJuice = defaultInitialAccountFeeJuice, genesisPublicData = []) {
|
|
24
|
+
export async function getGenesisValues(initialAccounts, initialAccountFeeJuice = defaultInitialAccountFeeJuice, genesisPublicData = [], genesisTimestamp = 0n) {
|
|
22
25
|
// Top up the accounts with fee juice.
|
|
23
26
|
let prefilledPublicData = await Promise.all(initialAccounts.map(async (address)=>new PublicDataTreeLeaf(await computeFeePayerBalanceLeafSlot(address), initialAccountFeeJuice)));
|
|
24
27
|
// Add user-defined public data
|
|
25
28
|
prefilledPublicData = prefilledPublicData.concat(genesisPublicData);
|
|
26
29
|
prefilledPublicData.sort((a, b)=>b.slot.lt(a.slot) ? 1 : -1);
|
|
27
|
-
const
|
|
30
|
+
const genesis = {
|
|
31
|
+
prefilledPublicData,
|
|
32
|
+
genesisTimestamp
|
|
33
|
+
};
|
|
34
|
+
const { genesisArchiveRoot } = await generateGenesisValues(genesis);
|
|
28
35
|
return {
|
|
29
36
|
genesisArchiveRoot,
|
|
30
|
-
|
|
37
|
+
genesis,
|
|
31
38
|
fundingNeeded: BigInt(initialAccounts.length) * initialAccountFeeJuice.toBigInt()
|
|
32
39
|
};
|
|
33
40
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/world-state",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.4d9804df",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -64,18 +64,21 @@
|
|
|
64
64
|
]
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@aztec/
|
|
68
|
-
"@aztec/
|
|
69
|
-
"@aztec/
|
|
70
|
-
"@aztec/
|
|
71
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
72
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
73
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
67
|
+
"@aztec/bb.js": "0.0.1-commit.4d9804df",
|
|
68
|
+
"@aztec/constants": "0.0.1-commit.4d9804df",
|
|
69
|
+
"@aztec/foundation": "0.0.1-commit.4d9804df",
|
|
70
|
+
"@aztec/kv-store": "0.0.1-commit.4d9804df",
|
|
71
|
+
"@aztec/protocol-contracts": "0.0.1-commit.4d9804df",
|
|
72
|
+
"@aztec/stdlib": "0.0.1-commit.4d9804df",
|
|
73
|
+
"@aztec/telemetry-client": "0.0.1-commit.4d9804df",
|
|
74
|
+
"@aztec/wsdb": "0.0.1-commit.4d9804df",
|
|
75
|
+
"msgpackr": "^1.11.2",
|
|
74
76
|
"tslib": "^2.4.0",
|
|
75
|
-
"zod": "^
|
|
77
|
+
"zod": "^4"
|
|
76
78
|
},
|
|
77
79
|
"devDependencies": {
|
|
78
|
-
"@aztec/archiver": "0.0.1-commit.
|
|
80
|
+
"@aztec/archiver": "0.0.1-commit.4d9804df",
|
|
81
|
+
"@aztec/ipc-runtime": "0.0.1-commit.4d9804df",
|
|
79
82
|
"@jest/globals": "^30.0.0",
|
|
80
83
|
"@types/jest": "^30.0.0",
|
|
81
84
|
"@types/node": "^22.15.17",
|
package/src/index.ts
CHANGED
|
@@ -10,24 +10,12 @@ import {
|
|
|
10
10
|
createUpDownCounterWithDefault,
|
|
11
11
|
} from '@aztec/telemetry-client';
|
|
12
12
|
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
type TreeDBStats,
|
|
16
|
-
type TreeMeta,
|
|
17
|
-
WorldStateMessageType,
|
|
18
|
-
type WorldStateStatusFull,
|
|
19
|
-
} from '../native/message.js';
|
|
13
|
+
import type { DBStats, TreeDBStats, TreeMeta, WorldStateStatusFull } from '../native/message.js';
|
|
14
|
+
import type { WorldStateOperationName } from '../native/world_state_operation.js';
|
|
20
15
|
|
|
21
16
|
type DBTypeString = 'leaf_preimage' | 'leaf_indices' | 'nodes' | 'blocks' | 'block_indices';
|
|
22
17
|
|
|
23
|
-
const durationTrackDenylist = new Set<
|
|
24
|
-
WorldStateMessageType.GET_INITIAL_STATE_REFERENCE,
|
|
25
|
-
WorldStateMessageType.CLOSE,
|
|
26
|
-
|
|
27
|
-
// these aren't used anymore, should be removed from the API
|
|
28
|
-
WorldStateMessageType.COMMIT,
|
|
29
|
-
WorldStateMessageType.ROLLBACK,
|
|
30
|
-
]);
|
|
18
|
+
const durationTrackDenylist = new Set<WorldStateOperationName>(['getInitialStateReference']);
|
|
31
19
|
|
|
32
20
|
export class WorldStateInstrumentation {
|
|
33
21
|
private dbMapSize: Gauge;
|
|
@@ -144,10 +132,10 @@ export class WorldStateInstrumentation {
|
|
|
144
132
|
);
|
|
145
133
|
}
|
|
146
134
|
|
|
147
|
-
public recordRoundTrip(timeUs: number,
|
|
148
|
-
if (!durationTrackDenylist.has(
|
|
135
|
+
public recordRoundTrip(timeUs: number, operation: WorldStateOperationName) {
|
|
136
|
+
if (!durationTrackDenylist.has(operation)) {
|
|
149
137
|
this.requestHistogram.record(Math.ceil(timeUs), {
|
|
150
|
-
[Attributes.WORLD_STATE_REQUEST_TYPE]:
|
|
138
|
+
[Attributes.WORLD_STATE_REQUEST_TYPE]: operation,
|
|
151
139
|
});
|
|
152
140
|
}
|
|
153
141
|
}
|
package/src/native/index.ts
CHANGED