@aztec/archiver 0.0.0-test.1 → 0.0.1-commit.023c3e5

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 (225) hide show
  1. package/README.md +164 -9
  2. package/dest/archiver.d.ts +136 -0
  3. package/dest/archiver.d.ts.map +1 -0
  4. package/dest/archiver.js +781 -0
  5. package/dest/config.d.ts +30 -0
  6. package/dest/config.d.ts.map +1 -0
  7. package/dest/config.js +71 -0
  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 +13 -16
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +103 -55
  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/l1/data_retrieval.js +312 -0
  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 +32 -0
  42. package/dest/l1/validate_trace.d.ts.map +1 -0
  43. package/dest/l1/validate_trace.js +154 -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/modules/instrumentation.js +110 -0
  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 +1112 -0
  56. package/dest/modules/validation.d.ts +17 -0
  57. package/dest/modules/validation.d.ts.map +1 -0
  58. package/dest/modules/validation.js +104 -0
  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 +25 -27
  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/store/contract_instance_store.js +77 -0
  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 +446 -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/store/message_store.js +188 -0
  77. package/dest/structs/data_retrieval.d.ts +27 -0
  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/structs/inbox_message.js +39 -0
  82. package/dest/structs/published.d.ts +2 -0
  83. package/dest/structs/published.d.ts.map +1 -0
  84. package/dest/structs/published.js +1 -0
  85. package/dest/test/fake_l1_state.d.ts +190 -0
  86. package/dest/test/fake_l1_state.d.ts.map +1 -0
  87. package/dest/test/fake_l1_state.js +383 -0
  88. package/dest/test/index.d.ts +2 -1
  89. package/dest/test/index.d.ts.map +1 -1
  90. package/dest/test/index.js +4 -1
  91. package/dest/test/mock_archiver.d.ts +16 -8
  92. package/dest/test/mock_archiver.d.ts.map +1 -1
  93. package/dest/test/mock_archiver.js +18 -14
  94. package/dest/test/mock_l1_to_l2_message_source.d.ts +9 -6
  95. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  96. package/dest/test/mock_l1_to_l2_message_source.js +30 -7
  97. package/dest/test/mock_l2_block_source.d.ts +62 -16
  98. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  99. package/dest/test/mock_l2_block_source.js +263 -32
  100. package/dest/test/mock_structs.d.ts +85 -0
  101. package/dest/test/mock_structs.d.ts.map +1 -0
  102. package/dest/test/mock_structs.js +171 -0
  103. package/dest/test/noop_l1_archiver.d.ts +23 -0
  104. package/dest/test/noop_l1_archiver.d.ts.map +1 -0
  105. package/dest/test/noop_l1_archiver.js +68 -0
  106. package/package.json +31 -33
  107. package/src/archiver.ts +543 -0
  108. package/src/config.ts +95 -0
  109. package/src/errors.ts +102 -0
  110. package/src/factory.ts +144 -71
  111. package/src/index.ts +10 -3
  112. package/src/interfaces.ts +9 -0
  113. package/src/l1/README.md +98 -0
  114. package/src/l1/bin/retrieve-calldata.ts +187 -0
  115. package/src/l1/calldata_retriever.ts +641 -0
  116. package/src/l1/data_retrieval.ts +495 -0
  117. package/src/l1/debug_tx.ts +99 -0
  118. package/src/l1/spire_proposer.ts +160 -0
  119. package/src/l1/trace_tx.ts +128 -0
  120. package/src/l1/types.ts +13 -0
  121. package/src/l1/validate_trace.ts +229 -0
  122. package/src/modules/data_source_base.ts +367 -0
  123. package/src/modules/data_store_updater.ts +423 -0
  124. package/src/modules/instrumentation.ts +157 -0
  125. package/src/modules/l1_synchronizer.ts +930 -0
  126. package/src/modules/validation.ts +129 -0
  127. package/src/store/block_store.ts +966 -0
  128. package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +26 -32
  129. package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +37 -29
  130. package/src/store/kv_archiver_store.ts +639 -0
  131. package/src/store/log_store.ts +575 -0
  132. package/src/store/message_store.ts +261 -0
  133. package/src/structs/inbox_message.ts +41 -0
  134. package/src/structs/published.ts +1 -0
  135. package/src/test/fake_l1_state.ts +599 -0
  136. package/src/test/fixtures/debug_traceTransaction-multicall3.json +88 -0
  137. package/src/test/fixtures/debug_traceTransaction-multiplePropose.json +153 -0
  138. package/src/test/fixtures/debug_traceTransaction-proxied.json +122 -0
  139. package/src/test/fixtures/trace_transaction-multicall3.json +65 -0
  140. package/src/test/fixtures/trace_transaction-multiplePropose.json +319 -0
  141. package/src/test/fixtures/trace_transaction-proxied.json +128 -0
  142. package/src/test/fixtures/trace_transaction-randomRevert.json +216 -0
  143. package/src/test/index.ts +4 -0
  144. package/src/test/mock_archiver.ts +22 -16
  145. package/src/test/mock_l1_to_l2_message_source.ts +26 -8
  146. package/src/test/mock_l2_block_source.ts +313 -42
  147. package/src/test/mock_structs.ts +311 -0
  148. package/src/test/noop_l1_archiver.ts +109 -0
  149. package/dest/archiver/archiver.d.ts +0 -197
  150. package/dest/archiver/archiver.d.ts.map +0 -1
  151. package/dest/archiver/archiver.js +0 -900
  152. package/dest/archiver/archiver_store.d.ts +0 -220
  153. package/dest/archiver/archiver_store.d.ts.map +0 -1
  154. package/dest/archiver/archiver_store.js +0 -4
  155. package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
  156. package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
  157. package/dest/archiver/archiver_store_test_suite.js +0 -794
  158. package/dest/archiver/config.d.ts +0 -37
  159. package/dest/archiver/config.d.ts.map +0 -1
  160. package/dest/archiver/config.js +0 -46
  161. package/dest/archiver/data_retrieval.d.ts +0 -74
  162. package/dest/archiver/data_retrieval.d.ts.map +0 -1
  163. package/dest/archiver/data_retrieval.js +0 -283
  164. package/dest/archiver/errors.d.ts +0 -4
  165. package/dest/archiver/errors.d.ts.map +0 -1
  166. package/dest/archiver/errors.js +0 -5
  167. package/dest/archiver/index.d.ts +0 -8
  168. package/dest/archiver/index.d.ts.map +0 -1
  169. package/dest/archiver/index.js +0 -5
  170. package/dest/archiver/instrumentation.d.ts +0 -29
  171. package/dest/archiver/instrumentation.d.ts.map +0 -1
  172. package/dest/archiver/instrumentation.js +0 -99
  173. package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -87
  174. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
  175. package/dest/archiver/kv_archiver_store/block_store.js +0 -217
  176. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
  177. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
  178. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -21
  179. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
  180. package/dest/archiver/kv_archiver_store/contract_instance_store.js +0 -63
  181. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -153
  182. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
  183. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -254
  184. package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -49
  185. package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
  186. package/dest/archiver/kv_archiver_store/log_store.js +0 -364
  187. package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -33
  188. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
  189. package/dest/archiver/kv_archiver_store/message_store.js +0 -85
  190. package/dest/archiver/kv_archiver_store/nullifier_store.d.ts +0 -12
  191. package/dest/archiver/kv_archiver_store/nullifier_store.d.ts.map +0 -1
  192. package/dest/archiver/kv_archiver_store/nullifier_store.js +0 -73
  193. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts +0 -23
  194. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts.map +0 -1
  195. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.js +0 -49
  196. package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts +0 -175
  197. package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts.map +0 -1
  198. package/dest/archiver/memory_archiver_store/memory_archiver_store.js +0 -636
  199. package/dest/archiver/structs/data_retrieval.d.ts +0 -27
  200. package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
  201. package/dest/archiver/structs/published.d.ts +0 -11
  202. package/dest/archiver/structs/published.d.ts.map +0 -1
  203. package/dest/archiver/structs/published.js +0 -1
  204. package/dest/rpc/index.d.ts +0 -10
  205. package/dest/rpc/index.d.ts.map +0 -1
  206. package/dest/rpc/index.js +0 -18
  207. package/src/archiver/archiver.ts +0 -1181
  208. package/src/archiver/archiver_store.ts +0 -263
  209. package/src/archiver/archiver_store_test_suite.ts +0 -810
  210. package/src/archiver/config.ts +0 -92
  211. package/src/archiver/data_retrieval.ts +0 -422
  212. package/src/archiver/errors.ts +0 -5
  213. package/src/archiver/index.ts +0 -7
  214. package/src/archiver/instrumentation.ts +0 -132
  215. package/src/archiver/kv_archiver_store/block_store.ts +0 -283
  216. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -358
  217. package/src/archiver/kv_archiver_store/log_store.ts +0 -444
  218. package/src/archiver/kv_archiver_store/message_store.ts +0 -102
  219. package/src/archiver/kv_archiver_store/nullifier_store.ts +0 -97
  220. package/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts +0 -61
  221. package/src/archiver/memory_archiver_store/memory_archiver_store.ts +0 -801
  222. package/src/archiver/structs/published.ts +0 -11
  223. package/src/rpc/index.ts +0 -20
  224. /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
  225. /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
@@ -1,92 +0,0 @@
1
- import { type BlobSinkConfig, blobSinkConfigMapping } from '@aztec/blob-sink/client';
2
- import {
3
- type L1ContractAddresses,
4
- type L1ContractsConfig,
5
- type L1ReaderConfig,
6
- l1ContractsConfigMappings,
7
- l1ReaderConfigMappings,
8
- } from '@aztec/ethereum';
9
- import { type ConfigMappingsType, getConfigFromMappings, numberConfigHelper } from '@aztec/foundation/config';
10
- import { type ChainConfig, chainConfigMappings } from '@aztec/stdlib/config';
11
-
12
- /**
13
- * There are 2 polling intervals used in this configuration. The first is the archiver polling interval, archiverPollingIntervalMS.
14
- * This is the interval between successive calls to eth_blockNumber via viem.
15
- * Results of calls to eth_blockNumber are cached by viem with this cache being updated periodically at the interval specified by viemPollingIntervalMS.
16
- * As a result the maximum observed polling time for new blocks will be viemPollingIntervalMS + archiverPollingIntervalMS.
17
- */
18
-
19
- /**
20
- * The archiver configuration.
21
- */
22
- export type ArchiverConfig = {
23
- /** URL for an archiver service. If set, will return an archiver client as opposed to starting a new one. */
24
- archiverUrl?: string;
25
-
26
- /** URL for an L1 consensus client */
27
- l1ConsensusHostUrl?: string;
28
-
29
- /** The polling interval in ms for retrieving new L2 blocks and encrypted logs. */
30
- archiverPollingIntervalMS?: number;
31
-
32
- /** The number of L2 blocks the archiver will attempt to download at a time. */
33
- archiverBatchSize?: number;
34
-
35
- /** The polling interval viem uses in ms */
36
- viemPollingIntervalMS?: number;
37
-
38
- /** The deployed L1 contract addresses */
39
- l1Contracts: L1ContractAddresses;
40
-
41
- /** The max number of logs that can be obtained in 1 "getPublicLogs" call. */
42
- maxLogs?: number;
43
- } & L1ReaderConfig &
44
- L1ContractsConfig &
45
- BlobSinkConfig &
46
- ChainConfig;
47
-
48
- export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
49
- ...blobSinkConfigMapping,
50
- archiverUrl: {
51
- env: 'ARCHIVER_URL',
52
- description:
53
- 'URL for an archiver service. If set, will return an archiver client as opposed to starting a new one.',
54
- },
55
- l1ConsensusHostUrl: {
56
- env: 'L1_CONSENSUS_HOST_URL',
57
- description: 'URL for an L1 consensus client.',
58
- parseEnv: (val: string) => val,
59
- },
60
- archiverPollingIntervalMS: {
61
- env: 'ARCHIVER_POLLING_INTERVAL_MS',
62
- description: 'The polling interval in ms for retrieving new L2 blocks and encrypted logs.',
63
- ...numberConfigHelper(500),
64
- },
65
- archiverBatchSize: {
66
- env: 'ARCHIVER_BATCH_SIZE',
67
- description: 'The number of L2 blocks the archiver will attempt to download at a time.',
68
- ...numberConfigHelper(100),
69
- },
70
- maxLogs: {
71
- env: 'ARCHIVER_MAX_LOGS',
72
- description: 'The max number of logs that can be obtained in 1 "getPublicLogs" call.',
73
- ...numberConfigHelper(1_000),
74
- },
75
- ...chainConfigMappings,
76
- ...l1ReaderConfigMappings,
77
- viemPollingIntervalMS: {
78
- env: 'ARCHIVER_VIEM_POLLING_INTERVAL_MS',
79
- description: 'The polling interval viem uses in ms',
80
- ...numberConfigHelper(1000),
81
- },
82
- ...l1ContractsConfigMappings,
83
- };
84
-
85
- /**
86
- * Returns the archiver configuration from the environment variables.
87
- * Note: If an environment variable is not set, the default value is used.
88
- * @returns The archiver configuration.
89
- */
90
- export function getArchiverConfigFromEnv(): ArchiverConfig {
91
- return getConfigFromMappings<ArchiverConfig>(archiverConfigMappings);
92
- }
@@ -1,422 +0,0 @@
1
- import { Blob, BlobDeserializationError } from '@aztec/blob-lib';
2
- import type { BlobSinkClientInterface } from '@aztec/blob-sink/client';
3
- import type { EpochProofPublicInputArgs, ViemPublicClient } from '@aztec/ethereum';
4
- import { asyncPool } from '@aztec/foundation/async-pool';
5
- import type { EthAddress } from '@aztec/foundation/eth-address';
6
- import type { ViemSignature } from '@aztec/foundation/eth-signature';
7
- import { Fr } from '@aztec/foundation/fields';
8
- import { type Logger, createLogger } from '@aztec/foundation/log';
9
- import { numToUInt32BE } from '@aztec/foundation/serialize';
10
- import { ForwarderAbi, type InboxAbi, RollupAbi } from '@aztec/l1-artifacts';
11
- import { Body, L2Block } from '@aztec/stdlib/block';
12
- import { InboxLeaf } from '@aztec/stdlib/messaging';
13
- import { Proof } from '@aztec/stdlib/proofs';
14
- import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
15
- import { BlockHeader } from '@aztec/stdlib/tx';
16
-
17
- import {
18
- type GetContractEventsReturnType,
19
- type GetContractReturnType,
20
- type Hex,
21
- decodeFunctionData,
22
- getAbiItem,
23
- hexToBytes,
24
- } from 'viem';
25
-
26
- import { NoBlobBodiesFoundError } from './errors.js';
27
- import type { DataRetrieval } from './structs/data_retrieval.js';
28
- import type { L1Published, L1PublishedData } from './structs/published.js';
29
-
30
- /**
31
- * Fetches new L2 blocks.
32
- * @param publicClient - The viem public client to use for transaction retrieval.
33
- * @param rollupAddress - The address of the rollup contract.
34
- * @param searchStartBlock - The block number to use for starting the search.
35
- * @param searchEndBlock - The highest block number that we should search up to.
36
- * @param expectedNextL2BlockNum - The next L2 block number that we expect to find.
37
- * @returns An array of block; as well as the next eth block to search from.
38
- */
39
- export async function retrieveBlocksFromRollup(
40
- rollup: GetContractReturnType<typeof RollupAbi, ViemPublicClient>,
41
- publicClient: ViemPublicClient,
42
- blobSinkClient: BlobSinkClientInterface,
43
- searchStartBlock: bigint,
44
- searchEndBlock: bigint,
45
- logger: Logger = createLogger('archiver'),
46
- ): Promise<L1Published<L2Block>[]> {
47
- const retrievedBlocks: L1Published<L2Block>[] = [];
48
- do {
49
- if (searchStartBlock > searchEndBlock) {
50
- break;
51
- }
52
- const l2BlockProposedLogs = (
53
- await rollup.getEvents.L2BlockProposed(
54
- {},
55
- {
56
- fromBlock: searchStartBlock,
57
- toBlock: searchEndBlock,
58
- },
59
- )
60
- ).filter(log => log.blockNumber! >= searchStartBlock && log.blockNumber! <= searchEndBlock);
61
-
62
- if (l2BlockProposedLogs.length === 0) {
63
- break;
64
- }
65
-
66
- const lastLog = l2BlockProposedLogs[l2BlockProposedLogs.length - 1];
67
- logger.debug(
68
- `Got ${l2BlockProposedLogs.length} L2 block processed logs for L2 blocks ${l2BlockProposedLogs[0].args.blockNumber}-${lastLog.args.blockNumber} between L1 blocks ${searchStartBlock}-${searchEndBlock}`,
69
- );
70
-
71
- const newBlocks = await processL2BlockProposedLogs(
72
- rollup,
73
- publicClient,
74
- blobSinkClient,
75
- l2BlockProposedLogs,
76
- logger,
77
- );
78
- retrievedBlocks.push(...newBlocks);
79
- searchStartBlock = lastLog.blockNumber! + 1n;
80
- } while (searchStartBlock <= searchEndBlock);
81
-
82
- // The asyncpool from processL2BlockProposedLogs will not necessarily return the blocks in order, so we sort them before returning.
83
- return retrievedBlocks.sort((a, b) => Number(a.l1.blockNumber - b.l1.blockNumber));
84
- }
85
-
86
- /**
87
- * Processes newly received L2BlockProposed logs.
88
- * @param rollup - The rollup contract
89
- * @param publicClient - The viem public client to use for transaction retrieval.
90
- * @param logs - L2BlockProposed logs.
91
- * @returns - An array blocks.
92
- */
93
- export async function processL2BlockProposedLogs(
94
- rollup: GetContractReturnType<typeof RollupAbi, ViemPublicClient>,
95
- publicClient: ViemPublicClient,
96
- blobSinkClient: BlobSinkClientInterface,
97
- logs: GetContractEventsReturnType<typeof RollupAbi, 'L2BlockProposed'>,
98
- logger: Logger,
99
- ): Promise<L1Published<L2Block>[]> {
100
- const retrievedBlocks: L1Published<L2Block>[] = [];
101
- await asyncPool(10, logs, async log => {
102
- const l2BlockNumber = log.args.blockNumber!;
103
- const archive = log.args.archive!;
104
- const archiveFromChain = await rollup.read.archiveAt([l2BlockNumber]);
105
- const blobHashes = log.args.versionedBlobHashes!.map(blobHash => Buffer.from(blobHash.slice(2), 'hex'));
106
-
107
- // The value from the event and contract will match only if the block is in the chain.
108
- if (archive === archiveFromChain) {
109
- const block = await getBlockFromRollupTx(
110
- publicClient,
111
- blobSinkClient,
112
- log.transactionHash!,
113
- blobHashes,
114
- l2BlockNumber,
115
- rollup.address,
116
- logger,
117
- );
118
-
119
- const l1: L1PublishedData = {
120
- blockNumber: log.blockNumber,
121
- blockHash: log.blockHash,
122
- timestamp: await getL1BlockTime(publicClient, log.blockNumber),
123
- };
124
-
125
- retrievedBlocks.push({ data: block, l1 });
126
- } else {
127
- logger.warn(`Ignoring L2 block ${l2BlockNumber} due to archive root mismatch`, {
128
- actual: archive,
129
- expected: archiveFromChain,
130
- });
131
- }
132
- });
133
-
134
- return retrievedBlocks;
135
- }
136
-
137
- export async function getL1BlockTime(publicClient: ViemPublicClient, blockNumber: bigint): Promise<bigint> {
138
- const block = await publicClient.getBlock({ blockNumber, includeTransactions: false });
139
- return block.timestamp;
140
- }
141
-
142
- /**
143
- * Extracts the first 'propose' method calldata from a forwarder transaction's data.
144
- * @param forwarderData - The forwarder transaction input data
145
- * @param rollupAddress - The address of the rollup contract
146
- * @returns The calldata for the first 'propose' method call to the rollup contract
147
- */
148
- function extractRollupProposeCalldata(forwarderData: Hex, rollupAddress: Hex): Hex {
149
- // TODO(#11451): custom forwarders
150
- const { functionName: forwarderFunctionName, args: forwarderArgs } = decodeFunctionData({
151
- abi: ForwarderAbi,
152
- data: forwarderData,
153
- });
154
-
155
- if (forwarderFunctionName !== 'forward') {
156
- throw new Error(`Unexpected forwarder method called ${forwarderFunctionName}`);
157
- }
158
-
159
- if (forwarderArgs.length !== 2) {
160
- throw new Error(`Unexpected number of arguments for forwarder`);
161
- }
162
-
163
- const [to, data] = forwarderArgs;
164
-
165
- // Find all rollup calls
166
- const rollupAddressLower = rollupAddress.toLowerCase();
167
-
168
- for (let i = 0; i < to.length; i++) {
169
- const addr = to[i];
170
- if (addr.toLowerCase() !== rollupAddressLower) {
171
- continue;
172
- }
173
- const callData = data[i];
174
-
175
- try {
176
- const { functionName: rollupFunctionName } = decodeFunctionData({
177
- abi: RollupAbi,
178
- data: callData,
179
- });
180
-
181
- if (rollupFunctionName === 'propose') {
182
- return callData;
183
- }
184
- } catch (err) {
185
- // Skip invalid function data
186
- continue;
187
- }
188
- }
189
-
190
- throw new Error(`Rollup address not found in forwarder args`);
191
- }
192
-
193
- /**
194
- * Gets block from the calldata of an L1 transaction.
195
- * Assumes that the block was published from an EOA.
196
- * TODO: Add retries and error management.
197
- * @param publicClient - The viem public client to use for transaction retrieval.
198
- * @param txHash - Hash of the tx that published it.
199
- * @param l2BlockNum - L2 block number.
200
- * @returns L2 block from the calldata, deserialized
201
- */
202
- async function getBlockFromRollupTx(
203
- publicClient: ViemPublicClient,
204
- blobSinkClient: BlobSinkClientInterface,
205
- txHash: `0x${string}`,
206
- blobHashes: Buffer[], // WORKTODO(md): buffer32?
207
- l2BlockNum: bigint,
208
- rollupAddress: Hex,
209
- logger: Logger,
210
- ): Promise<L2Block> {
211
- const { input: forwarderData, blockHash } = await publicClient.getTransaction({ hash: txHash });
212
-
213
- const rollupData = extractRollupProposeCalldata(forwarderData, rollupAddress);
214
- const { functionName: rollupFunctionName, args: rollupArgs } = decodeFunctionData({
215
- abi: RollupAbi,
216
- data: rollupData,
217
- });
218
-
219
- if (rollupFunctionName !== 'propose') {
220
- throw new Error(`Unexpected rollup method called ${rollupFunctionName}`);
221
- }
222
-
223
- const [decodedArgs, ,] = rollupArgs! as readonly [
224
- {
225
- header: Hex;
226
- archive: Hex;
227
- blockHash: Hex;
228
- oracleInput: {
229
- feeAssetPriceModifier: bigint;
230
- };
231
- txHashes: Hex[];
232
- },
233
- ViemSignature[],
234
- Hex,
235
- ];
236
-
237
- const header = BlockHeader.fromBuffer(Buffer.from(hexToBytes(decodedArgs.header)));
238
- const blobBodies = await blobSinkClient.getBlobSidecar(blockHash, blobHashes);
239
- if (blobBodies.length === 0) {
240
- throw new NoBlobBodiesFoundError(Number(l2BlockNum));
241
- }
242
-
243
- let blockFields: Fr[];
244
- try {
245
- blockFields = Blob.toEncodedFields(blobBodies);
246
- } catch (err: any) {
247
- if (err instanceof BlobDeserializationError) {
248
- logger.fatal(err.message);
249
- } else {
250
- logger.fatal('Unable to sync: failed to decode fetched blob, this blob was likely not created by us');
251
- }
252
- throw err;
253
- }
254
-
255
- // The blob source gives us blockFields, and we must construct the body from them:
256
- const blockBody = Body.fromBlobFields(blockFields);
257
-
258
- const blockNumberFromHeader = header.globalVariables.blockNumber.toBigInt();
259
-
260
- if (blockNumberFromHeader !== l2BlockNum) {
261
- throw new Error(`Block number mismatch: expected ${l2BlockNum} but got ${blockNumberFromHeader}`);
262
- }
263
-
264
- const archive = AppendOnlyTreeSnapshot.fromBuffer(
265
- Buffer.concat([
266
- Buffer.from(hexToBytes(decodedArgs.archive)), // L2Block.archive.root
267
- numToUInt32BE(Number(l2BlockNum + 1n)), // L2Block.archive.nextAvailableLeafIndex
268
- ]),
269
- );
270
-
271
- return new L2Block(archive, header, blockBody);
272
- }
273
-
274
- /**
275
- * Fetch L1 to L2 messages.
276
- * @param publicClient - The viem public client to use for transaction retrieval.
277
- * @param inboxAddress - The address of the inbox contract to fetch messages from.
278
- * @param blockUntilSynced - If true, blocks until the archiver has fully synced.
279
- * @param searchStartBlock - The block number to use for starting the search.
280
- * @param searchEndBlock - The highest block number that we should search up to.
281
- * @returns An array of InboxLeaf and next eth block to search from.
282
- */
283
- export async function retrieveL1ToL2Messages(
284
- inbox: GetContractReturnType<typeof InboxAbi, ViemPublicClient>,
285
- searchStartBlock: bigint,
286
- searchEndBlock: bigint,
287
- ): Promise<DataRetrieval<InboxLeaf>> {
288
- const retrievedL1ToL2Messages: InboxLeaf[] = [];
289
- do {
290
- if (searchStartBlock > searchEndBlock) {
291
- break;
292
- }
293
-
294
- const messageSentLogs = (
295
- await inbox.getEvents.MessageSent(
296
- {},
297
- {
298
- fromBlock: searchStartBlock,
299
- toBlock: searchEndBlock,
300
- },
301
- )
302
- ).filter(log => log.blockNumber! >= searchStartBlock && log.blockNumber! <= searchEndBlock);
303
-
304
- if (messageSentLogs.length === 0) {
305
- break;
306
- }
307
-
308
- for (const log of messageSentLogs) {
309
- const { index, hash } = log.args;
310
- retrievedL1ToL2Messages.push(new InboxLeaf(index!, Fr.fromHexString(hash!)));
311
- }
312
-
313
- // handles the case when there are no new messages:
314
- searchStartBlock = (messageSentLogs.findLast(msgLog => !!msgLog)?.blockNumber || searchStartBlock) + 1n;
315
- } while (searchStartBlock <= searchEndBlock);
316
- return { lastProcessedL1BlockNumber: searchStartBlock - 1n, retrievedData: retrievedL1ToL2Messages };
317
- }
318
-
319
- /** Retrieves L2ProofVerified events from the rollup contract. */
320
- export async function retrieveL2ProofVerifiedEvents(
321
- publicClient: ViemPublicClient,
322
- rollupAddress: EthAddress,
323
- searchStartBlock: bigint,
324
- searchEndBlock?: bigint,
325
- ): Promise<{ l1BlockNumber: bigint; l2BlockNumber: bigint; proverId: Fr; txHash: Hex }[]> {
326
- const logs = await publicClient.getLogs({
327
- address: rollupAddress.toString(),
328
- fromBlock: searchStartBlock,
329
- toBlock: searchEndBlock ? searchEndBlock : undefined,
330
- strict: true,
331
- event: getAbiItem({ abi: RollupAbi, name: 'L2ProofVerified' }),
332
- });
333
-
334
- return logs.map(log => ({
335
- l1BlockNumber: log.blockNumber,
336
- l2BlockNumber: log.args.blockNumber,
337
- proverId: Fr.fromHexString(log.args.proverId),
338
- txHash: log.transactionHash,
339
- }));
340
- }
341
-
342
- /** Retrieve submitted proofs from the rollup contract */
343
- export async function retrieveL2ProofsFromRollup(
344
- publicClient: ViemPublicClient,
345
- rollupAddress: EthAddress,
346
- searchStartBlock: bigint,
347
- searchEndBlock?: bigint,
348
- ): Promise<DataRetrieval<{ proof: Proof; proverId: Fr; l2BlockNumber: bigint; txHash: `0x${string}` }>> {
349
- const logs = await retrieveL2ProofVerifiedEvents(publicClient, rollupAddress, searchStartBlock, searchEndBlock);
350
- const retrievedData: { proof: Proof; proverId: Fr; l2BlockNumber: bigint; txHash: `0x${string}` }[] = [];
351
- const lastProcessedL1BlockNumber = logs.length > 0 ? logs.at(-1)!.l1BlockNumber : searchStartBlock - 1n;
352
-
353
- for (const { txHash, proverId, l2BlockNumber } of logs) {
354
- const proofData = await getProofFromSubmitProofTx(publicClient, txHash, proverId);
355
- retrievedData.push({ proof: proofData.proof, proverId: proofData.proverId, l2BlockNumber, txHash });
356
- }
357
- return {
358
- retrievedData,
359
- lastProcessedL1BlockNumber,
360
- };
361
- }
362
-
363
- export type SubmitBlockProof = {
364
- archiveRoot: Fr;
365
- proverId: Fr;
366
- aggregationObject: Buffer;
367
- proof: Proof;
368
- };
369
-
370
- /**
371
- * Gets block metadata (header and archive snapshot) from the calldata of an L1 transaction.
372
- * Assumes that the block was published from an EOA.
373
- * TODO: Add retries and error management.
374
- * @param publicClient - The viem public client to use for transaction retrieval.
375
- * @param txHash - Hash of the tx that published it.
376
- * @param l2BlockNum - L2 block number.
377
- * @returns L2 block metadata (header and archive) from the calldata, deserialized
378
- */
379
- export async function getProofFromSubmitProofTx(
380
- publicClient: ViemPublicClient,
381
- txHash: `0x${string}`,
382
- expectedProverId: Fr,
383
- ): Promise<SubmitBlockProof> {
384
- const { input: data } = await publicClient.getTransaction({ hash: txHash });
385
- const { functionName, args } = decodeFunctionData({ abi: RollupAbi, data });
386
-
387
- let proverId: Fr;
388
- let archiveRoot: Fr;
389
- let aggregationObject: Buffer;
390
- let proof: Proof;
391
-
392
- if (functionName === 'submitEpochRootProof') {
393
- const [decodedArgs] = args as readonly [
394
- {
395
- start: bigint;
396
- end: bigint;
397
- args: EpochProofPublicInputArgs;
398
- fees: readonly Hex[];
399
- aggregationObject: Hex;
400
- proof: Hex;
401
- },
402
- ];
403
-
404
- aggregationObject = Buffer.from(hexToBytes(decodedArgs.aggregationObject));
405
- proverId = Fr.fromHexString(decodedArgs.args.proverId);
406
- archiveRoot = Fr.fromHexString(decodedArgs.args.endArchive);
407
- proof = Proof.fromBuffer(Buffer.from(hexToBytes(decodedArgs.proof)));
408
- } else {
409
- throw new Error(`Unexpected proof method called ${functionName}`);
410
- }
411
-
412
- if (!proverId.equals(expectedProverId)) {
413
- throw new Error(`Prover ID mismatch: expected ${expectedProverId} but got ${proverId}`);
414
- }
415
-
416
- return {
417
- proverId,
418
- aggregationObject,
419
- archiveRoot,
420
- proof,
421
- };
422
- }
@@ -1,5 +0,0 @@
1
- export class NoBlobBodiesFoundError extends Error {
2
- constructor(l2BlockNum: number) {
3
- super(`No blob bodies found for block ${l2BlockNum}`);
4
- }
5
- }
@@ -1,7 +0,0 @@
1
- export * from './archiver.js';
2
- export * from './config.js';
3
- export { type L1Published, type L1PublishedData } from './structs/published.js';
4
- export { MemoryArchiverStore } from './memory_archiver_store/memory_archiver_store.js';
5
- export type { ArchiverDataStore } from './archiver_store.js';
6
- export { KVArchiverDataStore } from './kv_archiver_store/kv_archiver_store.js';
7
- export { ContractInstanceStore } from './kv_archiver_store/contract_instance_store.js';
@@ -1,132 +0,0 @@
1
- import { createLogger } from '@aztec/foundation/log';
2
- import type { L2Block } from '@aztec/stdlib/block';
3
- import {
4
- Attributes,
5
- type Gauge,
6
- type Histogram,
7
- LmdbMetrics,
8
- type LmdbStatsCallback,
9
- Metrics,
10
- type TelemetryClient,
11
- type Tracer,
12
- type UpDownCounter,
13
- ValueType,
14
- } from '@aztec/telemetry-client';
15
-
16
- export class ArchiverInstrumentation {
17
- public readonly tracer: Tracer;
18
-
19
- private blockHeight: Gauge;
20
- private txCount: UpDownCounter;
21
- private syncDuration: Histogram;
22
- private l1BlocksSynced: UpDownCounter;
23
- private l1BlockHeight: Gauge;
24
- private proofsSubmittedDelay: Histogram;
25
- private proofsSubmittedCount: UpDownCounter;
26
- private dbMetrics: LmdbMetrics;
27
- private pruneCount: UpDownCounter;
28
-
29
- private log = createLogger('archiver:instrumentation');
30
-
31
- private constructor(private telemetry: TelemetryClient, lmdbStats?: LmdbStatsCallback) {
32
- this.tracer = telemetry.getTracer('Archiver');
33
- const meter = telemetry.getMeter('Archiver');
34
- this.blockHeight = meter.createGauge(Metrics.ARCHIVER_BLOCK_HEIGHT, {
35
- description: 'The height of the latest block processed by the archiver',
36
- valueType: ValueType.INT,
37
- });
38
-
39
- this.txCount = meter.createUpDownCounter(Metrics.ARCHIVER_TX_COUNT, {
40
- description: 'The total number of transactions',
41
- valueType: ValueType.INT,
42
- });
43
-
44
- this.syncDuration = meter.createHistogram(Metrics.ARCHIVER_SYNC_DURATION, {
45
- unit: 'ms',
46
- description: 'Duration to sync a block',
47
- valueType: ValueType.INT,
48
- });
49
-
50
- this.proofsSubmittedCount = meter.createUpDownCounter(Metrics.ARCHIVER_ROLLUP_PROOF_COUNT, {
51
- description: 'Number of proofs submitted',
52
- valueType: ValueType.INT,
53
- });
54
-
55
- this.proofsSubmittedDelay = meter.createHistogram(Metrics.ARCHIVER_ROLLUP_PROOF_DELAY, {
56
- unit: 'ms',
57
- description: 'Time after a block is submitted until its proof is published',
58
- valueType: ValueType.INT,
59
- });
60
-
61
- this.l1BlocksSynced = meter.createUpDownCounter(Metrics.ARCHIVER_L1_BLOCKS_SYNCED, {
62
- description: 'Number of blocks synced from L1',
63
- valueType: ValueType.INT,
64
- });
65
-
66
- this.l1BlockHeight = meter.createGauge(Metrics.ARCHIVER_L1_BLOCK_HEIGHT, {
67
- description: 'The height of the latest L1 block processed by the archiver',
68
- valueType: ValueType.INT,
69
- });
70
-
71
- this.dbMetrics = new LmdbMetrics(
72
- meter,
73
- {
74
- [Attributes.DB_DATA_TYPE]: 'archiver',
75
- },
76
- lmdbStats,
77
- );
78
-
79
- this.pruneCount = meter.createUpDownCounter(Metrics.ARCHIVER_PRUNE_COUNT, {
80
- description: 'Number of prunes detected',
81
- valueType: ValueType.INT,
82
- });
83
- }
84
-
85
- public static async new(telemetry: TelemetryClient, lmdbStats?: LmdbStatsCallback) {
86
- const instance = new ArchiverInstrumentation(telemetry, lmdbStats);
87
-
88
- instance.l1BlocksSynced.add(0);
89
-
90
- await instance.telemetry.flush();
91
-
92
- return instance;
93
- }
94
-
95
- public isEnabled(): boolean {
96
- return this.telemetry.isEnabled();
97
- }
98
-
99
- public processNewBlocks(syncTimePerBlock: number, blocks: L2Block[]) {
100
- this.syncDuration.record(Math.ceil(syncTimePerBlock));
101
- this.blockHeight.record(Math.max(...blocks.map(b => b.number)));
102
- this.l1BlocksSynced.add(blocks.length);
103
- for (const block of blocks) {
104
- this.txCount.add(block.body.txEffects.length);
105
- }
106
- }
107
-
108
- public processPrune() {
109
- this.pruneCount.add(1);
110
- }
111
-
112
- public updateLastProvenBlock(blockNumber: number) {
113
- this.blockHeight.record(blockNumber, { [Attributes.STATUS]: 'proven' });
114
- }
115
-
116
- public processProofsVerified(logs: { proverId: string; l2BlockNumber: bigint; delay: bigint }[]) {
117
- for (const log of logs) {
118
- this.log.debug('Recording proof verified event', log);
119
- this.proofsSubmittedCount.add(1, {
120
- [Attributes.ROLLUP_PROVER_ID]: log.proverId,
121
- [Attributes.PROOF_TIMED_OUT]: log.delay > 20n * 60n * 1000n,
122
- });
123
- this.proofsSubmittedDelay.record(Math.ceil(Number(log.delay)), {
124
- [Attributes.ROLLUP_PROVER_ID]: log.proverId,
125
- });
126
- }
127
- }
128
-
129
- public updateL1BlockHeight(blockNumber: bigint) {
130
- this.l1BlockHeight.record(Number(blockNumber));
131
- }
132
- }