@aztec/archiver 0.0.1-commit.fce3e4f → 0.0.1-commit.fffb133c

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 (201) hide show
  1. package/README.md +156 -22
  2. package/dest/archiver.d.ts +135 -0
  3. package/dest/archiver.d.ts.map +1 -0
  4. package/dest/archiver.js +768 -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} +21 -5
  8. package/dest/errors.d.ts +41 -0
  9. package/dest/errors.d.ts.map +1 -0
  10. package/dest/errors.js +62 -0
  11. package/dest/factory.d.ts +7 -7
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +90 -10
  14. package/dest/index.d.ts +10 -4
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +8 -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 +149 -0
  23. package/dest/l1/calldata_retriever.d.ts +112 -0
  24. package/dest/l1/calldata_retriever.d.ts.map +1 -0
  25. package/dest/l1/calldata_retriever.js +471 -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}/data_retrieval.js +76 -150
  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 +157 -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_trace.d.ts +29 -0
  42. package/dest/l1/validate_trace.d.ts.map +1 -0
  43. package/dest/l1/validate_trace.js +150 -0
  44. package/dest/modules/data_source_base.d.ts +84 -0
  45. package/dest/modules/data_source_base.d.ts.map +1 -0
  46. package/dest/modules/data_source_base.js +260 -0
  47. package/dest/modules/data_store_updater.d.ts +73 -0
  48. package/dest/modules/data_store_updater.d.ts.map +1 -0
  49. package/dest/modules/data_store_updater.js +302 -0
  50. package/dest/modules/instrumentation.d.ts +37 -0
  51. package/dest/modules/instrumentation.d.ts.map +1 -0
  52. package/dest/{archiver → modules}/instrumentation.js +22 -59
  53. package/dest/modules/l1_synchronizer.d.ts +75 -0
  54. package/dest/modules/l1_synchronizer.d.ts.map +1 -0
  55. package/dest/modules/l1_synchronizer.js +1113 -0
  56. package/dest/modules/validation.d.ts +17 -0
  57. package/dest/modules/validation.d.ts.map +1 -0
  58. package/dest/{archiver → modules}/validation.js +7 -1
  59. package/dest/store/block_store.d.ts +192 -0
  60. package/dest/store/block_store.d.ts.map +1 -0
  61. package/dest/store/block_store.js +721 -0
  62. package/dest/store/contract_class_store.d.ts +18 -0
  63. package/dest/store/contract_class_store.d.ts.map +1 -0
  64. package/dest/{archiver/kv_archiver_store → store}/contract_class_store.js +2 -2
  65. package/dest/store/contract_instance_store.d.ts +24 -0
  66. package/dest/store/contract_instance_store.d.ts.map +1 -0
  67. package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +1 -1
  68. package/dest/store/kv_archiver_store.d.ts +340 -0
  69. package/dest/store/kv_archiver_store.d.ts.map +1 -0
  70. package/dest/store/kv_archiver_store.js +447 -0
  71. package/dest/store/log_store.d.ts +54 -0
  72. package/dest/store/log_store.d.ts.map +1 -0
  73. package/dest/store/log_store.js +436 -0
  74. package/dest/store/message_store.d.ts +40 -0
  75. package/dest/store/message_store.d.ts.map +1 -0
  76. package/dest/{archiver/kv_archiver_store → store}/message_store.js +15 -14
  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}/inbox_message.js +6 -5
  82. package/dest/structs/published.d.ts +2 -0
  83. package/dest/structs/published.d.ts.map +1 -0
  84. package/dest/test/fake_l1_state.d.ts +190 -0
  85. package/dest/test/fake_l1_state.d.ts.map +1 -0
  86. package/dest/test/fake_l1_state.js +383 -0
  87. package/dest/test/index.d.ts +2 -1
  88. package/dest/test/index.d.ts.map +1 -1
  89. package/dest/test/index.js +1 -0
  90. package/dest/test/mock_archiver.d.ts +16 -8
  91. package/dest/test/mock_archiver.d.ts.map +1 -1
  92. package/dest/test/mock_archiver.js +18 -14
  93. package/dest/test/mock_l1_to_l2_message_source.d.ts +7 -6
  94. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  95. package/dest/test/mock_l1_to_l2_message_source.js +21 -11
  96. package/dest/test/mock_l2_block_source.d.ts +34 -16
  97. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  98. package/dest/test/mock_l2_block_source.js +179 -59
  99. package/dest/test/mock_structs.d.ts +78 -3
  100. package/dest/test/mock_structs.d.ts.map +1 -1
  101. package/dest/test/mock_structs.js +141 -9
  102. package/package.json +19 -20
  103. package/src/archiver.ts +523 -0
  104. package/src/{archiver/config.ts → config.ts} +28 -12
  105. package/src/errors.ts +102 -0
  106. package/src/factory.ts +125 -10
  107. package/src/index.ts +10 -3
  108. package/src/interfaces.ts +9 -0
  109. package/src/l1/README.md +98 -0
  110. package/src/l1/bin/retrieve-calldata.ts +187 -0
  111. package/src/l1/calldata_retriever.ts +641 -0
  112. package/src/{archiver → l1}/data_retrieval.ts +142 -223
  113. package/src/l1/debug_tx.ts +99 -0
  114. package/src/l1/spire_proposer.ts +160 -0
  115. package/src/l1/trace_tx.ts +128 -0
  116. package/src/l1/types.ts +13 -0
  117. package/src/l1/validate_trace.ts +211 -0
  118. package/src/modules/data_source_base.ts +367 -0
  119. package/src/modules/data_store_updater.ts +423 -0
  120. package/src/{archiver → modules}/instrumentation.ts +26 -61
  121. package/src/modules/l1_synchronizer.ts +931 -0
  122. package/src/{archiver → modules}/validation.ts +11 -6
  123. package/src/store/block_store.ts +966 -0
  124. package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +2 -2
  125. package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +2 -2
  126. package/src/store/kv_archiver_store.ts +639 -0
  127. package/src/store/log_store.ts +575 -0
  128. package/src/{archiver/kv_archiver_store → store}/message_store.ts +21 -18
  129. package/src/{archiver/structs → structs}/inbox_message.ts +8 -8
  130. package/src/{archiver/structs → structs}/published.ts +0 -1
  131. package/src/test/fake_l1_state.ts +599 -0
  132. package/src/test/fixtures/debug_traceTransaction-multicall3.json +88 -0
  133. package/src/test/fixtures/debug_traceTransaction-multiplePropose.json +153 -0
  134. package/src/test/fixtures/debug_traceTransaction-proxied.json +122 -0
  135. package/src/test/fixtures/trace_transaction-multicall3.json +65 -0
  136. package/src/test/fixtures/trace_transaction-multiplePropose.json +319 -0
  137. package/src/test/fixtures/trace_transaction-proxied.json +128 -0
  138. package/src/test/fixtures/trace_transaction-randomRevert.json +216 -0
  139. package/src/test/index.ts +1 -0
  140. package/src/test/mock_archiver.ts +22 -16
  141. package/src/test/mock_l1_to_l2_message_source.ts +18 -11
  142. package/src/test/mock_l2_block_source.ts +195 -69
  143. package/src/test/mock_structs.ts +256 -10
  144. package/dest/archiver/archiver.d.ts +0 -287
  145. package/dest/archiver/archiver.d.ts.map +0 -1
  146. package/dest/archiver/archiver.js +0 -1408
  147. package/dest/archiver/archiver_store.d.ts +0 -255
  148. package/dest/archiver/archiver_store.d.ts.map +0 -1
  149. package/dest/archiver/archiver_store.js +0 -4
  150. package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
  151. package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
  152. package/dest/archiver/archiver_store_test_suite.js +0 -1289
  153. package/dest/archiver/config.d.ts +0 -21
  154. package/dest/archiver/config.d.ts.map +0 -1
  155. package/dest/archiver/data_retrieval.d.ts +0 -79
  156. package/dest/archiver/data_retrieval.d.ts.map +0 -1
  157. package/dest/archiver/errors.d.ts +0 -12
  158. package/dest/archiver/errors.d.ts.map +0 -1
  159. package/dest/archiver/errors.js +0 -17
  160. package/dest/archiver/index.d.ts +0 -7
  161. package/dest/archiver/index.d.ts.map +0 -1
  162. package/dest/archiver/index.js +0 -4
  163. package/dest/archiver/instrumentation.d.ts +0 -35
  164. package/dest/archiver/instrumentation.d.ts.map +0 -1
  165. package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -124
  166. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
  167. package/dest/archiver/kv_archiver_store/block_store.js +0 -370
  168. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
  169. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
  170. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
  171. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
  172. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -168
  173. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
  174. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -296
  175. package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -49
  176. package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
  177. package/dest/archiver/kv_archiver_store/log_store.js +0 -336
  178. package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -39
  179. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
  180. package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
  181. package/dest/archiver/structs/inbox_message.d.ts +0 -15
  182. package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
  183. package/dest/archiver/structs/published.d.ts +0 -3
  184. package/dest/archiver/structs/published.d.ts.map +0 -1
  185. package/dest/archiver/validation.d.ts +0 -17
  186. package/dest/archiver/validation.d.ts.map +0 -1
  187. package/dest/rpc/index.d.ts +0 -9
  188. package/dest/rpc/index.d.ts.map +0 -1
  189. package/dest/rpc/index.js +0 -15
  190. package/src/archiver/archiver.ts +0 -1858
  191. package/src/archiver/archiver_store.ts +0 -305
  192. package/src/archiver/archiver_store_test_suite.ts +0 -1264
  193. package/src/archiver/errors.ts +0 -26
  194. package/src/archiver/index.ts +0 -6
  195. package/src/archiver/kv_archiver_store/block_store.ts +0 -481
  196. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -422
  197. package/src/archiver/kv_archiver_store/log_store.ts +0 -406
  198. package/src/rpc/index.ts +0 -16
  199. /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
  200. /package/dest/{archiver/structs → structs}/published.js +0 -0
  201. /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
package/src/errors.ts ADDED
@@ -0,0 +1,102 @@
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 InitialBlockNumberNotSequentialError extends Error {
10
+ constructor(
11
+ public readonly newBlockNumber: number,
12
+ public readonly previousBlockNumber: number | undefined,
13
+ ) {
14
+ super(
15
+ `Cannot insert new block ${newBlockNumber} given previous block number in store is ${
16
+ previousBlockNumber ?? 'undefined'
17
+ }`,
18
+ );
19
+ }
20
+ }
21
+
22
+ export class BlockNumberNotSequentialError extends Error {
23
+ constructor(newBlockNumber: number, previous: number | undefined) {
24
+ super(
25
+ `Cannot insert new block ${newBlockNumber} given previous block number in batch is ${previous ?? 'undefined'}`,
26
+ );
27
+ }
28
+ }
29
+
30
+ export class InitialCheckpointNumberNotSequentialError extends Error {
31
+ constructor(
32
+ public readonly newCheckpointNumber: number,
33
+ public readonly previousCheckpointNumber: number | undefined,
34
+ ) {
35
+ super(
36
+ `Cannot insert new checkpoint ${newCheckpointNumber} given previous checkpoint number in store is ${
37
+ previousCheckpointNumber ?? 'undefined'
38
+ }`,
39
+ );
40
+ }
41
+ }
42
+
43
+ export class CheckpointNumberNotSequentialError extends Error {
44
+ constructor(newCheckpointNumber: number, previous: number | undefined) {
45
+ super(
46
+ `Cannot insert new checkpoint ${newCheckpointNumber} given previous checkpoint number in batch is ${previous ?? 'undefined'}`,
47
+ );
48
+ }
49
+ }
50
+
51
+ export class CheckpointNumberNotConsistentError extends Error {
52
+ constructor(newCheckpointNumber: number, previous: number | undefined) {
53
+ super(
54
+ `Cannot insert block for new checkpoint ${newCheckpointNumber} given previous block was checkpoint ${previous ?? 'undefined'}`,
55
+ );
56
+ }
57
+ }
58
+
59
+ export class BlockIndexNotSequentialError extends Error {
60
+ constructor(newBlockIndex: number, previousBlockIndex: number | undefined) {
61
+ super(
62
+ `Cannot insert new block at checkpoint index ${newBlockIndex} given previous block index is ${previousBlockIndex ?? 'undefined'}`,
63
+ );
64
+ }
65
+ }
66
+
67
+ export class BlockArchiveNotConsistentError extends Error {
68
+ constructor(
69
+ newBlockNumber: number,
70
+ previousBlockNumber: number | undefined,
71
+ newBlockArchive: Fr,
72
+ previousBlockArchive: Fr,
73
+ ) {
74
+ super(
75
+ `Cannot insert new block number ${newBlockNumber} with archive ${newBlockArchive.toString()} previous block number is ${previousBlockNumber ?? 'undefined'}, previous archive is ${previousBlockArchive?.toString() ?? 'undefined'}`,
76
+ );
77
+ }
78
+ }
79
+
80
+ export class CheckpointNotFoundError extends Error {
81
+ constructor(checkpointNumber: number) {
82
+ super(`Failed to find expected checkpoint number ${checkpointNumber}`);
83
+ }
84
+ }
85
+
86
+ export class BlockNotFoundError extends Error {
87
+ constructor(blockNumber: number) {
88
+ super(`Failed to find expected block number ${blockNumber}`);
89
+ }
90
+ }
91
+
92
+ export class CannotOverwriteCheckpointedBlockError extends Error {
93
+ constructor(
94
+ public readonly blockNumber: number,
95
+ public readonly lastCheckpointedBlock: number,
96
+ ) {
97
+ super(
98
+ `Cannot add block ${blockNumber}: would overwrite checkpointed data (checkpointed up to block ${lastCheckpointedBlock})`,
99
+ );
100
+ this.name = 'CannotOverwriteCheckpointedBlockError';
101
+ }
102
+ }
package/src/factory.ts CHANGED
@@ -1,35 +1,52 @@
1
+ import { EpochCache } from '@aztec/epoch-cache';
2
+ import { createEthereumChain } from '@aztec/ethereum/chain';
3
+ import { InboxContract, RollupContract } from '@aztec/ethereum/contracts';
4
+ import type { ViemPublicDebugClient } from '@aztec/ethereum/types';
5
+ import { BlockNumber } from '@aztec/foundation/branded-types';
6
+ import { Buffer32 } from '@aztec/foundation/buffer';
7
+ import { merge } from '@aztec/foundation/collection';
8
+ import { Fr } from '@aztec/foundation/curves/bn254';
1
9
  import { createLogger } from '@aztec/foundation/log';
10
+ import { DateProvider } from '@aztec/foundation/timer';
2
11
  import type { DataStoreConfig } from '@aztec/kv-store/config';
3
12
  import { createStore } from '@aztec/kv-store/lmdb-v2';
4
13
  import { protocolContractNames } from '@aztec/protocol-contracts';
5
14
  import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
6
15
  import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi';
16
+ import type { ArchiverEmitter } from '@aztec/stdlib/block';
7
17
  import { type ContractClassPublic, computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
18
+ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
19
+ import { getTelemetryClient } from '@aztec/telemetry-client';
8
20
 
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';
21
+ import { EventEmitter } from 'events';
22
+ import { createPublicClient, fallback, http } from 'viem';
23
+
24
+ import { Archiver, type ArchiverDeps } from './archiver.js';
25
+ import { type ArchiverConfig, mapArchiverConfig } from './config.js';
26
+ import { ArchiverInstrumentation } from './modules/instrumentation.js';
27
+ import { ArchiverL1Synchronizer } from './modules/l1_synchronizer.js';
28
+ import { ARCHIVER_DB_VERSION, KVArchiverDataStore } from './store/kv_archiver_store.js';
12
29
 
13
30
  export const ARCHIVER_STORE_NAME = 'archiver';
14
31
 
15
32
  /** Creates an archiver store. */
16
33
  export async function createArchiverStore(
17
34
  userConfig: Pick<ArchiverConfig, 'archiverStoreMapSizeKb' | 'maxLogs'> & DataStoreConfig,
35
+ l1Constants: Pick<L1RollupConstants, 'epochDuration'>,
18
36
  ) {
19
37
  const config = {
20
38
  ...userConfig,
21
39
  dataStoreMapSizeKb: userConfig.archiverStoreMapSizeKb ?? userConfig.dataStoreMapSizeKb,
22
40
  };
23
41
  const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config, createLogger('archiver:lmdb'));
24
- return new KVArchiverDataStore(store, config.maxLogs);
42
+ return new KVArchiverDataStore(store, config.maxLogs, l1Constants);
25
43
  }
26
44
 
27
45
  /**
28
46
  * Creates a local archiver.
29
47
  * @param config - The archiver configuration.
30
- * @param blobSinkClient - The blob sink client.
48
+ * @param deps - The archiver dependencies (blobClient, epochCache, dateProvider, telemetry).
31
49
  * @param opts - The options.
32
- * @param telemetry - The telemetry client.
33
50
  * @returns The local archiver.
34
51
  */
35
52
  export async function createArchiver(
@@ -37,9 +54,107 @@ export async function createArchiver(
37
54
  deps: ArchiverDeps,
38
55
  opts: { blockUntilSync: boolean } = { blockUntilSync: true },
39
56
  ): Promise<Archiver> {
40
- const archiverStore = await createArchiverStore(config);
57
+ const archiverStore = await createArchiverStore(config, { epochDuration: config.aztecEpochDuration });
41
58
  await registerProtocolContracts(archiverStore);
42
- return Archiver.createAndSync(config, archiverStore, deps, opts.blockUntilSync);
59
+
60
+ // Create Ethereum clients
61
+ const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
62
+ const publicClient = createPublicClient({
63
+ chain: chain.chainInfo,
64
+ transport: fallback(config.l1RpcUrls.map(url => http(url, { batch: false }))),
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: fallback(debugRpcUrls.map(url => http(url, { batch: false }))),
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 [l1StartBlock, l1GenesisTime, proofSubmissionEpochs, genesisArchiveRoot, slashingProposerAddress] =
82
+ await Promise.all([
83
+ rollup.getL1StartBlock(),
84
+ rollup.getL1GenesisTime(),
85
+ rollup.getProofSubmissionEpochs(),
86
+ rollup.getGenesisArchiveTreeRoot(),
87
+ rollup.getSlashingProposerAddress(),
88
+ ] as const);
89
+
90
+ const l1StartBlockHash = await publicClient
91
+ .getBlock({ blockNumber: l1StartBlock, includeTransactions: false })
92
+ .then(block => Buffer32.fromString(block.hash));
93
+
94
+ const { aztecEpochDuration: epochDuration, aztecSlotDuration: slotDuration, ethereumSlotDuration } = config;
95
+
96
+ const l1Constants = {
97
+ l1StartBlockHash,
98
+ l1StartBlock,
99
+ l1GenesisTime,
100
+ epochDuration,
101
+ slotDuration,
102
+ ethereumSlotDuration,
103
+ proofSubmissionEpochs: Number(proofSubmissionEpochs),
104
+ genesisArchiveRoot: Fr.fromString(genesisArchiveRoot.toString()),
105
+ };
106
+
107
+ const archiverConfig = merge(
108
+ {
109
+ pollingIntervalMs: 10_000,
110
+ batchSize: 100,
111
+ maxAllowedEthClientDriftSeconds: 300,
112
+ ethereumAllowNoDebugHosts: false,
113
+ },
114
+ mapArchiverConfig(config),
115
+ );
116
+
117
+ const epochCache = deps.epochCache ?? (await EpochCache.create(config.l1Contracts.rollupAddress, config, deps));
118
+ const telemetry = deps.telemetry ?? getTelemetryClient();
119
+ const instrumentation = await ArchiverInstrumentation.new(telemetry, () => archiverStore.estimateSize());
120
+
121
+ // Create the event emitter that will be shared by archiver and synchronizer
122
+ const events = new EventEmitter() as ArchiverEmitter;
123
+
124
+ // Create the L1 synchronizer
125
+ const synchronizer = new ArchiverL1Synchronizer(
126
+ publicClient,
127
+ debugClient,
128
+ rollup,
129
+ inbox,
130
+ { ...config.l1Contracts, slashingProposerAddress },
131
+ archiverStore,
132
+ archiverConfig,
133
+ deps.blobClient,
134
+ epochCache,
135
+ deps.dateProvider ?? new DateProvider(),
136
+ instrumentation,
137
+ l1Constants,
138
+ events,
139
+ instrumentation.tracer,
140
+ );
141
+
142
+ const archiver = new Archiver(
143
+ publicClient,
144
+ debugClient,
145
+ rollup,
146
+ { ...config.l1Contracts, slashingProposerAddress },
147
+ archiverStore,
148
+ archiverConfig,
149
+ deps.blobClient,
150
+ instrumentation,
151
+ l1Constants,
152
+ synchronizer,
153
+ events,
154
+ );
155
+
156
+ await archiver.start(opts.blockUntilSync);
157
+ return archiver;
43
158
  }
44
159
 
45
160
  async function registerProtocolContracts(store: KVArchiverDataStore) {
@@ -59,7 +174,7 @@ async function registerProtocolContracts(store: KVArchiverDataStore) {
59
174
 
60
175
  await store.registerContractFunctionSignatures(publicFunctionSignatures);
61
176
  const bytecodeCommitment = await computePublicBytecodeCommitment(contractClassPublic.packedBytecode);
62
- await store.addContractClasses([contractClassPublic], [bytecodeCommitment], blockNumber);
63
- await store.addContractInstances([contract.instance], blockNumber);
177
+ await store.addContractClasses([contractClassPublic], [bytecodeCommitment], BlockNumber(blockNumber));
178
+ await store.addContractInstances([contract.instance], BlockNumber(blockNumber));
64
179
  }
65
180
  }
package/src/index.ts CHANGED
@@ -1,5 +1,12 @@
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
+
12
+ 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,98 @@
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. A typical transaction includes:
9
+
10
+ 1. Attestation invalidations (if needed): `invalidateBadAttestation`, `invalidateInsufficientAttestations`
11
+ 2. Block proposal: `propose` (exactly one per transaction to the rollup contract)
12
+ 3. Governance and slashing (if needed): votes, payload creation/execution
13
+
14
+ The archiver needs to extract the `propose` calldata from these bundled transactions to reconstruct
15
+ L2 blocks. This class needs to handle scenarios where the transaction was submitted via multicall3,
16
+ as well as alternative ways for submitting the `propose` call that other clients might use.
17
+
18
+ ### Multicall3 Validation and Decoding
19
+
20
+ First attempt to decode the transaction as a multicall3 `aggregate3` call with validation:
21
+
22
+ - Check if transaction is to multicall3 address (`0xcA11bde05977b3631167028862bE2a173976CA11`)
23
+ - Decode as `aggregate3(Call3[] calldata calls)`
24
+ - Allow calls to known addresses and methods (rollup, governance, slashing contracts, etc.)
25
+ - Find the single `propose` call to the rollup contract
26
+ - Verify exactly one `propose` call exists
27
+ - Extract and return the propose calldata
28
+
29
+ This step handles the common case efficiently without requiring expensive trace or debug RPC calls.
30
+ Any validation failure triggers fallback to the next step.
31
+
32
+ ### Direct Propose Call
33
+
34
+ Second attempt to decode the transaction as a direct `propose` call to the rollup contract:
35
+
36
+ - Check if transaction is to the rollup address
37
+ - Decode as `propose` function call
38
+ - Verify the function is indeed `propose`
39
+ - Return the transaction input as the propose calldata
40
+
41
+ This handles scenarios where clients submit transactions directly to the rollup contract without
42
+ using multicall3 for bundling. Any validation failure triggers fallback to the next step.
43
+
44
+ ### Spire Proposer Call
45
+
46
+ Given existing attempts to route the call via the Spire proposer, we also check if the tx is `to` the
47
+ proposer known address, and if so, we try decoding it as either a multicall3 or a direct call to the
48
+ rollup contract.
49
+
50
+ Similar as with the multicall3 check, we check that there are no other calls in the Spire proposer, so
51
+ we are absolutely sure that the only call is the successful one to the rollup. Any extraneous call would
52
+ imply an unexpected path to calling `propose` in the rollup contract, and since we cannot verify if the
53
+ calldata arguments we extracted are the correct ones (see the section below), we cannot know for sure which
54
+ one is the call that succeeded, so we don't know which calldata to process.
55
+
56
+ Furthermore, since the Spire proposer is upgradeable, we check if the implementation has not changed in
57
+ order to decode. As usual, any validation failure triggers fallback to the next step.
58
+
59
+ ### Verifying Multicall3 Arguments
60
+
61
+ **This is NOT implemented for simplicity's sake**
62
+
63
+ If the checks above don't hold, such as when there are multiple calls to `propose`, then we cannot
64
+ reliably extract the `propose` calldata from the multicall3 arguments alone. We can try a best-effort
65
+ where we try all `propose` calls we see and validate them against on-chain data. Note that we can use these
66
+ same strategies if we were to obtain the calldata from another source.
67
+
68
+ #### TempBlockLog Verification
69
+
70
+ Read the stored `TempBlockLog` for the L2 block number from L1 and verify it matches our decoded header hash,
71
+ since the `TempBlockLog` stores the hash of the proposed block header, the payload commitment, and the attestations.
72
+
73
+ However, `TempBlockLog` is only stored temporarily and deleted after proven, so this method only works for recent
74
+ blocks, not for historical data syncing.
75
+
76
+ #### Archive Verification
77
+
78
+ Verify that the archive root in the decoded propose is correct with regard to the block header. This requires
79
+ hashing the block header we have retrieved, inserting it into the archive tree, and checking the resulting root
80
+ against the one we got from L1.
81
+
82
+ However, this requires that the archive keeps a reference to world-state, which is not the case in the current
83
+ system.
84
+
85
+ #### Emit Commitments in Rollup Contract
86
+
87
+ Modify rollup contract to emit commitments to the block header in the `L2BlockProposed` event, allowing us to easily
88
+ verify the calldata we obtained vs the emitted event.
89
+
90
+ However, modifying the rollup contract is out of scope for this change. But we can implement this approach in `v2`.
91
+
92
+ ### Debug and Trace Transaction Fallback
93
+
94
+ Last, we use L1 node's trace/debug RPC methods to definitively identify the one successful `propose` call within the tx.
95
+ We can then extract the exact calldata that hit the `propose` function in the rollup contract.
96
+
97
+ This approach requires access to a debug-enabled L1 node, which may be more resource-intensive, so we only
98
+ use it as a fallback when the first step fails, which should be rare in practice.
@@ -0,0 +1,187 @@
1
+ #!/usr/bin/env node
2
+ import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
3
+ import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
4
+ import { EthAddress } from '@aztec/foundation/eth-address';
5
+ import { createLogger } from '@aztec/foundation/log';
6
+
7
+ import { type Hex, createPublicClient, http } from 'viem';
8
+ import { mainnet } from 'viem/chains';
9
+
10
+ import { CalldataRetriever } from '../calldata_retriever.js';
11
+
12
+ const logger = createLogger('archiver:calldata-test');
13
+
14
+ interface ScriptArgs {
15
+ rollupAddress: EthAddress;
16
+ txHash: Hex;
17
+ rpcUrl: string;
18
+ targetCommitteeSize: number;
19
+ }
20
+
21
+ function parseArgs(): ScriptArgs {
22
+ const args = process.argv.slice(2);
23
+
24
+ if (args.length < 2) {
25
+ // eslint-disable-next-line no-console
26
+ console.error('Usage: node index.js <rollup-address> <tx-hash> [target-committee-size]');
27
+ // eslint-disable-next-line no-console
28
+ console.error('');
29
+ // eslint-disable-next-line no-console
30
+ console.error('Environment variables:');
31
+ // eslint-disable-next-line no-console
32
+ console.error(' ETHEREUM_HOST or RPC_URL - Ethereum RPC endpoint');
33
+ // eslint-disable-next-line no-console
34
+ console.error('');
35
+ // eslint-disable-next-line no-console
36
+ console.error('Example:');
37
+ // eslint-disable-next-line no-console
38
+ console.error(' RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR-API-KEY \\');
39
+ // eslint-disable-next-line no-console
40
+ console.error(' node index.js 0x1234... 0xabcd... 32');
41
+ process.exit(1);
42
+ }
43
+
44
+ const rollupAddress = EthAddress.fromString(args[0]);
45
+ const txHash = args[1] as Hex;
46
+ const targetCommitteeSize = args[2] ? parseInt(args[2], 10) : 24;
47
+
48
+ const rpcUrl = process.env.ETHEREUM_HOST || process.env.RPC_URL;
49
+ if (!rpcUrl) {
50
+ // eslint-disable-next-line no-console
51
+ console.error('Error: ETHEREUM_HOST or RPC_URL environment variable must be set');
52
+ process.exit(1);
53
+ }
54
+
55
+ if (targetCommitteeSize <= 0 || targetCommitteeSize > 256) {
56
+ // eslint-disable-next-line no-console
57
+ console.error('Error: target-committee-size must be between 1 and 256');
58
+ process.exit(1);
59
+ }
60
+
61
+ return { rollupAddress, txHash, rpcUrl, targetCommitteeSize };
62
+ }
63
+
64
+ async function main() {
65
+ const { rollupAddress, txHash, rpcUrl, targetCommitteeSize } = parseArgs();
66
+
67
+ logger.info('Calldata Retriever Test Script');
68
+ logger.info('===============================');
69
+ logger.info(`Rollup Address: ${rollupAddress.toString()}`);
70
+ logger.info(`Transaction Hash: ${txHash}`);
71
+ logger.info(`RPC URL: ${rpcUrl}`);
72
+ logger.info(`Target Committee Size: ${targetCommitteeSize}`);
73
+ logger.info('');
74
+
75
+ try {
76
+ // Create viem public client
77
+ const publicClient = createPublicClient({
78
+ chain: mainnet,
79
+ transport: http(rpcUrl, { batch: false }),
80
+ });
81
+
82
+ logger.info('Fetching transaction...');
83
+ const tx = await publicClient.getTransaction({ hash: txHash });
84
+
85
+ if (!tx) {
86
+ throw new Error(`Transaction ${txHash} not found`);
87
+ }
88
+
89
+ logger.info(`Transaction found in block ${tx.blockNumber}`);
90
+
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
+ // Create CalldataRetriever
100
+ const retriever = new CalldataRetriever(
101
+ publicClient as unknown as ViemPublicClient,
102
+ publicClient as unknown as ViemPublicDebugClient,
103
+ targetCommitteeSize,
104
+ undefined,
105
+ logger,
106
+ {
107
+ rollupAddress,
108
+ governanceProposerAddress,
109
+ slashingProposerAddress,
110
+ slashFactoryAddress,
111
+ },
112
+ );
113
+
114
+ // Extract L2 block number from transaction logs
115
+ logger.info('Decoding transaction to extract L2 block number...');
116
+ const receipt = await publicClient.getTransactionReceipt({ hash: txHash });
117
+ const l2BlockProposedEvent = receipt.logs.find(log => {
118
+ try {
119
+ // Try to match the L2BlockProposed event
120
+ return (
121
+ log.address.toLowerCase() === rollupAddress.toString().toLowerCase() &&
122
+ log.topics[0] === '0x2f1d0e696fa5186494a2f2f89a0e0bcbb15d607f6c5eac4637e07e1e5e7d3c00' // L2BlockProposed event signature
123
+ );
124
+ } catch {
125
+ return false;
126
+ }
127
+ });
128
+
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);
138
+ }
139
+
140
+ logger.info('');
141
+ logger.info('Retrieving block header from rollup transaction...');
142
+ logger.info('');
143
+
144
+ // For this script, we don't have blob hashes or expected hashes, so pass empty arrays/objects
145
+ const result = await retriever.getCheckpointFromRollupTx(
146
+ txHash,
147
+ [],
148
+ CheckpointNumber.fromBlockNumber(BlockNumber(l2BlockNumber)),
149
+ {},
150
+ );
151
+
152
+ logger.info(' Successfully retrieved block header!');
153
+ logger.info('');
154
+ logger.info('Block Header Details:');
155
+ logger.info('====================');
156
+ logger.info(`Checkpoint Number: ${result.checkpointNumber}`);
157
+ logger.info(`Block Hash: ${result.blockHash}`);
158
+ logger.info(`Archive Root: ${result.archiveRoot.toString()}`);
159
+ logger.info('');
160
+ logger.info('Header:');
161
+ logger.info(` Slot Number: ${result.header.slotNumber.toString()}`);
162
+ logger.info(` Timestamp: ${result.header.timestamp.toString()}`);
163
+ logger.info(` Coinbase: ${result.header.coinbase.toString()}`);
164
+ logger.info(` Fee Recipient: ${result.header.feeRecipient.toString()}`);
165
+ logger.info(` Total Mana Used: ${result.header.totalManaUsed.toString()}`);
166
+ logger.info('');
167
+ logger.info('Attestations:');
168
+ logger.info(` Count: ${result.attestations.length}`);
169
+ logger.info(` Non-empty attestations: ${result.attestations.filter((a: any) => !a.signature.isEmpty()).length}`);
170
+
171
+ process.exit(0);
172
+ } catch (error) {
173
+ logger.error('Error retrieving block header:');
174
+ logger.error(error instanceof Error ? error.message : String(error));
175
+
176
+ if (error instanceof Error && error.stack) {
177
+ logger.debug(error.stack);
178
+ }
179
+
180
+ process.exit(1);
181
+ }
182
+ }
183
+
184
+ // Only run if this is the main module
185
+ if (import.meta.url === `file://${process.argv[1]}`) {
186
+ void main();
187
+ }