@aztec/archiver 0.0.1-commit.d1f2d6c → 0.0.1-commit.d20b825a7

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 (120) hide show
  1. package/README.md +12 -6
  2. package/dest/archiver.d.ts +16 -10
  3. package/dest/archiver.d.ts.map +1 -1
  4. package/dest/archiver.js +110 -122
  5. package/dest/config.d.ts +5 -3
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +15 -3
  8. package/dest/errors.d.ts +55 -10
  9. package/dest/errors.d.ts.map +1 -1
  10. package/dest/errors.js +74 -15
  11. package/dest/factory.d.ts +5 -4
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +34 -29
  14. package/dest/index.d.ts +4 -2
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +3 -1
  17. package/dest/l1/bin/retrieve-calldata.js +36 -33
  18. package/dest/l1/calldata_retriever.d.ts +73 -50
  19. package/dest/l1/calldata_retriever.d.ts.map +1 -1
  20. package/dest/l1/calldata_retriever.js +191 -259
  21. package/dest/l1/data_retrieval.d.ts +26 -17
  22. package/dest/l1/data_retrieval.d.ts.map +1 -1
  23. package/dest/l1/data_retrieval.js +43 -48
  24. package/dest/l1/spire_proposer.d.ts +5 -5
  25. package/dest/l1/spire_proposer.d.ts.map +1 -1
  26. package/dest/l1/spire_proposer.js +9 -17
  27. package/dest/l1/validate_historical_logs.d.ts +23 -0
  28. package/dest/l1/validate_historical_logs.d.ts.map +1 -0
  29. package/dest/l1/validate_historical_logs.js +108 -0
  30. package/dest/l1/validate_trace.d.ts +6 -3
  31. package/dest/l1/validate_trace.d.ts.map +1 -1
  32. package/dest/l1/validate_trace.js +13 -9
  33. package/dest/modules/data_source_base.d.ts +17 -10
  34. package/dest/modules/data_source_base.d.ts.map +1 -1
  35. package/dest/modules/data_source_base.js +39 -77
  36. package/dest/modules/data_store_updater.d.ts +50 -26
  37. package/dest/modules/data_store_updater.d.ts.map +1 -1
  38. package/dest/modules/data_store_updater.js +169 -130
  39. package/dest/modules/instrumentation.d.ts +21 -3
  40. package/dest/modules/instrumentation.d.ts.map +1 -1
  41. package/dest/modules/instrumentation.js +58 -18
  42. package/dest/modules/l1_synchronizer.d.ts +10 -9
  43. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  44. package/dest/modules/l1_synchronizer.js +285 -157
  45. package/dest/modules/validation.d.ts +1 -1
  46. package/dest/modules/validation.d.ts.map +1 -1
  47. package/dest/modules/validation.js +2 -2
  48. package/dest/store/block_store.d.ts +85 -36
  49. package/dest/store/block_store.d.ts.map +1 -1
  50. package/dest/store/block_store.js +433 -162
  51. package/dest/store/contract_class_store.d.ts +2 -3
  52. package/dest/store/contract_class_store.d.ts.map +1 -1
  53. package/dest/store/contract_class_store.js +16 -72
  54. package/dest/store/contract_instance_store.d.ts +1 -1
  55. package/dest/store/contract_instance_store.d.ts.map +1 -1
  56. package/dest/store/contract_instance_store.js +6 -2
  57. package/dest/store/kv_archiver_store.d.ts +76 -32
  58. package/dest/store/kv_archiver_store.d.ts.map +1 -1
  59. package/dest/store/kv_archiver_store.js +92 -37
  60. package/dest/store/l2_tips_cache.d.ts +20 -0
  61. package/dest/store/l2_tips_cache.d.ts.map +1 -0
  62. package/dest/store/l2_tips_cache.js +109 -0
  63. package/dest/store/log_store.d.ts +6 -3
  64. package/dest/store/log_store.d.ts.map +1 -1
  65. package/dest/store/log_store.js +151 -56
  66. package/dest/store/message_store.d.ts +5 -1
  67. package/dest/store/message_store.d.ts.map +1 -1
  68. package/dest/store/message_store.js +21 -9
  69. package/dest/test/fake_l1_state.d.ts +24 -1
  70. package/dest/test/fake_l1_state.d.ts.map +1 -1
  71. package/dest/test/fake_l1_state.js +145 -28
  72. package/dest/test/index.js +3 -1
  73. package/dest/test/mock_archiver.d.ts +1 -1
  74. package/dest/test/mock_archiver.d.ts.map +1 -1
  75. package/dest/test/mock_archiver.js +3 -2
  76. package/dest/test/mock_l1_to_l2_message_source.d.ts +1 -1
  77. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  78. package/dest/test/mock_l1_to_l2_message_source.js +2 -1
  79. package/dest/test/mock_l2_block_source.d.ts +31 -10
  80. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  81. package/dest/test/mock_l2_block_source.js +163 -92
  82. package/dest/test/mock_structs.d.ts +6 -2
  83. package/dest/test/mock_structs.d.ts.map +1 -1
  84. package/dest/test/mock_structs.js +20 -6
  85. package/dest/test/noop_l1_archiver.d.ts +26 -0
  86. package/dest/test/noop_l1_archiver.d.ts.map +1 -0
  87. package/dest/test/noop_l1_archiver.js +74 -0
  88. package/package.json +14 -13
  89. package/src/archiver.ts +150 -146
  90. package/src/config.ts +22 -2
  91. package/src/errors.ts +116 -26
  92. package/src/factory.ts +49 -26
  93. package/src/index.ts +3 -1
  94. package/src/l1/README.md +25 -68
  95. package/src/l1/bin/retrieve-calldata.ts +46 -39
  96. package/src/l1/calldata_retriever.ts +250 -379
  97. package/src/l1/data_retrieval.ts +59 -70
  98. package/src/l1/spire_proposer.ts +7 -15
  99. package/src/l1/validate_historical_logs.ts +140 -0
  100. package/src/l1/validate_trace.ts +24 -6
  101. package/src/modules/data_source_base.ts +81 -101
  102. package/src/modules/data_store_updater.ts +202 -160
  103. package/src/modules/instrumentation.ts +71 -19
  104. package/src/modules/l1_synchronizer.ts +365 -197
  105. package/src/modules/validation.ts +2 -2
  106. package/src/store/block_store.ts +546 -206
  107. package/src/store/contract_class_store.ts +16 -110
  108. package/src/store/contract_instance_store.ts +8 -5
  109. package/src/store/kv_archiver_store.ts +143 -53
  110. package/src/store/l2_tips_cache.ts +134 -0
  111. package/src/store/log_store.ts +225 -67
  112. package/src/store/message_store.ts +27 -10
  113. package/src/structs/inbox_message.ts +1 -1
  114. package/src/test/fake_l1_state.ts +193 -32
  115. package/src/test/index.ts +3 -0
  116. package/src/test/mock_archiver.ts +3 -2
  117. package/src/test/mock_l1_to_l2_message_source.ts +1 -0
  118. package/src/test/mock_l2_block_source.ts +217 -90
  119. package/src/test/mock_structs.ts +42 -12
  120. package/src/test/noop_l1_archiver.ts +117 -0
@@ -1,10 +1,10 @@
1
1
  import { BlockNumber } from '@aztec/foundation/branded-types';
2
- import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { filterAsync } from '@aztec/foundation/collection';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
- import { ContractClassPublishedEvent, PrivateFunctionBroadcastedEvent, UtilityFunctionBroadcastedEvent } from '@aztec/protocol-contracts/class-registry';
4
+ import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
5
5
  import { ContractInstancePublishedEvent, ContractInstanceUpdatedEvent } from '@aztec/protocol-contracts/instance-registry';
6
- import { computePublicBytecodeCommitment, isValidPrivateFunctionMembershipProof, isValidUtilityFunctionMembershipProof } from '@aztec/stdlib/contract';
7
- import groupBy from 'lodash.groupby';
6
+ import { validateCheckpoint } from '@aztec/stdlib/checkpoint';
7
+ import { computeContractAddressFromInstance, computeContractClassId } from '@aztec/stdlib/contract';
8
8
  /** Operation type for contract data updates. */ var Operation = /*#__PURE__*/ function(Operation) {
9
9
  Operation[Operation["Store"] = 0] = "Store";
10
10
  Operation[Operation["Delete"] = 1] = "Delete";
@@ -12,49 +12,69 @@ 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;
16
+ opts;
15
17
  log;
16
- constructor(store){
18
+ constructor(store, l2TipsCache, opts = {}){
17
19
  this.store = store;
20
+ this.l2TipsCache = l2TipsCache;
21
+ this.opts = opts;
18
22
  this.log = createLogger('archiver:store_updater');
19
23
  }
20
24
  /**
21
- * Adds blocks to the store with contract class/instance extraction from logs.
22
- * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
23
- * and individually broadcasted functions from the block logs.
25
+ * Adds a proposed block to the store with contract class/instance extraction from logs.
26
+ * This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
27
+ * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the block logs.
24
28
  *
25
- * @param blocks - The L2 blocks to add.
29
+ * @param block - The proposed L2 block to add.
26
30
  * @param pendingChainValidationStatus - Optional validation status to set.
27
31
  * @returns True if the operation is successful.
28
- */ addBlocks(blocks, pendingChainValidationStatus) {
29
- return this.store.transactionAsync(async ()=>{
30
- await this.store.addBlocks(blocks);
32
+ */ async addProposedBlock(block, pendingChainValidationStatus) {
33
+ const result = await this.store.transactionAsync(async ()=>{
34
+ await this.store.addProposedBlock(block);
31
35
  const opResults = await Promise.all([
32
36
  // Update the pending chain validation status if provided
33
37
  pendingChainValidationStatus && this.store.setPendingChainValidationStatus(pendingChainValidationStatus),
34
- // Add any logs emitted during the retrieved blocks
35
- this.store.addLogs(blocks),
36
- // Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
37
- ...blocks.map((block)=>this.addBlockDataToDB(block))
38
+ // Add any logs emitted during the retrieved block
39
+ this.store.addLogs([
40
+ block
41
+ ]),
42
+ // Unroll all logs emitted during the retrieved block and extract any contract classes and instances from it
43
+ this.addContractDataToDb(block)
38
44
  ]);
45
+ await this.l2TipsCache?.refresh();
39
46
  return opResults.every(Boolean);
40
47
  });
48
+ return result;
41
49
  }
42
50
  /**
43
51
  * Reconciles local blocks with incoming checkpoints from L1.
44
- * Adds checkpoints to the store with contract class/instance extraction from logs.
52
+ * Adds new checkpoints to the store with contract class/instance extraction from logs.
45
53
  * Prunes any local blocks that conflict with checkpoint data (by comparing archive roots).
46
- * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
47
- * and individually broadcasted functions from the checkpoint block logs.
54
+ * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the checkpoint block logs.
55
+ * If `promoteProposed` is supplied, the proposed-checkpoint promotion runs inside the same transaction
56
+ * as the added checkpoints so both updates are applied atomically.
48
57
  *
49
- * @param checkpoints - The published checkpoints to add.
58
+ * @param checkpoints - The published checkpoints to add (excluding any being promoted from proposed).
50
59
  * @param pendingChainValidationStatus - Optional validation status to set.
60
+ * @param promoteProposed - Optional promotion of the current proposed checkpoint (fast path when blocks are already local).
51
61
  * @returns Result with information about any pruned blocks.
52
- */ setNewCheckpointData(checkpoints, pendingChainValidationStatus) {
53
- return this.store.transactionAsync(async ()=>{
62
+ */ async addCheckpoints(checkpoints, pendingChainValidationStatus, promoteProposed) {
63
+ for (const checkpoint of checkpoints){
64
+ validateCheckpoint(checkpoint.checkpoint, {
65
+ rollupManaLimit: this.opts?.rollupManaLimit
66
+ });
67
+ }
68
+ if (promoteProposed) {
69
+ validateCheckpoint(promoteProposed.checkpoint.checkpoint, {
70
+ rollupManaLimit: this.opts?.rollupManaLimit
71
+ });
72
+ }
73
+ const result = await this.store.transactionAsync(async ()=>{
54
74
  // Before adding checkpoints, check for conflicts with local blocks if any
55
75
  const { prunedBlocks, lastAlreadyInsertedBlockNumber } = await this.pruneMismatchingLocalBlocks(checkpoints);
56
76
  await this.store.addCheckpoints(checkpoints);
57
- // Filter out blocks that were already inserted via addBlocks() to avoid duplicating logs/contract data
77
+ // Filter out blocks that were already inserted via addProposedBlock() to avoid duplicating logs/contract data
58
78
  const newBlocks = checkpoints.flatMap((ch)=>ch.checkpoint.blocks).filter((b)=>lastAlreadyInsertedBlockNumber === undefined || b.number > lastAlreadyInsertedBlockNumber);
59
79
  await Promise.all([
60
80
  // Update the pending chain validation status if provided
@@ -62,13 +82,24 @@ import groupBy from 'lodash.groupby';
62
82
  // Add any logs emitted during the retrieved blocks
63
83
  this.store.addLogs(newBlocks),
64
84
  // Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
65
- ...newBlocks.map((block)=>this.addBlockDataToDB(block))
85
+ ...newBlocks.map((block)=>this.addContractDataToDb(block)),
86
+ // Promote the proposed checkpoint if requested
87
+ promoteProposed ? this.store.promoteProposedToCheckpointed(promoteProposed.l1, promoteProposed.attestations, promoteProposed.checkpoint.checkpoint.archive.root) : undefined
66
88
  ]);
89
+ await this.l2TipsCache?.refresh();
67
90
  return {
68
91
  prunedBlocks,
69
92
  lastAlreadyInsertedBlockNumber
70
93
  };
71
94
  });
95
+ return result;
96
+ }
97
+ async setProposedCheckpoint(proposedCheckpoint) {
98
+ const result = await this.store.transactionAsync(async ()=>{
99
+ await this.store.setProposedCheckpoint(proposedCheckpoint);
100
+ await this.l2TipsCache?.refresh();
101
+ });
102
+ return result;
72
103
  }
73
104
  /**
74
105
  * Checks for local proposed blocks that do not match the ones to be checkpointed and prunes them.
@@ -112,7 +143,7 @@ import groupBy from 'lodash.groupby';
112
143
  this.log.verbose(`Block number ${blockNumber} already inserted and matches checkpoint`, blockInfos);
113
144
  lastAlreadyInsertedBlockNumber = blockNumber;
114
145
  } else {
115
- this.log.warn(`Conflict detected at block ${blockNumber} between checkpointed and local block`, blockInfos);
146
+ this.log.info(`Conflict detected at block ${blockNumber} between checkpointed and local block`, blockInfos);
116
147
  const prunedBlocks = await this.removeBlocksAfter(BlockNumber(blockNumber - 1));
117
148
  return {
118
149
  prunedBlocks,
@@ -139,98 +170,152 @@ import groupBy from 'lodash.groupby';
139
170
  };
140
171
  }
141
172
  /**
142
- * Removes all blocks strictly after the specified block number and cleans up associated contract data.
173
+ * Removes all uncheckpointed blocks strictly after the specified block number and cleans up associated contract data.
143
174
  * This handles removal of provisionally added blocks along with their contract classes/instances.
175
+ * Verifies that each block being removed is not part of a stored checkpoint.
144
176
  *
145
177
  * @param blockNumber - Remove all blocks with number greater than this.
146
178
  * @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;
179
+ * @throws Error if any block to be removed is checkpointed.
180
+ */ async removeUncheckpointedBlocksAfter(blockNumber) {
181
+ const result = await this.store.transactionAsync(async ()=>{
182
+ // Verify we're only removing uncheckpointed blocks
183
+ const lastCheckpointedBlockNumber = await this.store.getCheckpointedL2BlockNumber();
184
+ if (blockNumber < lastCheckpointedBlockNumber) {
185
+ throw new Error(`Cannot remove blocks after ${blockNumber} because checkpointed blocks exist up to ${lastCheckpointedBlockNumber}`);
186
+ }
187
+ const result = await this.removeBlocksAfter(blockNumber);
188
+ // Clear the proposed checkpoint if it exists, since its blocks have been pruned
189
+ await this.store.deleteProposedCheckpoint();
190
+ await this.l2TipsCache?.refresh();
191
+ return result;
157
192
  });
193
+ return result;
194
+ }
195
+ /**
196
+ * Removes all blocks strictly after the given block number along with any logs and contract data.
197
+ * Does not remove their checkpoints.
198
+ */ async removeBlocksAfter(blockNumber) {
199
+ // First get the blocks to be removed so we can clean up contract data
200
+ const removedBlocks = await this.store.removeBlocksAfter(blockNumber);
201
+ // Clean up contract data and logs for the removed blocks
202
+ await Promise.all([
203
+ this.store.deleteLogs(removedBlocks),
204
+ ...removedBlocks.map((block)=>this.removeContractDataFromDb(block))
205
+ ]);
206
+ return removedBlocks;
158
207
  }
159
208
  /**
160
- * Unwinds checkpoints from the store with reverse contract extraction.
209
+ * Removes all checkpoints after the given checkpoint number.
161
210
  * Deletes ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated data
162
- * that was stored for the unwound checkpoints.
211
+ * that was stored for the removed checkpoints. Also removes ALL blocks (both checkpointed
212
+ * and uncheckpointed) after the last block of the given checkpoint.
163
213
  *
164
- * @param from - The checkpoint number to unwind from (must be the current tip).
165
- * @param checkpointsToUnwind - The number of checkpoints to unwind.
214
+ * @param checkpointNumber - Remove all checkpoints strictly after this one.
166
215
  * @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);
216
+ */ async removeCheckpointsAfter(checkpointNumber) {
217
+ return await this.store.transactionAsync(async ()=>{
218
+ const { blocksRemoved = [] } = await this.store.removeCheckpointsAfter(checkpointNumber);
219
+ const opResults = await Promise.all([
220
+ // Prune rolls back to the last proven block, which is by definition valid
221
+ this.store.setPendingChainValidationStatus({
222
+ valid: true
223
+ }),
224
+ // Remove contract data for all blocks being removed
225
+ ...blocksRemoved.map((block)=>this.removeContractDataFromDb(block)),
226
+ this.store.deleteLogs(blocksRemoved)
227
+ ]);
228
+ await this.l2TipsCache?.refresh();
229
+ return opResults.every(Boolean);
230
+ });
195
231
  }
196
- /** Extracts and stores contract data from a single block. */ addBlockDataToDB(block) {
197
- return this.editContractBlockData(block, 0);
232
+ /**
233
+ * Updates the proven checkpoint number and refreshes the L2 tips cache.
234
+ * @param checkpointNumber - The checkpoint number to set as proven.
235
+ */ async setProvenCheckpointNumber(checkpointNumber) {
236
+ await this.store.transactionAsync(async ()=>{
237
+ await this.store.setProvenCheckpointNumber(checkpointNumber);
238
+ await this.l2TipsCache?.refresh();
239
+ });
198
240
  }
199
- /** Removes contract data associated with a block. */ removeBlockDataFromDB(block) {
200
- return this.editContractBlockData(block, 1);
241
+ /**
242
+ * Updates the finalized checkpoint number and refreshes the L2 tips cache.
243
+ * @param checkpointNumber - The checkpoint number to set as finalized.
244
+ */ async setFinalizedCheckpointNumber(checkpointNumber) {
245
+ await this.store.transactionAsync(async ()=>{
246
+ await this.store.setFinalizedCheckpointNumber(checkpointNumber);
247
+ await this.l2TipsCache?.refresh();
248
+ });
249
+ }
250
+ /** Extracts and stores contract data from a single block. */ addContractDataToDb(block) {
251
+ return this.updateContractDataOnDb(block, 0);
252
+ }
253
+ /** Removes contract data associated with a block. */ removeContractDataFromDb(block) {
254
+ return this.updateContractDataOnDb(block, 1);
201
255
  }
202
- /** Adds or remove contract data associated with a block. */ async editContractBlockData(block, operation) {
256
+ /** Adds or remove contract data associated with a block. */ async updateContractDataOnDb(block, operation) {
203
257
  const contractClassLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.contractClassLogs);
204
258
  const privateLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.privateLogs);
205
259
  const publicLogs = block.body.txEffects.flatMap((txEffect)=>txEffect.publicLogs);
206
260
  return (await Promise.all([
207
261
  this.updatePublishedContractClasses(contractClassLogs, block.number, operation),
208
262
  this.updateDeployedContractInstances(privateLogs, block.number, operation),
209
- this.updateUpdatedContractInstances(publicLogs, block.header.globalVariables.timestamp, operation),
210
- operation === 0 ? this.storeBroadcastedIndividualFunctions(contractClassLogs, block.number) : Promise.resolve(true)
263
+ this.updateUpdatedContractInstances(publicLogs, block.header.globalVariables.timestamp, operation)
211
264
  ])).every(Boolean);
212
265
  }
213
266
  /**
214
267
  * Extracts and stores contract classes out of ContractClassPublished events emitted by the class registry contract.
215
268
  */ async updatePublishedContractClasses(allLogs, blockNum, operation) {
216
269
  const contractClassPublishedEvents = allLogs.filter((log)=>ContractClassPublishedEvent.isContractClassPublishedEvent(log)).map((log)=>ContractClassPublishedEvent.fromLog(log));
217
- const contractClasses = await Promise.all(contractClassPublishedEvents.map((e)=>e.toContractClassPublic()));
218
- if (contractClasses.length > 0) {
219
- contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
220
- if (operation == 0) {
221
- // TODO: Will probably want to create some worker threads to compute these bytecode commitments as they are expensive
222
- const commitments = await Promise.all(contractClasses.map((c)=>computePublicBytecodeCommitment(c.packedBytecode)));
223
- return await this.store.addContractClasses(contractClasses, commitments, blockNum);
224
- } else if (operation == 1) {
270
+ if (operation == 1) {
271
+ const contractClasses = contractClassPublishedEvents.map((e)=>e.toContractClassPublic());
272
+ if (contractClasses.length > 0) {
273
+ contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
225
274
  return await this.store.deleteContractClasses(contractClasses, blockNum);
226
275
  }
276
+ return true;
277
+ }
278
+ // Compute bytecode commitments and validate class IDs in a single pass.
279
+ const contractClasses = [];
280
+ for (const event of contractClassPublishedEvents){
281
+ const contractClass = await event.toContractClassPublicWithBytecodeCommitment();
282
+ const computedClassId = await computeContractClassId({
283
+ artifactHash: contractClass.artifactHash,
284
+ privateFunctionsRoot: contractClass.privateFunctionsRoot,
285
+ publicBytecodeCommitment: contractClass.publicBytecodeCommitment
286
+ });
287
+ if (!computedClassId.equals(contractClass.id)) {
288
+ this.log.warn(`Skipping contract class with mismatched id at block ${blockNum}. Claimed ${contractClass.id}, computed ${computedClassId}`, {
289
+ blockNum,
290
+ contractClassId: event.contractClassId.toString()
291
+ });
292
+ continue;
293
+ }
294
+ contractClasses.push(contractClass);
295
+ }
296
+ if (contractClasses.length > 0) {
297
+ contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
298
+ return await this.store.addContractClasses(contractClasses, blockNum);
227
299
  }
228
300
  return true;
229
301
  }
230
302
  /**
231
303
  * Extracts and stores contract instances out of ContractInstancePublished events emitted by the canonical deployer contract.
232
304
  */ async updateDeployedContractInstances(allLogs, blockNum, operation) {
233
- const contractInstances = allLogs.filter((log)=>ContractInstancePublishedEvent.isContractInstancePublishedEvent(log)).map((log)=>ContractInstancePublishedEvent.fromLog(log)).map((e)=>e.toContractInstance());
305
+ const allInstances = allLogs.filter((log)=>ContractInstancePublishedEvent.isContractInstancePublishedEvent(log)).map((log)=>ContractInstancePublishedEvent.fromLog(log)).map((e)=>e.toContractInstance());
306
+ // Verify that each instance's address matches the one derived from its fields if we're adding
307
+ const contractInstances = operation === 1 ? allInstances : await filterAsync(allInstances, async (instance)=>{
308
+ const computedAddress = await computeContractAddressFromInstance(instance);
309
+ if (!computedAddress.equals(instance.address)) {
310
+ this.log.warn(`Found contract instance with mismatched address at block ${blockNum}. Claimed ${instance.address} but computed ${computedAddress}.`, {
311
+ instanceAddress: instance.address.toString(),
312
+ computedAddress: computedAddress.toString(),
313
+ blockNum
314
+ });
315
+ return false;
316
+ }
317
+ return true;
318
+ });
234
319
  if (contractInstances.length > 0) {
235
320
  contractInstances.forEach((c)=>this.log.verbose(`${Operation[operation]} contract instance at ${c.address.toString()}`));
236
321
  if (operation == 0) {
@@ -255,50 +340,4 @@ import groupBy from 'lodash.groupby';
255
340
  }
256
341
  return true;
257
342
  }
258
- /**
259
- * Stores the functions that were broadcasted individually.
260
- *
261
- * @dev Beware that there is not a delete variant of this, since they are added to contract classes
262
- * and will be deleted as part of the class if needed.
263
- */ async storeBroadcastedIndividualFunctions(allLogs, _blockNum) {
264
- // Filter out private and utility function broadcast events
265
- const privateFnEvents = allLogs.filter((log)=>PrivateFunctionBroadcastedEvent.isPrivateFunctionBroadcastedEvent(log)).map((log)=>PrivateFunctionBroadcastedEvent.fromLog(log));
266
- const utilityFnEvents = allLogs.filter((log)=>UtilityFunctionBroadcastedEvent.isUtilityFunctionBroadcastedEvent(log)).map((log)=>UtilityFunctionBroadcastedEvent.fromLog(log));
267
- // Group all events by contract class id
268
- for (const [classIdString, classEvents] of Object.entries(groupBy([
269
- ...privateFnEvents,
270
- ...utilityFnEvents
271
- ], (e)=>e.contractClassId.toString()))){
272
- const contractClassId = Fr.fromHexString(classIdString);
273
- const contractClass = await this.store.getContractClass(contractClassId);
274
- if (!contractClass) {
275
- this.log.warn(`Skipping broadcasted functions as contract class ${contractClassId.toString()} was not found`);
276
- continue;
277
- }
278
- // Split private and utility functions, and filter out invalid ones
279
- const allFns = classEvents.map((e)=>e.toFunctionWithMembershipProof());
280
- const privateFns = allFns.filter((fn)=>'utilityFunctionsTreeRoot' in fn);
281
- const utilityFns = allFns.filter((fn)=>'privateFunctionsArtifactTreeRoot' in fn);
282
- const privateFunctionsWithValidity = await Promise.all(privateFns.map(async (fn)=>({
283
- fn,
284
- valid: await isValidPrivateFunctionMembershipProof(fn, contractClass)
285
- })));
286
- const validPrivateFns = privateFunctionsWithValidity.filter(({ valid })=>valid).map(({ fn })=>fn);
287
- const utilityFunctionsWithValidity = await Promise.all(utilityFns.map(async (fn)=>({
288
- fn,
289
- valid: await isValidUtilityFunctionMembershipProof(fn, contractClass)
290
- })));
291
- const validUtilityFns = utilityFunctionsWithValidity.filter(({ valid })=>valid).map(({ fn })=>fn);
292
- const validFnCount = validPrivateFns.length + validUtilityFns.length;
293
- if (validFnCount !== allFns.length) {
294
- this.log.warn(`Skipping ${allFns.length - validFnCount} invalid functions`);
295
- }
296
- // Store the functions in the contract class in a single operation
297
- if (validFnCount > 0) {
298
- this.log.verbose(`Storing ${validFnCount} functions for contract class ${contractClassId.toString()}`);
299
- }
300
- return await this.store.addFunctions(contractClassId, validPrivateFns, validUtilityFns);
301
- }
302
- return true;
303
- }
304
343
  }
@@ -1,9 +1,13 @@
1
+ import type { SlotNumber } from '@aztec/foundation/branded-types';
1
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;
@@ -12,20 +16,24 @@ export declare class ArchiverInstrumentation {
12
16
  private pruneDuration;
13
17
  private pruneCount;
14
18
  private syncDurationPerBlock;
19
+ private syncDurationPerCheckpoint;
15
20
  private syncBlockCount;
16
21
  private manaPerBlock;
17
22
  private txsPerBlock;
18
23
  private syncDurationPerMessage;
19
24
  private syncMessageCount;
20
25
  private blockProposalTxTargetCount;
26
+ private checkpointL1InclusionDelay;
27
+ private checkpointPromotedCount;
21
28
  private log;
22
29
  private constructor();
23
30
  static new(telemetry: TelemetryClient, lmdbStats?: LmdbStatsCallback): Promise<ArchiverInstrumentation>;
24
31
  isEnabled(): boolean;
25
- processNewBlocks(syncTimePerBlock: number, blocks: L2Block[]): void;
32
+ processNewProposedBlock(syncTimePerBlock: number, block: L2Block): void;
33
+ processNewCheckpointedBlocks(syncTimePerCheckpoint: number, blocks: L2Block[]): void;
26
34
  processNewMessages(count: number, syncPerMessageMs: number): void;
27
35
  processPrune(duration: number): void;
28
- updateLastProvenBlock(blockNumber: number): void;
36
+ updateLastProvenCheckpoint(checkpoint: CheckpointData): void;
29
37
  processProofsVerified(logs: {
30
38
  proverId: string;
31
39
  l2BlockNumber: bigint;
@@ -33,5 +41,15 @@ export declare class ArchiverInstrumentation {
33
41
  }[]): void;
34
42
  updateL1BlockHeight(blockNumber: bigint): void;
35
43
  recordBlockProposalTxTarget(target: string, usedTrace: boolean): void;
44
+ /** Records a checkpoint promoted from proposed (blob fetch skipped). */
45
+ processCheckpointPromoted(): void;
46
+ /**
47
+ * Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
48
+ */
49
+ processCheckpointL1Timing(data: {
50
+ slotNumber: SlotNumber;
51
+ l1Timest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AAc,CAAC,CAAC;KACxE,GAAG,IAAI,CAIP;CACF"}
@@ -1,9 +1,11 @@
1
1
  import { createLogger } from '@aztec/foundation/log';
2
- import { Attributes, LmdbMetrics, Metrics } from '@aztec/telemetry-client';
2
+ import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
3
+ import { Attributes, LmdbMetrics, Metrics, createUpDownCounterWithDefault } from '@aztec/telemetry-client';
3
4
  export class ArchiverInstrumentation {
4
5
  telemetry;
5
6
  tracer;
6
7
  blockHeight;
8
+ checkpointHeight;
7
9
  txCount;
8
10
  l1BlockHeight;
9
11
  proofsSubmittedDelay;
@@ -12,12 +14,15 @@ export class ArchiverInstrumentation {
12
14
  pruneDuration;
13
15
  pruneCount;
14
16
  syncDurationPerBlock;
17
+ syncDurationPerCheckpoint;
15
18
  syncBlockCount;
16
19
  manaPerBlock;
17
20
  txsPerBlock;
18
21
  syncDurationPerMessage;
19
22
  syncMessageCount;
20
23
  blockProposalTxTargetCount;
24
+ checkpointL1InclusionDelay;
25
+ checkpointPromotedCount;
21
26
  log;
22
27
  constructor(telemetry, lmdbStats){
23
28
  this.telemetry = telemetry;
@@ -25,43 +30,64 @@ export class ArchiverInstrumentation {
25
30
  this.tracer = telemetry.getTracer('Archiver');
26
31
  const meter = telemetry.getMeter('Archiver');
27
32
  this.blockHeight = meter.createGauge(Metrics.ARCHIVER_BLOCK_HEIGHT);
33
+ this.checkpointHeight = meter.createGauge(Metrics.ARCHIVER_CHECKPOINT_HEIGHT);
28
34
  this.l1BlockHeight = meter.createGauge(Metrics.ARCHIVER_L1_BLOCK_HEIGHT);
29
- this.txCount = meter.createUpDownCounter(Metrics.ARCHIVER_TOTAL_TXS);
30
- this.proofsSubmittedCount = meter.createUpDownCounter(Metrics.ARCHIVER_ROLLUP_PROOF_COUNT);
35
+ this.txCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_TOTAL_TXS);
36
+ this.proofsSubmittedCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_ROLLUP_PROOF_COUNT, {
37
+ [Attributes.PROOF_TIMED_OUT]: [
38
+ true,
39
+ false
40
+ ]
41
+ });
31
42
  this.proofsSubmittedDelay = meter.createHistogram(Metrics.ARCHIVER_ROLLUP_PROOF_DELAY);
32
43
  this.syncDurationPerBlock = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_BLOCK);
33
- this.syncBlockCount = meter.createUpDownCounter(Metrics.ARCHIVER_SYNC_BLOCK_COUNT);
44
+ this.syncDurationPerCheckpoint = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_CHECKPOINT);
45
+ this.syncBlockCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_BLOCK_COUNT);
34
46
  this.manaPerBlock = meter.createHistogram(Metrics.ARCHIVER_MANA_PER_BLOCK);
35
47
  this.txsPerBlock = meter.createHistogram(Metrics.ARCHIVER_TXS_PER_BLOCK);
36
48
  this.syncDurationPerMessage = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_MESSAGE);
37
- this.syncMessageCount = meter.createUpDownCounter(Metrics.ARCHIVER_SYNC_MESSAGE_COUNT);
49
+ this.syncMessageCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_MESSAGE_COUNT);
38
50
  this.pruneDuration = meter.createHistogram(Metrics.ARCHIVER_PRUNE_DURATION);
39
- this.pruneCount = meter.createUpDownCounter(Metrics.ARCHIVER_PRUNE_COUNT);
40
- this.blockProposalTxTargetCount = meter.createUpDownCounter(Metrics.ARCHIVER_BLOCK_PROPOSAL_TX_TARGET_COUNT);
51
+ this.pruneCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_PRUNE_COUNT);
52
+ this.blockProposalTxTargetCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_BLOCK_PROPOSAL_TX_TARGET_COUNT, {
53
+ [Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: [
54
+ true,
55
+ false
56
+ ]
57
+ });
58
+ this.checkpointL1InclusionDelay = meter.createHistogram(Metrics.ARCHIVER_CHECKPOINT_L1_INCLUSION_DELAY);
59
+ this.checkpointPromotedCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_CHECKPOINT_PROMOTED_COUNT);
41
60
  this.dbMetrics = new LmdbMetrics(meter, {
42
61
  [Attributes.DB_DATA_TYPE]: 'archiver'
43
62
  }, lmdbStats);
44
63
  }
45
64
  static async new(telemetry, lmdbStats) {
46
65
  const instance = new ArchiverInstrumentation(telemetry, lmdbStats);
47
- instance.syncBlockCount.add(0);
48
- instance.syncMessageCount.add(0);
49
- instance.pruneCount.add(0);
50
66
  await instance.telemetry.flush();
51
67
  return instance;
52
68
  }
53
69
  isEnabled() {
54
70
  return this.telemetry.isEnabled();
55
71
  }
56
- processNewBlocks(syncTimePerBlock, blocks) {
72
+ processNewProposedBlock(syncTimePerBlock, block) {
73
+ const attrs = {
74
+ [Attributes.STATUS]: 'proposed'
75
+ };
76
+ this.blockHeight.record(block.number, attrs);
57
77
  this.syncDurationPerBlock.record(Math.ceil(syncTimePerBlock));
78
+ // Per block metrics
79
+ this.txCount.add(block.body.txEffects.length);
80
+ this.txsPerBlock.record(block.body.txEffects.length);
81
+ this.manaPerBlock.record(block.header.totalManaUsed.toNumber() / 1e6);
82
+ }
83
+ processNewCheckpointedBlocks(syncTimePerCheckpoint, blocks) {
84
+ if (blocks.length === 0) {
85
+ return;
86
+ }
87
+ this.syncDurationPerCheckpoint.record(Math.ceil(syncTimePerCheckpoint));
58
88
  this.blockHeight.record(Math.max(...blocks.map((b)=>b.number)));
89
+ this.checkpointHeight.record(Math.max(...blocks.map((b)=>b.checkpointNumber)));
59
90
  this.syncBlockCount.add(blocks.length);
60
- for (const block of blocks){
61
- this.txCount.add(block.body.txEffects.length);
62
- this.txsPerBlock.record(block.body.txEffects.length);
63
- this.manaPerBlock.record(block.header.totalManaUsed.toNumber() / 1e6);
64
- }
65
91
  }
66
92
  processNewMessages(count, syncPerMessageMs) {
67
93
  if (count === 0) {
@@ -74,8 +100,12 @@ export class ArchiverInstrumentation {
74
100
  this.pruneCount.add(1);
75
101
  this.pruneDuration.record(Math.ceil(duration));
76
102
  }
77
- updateLastProvenBlock(blockNumber) {
78
- this.blockHeight.record(blockNumber, {
103
+ updateLastProvenCheckpoint(checkpoint) {
104
+ const lastBlockNumberInCheckpoint = checkpoint.startBlock + checkpoint.blockCount - 1;
105
+ this.blockHeight.record(lastBlockNumberInCheckpoint, {
106
+ [Attributes.STATUS]: 'proven'
107
+ });
108
+ this.checkpointHeight.record(checkpoint.checkpointNumber, {
79
109
  [Attributes.STATUS]: 'proven'
80
110
  });
81
111
  }
@@ -100,4 +130,14 @@ export class ArchiverInstrumentation {
100
130
  [Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: usedTrace
101
131
  });
102
132
  }
133
+ /** Records a checkpoint promoted from proposed (blob fetch skipped). */ processCheckpointPromoted() {
134
+ this.checkpointPromotedCount.add(1);
135
+ }
136
+ /**
137
+ * Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
138
+ */ processCheckpointL1Timing(data) {
139
+ const slotStartTs = getTimestampForSlot(data.slotNumber, data.l1Constants);
140
+ const inclusionDelaySeconds = Number(data.l1Timestamp - slotStartTs);
141
+ this.checkpointL1InclusionDelay.record(inclusionDelaySeconds);
142
+ }
103
143
  }