@aztec/archiver 0.0.1-commit.343b43af6 → 0.0.1-commit.35158ae7e

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 (61) hide show
  1. package/dest/archiver.d.ts +1 -2
  2. package/dest/archiver.d.ts.map +1 -1
  3. package/dest/archiver.js +21 -11
  4. package/dest/config.d.ts +3 -3
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +2 -1
  7. package/dest/errors.d.ts +15 -1
  8. package/dest/errors.d.ts.map +1 -1
  9. package/dest/errors.js +18 -0
  10. package/dest/factory.d.ts +2 -2
  11. package/dest/factory.d.ts.map +1 -1
  12. package/dest/factory.js +16 -13
  13. package/dest/modules/data_source_base.d.ts +3 -3
  14. package/dest/modules/data_source_base.d.ts.map +1 -1
  15. package/dest/modules/data_source_base.js +5 -5
  16. package/dest/modules/data_store_updater.d.ts +3 -6
  17. package/dest/modules/data_store_updater.d.ts.map +1 -1
  18. package/dest/modules/data_store_updater.js +47 -65
  19. package/dest/modules/l1_synchronizer.d.ts +1 -1
  20. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  21. package/dest/modules/l1_synchronizer.js +9 -5
  22. package/dest/store/block_store.d.ts +3 -2
  23. package/dest/store/block_store.d.ts.map +1 -1
  24. package/dest/store/block_store.js +7 -4
  25. package/dest/store/contract_class_store.d.ts +2 -3
  26. package/dest/store/contract_class_store.d.ts.map +1 -1
  27. package/dest/store/contract_class_store.js +7 -67
  28. package/dest/store/contract_instance_store.d.ts +1 -1
  29. package/dest/store/contract_instance_store.d.ts.map +1 -1
  30. package/dest/store/contract_instance_store.js +6 -2
  31. package/dest/store/kv_archiver_store.d.ts +14 -12
  32. package/dest/store/kv_archiver_store.d.ts.map +1 -1
  33. package/dest/store/kv_archiver_store.js +15 -14
  34. package/dest/store/log_store.d.ts +6 -3
  35. package/dest/store/log_store.d.ts.map +1 -1
  36. package/dest/store/log_store.js +93 -16
  37. package/dest/store/message_store.d.ts +5 -1
  38. package/dest/store/message_store.d.ts.map +1 -1
  39. package/dest/store/message_store.js +13 -0
  40. package/dest/test/fake_l1_state.d.ts +1 -1
  41. package/dest/test/fake_l1_state.d.ts.map +1 -1
  42. package/dest/test/fake_l1_state.js +11 -3
  43. package/dest/test/mock_l2_block_source.d.ts +1 -1
  44. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  45. package/dest/test/mock_l2_block_source.js +2 -2
  46. package/package.json +13 -13
  47. package/src/archiver.ts +24 -11
  48. package/src/config.ts +8 -1
  49. package/src/errors.ts +30 -0
  50. package/src/factory.ts +17 -10
  51. package/src/modules/data_source_base.ts +9 -4
  52. package/src/modules/data_store_updater.ts +54 -94
  53. package/src/modules/l1_synchronizer.ts +15 -10
  54. package/src/store/block_store.ts +11 -2
  55. package/src/store/contract_class_store.ts +8 -106
  56. package/src/store/contract_instance_store.ts +8 -5
  57. package/src/store/kv_archiver_store.ts +22 -25
  58. package/src/store/log_store.ts +126 -27
  59. package/src/store/message_store.ts +19 -0
  60. package/src/test/fake_l1_state.ts +15 -5
  61. package/src/test/mock_l2_block_source.ts +7 -1
@@ -14,6 +14,7 @@ import {
14
14
  } from '@aztec/kv-store';
15
15
  import { InboxLeaf } from '@aztec/stdlib/messaging';
16
16
 
17
+ import { L1ToL2MessagesNotReadyError } from '../errors.js';
17
18
  import {
18
19
  type InboxMessage,
19
20
  deserializeInboxMessage,
@@ -40,6 +41,8 @@ export class MessageStore {
40
41
  #lastSynchedL1Block: AztecAsyncSingleton<Buffer>;
41
42
  /** Stores total messages stored */
42
43
  #totalMessageCount: AztecAsyncSingleton<bigint>;
44
+ /** Stores the checkpoint number whose message tree is currently being filled on L1. */
45
+ #inboxTreeInProgress: AztecAsyncSingleton<bigint>;
43
46
 
44
47
  #log = createLogger('archiver:message_store');
45
48
 
@@ -48,6 +51,7 @@ export class MessageStore {
48
51
  this.#l1ToL2MessageIndices = db.openMap('archiver_l1_to_l2_message_indices');
49
52
  this.#lastSynchedL1Block = db.openSingleton('archiver_last_l1_block_id');
50
53
  this.#totalMessageCount = db.openSingleton('archiver_l1_to_l2_message_count');
54
+ this.#inboxTreeInProgress = db.openSingleton('archiver_inbox_tree_in_progress');
51
55
  }
52
56
 
53
57
  public async getTotalL1ToL2MessageCount(): Promise<bigint> {
@@ -185,7 +189,22 @@ export class MessageStore {
185
189
  return msg ? deserializeInboxMessage(msg) : undefined;
186
190
  }
187
191
 
192
+ /** Returns the inbox tree-in-progress checkpoint number from L1, or undefined if not yet set. */
193
+ public getInboxTreeInProgress(): Promise<bigint | undefined> {
194
+ return this.#inboxTreeInProgress.getAsync();
195
+ }
196
+
197
+ /** Persists the inbox tree-in-progress checkpoint number from L1 state. */
198
+ public async setInboxTreeInProgress(value: bigint): Promise<void> {
199
+ await this.#inboxTreeInProgress.set(value);
200
+ }
201
+
188
202
  public async getL1ToL2Messages(checkpointNumber: CheckpointNumber): Promise<Fr[]> {
203
+ const treeInProgress = await this.#inboxTreeInProgress.getAsync();
204
+ if (treeInProgress !== undefined && BigInt(checkpointNumber) >= treeInProgress) {
205
+ throw new L1ToL2MessagesNotReadyError(checkpointNumber, treeInProgress);
206
+ }
207
+
189
208
  const messages: Fr[] = [];
190
209
 
191
210
  const [startIndex, endIndex] = InboxLeaf.indexRangeForCheckpoint(checkpointNumber);
@@ -1,5 +1,6 @@
1
1
  import type { BlobClientInterface } from '@aztec/blob-client/client';
2
2
  import { type Blob, getBlobsPerL1Block, getPrefixedEthBlobCommitments } from '@aztec/blob-lib';
3
+ import { INITIAL_CHECKPOINT_NUMBER } from '@aztec/constants';
3
4
  import type { CheckpointProposedLog, InboxContract, MessageSentLog, RollupContract } from '@aztec/ethereum/contracts';
4
5
  import { MULTI_CALL_3_ADDRESS } from '@aztec/ethereum/contracts';
5
6
  import type { ViemPublicClient } from '@aztec/ethereum/types';
@@ -450,13 +451,22 @@ export class FakeL1State {
450
451
  createMockInboxContract(_publicClient: MockProxy<ViemPublicClient>): MockProxy<InboxContract> {
451
452
  const mockInbox = mock<InboxContract>();
452
453
 
453
- mockInbox.getState.mockImplementation(() =>
454
- Promise.resolve({
454
+ mockInbox.getState.mockImplementation(() => {
455
+ // treeInProgress must be > any sealed checkpoint. On L1, a checkpoint can only be proposed
456
+ // after its messages are sealed, so treeInProgress > checkpointNumber for all published checkpoints.
457
+ const maxFromMessages =
458
+ this.messages.length > 0 ? Math.max(...this.messages.map(m => Number(m.checkpointNumber))) + 1 : 0;
459
+ const maxFromCheckpoints =
460
+ this.checkpoints.length > 0
461
+ ? Math.max(...this.checkpoints.filter(cp => !cp.pruned).map(cp => Number(cp.checkpointNumber))) + 1
462
+ : 0;
463
+ const treeInProgress = Math.max(maxFromMessages, maxFromCheckpoints, INITIAL_CHECKPOINT_NUMBER);
464
+ return Promise.resolve({
455
465
  messagesRollingHash: this.messagesRollingHash,
456
466
  totalMessagesInserted: BigInt(this.messages.length),
457
- treeInProgress: 0n,
458
- }),
459
- );
467
+ treeInProgress: BigInt(treeInProgress),
468
+ });
469
+ });
460
470
 
461
471
  // Mock the wrapper methods for fetching message events
462
472
  mockInbox.getMessageSentEvents.mockImplementation((fromBlock: bigint, toBlock: bigint) =>
@@ -18,7 +18,12 @@ import {
18
18
  } from '@aztec/stdlib/block';
19
19
  import { Checkpoint, type CheckpointData, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
20
20
  import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
21
- import { EmptyL1RollupConstants, type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
21
+ import {
22
+ EmptyL1RollupConstants,
23
+ type L1RollupConstants,
24
+ getEpochAtSlot,
25
+ getSlotRangeForEpoch,
26
+ } from '@aztec/stdlib/epoch-helpers';
22
27
  import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
23
28
  import { CheckpointHeader } from '@aztec/stdlib/rollup';
24
29
  import { type BlockHeader, TxExecutionResult, TxHash, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
@@ -394,6 +399,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
394
399
  txEffect.transactionFee.toBigInt(),
395
400
  await block.hash(),
396
401
  block.number,
402
+ getEpochAtSlot(block.slot, EmptyL1RollupConstants),
397
403
  );
398
404
  }
399
405
  }