@aztec/archiver 0.0.1-commit.a89ec08 → 0.0.1-commit.aa0c64f

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 (121) hide show
  1. package/README.md +19 -11
  2. package/dest/archiver.d.ts +71 -16
  3. package/dest/archiver.d.ts.map +1 -1
  4. package/dest/archiver.js +276 -71
  5. package/dest/config.d.ts +7 -3
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +43 -14
  8. package/dest/errors.d.ts +50 -2
  9. package/dest/errors.d.ts.map +1 -1
  10. package/dest/errors.js +74 -2
  11. package/dest/factory.d.ts +19 -7
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +67 -24
  14. package/dest/index.d.ts +11 -3
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +10 -2
  17. package/dest/l1/calldata_retriever.d.ts +9 -1
  18. package/dest/l1/calldata_retriever.d.ts.map +1 -1
  19. package/dest/l1/calldata_retriever.js +22 -11
  20. package/dest/l1/data_retrieval.d.ts +30 -13
  21. package/dest/l1/data_retrieval.d.ts.map +1 -1
  22. package/dest/l1/data_retrieval.js +36 -37
  23. package/dest/l1/trace_tx.d.ts +12 -66
  24. package/dest/l1/trace_tx.d.ts.map +1 -1
  25. package/dest/l1/validate_historical_logs.d.ts +23 -0
  26. package/dest/l1/validate_historical_logs.d.ts.map +1 -0
  27. package/dest/l1/validate_historical_logs.js +108 -0
  28. package/dest/modules/contract_data_source_adapter.d.ts +25 -0
  29. package/dest/modules/contract_data_source_adapter.d.ts.map +1 -0
  30. package/dest/modules/contract_data_source_adapter.js +32 -0
  31. package/dest/modules/data_source_base.d.ts +71 -48
  32. package/dest/modules/data_source_base.d.ts.map +1 -1
  33. package/dest/modules/data_source_base.js +250 -144
  34. package/dest/modules/data_store_updater.d.ts +30 -13
  35. package/dest/modules/data_store_updater.d.ts.map +1 -1
  36. package/dest/modules/data_store_updater.js +129 -111
  37. package/dest/modules/instrumentation.d.ts +26 -2
  38. package/dest/modules/instrumentation.d.ts.map +1 -1
  39. package/dest/modules/instrumentation.js +58 -9
  40. package/dest/modules/l1_synchronizer.d.ts +13 -8
  41. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  42. package/dest/modules/l1_synchronizer.js +463 -224
  43. package/dest/modules/outbox_trees_resolver.d.ts +62 -0
  44. package/dest/modules/outbox_trees_resolver.d.ts.map +1 -0
  45. package/dest/modules/outbox_trees_resolver.js +162 -0
  46. package/dest/modules/validation.d.ts +30 -7
  47. package/dest/modules/validation.d.ts.map +1 -1
  48. package/dest/modules/validation.js +35 -17
  49. package/dest/store/block_store.d.ts +175 -68
  50. package/dest/store/block_store.d.ts.map +1 -1
  51. package/dest/store/block_store.js +627 -239
  52. package/dest/store/contract_class_store.d.ts +17 -4
  53. package/dest/store/contract_class_store.d.ts.map +1 -1
  54. package/dest/store/contract_class_store.js +37 -67
  55. package/dest/store/contract_instance_store.d.ts +28 -1
  56. package/dest/store/contract_instance_store.d.ts.map +1 -1
  57. package/dest/store/contract_instance_store.js +49 -1
  58. package/dest/store/data_stores.d.ts +68 -0
  59. package/dest/store/data_stores.d.ts.map +1 -0
  60. package/dest/store/data_stores.js +54 -0
  61. package/dest/store/function_names_cache.d.ts +17 -0
  62. package/dest/store/function_names_cache.d.ts.map +1 -0
  63. package/dest/store/function_names_cache.js +30 -0
  64. package/dest/store/l2_tips_cache.d.ts +13 -7
  65. package/dest/store/l2_tips_cache.d.ts.map +1 -1
  66. package/dest/store/l2_tips_cache.js +13 -76
  67. package/dest/store/log_store.d.ts +42 -37
  68. package/dest/store/log_store.d.ts.map +1 -1
  69. package/dest/store/log_store.js +259 -443
  70. package/dest/store/log_store_codec.d.ts +78 -0
  71. package/dest/store/log_store_codec.d.ts.map +1 -0
  72. package/dest/store/log_store_codec.js +110 -0
  73. package/dest/store/message_store.d.ts +11 -1
  74. package/dest/store/message_store.d.ts.map +1 -1
  75. package/dest/store/message_store.js +50 -8
  76. package/dest/test/fake_l1_state.d.ts +8 -3
  77. package/dest/test/fake_l1_state.d.ts.map +1 -1
  78. package/dest/test/fake_l1_state.js +78 -21
  79. package/dest/test/mock_l2_block_source.d.ts +48 -50
  80. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  81. package/dest/test/mock_l2_block_source.js +228 -179
  82. package/dest/test/mock_structs.d.ts +1 -1
  83. package/dest/test/mock_structs.d.ts.map +1 -1
  84. package/dest/test/mock_structs.js +2 -2
  85. package/dest/test/noop_l1_archiver.d.ts +14 -6
  86. package/dest/test/noop_l1_archiver.d.ts.map +1 -1
  87. package/dest/test/noop_l1_archiver.js +26 -10
  88. package/package.json +15 -14
  89. package/src/archiver.ts +361 -77
  90. package/src/config.ts +51 -13
  91. package/src/errors.ts +117 -2
  92. package/src/factory.ts +81 -22
  93. package/src/index.ts +18 -2
  94. package/src/l1/calldata_retriever.ts +29 -11
  95. package/src/l1/data_retrieval.ts +60 -54
  96. package/src/l1/validate_historical_logs.ts +140 -0
  97. package/src/modules/contract_data_source_adapter.ts +46 -0
  98. package/src/modules/data_source_base.ts +325 -187
  99. package/src/modules/data_store_updater.ts +155 -139
  100. package/src/modules/instrumentation.ts +63 -10
  101. package/src/modules/l1_synchronizer.ts +630 -273
  102. package/src/modules/outbox_trees_resolver.ts +199 -0
  103. package/src/modules/validation.ts +80 -23
  104. package/src/store/block_store.ts +766 -290
  105. package/src/store/contract_class_store.ts +43 -101
  106. package/src/store/contract_instance_store.ts +61 -1
  107. package/src/store/data_stores.ts +104 -0
  108. package/src/store/function_names_cache.ts +37 -0
  109. package/src/store/l2_tips_cache.ts +16 -70
  110. package/src/store/log_store.ts +298 -609
  111. package/src/store/log_store_codec.ts +143 -0
  112. package/src/store/message_store.ts +59 -9
  113. package/src/structs/inbox_message.ts +1 -1
  114. package/src/test/fake_l1_state.ts +99 -32
  115. package/src/test/mock_l2_block_source.ts +285 -232
  116. package/src/test/mock_structs.ts +5 -2
  117. package/src/test/noop_l1_archiver.ts +54 -11
  118. package/dest/store/kv_archiver_store.d.ts +0 -362
  119. package/dest/store/kv_archiver_store.d.ts.map +0 -1
  120. package/dest/store/kv_archiver_store.js +0 -475
  121. package/src/store/kv_archiver_store.ts +0 -685
@@ -1,24 +1,22 @@
1
1
  import { BlockNumber } from '@aztec/foundation/branded-types';
2
2
  import { filterAsync } from '@aztec/foundation/collection';
3
- import { Fr } from '@aztec/foundation/curves/bn254';
4
3
  import { createLogger } from '@aztec/foundation/log';
5
- import { ContractClassPublishedEvent, PrivateFunctionBroadcastedEvent, UtilityFunctionBroadcastedEvent } from '@aztec/protocol-contracts/class-registry';
4
+ import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
6
5
  import { ContractInstancePublishedEvent, ContractInstanceUpdatedEvent } from '@aztec/protocol-contracts/instance-registry';
7
6
  import { validateCheckpoint } from '@aztec/stdlib/checkpoint';
8
- import { computeContractAddressFromInstance, computeContractClassId, isValidPrivateFunctionMembershipProof, isValidUtilityFunctionMembershipProof } from '@aztec/stdlib/contract';
9
- import groupBy from 'lodash.groupby';
7
+ import { computeContractAddressFromInstance, computeContractClassId } from '@aztec/stdlib/contract';
10
8
  /** Operation type for contract data updates. */ var Operation = /*#__PURE__*/ function(Operation) {
11
9
  Operation[Operation["Store"] = 0] = "Store";
12
10
  Operation[Operation["Delete"] = 1] = "Delete";
13
11
  return Operation;
14
12
  }(Operation || {});
15
13
  /** Archiver helper module to handle updates to the data store. */ export class ArchiverDataStoreUpdater {
16
- store;
14
+ stores;
17
15
  l2TipsCache;
18
16
  opts;
19
17
  log;
20
- constructor(store, l2TipsCache, opts = {}){
21
- this.store = store;
18
+ constructor(stores, l2TipsCache, opts = {}){
19
+ this.stores = stores;
22
20
  this.l2TipsCache = l2TipsCache;
23
21
  this.opts = opts;
24
22
  this.log = createLogger('archiver:store_updater');
@@ -26,77 +24,103 @@ import groupBy from 'lodash.groupby';
26
24
  /**
27
25
  * Adds a proposed block to the store with contract class/instance extraction from logs.
28
26
  * This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
29
- * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
30
- * and individually broadcasted functions from the block logs.
27
+ * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the block logs.
31
28
  *
32
29
  * @param block - The proposed L2 block to add.
33
30
  * @param pendingChainValidationStatus - Optional validation status to set.
34
31
  * @returns True if the operation is successful.
35
32
  */ async addProposedBlock(block, pendingChainValidationStatus) {
36
- const result = await this.store.transactionAsync(async ()=>{
37
- await this.store.addProposedBlock(block);
33
+ const result = await this.stores.db.transactionAsync(async ()=>{
34
+ await this.stores.blocks.addProposedBlock(block);
38
35
  const opResults = await Promise.all([
39
36
  // Update the pending chain validation status if provided
40
- pendingChainValidationStatus && this.store.setPendingChainValidationStatus(pendingChainValidationStatus),
37
+ pendingChainValidationStatus && this.stores.blocks.setPendingChainValidationStatus(pendingChainValidationStatus),
41
38
  // Add any logs emitted during the retrieved block
42
- this.store.addLogs([
39
+ this.stores.logs.addLogs([
43
40
  block
44
41
  ]),
45
42
  // Unroll all logs emitted during the retrieved block and extract any contract classes and instances from it
46
43
  this.addContractDataToDb(block)
47
44
  ]);
48
- await this.l2TipsCache?.refresh();
49
45
  return opResults.every(Boolean);
50
46
  });
47
+ await this.l2TipsCache?.refresh();
51
48
  return result;
52
49
  }
53
50
  /**
54
51
  * Reconciles local blocks with incoming checkpoints from L1.
55
52
  * Adds new checkpoints to the store with contract class/instance extraction from logs.
56
53
  * Prunes any local blocks that conflict with checkpoint data (by comparing archive roots).
57
- * Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
58
- * 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.
59
57
  *
60
- * @param checkpoints - The published checkpoints to add.
58
+ * @param checkpoints - The published checkpoints to add (excluding any being promoted from proposed).
61
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).
62
61
  * @returns Result with information about any pruned blocks.
63
- */ async addCheckpoints(checkpoints, pendingChainValidationStatus) {
62
+ */ async addCheckpoints(checkpoints, pendingChainValidationStatus, promoteProposed, evictProposedFrom) {
64
63
  for (const checkpoint of checkpoints){
65
64
  validateCheckpoint(checkpoint.checkpoint, {
66
65
  rollupManaLimit: this.opts?.rollupManaLimit
67
66
  });
68
67
  }
69
- const result = await this.store.transactionAsync(async ()=>{
68
+ if (promoteProposed) {
69
+ validateCheckpoint(promoteProposed.checkpoint.checkpoint, {
70
+ rollupManaLimit: this.opts?.rollupManaLimit
71
+ });
72
+ }
73
+ const result = await this.stores.db.transactionAsync(async ()=>{
70
74
  // Before adding checkpoints, check for conflicts with local blocks if any
71
75
  const { prunedBlocks, lastAlreadyInsertedBlockNumber } = await this.pruneMismatchingLocalBlocks(checkpoints);
72
- await this.store.addCheckpoints(checkpoints);
73
- // Filter out blocks that were already inserted via addProposedBlock() to avoid duplicating logs/contract data
74
- const newBlocks = checkpoints.flatMap((ch)=>ch.checkpoint.blocks).filter((b)=>lastAlreadyInsertedBlockNumber === undefined || b.number > lastAlreadyInsertedBlockNumber);
76
+ const insertedCheckpoints = await this.stores.blocks.addCheckpoints(checkpoints);
77
+ // Skip blocks already inserted via addProposedBlock() and blocks of already-stored checkpoints
78
+ // re-included by an L1 reorg: their logs/contract data were extracted when first inserted.
79
+ const newBlocks = insertedCheckpoints.flatMap((ch)=>ch.checkpoint.blocks).filter((b)=>lastAlreadyInsertedBlockNumber === undefined || b.number > lastAlreadyInsertedBlockNumber);
75
80
  await Promise.all([
76
81
  // Update the pending chain validation status if provided
77
- pendingChainValidationStatus && this.store.setPendingChainValidationStatus(pendingChainValidationStatus),
82
+ pendingChainValidationStatus && this.stores.blocks.setPendingChainValidationStatus(pendingChainValidationStatus),
78
83
  // Add any logs emitted during the retrieved blocks
79
- this.store.addLogs(newBlocks),
84
+ this.stores.logs.addLogs(newBlocks),
80
85
  // Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
81
- ...newBlocks.map((block)=>this.addContractDataToDb(block))
86
+ ...newBlocks.map((block)=>this.addContractDataToDb(block)),
87
+ // Promote the proposed checkpoint if requested (uses explicit checkpoint number)
88
+ promoteProposed ? this.stores.blocks.promoteProposedToCheckpointed(promoteProposed.checkpoint.checkpoint.number, promoteProposed.l1, promoteProposed.attestations, promoteProposed.checkpoint.checkpoint.archive.root) : undefined,
89
+ // Evict pending checkpoints that diverged from what L1 mined
90
+ evictProposedFrom !== undefined ? this.stores.blocks.evictProposedCheckpointsFrom(evictProposedFrom) : undefined
82
91
  ]);
83
- await this.l2TipsCache?.refresh();
84
92
  return {
85
93
  prunedBlocks,
86
94
  lastAlreadyInsertedBlockNumber
87
95
  };
88
96
  });
97
+ await this.l2TipsCache?.refresh();
98
+ return result;
99
+ }
100
+ async addProposedCheckpoint(proposedCheckpoint) {
101
+ const result = await this.stores.db.transactionAsync(async ()=>{
102
+ await this.stores.blocks.addProposedCheckpoint(proposedCheckpoint);
103
+ });
104
+ await this.l2TipsCache?.refresh();
89
105
  return result;
90
106
  }
91
107
  /**
92
108
  * Checks for local proposed blocks that do not match the ones to be checkpointed and prunes them.
93
- * This method handles multiple checkpoints but returns after pruning the first conflict found.
94
- * This is correct because pruning from the first conflict point removes all subsequent blocks,
95
- * and when checkpoints are added afterward, they include all the correct blocks.
109
+ * Conflict detection is keyed on `blockNumber`: when a local proposed block and an L1
110
+ * checkpointed block share a block number but live at different slots (e.g. a different proposer
111
+ * mined the same block number one slot earlier), we still treat them as a conflict and prune.
112
+ * The trailing per-checkpoint prune that handles "local has extra trailing blocks within the
113
+ * same slot as the published checkpoint" remains scoped by slot to preserve pipelining: local
114
+ * blocks that live at a later slot than the checkpoint being processed represent speculation
115
+ * atop the just-confirmed tip (and may be referenced by a pending proposed checkpoint), so we
116
+ * leave them in place. This method handles multiple checkpoints but returns after pruning the
117
+ * first conflict found. This is correct because pruning from the first conflict point removes
118
+ * all subsequent blocks, and when checkpoints are added afterward, they include all the correct
119
+ * blocks.
96
120
  */ async pruneMismatchingLocalBlocks(checkpoints) {
97
121
  const [lastCheckpointedBlockNumber, lastBlockNumber] = await Promise.all([
98
- this.store.getCheckpointedL2BlockNumber(),
99
- this.store.getLatestBlockNumber()
122
+ this.stores.blocks.getCheckpointedL2BlockNumber(),
123
+ this.stores.blocks.getLatestL2BlockNumber()
100
124
  ]);
101
125
  // Exit early if there are no local uncheckpointed blocks
102
126
  if (lastBlockNumber === lastCheckpointedBlockNumber) {
@@ -106,22 +130,25 @@ import groupBy from 'lodash.groupby';
106
130
  };
107
131
  }
108
132
  // Get all uncheckpointed local blocks
109
- const uncheckpointedLocalBlocks = await this.store.getBlocks(BlockNumber.add(lastCheckpointedBlockNumber, 1), lastBlockNumber - lastCheckpointedBlockNumber);
133
+ const uncheckpointedLocalBlocks = await this.stores.blocks.getBlocksData({
134
+ from: BlockNumber.add(lastCheckpointedBlockNumber, 1),
135
+ limit: lastBlockNumber - lastCheckpointedBlockNumber
136
+ });
110
137
  let lastAlreadyInsertedBlockNumber;
111
138
  for (const publishedCheckpoint of checkpoints){
112
139
  const checkpointBlocks = publishedCheckpoint.checkpoint.blocks;
113
140
  const slot = publishedCheckpoint.checkpoint.slot;
114
- const localBlocksInSlot = uncheckpointedLocalBlocks.filter((b)=>b.slot === slot);
115
141
  if (checkpointBlocks.length === 0) {
116
142
  this.log.warn(`Checkpoint ${publishedCheckpoint.checkpoint.number} for slot ${slot} has no blocks`);
117
143
  continue;
118
144
  }
119
- // Find the first checkpoint block that conflicts with an existing local block and prune local afterwards
145
+ // Find the first checkpoint block that conflicts with an existing local block and prune local afterwards.
146
+ // Conflict detection joins on block number only — same block number at a different slot is still a conflict.
120
147
  for (const checkpointBlock of checkpointBlocks){
121
148
  const blockNumber = checkpointBlock.number;
122
- const existingBlock = localBlocksInSlot.find((b)=>b.number === blockNumber);
149
+ const existingBlock = uncheckpointedLocalBlocks.find((b)=>b.header.getBlockNumber() === blockNumber);
123
150
  const blockInfos = {
124
- existingBlock: existingBlock?.toBlockInfo(),
151
+ existingBlock: existingBlock?.header.toInspect(),
125
152
  checkpointBlock: checkpointBlock.toBlockInfo()
126
153
  };
127
154
  if (!existingBlock) {
@@ -132,19 +159,23 @@ import groupBy from 'lodash.groupby';
132
159
  } else {
133
160
  this.log.info(`Conflict detected at block ${blockNumber} between checkpointed and local block`, blockInfos);
134
161
  const prunedBlocks = await this.removeBlocksAfter(BlockNumber(blockNumber - 1));
162
+ await this.evictProposedCheckpointsForPrunedBlocks(prunedBlocks);
135
163
  return {
136
164
  prunedBlocks,
137
165
  lastAlreadyInsertedBlockNumber
138
166
  };
139
167
  }
140
168
  }
141
- // If local has more blocks than the checkpoint (e.g., local has [2,3,4] but checkpoint has [2,3]),
142
- // we need to prune the extra local blocks so they match what was checkpointed
169
+ // If the sequencer locally proposed extra blocks within this checkpoint's slot (e.g. local has
170
+ // [N, N+1] but L1 confirmed just [N]), prune the extras. Scoped to the checkpoint's slot so we
171
+ // do not throw away speculative blocks at later slots that belong to a pending proposed checkpoint.
143
172
  const lastCheckpointBlockNumber = checkpointBlocks.at(-1).number;
144
- const lastLocalBlockNumber = localBlocksInSlot.at(-1)?.number;
173
+ const localBlocksInSlot = uncheckpointedLocalBlocks.filter((b)=>b.header.getSlot() === slot);
174
+ const lastLocalBlockNumber = localBlocksInSlot.at(-1)?.header.getBlockNumber();
145
175
  if (lastLocalBlockNumber !== undefined && lastLocalBlockNumber > lastCheckpointBlockNumber) {
146
176
  this.log.warn(`Local chain for slot ${slot} ends at block ${lastLocalBlockNumber} but checkpoint ends at ${lastCheckpointBlockNumber}. Pruning blocks after block ${lastCheckpointBlockNumber}.`);
147
177
  const prunedBlocks = await this.removeBlocksAfter(lastCheckpointBlockNumber);
178
+ await this.evictProposedCheckpointsForPrunedBlocks(prunedBlocks);
148
179
  return {
149
180
  prunedBlocks,
150
181
  lastAlreadyInsertedBlockNumber
@@ -165,27 +196,60 @@ import groupBy from 'lodash.groupby';
165
196
  * @returns The removed blocks.
166
197
  * @throws Error if any block to be removed is checkpointed.
167
198
  */ async removeUncheckpointedBlocksAfter(blockNumber) {
168
- const result = await this.store.transactionAsync(async ()=>{
199
+ const result = await this.stores.db.transactionAsync(async ()=>{
169
200
  // Verify we're only removing uncheckpointed blocks
170
- const lastCheckpointedBlockNumber = await this.store.getCheckpointedL2BlockNumber();
201
+ const lastCheckpointedBlockNumber = await this.stores.blocks.getCheckpointedL2BlockNumber();
171
202
  if (blockNumber < lastCheckpointedBlockNumber) {
172
203
  throw new Error(`Cannot remove blocks after ${blockNumber} because checkpointed blocks exist up to ${lastCheckpointedBlockNumber}`);
173
204
  }
174
- const result = await this.removeBlocksAfter(blockNumber);
175
- await this.l2TipsCache?.refresh();
176
- return result;
205
+ const prunedBlocks = await this.removeBlocksAfter(blockNumber);
206
+ await this.evictProposedCheckpointsForPrunedBlocks(prunedBlocks);
207
+ return prunedBlocks;
208
+ });
209
+ await this.l2TipsCache?.refresh();
210
+ return result;
211
+ }
212
+ /**
213
+ * Removes all blocks without a proposed checkpoint strictly after the specified block number and cleans up associated contract data.
214
+ * This handles removal of provisionally added blocks along with their contract classes/instances.
215
+ * Verifies that each block being removed is not part of a stored checkpoint (proposed or not).
216
+ * This differs from `removeUncheckpointedBlocksAfter` in that it also checks proposed checkpoints.
217
+ *
218
+ * @param blockNumber - Remove all blocks with number greater than this.
219
+ * @returns The removed blocks.
220
+ * @throws Error if any block to be removed is checkpointed.
221
+ */ async removeBlocksWithoutProposedCheckpointAfter(blockNumber) {
222
+ const result = await this.stores.db.transactionAsync(async ()=>{
223
+ // Verify we're only removing uncheckpointed blocks
224
+ const lastCheckpointedBlockNumber = await this.stores.blocks.getProposedCheckpointL2BlockNumber();
225
+ if (blockNumber < lastCheckpointedBlockNumber) {
226
+ throw new Error(`Cannot remove blocks after ${blockNumber} because proposed checkpointed blocks exist up to ${lastCheckpointedBlockNumber}`);
227
+ }
228
+ return await this.removeBlocksAfter(blockNumber);
177
229
  });
230
+ await this.l2TipsCache?.refresh();
178
231
  return result;
179
232
  }
180
233
  /**
234
+ * Evicts pending proposed checkpoints that referenced any of the just-pruned blocks. Pruned
235
+ * blocks invalidate all proposed checkpoints from the lowest pruned block's checkpoint number
236
+ * onwards: those checkpoints either reference the pruned blocks directly or chain off them.
237
+ */ async evictProposedCheckpointsForPrunedBlocks(prunedBlocks) {
238
+ if (prunedBlocks.length === 0) {
239
+ return;
240
+ }
241
+ const fromCheckpointNumber = prunedBlocks[0].checkpointNumber;
242
+ await this.stores.blocks.evictProposedCheckpointsFrom(fromCheckpointNumber);
243
+ }
244
+ /**
181
245
  * Removes all blocks strictly after the given block number along with any logs and contract data.
182
246
  * Does not remove their checkpoints.
183
247
  */ async removeBlocksAfter(blockNumber) {
184
248
  // First get the blocks to be removed so we can clean up contract data
185
- const removedBlocks = await this.store.removeBlocksAfter(blockNumber);
249
+ const removedBlocks = await this.stores.blocks.removeBlocksAfter(blockNumber);
186
250
  // Clean up contract data and logs for the removed blocks
187
251
  await Promise.all([
188
- this.store.deleteLogs(removedBlocks),
252
+ this.stores.logs.deleteLogs(removedBlocks),
189
253
  ...removedBlocks.map((block)=>this.removeContractDataFromDb(block))
190
254
  ]);
191
255
  return removedBlocks;
@@ -199,38 +263,39 @@ import groupBy from 'lodash.groupby';
199
263
  * @param checkpointNumber - Remove all checkpoints strictly after this one.
200
264
  * @returns True if the operation is successful.
201
265
  */ async removeCheckpointsAfter(checkpointNumber) {
202
- return await this.store.transactionAsync(async ()=>{
203
- const { blocksRemoved = [] } = await this.store.removeCheckpointsAfter(checkpointNumber);
266
+ const result = await this.stores.db.transactionAsync(async ()=>{
267
+ const { blocksRemoved = [] } = await this.stores.blocks.removeCheckpointsAfter(checkpointNumber);
204
268
  const opResults = await Promise.all([
205
269
  // Prune rolls back to the last proven block, which is by definition valid
206
- this.store.setPendingChainValidationStatus({
270
+ this.stores.blocks.setPendingChainValidationStatus({
207
271
  valid: true
208
272
  }),
209
273
  // Remove contract data for all blocks being removed
210
274
  ...blocksRemoved.map((block)=>this.removeContractDataFromDb(block)),
211
- this.store.deleteLogs(blocksRemoved)
275
+ this.stores.logs.deleteLogs(blocksRemoved)
212
276
  ]);
213
- await this.l2TipsCache?.refresh();
214
277
  return opResults.every(Boolean);
215
278
  });
279
+ await this.l2TipsCache?.refresh();
280
+ return result;
216
281
  }
217
282
  /**
218
283
  * Updates the proven checkpoint number and refreshes the L2 tips cache.
219
284
  * @param checkpointNumber - The checkpoint number to set as proven.
220
285
  */ async setProvenCheckpointNumber(checkpointNumber) {
221
- await this.store.transactionAsync(async ()=>{
222
- await this.store.setProvenCheckpointNumber(checkpointNumber);
223
- await this.l2TipsCache?.refresh();
286
+ await this.stores.db.transactionAsync(async ()=>{
287
+ await this.stores.blocks.setProvenCheckpointNumber(checkpointNumber);
224
288
  });
289
+ await this.l2TipsCache?.refresh();
225
290
  }
226
291
  /**
227
292
  * Updates the finalized checkpoint number and refreshes the L2 tips cache.
228
293
  * @param checkpointNumber - The checkpoint number to set as finalized.
229
294
  */ async setFinalizedCheckpointNumber(checkpointNumber) {
230
- await this.store.transactionAsync(async ()=>{
231
- await this.store.setFinalizedCheckpointNumber(checkpointNumber);
232
- await this.l2TipsCache?.refresh();
295
+ await this.stores.db.transactionAsync(async ()=>{
296
+ await this.stores.blocks.setFinalizedCheckpointNumber(checkpointNumber);
233
297
  });
298
+ await this.l2TipsCache?.refresh();
234
299
  }
235
300
  /** Extracts and stores contract data from a single block. */ addContractDataToDb(block) {
236
301
  return this.updateContractDataOnDb(block, 0);
@@ -245,8 +310,7 @@ import groupBy from 'lodash.groupby';
245
310
  return (await Promise.all([
246
311
  this.updatePublishedContractClasses(contractClassLogs, block.number, operation),
247
312
  this.updateDeployedContractInstances(privateLogs, block.number, operation),
248
- this.updateUpdatedContractInstances(publicLogs, block.header.globalVariables.timestamp, operation),
249
- operation === 0 ? this.storeBroadcastedIndividualFunctions(contractClassLogs, block.number) : Promise.resolve(true)
313
+ this.updateUpdatedContractInstances(publicLogs, block.header.globalVariables.timestamp, operation)
250
314
  ])).every(Boolean);
251
315
  }
252
316
  /**
@@ -257,7 +321,7 @@ import groupBy from 'lodash.groupby';
257
321
  const contractClasses = contractClassPublishedEvents.map((e)=>e.toContractClassPublic());
258
322
  if (contractClasses.length > 0) {
259
323
  contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
260
- return await this.store.deleteContractClasses(contractClasses, blockNum);
324
+ return await this.stores.contractClasses.deleteContractClasses(contractClasses, blockNum);
261
325
  }
262
326
  return true;
263
327
  }
@@ -281,7 +345,7 @@ import groupBy from 'lodash.groupby';
281
345
  }
282
346
  if (contractClasses.length > 0) {
283
347
  contractClasses.forEach((c)=>this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
284
- return await this.store.addContractClasses(contractClasses, blockNum);
348
+ return await this.stores.contractClasses.addContractClasses(contractClasses, blockNum);
285
349
  }
286
350
  return true;
287
351
  }
@@ -305,9 +369,9 @@ import groupBy from 'lodash.groupby';
305
369
  if (contractInstances.length > 0) {
306
370
  contractInstances.forEach((c)=>this.log.verbose(`${Operation[operation]} contract instance at ${c.address.toString()}`));
307
371
  if (operation == 0) {
308
- return await this.store.addContractInstances(contractInstances, blockNum);
372
+ return await this.stores.contractInstances.addContractInstances(contractInstances, blockNum);
309
373
  } else if (operation == 1) {
310
- return await this.store.deleteContractInstances(contractInstances, blockNum);
374
+ return await this.stores.contractInstances.deleteContractInstances(contractInstances);
311
375
  }
312
376
  }
313
377
  return true;
@@ -319,56 +383,10 @@ import groupBy from 'lodash.groupby';
319
383
  if (contractUpdates.length > 0) {
320
384
  contractUpdates.forEach((c)=>this.log.verbose(`${Operation[operation]} contract instance update at ${c.address.toString()}`));
321
385
  if (operation == 0) {
322
- return await this.store.addContractInstanceUpdates(contractUpdates, timestamp);
386
+ return await this.stores.contractInstances.addContractInstanceUpdates(contractUpdates, timestamp);
323
387
  } else if (operation == 1) {
324
- return await this.store.deleteContractInstanceUpdates(contractUpdates, timestamp);
325
- }
326
- }
327
- return true;
328
- }
329
- /**
330
- * Stores the functions that were broadcasted individually.
331
- *
332
- * @dev Beware that there is not a delete variant of this, since they are added to contract classes
333
- * and will be deleted as part of the class if needed.
334
- */ async storeBroadcastedIndividualFunctions(allLogs, _blockNum) {
335
- // Filter out private and utility function broadcast events
336
- const privateFnEvents = allLogs.filter((log)=>PrivateFunctionBroadcastedEvent.isPrivateFunctionBroadcastedEvent(log)).map((log)=>PrivateFunctionBroadcastedEvent.fromLog(log));
337
- const utilityFnEvents = allLogs.filter((log)=>UtilityFunctionBroadcastedEvent.isUtilityFunctionBroadcastedEvent(log)).map((log)=>UtilityFunctionBroadcastedEvent.fromLog(log));
338
- // Group all events by contract class id
339
- for (const [classIdString, classEvents] of Object.entries(groupBy([
340
- ...privateFnEvents,
341
- ...utilityFnEvents
342
- ], (e)=>e.contractClassId.toString()))){
343
- const contractClassId = Fr.fromHexString(classIdString);
344
- const contractClass = await this.store.getContractClass(contractClassId);
345
- if (!contractClass) {
346
- this.log.warn(`Skipping broadcasted functions as contract class ${contractClassId.toString()} was not found`);
347
- continue;
348
- }
349
- // Split private and utility functions, and filter out invalid ones
350
- const allFns = classEvents.map((e)=>e.toFunctionWithMembershipProof());
351
- const privateFns = allFns.filter((fn)=>'utilityFunctionsTreeRoot' in fn);
352
- const utilityFns = allFns.filter((fn)=>'privateFunctionsArtifactTreeRoot' in fn);
353
- const privateFunctionsWithValidity = await Promise.all(privateFns.map(async (fn)=>({
354
- fn,
355
- valid: await isValidPrivateFunctionMembershipProof(fn, contractClass)
356
- })));
357
- const validPrivateFns = privateFunctionsWithValidity.filter(({ valid })=>valid).map(({ fn })=>fn);
358
- const utilityFunctionsWithValidity = await Promise.all(utilityFns.map(async (fn)=>({
359
- fn,
360
- valid: await isValidUtilityFunctionMembershipProof(fn, contractClass)
361
- })));
362
- const validUtilityFns = utilityFunctionsWithValidity.filter(({ valid })=>valid).map(({ fn })=>fn);
363
- const validFnCount = validPrivateFns.length + validUtilityFns.length;
364
- if (validFnCount !== allFns.length) {
365
- this.log.warn(`Skipping ${allFns.length - validFnCount} invalid functions`);
366
- }
367
- // Store the functions in the contract class in a single operation
368
- if (validFnCount > 0) {
369
- this.log.verbose(`Storing ${validFnCount} functions for contract class ${contractClassId.toString()}`);
388
+ return await this.stores.contractInstances.deleteContractInstanceUpdates(contractUpdates, timestamp);
370
389
  }
371
- await this.store.addFunctions(contractClassId, validPrivateFns, validUtilityFns);
372
390
  }
373
391
  return true;
374
392
  }
@@ -1,5 +1,7 @@
1
+ import type { SlotNumber } from '@aztec/foundation/branded-types';
1
2
  import type { L2Block } from '@aztec/stdlib/block';
2
3
  import type { CheckpointData } from '@aztec/stdlib/checkpoint';
4
+ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
3
5
  import { type LmdbStatsCallback, type TelemetryClient, type Tracer } from '@aztec/telemetry-client';
4
6
  export declare class ArchiverInstrumentation {
5
7
  private telemetry;
@@ -14,19 +16,31 @@ export declare class ArchiverInstrumentation {
14
16
  private pruneDuration;
15
17
  private pruneCount;
16
18
  private syncDurationPerBlock;
19
+ private syncDurationPerCheckpoint;
17
20
  private syncBlockCount;
18
21
  private manaPerBlock;
19
22
  private txsPerBlock;
20
23
  private syncDurationPerMessage;
21
24
  private syncMessageCount;
22
25
  private blockProposalTxTargetCount;
26
+ private checkpointL1InclusionDelay;
27
+ private checkpointPromotedCount;
23
28
  private log;
24
29
  private constructor();
25
30
  static new(telemetry: TelemetryClient, lmdbStats?: LmdbStatsCallback): Promise<ArchiverInstrumentation>;
26
31
  isEnabled(): boolean;
27
- processNewBlocks(syncTimePerBlock: number, blocks: L2Block[]): void;
32
+ processNewProposedBlock(syncTimePerBlock: number, block: L2Block): void;
33
+ processNewCheckpointedBlocks(syncTimePerCheckpoint: number, blocks: L2Block[]): void;
28
34
  processNewMessages(count: number, syncPerMessageMs: number): void;
29
35
  processPrune(duration: number): void;
36
+ /**
37
+ * Records a pending-chain reorg, where the archiver dropped proposed blocks (and world-state follows by pruning). The
38
+ * type distinguishes the cause: 'uncheckpointed' (slot ended without a checkpoint), 'l1_conflict' (proposed blocks
39
+ * conflicting with an L1 checkpoint), 'orphan' (no matching proposed checkpoint arrived before the deadline), or
40
+ * 'l1_mismatch' (the local checkpointed tip diverged from L1 — an L1 reorg or a pruned/missed-proof checkpoint — so
41
+ * already-checkpointed blocks were rewound).
42
+ */
43
+ recordPrune(pruneType: 'uncheckpointed' | 'l1_conflict' | 'orphan' | 'l1_mismatch'): void;
30
44
  updateLastProvenCheckpoint(checkpoint: CheckpointData): void;
31
45
  processProofsVerified(logs: {
32
46
  proverId: string;
@@ -35,5 +49,15 @@ export declare class ArchiverInstrumentation {
35
49
  }[]): void;
36
50
  updateL1BlockHeight(blockNumber: bigint): void;
37
51
  recordBlockProposalTxTarget(target: string, usedTrace: boolean): void;
52
+ /** Records a checkpoint promoted from proposed (blob fetch skipped). */
53
+ processCheckpointPromoted(): void;
54
+ /**
55
+ * Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
56
+ */
57
+ processCheckpointL1Timing(data: {
58
+ slotNumber: SlotNumber;
59
+ l1Timestamp: bigint;
60
+ l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'>;
61
+ }): void;
38
62
  }
39
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5zdHJ1bWVudGF0aW9uLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbW9kdWxlcy9pbnN0cnVtZW50YXRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxLQUFLLEVBQUUsT0FBTyxFQUFFLE1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,MAAM,CAAC;QACpB,WAAW,EAAE,IAAI,CAAC,iBAAiB,EAAE,eAAe,GAAG,cAAc,CAAC,CAAC;KACxE,GAAG,IAAI,CAIP;CACF"}
@@ -1,4 +1,5 @@
1
1
  import { createLogger } from '@aztec/foundation/log';
2
+ import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
2
3
  import { Attributes, LmdbMetrics, Metrics, createUpDownCounterWithDefault } from '@aztec/telemetry-client';
3
4
  export class ArchiverInstrumentation {
4
5
  telemetry;
@@ -13,12 +14,15 @@ export class ArchiverInstrumentation {
13
14
  pruneDuration;
14
15
  pruneCount;
15
16
  syncDurationPerBlock;
17
+ syncDurationPerCheckpoint;
16
18
  syncBlockCount;
17
19
  manaPerBlock;
18
20
  txsPerBlock;
19
21
  syncDurationPerMessage;
20
22
  syncMessageCount;
21
23
  blockProposalTxTargetCount;
24
+ checkpointL1InclusionDelay;
25
+ checkpointPromotedCount;
22
26
  log;
23
27
  constructor(telemetry, lmdbStats){
24
28
  this.telemetry = telemetry;
@@ -37,19 +41,30 @@ export class ArchiverInstrumentation {
37
41
  });
38
42
  this.proofsSubmittedDelay = meter.createHistogram(Metrics.ARCHIVER_ROLLUP_PROOF_DELAY);
39
43
  this.syncDurationPerBlock = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_BLOCK);
44
+ this.syncDurationPerCheckpoint = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_CHECKPOINT);
40
45
  this.syncBlockCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_BLOCK_COUNT);
41
46
  this.manaPerBlock = meter.createHistogram(Metrics.ARCHIVER_MANA_PER_BLOCK);
42
47
  this.txsPerBlock = meter.createHistogram(Metrics.ARCHIVER_TXS_PER_BLOCK);
43
48
  this.syncDurationPerMessage = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_MESSAGE);
44
49
  this.syncMessageCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_MESSAGE_COUNT);
45
50
  this.pruneDuration = meter.createHistogram(Metrics.ARCHIVER_PRUNE_DURATION);
46
- this.pruneCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_PRUNE_COUNT);
51
+ this.pruneCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_PRUNE_COUNT, {
52
+ [Attributes.PRUNE_TYPE]: [
53
+ 'unproven',
54
+ 'uncheckpointed',
55
+ 'l1_conflict',
56
+ 'orphan',
57
+ 'l1_mismatch'
58
+ ]
59
+ });
47
60
  this.blockProposalTxTargetCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_BLOCK_PROPOSAL_TX_TARGET_COUNT, {
48
61
  [Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: [
49
62
  true,
50
63
  false
51
64
  ]
52
65
  });
66
+ this.checkpointL1InclusionDelay = meter.createHistogram(Metrics.ARCHIVER_CHECKPOINT_L1_INCLUSION_DELAY);
67
+ this.checkpointPromotedCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_CHECKPOINT_PROMOTED_COUNT);
53
68
  this.dbMetrics = new LmdbMetrics(meter, {
54
69
  [Attributes.DB_DATA_TYPE]: 'archiver'
55
70
  }, lmdbStats);
@@ -62,16 +77,27 @@ export class ArchiverInstrumentation {
62
77
  isEnabled() {
63
78
  return this.telemetry.isEnabled();
64
79
  }
65
- processNewBlocks(syncTimePerBlock, blocks) {
80
+ processNewProposedBlock(syncTimePerBlock, block) {
81
+ const attrs = {
82
+ [Attributes.STATUS]: 'proposed'
83
+ };
84
+ this.blockHeight.record(block.number, attrs);
66
85
  this.syncDurationPerBlock.record(Math.ceil(syncTimePerBlock));
67
- this.blockHeight.record(Math.max(...blocks.map((b)=>b.number)));
86
+ // Per block metrics
87
+ this.txCount.add(block.body.txEffects.length);
88
+ this.txsPerBlock.record(block.body.txEffects.length);
89
+ this.manaPerBlock.record(block.header.totalManaUsed.toNumber() / 1e6);
90
+ }
91
+ processNewCheckpointedBlocks(syncTimePerCheckpoint, blocks) {
92
+ if (blocks.length === 0) {
93
+ return;
94
+ }
95
+ this.syncDurationPerCheckpoint.record(Math.ceil(syncTimePerCheckpoint));
96
+ this.blockHeight.record(Math.max(...blocks.map((b)=>b.number)), {
97
+ [Attributes.STATUS]: 'checkpointed'
98
+ });
68
99
  this.checkpointHeight.record(Math.max(...blocks.map((b)=>b.checkpointNumber)));
69
100
  this.syncBlockCount.add(blocks.length);
70
- for (const block of blocks){
71
- this.txCount.add(block.body.txEffects.length);
72
- this.txsPerBlock.record(block.body.txEffects.length);
73
- this.manaPerBlock.record(block.header.totalManaUsed.toNumber() / 1e6);
74
- }
75
101
  }
76
102
  processNewMessages(count, syncPerMessageMs) {
77
103
  if (count === 0) {
@@ -81,9 +107,22 @@ export class ArchiverInstrumentation {
81
107
  this.syncDurationPerMessage.record(Math.ceil(syncPerMessageMs));
82
108
  }
83
109
  processPrune(duration) {
84
- this.pruneCount.add(1);
110
+ this.pruneCount.add(1, {
111
+ [Attributes.PRUNE_TYPE]: 'unproven'
112
+ });
85
113
  this.pruneDuration.record(Math.ceil(duration));
86
114
  }
115
+ /**
116
+ * Records a pending-chain reorg, where the archiver dropped proposed blocks (and world-state follows by pruning). The
117
+ * type distinguishes the cause: 'uncheckpointed' (slot ended without a checkpoint), 'l1_conflict' (proposed blocks
118
+ * conflicting with an L1 checkpoint), 'orphan' (no matching proposed checkpoint arrived before the deadline), or
119
+ * 'l1_mismatch' (the local checkpointed tip diverged from L1 — an L1 reorg or a pruned/missed-proof checkpoint — so
120
+ * already-checkpointed blocks were rewound).
121
+ */ recordPrune(pruneType) {
122
+ this.pruneCount.add(1, {
123
+ [Attributes.PRUNE_TYPE]: pruneType
124
+ });
125
+ }
87
126
  updateLastProvenCheckpoint(checkpoint) {
88
127
  const lastBlockNumberInCheckpoint = checkpoint.startBlock + checkpoint.blockCount - 1;
89
128
  this.blockHeight.record(lastBlockNumberInCheckpoint, {
@@ -114,4 +153,14 @@ export class ArchiverInstrumentation {
114
153
  [Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: usedTrace
115
154
  });
116
155
  }
156
+ /** Records a checkpoint promoted from proposed (blob fetch skipped). */ processCheckpointPromoted() {
157
+ this.checkpointPromotedCount.add(1);
158
+ }
159
+ /**
160
+ * Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
161
+ */ processCheckpointL1Timing(data) {
162
+ const slotStartTs = getTimestampForSlot(data.slotNumber, data.l1Constants);
163
+ const inclusionDelaySeconds = Number(data.l1Timestamp - slotStartTs);
164
+ this.checkpointL1InclusionDelay.record(inclusionDelaySeconds);
165
+ }
117
166
  }