@aztec/archiver 0.0.1-commit.1142ef1 → 0.0.1-commit.11bf3dd6e

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 (214) hide show
  1. package/README.md +162 -22
  2. package/dest/archiver.d.ts +140 -0
  3. package/dest/archiver.d.ts.map +1 -0
  4. package/dest/archiver.js +750 -0
  5. package/dest/config.d.ts +30 -0
  6. package/dest/config.d.ts.map +1 -0
  7. package/dest/{archiver/config.js → config.js} +12 -2
  8. package/dest/errors.d.ts +65 -0
  9. package/dest/errors.d.ts.map +1 -0
  10. package/dest/errors.js +91 -0
  11. package/dest/factory.d.ts +8 -7
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +96 -13
  14. package/dest/index.d.ts +11 -4
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +9 -3
  17. package/dest/interfaces.d.ts +9 -0
  18. package/dest/interfaces.d.ts.map +1 -0
  19. package/dest/interfaces.js +3 -0
  20. package/dest/{archiver/l1 → l1}/bin/retrieve-calldata.d.ts +1 -1
  21. package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
  22. package/dest/{archiver/l1 → l1}/bin/retrieve-calldata.js +35 -32
  23. package/dest/l1/calldata_retriever.d.ts +135 -0
  24. package/dest/l1/calldata_retriever.d.ts.map +1 -0
  25. package/dest/l1/calldata_retriever.js +403 -0
  26. package/dest/l1/data_retrieval.d.ts +88 -0
  27. package/dest/l1/data_retrieval.d.ts.map +1 -0
  28. package/dest/{archiver/l1 → l1}/data_retrieval.js +59 -77
  29. package/dest/{archiver/l1 → l1}/debug_tx.d.ts +1 -1
  30. package/dest/l1/debug_tx.d.ts.map +1 -0
  31. package/dest/{archiver/l1 → l1}/spire_proposer.d.ts +5 -5
  32. package/dest/l1/spire_proposer.d.ts.map +1 -0
  33. package/dest/{archiver/l1 → l1}/spire_proposer.js +9 -17
  34. package/dest/{archiver/l1 → l1}/trace_tx.d.ts +1 -1
  35. package/dest/l1/trace_tx.d.ts.map +1 -0
  36. package/dest/l1/types.d.ts +12 -0
  37. package/dest/l1/types.d.ts.map +1 -0
  38. package/dest/{archiver/l1 → l1}/validate_trace.d.ts +6 -3
  39. package/dest/l1/validate_trace.d.ts.map +1 -0
  40. package/dest/{archiver/l1 → l1}/validate_trace.js +13 -9
  41. package/dest/modules/data_source_base.d.ts +91 -0
  42. package/dest/modules/data_source_base.d.ts.map +1 -0
  43. package/dest/modules/data_source_base.js +222 -0
  44. package/dest/modules/data_store_updater.d.ts +86 -0
  45. package/dest/modules/data_store_updater.d.ts.map +1 -0
  46. package/dest/modules/data_store_updater.js +333 -0
  47. package/dest/modules/instrumentation.d.ts +52 -0
  48. package/dest/modules/instrumentation.d.ts.map +1 -0
  49. package/dest/{archiver → modules}/instrumentation.js +53 -18
  50. package/dest/modules/l1_synchronizer.d.ts +73 -0
  51. package/dest/modules/l1_synchronizer.d.ts.map +1 -0
  52. package/dest/modules/l1_synchronizer.js +1154 -0
  53. package/dest/{archiver → modules}/validation.d.ts +1 -1
  54. package/dest/modules/validation.d.ts.map +1 -0
  55. package/dest/{archiver → modules}/validation.js +8 -2
  56. package/dest/store/block_store.d.ts +230 -0
  57. package/dest/store/block_store.d.ts.map +1 -0
  58. package/dest/store/block_store.js +942 -0
  59. package/dest/store/contract_class_store.d.ts +17 -0
  60. package/dest/store/contract_class_store.d.ts.map +1 -0
  61. package/dest/store/contract_class_store.js +64 -0
  62. package/dest/store/contract_instance_store.d.ts +24 -0
  63. package/dest/store/contract_instance_store.d.ts.map +1 -0
  64. package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +7 -3
  65. package/dest/store/kv_archiver_store.d.ts +377 -0
  66. package/dest/store/kv_archiver_store.d.ts.map +1 -0
  67. package/dest/store/kv_archiver_store.js +494 -0
  68. package/dest/store/l2_tips_cache.d.ts +20 -0
  69. package/dest/store/l2_tips_cache.d.ts.map +1 -0
  70. package/dest/store/l2_tips_cache.js +109 -0
  71. package/dest/store/log_store.d.ts +57 -0
  72. package/dest/store/log_store.d.ts.map +1 -0
  73. package/dest/store/log_store.js +531 -0
  74. package/dest/store/message_store.d.ts +44 -0
  75. package/dest/store/message_store.d.ts.map +1 -0
  76. package/dest/{archiver/kv_archiver_store → store}/message_store.js +21 -9
  77. package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
  78. package/dest/structs/data_retrieval.d.ts.map +1 -0
  79. package/dest/structs/inbox_message.d.ts +15 -0
  80. package/dest/structs/inbox_message.d.ts.map +1 -0
  81. package/dest/{archiver/structs → structs}/published.d.ts +1 -1
  82. package/dest/structs/published.d.ts.map +1 -0
  83. package/dest/test/fake_l1_state.d.ts +210 -0
  84. package/dest/test/fake_l1_state.d.ts.map +1 -0
  85. package/dest/test/fake_l1_state.js +490 -0
  86. package/dest/test/index.d.ts +2 -1
  87. package/dest/test/index.d.ts.map +1 -1
  88. package/dest/test/index.js +4 -1
  89. package/dest/test/mock_archiver.d.ts +2 -2
  90. package/dest/test/mock_archiver.d.ts.map +1 -1
  91. package/dest/test/mock_archiver.js +3 -3
  92. package/dest/test/mock_l1_to_l2_message_source.d.ts +1 -1
  93. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  94. package/dest/test/mock_l1_to_l2_message_source.js +2 -1
  95. package/dest/test/mock_l2_block_source.d.ts +43 -19
  96. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  97. package/dest/test/mock_l2_block_source.js +211 -80
  98. package/dest/test/mock_structs.d.ts +81 -3
  99. package/dest/test/mock_structs.d.ts.map +1 -1
  100. package/dest/test/mock_structs.js +152 -7
  101. package/dest/test/noop_l1_archiver.d.ts +26 -0
  102. package/dest/test/noop_l1_archiver.d.ts.map +1 -0
  103. package/dest/test/noop_l1_archiver.js +71 -0
  104. package/package.json +16 -17
  105. package/src/archiver.ts +510 -0
  106. package/src/{archiver/config.ts → config.ts} +20 -2
  107. package/src/errors.ts +146 -0
  108. package/src/factory.ts +152 -16
  109. package/src/index.ts +11 -3
  110. package/src/interfaces.ts +9 -0
  111. package/src/l1/README.md +55 -0
  112. package/src/{archiver/l1 → l1}/bin/retrieve-calldata.ts +45 -33
  113. package/src/l1/calldata_retriever.ts +512 -0
  114. package/src/{archiver/l1 → l1}/data_retrieval.ts +79 -102
  115. package/src/{archiver/l1 → l1}/spire_proposer.ts +7 -15
  116. package/src/{archiver/l1 → l1}/validate_trace.ts +24 -6
  117. package/src/modules/data_source_base.ts +347 -0
  118. package/src/modules/data_store_updater.ts +437 -0
  119. package/src/{archiver → modules}/instrumentation.ts +64 -20
  120. package/src/modules/l1_synchronizer.ts +961 -0
  121. package/src/{archiver → modules}/validation.ts +7 -2
  122. package/src/store/block_store.ts +1245 -0
  123. package/src/store/contract_class_store.ts +82 -0
  124. package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +9 -6
  125. package/src/store/kv_archiver_store.ts +713 -0
  126. package/src/store/l2_tips_cache.ts +134 -0
  127. package/src/store/log_store.ts +733 -0
  128. package/src/{archiver/kv_archiver_store → store}/message_store.ts +27 -10
  129. package/src/{archiver/structs → structs}/inbox_message.ts +1 -1
  130. package/src/test/fake_l1_state.ts +747 -0
  131. package/src/test/index.ts +4 -0
  132. package/src/test/mock_archiver.ts +4 -3
  133. package/src/test/mock_l1_to_l2_message_source.ts +1 -0
  134. package/src/test/mock_l2_block_source.ts +269 -94
  135. package/src/test/mock_structs.ts +283 -8
  136. package/src/test/noop_l1_archiver.ts +114 -0
  137. package/dest/archiver/archiver.d.ts +0 -307
  138. package/dest/archiver/archiver.d.ts.map +0 -1
  139. package/dest/archiver/archiver.js +0 -2102
  140. package/dest/archiver/archiver_store.d.ts +0 -315
  141. package/dest/archiver/archiver_store.d.ts.map +0 -1
  142. package/dest/archiver/archiver_store.js +0 -4
  143. package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
  144. package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
  145. package/dest/archiver/archiver_store_test_suite.js +0 -2770
  146. package/dest/archiver/config.d.ts +0 -22
  147. package/dest/archiver/config.d.ts.map +0 -1
  148. package/dest/archiver/errors.d.ts +0 -36
  149. package/dest/archiver/errors.d.ts.map +0 -1
  150. package/dest/archiver/errors.js +0 -54
  151. package/dest/archiver/index.d.ts +0 -7
  152. package/dest/archiver/index.d.ts.map +0 -1
  153. package/dest/archiver/index.js +0 -4
  154. package/dest/archiver/instrumentation.d.ts +0 -37
  155. package/dest/archiver/instrumentation.d.ts.map +0 -1
  156. package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -164
  157. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
  158. package/dest/archiver/kv_archiver_store/block_store.js +0 -626
  159. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
  160. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
  161. package/dest/archiver/kv_archiver_store/contract_class_store.js +0 -120
  162. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
  163. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
  164. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -159
  165. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
  166. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -316
  167. package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -45
  168. package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
  169. package/dest/archiver/kv_archiver_store/log_store.js +0 -401
  170. package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -40
  171. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
  172. package/dest/archiver/l1/bin/retrieve-calldata.d.ts.map +0 -1
  173. package/dest/archiver/l1/calldata_retriever.d.ts +0 -112
  174. package/dest/archiver/l1/calldata_retriever.d.ts.map +0 -1
  175. package/dest/archiver/l1/calldata_retriever.js +0 -471
  176. package/dest/archiver/l1/data_retrieval.d.ts +0 -90
  177. package/dest/archiver/l1/data_retrieval.d.ts.map +0 -1
  178. package/dest/archiver/l1/debug_tx.d.ts.map +0 -1
  179. package/dest/archiver/l1/spire_proposer.d.ts.map +0 -1
  180. package/dest/archiver/l1/trace_tx.d.ts.map +0 -1
  181. package/dest/archiver/l1/types.d.ts +0 -12
  182. package/dest/archiver/l1/types.d.ts.map +0 -1
  183. package/dest/archiver/l1/validate_trace.d.ts.map +0 -1
  184. package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
  185. package/dest/archiver/structs/inbox_message.d.ts +0 -15
  186. package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
  187. package/dest/archiver/structs/published.d.ts.map +0 -1
  188. package/dest/archiver/validation.d.ts.map +0 -1
  189. package/dest/rpc/index.d.ts +0 -9
  190. package/dest/rpc/index.d.ts.map +0 -1
  191. package/dest/rpc/index.js +0 -15
  192. package/src/archiver/archiver.ts +0 -2265
  193. package/src/archiver/archiver_store.ts +0 -380
  194. package/src/archiver/archiver_store_test_suite.ts +0 -2842
  195. package/src/archiver/errors.ts +0 -90
  196. package/src/archiver/index.ts +0 -6
  197. package/src/archiver/kv_archiver_store/block_store.ts +0 -850
  198. package/src/archiver/kv_archiver_store/contract_class_store.ts +0 -176
  199. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -442
  200. package/src/archiver/kv_archiver_store/log_store.ts +0 -516
  201. package/src/archiver/l1/README.md +0 -98
  202. package/src/archiver/l1/calldata_retriever.ts +0 -641
  203. package/src/rpc/index.ts +0 -16
  204. /package/dest/{archiver/l1 → l1}/debug_tx.js +0 -0
  205. /package/dest/{archiver/l1 → l1}/trace_tx.js +0 -0
  206. /package/dest/{archiver/l1 → l1}/types.js +0 -0
  207. /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
  208. /package/dest/{archiver/structs → structs}/inbox_message.js +0 -0
  209. /package/dest/{archiver/structs → structs}/published.js +0 -0
  210. /package/src/{archiver/l1 → l1}/debug_tx.ts +0 -0
  211. /package/src/{archiver/l1 → l1}/trace_tx.ts +0 -0
  212. /package/src/{archiver/l1 → l1}/types.ts +0 -0
  213. /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
  214. /package/src/{archiver/structs → structs}/published.ts +0 -0
package/src/errors.ts ADDED
@@ -0,0 +1,146 @@
1
+ import type { Fr } from '@aztec/foundation/schemas';
2
+
3
+ export class NoBlobBodiesFoundError extends Error {
4
+ constructor(l2BlockNum: number) {
5
+ super(`No blob bodies found for block ${l2BlockNum}`);
6
+ }
7
+ }
8
+
9
+ export class BlockNumberNotSequentialError extends Error {
10
+ constructor(newBlockNumber: number, previous: number | undefined) {
11
+ super(`Cannot insert new block ${newBlockNumber} given previous block number is ${previous ?? 'undefined'}`);
12
+ }
13
+ }
14
+
15
+ export class InitialCheckpointNumberNotSequentialError extends Error {
16
+ constructor(
17
+ public readonly newCheckpointNumber: number,
18
+ public readonly previousCheckpointNumber: number | undefined,
19
+ ) {
20
+ super(
21
+ `Cannot insert new checkpoint ${newCheckpointNumber} given previous checkpoint number in store is ${
22
+ previousCheckpointNumber ?? 'undefined'
23
+ }`,
24
+ );
25
+ }
26
+ }
27
+
28
+ export class CheckpointNumberNotSequentialError extends Error {
29
+ constructor(
30
+ newCheckpointNumber: number,
31
+ previous: number | undefined,
32
+ source: 'confirmed' | 'proposed' = 'confirmed',
33
+ ) {
34
+ super(
35
+ `Cannot insert new checkpoint ${newCheckpointNumber} given previous ${source} checkpoint number is ${previous ?? 'undefined'}`,
36
+ );
37
+ }
38
+ }
39
+
40
+ export class BlockIndexNotSequentialError extends Error {
41
+ constructor(newBlockIndex: number, previousBlockIndex: number | undefined) {
42
+ super(
43
+ `Cannot insert new block at checkpoint index ${newBlockIndex} given previous block index is ${previousBlockIndex ?? 'undefined'}`,
44
+ );
45
+ }
46
+ }
47
+
48
+ export class BlockArchiveNotConsistentError extends Error {
49
+ constructor(
50
+ newBlockNumber: number,
51
+ previousBlockNumber: number | undefined,
52
+ newBlockArchive: Fr,
53
+ previousBlockArchive: Fr,
54
+ ) {
55
+ super(
56
+ `Cannot insert new block number ${newBlockNumber} with archive ${newBlockArchive.toString()} previous block number is ${previousBlockNumber ?? 'undefined'}, previous archive is ${previousBlockArchive?.toString() ?? 'undefined'}`,
57
+ );
58
+ }
59
+ }
60
+
61
+ export class CheckpointNotFoundError extends Error {
62
+ constructor(checkpointNumber: number) {
63
+ super(`Failed to find expected checkpoint number ${checkpointNumber}`);
64
+ }
65
+ }
66
+
67
+ export class BlockNotFoundError extends Error {
68
+ constructor(blockNumber: number) {
69
+ super(`Failed to find expected block number ${blockNumber}`);
70
+ }
71
+ }
72
+
73
+ /** Thrown when a proposed block matches a block that was already checkpointed. This is expected for late proposals. */
74
+ export class BlockAlreadyCheckpointedError extends Error {
75
+ constructor(public readonly blockNumber: number) {
76
+ super(`Block ${blockNumber} has already been checkpointed with the same content`);
77
+ this.name = 'BlockAlreadyCheckpointedError';
78
+ }
79
+ }
80
+
81
+ /** Thrown when logs are added for a tag whose last stored log has a higher block number than the new log. */
82
+ export class OutOfOrderLogInsertionError extends Error {
83
+ constructor(
84
+ public readonly logType: 'private' | 'public',
85
+ public readonly tag: string,
86
+ public readonly lastBlockNumber: number,
87
+ public readonly newBlockNumber: number,
88
+ ) {
89
+ super(
90
+ `Out-of-order ${logType} log insertion for tag ${tag}: ` +
91
+ `last existing log is from block ${lastBlockNumber} but new log is from block ${newBlockNumber}`,
92
+ );
93
+ this.name = 'OutOfOrderLogInsertionError';
94
+ }
95
+ }
96
+
97
+ /** Thrown when L1 to L2 messages are requested for a checkpoint whose message tree hasn't been sealed yet. */
98
+ export class L1ToL2MessagesNotReadyError extends Error {
99
+ constructor(
100
+ public readonly checkpointNumber: number,
101
+ public readonly inboxTreeInProgress: bigint,
102
+ ) {
103
+ super(
104
+ `Cannot get L1 to L2 messages for checkpoint ${checkpointNumber}: ` +
105
+ `inbox tree in progress is ${inboxTreeInProgress}, messages not yet sealed`,
106
+ );
107
+ this.name = 'L1ToL2MessagesNotReadyError';
108
+ }
109
+ }
110
+
111
+ /** Thrown when a proposed checkpoint number is stale (already processed). */
112
+ export class ProposedCheckpointStaleError extends Error {
113
+ constructor(
114
+ public readonly proposedCheckpointNumber: number,
115
+ public readonly currentProposedNumber: number,
116
+ ) {
117
+ super(`Stale proposed checkpoint ${proposedCheckpointNumber}: current proposed is ${currentProposedNumber}`);
118
+ this.name = 'ProposedCheckpointStaleError';
119
+ }
120
+ }
121
+
122
+ /** Thrown when a proposed checkpoint number is not the expected confirmed + 1. */
123
+ export class ProposedCheckpointNotSequentialError extends Error {
124
+ constructor(
125
+ public readonly proposedCheckpointNumber: number,
126
+ public readonly confirmedCheckpointNumber: number,
127
+ ) {
128
+ super(
129
+ `Proposed checkpoint ${proposedCheckpointNumber} is not sequential: expected ${confirmedCheckpointNumber + 1} (confirmed + 1)`,
130
+ );
131
+ this.name = 'ProposedCheckpointNotSequentialError';
132
+ }
133
+ }
134
+
135
+ /** Thrown when a proposed block conflicts with an already checkpointed block (different content). */
136
+ export class CannotOverwriteCheckpointedBlockError extends Error {
137
+ constructor(
138
+ public readonly blockNumber: number,
139
+ public readonly lastCheckpointedBlock: number,
140
+ ) {
141
+ super(
142
+ `Cannot add block ${blockNumber}: would overwrite checkpointed data (checkpointed up to block ${lastCheckpointedBlock})`,
143
+ );
144
+ this.name = 'CannotOverwriteCheckpointedBlockError';
145
+ }
146
+ }
package/src/factory.ts CHANGED
@@ -1,15 +1,31 @@
1
+ import { EpochCache } from '@aztec/epoch-cache';
2
+ import { createEthereumChain } from '@aztec/ethereum/chain';
3
+ import { makeL1HttpTransport } from '@aztec/ethereum/client';
4
+ import { InboxContract, RollupContract } from '@aztec/ethereum/contracts';
5
+ import type { ViemPublicDebugClient } from '@aztec/ethereum/types';
1
6
  import { BlockNumber } from '@aztec/foundation/branded-types';
2
- import { createLogger } from '@aztec/foundation/log';
3
- import type { DataStoreConfig } from '@aztec/kv-store/config';
7
+ import { Buffer32 } from '@aztec/foundation/buffer';
8
+ import { merge } from '@aztec/foundation/collection';
9
+ import { Fr } from '@aztec/foundation/curves/bn254';
10
+ import { DateProvider } from '@aztec/foundation/timer';
4
11
  import { createStore } from '@aztec/kv-store/lmdb-v2';
5
12
  import { protocolContractNames } from '@aztec/protocol-contracts';
6
13
  import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
7
14
  import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi';
8
- import { type ContractClassPublic, computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
15
+ import type { ArchiverEmitter } from '@aztec/stdlib/block';
16
+ import { type ContractClassPublicWithCommitment, computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
17
+ import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
18
+ import { getTelemetryClient } from '@aztec/telemetry-client';
9
19
 
10
- import { Archiver, type ArchiverDeps } from './archiver/archiver.js';
11
- import type { ArchiverConfig } from './archiver/config.js';
12
- import { ARCHIVER_DB_VERSION, KVArchiverDataStore } from './archiver/kv_archiver_store/kv_archiver_store.js';
20
+ import { EventEmitter } from 'events';
21
+ import { createPublicClient } from 'viem';
22
+
23
+ import { Archiver, type ArchiverDeps } from './archiver.js';
24
+ import { type ArchiverConfig, mapArchiverConfig } from './config.js';
25
+ import { ArchiverInstrumentation } from './modules/instrumentation.js';
26
+ import { ArchiverL1Synchronizer } from './modules/l1_synchronizer.js';
27
+ import { ARCHIVER_DB_VERSION, KVArchiverDataStore } from './store/kv_archiver_store.js';
28
+ import { L2TipsCache } from './store/l2_tips_cache.js';
13
29
 
14
30
  export const ARCHIVER_STORE_NAME = 'archiver';
15
31
 
@@ -21,16 +37,15 @@ export async function createArchiverStore(
21
37
  ...userConfig,
22
38
  dataStoreMapSizeKb: userConfig.archiverStoreMapSizeKb ?? userConfig.dataStoreMapSizeKb,
23
39
  };
24
- const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config, createLogger('archiver:lmdb'));
40
+ const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config);
25
41
  return new KVArchiverDataStore(store, config.maxLogs);
26
42
  }
27
43
 
28
44
  /**
29
45
  * Creates a local archiver.
30
46
  * @param config - The archiver configuration.
31
- * @param blobClient - The blob client client.
47
+ * @param deps - The archiver dependencies (blobClient, epochCache, dateProvider, telemetry).
32
48
  * @param opts - The options.
33
- * @param telemetry - The telemetry client.
34
49
  * @returns The local archiver.
35
50
  */
36
51
  export async function createArchiver(
@@ -40,18 +55,140 @@ export async function createArchiver(
40
55
  ): Promise<Archiver> {
41
56
  const archiverStore = await createArchiverStore(config);
42
57
  await registerProtocolContracts(archiverStore);
43
- return Archiver.createAndSync(config, archiverStore, deps, opts.blockUntilSync);
58
+
59
+ // Create Ethereum clients
60
+ const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
61
+ const httpTimeout = config.l1HttpTimeoutMS;
62
+ const publicClient = createPublicClient({
63
+ chain: chain.chainInfo,
64
+ transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: httpTimeout }),
65
+ pollingInterval: config.viemPollingIntervalMS,
66
+ });
67
+
68
+ // Create debug client using debug RPC URLs if available, otherwise fall back to regular RPC URLs
69
+ const debugRpcUrls = config.l1DebugRpcUrls.length > 0 ? config.l1DebugRpcUrls : config.l1RpcUrls;
70
+ const debugClient = createPublicClient({
71
+ chain: chain.chainInfo,
72
+ transport: makeL1HttpTransport(debugRpcUrls, { timeout: httpTimeout }),
73
+ pollingInterval: config.viemPollingIntervalMS,
74
+ }) as ViemPublicDebugClient;
75
+
76
+ // Create L1 contract instances
77
+ const rollup = new RollupContract(publicClient, config.l1Contracts.rollupAddress);
78
+ const inbox = new InboxContract(publicClient, config.l1Contracts.inboxAddress);
79
+
80
+ // Fetch L1 constants from rollup contract
81
+ const [
82
+ l1StartBlock,
83
+ l1GenesisTime,
84
+ proofSubmissionEpochs,
85
+ genesisArchiveRoot,
86
+ slashingProposerAddress,
87
+ targetCommitteeSize,
88
+ rollupManaLimit,
89
+ ] = await Promise.all([
90
+ rollup.getL1StartBlock(),
91
+ rollup.getL1GenesisTime(),
92
+ rollup.getProofSubmissionEpochs(),
93
+ rollup.getGenesisArchiveTreeRoot(),
94
+ rollup.getSlashingProposerAddress(),
95
+ rollup.getTargetCommitteeSize(),
96
+ rollup.getManaLimit(),
97
+ ] as const);
98
+
99
+ const l1StartBlockHash = await publicClient
100
+ .getBlock({ blockNumber: l1StartBlock, includeTransactions: false })
101
+ .then(block => Buffer32.fromString(block.hash));
102
+
103
+ const { aztecEpochDuration: epochDuration, aztecSlotDuration: slotDuration, ethereumSlotDuration } = config;
104
+
105
+ const l1Constants = {
106
+ l1StartBlockHash,
107
+ l1StartBlock,
108
+ l1GenesisTime,
109
+ epochDuration,
110
+ slotDuration,
111
+ ethereumSlotDuration,
112
+ proofSubmissionEpochs: Number(proofSubmissionEpochs),
113
+ targetCommitteeSize,
114
+ genesisArchiveRoot: Fr.fromString(genesisArchiveRoot.toString()),
115
+ rollupManaLimit: Number(rollupManaLimit),
116
+ };
117
+
118
+ const archiverConfig = merge(
119
+ {
120
+ pollingIntervalMs: 10_000,
121
+ batchSize: 100,
122
+ maxAllowedEthClientDriftSeconds: 300,
123
+ ethereumAllowNoDebugHosts: false,
124
+ },
125
+ mapArchiverConfig(config),
126
+ );
127
+
128
+ const epochCache = deps.epochCache ?? (await EpochCache.create(config.l1Contracts.rollupAddress, config, deps));
129
+ const telemetry = deps.telemetry ?? getTelemetryClient();
130
+ const instrumentation = await ArchiverInstrumentation.new(telemetry, () => archiverStore.estimateSize());
131
+
132
+ // Create the event emitter that will be shared by archiver and synchronizer
133
+ const events = new EventEmitter() as ArchiverEmitter;
134
+
135
+ // Create L2 tips cache shared by archiver and synchronizer
136
+ const l2TipsCache = new L2TipsCache(archiverStore.blockStore);
137
+
138
+ // Create the L1 synchronizer
139
+ const synchronizer = new ArchiverL1Synchronizer(
140
+ publicClient,
141
+ debugClient,
142
+ rollup,
143
+ inbox,
144
+ archiverStore,
145
+ archiverConfig,
146
+ deps.blobClient,
147
+ epochCache,
148
+ deps.dateProvider ?? new DateProvider(),
149
+ instrumentation,
150
+ l1Constants,
151
+ events,
152
+ instrumentation.tracer,
153
+ l2TipsCache,
154
+ undefined, // log (use default)
155
+ );
156
+
157
+ const archiver = new Archiver(
158
+ publicClient,
159
+ debugClient,
160
+ rollup,
161
+ { ...config.l1Contracts, slashingProposerAddress },
162
+ archiverStore,
163
+ archiverConfig,
164
+ deps.blobClient,
165
+ instrumentation,
166
+ l1Constants,
167
+ synchronizer,
168
+ events,
169
+ l2TipsCache,
170
+ );
171
+
172
+ await archiver.start(opts.blockUntilSync);
173
+ return archiver;
44
174
  }
45
175
 
46
- async function registerProtocolContracts(store: KVArchiverDataStore) {
176
+ /** Registers protocol contracts in the archiver store. Idempotent — skips contracts that already exist (e.g. on node restart). */
177
+ export async function registerProtocolContracts(store: KVArchiverDataStore) {
47
178
  const blockNumber = 0;
48
179
  for (const name of protocolContractNames) {
49
180
  const provider = new BundledProtocolContractsProvider();
50
181
  const contract = await provider.getProtocolContractArtifact(name);
51
- const contractClassPublic: ContractClassPublic = {
182
+
183
+ // Skip if already registered (happens on node restart with a persisted store).
184
+ if (await store.getContractClass(contract.contractClass.id)) {
185
+ continue;
186
+ }
187
+
188
+ const publicBytecodeCommitment = await computePublicBytecodeCommitment(contract.contractClass.packedBytecode);
189
+ const contractClassPublic: ContractClassPublicWithCommitment = {
52
190
  ...contract.contractClass,
53
- privateFunctions: [],
54
- utilityFunctions: [],
191
+ publicBytecodeCommitment,
55
192
  };
56
193
 
57
194
  const publicFunctionSignatures = contract.artifact.functions
@@ -59,8 +196,7 @@ async function registerProtocolContracts(store: KVArchiverDataStore) {
59
196
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
60
197
 
61
198
  await store.registerContractFunctionSignatures(publicFunctionSignatures);
62
- const bytecodeCommitment = await computePublicBytecodeCommitment(contractClassPublic.packedBytecode);
63
- await store.addContractClasses([contractClassPublic], [bytecodeCommitment], BlockNumber(blockNumber));
199
+ await store.addContractClasses([contractClassPublic], BlockNumber(blockNumber));
64
200
  await store.addContractInstances([contract.instance], BlockNumber(blockNumber));
65
201
  }
66
202
  }
package/src/index.ts CHANGED
@@ -1,5 +1,13 @@
1
- export * from './archiver/index.js';
2
1
  export * from './factory.js';
3
- export * from './rpc/index.js';
2
+ export * from './interfaces.js';
3
+ export * from './archiver.js';
4
+ export * from './modules/data_source_base.js';
5
+ export * from './modules/data_store_updater.js';
6
+ export * from './config.js';
4
7
 
5
- export { retrieveCheckpointsFromRollup, retrieveL2ProofVerifiedEvents } from './archiver/l1/data_retrieval.js';
8
+ export { type L1PublishedData } from './structs/published.js';
9
+ export { KVArchiverDataStore, ARCHIVER_DB_VERSION } from './store/kv_archiver_store.js';
10
+ export { ContractInstanceStore } from './store/contract_instance_store.js';
11
+ export { L2TipsCache } from './store/l2_tips_cache.js';
12
+
13
+ export { retrieveCheckpointsFromRollup, retrieveL2ProofVerifiedEvents } from './l1/data_retrieval.js';
@@ -0,0 +1,9 @@
1
+ import type { L2BlockSource } from '@aztec/stdlib/block';
2
+ import type { ContractDataSource } from '@aztec/stdlib/contract';
3
+ import type { L2LogsSource } from '@aztec/stdlib/interfaces/server';
4
+ import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
5
+
6
+ /**
7
+ * Helper interface to combine all sources this archiver implementation provides.
8
+ */
9
+ export type ArchiverDataSource = L2BlockSource & L2LogsSource & ContractDataSource & L1ToL2MessageSource;
@@ -0,0 +1,55 @@
1
+ # Archiver L1 Data Retrieval
2
+
3
+ Modules and classes to handle data retrieval from L1 for the archiver.
4
+
5
+ ## Calldata Retriever
6
+
7
+ The sequencer publisher bundles multiple operations into a single multicall3 transaction for gas
8
+ efficiency. The archiver needs to extract the `propose` calldata from these bundled transactions
9
+ to reconstruct L2 blocks.
10
+
11
+ The retriever uses hash matching against `attestationsHash` and `payloadDigest` from the
12
+ `CheckpointProposed` L1 event to verify it has found the correct propose calldata. These hashes
13
+ are always required.
14
+
15
+ ### Multicall3 Decoding with Hash Matching
16
+
17
+ First attempt to decode the transaction as a multicall3 `aggregate3` call:
18
+
19
+ - Check if transaction is to multicall3 address (`0xcA11bde05977b3631167028862bE2a173976CA11`)
20
+ - Decode as `aggregate3(Call3[] calldata calls)`
21
+ - Find all calls matching the rollup contract address and the `propose` function selector
22
+ - Verify each candidate by computing `attestationsHash` (keccak256 of ABI-encoded attestations)
23
+ and `payloadDigest` (keccak256 of the consensus payload signing hash) and comparing against
24
+ expected values from the `CheckpointProposed` event
25
+ - Return the verified candidate (if multiple verify, return the first with a warning)
26
+
27
+ This approach works regardless of what other calls are in the multicall3 bundle, because hash
28
+ matching identifies the correct propose call without needing an allowlist.
29
+
30
+ ### Direct Propose Call
31
+
32
+ Second attempt to decode the transaction as a direct `propose` call to the rollup contract:
33
+
34
+ - Check if transaction is to the rollup address
35
+ - Decode as `propose` function call
36
+ - Verify against expected hashes
37
+ - Return the transaction input as the propose calldata
38
+
39
+ ### Spire Proposer Call
40
+
41
+ Given existing attempts to route the call via the Spire proposer, we also check if the tx is
42
+ `to` the proposer known address. If so, we extract all wrapped calls and try each as either
43
+ a multicall3 or direct propose call, using hash matching to find and verify the correct one.
44
+
45
+ Since the Spire proposer is upgradeable, we check that the implementation has not changed in
46
+ order to decode. Any validation failure triggers fallback to the next step.
47
+
48
+ ### Debug and Trace Transaction Fallback
49
+
50
+ Last, we use L1 node's trace/debug RPC methods to definitively identify the one successful
51
+ `propose` call within the tx. We can then extract the exact calldata that hit the `propose`
52
+ function in the rollup contract.
53
+
54
+ This approach requires access to a debug-enabled L1 node, which may be more resource-intensive,
55
+ so we only use it as a fallback when earlier steps fail, which should be rare in practice.
@@ -3,8 +3,9 @@ import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/ty
3
3
  import { CheckpointNumber } from '@aztec/foundation/branded-types';
4
4
  import { EthAddress } from '@aztec/foundation/eth-address';
5
5
  import { createLogger } from '@aztec/foundation/log';
6
+ import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
6
7
 
7
- import { type Hex, createPublicClient, http } from 'viem';
8
+ import { type Hex, createPublicClient, decodeEventLog, getAbiItem, http, toEventSelector } from 'viem';
8
9
  import { mainnet } from 'viem/chains';
9
10
 
10
11
  import { CalldataRetriever } from '../calldata_retriever.js';
@@ -88,14 +89,6 @@ async function main() {
88
89
 
89
90
  logger.info(`Transaction found in block ${tx.blockNumber}`);
90
91
 
91
- // For simplicity, use zero addresses for optional contract addresses
92
- // In production, these would be fetched from the rollup contract or configuration
93
- const slashingProposerAddress = EthAddress.ZERO;
94
- const governanceProposerAddress = EthAddress.ZERO;
95
- const slashFactoryAddress = undefined;
96
-
97
- logger.info('Using zero addresses for governance/slashing (can be configured if needed)');
98
-
99
92
  // Create CalldataRetriever
100
93
  const retriever = new CalldataRetriever(
101
94
  publicClient as unknown as ViemPublicClient,
@@ -103,48 +96,67 @@ async function main() {
103
96
  targetCommitteeSize,
104
97
  undefined,
105
98
  logger,
106
- {
107
- rollupAddress,
108
- governanceProposerAddress,
109
- slashingProposerAddress,
110
- slashFactoryAddress,
111
- },
99
+ rollupAddress,
112
100
  );
113
101
 
114
- // Extract L2 block number from transaction logs
115
- logger.info('Decoding transaction to extract L2 block number...');
102
+ // Extract checkpoint number and hashes from transaction logs
103
+ logger.info('Decoding transaction to extract checkpoint number and hashes...');
116
104
  const receipt = await publicClient.getTransactionReceipt({ hash: txHash });
117
- const l2BlockProposedEvent = receipt.logs.find(log => {
105
+
106
+ // Look for CheckpointProposed event
107
+ const checkpointProposedEventAbi = getAbiItem({ abi: RollupAbi, name: 'CheckpointProposed' });
108
+ const checkpointProposedLog = receipt.logs.find(log => {
118
109
  try {
119
- // Try to match the L2BlockProposed event
120
110
  return (
121
111
  log.address.toLowerCase() === rollupAddress.toString().toLowerCase() &&
122
- log.topics[0] === '0x2f1d0e696fa5186494a2f2f89a0e0bcbb15d607f6c5eac4637e07e1e5e7d3c00' // L2BlockProposed event signature
112
+ log.topics[0] === toEventSelector(checkpointProposedEventAbi)
123
113
  );
124
114
  } catch {
125
115
  return false;
126
116
  }
127
117
  });
128
118
 
129
- let l2BlockNumber: number;
130
- if (l2BlockProposedEvent && l2BlockProposedEvent.topics[1]) {
131
- // L2 block number is typically the first indexed parameter
132
- l2BlockNumber = Number(BigInt(l2BlockProposedEvent.topics[1]));
133
- logger.info(`L2 Block Number (from event): ${l2BlockNumber}`);
134
- } else {
135
- // Fallback: try to extract from transaction data or use a default
136
- logger.warn('Could not extract L2 block number from event, using block number as fallback');
137
- l2BlockNumber = Number(tx.blockNumber);
119
+ if (!checkpointProposedLog || checkpointProposedLog.topics[1] === undefined) {
120
+ throw new Error(`Checkpoint proposed event not found`);
138
121
  }
139
122
 
123
+ const checkpointNumber = CheckpointNumber.fromBigInt(BigInt(checkpointProposedLog.topics[1]));
124
+
125
+ // Decode the full event to extract attestationsHash and payloadDigest
126
+ const decodedEvent = decodeEventLog({
127
+ abi: RollupAbi,
128
+ data: checkpointProposedLog.data,
129
+ topics: checkpointProposedLog.topics,
130
+ });
131
+
132
+ const eventArgs = decodedEvent.args as {
133
+ checkpointNumber: bigint;
134
+ archive: Hex;
135
+ versionedBlobHashes: Hex[];
136
+ attestationsHash: Hex;
137
+ payloadDigest: Hex;
138
+ };
139
+
140
+ if (!eventArgs.attestationsHash || !eventArgs.payloadDigest) {
141
+ throw new Error(`CheckpointProposed event missing attestationsHash or payloadDigest`);
142
+ }
143
+
144
+ const expectedHashes = {
145
+ attestationsHash: eventArgs.attestationsHash,
146
+ payloadDigest: eventArgs.payloadDigest,
147
+ };
148
+
149
+ logger.info(`Checkpoint Number: ${checkpointNumber}`);
150
+ logger.info(`Attestations Hash: ${expectedHashes.attestationsHash}`);
151
+ logger.info(`Payload Digest: ${expectedHashes.payloadDigest}`);
152
+
140
153
  logger.info('');
141
- logger.info('Retrieving block header from rollup transaction...');
154
+ logger.info('Retrieving checkpoint from rollup transaction...');
142
155
  logger.info('');
143
156
 
144
- // For this script, we don't have blob hashes or expected hashes, so pass empty arrays/objects
145
- const result = await retriever.getCheckpointFromRollupTx(txHash, [], CheckpointNumber(l2BlockNumber), {});
157
+ const result = await retriever.getCheckpointFromRollupTx(txHash, [], checkpointNumber, expectedHashes);
146
158
 
147
- logger.info(' Successfully retrieved block header!');
159
+ logger.info(' Successfully retrieved block header!');
148
160
  logger.info('');
149
161
  logger.info('Block Header Details:');
150
162
  logger.info('====================');