@aztec/archiver 0.0.1-commit.5daedc8 → 0.0.1-commit.6201a7b05

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 (218) hide show
  1. package/README.md +162 -22
  2. package/dest/archiver.d.ts +147 -0
  3. package/dest/archiver.d.ts.map +1 -0
  4. package/dest/archiver.js +788 -0
  5. package/dest/config.d.ts +32 -0
  6. package/dest/config.d.ts.map +1 -0
  7. package/dest/config.js +83 -0
  8. package/dest/errors.d.ts +92 -0
  9. package/dest/errors.d.ts.map +1 -0
  10. package/dest/errors.js +136 -0
  11. package/dest/factory.d.ts +8 -7
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +100 -15
  14. package/dest/index.d.ts +12 -4
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +10 -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/l1/bin/retrieve-calldata.d.ts +3 -0
  21. package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
  22. package/dest/l1/bin/retrieve-calldata.js +152 -0
  23. package/dest/l1/calldata_retriever.d.ts +136 -0
  24. package/dest/l1/calldata_retriever.d.ts.map +1 -0
  25. package/dest/l1/calldata_retriever.js +408 -0
  26. package/dest/l1/data_retrieval.d.ts +97 -0
  27. package/dest/l1/data_retrieval.d.ts.map +1 -0
  28. package/dest/{archiver → l1}/data_retrieval.js +86 -165
  29. package/dest/l1/debug_tx.d.ts +19 -0
  30. package/dest/l1/debug_tx.d.ts.map +1 -0
  31. package/dest/l1/debug_tx.js +73 -0
  32. package/dest/l1/spire_proposer.d.ts +70 -0
  33. package/dest/l1/spire_proposer.d.ts.map +1 -0
  34. package/dest/l1/spire_proposer.js +149 -0
  35. package/dest/l1/trace_tx.d.ts +97 -0
  36. package/dest/l1/trace_tx.d.ts.map +1 -0
  37. package/dest/l1/trace_tx.js +91 -0
  38. package/dest/l1/types.d.ts +12 -0
  39. package/dest/l1/types.d.ts.map +1 -0
  40. package/dest/l1/types.js +3 -0
  41. package/dest/l1/validate_historical_logs.d.ts +23 -0
  42. package/dest/l1/validate_historical_logs.d.ts.map +1 -0
  43. package/dest/l1/validate_historical_logs.js +108 -0
  44. package/dest/l1/validate_trace.d.ts +32 -0
  45. package/dest/l1/validate_trace.d.ts.map +1 -0
  46. package/dest/l1/validate_trace.js +154 -0
  47. package/dest/modules/data_source_base.d.ts +95 -0
  48. package/dest/modules/data_source_base.d.ts.map +1 -0
  49. package/dest/modules/data_source_base.js +234 -0
  50. package/dest/modules/data_store_updater.d.ts +93 -0
  51. package/dest/modules/data_store_updater.d.ts.map +1 -0
  52. package/dest/modules/data_store_updater.js +345 -0
  53. package/dest/modules/instrumentation.d.ts +55 -0
  54. package/dest/modules/instrumentation.d.ts.map +1 -0
  55. package/dest/modules/instrumentation.js +143 -0
  56. package/dest/modules/l1_synchronizer.d.ts +77 -0
  57. package/dest/modules/l1_synchronizer.d.ts.map +1 -0
  58. package/dest/modules/l1_synchronizer.js +1265 -0
  59. package/dest/modules/validation.d.ts +18 -0
  60. package/dest/modules/validation.d.ts.map +1 -0
  61. package/dest/{archiver → modules}/validation.js +13 -7
  62. package/dest/store/block_store.d.ts +262 -0
  63. package/dest/store/block_store.d.ts.map +1 -0
  64. package/dest/store/block_store.js +1048 -0
  65. package/dest/store/contract_class_store.d.ts +17 -0
  66. package/dest/store/contract_class_store.d.ts.map +1 -0
  67. package/dest/store/contract_class_store.js +64 -0
  68. package/dest/store/contract_instance_store.d.ts +24 -0
  69. package/dest/store/contract_instance_store.d.ts.map +1 -0
  70. package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +7 -3
  71. package/dest/store/kv_archiver_store.d.ts +401 -0
  72. package/dest/store/kv_archiver_store.d.ts.map +1 -0
  73. package/dest/store/kv_archiver_store.js +525 -0
  74. package/dest/store/l2_tips_cache.d.ts +20 -0
  75. package/dest/store/l2_tips_cache.d.ts.map +1 -0
  76. package/dest/store/l2_tips_cache.js +109 -0
  77. package/dest/store/log_store.d.ts +57 -0
  78. package/dest/store/log_store.d.ts.map +1 -0
  79. package/dest/store/log_store.js +531 -0
  80. package/dest/store/message_store.d.ts +44 -0
  81. package/dest/store/message_store.d.ts.map +1 -0
  82. package/dest/{archiver/kv_archiver_store → store}/message_store.js +36 -23
  83. package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
  84. package/dest/structs/data_retrieval.d.ts.map +1 -0
  85. package/dest/structs/inbox_message.d.ts +15 -0
  86. package/dest/structs/inbox_message.d.ts.map +1 -0
  87. package/dest/{archiver/structs → structs}/inbox_message.js +6 -5
  88. package/dest/structs/published.d.ts +2 -0
  89. package/dest/structs/published.d.ts.map +1 -0
  90. package/dest/test/fake_l1_state.d.ts +214 -0
  91. package/dest/test/fake_l1_state.d.ts.map +1 -0
  92. package/dest/test/fake_l1_state.js +517 -0
  93. package/dest/test/index.d.ts +2 -1
  94. package/dest/test/index.d.ts.map +1 -1
  95. package/dest/test/index.js +4 -1
  96. package/dest/test/mock_archiver.d.ts +16 -8
  97. package/dest/test/mock_archiver.d.ts.map +1 -1
  98. package/dest/test/mock_archiver.js +19 -14
  99. package/dest/test/mock_l1_to_l2_message_source.d.ts +7 -6
  100. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  101. package/dest/test/mock_l1_to_l2_message_source.js +23 -12
  102. package/dest/test/mock_l2_block_source.d.ts +68 -20
  103. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  104. package/dest/test/mock_l2_block_source.js +298 -85
  105. package/dest/test/mock_structs.d.ts +83 -4
  106. package/dest/test/mock_structs.d.ts.map +1 -1
  107. package/dest/test/mock_structs.js +157 -11
  108. package/dest/test/noop_l1_archiver.d.ts +26 -0
  109. package/dest/test/noop_l1_archiver.d.ts.map +1 -0
  110. package/dest/test/noop_l1_archiver.js +74 -0
  111. package/package.json +20 -20
  112. package/src/archiver.ts +566 -0
  113. package/src/{archiver/config.ts → config.ts} +51 -14
  114. package/src/errors.ts +213 -0
  115. package/src/factory.ts +155 -17
  116. package/src/index.ts +12 -3
  117. package/src/interfaces.ts +9 -0
  118. package/src/l1/README.md +55 -0
  119. package/src/l1/bin/retrieve-calldata.ts +194 -0
  120. package/src/l1/calldata_retriever.ts +523 -0
  121. package/src/{archiver → l1}/data_retrieval.ts +155 -247
  122. package/src/l1/debug_tx.ts +99 -0
  123. package/src/l1/spire_proposer.ts +152 -0
  124. package/src/l1/trace_tx.ts +128 -0
  125. package/src/l1/types.ts +13 -0
  126. package/src/l1/validate_historical_logs.ts +140 -0
  127. package/src/l1/validate_trace.ts +229 -0
  128. package/src/modules/data_source_base.ts +364 -0
  129. package/src/modules/data_store_updater.ts +465 -0
  130. package/src/modules/instrumentation.ts +204 -0
  131. package/src/modules/l1_synchronizer.ts +1126 -0
  132. package/src/{archiver → modules}/validation.ts +21 -15
  133. package/src/store/block_store.ts +1361 -0
  134. package/src/store/contract_class_store.ts +82 -0
  135. package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +10 -7
  136. package/src/store/kv_archiver_store.ts +765 -0
  137. package/src/store/l2_tips_cache.ts +134 -0
  138. package/src/store/log_store.ts +733 -0
  139. package/src/{archiver/kv_archiver_store → store}/message_store.ts +48 -28
  140. package/src/{archiver/structs → structs}/inbox_message.ts +7 -7
  141. package/src/{archiver/structs → structs}/published.ts +0 -1
  142. package/src/test/fake_l1_state.ts +770 -0
  143. package/src/test/fixtures/debug_traceTransaction-multicall3.json +88 -0
  144. package/src/test/fixtures/debug_traceTransaction-multiplePropose.json +153 -0
  145. package/src/test/fixtures/debug_traceTransaction-proxied.json +122 -0
  146. package/src/test/fixtures/trace_transaction-multicall3.json +65 -0
  147. package/src/test/fixtures/trace_transaction-multiplePropose.json +319 -0
  148. package/src/test/fixtures/trace_transaction-proxied.json +128 -0
  149. package/src/test/fixtures/trace_transaction-randomRevert.json +216 -0
  150. package/src/test/index.ts +4 -0
  151. package/src/test/mock_archiver.ts +23 -16
  152. package/src/test/mock_l1_to_l2_message_source.ts +19 -11
  153. package/src/test/mock_l2_block_source.ts +367 -93
  154. package/src/test/mock_structs.ts +289 -13
  155. package/src/test/noop_l1_archiver.ts +117 -0
  156. package/dest/archiver/archiver.d.ts +0 -287
  157. package/dest/archiver/archiver.d.ts.map +0 -1
  158. package/dest/archiver/archiver.js +0 -1408
  159. package/dest/archiver/archiver_store.d.ts +0 -255
  160. package/dest/archiver/archiver_store.d.ts.map +0 -1
  161. package/dest/archiver/archiver_store.js +0 -4
  162. package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
  163. package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
  164. package/dest/archiver/archiver_store_test_suite.js +0 -1289
  165. package/dest/archiver/config.d.ts +0 -21
  166. package/dest/archiver/config.d.ts.map +0 -1
  167. package/dest/archiver/config.js +0 -55
  168. package/dest/archiver/data_retrieval.d.ts +0 -79
  169. package/dest/archiver/data_retrieval.d.ts.map +0 -1
  170. package/dest/archiver/errors.d.ts +0 -12
  171. package/dest/archiver/errors.d.ts.map +0 -1
  172. package/dest/archiver/errors.js +0 -17
  173. package/dest/archiver/index.d.ts +0 -7
  174. package/dest/archiver/index.d.ts.map +0 -1
  175. package/dest/archiver/index.js +0 -4
  176. package/dest/archiver/instrumentation.d.ts +0 -35
  177. package/dest/archiver/instrumentation.d.ts.map +0 -1
  178. package/dest/archiver/instrumentation.js +0 -140
  179. package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -124
  180. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
  181. package/dest/archiver/kv_archiver_store/block_store.js +0 -370
  182. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
  183. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
  184. package/dest/archiver/kv_archiver_store/contract_class_store.js +0 -120
  185. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
  186. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
  187. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -168
  188. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
  189. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -296
  190. package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -49
  191. package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
  192. package/dest/archiver/kv_archiver_store/log_store.js +0 -336
  193. package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -39
  194. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
  195. package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
  196. package/dest/archiver/structs/inbox_message.d.ts +0 -15
  197. package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
  198. package/dest/archiver/structs/published.d.ts +0 -3
  199. package/dest/archiver/structs/published.d.ts.map +0 -1
  200. package/dest/archiver/validation.d.ts +0 -17
  201. package/dest/archiver/validation.d.ts.map +0 -1
  202. package/dest/rpc/index.d.ts +0 -9
  203. package/dest/rpc/index.d.ts.map +0 -1
  204. package/dest/rpc/index.js +0 -15
  205. package/src/archiver/archiver.ts +0 -1858
  206. package/src/archiver/archiver_store.ts +0 -305
  207. package/src/archiver/archiver_store_test_suite.ts +0 -1264
  208. package/src/archiver/errors.ts +0 -26
  209. package/src/archiver/index.ts +0 -6
  210. package/src/archiver/instrumentation.ts +0 -187
  211. package/src/archiver/kv_archiver_store/block_store.ts +0 -481
  212. package/src/archiver/kv_archiver_store/contract_class_store.ts +0 -176
  213. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -422
  214. package/src/archiver/kv_archiver_store/log_store.ts +0 -406
  215. package/src/rpc/index.ts +0 -16
  216. /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
  217. /package/dest/{archiver/structs → structs}/published.js +0 -0
  218. /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
package/src/errors.ts ADDED
@@ -0,0 +1,213 @@
1
+ import type { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
2
+ import type { Fr } from '@aztec/foundation/schemas';
3
+
4
+ export class NoBlobBodiesFoundError extends Error {
5
+ constructor(l2BlockNum: number) {
6
+ super(`No blob bodies found for block ${l2BlockNum}`);
7
+ this.name = 'NoBlobBodiesFoundError';
8
+ }
9
+ }
10
+
11
+ export class BlockNumberNotSequentialError extends Error {
12
+ constructor(newBlockNumber: number, previous: number | undefined) {
13
+ super(`Cannot insert new block ${newBlockNumber} given previous block number is ${previous ?? 'undefined'}`);
14
+ this.name = 'BlockNumberNotSequentialError';
15
+ }
16
+ }
17
+
18
+ export class InitialCheckpointNumberNotSequentialError extends Error {
19
+ constructor(
20
+ public readonly newCheckpointNumber: number,
21
+ public readonly previousCheckpointNumber: number | undefined,
22
+ ) {
23
+ super(
24
+ `Cannot insert new checkpoint ${newCheckpointNumber} given previous checkpoint number in store is ${
25
+ previousCheckpointNumber ?? 'undefined'
26
+ }`,
27
+ );
28
+ this.name = 'InitialCheckpointNumberNotSequentialError';
29
+ }
30
+ }
31
+
32
+ export class BlockCheckpointNumberNotSequentialError extends Error {
33
+ constructor(
34
+ blockNumber: BlockNumber,
35
+ blockCheckpointNumber: CheckpointNumber,
36
+ previous: CheckpointNumber | undefined,
37
+ ) {
38
+ super(
39
+ `Cannot insert new block ${blockNumber} for checkpoint ${blockCheckpointNumber} given previous checkpoint number is ${previous ?? 'undefined'}`,
40
+ );
41
+ this.name = 'BlockCheckpointNumberNotSequentialError';
42
+ }
43
+ }
44
+
45
+ export class CheckpointNumberNotSequentialError extends Error {
46
+ constructor(newCheckpointNumber: CheckpointNumber, previous: CheckpointNumber | undefined) {
47
+ super(
48
+ `Cannot insert new checkpoint ${newCheckpointNumber} given previous checkpoint number is ${previous ?? 'undefined'}`,
49
+ );
50
+ this.name = 'CheckpointNumberNotSequentialError';
51
+ }
52
+ }
53
+
54
+ export class BlockIndexNotSequentialError extends Error {
55
+ constructor(newBlockIndex: number, previousBlockIndex: number | undefined) {
56
+ super(
57
+ `Cannot insert new block at checkpoint index ${newBlockIndex} given previous block index is ${previousBlockIndex ?? 'undefined'}`,
58
+ );
59
+ this.name = 'BlockIndexNotSequentialError';
60
+ }
61
+ }
62
+
63
+ export class BlockArchiveNotConsistentError extends Error {
64
+ constructor(
65
+ newBlockNumber: number,
66
+ previousBlockNumber: number | undefined,
67
+ newBlockArchive: Fr,
68
+ previousBlockArchive: Fr,
69
+ ) {
70
+ super(
71
+ `Cannot insert new block number ${newBlockNumber} with archive ${newBlockArchive.toString()} previous block number is ${previousBlockNumber ?? 'undefined'}, previous archive is ${previousBlockArchive?.toString() ?? 'undefined'}`,
72
+ );
73
+ this.name = 'BlockArchiveNotConsistentError';
74
+ }
75
+ }
76
+
77
+ export class CheckpointNotFoundError extends Error {
78
+ constructor(checkpointNumber: number) {
79
+ super(`Failed to find expected checkpoint number ${checkpointNumber}`);
80
+ this.name = 'CheckpointNotFoundError';
81
+ }
82
+ }
83
+
84
+ export class BlockNotFoundError extends Error {
85
+ constructor(blockNumber: number) {
86
+ super(`Failed to find expected block number ${blockNumber}`);
87
+ this.name = 'BlockNotFoundError';
88
+ }
89
+ }
90
+
91
+ /** Thrown when a proposed block matches a block that was already checkpointed. This is expected for late proposals. */
92
+ export class BlockAlreadyCheckpointedError extends Error {
93
+ constructor(public readonly blockNumber: number) {
94
+ super(`Block ${blockNumber} has already been checkpointed with the same content`);
95
+ this.name = 'BlockAlreadyCheckpointedError';
96
+ }
97
+ }
98
+
99
+ /** Thrown when logs are added for a tag whose last stored log has a higher block number than the new log. */
100
+ export class OutOfOrderLogInsertionError extends Error {
101
+ constructor(
102
+ public readonly logType: 'private' | 'public',
103
+ public readonly tag: string,
104
+ public readonly lastBlockNumber: number,
105
+ public readonly newBlockNumber: number,
106
+ ) {
107
+ super(
108
+ `Out-of-order ${logType} log insertion for tag ${tag}: ` +
109
+ `last existing log is from block ${lastBlockNumber} but new log is from block ${newBlockNumber}`,
110
+ );
111
+ this.name = 'OutOfOrderLogInsertionError';
112
+ }
113
+ }
114
+
115
+ /** Thrown when L1 to L2 messages are requested for a checkpoint whose message tree hasn't been sealed yet. */
116
+ export class L1ToL2MessagesNotReadyError extends Error {
117
+ constructor(
118
+ public readonly checkpointNumber: number,
119
+ public readonly inboxTreeInProgress: bigint,
120
+ ) {
121
+ super(
122
+ `Cannot get L1 to L2 messages for checkpoint ${checkpointNumber}: ` +
123
+ `inbox tree in progress is ${inboxTreeInProgress}, messages not yet sealed`,
124
+ );
125
+ this.name = 'L1ToL2MessagesNotReadyError';
126
+ }
127
+ }
128
+
129
+ /** Thrown when a proposed checkpoint number is stale (already processed). */
130
+ export class ProposedCheckpointStaleError extends Error {
131
+ constructor(
132
+ public readonly proposedCheckpointNumber: number,
133
+ public readonly currentProposedNumber: number,
134
+ ) {
135
+ super(`Stale proposed checkpoint ${proposedCheckpointNumber}: current proposed is ${currentProposedNumber}`);
136
+ this.name = 'ProposedCheckpointStaleError';
137
+ }
138
+ }
139
+
140
+ /** Thrown when a proposed checkpoint number is not the expected latestTip + 1. */
141
+ export class ProposedCheckpointNotSequentialError extends Error {
142
+ constructor(
143
+ public readonly proposedCheckpointNumber: number,
144
+ public readonly latestTipNumber: number,
145
+ ) {
146
+ super(
147
+ `Proposed checkpoint ${proposedCheckpointNumber} is not sequential: expected ${latestTipNumber + 1} (latest tip + 1, where tip is highest of confirmed or pending)`,
148
+ );
149
+ this.name = 'ProposedCheckpointNotSequentialError';
150
+ }
151
+ }
152
+
153
+ /** Thrown when a proposed checkpoint or block L2 slot has already expired on L1. */
154
+ export class BlockOrCheckpointSlotExpiredError extends Error {
155
+ constructor(
156
+ public readonly slot: number,
157
+ public readonly nextSlotStart: bigint,
158
+ public readonly l1TimestampSynced: bigint | undefined,
159
+ ) {
160
+ super(
161
+ `Checkpoint or block for slot ${slot} is expired: L1 synced to ${l1TimestampSynced} which is past the next slot start ${nextSlotStart}. ` +
162
+ `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).`,
163
+ );
164
+ this.name = 'BlockOrCheckpointSlotExpiredError';
165
+ }
166
+ }
167
+
168
+ /** Thrown when attempting to promote a proposed checkpoint but no proposed checkpoint exists in the store. */
169
+ export class NoProposedCheckpointToPromoteError extends Error {
170
+ constructor() {
171
+ super('Cannot promote proposed checkpoint: no proposed checkpoint exists');
172
+ this.name = 'NoProposedCheckpointToPromoteError';
173
+ }
174
+ }
175
+
176
+ /** Thrown when the archive root of the proposed checkpoint does not match the expected one. */
177
+ export class ProposedCheckpointArchiveRootMismatchError extends Error {
178
+ constructor(
179
+ public readonly expectedArchiveRoot: Fr,
180
+ public readonly actualArchiveRoot: Fr,
181
+ ) {
182
+ super(
183
+ `Cannot promote proposed checkpoint: archive root mismatch (expected ${expectedArchiveRoot}, got ${actualArchiveRoot})`,
184
+ );
185
+ this.name = 'ProposedCheckpointArchiveRootMismatchError';
186
+ }
187
+ }
188
+
189
+ /** Thrown when the proposed checkpoint does not directly follow the latest confirmed checkpoint. */
190
+ export class ProposedCheckpointPromotionNotSequentialError extends Error {
191
+ constructor(
192
+ public readonly proposedCheckpointNumber: number,
193
+ public readonly latestCheckpointNumber: number,
194
+ ) {
195
+ super(
196
+ `Cannot promote proposed checkpoint: not sequential (latest ${latestCheckpointNumber}, proposed ${proposedCheckpointNumber})`,
197
+ );
198
+ this.name = 'ProposedCheckpointPromotionNotSequentialError';
199
+ }
200
+ }
201
+
202
+ /** Thrown when a proposed block conflicts with an already checkpointed block (different content). */
203
+ export class CannotOverwriteCheckpointedBlockError extends Error {
204
+ constructor(
205
+ public readonly blockNumber: number,
206
+ public readonly lastCheckpointedBlock: number,
207
+ ) {
208
+ super(
209
+ `Cannot add block ${blockNumber}: would overwrite checkpointed data (checkpointed up to block ${lastCheckpointedBlock})`,
210
+ );
211
+ this.name = 'CannotOverwriteCheckpointedBlockError';
212
+ }
213
+ }
package/src/factory.ts CHANGED
@@ -1,14 +1,31 @@
1
- import { createLogger } from '@aztec/foundation/log';
2
- import type { DataStoreConfig } from '@aztec/kv-store/config';
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';
6
+ import { BlockNumber } from '@aztec/foundation/branded-types';
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';
3
11
  import { createStore } from '@aztec/kv-store/lmdb-v2';
4
12
  import { protocolContractNames } from '@aztec/protocol-contracts';
5
13
  import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
6
14
  import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi';
7
- 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';
8
19
 
9
- import { Archiver, type ArchiverDeps } from './archiver/archiver.js';
10
- import type { ArchiverConfig } from './archiver/config.js';
11
- 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';
12
29
 
13
30
  export const ARCHIVER_STORE_NAME = 'archiver';
14
31
 
@@ -20,16 +37,15 @@ export async function createArchiverStore(
20
37
  ...userConfig,
21
38
  dataStoreMapSizeKb: userConfig.archiverStoreMapSizeKb ?? userConfig.dataStoreMapSizeKb,
22
39
  };
23
- 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);
24
41
  return new KVArchiverDataStore(store, config.maxLogs);
25
42
  }
26
43
 
27
44
  /**
28
45
  * Creates a local archiver.
29
46
  * @param config - The archiver configuration.
30
- * @param blobSinkClient - The blob sink client.
47
+ * @param deps - The archiver dependencies (blobClient, epochCache, dateProvider, telemetry).
31
48
  * @param opts - The options.
32
- * @param telemetry - The telemetry client.
33
49
  * @returns The local archiver.
34
50
  */
35
51
  export async function createArchiver(
@@ -39,18 +55,141 @@ export async function createArchiver(
39
55
  ): Promise<Archiver> {
40
56
  const archiverStore = await createArchiverStore(config);
41
57
  await registerProtocolContracts(archiverStore);
42
- 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
+ skipHistoricalLogsCheck: false,
125
+ },
126
+ mapArchiverConfig(config),
127
+ );
128
+
129
+ const epochCache = deps.epochCache ?? (await EpochCache.create(config.l1Contracts.rollupAddress, config, deps));
130
+ const telemetry = deps.telemetry ?? getTelemetryClient();
131
+ const instrumentation = await ArchiverInstrumentation.new(telemetry, () => archiverStore.estimateSize());
132
+
133
+ // Create the event emitter that will be shared by archiver and synchronizer
134
+ const events = new EventEmitter() as ArchiverEmitter;
135
+
136
+ // Create L2 tips cache shared by archiver and synchronizer
137
+ const l2TipsCache = new L2TipsCache(archiverStore.blockStore);
138
+
139
+ // Create the L1 synchronizer
140
+ const synchronizer = new ArchiverL1Synchronizer(
141
+ publicClient,
142
+ debugClient,
143
+ rollup,
144
+ inbox,
145
+ archiverStore,
146
+ archiverConfig,
147
+ deps.blobClient,
148
+ epochCache,
149
+ deps.dateProvider ?? new DateProvider(),
150
+ instrumentation,
151
+ l1Constants,
152
+ events,
153
+ instrumentation.tracer,
154
+ l2TipsCache,
155
+ undefined, // log (use default)
156
+ );
157
+
158
+ const archiver = new Archiver(
159
+ publicClient,
160
+ debugClient,
161
+ rollup,
162
+ { ...config.l1Contracts, slashingProposerAddress },
163
+ archiverStore,
164
+ archiverConfig,
165
+ deps.blobClient,
166
+ instrumentation,
167
+ l1Constants,
168
+ synchronizer,
169
+ events,
170
+ l2TipsCache,
171
+ );
172
+
173
+ await archiver.start(opts.blockUntilSync);
174
+ return archiver;
43
175
  }
44
176
 
45
- async function registerProtocolContracts(store: KVArchiverDataStore) {
177
+ /** Registers protocol contracts in the archiver store. Idempotent — skips contracts that already exist (e.g. on node restart). */
178
+ export async function registerProtocolContracts(store: KVArchiverDataStore) {
46
179
  const blockNumber = 0;
47
180
  for (const name of protocolContractNames) {
48
181
  const provider = new BundledProtocolContractsProvider();
49
182
  const contract = await provider.getProtocolContractArtifact(name);
50
- const contractClassPublic: ContractClassPublic = {
183
+
184
+ // Skip if already registered (happens on node restart with a persisted store).
185
+ if (await store.getContractClass(contract.contractClass.id)) {
186
+ continue;
187
+ }
188
+
189
+ const publicBytecodeCommitment = await computePublicBytecodeCommitment(contract.contractClass.packedBytecode);
190
+ const contractClassPublic: ContractClassPublicWithCommitment = {
51
191
  ...contract.contractClass,
52
- privateFunctions: [],
53
- utilityFunctions: [],
192
+ publicBytecodeCommitment,
54
193
  };
55
194
 
56
195
  const publicFunctionSignatures = contract.artifact.functions
@@ -58,8 +197,7 @@ async function registerProtocolContracts(store: KVArchiverDataStore) {
58
197
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
59
198
 
60
199
  await store.registerContractFunctionSignatures(publicFunctionSignatures);
61
- const bytecodeCommitment = await computePublicBytecodeCommitment(contractClassPublic.packedBytecode);
62
- await store.addContractClasses([contractClassPublic], [bytecodeCommitment], blockNumber);
63
- await store.addContractInstances([contract.instance], blockNumber);
200
+ await store.addContractClasses([contractClassPublic], BlockNumber(blockNumber));
201
+ await store.addContractInstances([contract.instance], BlockNumber(blockNumber));
64
202
  }
65
203
  }
package/src/index.ts CHANGED
@@ -1,5 +1,14 @@
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 { retrieveL2ProofVerifiedEvents } from './archiver/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 { retrieveL2ProofVerifiedEvents } from './l1/data_retrieval.js';
14
+ export { CalldataRetriever } from './l1/calldata_retriever.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.