@aztec/archiver 0.0.1-commit.fcb71a6 → 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 (192) 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/{archiver/config.d.ts → config.d.ts} +9 -1
  6. package/dest/config.d.ts.map +1 -0
  7. package/dest/{archiver/config.js → config.js} +11 -2
  8. package/dest/errors.d.ts +41 -0
  9. package/dest/errors.d.ts.map +1 -0
  10. package/dest/{archiver/errors.js → errors.js} +8 -0
  11. package/dest/factory.d.ts +7 -7
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +87 -8
  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/{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 +2 -2
  23. package/dest/{archiver/l1 → l1}/calldata_retriever.d.ts +3 -3
  24. package/dest/l1/calldata_retriever.d.ts.map +1 -0
  25. package/dest/{archiver/l1 → l1}/calldata_retriever.js +2 -2
  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 +35 -54
  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 +1 -1
  32. package/dest/l1/spire_proposer.d.ts.map +1 -0
  33. package/dest/{archiver/l1 → l1}/trace_tx.d.ts +1 -1
  34. package/dest/l1/trace_tx.d.ts.map +1 -0
  35. package/dest/l1/types.d.ts +12 -0
  36. package/dest/l1/types.d.ts.map +1 -0
  37. package/dest/{archiver/l1 → l1}/validate_trace.d.ts +1 -1
  38. package/dest/l1/validate_trace.d.ts.map +1 -0
  39. package/dest/{archiver/l1 → l1}/validate_trace.js +1 -1
  40. package/dest/modules/data_source_base.d.ts +84 -0
  41. package/dest/modules/data_source_base.d.ts.map +1 -0
  42. package/dest/modules/data_source_base.js +260 -0
  43. package/dest/modules/data_store_updater.d.ts +73 -0
  44. package/dest/modules/data_store_updater.d.ts.map +1 -0
  45. package/dest/modules/data_store_updater.js +302 -0
  46. package/dest/modules/instrumentation.d.ts +37 -0
  47. package/dest/modules/instrumentation.d.ts.map +1 -0
  48. package/dest/{archiver → modules}/instrumentation.js +15 -63
  49. package/dest/modules/l1_synchronizer.d.ts +75 -0
  50. package/dest/modules/l1_synchronizer.d.ts.map +1 -0
  51. package/dest/modules/l1_synchronizer.js +1113 -0
  52. package/dest/modules/validation.d.ts +17 -0
  53. package/dest/modules/validation.d.ts.map +1 -0
  54. package/dest/{archiver → modules}/validation.js +7 -1
  55. package/dest/store/block_store.d.ts +192 -0
  56. package/dest/store/block_store.d.ts.map +1 -0
  57. package/dest/{archiver/kv_archiver_store → store}/block_store.js +162 -48
  58. package/dest/store/contract_class_store.d.ts +18 -0
  59. package/dest/store/contract_class_store.d.ts.map +1 -0
  60. package/dest/{archiver/kv_archiver_store → store}/contract_class_store.js +1 -1
  61. package/dest/store/contract_instance_store.d.ts +24 -0
  62. package/dest/store/contract_instance_store.d.ts.map +1 -0
  63. package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +1 -1
  64. package/dest/store/kv_archiver_store.d.ts +340 -0
  65. package/dest/store/kv_archiver_store.d.ts.map +1 -0
  66. package/dest/store/kv_archiver_store.js +447 -0
  67. package/dest/store/log_store.d.ts +54 -0
  68. package/dest/store/log_store.d.ts.map +1 -0
  69. package/dest/{archiver/kv_archiver_store → store}/log_store.js +89 -54
  70. package/dest/{archiver/kv_archiver_store → store}/message_store.d.ts +1 -1
  71. package/dest/store/message_store.d.ts.map +1 -0
  72. package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
  73. package/dest/structs/data_retrieval.d.ts.map +1 -0
  74. package/dest/structs/inbox_message.d.ts +15 -0
  75. package/dest/structs/inbox_message.d.ts.map +1 -0
  76. package/dest/{archiver/structs → structs}/published.d.ts +1 -1
  77. package/dest/structs/published.d.ts.map +1 -0
  78. package/dest/test/fake_l1_state.d.ts +190 -0
  79. package/dest/test/fake_l1_state.d.ts.map +1 -0
  80. package/dest/test/fake_l1_state.js +383 -0
  81. package/dest/test/index.d.ts +2 -1
  82. package/dest/test/index.d.ts.map +1 -1
  83. package/dest/test/index.js +1 -0
  84. package/dest/test/mock_archiver.d.ts +2 -2
  85. package/dest/test/mock_archiver.d.ts.map +1 -1
  86. package/dest/test/mock_archiver.js +1 -2
  87. package/dest/test/mock_l1_to_l2_message_source.d.ts +2 -2
  88. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  89. package/dest/test/mock_l1_to_l2_message_source.js +12 -3
  90. package/dest/test/mock_l2_block_source.d.ts +22 -15
  91. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  92. package/dest/test/mock_l2_block_source.js +163 -57
  93. package/dest/test/mock_structs.d.ts +76 -2
  94. package/dest/test/mock_structs.d.ts.map +1 -1
  95. package/dest/test/mock_structs.js +133 -2
  96. package/package.json +15 -17
  97. package/src/archiver.ts +523 -0
  98. package/src/{archiver/config.ts → config.ts} +13 -2
  99. package/src/{archiver/errors.ts → errors.ts} +12 -0
  100. package/src/factory.ts +122 -8
  101. package/src/index.ts +10 -3
  102. package/src/interfaces.ts +9 -0
  103. package/src/{archiver/l1 → l1}/bin/retrieve-calldata.ts +7 -2
  104. package/src/{archiver/l1 → l1}/calldata_retriever.ts +3 -3
  105. package/src/{archiver/l1 → l1}/data_retrieval.ts +56 -73
  106. package/src/{archiver/l1 → l1}/validate_trace.ts +1 -1
  107. package/src/modules/data_source_base.ts +367 -0
  108. package/src/modules/data_store_updater.ts +423 -0
  109. package/src/{archiver → modules}/instrumentation.ts +16 -65
  110. package/src/modules/l1_synchronizer.ts +931 -0
  111. package/src/{archiver → modules}/validation.ts +11 -6
  112. package/src/{archiver/kv_archiver_store → store}/block_store.ts +210 -66
  113. package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +1 -1
  114. package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +1 -1
  115. package/src/{archiver/kv_archiver_store → store}/kv_archiver_store.ts +236 -35
  116. package/src/{archiver/kv_archiver_store → store}/log_store.ts +145 -86
  117. package/src/test/fake_l1_state.ts +599 -0
  118. package/src/test/index.ts +1 -0
  119. package/src/test/mock_archiver.ts +2 -2
  120. package/src/test/mock_l1_to_l2_message_source.ts +10 -4
  121. package/src/test/mock_l2_block_source.ts +173 -67
  122. package/src/test/mock_structs.ts +247 -2
  123. package/dest/archiver/archiver.d.ts +0 -304
  124. package/dest/archiver/archiver.d.ts.map +0 -1
  125. package/dest/archiver/archiver.js +0 -1645
  126. package/dest/archiver/archiver_store.d.ts +0 -308
  127. package/dest/archiver/archiver_store.d.ts.map +0 -1
  128. package/dest/archiver/archiver_store.js +0 -4
  129. package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
  130. package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
  131. package/dest/archiver/archiver_store_test_suite.js +0 -2770
  132. package/dest/archiver/config.d.ts.map +0 -1
  133. package/dest/archiver/errors.d.ts +0 -36
  134. package/dest/archiver/errors.d.ts.map +0 -1
  135. package/dest/archiver/index.d.ts +0 -7
  136. package/dest/archiver/index.d.ts.map +0 -1
  137. package/dest/archiver/index.js +0 -4
  138. package/dest/archiver/instrumentation.d.ts +0 -37
  139. package/dest/archiver/instrumentation.d.ts.map +0 -1
  140. package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -157
  141. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
  142. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
  143. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
  144. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
  145. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
  146. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -158
  147. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
  148. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -313
  149. package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -45
  150. package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
  151. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
  152. package/dest/archiver/l1/bin/retrieve-calldata.d.ts.map +0 -1
  153. package/dest/archiver/l1/calldata_retriever.d.ts.map +0 -1
  154. package/dest/archiver/l1/data_retrieval.d.ts +0 -90
  155. package/dest/archiver/l1/data_retrieval.d.ts.map +0 -1
  156. package/dest/archiver/l1/debug_tx.d.ts.map +0 -1
  157. package/dest/archiver/l1/spire_proposer.d.ts.map +0 -1
  158. package/dest/archiver/l1/trace_tx.d.ts.map +0 -1
  159. package/dest/archiver/l1/types.d.ts +0 -12
  160. package/dest/archiver/l1/types.d.ts.map +0 -1
  161. package/dest/archiver/l1/validate_trace.d.ts.map +0 -1
  162. package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
  163. package/dest/archiver/structs/inbox_message.d.ts +0 -15
  164. package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
  165. package/dest/archiver/structs/published.d.ts.map +0 -1
  166. package/dest/archiver/validation.d.ts +0 -17
  167. package/dest/archiver/validation.d.ts.map +0 -1
  168. package/dest/rpc/index.d.ts +0 -9
  169. package/dest/rpc/index.d.ts.map +0 -1
  170. package/dest/rpc/index.js +0 -15
  171. package/src/archiver/archiver.ts +0 -2157
  172. package/src/archiver/archiver_store.ts +0 -372
  173. package/src/archiver/archiver_store_test_suite.ts +0 -2843
  174. package/src/archiver/index.ts +0 -6
  175. package/src/rpc/index.ts +0 -16
  176. /package/dest/{archiver/l1 → l1}/debug_tx.js +0 -0
  177. /package/dest/{archiver/l1 → l1}/spire_proposer.js +0 -0
  178. /package/dest/{archiver/l1 → l1}/trace_tx.js +0 -0
  179. /package/dest/{archiver/l1 → l1}/types.js +0 -0
  180. /package/dest/{archiver/kv_archiver_store → store}/message_store.js +0 -0
  181. /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
  182. /package/dest/{archiver/structs → structs}/inbox_message.js +0 -0
  183. /package/dest/{archiver/structs → structs}/published.js +0 -0
  184. /package/src/{archiver/l1 → l1}/README.md +0 -0
  185. /package/src/{archiver/l1 → l1}/debug_tx.ts +0 -0
  186. /package/src/{archiver/l1 → l1}/spire_proposer.ts +0 -0
  187. /package/src/{archiver/l1 → l1}/trace_tx.ts +0 -0
  188. /package/src/{archiver/l1 → l1}/types.ts +0 -0
  189. /package/src/{archiver/kv_archiver_store → store}/message_store.ts +0 -0
  190. /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
  191. /package/src/{archiver/structs → structs}/inbox_message.ts +0 -0
  192. /package/src/{archiver/structs → structs}/published.ts +0 -0
package/src/factory.ts CHANGED
@@ -1,36 +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';
1
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';
2
9
  import { createLogger } from '@aztec/foundation/log';
10
+ import { DateProvider } from '@aztec/foundation/timer';
3
11
  import type { DataStoreConfig } from '@aztec/kv-store/config';
4
12
  import { createStore } from '@aztec/kv-store/lmdb-v2';
5
13
  import { protocolContractNames } from '@aztec/protocol-contracts';
6
14
  import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
7
15
  import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi';
16
+ import type { ArchiverEmitter } from '@aztec/stdlib/block';
8
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';
9
20
 
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';
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';
13
29
 
14
30
  export const ARCHIVER_STORE_NAME = 'archiver';
15
31
 
16
32
  /** Creates an archiver store. */
17
33
  export async function createArchiverStore(
18
34
  userConfig: Pick<ArchiverConfig, 'archiverStoreMapSizeKb' | 'maxLogs'> & DataStoreConfig,
35
+ l1Constants: Pick<L1RollupConstants, 'epochDuration'>,
19
36
  ) {
20
37
  const config = {
21
38
  ...userConfig,
22
39
  dataStoreMapSizeKb: userConfig.archiverStoreMapSizeKb ?? userConfig.dataStoreMapSizeKb,
23
40
  };
24
41
  const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config, createLogger('archiver:lmdb'));
25
- return new KVArchiverDataStore(store, config.maxLogs);
42
+ return new KVArchiverDataStore(store, config.maxLogs, l1Constants);
26
43
  }
27
44
 
28
45
  /**
29
46
  * Creates a local archiver.
30
47
  * @param config - The archiver configuration.
31
- * @param blobClient - The blob client client.
48
+ * @param deps - The archiver dependencies (blobClient, epochCache, dateProvider, telemetry).
32
49
  * @param opts - The options.
33
- * @param telemetry - The telemetry client.
34
50
  * @returns The local archiver.
35
51
  */
36
52
  export async function createArchiver(
@@ -38,9 +54,107 @@ export async function createArchiver(
38
54
  deps: ArchiverDeps,
39
55
  opts: { blockUntilSync: boolean } = { blockUntilSync: true },
40
56
  ): Promise<Archiver> {
41
- const archiverStore = await createArchiverStore(config);
57
+ const archiverStore = await createArchiverStore(config, { epochDuration: config.aztecEpochDuration });
42
58
  await registerProtocolContracts(archiverStore);
43
- 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;
44
158
  }
45
159
 
46
160
  async function registerProtocolContracts(store: KVArchiverDataStore) {
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 { 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
+
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;
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
3
- import { CheckpointNumber } from '@aztec/foundation/branded-types';
3
+ import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
4
4
  import { EthAddress } from '@aztec/foundation/eth-address';
5
5
  import { createLogger } from '@aztec/foundation/log';
6
6
 
@@ -142,7 +142,12 @@ async function main() {
142
142
  logger.info('');
143
143
 
144
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), {});
145
+ const result = await retriever.getCheckpointFromRollupTx(
146
+ txHash,
147
+ [],
148
+ CheckpointNumber.fromBlockNumber(BlockNumber(l2BlockNumber)),
149
+ {},
150
+ );
146
151
 
147
152
  logger.info(' Successfully retrieved block header!');
148
153
  logger.info('');
@@ -28,7 +28,7 @@ import {
28
28
  toFunctionSelector,
29
29
  } from 'viem';
30
30
 
31
- import type { ArchiverInstrumentation } from '../instrumentation.js';
31
+ import type { ArchiverInstrumentation } from '../modules/instrumentation.js';
32
32
  import { getSuccessfulCallsFromDebug } from './debug_tx.js';
33
33
  import { getCallFromSpireProposer } from './spire_proposer.js';
34
34
  import { getSuccessfulCallsFromTrace } from './trace_tx.js';
@@ -72,7 +72,7 @@ export class CalldataRetriever {
72
72
  */
73
73
  async getCheckpointFromRollupTx(
74
74
  txHash: `0x${string}`,
75
- blobHashes: Buffer[],
75
+ _blobHashes: Buffer[],
76
76
  checkpointNumber: CheckpointNumber,
77
77
  expectedHashes: {
78
78
  attestationsHash?: Hex;
@@ -459,7 +459,7 @@ export class CalldataRetriever {
459
459
  // Use ConsensusPayload to compute the digest - this ensures we match the exact logic
460
460
  // used by the network for signing and verification
461
461
  const consensusPayload = new ConsensusPayload(header, archiveRoot);
462
- const payloadToSign = consensusPayload.getPayloadToSign(SignatureDomainSeparator.blockAttestation);
462
+ const payloadToSign = consensusPayload.getPayloadToSign(SignatureDomainSeparator.checkpointAttestation);
463
463
  const computedPayloadDigest = keccak256(payloadToSign);
464
464
 
465
465
  // Compare as buffers to avoid case-sensitivity and string comparison issues
@@ -6,33 +6,31 @@ import {
6
6
  decodeCheckpointBlobDataFromBlobs,
7
7
  encodeBlockBlobData,
8
8
  } from '@aztec/blob-lib';
9
- import type { EpochProofPublicInputArgs } from '@aztec/ethereum/contracts';
10
- import type { ViemClient, ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
9
+ import type {
10
+ CheckpointProposedLog,
11
+ EpochProofPublicInputArgs,
12
+ InboxContract,
13
+ MessageSentLog,
14
+ RollupContract,
15
+ } from '@aztec/ethereum/contracts';
16
+ import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
11
17
  import { asyncPool } from '@aztec/foundation/async-pool';
12
- import { CheckpointNumber } from '@aztec/foundation/branded-types';
13
- import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
18
+ import { CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
14
19
  import { Fr } from '@aztec/foundation/curves/bn254';
15
20
  import { EthAddress } from '@aztec/foundation/eth-address';
16
21
  import { type Logger, createLogger } from '@aztec/foundation/log';
17
- import { type InboxAbi, RollupAbi } from '@aztec/l1-artifacts';
18
- import { Body, CommitteeAttestation, L2BlockNew } from '@aztec/stdlib/block';
22
+ import { RollupAbi } from '@aztec/l1-artifacts';
23
+ import { Body, CommitteeAttestation, L2Block } from '@aztec/stdlib/block';
19
24
  import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
20
25
  import { Proof } from '@aztec/stdlib/proofs';
21
26
  import { CheckpointHeader } from '@aztec/stdlib/rollup';
22
27
  import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
23
28
  import { BlockHeader, GlobalVariables, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
24
29
 
25
- import {
26
- type GetContractEventsReturnType,
27
- type GetContractReturnType,
28
- type Hex,
29
- decodeFunctionData,
30
- getAbiItem,
31
- hexToBytes,
32
- } from 'viem';
30
+ import { type Hex, decodeFunctionData, getAbiItem, hexToBytes } from 'viem';
33
31
 
34
32
  import { NoBlobBodiesFoundError } from '../errors.js';
35
- import type { ArchiverInstrumentation } from '../instrumentation.js';
33
+ import type { ArchiverInstrumentation } from '../modules/instrumentation.js';
36
34
  import type { DataRetrieval } from '../structs/data_retrieval.js';
37
35
  import type { InboxMessage } from '../structs/inbox_message.js';
38
36
  import { CalldataRetriever } from './calldata_retriever.js';
@@ -71,7 +69,7 @@ export async function retrievedToPublishedCheckpoint({
71
69
  const l1toL2MessageTreeRoot = blocksBlobData[0].l1ToL2MessageRoot!;
72
70
 
73
71
  const spongeBlob = SpongeBlob.init();
74
- const l2Blocks: L2BlockNew[] = [];
72
+ const l2Blocks: L2Block[] = [];
75
73
  for (let i = 0; i < blocksBlobData.length; i++) {
76
74
  const blockBlobData = blocksBlobData[i];
77
75
  const { blockEndMarker, blockEndStateField, lastArchiveRoot, noteHashRoot, nullifierRoot, publicDataRoot } =
@@ -121,7 +119,7 @@ export async function retrievedToPublishedCheckpoint({
121
119
 
122
120
  const newArchive = new AppendOnlyTreeSnapshot(newArchiveRoots[i], l2BlockNumber + 1);
123
121
 
124
- l2Blocks.push(new L2BlockNew(newArchive, header, body, checkpointNumber, i));
122
+ l2Blocks.push(new L2Block(newArchive, header, body, checkpointNumber, IndexWithinCheckpoint(i)));
125
123
  }
126
124
 
127
125
  const lastBlock = l2Blocks.at(-1)!;
@@ -137,7 +135,7 @@ export async function retrievedToPublishedCheckpoint({
137
135
 
138
136
  /**
139
137
  * Fetches new checkpoints.
140
- * @param rollup - The rollup contract instance.
138
+ * @param rollup - The rollup contract wrapper.
141
139
  * @param publicClient - The viem public client to use for transaction retrieval.
142
140
  * @param debugClient - The viem debug client to use for trace/debug RPC methods (optional).
143
141
  * @param blobClient - The blob client client for fetching blob data.
@@ -150,7 +148,7 @@ export async function retrievedToPublishedCheckpoint({
150
148
  * @returns An array of retrieved checkpoints.
151
149
  */
152
150
  export async function retrieveCheckpointsFromRollup(
153
- rollup: GetContractReturnType<typeof RollupAbi, ViemPublicClient>,
151
+ rollup: RollupContract,
154
152
  publicClient: ViemPublicClient,
155
153
  debugClient: ViemPublicDebugClient,
156
154
  blobClient: BlobClientInterface,
@@ -173,15 +171,7 @@ export async function retrieveCheckpointsFromRollup(
173
171
  if (searchStartBlock > searchEndBlock) {
174
172
  break;
175
173
  }
176
- const checkpointProposedLogs = (
177
- await rollup.getEvents.CheckpointProposed(
178
- {},
179
- {
180
- fromBlock: searchStartBlock,
181
- toBlock: searchEndBlock,
182
- },
183
- )
184
- ).filter(log => log.blockNumber! >= searchStartBlock && log.blockNumber! <= searchEndBlock);
174
+ const checkpointProposedLogs = await rollup.getCheckpointProposedEvents(searchStartBlock, searchEndBlock);
185
175
 
186
176
  if (checkpointProposedLogs.length === 0) {
187
177
  break;
@@ -189,19 +179,19 @@ export async function retrieveCheckpointsFromRollup(
189
179
 
190
180
  const lastLog = checkpointProposedLogs.at(-1)!;
191
181
  logger.debug(
192
- `Got ${checkpointProposedLogs.length} processed logs for checkpoints ${checkpointProposedLogs[0].args.checkpointNumber}-${lastLog.args.checkpointNumber} between L1 blocks ${searchStartBlock}-${searchEndBlock}`,
182
+ `Got ${checkpointProposedLogs.length} processed logs for checkpoints ${checkpointProposedLogs[0].args.checkpointNumber}-${lastLog.args.checkpointNumber} between L1 blocks ${searchStartBlock}-${searchEndBlock}`,
193
183
  );
194
184
 
195
185
  if (rollupConstants === undefined) {
196
186
  const [chainId, version, targetCommitteeSize] = await Promise.all([
197
187
  publicClient.getChainId(),
198
- rollup.read.getVersion(),
199
- rollup.read.getTargetCommitteeSize(),
188
+ rollup.getVersion(),
189
+ rollup.getTargetCommitteeSize(),
200
190
  ]);
201
191
  rollupConstants = {
202
192
  chainId: new Fr(chainId),
203
193
  version: new Fr(version),
204
- targetCommitteeSize: Number(targetCommitteeSize),
194
+ targetCommitteeSize,
205
195
  };
206
196
  }
207
197
 
@@ -218,7 +208,7 @@ export async function retrieveCheckpointsFromRollup(
218
208
  isHistoricalSync,
219
209
  );
220
210
  retrievedCheckpoints.push(...newCheckpoints);
221
- searchStartBlock = lastLog.blockNumber! + 1n;
211
+ searchStartBlock = lastLog.l1BlockNumber + 1n;
222
212
  } while (searchStartBlock <= searchEndBlock);
223
213
 
224
214
  // The asyncPool from processCheckpointProposedLogs will not necessarily return the checkpoints in order, so we sort them before returning.
@@ -227,7 +217,7 @@ export async function retrieveCheckpointsFromRollup(
227
217
 
228
218
  /**
229
219
  * Processes newly received CheckpointProposed logs.
230
- * @param rollup - The rollup contract instance.
220
+ * @param rollup - The rollup contract wrapper.
231
221
  * @param publicClient - The viem public client to use for transaction retrieval.
232
222
  * @param debugClient - The viem debug client to use for trace/debug RPC methods (optional).
233
223
  * @param blobClient - The blob client client for fetching blob data.
@@ -240,11 +230,11 @@ export async function retrieveCheckpointsFromRollup(
240
230
  * @returns An array of retrieved checkpoints.
241
231
  */
242
232
  async function processCheckpointProposedLogs(
243
- rollup: GetContractReturnType<typeof RollupAbi, ViemPublicClient>,
233
+ rollup: RollupContract,
244
234
  publicClient: ViemPublicClient,
245
235
  debugClient: ViemPublicDebugClient,
246
236
  blobClient: BlobClientInterface,
247
- logs: GetContractEventsReturnType<typeof RollupAbi, 'CheckpointProposed'>,
237
+ logs: CheckpointProposedLog[],
248
238
  { chainId, version, targetCommitteeSize }: { chainId: Fr; version: Fr; targetCommitteeSize: number },
249
239
  contractAddresses: {
250
240
  governanceProposerAddress: EthAddress;
@@ -266,21 +256,21 @@ async function processCheckpointProposedLogs(
266
256
  );
267
257
 
268
258
  await asyncPool(10, logs, async log => {
269
- const checkpointNumber = CheckpointNumber.fromBigInt(log.args.checkpointNumber!);
270
- const archive = log.args.archive!;
271
- const archiveFromChain = await rollup.read.archiveAt([BigInt(checkpointNumber)]);
272
- const blobHashes = log.args.versionedBlobHashes!.map(blobHash => Buffer.from(blobHash.slice(2), 'hex'));
259
+ const checkpointNumber = log.args.checkpointNumber;
260
+ const archive = log.args.archive;
261
+ const archiveFromChain = await rollup.archiveAt(checkpointNumber);
262
+ const blobHashes = log.args.versionedBlobHashes;
273
263
 
274
264
  // The value from the event and contract will match only if the checkpoint is in the chain.
275
- if (archive === archiveFromChain) {
265
+ if (archive.equals(archiveFromChain)) {
276
266
  // Build expected hashes object (fields may be undefined for backwards compatibility with older events)
277
267
  const expectedHashes = {
278
- attestationsHash: log.args.attestationsHash,
279
- payloadDigest: log.args.payloadDigest,
268
+ attestationsHash: log.args.attestationsHash?.toString(),
269
+ payloadDigest: log.args.payloadDigest?.toString(),
280
270
  };
281
271
 
282
272
  const checkpoint = await calldataRetriever.getCheckpointFromRollupTx(
283
- log.transactionHash!,
273
+ log.l1TransactionHash,
284
274
  blobHashes,
285
275
  checkpointNumber,
286
276
  expectedHashes,
@@ -295,22 +285,22 @@ async function processCheckpointProposedLogs(
295
285
  );
296
286
 
297
287
  const l1 = new L1PublishedData(
298
- log.blockNumber,
299
- await getL1BlockTime(publicClient, log.blockNumber),
300
- log.blockHash,
288
+ log.l1BlockNumber,
289
+ await getL1BlockTime(publicClient, log.l1BlockNumber),
290
+ log.l1BlockHash.toString(),
301
291
  );
302
292
 
303
293
  retrievedCheckpoints.push({ ...checkpoint, checkpointBlobData, l1, chainId, version });
304
- logger.trace(`Retrieved checkpoint ${checkpointNumber} from L1 tx ${log.transactionHash}`, {
305
- l1BlockNumber: log.blockNumber,
294
+ logger.trace(`Retrieved checkpoint ${checkpointNumber} from L1 tx ${log.l1TransactionHash}`, {
295
+ l1BlockNumber: log.l1BlockNumber,
306
296
  checkpointNumber,
307
297
  archive: archive.toString(),
308
298
  attestations: checkpoint.attestations,
309
299
  });
310
300
  } else {
311
301
  logger.warn(`Ignoring checkpoint ${checkpointNumber} due to archive root mismatch`, {
312
- actual: archive,
313
- expected: archiveFromChain,
302
+ actual: archive.toString(),
303
+ expected: archiveFromChain.toString(),
314
304
  });
315
305
  }
316
306
  });
@@ -355,12 +345,12 @@ export async function getCheckpointBlobDataFromBlobs(
355
345
 
356
346
  /** Given an L1 to L2 message, retrieves its corresponding event from the Inbox within a specific block range. */
357
347
  export async function retrieveL1ToL2Message(
358
- inbox: GetContractReturnType<typeof InboxAbi, ViemClient>,
348
+ inbox: InboxContract,
359
349
  leaf: Fr,
360
350
  fromBlock: bigint,
361
351
  toBlock: bigint,
362
352
  ): Promise<InboxMessage | undefined> {
363
- const logs = await inbox.getEvents.MessageSent({ hash: leaf.toString() }, { fromBlock, toBlock });
353
+ const logs = await inbox.getMessageSentEventByHash(leaf.toString(), fromBlock, toBlock);
364
354
 
365
355
  const messages = mapLogsInboxMessage(logs);
366
356
  return messages.length > 0 ? messages[0] : undefined;
@@ -368,47 +358,40 @@ export async function retrieveL1ToL2Message(
368
358
 
369
359
  /**
370
360
  * Fetch L1 to L2 messages.
371
- * @param publicClient - The viem public client to use for transaction retrieval.
372
- * @param inboxAddress - The address of the inbox contract to fetch messages from.
373
- * @param blockUntilSynced - If true, blocks until the archiver has fully synced.
361
+ * @param inbox - The inbox contract wrapper.
374
362
  * @param searchStartBlock - The block number to use for starting the search.
375
363
  * @param searchEndBlock - The highest block number that we should search up to.
376
364
  * @returns An array of InboxLeaf and next eth block to search from.
377
365
  */
378
366
  export async function retrieveL1ToL2Messages(
379
- inbox: GetContractReturnType<typeof InboxAbi, ViemClient>,
367
+ inbox: InboxContract,
380
368
  searchStartBlock: bigint,
381
369
  searchEndBlock: bigint,
382
370
  ): Promise<InboxMessage[]> {
383
371
  const retrievedL1ToL2Messages: InboxMessage[] = [];
384
372
  while (searchStartBlock <= searchEndBlock) {
385
- const messageSentLogs = (
386
- await inbox.getEvents.MessageSent({}, { fromBlock: searchStartBlock, toBlock: searchEndBlock })
387
- ).filter(log => log.blockNumber! >= searchStartBlock && log.blockNumber! <= searchEndBlock);
373
+ const messageSentLogs = await inbox.getMessageSentEvents(searchStartBlock, searchEndBlock);
388
374
 
389
375
  if (messageSentLogs.length === 0) {
390
376
  break;
391
377
  }
392
378
 
393
379
  retrievedL1ToL2Messages.push(...mapLogsInboxMessage(messageSentLogs));
394
- searchStartBlock = messageSentLogs.at(-1)!.blockNumber + 1n;
380
+ searchStartBlock = messageSentLogs.at(-1)!.l1BlockNumber + 1n;
395
381
  }
396
382
 
397
383
  return retrievedL1ToL2Messages;
398
384
  }
399
385
 
400
- function mapLogsInboxMessage(logs: GetContractEventsReturnType<typeof InboxAbi, 'MessageSent'>): InboxMessage[] {
401
- return logs.map(log => {
402
- const { index, hash, checkpointNumber, rollingHash } = log.args;
403
- return {
404
- index: index!,
405
- leaf: Fr.fromHexString(hash!),
406
- l1BlockNumber: log.blockNumber,
407
- l1BlockHash: Buffer32.fromString(log.blockHash),
408
- checkpointNumber: CheckpointNumber.fromBigInt(checkpointNumber!),
409
- rollingHash: Buffer16.fromString(rollingHash!),
410
- };
411
- });
386
+ function mapLogsInboxMessage(logs: MessageSentLog[]): InboxMessage[] {
387
+ return logs.map(log => ({
388
+ index: log.args.index,
389
+ leaf: log.args.leaf,
390
+ l1BlockNumber: log.l1BlockNumber,
391
+ l1BlockHash: log.l1BlockHash,
392
+ checkpointNumber: log.args.checkpointNumber,
393
+ rollingHash: log.args.rollingHash,
394
+ }));
412
395
  }
413
396
 
414
397
  /** Retrieves L2ProofVerified events from the rollup contract. */
@@ -165,7 +165,7 @@ export async function validateAndLogTraceAvailability(
165
165
  client: ViemPublicDebugClient,
166
166
  ethereumAllowNoDebugHosts: boolean,
167
167
  ): Promise<void> {
168
- logger.info('Validating trace/debug method availability...');
168
+ logger.debug('Validating trace/debug method availability...');
169
169
 
170
170
  const availability = await validateTraceAvailability(client);
171
171