@aztec/archiver 0.0.1-commit.e588bc7e5 → 0.0.1-commit.e5a3663dd

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 (105) hide show
  1. package/dest/archiver.d.ts +19 -11
  2. package/dest/archiver.d.ts.map +1 -1
  3. package/dest/archiver.js +96 -53
  4. package/dest/config.d.ts +3 -1
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +14 -3
  7. package/dest/errors.d.ts +32 -5
  8. package/dest/errors.d.ts.map +1 -1
  9. package/dest/errors.js +51 -6
  10. package/dest/factory.d.ts +4 -4
  11. package/dest/factory.d.ts.map +1 -1
  12. package/dest/factory.js +13 -10
  13. package/dest/index.d.ts +10 -3
  14. package/dest/index.d.ts.map +1 -1
  15. package/dest/index.js +9 -2
  16. package/dest/l1/calldata_retriever.d.ts +2 -1
  17. package/dest/l1/calldata_retriever.d.ts.map +1 -1
  18. package/dest/l1/calldata_retriever.js +9 -4
  19. package/dest/l1/data_retrieval.d.ts +18 -9
  20. package/dest/l1/data_retrieval.d.ts.map +1 -1
  21. package/dest/l1/data_retrieval.js +13 -19
  22. package/dest/l1/validate_historical_logs.d.ts +23 -0
  23. package/dest/l1/validate_historical_logs.d.ts.map +1 -0
  24. package/dest/l1/validate_historical_logs.js +108 -0
  25. package/dest/modules/contract_data_source_adapter.d.ts +25 -0
  26. package/dest/modules/contract_data_source_adapter.d.ts.map +1 -0
  27. package/dest/modules/contract_data_source_adapter.js +42 -0
  28. package/dest/modules/data_source_base.d.ts +16 -10
  29. package/dest/modules/data_source_base.d.ts.map +1 -1
  30. package/dest/modules/data_source_base.js +71 -60
  31. package/dest/modules/data_store_updater.d.ts +16 -9
  32. package/dest/modules/data_store_updater.d.ts.map +1 -1
  33. package/dest/modules/data_store_updater.js +52 -40
  34. package/dest/modules/instrumentation.d.ts +7 -2
  35. package/dest/modules/instrumentation.d.ts.map +1 -1
  36. package/dest/modules/instrumentation.js +22 -6
  37. package/dest/modules/l1_synchronizer.d.ts +8 -4
  38. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  39. package/dest/modules/l1_synchronizer.js +212 -79
  40. package/dest/modules/validation.d.ts +4 -3
  41. package/dest/modules/validation.d.ts.map +1 -1
  42. package/dest/modules/validation.js +4 -4
  43. package/dest/store/block_store.d.ts +60 -21
  44. package/dest/store/block_store.d.ts.map +1 -1
  45. package/dest/store/block_store.js +229 -70
  46. package/dest/store/contract_class_store.d.ts +17 -3
  47. package/dest/store/contract_class_store.d.ts.map +1 -1
  48. package/dest/store/contract_class_store.js +17 -1
  49. package/dest/store/contract_instance_store.d.ts +28 -1
  50. package/dest/store/contract_instance_store.d.ts.map +1 -1
  51. package/dest/store/contract_instance_store.js +31 -0
  52. package/dest/store/data_stores.d.ts +68 -0
  53. package/dest/store/data_stores.d.ts.map +1 -0
  54. package/dest/store/data_stores.js +50 -0
  55. package/dest/store/function_names_cache.d.ts +17 -0
  56. package/dest/store/function_names_cache.d.ts.map +1 -0
  57. package/dest/store/function_names_cache.js +30 -0
  58. package/dest/store/l2_tips_cache.d.ts +1 -1
  59. package/dest/store/l2_tips_cache.d.ts.map +1 -1
  60. package/dest/store/l2_tips_cache.js +3 -3
  61. package/dest/store/log_store.d.ts +1 -1
  62. package/dest/store/log_store.d.ts.map +1 -1
  63. package/dest/store/log_store.js +2 -4
  64. package/dest/store/message_store.d.ts +9 -3
  65. package/dest/store/message_store.d.ts.map +1 -1
  66. package/dest/store/message_store.js +31 -1
  67. package/dest/test/fake_l1_state.d.ts +14 -3
  68. package/dest/test/fake_l1_state.d.ts.map +1 -1
  69. package/dest/test/fake_l1_state.js +55 -15
  70. package/dest/test/mock_l2_block_source.d.ts +12 -3
  71. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  72. package/dest/test/mock_l2_block_source.js +24 -2
  73. package/dest/test/noop_l1_archiver.d.ts +4 -4
  74. package/dest/test/noop_l1_archiver.d.ts.map +1 -1
  75. package/dest/test/noop_l1_archiver.js +9 -7
  76. package/package.json +13 -13
  77. package/src/archiver.ts +113 -52
  78. package/src/config.ts +15 -1
  79. package/src/errors.ts +75 -8
  80. package/src/factory.ts +11 -10
  81. package/src/index.ts +17 -2
  82. package/src/l1/calldata_retriever.ts +15 -4
  83. package/src/l1/data_retrieval.ts +30 -35
  84. package/src/l1/validate_historical_logs.ts +140 -0
  85. package/src/modules/contract_data_source_adapter.ts +59 -0
  86. package/src/modules/data_source_base.ts +75 -57
  87. package/src/modules/data_store_updater.ts +71 -39
  88. package/src/modules/instrumentation.ts +27 -7
  89. package/src/modules/l1_synchronizer.ts +301 -83
  90. package/src/modules/validation.ts +8 -7
  91. package/src/store/block_store.ts +264 -77
  92. package/src/store/contract_class_store.ts +28 -2
  93. package/src/store/contract_instance_store.ts +43 -0
  94. package/src/store/data_stores.ts +108 -0
  95. package/src/store/function_names_cache.ts +37 -0
  96. package/src/store/l2_tips_cache.ts +9 -3
  97. package/src/store/log_store.ts +2 -5
  98. package/src/store/message_store.ts +35 -2
  99. package/src/test/fake_l1_state.ts +62 -24
  100. package/src/test/mock_l2_block_source.ts +23 -2
  101. package/src/test/noop_l1_archiver.ts +9 -7
  102. package/dest/store/kv_archiver_store.d.ts +0 -377
  103. package/dest/store/kv_archiver_store.d.ts.map +0 -1
  104. package/dest/store/kv_archiver_store.js +0 -494
  105. package/src/store/kv_archiver_store.ts +0 -713
@@ -6,20 +6,21 @@ import { createLogger } from '@aztec/foundation/log';
6
6
  import { BufferReader } from '@aztec/foundation/serialize';
7
7
  import { bufferToHex } from '@aztec/foundation/string';
8
8
  import { isDefined } from '@aztec/foundation/types';
9
- import { Body, CheckpointedL2Block, CommitteeAttestation, L2Block, deserializeValidateCheckpointResult, serializeValidateCheckpointResult } from '@aztec/stdlib/block';
9
+ import { BlockHash, Body, CheckpointedL2Block, CommitteeAttestation, L2Block, deserializeValidateCheckpointResult, serializeValidateCheckpointResult } from '@aztec/stdlib/block';
10
10
  import { Checkpoint, L1PublishedData } from '@aztec/stdlib/checkpoint';
11
11
  import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
12
12
  import { CheckpointHeader } from '@aztec/stdlib/rollup';
13
13
  import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
14
14
  import { BlockHeader, TxHash, TxReceipt, TxStatus, deserializeIndexedTxEffect, serializeIndexedTxEffect } from '@aztec/stdlib/tx';
15
- import { BlockAlreadyCheckpointedError, BlockArchiveNotConsistentError, BlockIndexNotSequentialError, BlockNotFoundError, BlockNumberNotSequentialError, CannotOverwriteCheckpointedBlockError, CheckpointNotFoundError, CheckpointNumberNotSequentialError, InitialCheckpointNumberNotSequentialError, ProposedCheckpointNotSequentialError, ProposedCheckpointStaleError } from '../errors.js';
15
+ import { BlockAlreadyCheckpointedError, BlockArchiveNotConsistentError, BlockCheckpointNumberNotSequentialError, BlockIndexNotSequentialError, BlockNotFoundError, BlockNumberNotSequentialError, CannotOverwriteCheckpointedBlockError, CheckpointNotFoundError, CheckpointNumberNotSequentialError, InitialCheckpointNumberNotSequentialError, NoProposedCheckpointToPromoteError, ProposedCheckpointArchiveRootMismatchError, ProposedCheckpointNotSequentialError, ProposedCheckpointPromotionNotSequentialError } from '../errors.js';
16
16
  export { TxReceipt } from '@aztec/stdlib/tx';
17
17
  /**
18
18
  * LMDB-based block storage for the archiver.
19
19
  */ export class BlockStore {
20
20
  db;
21
21
  /** Map block number to block data */ #blocks;
22
- /** Map checkpoint number to checkpoint data */ #checkpoints;
22
+ /** Map keyed by checkpoint number holding proposed (locally-validated, not yet L1-confirmed) checkpoints. */ #proposedCheckpoints;
23
+ /** Map checkpoint number to checkpoint data for mined checkpoints only */ #checkpoints;
23
24
  /** Map slot number to checkpoint number, for looking up checkpoints by slot range. */ #slotToCheckpoint;
24
25
  /** Map block hash to list of tx hashes */ #blockTxs;
25
26
  /** Tx hash to serialized IndexedTxEffect */ #txEffects;
@@ -30,7 +31,6 @@ export { TxReceipt } from '@aztec/stdlib/tx';
30
31
  /** Index mapping a contract's address (as a string) to its location in a block */ #contractIndex;
31
32
  /** Index mapping block hash to block number */ #blockHashIndex;
32
33
  /** Index mapping block archive to block number */ #blockArchiveIndex;
33
- /** Singleton: assumes max 1-deep pipeline. For deeper pipelining, replace with a map keyed by checkpoint number. */ #proposedCheckpoint;
34
34
  #log;
35
35
  constructor(db){
36
36
  this.db = db;
@@ -47,7 +47,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
47
47
  this.#pendingChainValidationStatus = db.openSingleton('archiver_pending_chain_validation_status');
48
48
  this.#checkpoints = db.openMap('archiver_checkpoints');
49
49
  this.#slotToCheckpoint = db.openMap('archiver_slot_to_checkpoint');
50
- this.#proposedCheckpoint = db.openSingleton('proposed_checkpoint_data');
50
+ this.#proposedCheckpoints = db.openMap('archiver_proposed_checkpoints');
51
51
  }
52
52
  /**
53
53
  * Returns the finalized L2 block number. An L2 block is finalized when it was proven
@@ -78,8 +78,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
78
78
  const blockLastArchive = block.header.lastArchive.root;
79
79
  // Extract the latest block and checkpoint numbers
80
80
  const previousBlockNumber = await this.getLatestL2BlockNumber();
81
- const proposedCheckpointNumber = await this.getProposedCheckpointNumber();
82
- const previousCheckpointNumber = await this.getLatestCheckpointNumber();
81
+ const latestCheckpointNumber = await this.getLatestCheckpointNumber();
83
82
  // Verify we're not overwriting checkpointed blocks
84
83
  const lastCheckpointedBlockNumber = await this.getCheckpointedL2BlockNumber();
85
84
  if (!opts.force && blockNumber <= lastCheckpointedBlockNumber) {
@@ -94,18 +93,17 @@ export { TxReceipt } from '@aztec/stdlib/tx';
94
93
  if (!opts.force && previousBlockNumber !== blockNumber - 1) {
95
94
  throw new BlockNumberNotSequentialError(blockNumber, previousBlockNumber);
96
95
  }
97
- // The same check as above but for checkpoints. Accept the block if either the confirmed
98
- // checkpoint or the pending (locally validated but not yet confirmed) checkpoint matches.
96
+ // Accept the block if either the confirmed checkpoint or a pending checkpoint matches
97
+ // the expected predecessor. We look for a pending entry at exactly blockCheckpointNumber - 1.
99
98
  const expectedCheckpointNumber = blockCheckpointNumber - 1;
100
- if (!opts.force && previousCheckpointNumber !== expectedCheckpointNumber && proposedCheckpointNumber !== expectedCheckpointNumber) {
101
- const [reported, source] = proposedCheckpointNumber > previousCheckpointNumber ? [
102
- proposedCheckpointNumber,
103
- 'proposed'
104
- ] : [
105
- previousCheckpointNumber,
106
- 'confirmed'
107
- ];
108
- throw new CheckpointNumberNotSequentialError(blockCheckpointNumber, reported, source);
99
+ const hasPendingAtExpected = await this.#proposedCheckpoints.hasAsync(expectedCheckpointNumber);
100
+ if (!opts.force && latestCheckpointNumber !== expectedCheckpointNumber && !hasPendingAtExpected) {
101
+ const [latestPendingKey] = await toArray(this.#proposedCheckpoints.keysAsync({
102
+ reverse: true,
103
+ limit: 1
104
+ }));
105
+ const previous = CheckpointNumber(Math.max(latestCheckpointNumber, latestPendingKey ?? 0));
106
+ throw new BlockCheckpointNumberNotSequentialError(blockNumber, blockCheckpointNumber, previous);
109
107
  }
110
108
  // Extract the previous block if there is one and see if it is for the same checkpoint or not
111
109
  const previousBlockResult = await this.getBlock(previousBlockNumber);
@@ -138,14 +136,26 @@ export { TxReceipt } from '@aztec/stdlib/tx';
138
136
  return true;
139
137
  }
140
138
  return await this.db.transactionAsync(async ()=>{
141
- // Check that the checkpoint immediately before the first block to be added is present in the store.
142
139
  const firstCheckpointNumber = checkpoints[0].checkpoint.number;
143
140
  const previousCheckpointNumber = await this.getLatestCheckpointNumber();
144
- if (previousCheckpointNumber !== firstCheckpointNumber - 1 && !opts.force) {
141
+ // Handle already-stored checkpoints at the start of the batch.
142
+ // This can happen after an L1 reorg re-includes a checkpoint in a different L1 block.
143
+ // We accept them if archives match (same content) and update their L1 metadata.
144
+ if (!opts.force && firstCheckpointNumber <= previousCheckpointNumber) {
145
+ checkpoints = await this.skipOrUpdateAlreadyStoredCheckpoints(checkpoints, previousCheckpointNumber);
146
+ if (checkpoints.length === 0) {
147
+ return true;
148
+ }
149
+ // Re-check sequentiality after skipping
150
+ const newFirstNumber = checkpoints[0].checkpoint.number;
151
+ if (previousCheckpointNumber !== newFirstNumber - 1) {
152
+ throw new InitialCheckpointNumberNotSequentialError(newFirstNumber, previousCheckpointNumber);
153
+ }
154
+ } else if (previousCheckpointNumber !== firstCheckpointNumber - 1 && !opts.force) {
145
155
  throw new InitialCheckpointNumberNotSequentialError(firstCheckpointNumber, previousCheckpointNumber);
146
156
  }
147
157
  // Get the last block of the previous checkpoint for archive chaining
148
- let previousBlock = await this.getPreviousCheckpointBlock(firstCheckpointNumber);
158
+ let previousBlock = await this.getPreviousCheckpointBlock(checkpoints[0].checkpoint.number);
149
159
  // Iterate over checkpoints array and insert them, checking that the block numbers are sequential.
150
160
  let previousCheckpoint = undefined;
151
161
  for (const checkpoint of checkpoints){
@@ -169,19 +179,52 @@ export { TxReceipt } from '@aztec/stdlib/tx';
169
179
  attestations: checkpoint.attestations.map((attestation)=>attestation.toBuffer()),
170
180
  checkpointNumber: checkpoint.checkpoint.number,
171
181
  startBlock: checkpoint.checkpoint.blocks[0].number,
172
- blockCount: checkpoint.checkpoint.blocks.length
182
+ blockCount: checkpoint.checkpoint.blocks.length,
183
+ feeAssetPriceModifier: checkpoint.checkpoint.feeAssetPriceModifier.toString()
173
184
  });
174
185
  // Update slot-to-checkpoint index
175
186
  await this.#slotToCheckpoint.set(checkpoint.checkpoint.header.slotNumber, checkpoint.checkpoint.number);
187
+ // Remove proposed checkpoint if it exists, since L1 is authoritative
188
+ await this.#proposedCheckpoints.delete(checkpoint.checkpoint.number);
176
189
  }
177
- // Clear the proposed checkpoint if any of the confirmed checkpoints match or supersede it
178
- const lastConfirmedCheckpointNumber = checkpoints[checkpoints.length - 1].checkpoint.number;
179
- await this.clearProposedCheckpointIfSuperseded(lastConfirmedCheckpointNumber);
180
190
  await this.#lastSynchedL1Block.set(checkpoints[checkpoints.length - 1].l1.blockNumber);
181
191
  return true;
182
192
  });
183
193
  }
184
194
  /**
195
+ * Handles checkpoints at the start of a batch that are already stored (e.g. due to L1 reorg).
196
+ * Verifies the archive root matches, updates L1 metadata, and returns only the new checkpoints.
197
+ */ async skipOrUpdateAlreadyStoredCheckpoints(checkpoints, latestStored) {
198
+ let i = 0;
199
+ for(; i < checkpoints.length && checkpoints[i].checkpoint.number <= latestStored; i++){
200
+ const incoming = checkpoints[i];
201
+ const stored = await this.getCheckpointData(incoming.checkpoint.number);
202
+ if (!stored) {
203
+ break;
204
+ }
205
+ // Verify the checkpoint content matches (archive root)
206
+ if (!stored.archive.root.equals(incoming.checkpoint.archive.root)) {
207
+ throw new Error(`Checkpoint ${incoming.checkpoint.number} already exists in store but with a different archive root. ` + `Stored: ${stored.archive.root}, incoming: ${incoming.checkpoint.archive.root}`);
208
+ }
209
+ // Update L1 metadata and attestations for the already-stored checkpoint
210
+ this.#log.warn(`Checkpoint ${incoming.checkpoint.number} already stored, updating L1 info ` + `(L1 block ${stored.l1.blockNumber} -> ${incoming.l1.blockNumber})`);
211
+ await this.#checkpoints.set(incoming.checkpoint.number, {
212
+ header: incoming.checkpoint.header.toBuffer(),
213
+ archive: incoming.checkpoint.archive.toBuffer(),
214
+ checkpointOutHash: incoming.checkpoint.getCheckpointOutHash().toBuffer(),
215
+ l1: incoming.l1.toBuffer(),
216
+ attestations: incoming.attestations.map((a)=>a.toBuffer()),
217
+ checkpointNumber: incoming.checkpoint.number,
218
+ startBlock: incoming.checkpoint.blocks[0].number,
219
+ blockCount: incoming.checkpoint.blocks.length,
220
+ feeAssetPriceModifier: incoming.checkpoint.feeAssetPriceModifier.toString()
221
+ });
222
+ // Update the sync point to reflect the new L1 block
223
+ await this.#lastSynchedL1Block.set(incoming.l1.blockNumber);
224
+ }
225
+ return checkpoints.slice(i);
226
+ }
227
+ /**
185
228
  * Gets the last block of the checkpoint before the given one.
186
229
  * Returns undefined if there is no previous checkpoint (i.e. genesis).
187
230
  */ async getPreviousCheckpointBlock(checkpointNumber) {
@@ -189,11 +232,12 @@ export { TxReceipt } from '@aztec/stdlib/tx';
189
232
  if (previousCheckpointNumber === INITIAL_CHECKPOINT_NUMBER - 1) {
190
233
  return undefined;
191
234
  }
192
- const previousCheckpointData = await this.getCheckpointData(previousCheckpointNumber);
193
- if (previousCheckpointData === undefined) {
235
+ // Check across both proposed and mined checkpoints
236
+ const predecessor = await this.getProposedCheckpointByNumber(previousCheckpointNumber) ?? await this.getCheckpointData(previousCheckpointNumber);
237
+ if (!predecessor) {
194
238
  throw new CheckpointNotFoundError(previousCheckpointNumber);
195
239
  }
196
- const previousBlockNumber = BlockNumber(previousCheckpointData.startBlock + previousCheckpointData.blockCount - 1);
240
+ const previousBlockNumber = BlockNumber(predecessor.startBlock + predecessor.blockCount - 1);
197
241
  const previousBlock = await this.getBlock(previousBlockNumber);
198
242
  if (previousBlock === undefined) {
199
243
  throw new BlockNotFoundError(previousBlockNumber);
@@ -203,7 +247,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
203
247
  /**
204
248
  * Validates that blocks are sequential, have correct indexes, and chain via archive roots.
205
249
  * This is the same validation used for both confirmed checkpoints (addCheckpoints) and
206
- * proposed checkpoints (setProposedCheckpoint).
250
+ * proposed checkpoints (addProposedCheckpoint).
207
251
  */ validateCheckpointBlocks(blocks, previousBlock) {
208
252
  for (const block of blocks){
209
253
  if (previousBlock) {
@@ -308,11 +352,8 @@ export { TxReceipt } from '@aztec/stdlib/tx';
308
352
  await this.#checkpoints.delete(c);
309
353
  this.#log.debug(`Removed checkpoint ${c}`);
310
354
  }
311
- // Clear any proposed checkpoint that was orphaned by the removal (its base chain no longer exists)
312
- const proposedCheckpointNumber = await this.getProposedCheckpointNumber();
313
- if (proposedCheckpointNumber > checkpointNumber) {
314
- await this.#proposedCheckpoint.delete();
315
- }
355
+ // Evict all pending checkpoints > checkpointNumber (their base chain no longer exists)
356
+ await this.evictProposedCheckpointsFrom(CheckpointNumber(checkpointNumber + 1));
316
357
  return {
317
358
  blocksRemoved
318
359
  };
@@ -357,6 +398,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
357
398
  checkpointNumber: CheckpointNumber(checkpointStorage.checkpointNumber),
358
399
  startBlock: BlockNumber(checkpointStorage.startBlock),
359
400
  blockCount: checkpointStorage.blockCount,
401
+ feeAssetPriceModifier: BigInt(checkpointStorage.feeAssetPriceModifier),
360
402
  l1: L1PublishedData.fromBuffer(checkpointStorage.l1),
361
403
  attestations: checkpointStorage.attestations.map((buf)=>CommitteeAttestation.fromBuffer(buf))
362
404
  };
@@ -443,36 +485,108 @@ export { TxReceipt } from '@aztec/stdlib/tx';
443
485
  return CheckpointNumber(latestCheckpointNumber);
444
486
  }
445
487
  async hasProposedCheckpoint() {
446
- const proposed = await this.#proposedCheckpoint.getAsync();
447
- return proposed !== undefined;
448
- }
449
- /** Deletes the proposed checkpoint from storage. */ async deleteProposedCheckpoint() {
450
- await this.#proposedCheckpoint.delete();
488
+ const [key] = await toArray(this.#proposedCheckpoints.keysAsync({
489
+ limit: 1
490
+ }));
491
+ return key !== undefined;
451
492
  }
452
- /** Clears the proposed checkpoint if the given confirmed checkpoint number supersedes it. */ async clearProposedCheckpointIfSuperseded(confirmedCheckpointNumber) {
453
- const proposedCheckpointNumber = await this.getProposedCheckpointNumber();
454
- if (proposedCheckpointNumber <= confirmedCheckpointNumber) {
455
- await this.#proposedCheckpoint.delete();
493
+ /** Deletes all pending proposed checkpoints from storage. */ async deleteProposedCheckpoints() {
494
+ for await (const key of this.#proposedCheckpoints.keysAsync()){
495
+ await this.#proposedCheckpoints.delete(key);
456
496
  }
457
497
  }
458
- /** Returns the proposed checkpoint data, or undefined if no proposed checkpoint exists. No fallback to confirmed. */ async getProposedCheckpointOnly() {
459
- const stored = await this.#proposedCheckpoint.getAsync();
460
- if (!stored) {
498
+ /**
499
+ * Promotes a specific pending checkpoint to a confirmed checkpoint entry.
500
+ * This persists the checkpoint to the store, removes only that pending entry, and updates the L1 sync point.
501
+ * Remaining pending entries (e.g. N+1, N+2) are left intact — they chain off the just-promoted one.
502
+ * @param checkpointNumber - The checkpoint number to promote.
503
+ * @param l1 - L1 published data for the checkpoint.
504
+ * @param attestations - Committee attestations.
505
+ * @param expectedArchiveRoot - Archive root guard against races.
506
+ */ async promoteProposedToCheckpointed(checkpointNumber, l1, attestations, expectedArchiveRoot) {
507
+ return await this.db.transactionAsync(async ()=>{
508
+ const proposed = await this.getProposedCheckpointByNumber(checkpointNumber);
509
+ if (!proposed) {
510
+ throw new NoProposedCheckpointToPromoteError();
511
+ }
512
+ if (!proposed.archive.root.equals(expectedArchiveRoot)) {
513
+ throw new ProposedCheckpointArchiveRootMismatchError(expectedArchiveRoot, proposed.archive.root);
514
+ }
515
+ // Verify sequentiality: promoted checkpoint must follow the latest confirmed one
516
+ const latestCheckpointNumber = await this.getLatestCheckpointNumber();
517
+ if (latestCheckpointNumber !== proposed.checkpointNumber - 1) {
518
+ throw new ProposedCheckpointPromotionNotSequentialError(proposed.checkpointNumber, latestCheckpointNumber);
519
+ }
520
+ // Write the checkpoint entry
521
+ await this.#checkpoints.set(proposed.checkpointNumber, {
522
+ header: proposed.header.toBuffer(),
523
+ archive: proposed.archive.toBuffer(),
524
+ checkpointOutHash: proposed.checkpointOutHash.toBuffer(),
525
+ l1: l1.toBuffer(),
526
+ attestations: attestations.map((attestation)=>attestation.toBuffer()),
527
+ checkpointNumber: proposed.checkpointNumber,
528
+ startBlock: proposed.startBlock,
529
+ blockCount: proposed.blockCount,
530
+ feeAssetPriceModifier: proposed.feeAssetPriceModifier.toString()
531
+ });
532
+ // Update the slot-to-checkpoint index
533
+ await this.#slotToCheckpoint.set(proposed.header.slotNumber, proposed.checkpointNumber);
534
+ // Remove only this pending entry — remaining entries N+1, N+2, ... stay valid
535
+ await this.#proposedCheckpoints.delete(proposed.checkpointNumber);
536
+ // Update the last synced L1 block
537
+ await this.#lastSynchedL1Block.set(l1.blockNumber);
538
+ });
539
+ }
540
+ /**
541
+ * Returns the latest pending checkpoint (highest-numbered entry), or undefined if none.
542
+ * No fallback to confirmed.
543
+ */ async getLastProposedCheckpoint() {
544
+ const [key] = await toArray(this.#proposedCheckpoints.keysAsync({
545
+ reverse: true,
546
+ limit: 1
547
+ }));
548
+ if (key === undefined) {
461
549
  return undefined;
462
550
  }
463
- return this.convertToProposedCheckpointData(stored);
551
+ const stored = await this.#proposedCheckpoints.getAsync(key);
552
+ return stored ? this.convertToProposedCheckpointData(stored) : undefined;
553
+ }
554
+ /** Returns the pending checkpoint for a specific checkpoint number, or undefined if not found. */ async getProposedCheckpointByNumber(n) {
555
+ const stored = await this.#proposedCheckpoints.getAsync(n);
556
+ return stored ? this.convertToProposedCheckpointData(stored) : undefined;
557
+ }
558
+ /** Returns all pending checkpoints in ascending checkpoint-number order. */ async getProposedCheckpoints() {
559
+ const results = [];
560
+ for await (const [, stored] of this.#proposedCheckpoints.entriesAsync()){
561
+ results.push(this.convertToProposedCheckpointData(stored));
562
+ }
563
+ return results;
464
564
  }
465
565
  /**
466
- * Gets the checkpoint at the proposed tip
467
- * - pending checkpoint if it exists
566
+ * Evicts all pending checkpoints with checkpoint number >= fromNumber.
567
+ * Used for divergent-mined-checkpoint cleanup: when L1 mines checkpoint N with a different archive,
568
+ * all pending >= N must be evicted since they chain off the now-invalid pending N.
569
+ */ async evictProposedCheckpointsFrom(fromNumber) {
570
+ const keysToDelete = [];
571
+ for await (const key of this.#proposedCheckpoints.keysAsync()){
572
+ if (key >= fromNumber) {
573
+ keysToDelete.push(key);
574
+ }
575
+ }
576
+ for (const key of keysToDelete){
577
+ await this.#proposedCheckpoints.delete(key);
578
+ }
579
+ }
580
+ /**
581
+ * Gets the checkpoint at the proposed tip:
582
+ * - latest pending checkpoint if any exist
468
583
  * - fallsback to latest confirmed checkpoint otherwise
469
- * @returns CommonCheckpointData
470
- */ async getProposedCheckpoint() {
471
- const stored = await this.#proposedCheckpoint.getAsync();
472
- if (!stored) {
584
+ */ async getLastCheckpoint() {
585
+ const latest = await this.getLastProposedCheckpoint();
586
+ if (!latest) {
473
587
  return this.getCheckpointData(await this.getLatestCheckpointNumber());
474
588
  }
475
- return this.convertToProposedCheckpointData(stored);
589
+ return latest;
476
590
  }
477
591
  convertToProposedCheckpointData(stored) {
478
592
  return {
@@ -490,7 +604,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
490
604
  * Attempts to get the proposedCheckpoint's number, if there is not one, then fallback to the latest confirmed checkpoint number.
491
605
  * @returns CheckpointNumber
492
606
  */ async getProposedCheckpointNumber() {
493
- const proposed = await this.getProposedCheckpoint();
607
+ const proposed = await this.getLastCheckpoint();
494
608
  if (!proposed) {
495
609
  return await this.getLatestCheckpointNumber();
496
610
  }
@@ -500,7 +614,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
500
614
  * Attempts to get the proposedCheckpoint's block number, if there is not one, then fallback to the checkpointed block number
501
615
  * @returns BlockNumber
502
616
  */ async getProposedCheckpointL2BlockNumber() {
503
- const proposed = await this.getProposedCheckpoint();
617
+ const proposed = await this.getLastCheckpoint();
504
618
  if (!proposed) {
505
619
  return await this.getCheckpointedL2BlockNumber();
506
620
  }
@@ -526,7 +640,10 @@ export { TxReceipt } from '@aztec/stdlib/tx';
526
640
  * @param start - Number of the first block to return (inclusive).
527
641
  * @param limit - The number of blocks to return.
528
642
  * @returns The requested L2 blocks
529
- */ async *getCheckpointedBlocks(start, limit) {
643
+ */ getCheckpointedBlocks(start, limit) {
644
+ return toArray(this.iterateCheckpointedBlocks(start, limit));
645
+ }
646
+ /** Async iterator variant of {@link getCheckpointedBlocks}. */ async *iterateCheckpointedBlocks(start, limit) {
530
647
  const checkpointCache = new Map();
531
648
  for await (const [blockNumber, blockStorage] of this.getBlockStorages(start, limit)){
532
649
  const block = await this.getBlockFromBlockStorage(blockNumber, blockStorage);
@@ -559,7 +676,10 @@ export { TxReceipt } from '@aztec/stdlib/tx';
559
676
  * @param start - Number of the first block to return (inclusive).
560
677
  * @param limit - The number of blocks to return.
561
678
  * @returns The requested L2 blocks
562
- */ async *getBlocks(start, limit) {
679
+ */ getBlocks(start, limit) {
680
+ return toArray(this.iterateBlocks(start, limit));
681
+ }
682
+ /** Async iterator variant of {@link getBlocks}. */ async *iterateBlocks(start, limit) {
563
683
  for await (const [blockNumber, blockStorage] of this.getBlockStorages(start, limit)){
564
684
  const block = await this.getBlockFromBlockStorage(blockNumber, blockStorage);
565
685
  if (block) {
@@ -579,6 +699,37 @@ export { TxReceipt } from '@aztec/stdlib/tx';
579
699
  return this.getBlockDataFromBlockStorage(blockStorage);
580
700
  }
581
701
  /**
702
+ * Gets block metadata plus checkpoint-derived context (L1 publish info, attestations) without
703
+ * deserializing tx bodies. When the block's containing checkpoint has not yet been L1-confirmed,
704
+ * `checkpoint` and `l1` are `undefined` and `attestations` is empty.
705
+ */ async getBlockDataWithCheckpointContext(blockNumber) {
706
+ const blockStorage = await this.#blocks.getAsync(blockNumber);
707
+ if (!blockStorage || !blockStorage.header) {
708
+ return undefined;
709
+ }
710
+ const data = this.getBlockDataFromBlockStorage(blockStorage);
711
+ const checkpointStorage = await this.#checkpoints.getAsync(blockStorage.checkpointNumber);
712
+ if (!checkpointStorage) {
713
+ return {
714
+ data,
715
+ checkpoint: undefined,
716
+ l1: undefined,
717
+ attestations: []
718
+ };
719
+ }
720
+ const checkpoint = this.checkpointDataFromCheckpointStorage(checkpointStorage);
721
+ return {
722
+ data,
723
+ checkpoint,
724
+ l1: checkpoint.l1,
725
+ attestations: checkpoint.attestations
726
+ };
727
+ }
728
+ /** Returns the checkpoint number that contains the given slot (or undefined if not found). */ async getCheckpointNumberBySlot(slot) {
729
+ const checkpointNumber = await this.#slotToCheckpoint.getAsync(slot);
730
+ return checkpointNumber === undefined ? undefined : CheckpointNumber(checkpointNumber);
731
+ }
732
+ /**
582
733
  * Gets block metadata (without tx data) by archive root.
583
734
  * @param archive - The archive root of the block to return.
584
735
  * @returns The requested block data.
@@ -657,7 +808,10 @@ export { TxReceipt } from '@aztec/stdlib/tx';
657
808
  * @param start - Number of the first block to return (inclusive).
658
809
  * @param limit - The number of blocks to return.
659
810
  * @returns The requested L2 block headers
660
- */ async *getBlockHeaders(start, limit) {
811
+ */ getBlockHeaders(start, limit) {
812
+ return toArray(this.iterateBlockHeaders(start, limit));
813
+ }
814
+ /** Async iterator variant of {@link getBlockHeaders}. */ async *iterateBlockHeaders(start, limit) {
661
815
  for await (const [blockNumber, blockStorage] of this.getBlockStorages(start, limit)){
662
816
  const header = BlockHeader.fromBuffer(blockStorage.header);
663
817
  if (header.getBlockNumber() !== blockNumber) {
@@ -683,7 +837,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
683
837
  return {
684
838
  header: BlockHeader.fromBuffer(blockStorage.header),
685
839
  archive: AppendOnlyTreeSnapshot.fromBuffer(blockStorage.archive),
686
- blockHash: Fr.fromBuffer(blockStorage.blockHash),
840
+ blockHash: BlockHash.fromBuffer(blockStorage.blockHash),
687
841
  checkpointNumber: CheckpointNumber(blockStorage.checkpointNumber),
688
842
  indexWithinCheckpoint: IndexWithinCheckpoint(blockStorage.indexWithinCheckpoint)
689
843
  };
@@ -805,18 +959,23 @@ export { TxReceipt } from '@aztec/stdlib/tx';
805
959
  setSynchedL1BlockNumber(l1BlockNumber) {
806
960
  return this.#lastSynchedL1Block.set(l1BlockNumber);
807
961
  }
808
- /** Sets the proposed checkpoint (not yet L1-confirmed). Only accepts confirmed + 1.
809
- * Computes archive and checkpointOutHash from the stored blocks. */ async setProposedCheckpoint(proposed) {
962
+ /**
963
+ * Adds a proposed checkpoint to the pending queue.
964
+ * Accepts proposed.checkpointNumber === latestTip + 1, where latestTip is the highest of
965
+ * confirmed and the highest pending checkpoint number.
966
+ * Computes archive and checkpointOutHash from the stored blocks.
967
+ */ async addProposedCheckpoint(proposed) {
810
968
  return await this.db.transactionAsync(async ()=>{
811
- const current = await this.getProposedCheckpointNumber();
812
- if (proposed.checkpointNumber <= current) {
813
- throw new ProposedCheckpointStaleError(proposed.checkpointNumber, current);
814
- }
815
969
  const confirmed = await this.getLatestCheckpointNumber();
816
- if (proposed.checkpointNumber !== confirmed + 1) {
817
- throw new ProposedCheckpointNotSequentialError(proposed.checkpointNumber, confirmed);
970
+ const [latestPendingKey] = await toArray(this.#proposedCheckpoints.keysAsync({
971
+ reverse: true,
972
+ limit: 1
973
+ }));
974
+ const latestTip = CheckpointNumber(latestPendingKey !== undefined ? Math.max(latestPendingKey, confirmed) : confirmed);
975
+ if (proposed.checkpointNumber !== latestTip + 1) {
976
+ throw new ProposedCheckpointNotSequentialError(proposed.checkpointNumber, latestTip);
818
977
  }
819
- // Ensure the previous checkpoint + blocks exist
978
+ // Ensure the predecessor block (from pending or confirmed chain) exists
820
979
  const previousBlock = await this.getPreviousCheckpointBlock(proposed.checkpointNumber);
821
980
  const blocks = [];
822
981
  for(let i = 0; i < proposed.blockCount; i++){
@@ -829,7 +988,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
829
988
  this.validateCheckpointBlocks(blocks, previousBlock);
830
989
  const archive = blocks[blocks.length - 1].archive;
831
990
  const checkpointOutHash = Checkpoint.getCheckpointOutHash(blocks);
832
- await this.#proposedCheckpoint.set({
991
+ await this.#proposedCheckpoints.set(proposed.checkpointNumber, {
833
992
  header: proposed.header.toBuffer(),
834
993
  archive: archive.toBuffer(),
835
994
  checkpointOutHash: checkpointOutHash.toBuffer(),
@@ -1,6 +1,6 @@
1
1
  import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
3
- import type { ContractClassPublic } from '@aztec/stdlib/contract';
3
+ import type { ContractClassPublic, ContractClassPublicWithCommitment } from '@aztec/stdlib/contract';
4
4
  /**
5
5
  * LMDB-based contract class storage for the archiver.
6
6
  */
@@ -8,10 +8,24 @@ export declare class ContractClassStore {
8
8
  #private;
9
9
  private db;
10
10
  constructor(db: AztecAsyncKVStore);
11
+ /**
12
+ * Adds multiple contract classes to the store.
13
+ * @param data - Contract classes (with bytecode commitments) to add.
14
+ * @param blockNumber - L2 block number where the classes were registered.
15
+ * @returns True if every insert succeeded.
16
+ */
17
+ addContractClasses(data: ContractClassPublicWithCommitment[], blockNumber: number): Promise<boolean>;
18
+ /**
19
+ * Removes multiple contract classes from the store, but only if they were registered at or after the given block.
20
+ * @param data - Contract classes to delete.
21
+ * @param blockNumber - Lower bound on the block number at which the classes were registered.
22
+ * @returns True if every delete succeeded.
23
+ */
24
+ deleteContractClasses(data: ContractClassPublic[], blockNumber: number): Promise<boolean>;
11
25
  addContractClass(contractClass: ContractClassPublic, bytecodeCommitment: Fr, blockNumber: number): Promise<void>;
12
- deleteContractClasses(contractClass: ContractClassPublic, blockNumber: number): Promise<void>;
26
+ deleteContractClass(contractClass: ContractClassPublic, blockNumber: number): Promise<void>;
13
27
  getContractClass(id: Fr): Promise<ContractClassPublic | undefined>;
14
28
  getBytecodeCommitment(id: Fr): Promise<Fr | undefined>;
15
29
  getContractClassIds(): Promise<Fr[]>;
16
30
  }
17
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udHJhY3RfY2xhc3Nfc3RvcmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zdG9yZS9jb250cmFjdF9jbGFzc19zdG9yZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFHcEQsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQWlCLE1BQU0saUJBQWlCLENBQUM7QUFDeEUsT0FBTyxLQUFLLEVBQUUsbUJBQW1CLEVBQXNDLE1BQU0sd0JBQXdCLENBQUM7QUFFdEc7O0dBRUc7QUFDSCxxQkFBYSxrQkFBa0I7O0lBSWpCLE9BQU8sQ0FBQyxFQUFFO0lBQXRCLFlBQW9CLEVBQUUsRUFBRSxpQkFBaUIsRUFHeEM7SUFFSyxnQkFBZ0IsQ0FDcEIsYUFBYSxFQUFFLG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kB,EAAE,EAAE,EACtB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CAYf;IAEK,mBAAmB,CAAC,aAAa,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQhG;IAEK,gBAAgB,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAGvE;IAEK,qBAAqB,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC,CAG3D;IAEK,mBAAmB,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC,CAEzC;CACF"}
@@ -12,6 +12,22 @@ import { BufferReader, numToUInt8, serializeToBuffer } from '@aztec/foundation/s
12
12
  this.#contractClasses = db.openMap('archiver_contract_classes');
13
13
  this.#bytecodeCommitments = db.openMap('archiver_bytecode_commitments');
14
14
  }
15
+ /**
16
+ * Adds multiple contract classes to the store.
17
+ * @param data - Contract classes (with bytecode commitments) to add.
18
+ * @param blockNumber - L2 block number where the classes were registered.
19
+ * @returns True if every insert succeeded.
20
+ */ async addContractClasses(data, blockNumber) {
21
+ return (await Promise.all(data.map((c)=>this.addContractClass(c, c.publicBytecodeCommitment, blockNumber)))).every(Boolean);
22
+ }
23
+ /**
24
+ * Removes multiple contract classes from the store, but only if they were registered at or after the given block.
25
+ * @param data - Contract classes to delete.
26
+ * @param blockNumber - Lower bound on the block number at which the classes were registered.
27
+ * @returns True if every delete succeeded.
28
+ */ async deleteContractClasses(data, blockNumber) {
29
+ return (await Promise.all(data.map((c)=>this.deleteContractClass(c, blockNumber)))).every(Boolean);
30
+ }
15
31
  async addContractClass(contractClass, bytecodeCommitment, blockNumber) {
16
32
  await this.db.transactionAsync(async ()=>{
17
33
  const key = contractClass.id.toString();
@@ -25,7 +41,7 @@ import { BufferReader, numToUInt8, serializeToBuffer } from '@aztec/foundation/s
25
41
  await this.#bytecodeCommitments.set(key, bytecodeCommitment.toBuffer());
26
42
  });
27
43
  }
28
- async deleteContractClasses(contractClass, blockNumber) {
44
+ async deleteContractClass(contractClass, blockNumber) {
29
45
  const restoredContractClass = await this.#contractClasses.getAsync(contractClass.id.toString());
30
46
  if (restoredContractClass && deserializeContractClassPublic(restoredContractClass).l2BlockNumber >= blockNumber) {
31
47
  await this.db.transactionAsync(async ()=>{
@@ -11,6 +11,33 @@ export declare class ContractInstanceStore {
11
11
  #private;
12
12
  private db;
13
13
  constructor(db: AztecAsyncKVStore);
14
+ /**
15
+ * Adds multiple contract instances to the store.
16
+ * @param data - Contract instances to add.
17
+ * @param blockNumber - L2 block number where the instances were deployed.
18
+ * @returns True if every insert succeeded.
19
+ */
20
+ addContractInstances(data: ContractInstanceWithAddress[], blockNumber: number): Promise<boolean>;
21
+ /**
22
+ * Removes multiple contract instances from the store.
23
+ * @param data - Contract instances to delete.
24
+ * @returns True if every delete succeeded.
25
+ */
26
+ deleteContractInstances(data: ContractInstanceWithAddress[]): Promise<boolean>;
27
+ /**
28
+ * Adds multiple contract instance updates to the store.
29
+ * @param data - Contract instance updates to add.
30
+ * @param timestamp - Timestamp at which the updates were scheduled.
31
+ * @returns True if every insert succeeded.
32
+ */
33
+ addContractInstanceUpdates(data: ContractInstanceUpdateWithAddress[], timestamp: UInt64): Promise<boolean>;
34
+ /**
35
+ * Removes multiple contract instance updates from the store.
36
+ * @param data - Contract instance updates to delete.
37
+ * @param timestamp - Timestamp at which the updates were scheduled.
38
+ * @returns True if every delete succeeded.
39
+ */
40
+ deleteContractInstanceUpdates(data: ContractInstanceUpdateWithAddress[], timestamp: UInt64): Promise<boolean>;
14
41
  addContractInstance(contractInstance: ContractInstanceWithAddress, blockNumber: number): Promise<void>;
15
42
  deleteContractInstance(contractInstance: ContractInstanceWithAddress): Promise<void>;
16
43
  getUpdateKey(contractAddress: AztecAddress, timestamp: UInt64, logIndex?: number): ContractInstanceUpdateKey;
@@ -21,4 +48,4 @@ export declare class ContractInstanceStore {
21
48
  getContractInstanceDeploymentBlockNumber(address: AztecAddress): Promise<number | undefined>;
22
49
  }
23
50
  export {};
24
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udHJhY3RfaW5zdGFuY2Vfc3RvcmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zdG9yZS9jb250cmFjdF9pbnN0YW5jZV9zdG9yZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUN6RCxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBaUIsTUFBTSxpQkFBaUIsQ0FBQztBQUN4RSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEVBQ0wsS0FBSyxpQ0FBaUMsRUFDdEMsS0FBSywyQkFBMkIsRUFHakMsTUFBTSx3QkFBd0IsQ0FBQztBQUNoQyxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUVsRCxLQUFLLHlCQUF5QixHQUFHLENBQUMsTUFBTSxFQUFFLE1BQU0sQ0FBQyxHQUFHLENBQUMsTUFBTSxFQUFFLE1BQU0sRUFBRSxNQUFNLENBQUMsQ0FBQztBQUU3RTs7R0FFRztBQUNILHFCQUFhLHFCQUFxQjs7SUFLcEIsT0FBTyxDQUFDLEVBQUU7SUFBdEIsWUFBb0IsRUFBRSxFQUFFLGlCQUFpQixFQUl4QztJQUVELG1CQUFtQixDQUFDLGdCQUFnQixFQUFFLDJCQUEyQixFQUFFLFdBQVcsRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQVdyRztJQUVELHNCQUFzQixDQUFDLGdCQUFnQixFQUFFLDJCQUEyQixHQUFHLE9BQU8sQ0FBQ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AiC,CAAC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,CAoBlH;IAEK,mBAAmB,CACvB,OAAO,EAAE,YAAY,EACrB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,2BAA2B,GAAG,SAAS,CAAC,CAalD;IAED,wCAAwC,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAE3F;CACF"}
1
+ {"version":3,"file":"contract_instance_store.d.ts","sourceRoot":"","sources":["../../src/store/contract_instance_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EACL,KAAK,iCAAiC,EACtC,KAAK,2BAA2B,EAGjC,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,KAAK,yBAAyB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAE7E;;GAEG;AACH,qBAAa,qBAAqB;;IAKpB,OAAO,CAAC,EAAE;IAAtB,YAAoB,EAAE,EAAE,iBAAiB,EAIxC;IAED;;;;;OAKG;IACG,oBAAoB,CAAC,IAAI,EAAE,2BAA2B,EAAE,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAErG;IAED;;;;OAIG;IACG,uBAAuB,CAAC,IAAI,EAAE,2BAA2B,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAEnF;IAED;;;;;OAKG;IACG,0BAA0B,CAAC,IAAI,EAAE,iCAAiC,EAAE,EAAE,SAAS,EAAE,MAAM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