@aztec/archiver 5.0.0-private.20260319 → 5.0.0-rc.2

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 -13
  2. package/dest/archiver.d.ts +71 -15
  3. package/dest/archiver.d.ts.map +1 -1
  4. package/dest/archiver.js +268 -74
  5. package/dest/config.d.ts +7 -3
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +39 -16
  8. package/dest/errors.d.ts +44 -10
  9. package/dest/errors.d.ts.map +1 -1
  10. package/dest/errors.js +66 -12
  11. package/dest/factory.d.ts +12 -7
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +40 -25
  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 +2 -1
  18. package/dest/l1/calldata_retriever.d.ts.map +1 -1
  19. package/dest/l1/calldata_retriever.js +15 -5
  20. package/dest/l1/data_retrieval.d.ts +19 -10
  21. package/dest/l1/data_retrieval.d.ts.map +1 -1
  22. package/dest/l1/data_retrieval.js +25 -32
  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 +72 -48
  32. package/dest/modules/data_source_base.d.ts.map +1 -1
  33. package/dest/modules/data_source_base.js +266 -143
  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 +172 -117
  37. package/dest/modules/instrumentation.d.ts +7 -2
  38. package/dest/modules/instrumentation.d.ts.map +1 -1
  39. package/dest/modules/instrumentation.js +25 -7
  40. package/dest/modules/l1_synchronizer.d.ts +11 -6
  41. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  42. package/dest/modules/l1_synchronizer.js +437 -217
  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 +24 -5
  47. package/dest/modules/validation.d.ts.map +1 -1
  48. package/dest/modules/validation.js +40 -15
  49. package/dest/store/block_store.d.ts +164 -66
  50. package/dest/store/block_store.d.ts.map +1 -1
  51. package/dest/store/block_store.js +638 -233
  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 +36 -68
  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 +48 -2
  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 -40
  68. package/dest/store/log_store.d.ts.map +1 -1
  69. package/dest/store/log_store.js +257 -480
  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 +9 -3
  74. package/dest/store/message_store.d.ts.map +1 -1
  75. package/dest/store/message_store.js +39 -10
  76. package/dest/test/fake_l1_state.d.ts +15 -3
  77. package/dest/test/fake_l1_state.d.ts.map +1 -1
  78. package/dest/test/fake_l1_state.js +80 -18
  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 +223 -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 +25 -9
  88. package/package.json +14 -14
  89. package/src/archiver.ts +353 -80
  90. package/src/config.ts +43 -20
  91. package/src/errors.ts +103 -18
  92. package/src/factory.ts +56 -24
  93. package/src/index.ts +18 -2
  94. package/src/l1/calldata_retriever.ts +16 -5
  95. package/src/l1/data_retrieval.ts +38 -46
  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 +340 -189
  99. package/src/modules/data_store_updater.ts +211 -148
  100. package/src/modules/instrumentation.ts +28 -8
  101. package/src/modules/l1_synchronizer.ts +583 -255
  102. package/src/modules/outbox_trees_resolver.ts +199 -0
  103. package/src/modules/validation.ts +81 -21
  104. package/src/store/block_store.ts +792 -285
  105. package/src/store/contract_class_store.ts +43 -103
  106. package/src/store/contract_instance_store.ts +62 -5
  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 +296 -652
  111. package/src/store/log_store_codec.ts +143 -0
  112. package/src/store/message_store.ts +43 -12
  113. package/src/structs/inbox_message.ts +1 -1
  114. package/src/test/fake_l1_state.ts +99 -27
  115. package/src/test/mock_l2_block_source.ts +279 -233
  116. package/src/test/mock_structs.ts +5 -2
  117. package/src/test/noop_l1_archiver.ts +52 -9
  118. package/dest/store/kv_archiver_store.d.ts +0 -367
  119. package/dest/store/kv_archiver_store.d.ts.map +0 -1
  120. package/dest/store/kv_archiver_store.js +0 -481
  121. package/src/store/kv_archiver_store.ts +0 -697
package/src/config.ts CHANGED
@@ -1,20 +1,16 @@
1
1
  import { type BlobClientConfig, blobClientConfigMapping } from '@aztec/blob-client/client/config';
2
2
  import { type L1ContractsConfig, l1ContractsConfigMappings } from '@aztec/ethereum/config';
3
- import { l1ContractAddressesMapping } from '@aztec/ethereum/l1-contract-addresses';
4
3
  import { type L1ReaderConfig, l1ReaderConfigMappings } from '@aztec/ethereum/l1-reader';
5
4
  import {
6
5
  type ConfigMappingsType,
7
6
  booleanConfigHelper,
8
7
  getConfigFromMappings,
9
8
  numberConfigHelper,
9
+ optionalNumberConfigHelper,
10
10
  } from '@aztec/foundation/config';
11
- import {
12
- type ChainConfig,
13
- type PipelineConfig,
14
- chainConfigMappings,
15
- pipelineConfigMappings,
16
- } from '@aztec/stdlib/config';
11
+ import { type ChainConfig, type SequencerConfig, chainConfigMappings } from '@aztec/stdlib/config';
17
12
  import type { ArchiverSpecificConfig } from '@aztec/stdlib/interfaces/server';
13
+ import { DEFAULT_ORPHAN_PRUNE_NO_PROPOSAL_TOLERANCE } from '@aztec/stdlib/timetable';
18
14
 
19
15
  /**
20
16
  * The archiver configuration.
@@ -26,13 +22,12 @@ import type { ArchiverSpecificConfig } from '@aztec/stdlib/interfaces/server';
26
22
  export type ArchiverConfig = ArchiverSpecificConfig &
27
23
  L1ReaderConfig &
28
24
  L1ContractsConfig &
29
- PipelineConfig & // required to pass through to epoch cache
30
25
  BlobClientConfig &
31
- ChainConfig;
26
+ ChainConfig &
27
+ Pick<SequencerConfig, 'blockDurationMs' | 'checkpointProposalSyncGraceSeconds'>;
32
28
 
33
29
  export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
34
30
  ...blobClientConfigMapping,
35
- ...pipelineConfigMappings,
36
31
  archiverPollingIntervalMS: {
37
32
  env: 'ARCHIVER_POLLING_INTERVAL_MS',
38
33
  description: 'The polling interval in ms for retrieving new L2 blocks and encrypted logs.',
@@ -43,20 +38,31 @@ export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
43
38
  description: 'The number of L2 blocks the archiver will attempt to download at a time.',
44
39
  ...numberConfigHelper(100),
45
40
  },
46
- maxLogs: {
47
- env: 'ARCHIVER_MAX_LOGS',
48
- description: 'The max number of logs that can be obtained in 1 "getPublicLogs" call.',
49
- ...numberConfigHelper(1_000),
50
- },
51
41
  archiverStoreMapSizeKb: {
52
42
  env: 'ARCHIVER_STORE_MAP_SIZE_KB',
53
- parseEnv: (val: string | undefined) => (val ? +val : undefined),
43
+ ...optionalNumberConfigHelper(),
54
44
  description: 'The maximum possible size of the archiver DB in KB. Overwrites the general dataStoreMapSizeKb.',
55
45
  },
46
+ blockDurationMs: {
47
+ env: 'SEQ_BLOCK_DURATION_MS',
48
+ description:
49
+ 'Duration per block in milliseconds when building multiple blocks per slot. Used to derive orphan proposed block pruning timing.',
50
+ ...optionalNumberConfigHelper(),
51
+ },
52
+ checkpointProposalSyncGraceSeconds: {
53
+ env: 'CHECKPOINT_PROPOSAL_SYNC_GRACE_SECONDS',
54
+ description:
55
+ 'Consensus grace in seconds for a received checkpoint proposal to materialize into local proposed state.',
56
+ ...optionalNumberConfigHelper(),
57
+ },
56
58
  skipValidateCheckpointAttestations: {
57
59
  description: 'Skip validating checkpoint attestations (for testing purposes only)',
58
60
  ...booleanConfigHelper(false),
59
61
  },
62
+ skipPromoteProposedCheckpointDuringL1Sync: {
63
+ description: 'Skip promoting proposed checkpoints during L1 sync (for testing purposes only)',
64
+ ...booleanConfigHelper(false),
65
+ },
60
66
  maxAllowedEthClientDriftSeconds: {
61
67
  env: 'MAX_ALLOWED_ETH_CLIENT_DRIFT_SECONDS',
62
68
  description: 'Maximum allowed drift in seconds between the Ethereum client and current time.',
@@ -67,6 +73,23 @@ export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
67
73
  description: 'Whether to allow starting the archiver without debug/trace method support on Ethereum hosts',
68
74
  ...booleanConfigHelper(true),
69
75
  },
76
+ archiverSkipHistoricalLogsCheck: {
77
+ env: 'ARCHIVER_SKIP_HISTORICAL_LOGS_CHECK',
78
+ description:
79
+ 'Skip the startup check that probes the L1 RPC for historical Rollup contract logs. ' +
80
+ 'Set to true to bypass the check when the connected RPC node is known to prune old logs.',
81
+ ...booleanConfigHelper(false),
82
+ },
83
+ orphanPruneNoProposalTolerance: {
84
+ env: 'ARCHIVER_ORPHAN_PRUNE_NO_PROPOSAL_TOLERANCE',
85
+ description: 'Local tolerance in seconds before pruning an orphan block when no checkpoint proposal was received.',
86
+ ...numberConfigHelper(DEFAULT_ORPHAN_PRUNE_NO_PROPOSAL_TOLERANCE),
87
+ },
88
+ skipOrphanProposedBlockPruning: {
89
+ env: 'ARCHIVER_SKIP_ORPHAN_PROPOSED_BLOCK_PRUNING',
90
+ description: 'Skip pruning orphan proposed blocks that have no matching proposed checkpoint.',
91
+ ...booleanConfigHelper(false),
92
+ },
70
93
  ...chainConfigMappings,
71
94
  ...l1ReaderConfigMappings,
72
95
  viemPollingIntervalMS: {
@@ -75,10 +98,6 @@ export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
75
98
  ...numberConfigHelper(1000),
76
99
  },
77
100
  ...l1ContractsConfigMappings,
78
- l1Contracts: {
79
- description: 'The deployed L1 contract addresses',
80
- nested: l1ContractAddressesMapping,
81
- },
82
101
  };
83
102
 
84
103
  /**
@@ -96,7 +115,11 @@ export function mapArchiverConfig(config: Partial<ArchiverConfig>) {
96
115
  pollingIntervalMs: config.archiverPollingIntervalMS,
97
116
  batchSize: config.archiverBatchSize,
98
117
  skipValidateCheckpointAttestations: config.skipValidateCheckpointAttestations,
118
+ skipPromoteProposedCheckpointDuringL1Sync: config.skipPromoteProposedCheckpointDuringL1Sync,
99
119
  maxAllowedEthClientDriftSeconds: config.maxAllowedEthClientDriftSeconds,
100
120
  ethereumAllowNoDebugHosts: config.ethereumAllowNoDebugHosts,
121
+ skipHistoricalLogsCheck: config.archiverSkipHistoricalLogsCheck,
122
+ orphanPruneNoProposalTolerance: config.orphanPruneNoProposalTolerance,
123
+ skipOrphanProposedBlockPruning: config.skipOrphanProposedBlockPruning,
101
124
  };
102
125
  }
package/src/errors.ts CHANGED
@@ -1,14 +1,17 @@
1
+ import type { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
1
2
  import type { Fr } from '@aztec/foundation/schemas';
2
3
 
3
4
  export class NoBlobBodiesFoundError extends Error {
4
5
  constructor(l2BlockNum: number) {
5
6
  super(`No blob bodies found for block ${l2BlockNum}`);
7
+ this.name = 'NoBlobBodiesFoundError';
6
8
  }
7
9
  }
8
10
 
9
11
  export class BlockNumberNotSequentialError extends Error {
10
12
  constructor(newBlockNumber: number, previous: number | undefined) {
11
13
  super(`Cannot insert new block ${newBlockNumber} given previous block number is ${previous ?? 'undefined'}`);
14
+ this.name = 'BlockNumberNotSequentialError';
12
15
  }
13
16
  }
14
17
 
@@ -22,14 +25,35 @@ export class InitialCheckpointNumberNotSequentialError extends Error {
22
25
  previousCheckpointNumber ?? 'undefined'
23
26
  }`,
24
27
  );
28
+ this.name = 'InitialCheckpointNumberNotSequentialError';
25
29
  }
26
30
  }
27
31
 
28
32
  export class CheckpointNumberNotSequentialError extends Error {
29
- constructor(newCheckpointNumber: number, previous: number | undefined) {
33
+ constructor(
34
+ public readonly newCheckpointNumber: CheckpointNumber,
35
+ public readonly previousCheckpointNumber: CheckpointNumber | undefined,
36
+ source?: 'proposed' | 'confirmed',
37
+ ) {
38
+ const qualifier = source ? `${source} ` : '';
30
39
  super(
31
- `Cannot insert new checkpoint ${newCheckpointNumber} given previous checkpoint number in batch is ${previous ?? 'undefined'}`,
40
+ `Cannot insert new checkpoint ${newCheckpointNumber} given previous ${qualifier}checkpoint number is ${previousCheckpointNumber ?? 'undefined'}`,
32
41
  );
42
+ this.name = 'CheckpointNumberNotSequentialError';
43
+ }
44
+ }
45
+
46
+ /** Thrown when a proposed block carries a checkpoint number that does not follow the latest one. */
47
+ export class BlockCheckpointNumberNotSequentialError extends Error {
48
+ constructor(
49
+ blockNumber: BlockNumber,
50
+ blockCheckpointNumber: CheckpointNumber,
51
+ previous: CheckpointNumber | undefined,
52
+ ) {
53
+ super(
54
+ `Cannot insert new block ${blockNumber} for checkpoint ${blockCheckpointNumber} given previous checkpoint number is ${previous ?? 'undefined'}`,
55
+ );
56
+ this.name = 'BlockCheckpointNumberNotSequentialError';
33
57
  }
34
58
  }
35
59
 
@@ -38,6 +62,7 @@ export class BlockIndexNotSequentialError extends Error {
38
62
  super(
39
63
  `Cannot insert new block at checkpoint index ${newBlockIndex} given previous block index is ${previousBlockIndex ?? 'undefined'}`,
40
64
  );
65
+ this.name = 'BlockIndexNotSequentialError';
41
66
  }
42
67
  }
43
68
 
@@ -51,18 +76,21 @@ export class BlockArchiveNotConsistentError extends Error {
51
76
  super(
52
77
  `Cannot insert new block number ${newBlockNumber} with archive ${newBlockArchive.toString()} previous block number is ${previousBlockNumber ?? 'undefined'}, previous archive is ${previousBlockArchive?.toString() ?? 'undefined'}`,
53
78
  );
79
+ this.name = 'BlockArchiveNotConsistentError';
54
80
  }
55
81
  }
56
82
 
57
83
  export class CheckpointNotFoundError extends Error {
58
84
  constructor(checkpointNumber: number) {
59
85
  super(`Failed to find expected checkpoint number ${checkpointNumber}`);
86
+ this.name = 'CheckpointNotFoundError';
60
87
  }
61
88
  }
62
89
 
63
90
  export class BlockNotFoundError extends Error {
64
91
  constructor(blockNumber: number) {
65
92
  super(`Failed to find expected block number ${blockNumber}`);
93
+ this.name = 'BlockNotFoundError';
66
94
  }
67
95
  }
68
96
 
@@ -74,22 +102,6 @@ export class BlockAlreadyCheckpointedError extends Error {
74
102
  }
75
103
  }
76
104
 
77
- /** Thrown when logs are added for a tag whose last stored log has a higher block number than the new log. */
78
- export class OutOfOrderLogInsertionError extends Error {
79
- constructor(
80
- public readonly logType: 'private' | 'public',
81
- public readonly tag: string,
82
- public readonly lastBlockNumber: number,
83
- public readonly newBlockNumber: number,
84
- ) {
85
- super(
86
- `Out-of-order ${logType} log insertion for tag ${tag}: ` +
87
- `last existing log is from block ${lastBlockNumber} but new log is from block ${newBlockNumber}`,
88
- );
89
- this.name = 'OutOfOrderLogInsertionError';
90
- }
91
- }
92
-
93
105
  /** Thrown when L1 to L2 messages are requested for a checkpoint whose message tree hasn't been sealed yet. */
94
106
  export class L1ToL2MessagesNotReadyError extends Error {
95
107
  constructor(
@@ -104,6 +116,79 @@ export class L1ToL2MessagesNotReadyError extends Error {
104
116
  }
105
117
  }
106
118
 
119
+ /** Thrown when a proposed checkpoint number is stale (already processed). */
120
+ export class ProposedCheckpointStaleError extends Error {
121
+ constructor(
122
+ public readonly proposedCheckpointNumber: number,
123
+ public readonly currentProposedNumber: number,
124
+ ) {
125
+ super(`Stale proposed checkpoint ${proposedCheckpointNumber}: current proposed is ${currentProposedNumber}`);
126
+ this.name = 'ProposedCheckpointStaleError';
127
+ }
128
+ }
129
+
130
+ /** Thrown when a proposed checkpoint number is not the expected latestTip + 1. */
131
+ export class ProposedCheckpointNotSequentialError extends Error {
132
+ constructor(
133
+ public readonly proposedCheckpointNumber: number,
134
+ public readonly latestTipNumber: number,
135
+ ) {
136
+ super(
137
+ `Proposed checkpoint ${proposedCheckpointNumber} is not sequential: expected ${latestTipNumber + 1} (latest tip + 1, where tip is highest of confirmed or pending)`,
138
+ );
139
+ this.name = 'ProposedCheckpointNotSequentialError';
140
+ }
141
+ }
142
+
143
+ /** Thrown when a proposed checkpoint or block L2 slot has already expired on L1. */
144
+ export class BlockOrCheckpointSlotExpiredError extends Error {
145
+ constructor(
146
+ public readonly slot: number,
147
+ public readonly nextSlotStart: bigint,
148
+ public readonly l1TimestampSynced: bigint | undefined,
149
+ ) {
150
+ super(
151
+ `Checkpoint or block for slot ${slot} is expired: L1 synced to ${l1TimestampSynced} which is past the next slot start ${nextSlotStart}. ` +
152
+ `If the checkpoint still lands via a late L1 tx, the archiver will pick it up via normal L1-sync (not the pending-queue shortcut).`,
153
+ );
154
+ this.name = 'BlockOrCheckpointSlotExpiredError';
155
+ }
156
+ }
157
+
158
+ /** Thrown when attempting to promote a proposed checkpoint but no proposed checkpoint exists in the store. */
159
+ export class NoProposedCheckpointToPromoteError extends Error {
160
+ constructor() {
161
+ super('Cannot promote proposed checkpoint: no proposed checkpoint exists');
162
+ this.name = 'NoProposedCheckpointToPromoteError';
163
+ }
164
+ }
165
+
166
+ /** Thrown when the archive root of the proposed checkpoint does not match the expected one. */
167
+ export class ProposedCheckpointArchiveRootMismatchError extends Error {
168
+ constructor(
169
+ public readonly expectedArchiveRoot: Fr,
170
+ public readonly actualArchiveRoot: Fr,
171
+ ) {
172
+ super(
173
+ `Cannot promote proposed checkpoint: archive root mismatch (expected ${expectedArchiveRoot}, got ${actualArchiveRoot})`,
174
+ );
175
+ this.name = 'ProposedCheckpointArchiveRootMismatchError';
176
+ }
177
+ }
178
+
179
+ /** Thrown when the proposed checkpoint does not directly follow the latest confirmed checkpoint. */
180
+ export class ProposedCheckpointPromotionNotSequentialError extends Error {
181
+ constructor(
182
+ public readonly proposedCheckpointNumber: number,
183
+ public readonly latestCheckpointNumber: number,
184
+ ) {
185
+ super(
186
+ `Cannot promote proposed checkpoint: not sequential (latest ${latestCheckpointNumber}, proposed ${proposedCheckpointNumber})`,
187
+ );
188
+ this.name = 'ProposedCheckpointPromotionNotSequentialError';
189
+ }
190
+ }
191
+
107
192
  /** Thrown when a proposed block conflicts with an already checkpointed block (different content). */
108
193
  export class CannotOverwriteCheckpointedBlockError extends Error {
109
194
  constructor(
package/src/factory.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { EpochCache } from '@aztec/epoch-cache';
2
2
  import { createEthereumChain } from '@aztec/ethereum/chain';
3
3
  import { makeL1HttpTransport } from '@aztec/ethereum/client';
4
- import { InboxContract, RollupContract } from '@aztec/ethereum/contracts';
4
+ import { InboxContract, OutboxContract, RollupContract } from '@aztec/ethereum/contracts';
5
+ import { pickL1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
5
6
  import type { ViemPublicDebugClient } from '@aztec/ethereum/types';
6
7
  import { BlockNumber } from '@aztec/foundation/branded-types';
7
8
  import { Buffer32 } from '@aztec/foundation/buffer';
@@ -12,9 +13,15 @@ import { createStore } from '@aztec/kv-store/lmdb-v2';
12
13
  import { protocolContractNames } from '@aztec/protocol-contracts';
13
14
  import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
14
15
  import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi';
15
- import type { ArchiverEmitter } from '@aztec/stdlib/block';
16
- import { type ContractClassPublic, computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
16
+ import type { ArchiverEmitter, BlockHash } from '@aztec/stdlib/block';
17
+ import { DEFAULT_BLOCK_DURATION_MS } from '@aztec/stdlib/config';
18
+ import { type ContractClassPublicWithCommitment, computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
17
19
  import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
20
+ import {
21
+ DEFAULT_ORPHAN_PRUNE_NO_PROPOSAL_TOLERANCE,
22
+ getDefaultCheckpointProposalSyncGrace,
23
+ } from '@aztec/stdlib/timetable';
24
+ import type { BlockHeader } from '@aztec/stdlib/tx';
18
25
  import { getTelemetryClient } from '@aztec/telemetry-client';
19
26
 
20
27
  import { EventEmitter } from 'events';
@@ -24,21 +31,22 @@ import { Archiver, type ArchiverDeps } from './archiver.js';
24
31
  import { type ArchiverConfig, mapArchiverConfig } from './config.js';
25
32
  import { ArchiverInstrumentation } from './modules/instrumentation.js';
26
33
  import { ArchiverL1Synchronizer } from './modules/l1_synchronizer.js';
27
- import { ARCHIVER_DB_VERSION, KVArchiverDataStore } from './store/kv_archiver_store.js';
34
+ import { ARCHIVER_DB_VERSION, type ArchiverDataStores, createArchiverDataStores } from './store/data_stores.js';
28
35
  import { L2TipsCache } from './store/l2_tips_cache.js';
29
36
 
30
37
  export const ARCHIVER_STORE_NAME = 'archiver';
31
38
 
32
39
  /** Creates an archiver store. */
33
40
  export async function createArchiverStore(
34
- userConfig: Pick<ArchiverConfig, 'archiverStoreMapSizeKb' | 'maxLogs'> & DataStoreConfig,
35
- ) {
41
+ userConfig: Pick<ArchiverConfig, 'archiverStoreMapSizeKb'> & DataStoreConfig,
42
+ genesisBlockHash: BlockHash,
43
+ ): Promise<ArchiverDataStores> {
36
44
  const config = {
37
45
  ...userConfig,
38
46
  dataStoreMapSizeKb: userConfig.archiverStoreMapSizeKb ?? userConfig.dataStoreMapSizeKb,
39
47
  };
40
48
  const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config);
41
- return new KVArchiverDataStore(store, config.maxLogs);
49
+ return createArchiverDataStores(store, genesisBlockHash);
42
50
  }
43
51
 
44
52
  /**
@@ -46,14 +54,19 @@ export async function createArchiverStore(
46
54
  * @param config - The archiver configuration.
47
55
  * @param deps - The archiver dependencies (blobClient, epochCache, dateProvider, telemetry).
48
56
  * @param opts - The options.
57
+ * @param initialHeader - The genesis block header from world-state, used to answer block-0 queries.
58
+ * @param initialBlockHash - Precomputed hash of `initialHeader`. Hoisted to the caller so the archiver
59
+ * can expose `getGenesisBlockHash()` synchronously.
49
60
  * @returns The local archiver.
50
61
  */
51
62
  export async function createArchiver(
52
63
  config: ArchiverConfig & DataStoreConfig,
53
64
  deps: ArchiverDeps,
54
65
  opts: { blockUntilSync: boolean } = { blockUntilSync: true },
66
+ initialHeader: BlockHeader,
67
+ initialBlockHash: BlockHash,
55
68
  ): Promise<Archiver> {
56
- const archiverStore = await createArchiverStore(config);
69
+ const archiverStore = await createArchiverStore(config, initialBlockHash);
57
70
  await registerProtocolContracts(archiverStore);
58
71
 
59
72
  // Create Ethereum clients
@@ -74,8 +87,9 @@ export async function createArchiver(
74
87
  }) as ViemPublicDebugClient;
75
88
 
76
89
  // Create L1 contract instances
77
- const rollup = new RollupContract(publicClient, config.l1Contracts.rollupAddress);
78
- const inbox = new InboxContract(publicClient, config.l1Contracts.inboxAddress);
90
+ const rollup = new RollupContract(publicClient, config.rollupAddress);
91
+ const inbox = new InboxContract(publicClient, config.inboxAddress);
92
+ const outbox = new OutboxContract(publicClient, config.outboxAddress);
79
93
 
80
94
  // Fetch L1 constants from rollup contract
81
95
  const [
@@ -121,19 +135,28 @@ export async function createArchiver(
121
135
  batchSize: 100,
122
136
  maxAllowedEthClientDriftSeconds: 300,
123
137
  ethereumAllowNoDebugHosts: false,
138
+ skipHistoricalLogsCheck: false,
139
+ checkpointProposalSyncGrace:
140
+ config.checkpointProposalSyncGraceSeconds ??
141
+ getDefaultCheckpointProposalSyncGrace((config.blockDurationMs ?? DEFAULT_BLOCK_DURATION_MS) / 1000),
142
+ orphanPruneNoProposalTolerance: DEFAULT_ORPHAN_PRUNE_NO_PROPOSAL_TOLERANCE,
143
+ skipOrphanProposedBlockPruning: false,
144
+ blockDuration: (config.blockDurationMs ?? DEFAULT_BLOCK_DURATION_MS) / 1000,
124
145
  },
125
146
  mapArchiverConfig(config),
126
147
  );
127
148
 
128
- const epochCache = deps.epochCache ?? (await EpochCache.create(config.l1Contracts.rollupAddress, config, deps));
149
+ const epochCache = deps.epochCache ?? (await EpochCache.create(config.rollupAddress, config, deps));
129
150
  const telemetry = deps.telemetry ?? getTelemetryClient();
130
- const instrumentation = await ArchiverInstrumentation.new(telemetry, () => archiverStore.estimateSize());
151
+ const instrumentation = await ArchiverInstrumentation.new(telemetry, () => archiverStore.db.estimateSize());
131
152
 
132
153
  // Create the event emitter that will be shared by archiver and synchronizer
133
154
  const events = new EventEmitter() as ArchiverEmitter;
134
155
 
135
- // Create L2 tips cache shared by archiver and synchronizer
136
- const l2TipsCache = new L2TipsCache(archiverStore.blockStore);
156
+ // Create L2 tips cache shared by archiver and synchronizer. The genesis block hash is dynamic —
157
+ // it depends on the injected initial header (genesisTimestamp + prefilled state). Hoisted to the
158
+ // caller so we can pass the same value to the archiver and expose it via `getGenesisBlockHash()`.
159
+ const l2TipsCache = new L2TipsCache(archiverStore.blocks, initialBlockHash);
137
160
 
138
161
  // Create the L1 synchronizer
139
162
  const synchronizer = new ArchiverL1Synchronizer(
@@ -158,7 +181,8 @@ export async function createArchiver(
158
181
  publicClient,
159
182
  debugClient,
160
183
  rollup,
161
- { ...config.l1Contracts, slashingProposerAddress },
184
+ outbox,
185
+ { ...pickL1ContractAddresses(config), slashingProposerAddress },
162
186
  archiverStore,
163
187
  archiverConfig,
164
188
  deps.blobClient,
@@ -166,32 +190,40 @@ export async function createArchiver(
166
190
  l1Constants,
167
191
  synchronizer,
168
192
  events,
193
+ initialHeader,
194
+ initialBlockHash,
169
195
  l2TipsCache,
196
+ deps.dateProvider ?? new DateProvider(),
170
197
  );
171
198
 
172
199
  await archiver.start(opts.blockUntilSync);
173
200
  return archiver;
174
201
  }
175
202
 
176
- /** Registers protocol contracts in the archiver store. */
177
- export async function registerProtocolContracts(store: KVArchiverDataStore) {
203
+ /** Registers protocol contracts in the archiver store. Idempotent — skips contracts that already exist (e.g. on node restart). */
204
+ export async function registerProtocolContracts(stores: ArchiverDataStores) {
178
205
  const blockNumber = 0;
179
206
  for (const name of protocolContractNames) {
180
207
  const provider = new BundledProtocolContractsProvider();
181
208
  const contract = await provider.getProtocolContractArtifact(name);
182
- const contractClassPublic: ContractClassPublic = {
209
+
210
+ // Skip if already registered (happens on node restart with a persisted store).
211
+ if (await stores.contractClasses.getContractClass(contract.contractClass.id)) {
212
+ continue;
213
+ }
214
+
215
+ const publicBytecodeCommitment = await computePublicBytecodeCommitment(contract.contractClass.packedBytecode);
216
+ const contractClassPublic: ContractClassPublicWithCommitment = {
183
217
  ...contract.contractClass,
184
- privateFunctions: [],
185
- utilityFunctions: [],
218
+ publicBytecodeCommitment,
186
219
  };
187
220
 
188
221
  const publicFunctionSignatures = contract.artifact.functions
189
222
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
190
223
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
191
224
 
192
- await store.registerContractFunctionSignatures(publicFunctionSignatures);
193
- const bytecodeCommitment = await computePublicBytecodeCommitment(contractClassPublic.packedBytecode);
194
- await store.addContractClasses([contractClassPublic], [bytecodeCommitment], BlockNumber(blockNumber));
195
- await store.addContractInstances([contract.instance], BlockNumber(blockNumber));
225
+ await stores.functionNames.register(publicFunctionSignatures);
226
+ await stores.contractClasses.addContractClasses([contractClassPublic], BlockNumber(blockNumber));
227
+ await stores.contractInstances.addContractInstances([contract.instance], BlockNumber(blockNumber));
196
228
  }
197
229
  }
package/src/index.ts CHANGED
@@ -4,10 +4,26 @@ export * from './archiver.js';
4
4
  export * from './modules/data_source_base.js';
5
5
  export * from './modules/data_store_updater.js';
6
6
  export * from './config.js';
7
+ export * from './errors.js';
7
8
 
8
9
  export { type L1PublishedData } from './structs/published.js';
9
- export { KVArchiverDataStore, ARCHIVER_DB_VERSION } from './store/kv_archiver_store.js';
10
+ export {
11
+ ARCHIVER_DB_VERSION,
12
+ type ArchiverDataStores,
13
+ type ArchiverL1SynchPoint,
14
+ backupArchiverDataStores,
15
+ createArchiverDataStores,
16
+ createContractDataSource,
17
+ getArchiverSynchPoint,
18
+ } from './store/data_stores.js';
19
+ export { FunctionNamesCache } from './store/function_names_cache.js';
20
+ export { ArchiverContractDataSourceAdapter } from './modules/contract_data_source_adapter.js';
21
+ export { BlockStore } from './store/block_store.js';
22
+ export { LogStore } from './store/log_store.js';
23
+ export { MessageStore } from './store/message_store.js';
24
+ export { ContractClassStore } from './store/contract_class_store.js';
10
25
  export { ContractInstanceStore } from './store/contract_instance_store.js';
11
26
  export { L2TipsCache } from './store/l2_tips_cache.js';
12
27
 
13
- export { retrieveCheckpointsFromRollup, retrieveL2ProofVerifiedEvents } from './l1/data_retrieval.js';
28
+ export { retrieveL2ProofVerifiedEvents } from './l1/data_retrieval.js';
29
+ export { CalldataRetriever } from './l1/calldata_retriever.js';
@@ -1,12 +1,13 @@
1
1
  import { MULTI_CALL_3_ADDRESS, type ViemCommitteeAttestations, type ViemHeader } from '@aztec/ethereum/contracts';
2
2
  import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
3
3
  import { CheckpointNumber } from '@aztec/foundation/branded-types';
4
+ import { LruSet } from '@aztec/foundation/collection';
4
5
  import { Fr } from '@aztec/foundation/curves/bn254';
5
6
  import { EthAddress } from '@aztec/foundation/eth-address';
6
7
  import type { Logger } from '@aztec/foundation/log';
7
8
  import { RollupAbi } from '@aztec/l1-artifacts';
8
9
  import { CommitteeAttestation } from '@aztec/stdlib/block';
9
- import { ConsensusPayload, SignatureDomainSeparator } from '@aztec/stdlib/p2p';
10
+ import { computeCheckpointPayloadDigest } from '@aztec/stdlib/checkpoint';
10
11
  import { CheckpointHeader } from '@aztec/stdlib/rollup';
11
12
 
12
13
  import {
@@ -44,7 +45,7 @@ type CheckpointData = {
44
45
  */
45
46
  export class CalldataRetriever {
46
47
  /** Tx hashes we've already logged for trace+debug failure (log once per tx per process). */
47
- private static readonly traceFailureWarnedTxHashes = new Set<string>();
48
+ private static readonly traceFailureWarnedTxHashes = new LruSet<string>(1000);
48
49
 
49
50
  /** Clears the trace-failure warned set. For testing only. */
50
51
  static resetTraceFailureWarnedForTesting(): void {
@@ -60,6 +61,13 @@ export class CalldataRetriever {
60
61
  private readonly rollupAddress: EthAddress,
61
62
  ) {}
62
63
 
64
+ private getSignatureContext() {
65
+ return {
66
+ chainId: this.publicClient.chain.id,
67
+ rollupAddress: this.rollupAddress,
68
+ };
69
+ }
70
+
63
71
  /**
64
72
  * Gets checkpoint header and metadata from the calldata of an L1 transaction.
65
73
  * Tries multicall3 decoding, falls back to trace-based extraction.
@@ -465,9 +473,12 @@ export class CalldataRetriever {
465
473
 
466
474
  /** Computes the keccak256 payload digest from the checkpoint header, archive root, and fee asset price modifier. */
467
475
  private computePayloadDigest(header: CheckpointHeader, archiveRoot: Fr, feeAssetPriceModifier: bigint): Hex {
468
- const consensusPayload = new ConsensusPayload(header, archiveRoot, feeAssetPriceModifier);
469
- const payloadToSign = consensusPayload.getPayloadToSign(SignatureDomainSeparator.checkpointAttestation);
470
- return keccak256(payloadToSign);
476
+ return computeCheckpointPayloadDigest({
477
+ header,
478
+ archiveRoot,
479
+ feeAssetPriceModifier,
480
+ signatureContext: this.getSignatureContext(),
481
+ }).toString();
471
482
  }
472
483
 
473
484
  /**