@aztec/world-state 0.0.1-commit.b655e406 → 0.0.1-commit.b6e433891

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.
Files changed (59) hide show
  1. package/dest/index.d.ts +1 -1
  2. package/dest/instrumentation/instrumentation.d.ts +1 -1
  3. package/dest/instrumentation/instrumentation.d.ts.map +1 -1
  4. package/dest/instrumentation/instrumentation.js +17 -41
  5. package/dest/native/bench_metrics.d.ts +1 -1
  6. package/dest/native/bench_metrics.d.ts.map +1 -1
  7. package/dest/native/fork_checkpoint.d.ts +7 -1
  8. package/dest/native/fork_checkpoint.d.ts.map +1 -1
  9. package/dest/native/fork_checkpoint.js +15 -3
  10. package/dest/native/index.d.ts +1 -1
  11. package/dest/native/merkle_trees_facade.d.ts +15 -9
  12. package/dest/native/merkle_trees_facade.d.ts.map +1 -1
  13. package/dest/native/merkle_trees_facade.js +47 -13
  14. package/dest/native/message.d.ts +25 -15
  15. package/dest/native/message.d.ts.map +1 -1
  16. package/dest/native/message.js +14 -13
  17. package/dest/native/native_world_state.d.ts +15 -12
  18. package/dest/native/native_world_state.d.ts.map +1 -1
  19. package/dest/native/native_world_state.js +23 -18
  20. package/dest/native/native_world_state_instance.d.ts +12 -3
  21. package/dest/native/native_world_state_instance.d.ts.map +1 -1
  22. package/dest/native/native_world_state_instance.js +25 -4
  23. package/dest/native/world_state_ops_queue.d.ts +1 -1
  24. package/dest/native/world_state_ops_queue.d.ts.map +1 -1
  25. package/dest/synchronizer/config.d.ts +3 -5
  26. package/dest/synchronizer/config.d.ts.map +1 -1
  27. package/dest/synchronizer/config.js +7 -9
  28. package/dest/synchronizer/errors.d.ts +1 -1
  29. package/dest/synchronizer/errors.d.ts.map +1 -1
  30. package/dest/synchronizer/factory.d.ts +5 -4
  31. package/dest/synchronizer/factory.d.ts.map +1 -1
  32. package/dest/synchronizer/factory.js +5 -5
  33. package/dest/synchronizer/index.d.ts +1 -1
  34. package/dest/synchronizer/server_world_state_synchronizer.d.ts +11 -28
  35. package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
  36. package/dest/synchronizer/server_world_state_synchronizer.js +149 -80
  37. package/dest/test/index.d.ts +1 -1
  38. package/dest/test/utils.d.ts +12 -5
  39. package/dest/test/utils.d.ts.map +1 -1
  40. package/dest/test/utils.js +54 -50
  41. package/dest/testing.d.ts +2 -2
  42. package/dest/testing.d.ts.map +1 -1
  43. package/dest/testing.js +1 -1
  44. package/dest/world-state-db/index.d.ts +1 -1
  45. package/dest/world-state-db/merkle_tree_db.d.ts +9 -19
  46. package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
  47. package/package.json +12 -12
  48. package/src/instrumentation/instrumentation.ts +17 -41
  49. package/src/native/fork_checkpoint.ts +19 -3
  50. package/src/native/merkle_trees_facade.ts +55 -14
  51. package/src/native/message.ts +38 -26
  52. package/src/native/native_world_state.ts +52 -28
  53. package/src/native/native_world_state_instance.ts +34 -4
  54. package/src/synchronizer/config.ts +8 -19
  55. package/src/synchronizer/factory.ts +8 -2
  56. package/src/synchronizer/server_world_state_synchronizer.ts +176 -105
  57. package/src/test/utils.ts +87 -92
  58. package/src/testing.ts +1 -1
  59. package/src/world-state-db/merkle_tree_db.ts +12 -19
@@ -1,12 +1,12 @@
1
- import { L1_TO_L2_MSG_SUBTREE_HEIGHT } from '@aztec/constants';
2
- import { SHA256Trunc } from '@aztec/foundation/crypto';
1
+ import { GENESIS_BLOCK_HEADER_HASH, INITIAL_CHECKPOINT_NUMBER, INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
2
+ import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
4
  import { promiseWithResolvers } from '@aztec/foundation/promise';
5
5
  import { elapsed } from '@aztec/foundation/timer';
6
- import { MerkleTreeCalculator } from '@aztec/foundation/trees';
6
+ import { GENESIS_CHECKPOINT_HEADER_HASH, L2BlockStream } from '@aztec/stdlib/block';
7
7
  import { WorldStateRunningState } from '@aztec/stdlib/interfaces/server';
8
8
  import { MerkleTreeId } from '@aztec/stdlib/trees';
9
- import { TraceableL2BlockStream, getTelemetryClient } from '@aztec/telemetry-client';
9
+ import { getTelemetryClient } from '@aztec/telemetry-client';
10
10
  import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
11
11
  import { WorldStateSynchronizerError } from './errors.js';
12
12
  /**
@@ -23,7 +23,6 @@ import { WorldStateSynchronizerError } from './errors.js';
23
23
  latestBlockNumberAtStart;
24
24
  historyToKeep;
25
25
  currentState;
26
- latestBlockHashQuery;
27
26
  syncPromise;
28
27
  blockStream;
29
28
  // WorldState doesn't track the proven block number, it only tracks the latest tips of the pending chain and the finalized chain
@@ -35,12 +34,11 @@ import { WorldStateSynchronizerError } from './errors.js';
35
34
  this.config = config;
36
35
  this.instrumentation = instrumentation;
37
36
  this.log = log;
38
- this.latestBlockNumberAtStart = 0;
37
+ this.latestBlockNumberAtStart = BlockNumber.ZERO;
39
38
  this.currentState = WorldStateRunningState.IDLE;
40
- this.latestBlockHashQuery = undefined;
41
39
  this.syncPromise = promiseWithResolvers();
42
40
  this.merkleTreeCommitted = this.merkleTreeDb.getCommitted();
43
- this.historyToKeep = config.worldStateBlockHistory < 1 ? undefined : config.worldStateBlockHistory;
41
+ this.historyToKeep = config.worldStateCheckpointHistory < 1 ? undefined : config.worldStateCheckpointHistory;
44
42
  this.log.info(`Created world state synchroniser with block history of ${this.historyToKeep === undefined ? 'infinity' : this.historyToKeep}`);
45
43
  }
46
44
  getCommitted() {
@@ -49,8 +47,8 @@ import { WorldStateSynchronizerError } from './errors.js';
49
47
  getSnapshot(blockNumber) {
50
48
  return this.merkleTreeDb.getSnapshot(blockNumber);
51
49
  }
52
- fork(blockNumber) {
53
- return this.merkleTreeDb.fork(blockNumber);
50
+ fork(blockNumber, opts) {
51
+ return this.merkleTreeDb.fork(blockNumber, opts);
54
52
  }
55
53
  backupTo(dstPath, compact) {
56
54
  return this.merkleTreeDb.backupTo(dstPath, compact);
@@ -66,7 +64,7 @@ import { WorldStateSynchronizerError } from './errors.js';
66
64
  return this.syncPromise;
67
65
  }
68
66
  // Get the current latest block number
69
- this.latestBlockNumberAtStart = await (this.config.worldStateProvenBlocksOnly ? this.l2BlockSource.getProvenBlockNumber() : this.l2BlockSource.getBlockNumber());
67
+ this.latestBlockNumberAtStart = BlockNumber(await this.l2BlockSource.getBlockNumber());
70
68
  const blockToDownloadFrom = await this.getLatestBlockNumber() + 1;
71
69
  if (blockToDownloadFrom <= this.latestBlockNumberAtStart) {
72
70
  // If there are blocks to be retrieved, go to a synching state
@@ -84,12 +82,11 @@ import { WorldStateSynchronizerError } from './errors.js';
84
82
  return this.syncPromise.promise;
85
83
  }
86
84
  createBlockStream() {
87
- const tracer = this.instrumentation.telemetry.getTracer('WorldStateL2BlockStream');
88
85
  const logger = createLogger('world-state:block_stream');
89
- return new TraceableL2BlockStream(this.l2BlockSource, this, this, tracer, 'WorldStateL2BlockStream', logger, {
90
- proven: this.config.worldStateProvenBlocksOnly,
86
+ return new L2BlockStream(this.l2BlockSource, this, this, logger, {
91
87
  pollIntervalMS: this.config.worldStateBlockCheckIntervalMS,
92
- batchSize: this.config.worldStateBlockRequestBatchSize
88
+ batchSize: this.config.worldStateBlockRequestBatchSize,
89
+ ignoreCheckpoints: true
93
90
  });
94
91
  }
95
92
  async stop() {
@@ -103,10 +100,10 @@ import { WorldStateSynchronizerError } from './errors.js';
103
100
  async status() {
104
101
  const summary = await this.merkleTreeDb.getStatusSummary();
105
102
  const status = {
106
- latestBlockNumber: Number(summary.unfinalizedBlockNumber),
107
- latestBlockHash: await this.getL2BlockHash(Number(summary.unfinalizedBlockNumber)) ?? '',
108
- finalizedBlockNumber: Number(summary.finalizedBlockNumber),
109
- oldestHistoricBlockNumber: Number(summary.oldestHistoricalBlock),
103
+ latestBlockNumber: summary.unfinalizedBlockNumber,
104
+ latestBlockHash: await this.getL2BlockHash(summary.unfinalizedBlockNumber) ?? '',
105
+ finalizedBlockNumber: summary.finalizedBlockNumber,
106
+ oldestHistoricBlockNumber: summary.oldestHistoricalBlock,
110
107
  treesAreSynched: summary.treesAreSynched
111
108
  };
112
109
  return {
@@ -115,7 +112,7 @@ import { WorldStateSynchronizerError } from './errors.js';
115
112
  };
116
113
  }
117
114
  async getLatestBlockNumber() {
118
- return (await this.getL2Tips()).latest.number;
115
+ return (await this.getL2Tips()).proposed.number;
119
116
  }
120
117
  async stopSync() {
121
118
  this.log.debug('Stopping sync...');
@@ -133,9 +130,9 @@ import { WorldStateSynchronizerError } from './errors.js';
133
130
  /**
134
131
  * Forces an immediate sync.
135
132
  * @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it.
136
- * @param skipThrowIfTargetNotReached - Whether to skip throwing if the target block number is not reached.
133
+ * @param blockHash - If provided, verifies the block at targetBlockNumber matches this hash. On mismatch, triggers a resync (reorg detection).
137
134
  * @returns A promise that resolves with the block number the world state was synced to
138
- */ async syncImmediate(targetBlockNumber, skipThrowIfTargetNotReached) {
135
+ */ async syncImmediate(targetBlockNumber, blockHash) {
139
136
  if (this.currentState !== WorldStateRunningState.RUNNING) {
140
137
  throw new Error(`World State is not running. Unable to perform sync.`);
141
138
  }
@@ -145,12 +142,21 @@ import { WorldStateSynchronizerError } from './errors.js';
145
142
  // If we have been given a block number to sync to and we have reached that number then return
146
143
  const currentBlockNumber = await this.getLatestBlockNumber();
147
144
  if (targetBlockNumber !== undefined && targetBlockNumber <= currentBlockNumber) {
148
- return currentBlockNumber;
145
+ if (blockHash === undefined) {
146
+ return currentBlockNumber;
147
+ }
148
+ // If a block hash was provided, verify we're on the expected fork
149
+ const currentHash = await this.getL2BlockHash(targetBlockNumber);
150
+ if (currentHash === blockHash.toString()) {
151
+ return currentBlockNumber;
152
+ }
153
+ // Hash mismatch: a reorg may have occurred, fall through to trigger sync
154
+ this.log.debug(`World state block hash mismatch at ${targetBlockNumber} (expected ${blockHash}, got ${currentHash}). Triggering resync.`);
149
155
  }
150
156
  this.log.debug(`World State at ${currentBlockNumber} told to sync to ${targetBlockNumber ?? 'latest'}`);
151
157
  // If the archiver is behind the target block, force an archiver sync
152
158
  if (targetBlockNumber) {
153
- const archiverLatestBlock = await this.l2BlockSource.getBlockNumber();
159
+ const archiverLatestBlock = BlockNumber(await this.l2BlockSource.getBlockNumber());
154
160
  if (archiverLatestBlock < targetBlockNumber) {
155
161
  this.log.debug(`Archiver is at ${archiverLatestBlock} behind target block ${targetBlockNumber}.`);
156
162
  await this.l2BlockSource.syncImmediate();
@@ -160,7 +166,7 @@ import { WorldStateSynchronizerError } from './errors.js';
160
166
  await this.blockStream.sync();
161
167
  // If we have been given a block number to sync to and we have not reached that number then fail
162
168
  const updatedBlockNumber = await this.getLatestBlockNumber();
163
- if (!skipThrowIfTargetNotReached && targetBlockNumber !== undefined && targetBlockNumber > updatedBlockNumber) {
169
+ if (targetBlockNumber !== undefined && targetBlockNumber > updatedBlockNumber) {
164
170
  throw new WorldStateSynchronizerError(`Unable to sync to block number ${targetBlockNumber} (last synced is ${updatedBlockNumber})`, {
165
171
  cause: {
166
172
  reason: 'block_not_available',
@@ -170,43 +176,85 @@ import { WorldStateSynchronizerError } from './errors.js';
170
176
  }
171
177
  });
172
178
  }
179
+ // If a block hash was provided, verify we're on the expected fork after syncing, throw otherwise
180
+ if (blockHash !== undefined && targetBlockNumber !== undefined) {
181
+ const updatedHash = await this.getL2BlockHash(targetBlockNumber);
182
+ if (updatedHash !== blockHash.toString()) {
183
+ throw new WorldStateSynchronizerError(`Block hash mismatch at block ${targetBlockNumber} (expected ${blockHash} but got ${updatedHash})`, {
184
+ cause: {
185
+ reason: 'block_hash_mismatch',
186
+ targetBlockNumber,
187
+ expectedHash: blockHash.toString(),
188
+ actualHash: updatedHash
189
+ }
190
+ });
191
+ }
192
+ }
173
193
  return updatedBlockNumber;
174
194
  }
175
195
  /** Returns the L2 block hash for a given number. Used by the L2BlockStream for detecting reorgs. */ async getL2BlockHash(number) {
176
- if (number === 0) {
196
+ if (number === BlockNumber.ZERO) {
177
197
  return (await this.merkleTreeCommitted.getInitialHeader().hash()).toString();
178
198
  }
179
- if (this.latestBlockHashQuery?.hash === undefined || number !== this.latestBlockHashQuery.blockNumber) {
180
- this.latestBlockHashQuery = {
181
- hash: await this.merkleTreeCommitted.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(number)).then((leaf)=>leaf?.toString()),
182
- blockNumber: number
183
- };
184
- }
185
- return this.latestBlockHashQuery.hash;
199
+ return this.merkleTreeCommitted.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(number)).then((leaf)=>leaf?.toString());
186
200
  }
187
201
  /** Returns the latest L2 block number for each tip of the chain (latest, proven, finalized). */ async getL2Tips() {
188
202
  const status = await this.merkleTreeDb.getStatusSummary();
189
- const unfinalizedBlockHash = await this.getL2BlockHash(Number(status.unfinalizedBlockNumber));
203
+ const unfinalizedBlockHashPromise = this.getL2BlockHash(status.unfinalizedBlockNumber);
204
+ const finalizedBlockHashPromise = this.getL2BlockHash(status.finalizedBlockNumber);
205
+ const provenBlockNumber = this.provenBlockNumber ?? status.finalizedBlockNumber;
206
+ const provenBlockHashPromise = this.provenBlockNumber === undefined ? finalizedBlockHashPromise : this.getL2BlockHash(this.provenBlockNumber);
207
+ const [unfinalizedBlockHash, finalizedBlockHash, provenBlockHash] = await Promise.all([
208
+ unfinalizedBlockHashPromise,
209
+ finalizedBlockHashPromise,
210
+ provenBlockHashPromise
211
+ ]);
190
212
  const latestBlockId = {
191
- number: Number(status.unfinalizedBlockNumber),
213
+ number: status.unfinalizedBlockNumber,
192
214
  hash: unfinalizedBlockHash
193
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();
194
220
  return {
195
- latest: latestBlockId,
221
+ proposed: latestBlockId,
222
+ checkpointed: {
223
+ block: {
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
+ },
196
232
  finalized: {
197
- number: Number(status.finalizedBlockNumber),
198
- hash: ''
233
+ block: {
234
+ number: status.finalizedBlockNumber,
235
+ hash: finalizedBlockHash ?? ''
236
+ },
237
+ checkpoint: {
238
+ number: INITIAL_CHECKPOINT_NUMBER,
239
+ hash: genesisCheckpointHeaderHash
240
+ }
199
241
  },
200
242
  proven: {
201
- number: Number(this.provenBlockNumber ?? status.finalizedBlockNumber),
202
- hash: ''
243
+ block: {
244
+ number: provenBlockNumber,
245
+ hash: provenBlockHash ?? ''
246
+ },
247
+ checkpoint: {
248
+ number: INITIAL_CHECKPOINT_NUMBER,
249
+ hash: genesisCheckpointHeaderHash
250
+ }
203
251
  }
204
252
  };
205
253
  }
206
254
  /** Handles an event emitted by the block stream. */ async handleBlockStreamEvent(event) {
207
255
  switch(event.type){
208
256
  case 'blocks-added':
209
- await this.handleL2Blocks(event.blocks.map((b)=>b.block));
257
+ await this.handleL2Blocks(event.blocks);
210
258
  break;
211
259
  case 'chain-pruned':
212
260
  await this.handleChainPruned(event.block.number);
@@ -224,19 +272,23 @@ import { WorldStateSynchronizerError } from './errors.js';
224
272
  * @param l2Blocks - The L2 blocks to handle.
225
273
  * @returns Whether the block handled was produced by this same node.
226
274
  */ async handleL2Blocks(l2Blocks) {
227
- this.log.trace(`Handling L2 blocks ${l2Blocks[0].number} to ${l2Blocks.at(-1).number}`);
228
- const messagePromises = l2Blocks.map((block)=>this.l2BlockSource.getL1ToL2Messages(block.number));
229
- const l1ToL2Messages = await Promise.all(messagePromises);
275
+ this.log.debug(`Handling L2 blocks ${l2Blocks[0].number} to ${l2Blocks.at(-1).number}`);
276
+ // Fetch the L1->L2 messages for the first block in a checkpoint.
277
+ const messagesForBlocks = new Map();
278
+ await Promise.all(l2Blocks.filter((b)=>b.indexWithinCheckpoint === 0).map(async (block)=>{
279
+ const l1ToL2Messages = await this.l2BlockSource.getL1ToL2Messages(block.checkpointNumber);
280
+ messagesForBlocks.set(block.number, l1ToL2Messages);
281
+ }));
230
282
  let updateStatus = undefined;
231
- for(let i = 0; i < l2Blocks.length; i++){
232
- const [duration, result] = await elapsed(()=>this.handleL2Block(l2Blocks[i], l1ToL2Messages[i]));
233
- this.log.info(`World state updated with L2 block ${l2Blocks[i].number}`, {
283
+ for (const block of l2Blocks){
284
+ const [duration, result] = await elapsed(()=>this.handleL2Block(block, messagesForBlocks.get(block.number) ?? []));
285
+ this.log.info(`World state updated with L2 block ${block.number}`, {
234
286
  eventName: 'l2-block-handled',
235
287
  duration,
236
- unfinalizedBlockNumber: result.summary.unfinalizedBlockNumber,
237
- finalizedBlockNumber: result.summary.finalizedBlockNumber,
238
- oldestHistoricBlock: result.summary.oldestHistoricalBlock,
239
- ...l2Blocks[i].getStats()
288
+ unfinalizedBlockNumber: BigInt(result.summary.unfinalizedBlockNumber),
289
+ finalizedBlockNumber: BigInt(result.summary.finalizedBlockNumber),
290
+ oldestHistoricBlock: BigInt(result.summary.oldestHistoricalBlock),
291
+ ...block.getStats()
240
292
  });
241
293
  updateStatus = result;
242
294
  }
@@ -251,16 +303,12 @@ import { WorldStateSynchronizerError } from './errors.js';
251
303
  * @param l1ToL2Messages - The L1 to L2 messages for the block.
252
304
  * @returns Whether the block handled was produced by this same node.
253
305
  */ async handleL2Block(l2Block, l1ToL2Messages) {
254
- // First we check that the L1 to L2 messages hash to the block inHash.
255
- // Note that we cannot optimize this check by checking the root of the subtree after inserting the messages
256
- // to the real L1_TO_L2_MESSAGE_TREE (like we do in merkleTreeDb.handleL2BlockAndMessages(...)) because that
257
- // tree uses pedersen and we don't have access to the converted root.
258
- await this.verifyMessagesHashToInHash(l1ToL2Messages, l2Block.header.contentCommitment.inHash);
259
- // If the above check succeeds, we can proceed to handle the block.
260
- this.log.trace(`Pushing L2 block ${l2Block.number} to merkle tree db `, {
306
+ this.log.debug(`Pushing L2 block ${l2Block.number} to merkle tree db `, {
261
307
  blockNumber: l2Block.number,
262
308
  blockHash: await l2Block.hash().then((h)=>h.toString()),
263
- l1ToL2Messages: l1ToL2Messages.map((msg)=>msg.toString())
309
+ l1ToL2Messages: l1ToL2Messages.map((msg)=>msg.toString()),
310
+ blockHeader: l2Block.header.toInspect(),
311
+ blockStats: l2Block.getStats()
264
312
  });
265
313
  const result = await this.merkleTreeDb.handleL2BlockAndMessages(l2Block, l1ToL2Messages);
266
314
  if (this.currentState === WorldStateRunningState.SYNCHING && l2Block.number >= this.latestBlockNumberAtStart) {
@@ -271,27 +319,60 @@ import { WorldStateSynchronizerError } from './errors.js';
271
319
  }
272
320
  async handleChainFinalized(blockNumber) {
273
321
  this.log.verbose(`Finalized chain is now at block ${blockNumber}`);
274
- const summary = await this.merkleTreeDb.setFinalized(BigInt(blockNumber));
322
+ // If the finalized block number is older than the oldest available block in world state,
323
+ // skip entirely. The finalized block number can jump backwards (e.g. when the finalization
324
+ // heuristic changes) and try to read block data that has already been pruned. When this
325
+ // happens, there is nothing useful to do — the native world state is already finalized
326
+ // past this point and pruning has already happened.
327
+ const currentSummary = await this.merkleTreeDb.getStatusSummary();
328
+ if (blockNumber < currentSummary.oldestHistoricalBlock || blockNumber < 1) {
329
+ this.log.trace(`Finalized block ${blockNumber} is older than the oldest available block ${currentSummary.oldestHistoricalBlock}. Skipping.`);
330
+ return;
331
+ }
332
+ const summary = await this.merkleTreeDb.setFinalized(blockNumber);
275
333
  if (this.historyToKeep === undefined) {
276
334
  return;
277
335
  }
278
- const newHistoricBlock = summary.finalizedBlockNumber - BigInt(this.historyToKeep) + 1n;
279
- if (newHistoricBlock <= 1) {
336
+ // Get the checkpointed block for the finalized block number
337
+ const finalisedCheckpoint = await this.l2BlockSource.getCheckpointedBlock(summary.finalizedBlockNumber);
338
+ if (finalisedCheckpoint === undefined) {
339
+ this.log.warn(`Failed to retrieve checkpointed block for finalized block number: ${summary.finalizedBlockNumber}`);
280
340
  return;
281
341
  }
282
- this.log.verbose(`Pruning historic blocks to ${newHistoricBlock}`);
283
- const status = await this.merkleTreeDb.removeHistoricalBlocks(newHistoricBlock);
342
+ // Compute the required historic checkpoint number
343
+ const newHistoricCheckpointNumber = finalisedCheckpoint.checkpointNumber - this.historyToKeep + 1;
344
+ if (newHistoricCheckpointNumber <= 1) {
345
+ return;
346
+ }
347
+ // Retrieve the historic checkpoint
348
+ const historicCheckpoints = await this.l2BlockSource.getCheckpoints(CheckpointNumber(newHistoricCheckpointNumber), 1);
349
+ if (historicCheckpoints.length === 0 || historicCheckpoints[0] === undefined) {
350
+ this.log.warn(`Failed to retrieve checkpoint number ${newHistoricCheckpointNumber} from Archiver`);
351
+ return;
352
+ }
353
+ const historicCheckpoint = historicCheckpoints[0];
354
+ if (historicCheckpoint.checkpoint.blocks.length === 0 || historicCheckpoint.checkpoint.blocks[0] === undefined) {
355
+ this.log.warn(`Retrieved checkpoint number ${newHistoricCheckpointNumber} has no blocks!`);
356
+ return;
357
+ }
358
+ // Find the block at the start of the checkpoint and remove blocks up to this one
359
+ const newHistoricBlock = historicCheckpoint.checkpoint.blocks[0];
360
+ if (newHistoricBlock.number <= currentSummary.oldestHistoricalBlock) {
361
+ this.log.debug(`Historic block ${newHistoricBlock.number} is not newer than oldest available ${currentSummary.oldestHistoricalBlock}. Skipping prune.`);
362
+ return;
363
+ }
364
+ this.log.verbose(`Pruning historic blocks to ${newHistoricBlock.number}`);
365
+ const status = await this.merkleTreeDb.removeHistoricalBlocks(BlockNumber(newHistoricBlock.number));
284
366
  this.log.debug(`World state summary `, status.summary);
285
367
  }
286
368
  handleChainProven(blockNumber) {
287
- this.provenBlockNumber = BigInt(blockNumber);
369
+ this.provenBlockNumber = blockNumber;
288
370
  this.log.debug(`Proven chain is now at block ${blockNumber}`);
289
371
  return Promise.resolve();
290
372
  }
291
373
  async handleChainPruned(blockNumber) {
292
- this.log.warn(`Chain pruned to block ${blockNumber}`);
293
- const status = await this.merkleTreeDb.unwindBlocks(BigInt(blockNumber));
294
- this.latestBlockHashQuery = undefined;
374
+ this.log.info(`Chain pruned to block ${blockNumber}`);
375
+ const status = await this.merkleTreeDb.unwindBlocks(blockNumber);
295
376
  this.provenBlockNumber = undefined;
296
377
  this.instrumentation.updateWorldStateMetrics(status);
297
378
  }
@@ -302,16 +383,4 @@ import { WorldStateSynchronizerError } from './errors.js';
302
383
  this.currentState = newState;
303
384
  this.log.debug(`Moved to state ${WorldStateRunningState[this.currentState]}`);
304
385
  }
305
- /**
306
- * Verifies that the L1 to L2 messages hash to the block inHash.
307
- * @param l1ToL2Messages - The L1 to L2 messages for the block.
308
- * @param inHash - The inHash of the block.
309
- * @throws If the L1 to L2 messages do not hash to the block inHash.
310
- */ async verifyMessagesHashToInHash(l1ToL2Messages, inHash) {
311
- const treeCalculator = await MerkleTreeCalculator.create(L1_TO_L2_MSG_SUBTREE_HEIGHT, Buffer.alloc(32), (lhs, rhs)=>Promise.resolve(new SHA256Trunc().hash(lhs, rhs)));
312
- const root = await treeCalculator.computeTreeRoot(l1ToL2Messages.map((msg)=>msg.toBuffer()));
313
- if (!root.equals(inHash.toBuffer())) {
314
- throw new Error('Obtained L1 to L2 messages failed to be hashed to the block inHash');
315
- }
316
- }
317
386
  }
@@ -1,2 +1,2 @@
1
1
  export * from './utils.js';
2
- //# sourceMappingURL=index.d.ts.map
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0L2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGNBQWMsWUFBWSxDQUFDIn0=
@@ -1,19 +1,26 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { BlockNumber, type CheckpointNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
3
  import { L2Block } from '@aztec/stdlib/block';
3
4
  import type { MerkleTreeReadOperations, MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
5
+ import { mockCheckpointAndMessages } from '@aztec/stdlib/testing';
4
6
  import type { NativeWorldStateService } from '../native/native_world_state.js';
5
- export declare function mockBlock(blockNum: number, size: number, fork: MerkleTreeWriteOperations, maxEffects?: number | undefined): Promise<{
7
+ export declare function updateBlockState(block: L2Block, l1ToL2Messages: Fr[], fork: MerkleTreeWriteOperations): Promise<void>;
8
+ export declare function mockBlock(blockNum: BlockNumber, size: number, fork: MerkleTreeWriteOperations, maxEffects?: number | undefined, numL1ToL2Messages?: number, isFirstBlockInCheckpoint?: boolean): Promise<{
6
9
  block: L2Block;
7
10
  messages: Fr[];
8
11
  }>;
9
- export declare function mockEmptyBlock(blockNum: number, fork: MerkleTreeWriteOperations): Promise<{
12
+ export declare function mockEmptyBlock(blockNum: BlockNumber, fork: MerkleTreeWriteOperations): Promise<{
10
13
  block: L2Block;
11
14
  messages: Fr[];
12
15
  }>;
13
- export declare function mockBlocks(from: number, count: number, numTxs: number, worldState: NativeWorldStateService): Promise<{
16
+ export declare function mockBlocks(from: BlockNumber, count: number, numTxs: number, worldState: NativeWorldStateService): Promise<{
14
17
  blocks: L2Block[];
15
18
  messages: Fr[][];
16
19
  }>;
20
+ export declare function mockCheckpoint(checkpointNumber: CheckpointNumber, fork: MerkleTreeWriteOperations, options?: Partial<Parameters<typeof mockCheckpointAndMessages>[1]>): Promise<{
21
+ checkpoint: import("@aztec/stdlib/checkpoint").Checkpoint;
22
+ messages: Fr[];
23
+ }>;
17
24
  export declare function assertSameState(forkA: MerkleTreeReadOperations, forkB: MerkleTreeReadOperations): Promise<void>;
18
25
  export declare function compareChains(left: MerkleTreeReadOperations, right: MerkleTreeReadOperations): Promise<void>;
19
- //# sourceMappingURL=utils.d.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AE,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"}
@@ -1,37 +1,51 @@
1
1
  import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NULLIFIER_SUBTREE_HEIGHT, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
+ import { asyncMap } from '@aztec/foundation/async-map';
3
+ import { BlockNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
2
4
  import { padArrayEnd } from '@aztec/foundation/collection';
3
- import { Fr } from '@aztec/foundation/fields';
5
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
6
  import { L2Block } from '@aztec/stdlib/block';
7
+ import { mockCheckpointAndMessages, mockL1ToL2Messages } from '@aztec/stdlib/testing';
5
8
  import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
6
- export async function mockBlock(blockNum, size, fork, maxEffects = undefined) {
7
- const l2Block = await L2Block.random(blockNum, size, maxEffects);
8
- const l1ToL2Messages = Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.random);
9
- {
10
- const insertData = async (treeId, data, subTreeHeight, fork)=>{
11
- for (const dataBatch of data){
12
- await fork.batchInsert(treeId, dataBatch, subTreeHeight);
13
- }
14
- };
15
- const publicDataInsert = insertData(MerkleTreeId.PUBLIC_DATA_TREE, l2Block.body.txEffects.map((txEffect)=>txEffect.publicDataWrites.map((write)=>write.toBuffer())), 0, fork);
16
- const nullifierInsert = insertData(MerkleTreeId.NULLIFIER_TREE, l2Block.body.txEffects.map((txEffect)=>padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map((nullifier)=>nullifier.toBuffer())), NULLIFIER_SUBTREE_HEIGHT, fork);
17
- const noteHashesPadded = l2Block.body.txEffects.flatMap((txEffect)=>padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
18
- const l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
19
- const noteHashInsert = fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
20
- const messageInsert = fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
21
- await Promise.all([
22
- publicDataInsert,
23
- nullifierInsert,
24
- noteHashInsert,
25
- messageInsert
26
- ]);
27
- }
9
+ import { BlockHeader } from '@aztec/stdlib/tx';
10
+ export async function updateBlockState(block, l1ToL2Messages, fork) {
11
+ const insertData = async (treeId, data, subTreeHeight, fork)=>{
12
+ for (const dataBatch of data){
13
+ await fork.batchInsert(treeId, dataBatch, subTreeHeight);
14
+ }
15
+ };
16
+ const publicDataInsert = insertData(MerkleTreeId.PUBLIC_DATA_TREE, block.body.txEffects.map((txEffect)=>txEffect.publicDataWrites.map((write)=>write.toBuffer())), 0, fork);
17
+ const nullifierInsert = insertData(MerkleTreeId.NULLIFIER_TREE, block.body.txEffects.map((txEffect)=>padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map((nullifier)=>nullifier.toBuffer())), NULLIFIER_SUBTREE_HEIGHT, fork);
18
+ const noteHashesPadded = block.body.txEffects.flatMap((txEffect)=>padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
19
+ const l1ToL2MessagesPadded = block.indexWithinCheckpoint === 0 ? padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP) : l1ToL2Messages;
20
+ const noteHashInsert = fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
21
+ const messageInsert = fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
22
+ await Promise.all([
23
+ publicDataInsert,
24
+ nullifierInsert,
25
+ noteHashInsert,
26
+ messageInsert
27
+ ]);
28
28
  const state = await fork.getStateReference();
29
- l2Block.header.state = state;
30
- await fork.updateArchive(l2Block.getBlockHeader());
29
+ block.header = BlockHeader.from({
30
+ ...block.header,
31
+ state
32
+ });
33
+ await fork.updateArchive(block.header);
31
34
  const archiveState = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
32
- l2Block.archive = new AppendOnlyTreeSnapshot(Fr.fromBuffer(archiveState.root), Number(archiveState.size));
35
+ block.archive = new AppendOnlyTreeSnapshot(Fr.fromBuffer(archiveState.root), Number(archiveState.size));
36
+ }
37
+ export async function mockBlock(blockNum, size, fork, maxEffects = 1000, numL1ToL2Messages = NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, isFirstBlockInCheckpoint = true) {
38
+ const block = await L2Block.random(blockNum, {
39
+ indexWithinCheckpoint: isFirstBlockInCheckpoint ? IndexWithinCheckpoint(0) : IndexWithinCheckpoint(1),
40
+ txsPerBlock: size,
41
+ txOptions: {
42
+ maxEffects
43
+ }
44
+ });
45
+ const l1ToL2Messages = mockL1ToL2Messages(numL1ToL2Messages);
46
+ await updateBlockState(block, l1ToL2Messages, fork);
33
47
  return {
34
- block: l2Block,
48
+ block,
35
49
  messages: l1ToL2Messages
36
50
  };
37
51
  }
@@ -39,38 +53,18 @@ export async function mockEmptyBlock(blockNum, fork) {
39
53
  const l2Block = L2Block.empty();
40
54
  const l1ToL2Messages = Array(16).fill(0).map(Fr.zero);
41
55
  l2Block.header.globalVariables.blockNumber = blockNum;
42
- // Sync the append only trees
43
- {
44
- const noteHashesPadded = l2Block.body.txEffects.flatMap((txEffect)=>padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
45
- await fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
46
- const l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
47
- await fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
48
- }
49
- // Sync the indexed trees
50
- {
51
- // We insert the public data tree leaves with one batch per tx to avoid updating the same key twice
52
- for (const txEffect of l2Block.body.txEffects){
53
- await fork.batchInsert(MerkleTreeId.PUBLIC_DATA_TREE, txEffect.publicDataWrites.map((write)=>write.toBuffer()), 0);
54
- const nullifiersPadded = padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX);
55
- await fork.batchInsert(MerkleTreeId.NULLIFIER_TREE, nullifiersPadded.map((nullifier)=>nullifier.toBuffer()), NULLIFIER_SUBTREE_HEIGHT);
56
- }
57
- }
58
- const state = await fork.getStateReference();
59
- l2Block.header.state = state;
60
- await fork.updateArchive(l2Block.getBlockHeader());
61
- const archiveState = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
62
- l2Block.archive = new AppendOnlyTreeSnapshot(Fr.fromBuffer(archiveState.root), Number(archiveState.size));
56
+ await updateBlockState(l2Block, l1ToL2Messages, fork);
63
57
  return {
64
58
  block: l2Block,
65
59
  messages: l1ToL2Messages
66
60
  };
67
61
  }
68
62
  export async function mockBlocks(from, count, numTxs, worldState) {
69
- const tempFork = await worldState.fork(from - 1);
63
+ const tempFork = await worldState.fork(BlockNumber(from - 1));
70
64
  const blocks = [];
71
65
  const messagesArray = [];
72
66
  for(let blockNumber = from; blockNumber < from + count; blockNumber++){
73
- const { block, messages } = await mockBlock(blockNumber, numTxs, tempFork);
67
+ const { block, messages } = await mockBlock(BlockNumber(blockNumber), numTxs, tempFork);
74
68
  blocks.push(block);
75
69
  messagesArray.push(messages);
76
70
  }
@@ -80,6 +74,16 @@ export async function mockBlocks(from, count, numTxs, worldState) {
80
74
  messages: messagesArray
81
75
  };
82
76
  }
77
+ export async function mockCheckpoint(checkpointNumber, fork, options = {}) {
78
+ const { checkpoint, messages } = await mockCheckpointAndMessages(checkpointNumber, options);
79
+ await asyncMap(checkpoint.blocks, async (block, i)=>{
80
+ await updateBlockState(block, i === 0 ? messages : [], fork);
81
+ });
82
+ return {
83
+ checkpoint,
84
+ messages
85
+ };
86
+ }
83
87
  export async function assertSameState(forkA, forkB) {
84
88
  const nativeStateRef = await forkA.getStateReference();
85
89
  const nativeArchive = await forkA.getTreeInfo(MerkleTreeId.ARCHIVE);
package/dest/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Fr } from '@aztec/foundation/fields';
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
4
  export declare const defaultInitialAccountFeeJuice: Fr;
@@ -7,4 +7,4 @@ export declare function getGenesisValues(initialAccounts: AztecAddress[], initia
7
7
  prefilledPublicData: PublicDataTreeLeaf[];
8
8
  fundingNeeded: bigint;
9
9
  }>;
10
- //# sourceMappingURL=testing.d.ts.map
10
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdGluZy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3Rlc3RpbmcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBRXBELE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQ2hFLE9BQU8sRUFBZ0Isa0JBQWtCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQXlCdkUsZUFBTyxNQUFNLDZCQUE2QixJQUFxQixDQUFDO0FBRWhFLHdCQUFzQixnQkFBZ0IsQ0FDcEMsZUFBZSxFQUFFLFlBQVksRUFBRSxFQUMvQixzQkFBc0IsS0FBZ0MsRUFDdEQsaUJBQWlCLEdBQUUsa0JBQWtCLEVBQU87Ozs7R0FxQjdDIn0=
@@ -1 +1 @@
1
- {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAgB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAyBvE,eAAO,MAAM,6BAA6B,IAAqB,CAAC;AAEhE,wBAAsB,gBAAgB,CACpC,eAAe,EAAE,YAAY,EAAE,EAC/B,sBAAsB,KAAgC,EACtD,iBAAiB,GAAE,kBAAkB,EAAO;;;;GAqB7C"}
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;AAyBvE,eAAO,MAAM,6BAA6B,IAAqB,CAAC;AAEhE,wBAAsB,gBAAgB,CACpC,eAAe,EAAE,YAAY,EAAE,EAC/B,sBAAsB,KAAgC,EACtD,iBAAiB,GAAE,kBAAkB,EAAO;;;;GAqB7C"}
package/dest/testing.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
2
- import { Fr } from '@aztec/foundation/fields';
2
+ 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';
@@ -1,3 +1,3 @@
1
1
  export * from './merkle_tree_db.js';
2
2
  export type { MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
3
- //# sourceMappingURL=index.d.ts.map
3
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93b3JsZC1zdGF0ZS1kYi9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLHFCQUFxQixDQUFDO0FBRXBDLFlBQVksRUFBRSx3QkFBd0IsRUFBRSxNQUFNLGlDQUFpQyxDQUFDIn0=