@aztec/archiver 0.0.1-commit.993d240 → 0.0.1-commit.9a89641

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 (86) hide show
  1. package/dest/archiver.d.ts +44 -8
  2. package/dest/archiver.d.ts.map +1 -1
  3. package/dest/archiver.js +103 -35
  4. package/dest/config.d.ts +5 -4
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +28 -7
  7. package/dest/factory.d.ts +8 -1
  8. package/dest/factory.d.ts.map +1 -1
  9. package/dest/factory.js +41 -5
  10. package/dest/l1/calldata_retriever.d.ts +8 -1
  11. package/dest/l1/calldata_retriever.d.ts.map +1 -1
  12. package/dest/l1/calldata_retriever.js +7 -6
  13. package/dest/l1/data_retrieval.d.ts +7 -2
  14. package/dest/l1/data_retrieval.d.ts.map +1 -1
  15. package/dest/modules/contract_data_source_adapter.d.ts +2 -2
  16. package/dest/modules/contract_data_source_adapter.d.ts.map +1 -1
  17. package/dest/modules/contract_data_source_adapter.js +1 -9
  18. package/dest/modules/data_source_base.d.ts +5 -6
  19. package/dest/modules/data_source_base.d.ts.map +1 -1
  20. package/dest/modules/data_source_base.js +9 -38
  21. package/dest/modules/data_store_updater.d.ts +1 -1
  22. package/dest/modules/data_store_updater.d.ts.map +1 -1
  23. package/dest/modules/data_store_updater.js +4 -3
  24. package/dest/modules/instrumentation.d.ts +9 -1
  25. package/dest/modules/instrumentation.d.ts.map +1 -1
  26. package/dest/modules/instrumentation.js +23 -2
  27. package/dest/modules/l1_synchronizer.d.ts +3 -3
  28. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  29. package/dest/modules/l1_synchronizer.js +78 -41
  30. package/dest/modules/outbox_trees_resolver.d.ts +64 -0
  31. package/dest/modules/outbox_trees_resolver.d.ts.map +1 -0
  32. package/dest/modules/outbox_trees_resolver.js +184 -0
  33. package/dest/modules/validation.d.ts +29 -7
  34. package/dest/modules/validation.d.ts.map +1 -1
  35. package/dest/modules/validation.js +31 -13
  36. package/dest/store/block_store.d.ts +26 -22
  37. package/dest/store/block_store.d.ts.map +1 -1
  38. package/dest/store/block_store.js +105 -78
  39. package/dest/store/contract_class_store.d.ts +1 -1
  40. package/dest/store/contract_class_store.d.ts.map +1 -1
  41. package/dest/store/contract_class_store.js +19 -1
  42. package/dest/store/contract_instance_store.d.ts +1 -1
  43. package/dest/store/contract_instance_store.d.ts.map +1 -1
  44. package/dest/store/contract_instance_store.js +18 -1
  45. package/dest/store/log_store.d.ts +1 -1
  46. package/dest/store/log_store.d.ts.map +1 -1
  47. package/dest/store/log_store.js +3 -3
  48. package/dest/store/log_store_codec.d.ts +9 -1
  49. package/dest/store/log_store_codec.d.ts.map +1 -1
  50. package/dest/store/log_store_codec.js +9 -0
  51. package/dest/test/fake_l1_state.js +3 -3
  52. package/dest/test/mock_l1_to_l2_message_source.d.ts +1 -1
  53. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  54. package/dest/test/mock_l1_to_l2_message_source.js +1 -2
  55. package/dest/test/mock_l2_block_source.d.ts +4 -11
  56. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  57. package/dest/test/mock_l2_block_source.js +15 -39
  58. package/dest/test/mock_structs.d.ts +1 -1
  59. package/dest/test/mock_structs.d.ts.map +1 -1
  60. package/dest/test/mock_structs.js +2 -2
  61. package/dest/test/noop_l1_archiver.d.ts +8 -3
  62. package/dest/test/noop_l1_archiver.d.ts.map +1 -1
  63. package/dest/test/noop_l1_archiver.js +12 -9
  64. package/package.json +13 -13
  65. package/src/archiver.ts +147 -42
  66. package/src/config.ts +34 -16
  67. package/src/factory.ts +48 -4
  68. package/src/l1/calldata_retriever.ts +13 -6
  69. package/src/l1/data_retrieval.ts +8 -1
  70. package/src/modules/contract_data_source_adapter.ts +1 -10
  71. package/src/modules/data_source_base.ts +17 -44
  72. package/src/modules/data_store_updater.ts +4 -3
  73. package/src/modules/instrumentation.ts +15 -2
  74. package/src/modules/l1_synchronizer.ts +120 -57
  75. package/src/modules/outbox_trees_resolver.ts +220 -0
  76. package/src/modules/validation.ts +71 -15
  77. package/src/store/block_store.ts +108 -101
  78. package/src/store/contract_class_store.ts +19 -1
  79. package/src/store/contract_instance_store.ts +18 -1
  80. package/src/store/log_store.ts +3 -2
  81. package/src/store/log_store_codec.ts +11 -0
  82. package/src/test/fake_l1_state.ts +3 -3
  83. package/src/test/mock_l1_to_l2_message_source.ts +0 -1
  84. package/src/test/mock_l2_block_source.ts +14 -53
  85. package/src/test/mock_structs.ts +5 -2
  86. package/src/test/noop_l1_archiver.ts +30 -11
@@ -38,16 +38,11 @@ import {
38
38
  PublishedCheckpoint,
39
39
  } from '@aztec/stdlib/checkpoint';
40
40
  import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
41
- import {
42
- EmptyL1RollupConstants,
43
- type L1RollupConstants,
44
- getEpochAtSlot,
45
- getSlotRangeForEpoch,
46
- } from '@aztec/stdlib/epoch-helpers';
41
+ import { EmptyL1RollupConstants, type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
47
42
  import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
48
43
  import { CheckpointHeader } from '@aztec/stdlib/rollup';
49
44
  import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
50
- import { BlockHeader, TxExecutionResult, TxHash, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
45
+ import { BlockHeader, TxHash } from '@aztec/stdlib/tx';
51
46
  import type { UInt64 } from '@aztec/stdlib/types';
52
47
 
53
48
  /**
@@ -60,7 +55,6 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
60
55
  private provenBlockNumber: number = 0;
61
56
  private finalizedBlockNumber: number = 0;
62
57
  private checkpointedBlockNumber: number = 0;
63
- private proposedCheckpointBlockNumber: number = 0;
64
58
 
65
59
  private initialHeader: BlockHeader = BlockHeader.empty();
66
60
  private initialHeaderHash: BlockHash = GENESIS_BLOCK_HEADER_HASH;
@@ -169,7 +163,6 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
169
163
  });
170
164
  // Keep tip numbers consistent with remaining blocks.
171
165
  this.checkpointedBlockNumber = Math.min(this.checkpointedBlockNumber, maxBlockNum);
172
- this.proposedCheckpointBlockNumber = Math.min(this.proposedCheckpointBlockNumber, maxBlockNum);
173
166
  this.provenBlockNumber = Math.min(this.provenBlockNumber, maxBlockNum);
174
167
  this.finalizedBlockNumber = Math.min(this.finalizedBlockNumber, maxBlockNum);
175
168
  this.log.verbose(`Removed ${numBlocks} blocks from the mock L2 block source`);
@@ -186,17 +179,9 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
186
179
  this.finalizedBlockNumber = finalizedBlockNumber;
187
180
  }
188
181
 
189
- public setProposedCheckpointBlockNumber(blockNumber: number) {
190
- this.proposedCheckpointBlockNumber = blockNumber;
191
- }
192
-
193
182
  public setCheckpointedBlockNumber(checkpointedBlockNumber: number) {
194
183
  const prevCheckpointed = this.checkpointedBlockNumber;
195
184
  this.checkpointedBlockNumber = checkpointedBlockNumber;
196
- // Proposed checkpoint is always at least as advanced as checkpointed
197
- if (this.proposedCheckpointBlockNumber < checkpointedBlockNumber) {
198
- this.proposedCheckpointBlockNumber = checkpointedBlockNumber;
199
- }
200
185
  // Auto-create single-block checkpoints for newly checkpointed blocks that don't have one yet.
201
186
  // This handles blocks added via addProposedBlocks that are now being marked as checkpointed.
202
187
  const newCheckpoints: Checkpoint[] = [];
@@ -260,10 +245,6 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
260
245
  return block ? block.header.globalVariables.blockNumber : undefined;
261
246
  }
262
247
 
263
- public getProposedCheckpointL2BlockNumber() {
264
- return Promise.resolve(BlockNumber(this.proposedCheckpointBlockNumber));
265
- }
266
-
267
248
  public getCheckpoint(query: CheckpointQuery): Promise<PublishedCheckpoint | undefined> {
268
249
  const checkpoint = this.resolveCheckpointQuery(query);
269
250
  if (!checkpoint) {
@@ -342,6 +323,13 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
342
323
  if ('from' in query) {
343
324
  return this.checkpointList.slice(query.from - 1, query.from - 1 + query.limit);
344
325
  }
326
+ if ('fromSlot' in query) {
327
+ const matching = this.checkpointList.filter(c =>
328
+ query.reverse ? c.header.slotNumber <= query.fromSlot : c.header.slotNumber >= query.fromSlot,
329
+ );
330
+ const nearestFirst = query.reverse ? matching.reverse() : matching;
331
+ return nearestFirst.slice(0, query.limit);
332
+ }
345
333
  return this.getCheckpointsInEpoch(query.epoch);
346
334
  }
347
335
 
@@ -368,49 +356,27 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
368
356
  l2BlockNumber: block.number,
369
357
  l2BlockHash: await block.hash(),
370
358
  txIndexInBlock: block.body.txEffects.findIndex(t => t.txHash.equals(txHash)),
359
+ slotNumber: block.header.globalVariables.slotNumber,
371
360
  };
372
361
  }
373
362
 
374
- /**
375
- * Gets a receipt of a settled tx.
376
- * @param txHash - The hash of a tx we try to get the receipt for.
377
- * @returns The requested tx receipt (or undefined if not found).
378
- */
379
- public async getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
380
- for (const block of this.l2Blocks) {
381
- for (const txEffect of block.body.txEffects) {
382
- if (txEffect.txHash.equals(txHash)) {
383
- // In mock, assume all txs are checkpointed with successful execution
384
- return new TxReceipt(
385
- txHash,
386
- TxStatus.CHECKPOINTED,
387
- TxExecutionResult.SUCCESS,
388
- undefined,
389
- txEffect.transactionFee.toBigInt(),
390
- await block.hash(),
391
- block.number,
392
- getEpochAtSlot(block.slot, EmptyL1RollupConstants),
393
- );
394
- }
395
- }
396
- }
397
- return undefined;
363
+ public getL2ToL1MembershipWitness(): Promise<undefined> {
364
+ // Mock does not back the L2-to-L1 message witness flow.
365
+ return Promise.resolve(undefined);
398
366
  }
399
367
 
400
368
  async getL2Tips(): Promise<L2Tips> {
401
- const [latest, proven, finalized, checkpointed, proposedCheckpoint] = [
369
+ const [latest, proven, finalized, checkpointed] = [
402
370
  await this.getBlockNumber(),
403
371
  this.provenBlockNumber,
404
372
  this.finalizedBlockNumber,
405
373
  this.checkpointedBlockNumber,
406
- await this.getProposedCheckpointL2BlockNumber(),
407
374
  ] as const;
408
375
 
409
376
  const latestBlock = this.l2Blocks[latest - 1];
410
377
  const provenBlock = this.l2Blocks[proven - 1];
411
378
  const finalizedBlock = this.l2Blocks[finalized - 1];
412
379
  const checkpointedBlock = this.l2Blocks[checkpointed - 1];
413
- const proposedCheckpointBlock = this.l2Blocks[proposedCheckpoint - 1];
414
380
 
415
381
  // For genesis tips (block number 0) report the dynamic initial header hash so consumers
416
382
  // running L2BlockStream against this mock agree at block 0 with their local tip store.
@@ -438,10 +404,6 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
438
404
  number: BlockNumber(checkpointed),
439
405
  hash: await tipHash(checkpointedBlock, checkpointed),
440
406
  };
441
- const proposedCheckpointBlockId = {
442
- number: BlockNumber(proposedCheckpoint),
443
- hash: await tipHash(proposedCheckpointBlock, proposedCheckpoint),
444
- };
445
407
 
446
408
  const makeTipId = (blockId: typeof latestBlockId) => {
447
409
  const checkpointNumber = this.findCheckpointNumberForBlock(blockId.number) ?? CheckpointNumber(0);
@@ -460,7 +422,6 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
460
422
  checkpointed: makeTipId(checkpointedBlockId),
461
423
  proven: makeTipId(provenBlockId),
462
424
  finalized: makeTipId(finalizedBlockId),
463
- proposedCheckpoint: makeTipId(proposedCheckpointBlockId),
464
425
  };
465
426
  }
466
427
 
@@ -269,7 +269,10 @@ export function makePublicLogTag(blockNumber: number, txIndex: number, logIndex:
269
269
  }
270
270
 
271
271
  /** Creates a PublicLog with fields derived from the tag. */
272
- export function makePublicLog(tag: Tag, contractAddress: AztecAddress = AztecAddress.fromNumber(543254)): PublicLog {
272
+ export function makePublicLog(
273
+ tag: Tag,
274
+ contractAddress: AztecAddress = AztecAddress.fromNumberUnsafe(543254),
275
+ ): PublicLog {
273
276
  return PublicLog.from({
274
277
  contractAddress,
275
278
  fields: new Array(10).fill(null).map((_, i) => (!i ? tag.value : new Fr(tag.value.toBigInt() + BigInt(i)))),
@@ -281,7 +284,7 @@ export function makePublicLogs(
281
284
  blockNumber: number,
282
285
  txIndex: number,
283
286
  numLogsPerTx: number,
284
- contractAddress: AztecAddress = AztecAddress.fromNumber(543254),
287
+ contractAddress: AztecAddress = AztecAddress.fromNumberUnsafe(543254),
285
288
  ): PublicLog[] {
286
289
  return times(numLogsPerTx, logIndex => {
287
290
  const tag = makePublicLogTag(blockNumber, txIndex, logIndex);
@@ -1,6 +1,5 @@
1
1
  import type { BlobClientInterface } from '@aztec/blob-client/client';
2
- import { EpochCache } from '@aztec/epoch-cache';
3
- import type { RollupContract } from '@aztec/ethereum/contracts';
2
+ import type { OutboxContract, RollupContract } from '@aztec/ethereum/contracts';
4
3
  import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
5
4
  import { SlotNumber } from '@aztec/foundation/branded-types';
6
5
  import { Buffer32 } from '@aztec/foundation/buffer';
@@ -8,7 +7,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
8
7
  import { EthAddress } from '@aztec/foundation/eth-address';
9
8
  import { DateProvider } from '@aztec/foundation/timer';
10
9
  import type { FunctionsOf } from '@aztec/foundation/types';
11
- import type { ArchiverEmitter, BlockHash } from '@aztec/stdlib/block';
10
+ import type { ArchiverEmitter, BlockHash, L2Block } from '@aztec/stdlib/block';
12
11
  import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
13
12
  import type { BlockHeader } from '@aztec/stdlib/tx';
14
13
  import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
@@ -22,6 +21,10 @@ import type { ArchiverL1Synchronizer } from '../modules/l1_synchronizer.js';
22
21
  import type { ArchiverDataStores } from '../store/data_stores.js';
23
22
  import { L2TipsCache } from '../store/l2_tips_cache.js';
24
23
 
24
+ type NoopL1ArchiverConfigOverrides = Partial<{
25
+ skipOrphanProposedBlockPruning: boolean;
26
+ }>;
27
+
25
28
  /** Noop L1 synchronizer for testing without L1 connectivity. */
26
29
  class NoopL1Synchronizer implements FunctionsOf<ArchiverL1Synchronizer> {
27
30
  public readonly tracer: Tracer;
@@ -40,8 +43,8 @@ class NoopL1Synchronizer implements FunctionsOf<ArchiverL1Synchronizer> {
40
43
  testEthereumNodeSynced(): Promise<void> {
41
44
  return Promise.resolve();
42
45
  }
43
- syncFromL1(_initialSyncComplete: boolean): Promise<void> {
44
- return Promise.resolve();
46
+ syncFromL1(_initialSyncComplete: boolean): Promise<L2Block[]> {
47
+ return Promise.resolve([]);
45
48
  }
46
49
  }
47
50
 
@@ -58,11 +61,14 @@ export class NoopL1Archiver extends Archiver {
58
61
  initialHeader: BlockHeader,
59
62
  initialBlockHash: BlockHash,
60
63
  l2TipsCache: L2TipsCache,
64
+ dateProvider: DateProvider = new DateProvider(),
65
+ configOverrides: NoopL1ArchiverConfigOverrides = {},
61
66
  ) {
62
67
  // Create mocks for L1 clients
63
68
  const publicClient = mock<ViemPublicClient>();
64
69
  const debugClient = mock<ViemPublicDebugClient>();
65
70
  const rollup = mock<RollupContract>();
71
+ const outbox = mock<OutboxContract>();
66
72
  const blobClient = mock<BlobClientInterface>();
67
73
 
68
74
  // Mock methods called during start()
@@ -71,13 +77,12 @@ export class NoopL1Archiver extends Archiver {
71
77
 
72
78
  const events = new EventEmitter() as ArchiverEmitter;
73
79
  const synchronizer = new NoopL1Synchronizer(instrumentation.tracer);
74
- const epochCache = mock<EpochCache>();
75
- epochCache.pipeliningOffset.mockReturnValue(0);
76
80
 
77
81
  super(
78
82
  publicClient,
79
83
  debugClient,
80
84
  rollup,
85
+ outbox,
81
86
  {
82
87
  rollupAddress: EthAddress.ZERO,
83
88
  registryAddress: EthAddress.ZERO,
@@ -93,7 +98,11 @@ export class NoopL1Archiver extends Archiver {
93
98
  maxAllowedEthClientDriftSeconds: 300,
94
99
  ethereumAllowNoDebugHosts: true, // Skip trace validation
95
100
  skipHistoricalLogsCheck: true, // Skip historical logs validation
96
- orphanProposedBlockPruneGraceSeconds: 2,
101
+ checkpointProposalSyncGrace: 4,
102
+ orphanPruneNoProposalTolerance: 1,
103
+ skipOrphanProposedBlockPruning: true,
104
+ blockDuration: 2,
105
+ ...configOverrides,
97
106
  },
98
107
  blobClient,
99
108
  instrumentation,
@@ -103,8 +112,7 @@ export class NoopL1Archiver extends Archiver {
103
112
  initialHeader,
104
113
  initialBlockHash,
105
114
  l2TipsCache,
106
- epochCache,
107
- new DateProvider(),
115
+ dateProvider,
108
116
  );
109
117
  }
110
118
 
@@ -127,6 +135,8 @@ export async function createNoopL1Archiver(
127
135
  l1Constants: L1RollupConstants & { genesisArchiveRoot: Fr },
128
136
  telemetry: TelemetryClient = getTelemetryClient(),
129
137
  initialHeader: BlockHeader,
138
+ dateProvider?: DateProvider,
139
+ configOverrides?: NoopL1ArchiverConfigOverrides,
130
140
  ): Promise<NoopL1Archiver> {
131
141
  const instrumentation = await ArchiverInstrumentation.new(telemetry, () => dataStores.db.estimateSize());
132
142
  // Mirror the production factory: precompute the dynamic genesis block hash from the injected
@@ -135,5 +145,14 @@ export async function createNoopL1Archiver(
135
145
  // with default empty genesis.
136
146
  const initialBlockHash = await initialHeader.hash();
137
147
  const l2TipsCache = new L2TipsCache(dataStores.blocks, initialBlockHash);
138
- return new NoopL1Archiver(dataStores, l1Constants, instrumentation, initialHeader, initialBlockHash, l2TipsCache);
148
+ return new NoopL1Archiver(
149
+ dataStores,
150
+ l1Constants,
151
+ instrumentation,
152
+ initialHeader,
153
+ initialBlockHash,
154
+ l2TipsCache,
155
+ dateProvider,
156
+ configOverrides,
157
+ );
139
158
  }