@aztec/archiver 0.0.1-commit.d431d1c → 0.0.1-commit.dbf9cec

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 (95) hide show
  1. package/README.md +9 -0
  2. package/dest/archiver.d.ts +10 -6
  3. package/dest/archiver.d.ts.map +1 -1
  4. package/dest/archiver.js +37 -107
  5. package/dest/errors.d.ts +6 -1
  6. package/dest/errors.d.ts.map +1 -1
  7. package/dest/errors.js +8 -0
  8. package/dest/factory.d.ts +5 -2
  9. package/dest/factory.d.ts.map +1 -1
  10. package/dest/factory.js +16 -13
  11. package/dest/index.d.ts +2 -1
  12. package/dest/index.d.ts.map +1 -1
  13. package/dest/index.js +1 -0
  14. package/dest/l1/bin/retrieve-calldata.js +35 -32
  15. package/dest/l1/calldata_retriever.d.ts +73 -50
  16. package/dest/l1/calldata_retriever.d.ts.map +1 -1
  17. package/dest/l1/calldata_retriever.js +190 -259
  18. package/dest/l1/data_retrieval.d.ts +9 -9
  19. package/dest/l1/data_retrieval.d.ts.map +1 -1
  20. package/dest/l1/data_retrieval.js +24 -22
  21. package/dest/l1/spire_proposer.d.ts +5 -5
  22. package/dest/l1/spire_proposer.d.ts.map +1 -1
  23. package/dest/l1/spire_proposer.js +9 -17
  24. package/dest/l1/validate_trace.d.ts +6 -3
  25. package/dest/l1/validate_trace.d.ts.map +1 -1
  26. package/dest/l1/validate_trace.js +13 -9
  27. package/dest/modules/data_source_base.d.ts +23 -19
  28. package/dest/modules/data_source_base.d.ts.map +1 -1
  29. package/dest/modules/data_source_base.js +44 -119
  30. package/dest/modules/data_store_updater.d.ts +31 -20
  31. package/dest/modules/data_store_updater.d.ts.map +1 -1
  32. package/dest/modules/data_store_updater.js +79 -60
  33. package/dest/modules/instrumentation.d.ts +17 -4
  34. package/dest/modules/instrumentation.d.ts.map +1 -1
  35. package/dest/modules/instrumentation.js +36 -12
  36. package/dest/modules/l1_synchronizer.d.ts +4 -8
  37. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  38. package/dest/modules/l1_synchronizer.js +23 -19
  39. package/dest/store/block_store.d.ts +50 -32
  40. package/dest/store/block_store.d.ts.map +1 -1
  41. package/dest/store/block_store.js +147 -54
  42. package/dest/store/contract_class_store.d.ts +1 -1
  43. package/dest/store/contract_class_store.d.ts.map +1 -1
  44. package/dest/store/contract_class_store.js +11 -7
  45. package/dest/store/kv_archiver_store.d.ts +43 -25
  46. package/dest/store/kv_archiver_store.d.ts.map +1 -1
  47. package/dest/store/kv_archiver_store.js +38 -17
  48. package/dest/store/l2_tips_cache.d.ts +19 -0
  49. package/dest/store/l2_tips_cache.d.ts.map +1 -0
  50. package/dest/store/l2_tips_cache.js +89 -0
  51. package/dest/store/log_store.d.ts +4 -4
  52. package/dest/store/log_store.d.ts.map +1 -1
  53. package/dest/store/log_store.js +57 -37
  54. package/dest/test/fake_l1_state.d.ts +9 -4
  55. package/dest/test/fake_l1_state.d.ts.map +1 -1
  56. package/dest/test/fake_l1_state.js +56 -18
  57. package/dest/test/index.js +3 -1
  58. package/dest/test/mock_archiver.d.ts +1 -1
  59. package/dest/test/mock_archiver.d.ts.map +1 -1
  60. package/dest/test/mock_archiver.js +3 -2
  61. package/dest/test/mock_l2_block_source.d.ts +36 -21
  62. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  63. package/dest/test/mock_l2_block_source.js +151 -109
  64. package/dest/test/mock_structs.d.ts +3 -2
  65. package/dest/test/mock_structs.d.ts.map +1 -1
  66. package/dest/test/mock_structs.js +11 -9
  67. package/dest/test/noop_l1_archiver.d.ts +23 -0
  68. package/dest/test/noop_l1_archiver.d.ts.map +1 -0
  69. package/dest/test/noop_l1_archiver.js +68 -0
  70. package/package.json +14 -13
  71. package/src/archiver.ts +50 -132
  72. package/src/errors.ts +12 -0
  73. package/src/factory.ts +30 -14
  74. package/src/index.ts +1 -0
  75. package/src/l1/README.md +25 -68
  76. package/src/l1/bin/retrieve-calldata.ts +45 -33
  77. package/src/l1/calldata_retriever.ts +249 -379
  78. package/src/l1/data_retrieval.ts +27 -29
  79. package/src/l1/spire_proposer.ts +7 -15
  80. package/src/l1/validate_trace.ts +24 -6
  81. package/src/modules/data_source_base.ts +73 -163
  82. package/src/modules/data_store_updater.ts +92 -63
  83. package/src/modules/instrumentation.ts +46 -14
  84. package/src/modules/l1_synchronizer.ts +26 -24
  85. package/src/store/block_store.ts +188 -92
  86. package/src/store/contract_class_store.ts +11 -7
  87. package/src/store/kv_archiver_store.ts +69 -29
  88. package/src/store/l2_tips_cache.ts +89 -0
  89. package/src/store/log_store.ts +105 -43
  90. package/src/test/fake_l1_state.ts +77 -19
  91. package/src/test/index.ts +3 -0
  92. package/src/test/mock_archiver.ts +3 -2
  93. package/src/test/mock_l2_block_source.ts +196 -126
  94. package/src/test/mock_structs.ts +26 -10
  95. package/src/test/noop_l1_archiver.ts +109 -0
@@ -1,6 +1,6 @@
1
- import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
1
+ import { range } from '@aztec/foundation/array';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
3
  import { isDefined } from '@aztec/foundation/types';
3
- import { CheckpointedL2Block, CommitteeAttestation } from '@aztec/stdlib/block';
4
4
  import { Checkpoint, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
5
5
  import { getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
6
6
  /**
@@ -40,9 +40,12 @@ import { getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
40
40
  getCheckpointedBlock(number) {
41
41
  return this.store.getCheckpointedBlock(number);
42
42
  }
43
- getCheckpointedBlockNumber() {
43
+ getCheckpointedL2BlockNumber() {
44
44
  return this.store.getCheckpointedL2BlockNumber();
45
45
  }
46
+ getFinalizedL2BlockNumber() {
47
+ return this.store.getFinalizedL2BlockNumber();
48
+ }
46
49
  async getCheckpointHeader(number) {
47
50
  if (number === 'latest') {
48
51
  number = await this.store.getSynchedCheckpointNumber();
@@ -61,15 +64,10 @@ import { getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
61
64
  if (!checkpointData) {
62
65
  return undefined;
63
66
  }
64
- return BlockNumber(checkpointData.startBlock + checkpointData.numBlocks - 1);
67
+ return BlockNumber(checkpointData.startBlock + checkpointData.blockCount - 1);
65
68
  }
66
- async getCheckpointedBlocks(from, limit, proven) {
67
- const blocks = await this.store.getCheckpointedBlocks(from, limit);
68
- if (proven === true) {
69
- const provenBlockNumber = await this.store.getProvenBlockNumber();
70
- return blocks.filter((b)=>b.block.number <= provenBlockNumber);
71
- }
72
- return blocks;
69
+ getCheckpointedBlocks(from, limit) {
70
+ return this.store.getCheckpointedBlocks(from, limit);
73
71
  }
74
72
  getBlockHeaderByHash(blockHash) {
75
73
  return this.store.getBlockHeaderByHash(blockHash);
@@ -77,7 +75,13 @@ import { getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
77
75
  getBlockHeaderByArchive(archive) {
78
76
  return this.store.getBlockHeaderByArchive(archive);
79
77
  }
80
- async getL2BlockNew(number) {
78
+ getBlockData(number) {
79
+ return this.store.getBlockData(number);
80
+ }
81
+ getBlockDataByArchive(archive) {
82
+ return this.store.getBlockDataByArchive(archive);
83
+ }
84
+ async getL2Block(number) {
81
85
  // If the number provided is -ve, then return the latest block.
82
86
  if (number < 0) {
83
87
  number = await this.store.getLatestBlockNumber();
@@ -102,14 +106,6 @@ import { getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
102
106
  valid: true
103
107
  };
104
108
  }
105
- async getL2BlocksNew(from, limit, proven) {
106
- const blocks = await this.store.getBlocks(from, limit);
107
- if (proven === true) {
108
- const provenBlockNumber = await this.store.getProvenBlockNumber();
109
- return blocks.filter((b)=>b.number <= provenBlockNumber);
110
- }
111
- return blocks;
112
- }
113
109
  getPrivateLogsByTags(tags, page) {
114
110
  return this.store.getPrivateLogsByTags(tags, page);
115
111
  }
@@ -154,107 +150,41 @@ import { getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
154
150
  getL1ToL2MessageIndex(l1ToL2Message) {
155
151
  return this.store.getL1ToL2MessageIndex(l1ToL2Message);
156
152
  }
157
- async getPublishedCheckpoints(checkpointNumber, limit) {
153
+ async getCheckpoints(checkpointNumber, limit) {
158
154
  const checkpoints = await this.store.getRangeOfCheckpoints(checkpointNumber, limit);
159
- const blocks = (await Promise.all(checkpoints.map((ch)=>this.store.getBlocksForCheckpoint(ch.checkpointNumber)))).filter(isDefined);
160
- const fullCheckpoints = [];
161
- for(let i = 0; i < checkpoints.length; i++){
162
- const blocksForCheckpoint = blocks[i];
163
- const checkpoint = checkpoints[i];
164
- const fullCheckpoint = new Checkpoint(checkpoint.archive, checkpoint.header, blocksForCheckpoint, checkpoint.checkpointNumber);
165
- const publishedCheckpoint = new PublishedCheckpoint(fullCheckpoint, checkpoint.l1, checkpoint.attestations.map((x)=>CommitteeAttestation.fromBuffer(x)));
166
- fullCheckpoints.push(publishedCheckpoint);
155
+ return Promise.all(checkpoints.map((ch)=>this.getPublishedCheckpointFromCheckpointData(ch)));
156
+ }
157
+ async getPublishedCheckpointFromCheckpointData(checkpoint) {
158
+ const blocksForCheckpoint = await this.store.getBlocksForCheckpoint(checkpoint.checkpointNumber);
159
+ if (!blocksForCheckpoint) {
160
+ throw new Error(`Blocks for checkpoint ${checkpoint.checkpointNumber} not found`);
167
161
  }
168
- return fullCheckpoints;
162
+ const fullCheckpoint = new Checkpoint(checkpoint.archive, checkpoint.header, blocksForCheckpoint, checkpoint.checkpointNumber);
163
+ return new PublishedCheckpoint(fullCheckpoint, checkpoint.l1, checkpoint.attestations);
169
164
  }
170
165
  getBlocksForSlot(slotNumber) {
171
166
  return this.store.getBlocksForSlot(slotNumber);
172
167
  }
173
- async getBlocksForEpoch(epochNumber) {
174
- if (!this.l1Constants) {
175
- throw new Error('L1 constants not set');
176
- }
177
- const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
178
- const blocks = [];
179
- // Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
180
- // We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
181
- let checkpoint = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
182
- const slot = (b)=>b.header.slotNumber;
183
- while(checkpoint && slot(checkpoint) >= start){
184
- if (slot(checkpoint) <= end) {
185
- // push the blocks on backwards
186
- const endBlock = checkpoint.startBlock + checkpoint.numBlocks - 1;
187
- for(let i = endBlock; i >= checkpoint.startBlock; i--){
188
- const block = await this.getBlock(BlockNumber(i));
189
- if (block) {
190
- blocks.push(block);
191
- }
192
- }
193
- }
194
- checkpoint = await this.store.getCheckpointData(CheckpointNumber(checkpoint.checkpointNumber - 1));
195
- }
196
- return blocks.reverse();
168
+ async getCheckpointedBlocksForEpoch(epochNumber) {
169
+ const checkpointsData = await this.getCheckpointsDataForEpoch(epochNumber);
170
+ const blocks = await Promise.all(checkpointsData.flatMap((checkpoint)=>range(checkpoint.blockCount, checkpoint.startBlock).map((blockNumber)=>this.getCheckpointedBlock(BlockNumber(blockNumber)))));
171
+ return blocks.filter(isDefined);
197
172
  }
198
- async getBlockHeadersForEpoch(epochNumber) {
199
- if (!this.l1Constants) {
200
- throw new Error('L1 constants not set');
201
- }
202
- const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
203
- const blocks = [];
204
- // Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
205
- // We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
206
- let checkpoint = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
207
- const slot = (b)=>b.header.slotNumber;
208
- while(checkpoint && slot(checkpoint) >= start){
209
- if (slot(checkpoint) <= end) {
210
- // push the blocks on backwards
211
- const endBlock = checkpoint.startBlock + checkpoint.numBlocks - 1;
212
- for(let i = endBlock; i >= checkpoint.startBlock; i--){
213
- const block = await this.getBlockHeader(BlockNumber(i));
214
- if (block) {
215
- blocks.push(block);
216
- }
217
- }
218
- }
219
- checkpoint = await this.store.getCheckpointData(CheckpointNumber(checkpoint.checkpointNumber - 1));
220
- }
221
- return blocks.reverse();
173
+ async getCheckpointedBlockHeadersForEpoch(epochNumber) {
174
+ const checkpointsData = await this.getCheckpointsDataForEpoch(epochNumber);
175
+ const blocks = await Promise.all(checkpointsData.flatMap((checkpoint)=>range(checkpoint.blockCount, checkpoint.startBlock).map((blockNumber)=>this.getBlockHeader(BlockNumber(blockNumber)))));
176
+ return blocks.filter(isDefined);
222
177
  }
223
178
  async getCheckpointsForEpoch(epochNumber) {
179
+ const checkpointsData = await this.getCheckpointsDataForEpoch(epochNumber);
180
+ return Promise.all(checkpointsData.map((data)=>this.getPublishedCheckpointFromCheckpointData(data).then((p)=>p.checkpoint)));
181
+ }
182
+ /** Returns checkpoint data for all checkpoints whose slot falls within the given epoch. */ getCheckpointsDataForEpoch(epochNumber) {
224
183
  if (!this.l1Constants) {
225
184
  throw new Error('L1 constants not set');
226
185
  }
227
186
  const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
228
- const checkpoints = [];
229
- // Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
230
- // We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
231
- let checkpointData = await this.store.getCheckpointData(await this.store.getSynchedCheckpointNumber());
232
- const slot = (b)=>b.header.slotNumber;
233
- while(checkpointData && slot(checkpointData) >= start){
234
- if (slot(checkpointData) <= end) {
235
- // push the checkpoints on backwards
236
- const [checkpoint] = await this.getPublishedCheckpoints(checkpointData.checkpointNumber, 1);
237
- checkpoints.push(checkpoint.checkpoint);
238
- }
239
- checkpointData = await this.store.getCheckpointData(CheckpointNumber(checkpointData.checkpointNumber - 1));
240
- }
241
- return checkpoints.reverse();
242
- }
243
- async getPublishedBlocks(from, limit, proven) {
244
- const checkpoints = await this.store.getRangeOfCheckpoints(CheckpointNumber(from), limit);
245
- const provenCheckpointNumber = await this.store.getProvenCheckpointNumber();
246
- const blocks = (await Promise.all(checkpoints.map((ch)=>this.store.getBlocksForCheckpoint(ch.checkpointNumber)))).filter(isDefined);
247
- const publishedBlocks = [];
248
- for(let i = 0; i < checkpoints.length; i++){
249
- const blockForCheckpoint = blocks[i][0];
250
- const checkpoint = checkpoints[i];
251
- if (checkpoint.checkpointNumber > provenCheckpointNumber && proven === true) {
252
- continue;
253
- }
254
- const publishedBlock = new CheckpointedL2Block(checkpoint.checkpointNumber, blockForCheckpoint, checkpoint.l1, checkpoint.attestations.map((x)=>CommitteeAttestation.fromBuffer(x)));
255
- publishedBlocks.push(publishedBlock);
256
- }
257
- return publishedBlocks;
187
+ return this.store.getCheckpointDataForSlotRange(start, end);
258
188
  }
259
189
  async getBlock(number) {
260
190
  // If the number provided is -ve, then return the latest block.
@@ -266,25 +196,20 @@ import { getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
266
196
  }
267
197
  return this.store.getBlock(number);
268
198
  }
269
- async getBlocks(from, limit, proven) {
270
- const blocks = await this.store.getBlocks(from, limit);
271
- if (proven === true) {
272
- const provenBlockNumber = await this.store.getProvenBlockNumber();
273
- return blocks.filter((b)=>b.number <= provenBlockNumber);
274
- }
275
- return blocks;
199
+ getBlocks(from, limit) {
200
+ return this.store.getBlocks(from, limit);
276
201
  }
277
- getPublishedBlockByHash(blockHash) {
202
+ getCheckpointedBlockByHash(blockHash) {
278
203
  return this.store.getCheckpointedBlockByHash(blockHash);
279
204
  }
280
- getPublishedBlockByArchive(archive) {
205
+ getCheckpointedBlockByArchive(archive) {
281
206
  return this.store.getCheckpointedBlockByArchive(archive);
282
207
  }
283
- async getL2BlockNewByHash(blockHash) {
208
+ async getL2BlockByHash(blockHash) {
284
209
  const checkpointedBlock = await this.store.getCheckpointedBlockByHash(blockHash);
285
210
  return checkpointedBlock?.block;
286
211
  }
287
- async getL2BlockNewByArchive(archive) {
212
+ async getL2BlockByArchive(archive) {
288
213
  const checkpointedBlock = await this.store.getCheckpointedBlockByArchive(archive);
289
214
  return checkpointedBlock?.block;
290
215
  }
@@ -1,32 +1,35 @@
1
- import { BlockNumber, type CheckpointNumber } from '@aztec/foundation/branded-types';
2
- import type { L2BlockNew, ValidateCheckpointResult } from '@aztec/stdlib/block';
1
+ import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
2
+ import type { L2Block, ValidateCheckpointResult } from '@aztec/stdlib/block';
3
3
  import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
4
4
  import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
5
+ import type { L2TipsCache } from '../store/l2_tips_cache.js';
5
6
  /** Result of adding checkpoints with information about any pruned blocks. */
6
7
  type ReconcileCheckpointsResult = {
7
8
  /** Blocks that were pruned due to conflict with L1 checkpoints. */
8
- prunedBlocks: L2BlockNew[] | undefined;
9
+ prunedBlocks: L2Block[] | undefined;
9
10
  /** Last block number that was already inserted locally, or undefined if none. */
10
11
  lastAlreadyInsertedBlockNumber: BlockNumber | undefined;
11
12
  };
12
13
  /** Archiver helper module to handle updates to the data store. */
13
14
  export declare class ArchiverDataStoreUpdater {
14
15
  private store;
16
+ private l2TipsCache?;
15
17
  private readonly log;
16
- constructor(store: KVArchiverDataStore);
18
+ constructor(store: KVArchiverDataStore, l2TipsCache?: L2TipsCache | undefined);
17
19
  /**
18
- * Adds blocks to the store with contract class/instance extraction from logs.
20
+ * Adds proposed blocks to the store with contract class/instance extraction from logs.
21
+ * These are uncheckpointed blocks that have been proposed by the sequencer but not yet included in a checkpoint on L1.
19
22
  * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
20
23
  * and individually broadcasted functions from the block logs.
21
24
  *
22
- * @param blocks - The L2 blocks to add.
25
+ * @param blocks - The proposed L2 blocks to add.
23
26
  * @param pendingChainValidationStatus - Optional validation status to set.
24
27
  * @returns True if the operation is successful.
25
28
  */
26
- addBlocks(blocks: L2BlockNew[], pendingChainValidationStatus?: ValidateCheckpointResult): Promise<boolean>;
29
+ addProposedBlocks(blocks: L2Block[], pendingChainValidationStatus?: ValidateCheckpointResult): Promise<boolean>;
27
30
  /**
28
31
  * Reconciles local blocks with incoming checkpoints from L1.
29
- * Adds checkpoints to the store with contract class/instance extraction from logs.
32
+ * Adds new checkpoints to the store with contract class/instance extraction from logs.
30
33
  * Prunes any local blocks that conflict with checkpoint data (by comparing archive roots).
31
34
  * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
32
35
  * and individually broadcasted functions from the checkpoint block logs.
@@ -35,35 +38,43 @@ export declare class ArchiverDataStoreUpdater {
35
38
  * @param pendingChainValidationStatus - Optional validation status to set.
36
39
  * @returns Result with information about any pruned blocks.
37
40
  */
38
- setNewCheckpointData(checkpoints: PublishedCheckpoint[], pendingChainValidationStatus?: ValidateCheckpointResult): Promise<ReconcileCheckpointsResult>;
41
+ addCheckpoints(checkpoints: PublishedCheckpoint[], pendingChainValidationStatus?: ValidateCheckpointResult): Promise<ReconcileCheckpointsResult>;
39
42
  private pruneMismatchingLocalBlocks;
40
43
  /**
41
- * Removes all blocks strictly after the specified block number and cleans up associated contract data.
44
+ * Removes all uncheckpointed blocks strictly after the specified block number and cleans up associated contract data.
42
45
  * This handles removal of provisionally added blocks along with their contract classes/instances.
46
+ * Verifies that each block being removed is not part of a stored checkpoint.
43
47
  *
44
48
  * @param blockNumber - Remove all blocks with number greater than this.
45
49
  * @returns The removed blocks.
50
+ * @throws Error if any block to be removed is checkpointed.
46
51
  */
47
- removeBlocksAfter(blockNumber: BlockNumber): Promise<L2BlockNew[]>;
52
+ removeUncheckpointedBlocksAfter(blockNumber: BlockNumber): Promise<L2Block[]>;
53
+ private removeBlocksAfter;
48
54
  /**
49
- * Unwinds checkpoints from the store with reverse contract extraction.
55
+ * Removes all checkpoints after the given checkpoint number.
50
56
  * Deletes ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated data
51
- * that was stored for the unwound checkpoints.
57
+ * that was stored for the removed checkpoints. Also removes ALL blocks (both checkpointed
58
+ * and uncheckpointed) after the last block of the given checkpoint.
52
59
  *
53
- * @param from - The checkpoint number to unwind from (must be the current tip).
54
- * @param checkpointsToUnwind - The number of checkpoints to unwind.
60
+ * @param checkpointNumber - Remove all checkpoints strictly after this one.
55
61
  * @returns True if the operation is successful.
56
62
  */
57
- unwindCheckpoints(from: CheckpointNumber, checkpointsToUnwind: number): Promise<boolean>;
63
+ removeCheckpointsAfter(checkpointNumber: CheckpointNumber): Promise<boolean>;
64
+ /**
65
+ * Updates the proven checkpoint number and refreshes the L2 tips cache.
66
+ * @param checkpointNumber - The checkpoint number to set as proven.
67
+ */
68
+ setProvenCheckpointNumber(checkpointNumber: CheckpointNumber): Promise<void>;
58
69
  /** Extracts and stores contract data from a single block. */
59
- private addBlockDataToDB;
70
+ private addContractDataToDb;
60
71
  /** Removes contract data associated with a block. */
61
- private removeBlockDataFromDB;
62
- private editContractBlockData;
72
+ private removeContractDataFromDb;
73
+ private updateContractDataOnDb;
63
74
  private updatePublishedContractClasses;
64
75
  private updateDeployedContractInstances;
65
76
  private updateUpdatedContractInstances;
66
77
  private storeBroadcastedIndividualFunctions;
67
78
  }
68
79
  export {};
69
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGF0YV9zdG9yZV91cGRhdGVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbW9kdWxlcy9kYXRhX3N0b3JlX3VwZGF0ZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFdBQVcsRUFBRSxLQUFLLGdCQUFnQixFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFZckYsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLHdCQUF3QixFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDaEYsT0FBTyxLQUFLLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQWFwRSxPQUFPLEtBQUssRUFBRSxtQkFBbUIsRUFBRSxNQUFNLCtCQUErQixDQUFDO0FBU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B;IAa/B;;;;;;;;OAQG;IACU,sBAAsB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAexF;IAED;;;OAGG;IACU,yBAAyB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAKxF;IAED,6DAA6D;IAC7D,OAAO,CAAC,mBAAmB;IAI3B,qDAAqD;IACrD,OAAO,CAAC,wBAAwB;YAKlB,sBAAsB;YAoBtB,8BAA8B;YA4B9B,+BAA+B;YAyB/B,8BAA8B;YA6B9B,mCAAmC;CAwDlD"}
@@ -12,36 +12,41 @@ import groupBy from 'lodash.groupby';
12
12
  }(Operation || {});
13
13
  /** Archiver helper module to handle updates to the data store. */ export class ArchiverDataStoreUpdater {
14
14
  store;
15
+ l2TipsCache;
15
16
  log;
16
- constructor(store){
17
+ constructor(store, l2TipsCache){
17
18
  this.store = store;
19
+ this.l2TipsCache = l2TipsCache;
18
20
  this.log = createLogger('archiver:store_updater');
19
21
  }
20
22
  /**
21
- * Adds blocks to the store with contract class/instance extraction from logs.
23
+ * Adds proposed blocks to the store with contract class/instance extraction from logs.
24
+ * These are uncheckpointed blocks that have been proposed by the sequencer but not yet included in a checkpoint on L1.
22
25
  * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
23
26
  * and individually broadcasted functions from the block logs.
24
27
  *
25
- * @param blocks - The L2 blocks to add.
28
+ * @param blocks - The proposed L2 blocks to add.
26
29
  * @param pendingChainValidationStatus - Optional validation status to set.
27
30
  * @returns True if the operation is successful.
28
- */ addBlocks(blocks, pendingChainValidationStatus) {
29
- return this.store.transactionAsync(async ()=>{
30
- await this.store.addBlocks(blocks);
31
+ */ async addProposedBlocks(blocks, pendingChainValidationStatus) {
32
+ const result = await this.store.transactionAsync(async ()=>{
33
+ await this.store.addProposedBlocks(blocks);
31
34
  const opResults = await Promise.all([
32
35
  // Update the pending chain validation status if provided
33
36
  pendingChainValidationStatus && this.store.setPendingChainValidationStatus(pendingChainValidationStatus),
34
37
  // Add any logs emitted during the retrieved blocks
35
38
  this.store.addLogs(blocks),
36
39
  // Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
37
- ...blocks.map((block)=>this.addBlockDataToDB(block))
40
+ ...blocks.map((block)=>this.addContractDataToDb(block))
38
41
  ]);
42
+ await this.l2TipsCache?.refresh();
39
43
  return opResults.every(Boolean);
40
44
  });
45
+ return result;
41
46
  }
42
47
  /**
43
48
  * Reconciles local blocks with incoming checkpoints from L1.
44
- * Adds checkpoints to the store with contract class/instance extraction from logs.
49
+ * Adds new checkpoints to the store with contract class/instance extraction from logs.
45
50
  * Prunes any local blocks that conflict with checkpoint data (by comparing archive roots).
46
51
  * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
47
52
  * and individually broadcasted functions from the checkpoint block logs.
@@ -49,12 +54,12 @@ import groupBy from 'lodash.groupby';
49
54
  * @param checkpoints - The published checkpoints to add.
50
55
  * @param pendingChainValidationStatus - Optional validation status to set.
51
56
  * @returns Result with information about any pruned blocks.
52
- */ setNewCheckpointData(checkpoints, pendingChainValidationStatus) {
53
- return this.store.transactionAsync(async ()=>{
57
+ */ async addCheckpoints(checkpoints, pendingChainValidationStatus) {
58
+ const result = await this.store.transactionAsync(async ()=>{
54
59
  // Before adding checkpoints, check for conflicts with local blocks if any
55
60
  const { prunedBlocks, lastAlreadyInsertedBlockNumber } = await this.pruneMismatchingLocalBlocks(checkpoints);
56
61
  await this.store.addCheckpoints(checkpoints);
57
- // Filter out blocks that were already inserted via addBlocks() to avoid duplicating logs/contract data
62
+ // Filter out blocks that were already inserted via addProposedBlocks() to avoid duplicating logs/contract data
58
63
  const newBlocks = checkpoints.flatMap((ch)=>ch.checkpoint.blocks).filter((b)=>lastAlreadyInsertedBlockNumber === undefined || b.number > lastAlreadyInsertedBlockNumber);
59
64
  await Promise.all([
60
65
  // Update the pending chain validation status if provided
@@ -62,13 +67,15 @@ import groupBy from 'lodash.groupby';
62
67
  // Add any logs emitted during the retrieved blocks
63
68
  this.store.addLogs(newBlocks),
64
69
  // Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
65
- ...newBlocks.map((block)=>this.addBlockDataToDB(block))
70
+ ...newBlocks.map((block)=>this.addContractDataToDb(block))
66
71
  ]);
72
+ await this.l2TipsCache?.refresh();
67
73
  return {
68
74
  prunedBlocks,
69
75
  lastAlreadyInsertedBlockNumber
70
76
  };
71
77
  });
78
+ return result;
72
79
  }
73
80
  /**
74
81
  * Checks for local proposed blocks that do not match the ones to be checkpointed and prunes them.
@@ -139,67 +146,79 @@ import groupBy from 'lodash.groupby';
139
146
  };
140
147
  }
141
148
  /**
142
- * Removes all blocks strictly after the specified block number and cleans up associated contract data.
149
+ * Removes all uncheckpointed blocks strictly after the specified block number and cleans up associated contract data.
143
150
  * This handles removal of provisionally added blocks along with their contract classes/instances.
151
+ * Verifies that each block being removed is not part of a stored checkpoint.
144
152
  *
145
153
  * @param blockNumber - Remove all blocks with number greater than this.
146
154
  * @returns The removed blocks.
147
- */ removeBlocksAfter(blockNumber) {
148
- return this.store.transactionAsync(async ()=>{
149
- // First get the blocks to be removed so we can clean up contract data
150
- const removedBlocks = await this.store.removeBlocksAfter(blockNumber);
151
- // Clean up contract data and logs for the removed blocks
152
- await Promise.all([
153
- this.store.deleteLogs(removedBlocks),
154
- ...removedBlocks.map((block)=>this.removeBlockDataFromDB(block))
155
- ]);
156
- return removedBlocks;
155
+ * @throws Error if any block to be removed is checkpointed.
156
+ */ async removeUncheckpointedBlocksAfter(blockNumber) {
157
+ const result = await this.store.transactionAsync(async ()=>{
158
+ // Verify we're only removing uncheckpointed blocks
159
+ const lastCheckpointedBlockNumber = await this.store.getCheckpointedL2BlockNumber();
160
+ if (blockNumber < lastCheckpointedBlockNumber) {
161
+ throw new Error(`Cannot remove blocks after ${blockNumber} because checkpointed blocks exist up to ${lastCheckpointedBlockNumber}`);
162
+ }
163
+ const result = await this.removeBlocksAfter(blockNumber);
164
+ await this.l2TipsCache?.refresh();
165
+ return result;
157
166
  });
167
+ return result;
168
+ }
169
+ /**
170
+ * Removes all blocks strictly after the given block number along with any logs and contract data.
171
+ * Does not remove their checkpoints.
172
+ */ async removeBlocksAfter(blockNumber) {
173
+ // First get the blocks to be removed so we can clean up contract data
174
+ const removedBlocks = await this.store.removeBlocksAfter(blockNumber);
175
+ // Clean up contract data and logs for the removed blocks
176
+ await Promise.all([
177
+ this.store.deleteLogs(removedBlocks),
178
+ ...removedBlocks.map((block)=>this.removeContractDataFromDb(block))
179
+ ]);
180
+ return removedBlocks;
158
181
  }
159
182
  /**
160
- * Unwinds checkpoints from the store with reverse contract extraction.
183
+ * Removes all checkpoints after the given checkpoint number.
161
184
  * Deletes ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated data
162
- * that was stored for the unwound checkpoints.
185
+ * that was stored for the removed checkpoints. Also removes ALL blocks (both checkpointed
186
+ * and uncheckpointed) after the last block of the given checkpoint.
163
187
  *
164
- * @param from - The checkpoint number to unwind from (must be the current tip).
165
- * @param checkpointsToUnwind - The number of checkpoints to unwind.
188
+ * @param checkpointNumber - Remove all checkpoints strictly after this one.
166
189
  * @returns True if the operation is successful.
167
- */ async unwindCheckpoints(from, checkpointsToUnwind) {
168
- if (checkpointsToUnwind <= 0) {
169
- throw new Error(`Cannot unwind ${checkpointsToUnwind} blocks`);
170
- }
171
- const last = await this.store.getSynchedCheckpointNumber();
172
- if (from != last) {
173
- throw new Error(`Cannot unwind checkpoints from checkpoint ${from} when the last checkpoint is ${last}`);
174
- }
175
- const blocks = [];
176
- const lastCheckpointNumber = from + checkpointsToUnwind - 1;
177
- for(let checkpointNumber = from; checkpointNumber <= lastCheckpointNumber; checkpointNumber++){
178
- const blocksForCheckpoint = await this.store.getBlocksForCheckpoint(checkpointNumber);
179
- if (!blocksForCheckpoint) {
180
- continue;
181
- }
182
- blocks.push(...blocksForCheckpoint);
183
- }
184
- const opResults = await Promise.all([
185
- // Prune rolls back to the last proven block, which is by definition valid
186
- this.store.setPendingChainValidationStatus({
187
- valid: true
188
- }),
189
- // Remove contract data for all blocks being unwound
190
- ...blocks.map((block)=>this.removeBlockDataFromDB(block)),
191
- this.store.deleteLogs(blocks),
192
- this.store.unwindCheckpoints(from, checkpointsToUnwind)
193
- ]);
194
- return opResults.every(Boolean);
190
+ */ async removeCheckpointsAfter(checkpointNumber) {
191
+ return await this.store.transactionAsync(async ()=>{
192
+ const { blocksRemoved = [] } = await this.store.removeCheckpointsAfter(checkpointNumber);
193
+ const opResults = await Promise.all([
194
+ // Prune rolls back to the last proven block, which is by definition valid
195
+ this.store.setPendingChainValidationStatus({
196
+ valid: true
197
+ }),
198
+ // Remove contract data for all blocks being removed
199
+ ...blocksRemoved.map((block)=>this.removeContractDataFromDb(block)),
200
+ this.store.deleteLogs(blocksRemoved)
201
+ ]);
202
+ await this.l2TipsCache?.refresh();
203
+ return opResults.every(Boolean);
204
+ });
205
+ }
206
+ /**
207
+ * Updates the proven checkpoint number and refreshes the L2 tips cache.
208
+ * @param checkpointNumber - The checkpoint number to set as proven.
209
+ */ async setProvenCheckpointNumber(checkpointNumber) {
210
+ await this.store.transactionAsync(async ()=>{
211
+ await this.store.setProvenCheckpointNumber(checkpointNumber);
212
+ await this.l2TipsCache?.refresh();
213
+ });
195
214
  }
196
- /** Extracts and stores contract data from a single block. */ addBlockDataToDB(block) {
197
- return this.editContractBlockData(block, 0);
215
+ /** Extracts and stores contract data from a single block. */ addContractDataToDb(block) {
216
+ return this.updateContractDataOnDb(block, 0);
198
217
  }
199
- /** Removes contract data associated with a block. */ removeBlockDataFromDB(block) {
200
- return this.editContractBlockData(block, 1);
218
+ /** Removes contract data associated with a block. */ removeContractDataFromDb(block) {
219
+ return this.updateContractDataOnDb(block, 1);
201
220
  }
202
- /** Adds or remove contract data associated with a block. */ async editContractBlockData(block, operation) {
221
+ /** Adds or remove contract data associated with a block. */ async updateContractDataOnDb(block, operation) {
203
222
  const contractClassLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.contractClassLogs);
204
223
  const privateLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.privateLogs);
205
224
  const publicLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.publicLogs);
@@ -1,9 +1,13 @@
1
- import type { L2BlockNew } from '@aztec/stdlib/block';
1
+ import type { SlotNumber } from '@aztec/foundation/branded-types';
2
+ import type { L2Block } from '@aztec/stdlib/block';
3
+ import type { CheckpointData } from '@aztec/stdlib/checkpoint';
4
+ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
2
5
  import { type LmdbStatsCallback, type TelemetryClient, type Tracer } from '@aztec/telemetry-client';
3
6
  export declare class ArchiverInstrumentation {
4
7
  private telemetry;
5
8
  readonly tracer: Tracer;
6
9
  private blockHeight;
10
+ private checkpointHeight;
7
11
  private txCount;
8
12
  private l1BlockHeight;
9
13
  private proofsSubmittedDelay;
@@ -18,14 +22,15 @@ export declare class ArchiverInstrumentation {
18
22
  private syncDurationPerMessage;
19
23
  private syncMessageCount;
20
24
  private blockProposalTxTargetCount;
25
+ private checkpointL1InclusionDelay;
21
26
  private log;
22
27
  private constructor();
23
28
  static new(telemetry: TelemetryClient, lmdbStats?: LmdbStatsCallback): Promise<ArchiverInstrumentation>;
24
29
  isEnabled(): boolean;
25
- processNewBlocks(syncTimePerBlock: number, blocks: L2BlockNew[]): void;
30
+ processNewBlocks(syncTimePerBlock: number, blocks: L2Block[]): void;
26
31
  processNewMessages(count: number, syncPerMessageMs: number): void;
27
32
  processPrune(duration: number): void;
28
- updateLastProvenBlock(blockNumber: number): void;
33
+ updateLastProvenCheckpoint(checkpoint: CheckpointData): void;
29
34
  processProofsVerified(logs: {
30
35
  proverId: string;
31
36
  l2BlockNumber: bigint;
@@ -33,5 +38,13 @@ export declare class ArchiverInstrumentation {
33
38
  }[]): void;
34
39
  updateL1BlockHeight(blockNumber: bigint): void;
35
40
  recordBlockProposalTxTarget(target: string, usedTrace: boolean): void;
41
+ /**
42
+ * Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
43
+ */
44
+ processCheckpointL1Timing(data: {
45
+ slotNumber: SlotNumber;
46
+ l1Timestamp: bigint;
47
+ l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'>;
48
+ }): void;
36
49
  }
37
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5zdHJ1bWVudGF0aW9uLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbW9kdWxlcy9pbnN0cnVtZW50YXRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDdEQsT0FBTyxFQUtMLEtBQUssaUJBQWlCLEVBRXRCLEtBQUssZUFBZSxFQUNwQixLQUFLLE1BQU0sRUFFWixNQUFNLHlCQUF5QixDQUFDO0FBRWpDLHFCQUFhLHVCQUF1QjtJQTBCaEMsT0FBTyxDQUFDLFNBQVM7SUF6Qm5CLFNBQWdCLE1BQU0sRUFBRSxNQUFNLENBQUM7SUFFL0IsT0FBTyxDQUFDLFdBQVcsQ0FBUTtJQUMzQixPQUFPLENBQUMsT0FBTyxDQUFnQjtJQUMvQixPQUFPLENBQUMsYUFBYSxDQUFRO0lBQzdCLE9BQU8sQ0FBQyxvQkFBb0IsQ0FBWTtJQUN4QyxPQUFPLENBQUMsb0JBQW9CLENBQWdCO0lBQzVDLE9BQU8sQ0FBQyxTQUFTLENBQWM7SUFFL0IsT0FBTyxDQUFDLGFBQWEsQ0FBWTtJQUNqQyxPQUFPLENBQUMsVUFBVSxDQUFnQjtJQUVsQyxPQUFPLENBQUMsb0JBQW9CLENBQVk7SUFDeEMsT0FBTyxDQUFDLGNBQWMsQ0FBZ0I7SUFDdEMsT0FBTyxDQUFDLFlBQVksQ0FBWTtJQUNoQyxPQUFPLENBQUMsV0FBV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