@aztec/archiver 0.0.0-test.0 → 0.0.1-commit.24de95ac

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 (102) hide show
  1. package/README.md +27 -6
  2. package/dest/archiver/archiver.d.ts +126 -46
  3. package/dest/archiver/archiver.d.ts.map +1 -1
  4. package/dest/archiver/archiver.js +683 -261
  5. package/dest/archiver/archiver_store.d.ts +84 -49
  6. package/dest/archiver/archiver_store.d.ts.map +1 -1
  7. package/dest/archiver/archiver_store_test_suite.d.ts.map +1 -1
  8. package/dest/archiver/archiver_store_test_suite.js +707 -213
  9. package/dest/archiver/config.d.ts +4 -20
  10. package/dest/archiver/config.d.ts.map +1 -1
  11. package/dest/archiver/config.js +16 -12
  12. package/dest/archiver/data_retrieval.d.ts +25 -20
  13. package/dest/archiver/data_retrieval.d.ts.map +1 -1
  14. package/dest/archiver/data_retrieval.js +147 -68
  15. package/dest/archiver/errors.d.ts +8 -0
  16. package/dest/archiver/errors.d.ts.map +1 -1
  17. package/dest/archiver/errors.js +12 -0
  18. package/dest/archiver/index.d.ts +2 -3
  19. package/dest/archiver/index.d.ts.map +1 -1
  20. package/dest/archiver/index.js +1 -2
  21. package/dest/archiver/instrumentation.d.ts +9 -3
  22. package/dest/archiver/instrumentation.d.ts.map +1 -1
  23. package/dest/archiver/instrumentation.js +58 -17
  24. package/dest/archiver/kv_archiver_store/block_store.d.ts +47 -10
  25. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
  26. package/dest/archiver/kv_archiver_store/block_store.js +216 -63
  27. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +2 -2
  28. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +1 -1
  29. package/dest/archiver/kv_archiver_store/contract_class_store.js +12 -18
  30. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +10 -7
  31. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +1 -1
  32. package/dest/archiver/kv_archiver_store/contract_instance_store.js +30 -16
  33. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +49 -34
  34. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
  35. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +88 -46
  36. package/dest/archiver/kv_archiver_store/log_store.d.ts +1 -1
  37. package/dest/archiver/kv_archiver_store/log_store.d.ts.map +1 -1
  38. package/dest/archiver/kv_archiver_store/log_store.js +18 -46
  39. package/dest/archiver/kv_archiver_store/message_store.d.ts +22 -16
  40. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +1 -1
  41. package/dest/archiver/kv_archiver_store/message_store.js +150 -48
  42. package/dest/archiver/structs/inbox_message.d.ts +15 -0
  43. package/dest/archiver/structs/inbox_message.d.ts.map +1 -0
  44. package/dest/archiver/structs/inbox_message.js +38 -0
  45. package/dest/archiver/structs/published.d.ts +1 -10
  46. package/dest/archiver/structs/published.d.ts.map +1 -1
  47. package/dest/archiver/structs/published.js +1 -1
  48. package/dest/archiver/validation.d.ts +11 -0
  49. package/dest/archiver/validation.d.ts.map +1 -0
  50. package/dest/archiver/validation.js +90 -0
  51. package/dest/factory.d.ts +7 -12
  52. package/dest/factory.d.ts.map +1 -1
  53. package/dest/factory.js +18 -49
  54. package/dest/rpc/index.d.ts +1 -2
  55. package/dest/rpc/index.d.ts.map +1 -1
  56. package/dest/rpc/index.js +1 -4
  57. package/dest/test/mock_archiver.d.ts +1 -1
  58. package/dest/test/mock_l1_to_l2_message_source.d.ts +4 -2
  59. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  60. package/dest/test/mock_l1_to_l2_message_source.js +14 -1
  61. package/dest/test/mock_l2_block_source.d.ts +32 -5
  62. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  63. package/dest/test/mock_l2_block_source.js +118 -7
  64. package/dest/test/mock_structs.d.ts +9 -0
  65. package/dest/test/mock_structs.d.ts.map +1 -0
  66. package/dest/test/mock_structs.js +37 -0
  67. package/package.json +25 -27
  68. package/src/archiver/archiver.ts +858 -317
  69. package/src/archiver/archiver_store.ts +97 -55
  70. package/src/archiver/archiver_store_test_suite.ts +663 -210
  71. package/src/archiver/config.ts +23 -41
  72. package/src/archiver/data_retrieval.ts +215 -92
  73. package/src/archiver/errors.ts +21 -0
  74. package/src/archiver/index.ts +2 -3
  75. package/src/archiver/instrumentation.ts +75 -20
  76. package/src/archiver/kv_archiver_store/block_store.ts +270 -72
  77. package/src/archiver/kv_archiver_store/contract_class_store.ts +13 -23
  78. package/src/archiver/kv_archiver_store/contract_instance_store.ts +35 -27
  79. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +127 -63
  80. package/src/archiver/kv_archiver_store/log_store.ts +24 -62
  81. package/src/archiver/kv_archiver_store/message_store.ts +209 -53
  82. package/src/archiver/structs/inbox_message.ts +41 -0
  83. package/src/archiver/structs/published.ts +1 -11
  84. package/src/archiver/validation.ts +99 -0
  85. package/src/factory.ts +24 -66
  86. package/src/rpc/index.ts +1 -5
  87. package/src/test/mock_archiver.ts +1 -1
  88. package/src/test/mock_l1_to_l2_message_source.ts +14 -3
  89. package/src/test/mock_l2_block_source.ts +152 -8
  90. package/src/test/mock_structs.ts +49 -0
  91. package/dest/archiver/kv_archiver_store/nullifier_store.d.ts +0 -12
  92. package/dest/archiver/kv_archiver_store/nullifier_store.d.ts.map +0 -1
  93. package/dest/archiver/kv_archiver_store/nullifier_store.js +0 -73
  94. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts +0 -23
  95. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts.map +0 -1
  96. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.js +0 -49
  97. package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts +0 -175
  98. package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts.map +0 -1
  99. package/dest/archiver/memory_archiver_store/memory_archiver_store.js +0 -636
  100. package/src/archiver/kv_archiver_store/nullifier_store.ts +0 -97
  101. package/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts +0 -61
  102. package/src/archiver/memory_archiver_store/memory_archiver_store.ts +0 -801
@@ -1,32 +1,16 @@
1
1
  import { type BlobSinkConfig } from '@aztec/blob-sink/client';
2
- import { type L1ContractAddresses, type L1ContractsConfig, type L1ReaderConfig } from '@aztec/ethereum';
2
+ import { type L1ContractsConfig, type L1ReaderConfig } from '@aztec/ethereum';
3
3
  import { type ConfigMappingsType } from '@aztec/foundation/config';
4
4
  import { type ChainConfig } from '@aztec/stdlib/config';
5
+ import type { ArchiverSpecificConfig } from '@aztec/stdlib/interfaces/server';
5
6
  /**
7
+ * The archiver configuration.
6
8
  * There are 2 polling intervals used in this configuration. The first is the archiver polling interval, archiverPollingIntervalMS.
7
9
  * This is the interval between successive calls to eth_blockNumber via viem.
8
10
  * Results of calls to eth_blockNumber are cached by viem with this cache being updated periodically at the interval specified by viemPollingIntervalMS.
9
11
  * As a result the maximum observed polling time for new blocks will be viemPollingIntervalMS + archiverPollingIntervalMS.
10
12
  */
11
- /**
12
- * The archiver configuration.
13
- */
14
- export type ArchiverConfig = {
15
- /** URL for an archiver service. If set, will return an archiver client as opposed to starting a new one. */
16
- archiverUrl?: string;
17
- /** URL for an L1 consensus client */
18
- l1ConsensusHostUrl?: string;
19
- /** The polling interval in ms for retrieving new L2 blocks and encrypted logs. */
20
- archiverPollingIntervalMS?: number;
21
- /** The number of L2 blocks the archiver will attempt to download at a time. */
22
- archiverBatchSize?: number;
23
- /** The polling interval viem uses in ms */
24
- viemPollingIntervalMS?: number;
25
- /** The deployed L1 contract addresses */
26
- l1Contracts: L1ContractAddresses;
27
- /** The max number of logs that can be obtained in 1 "getPublicLogs" call. */
28
- maxLogs?: number;
29
- } & L1ReaderConfig & L1ContractsConfig & BlobSinkConfig & ChainConfig;
13
+ export type ArchiverConfig = ArchiverSpecificConfig & L1ReaderConfig & L1ContractsConfig & BlobSinkConfig & ChainConfig;
30
14
  export declare const archiverConfigMappings: ConfigMappingsType<ArchiverConfig>;
31
15
  /**
32
16
  * Returns the archiver configuration from the environment variables.
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/archiver/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAyB,MAAM,yBAAyB,CAAC;AACrF,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EAGpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,KAAK,kBAAkB,EAA6C,MAAM,0BAA0B,CAAC;AAC9G,OAAO,EAAE,KAAK,WAAW,EAAuB,MAAM,sBAAsB,CAAC;AAE7E;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,4GAA4G;IAC5G,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,qCAAqC;IACrC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B,kFAAkF;IAClF,yBAAyB,CAAC,EAAE,MAAM,CAAC;IAEnC,+EAA+E;IAC/E,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B,2CAA2C;IAC3C,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B,yCAAyC;IACzC,WAAW,EAAE,mBAAmB,CAAC;IAEjC,6EAA6E;IAC7E,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,cAAc,GAChB,iBAAiB,GACjB,cAAc,GACd,WAAW,CAAC;AAEd,eAAO,MAAM,sBAAsB,EAAE,kBAAkB,CAAC,cAAc,CAmCrE,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,wBAAwB,IAAI,cAAc,CAEzD"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/archiver/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAyB,MAAM,yBAAyB,CAAC;AACrF,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,cAAc,EAIpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,KAAK,kBAAkB,EAIxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,WAAW,EAAuB,MAAM,sBAAsB,CAAC;AAC7E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAE9E;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,sBAAsB,GAAG,cAAc,GAAG,iBAAiB,GAAG,cAAc,GAAG,WAAW,CAAC;AAExH,eAAO,MAAM,sBAAsB,EAAE,kBAAkB,CAAC,cAAc,CAsCrE,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,wBAAwB,IAAI,cAAc,CAEzD"}
@@ -1,18 +1,9 @@
1
1
  import { blobSinkConfigMapping } from '@aztec/blob-sink/client';
2
- import { l1ContractsConfigMappings, l1ReaderConfigMappings } from '@aztec/ethereum';
3
- import { getConfigFromMappings, numberConfigHelper } from '@aztec/foundation/config';
2
+ import { l1ContractAddressesMapping, l1ContractsConfigMappings, l1ReaderConfigMappings } from '@aztec/ethereum';
3
+ import { booleanConfigHelper, getConfigFromMappings, numberConfigHelper } from '@aztec/foundation/config';
4
4
  import { chainConfigMappings } from '@aztec/stdlib/config';
5
5
  export const archiverConfigMappings = {
6
6
  ...blobSinkConfigMapping,
7
- archiverUrl: {
8
- env: 'ARCHIVER_URL',
9
- description: 'URL for an archiver service. If set, will return an archiver client as opposed to starting a new one.'
10
- },
11
- l1ConsensusHostUrl: {
12
- env: 'L1_CONSENSUS_HOST_URL',
13
- description: 'URL for an L1 consensus client.',
14
- parseEnv: (val)=>val
15
- },
16
7
  archiverPollingIntervalMS: {
17
8
  env: 'ARCHIVER_POLLING_INTERVAL_MS',
18
9
  description: 'The polling interval in ms for retrieving new L2 blocks and encrypted logs.',
@@ -28,6 +19,15 @@ export const archiverConfigMappings = {
28
19
  description: 'The max number of logs that can be obtained in 1 "getPublicLogs" call.',
29
20
  ...numberConfigHelper(1_000)
30
21
  },
22
+ archiverStoreMapSizeKb: {
23
+ env: 'ARCHIVER_STORE_MAP_SIZE_KB',
24
+ parseEnv: (val)=>val ? +val : undefined,
25
+ description: 'The maximum possible size of the archiver DB in KB. Overwrites the general dataStoreMapSizeKb.'
26
+ },
27
+ skipValidateBlockAttestations: {
28
+ description: 'Whether to skip validating block attestations (use only for testing).',
29
+ ...booleanConfigHelper(false)
30
+ },
31
31
  ...chainConfigMappings,
32
32
  ...l1ReaderConfigMappings,
33
33
  viemPollingIntervalMS: {
@@ -35,7 +35,11 @@ export const archiverConfigMappings = {
35
35
  description: 'The polling interval viem uses in ms',
36
36
  ...numberConfigHelper(1000)
37
37
  },
38
- ...l1ContractsConfigMappings
38
+ ...l1ContractsConfigMappings,
39
+ l1Contracts: {
40
+ description: 'The deployed L1 contract addresses',
41
+ nested: l1ContractAddressesMapping
42
+ }
39
43
  };
40
44
  /**
41
45
  * Returns the archiver configuration from the environment variables.
@@ -1,17 +1,29 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
1
  import type { BlobSinkClientInterface } from '@aztec/blob-sink/client';
4
- import type { ViemPublicClient } from '@aztec/ethereum';
2
+ import type { ViemClient, ViemPublicClient } from '@aztec/ethereum';
5
3
  import type { EthAddress } from '@aztec/foundation/eth-address';
6
4
  import { Fr } from '@aztec/foundation/fields';
7
5
  import { type Logger } from '@aztec/foundation/log';
8
6
  import { type InboxAbi, RollupAbi } from '@aztec/l1-artifacts';
9
- import { L2Block } from '@aztec/stdlib/block';
10
- import { InboxLeaf } from '@aztec/stdlib/messaging';
7
+ import { CommitteeAttestation, PublishedL2Block } from '@aztec/stdlib/block';
11
8
  import { Proof } from '@aztec/stdlib/proofs';
12
- import { type GetContractEventsReturnType, type GetContractReturnType, type Hex } from 'viem';
9
+ import { CheckpointHeader } from '@aztec/stdlib/rollup';
10
+ import { StateReference } from '@aztec/stdlib/tx';
11
+ import { type GetContractReturnType, type Hex } from 'viem';
13
12
  import type { DataRetrieval } from './structs/data_retrieval.js';
14
- import type { L1Published } from './structs/published.js';
13
+ import type { InboxMessage } from './structs/inbox_message.js';
14
+ import type { L1PublishedData } from './structs/published.js';
15
+ export type RetrievedL2Block = {
16
+ l2BlockNumber: number;
17
+ archiveRoot: Fr;
18
+ stateReference: StateReference;
19
+ header: CheckpointHeader;
20
+ blobFields: Fr[];
21
+ l1: L1PublishedData;
22
+ chainId: Fr;
23
+ version: Fr;
24
+ attestations: CommitteeAttestation[];
25
+ };
26
+ export declare function retrievedBlockToPublishedL2Block(retrievedBlock: RetrievedL2Block): Promise<PublishedL2Block>;
15
27
  /**
16
28
  * Fetches new L2 blocks.
17
29
  * @param publicClient - The viem public client to use for transaction retrieval.
@@ -21,16 +33,10 @@ import type { L1Published } from './structs/published.js';
21
33
  * @param expectedNextL2BlockNum - The next L2 block number that we expect to find.
22
34
  * @returns An array of block; as well as the next eth block to search from.
23
35
  */
24
- export declare function retrieveBlocksFromRollup(rollup: GetContractReturnType<typeof RollupAbi, ViemPublicClient>, publicClient: ViemPublicClient, blobSinkClient: BlobSinkClientInterface, searchStartBlock: bigint, searchEndBlock: bigint, logger?: Logger): Promise<L1Published<L2Block>[]>;
25
- /**
26
- * Processes newly received L2BlockProposed logs.
27
- * @param rollup - The rollup contract
28
- * @param publicClient - The viem public client to use for transaction retrieval.
29
- * @param logs - L2BlockProposed logs.
30
- * @returns - An array blocks.
31
- */
32
- export declare function processL2BlockProposedLogs(rollup: GetContractReturnType<typeof RollupAbi, ViemPublicClient>, publicClient: ViemPublicClient, blobSinkClient: BlobSinkClientInterface, logs: GetContractEventsReturnType<typeof RollupAbi, 'L2BlockProposed'>, logger: Logger): Promise<L1Published<L2Block>[]>;
36
+ export declare function retrieveBlocksFromRollup(rollup: GetContractReturnType<typeof RollupAbi, ViemPublicClient>, publicClient: ViemPublicClient, blobSinkClient: BlobSinkClientInterface, searchStartBlock: bigint, searchEndBlock: bigint, logger?: Logger): Promise<RetrievedL2Block[]>;
33
37
  export declare function getL1BlockTime(publicClient: ViemPublicClient, blockNumber: bigint): Promise<bigint>;
38
+ /** Given an L1 to L2 message, retrieves its corresponding event from the Inbox within a specific block range. */
39
+ export declare function retrieveL1ToL2Message(inbox: GetContractReturnType<typeof InboxAbi, ViemClient>, leaf: Fr, fromBlock: bigint, toBlock: bigint): Promise<InboxMessage | undefined>;
34
40
  /**
35
41
  * Fetch L1 to L2 messages.
36
42
  * @param publicClient - The viem public client to use for transaction retrieval.
@@ -40,11 +46,11 @@ export declare function getL1BlockTime(publicClient: ViemPublicClient, blockNumb
40
46
  * @param searchEndBlock - The highest block number that we should search up to.
41
47
  * @returns An array of InboxLeaf and next eth block to search from.
42
48
  */
43
- export declare function retrieveL1ToL2Messages(inbox: GetContractReturnType<typeof InboxAbi, ViemPublicClient>, searchStartBlock: bigint, searchEndBlock: bigint): Promise<DataRetrieval<InboxLeaf>>;
49
+ export declare function retrieveL1ToL2Messages(inbox: GetContractReturnType<typeof InboxAbi, ViemClient>, searchStartBlock: bigint, searchEndBlock: bigint): Promise<InboxMessage[]>;
44
50
  /** Retrieves L2ProofVerified events from the rollup contract. */
45
51
  export declare function retrieveL2ProofVerifiedEvents(publicClient: ViemPublicClient, rollupAddress: EthAddress, searchStartBlock: bigint, searchEndBlock?: bigint): Promise<{
46
52
  l1BlockNumber: bigint;
47
- l2BlockNumber: bigint;
53
+ l2BlockNumber: number;
48
54
  proverId: Fr;
49
55
  txHash: Hex;
50
56
  }[]>;
@@ -52,13 +58,12 @@ export declare function retrieveL2ProofVerifiedEvents(publicClient: ViemPublicCl
52
58
  export declare function retrieveL2ProofsFromRollup(publicClient: ViemPublicClient, rollupAddress: EthAddress, searchStartBlock: bigint, searchEndBlock?: bigint): Promise<DataRetrieval<{
53
59
  proof: Proof;
54
60
  proverId: Fr;
55
- l2BlockNumber: bigint;
61
+ l2BlockNumber: number;
56
62
  txHash: `0x${string}`;
57
63
  }>>;
58
64
  export type SubmitBlockProof = {
59
65
  archiveRoot: Fr;
60
66
  proverId: Fr;
61
- aggregationObject: Buffer;
62
67
  proof: Proof;
63
68
  };
64
69
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"data_retrieval.d.ts","sourceRoot":"","sources":["../../src/archiver/data_retrieval.ts"],"names":[],"mappings":";;AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,KAAK,EAA6B,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAElE,OAAO,EAAgB,KAAK,QAAQ,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC7E,OAAO,EAAQ,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAI7C,OAAO,EACL,KAAK,2BAA2B,EAChC,KAAK,qBAAqB,EAC1B,KAAK,GAAG,EAIT,MAAM,MAAM,CAAC;AAGd,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAmB,MAAM,wBAAwB,CAAC;AAE3E;;;;;;;;GAQG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,qBAAqB,CAAC,OAAO,SAAS,EAAE,gBAAgB,CAAC,EACjE,YAAY,EAAE,gBAAgB,EAC9B,cAAc,EAAE,uBAAuB,EACvC,gBAAgB,EAAE,MAAM,EACxB,cAAc,EAAE,MAAM,EACtB,MAAM,GAAE,MAAiC,GACxC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC,CAsCjC;AAED;;;;;;GAMG;AACH,wBAAsB,0BAA0B,CAC9C,MA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GACrB,OAAO,CAAC,YAAY,EAAE,CAAC,CAgBzB;AAgBD,iEAAiE;AACjE,wBAAsB,6BAA6B,CACjD,YAAY,EAAE,gBAAgB,EAC9B,aAAa,EAAE,UAAU,EACzB,gBAAgB,EAAE,MAAM,EACxB,cAAc,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,EAAE,CAAC;IAAC,MAAM,EAAE,GAAG,CAAA;CAAE,EAAE,CAAC,CAexF;AAED,yDAAyD;AACzD,wBAAsB,0BAA0B,CAC9C,YAAY,EAAE,gBAAgB,EAC9B,aAAa,EAAE,UAAU,EACzB,gBAAgB,EAAE,MAAM,EACxB,cAAc,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,aAAa,CAAC;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,EAAE,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,KAAK,MAAM,EAAE,CAAA;CAAE,CAAC,CAAC,CAatG;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,EAAE,EAAE,CAAC;IAChB,QAAQ,EAAE,EAAE,CAAC;IACb,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAsB,yBAAyB,CAC7C,YAAY,EAAE,gBAAgB,EAC9B,MAAM,EAAE,KAAK,MAAM,EAAE,EACrB,gBAAgB,EAAE,EAAE,GACnB,OAAO,CAAC,gBAAgB,CAAC,CAmC3B"}
@@ -1,16 +1,54 @@
1
- import { Blob, BlobDeserializationError } from '@aztec/blob-lib';
1
+ import { BlobDeserializationError, SpongeBlob, getBlobFieldsInCheckpoint } from '@aztec/blob-lib';
2
2
  import { asyncPool } from '@aztec/foundation/async-pool';
3
+ import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
3
4
  import { Fr } from '@aztec/foundation/fields';
4
5
  import { createLogger } from '@aztec/foundation/log';
5
- import { numToUInt32BE } from '@aztec/foundation/serialize';
6
- import { ForwarderAbi, RollupAbi } from '@aztec/l1-artifacts';
7
- import { Body, L2Block } from '@aztec/stdlib/block';
8
- import { InboxLeaf } from '@aztec/stdlib/messaging';
6
+ import { RollupAbi } from '@aztec/l1-artifacts';
7
+ import { Body, CommitteeAttestation, L2Block, L2BlockHeader, PublishedL2Block } from '@aztec/stdlib/block';
9
8
  import { Proof } from '@aztec/stdlib/proofs';
9
+ import { CheckpointHeader } from '@aztec/stdlib/rollup';
10
10
  import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
11
- import { BlockHeader } from '@aztec/stdlib/tx';
12
- import { decodeFunctionData, getAbiItem, hexToBytes } from 'viem';
11
+ import { GlobalVariables, StateReference } from '@aztec/stdlib/tx';
12
+ import { decodeFunctionData, getAbiItem, hexToBytes, multicall3Abi } from 'viem';
13
13
  import { NoBlobBodiesFoundError } from './errors.js';
14
+ export async function retrievedBlockToPublishedL2Block(retrievedBlock) {
15
+ const { l2BlockNumber, archiveRoot, stateReference, header: checkpointHeader, blobFields, l1, chainId, version, attestations } = retrievedBlock;
16
+ const archive = new AppendOnlyTreeSnapshot(archiveRoot, l2BlockNumber + 1);
17
+ const globalVariables = GlobalVariables.from({
18
+ chainId,
19
+ version,
20
+ blockNumber: l2BlockNumber,
21
+ slotNumber: checkpointHeader.slotNumber,
22
+ timestamp: checkpointHeader.timestamp,
23
+ coinbase: checkpointHeader.coinbase,
24
+ feeRecipient: checkpointHeader.feeRecipient,
25
+ gasFees: checkpointHeader.gasFees
26
+ });
27
+ // TODO(#17027)
28
+ // This works when there's only one block in the checkpoint.
29
+ // If there's more than one block, we need to build the spongeBlob from the endSpongeBlob of the previous block.
30
+ const spongeBlob = await SpongeBlob.init(blobFields.length);
31
+ // Skip the first field which is the checkpoint prefix indicating the number of total blob fields in a checkpoint.
32
+ const blockBlobFields = blobFields.slice(1);
33
+ await spongeBlob.absorb(blockBlobFields);
34
+ const spongeBlobHash = await spongeBlob.squeeze();
35
+ const body = Body.fromBlobFields(blockBlobFields);
36
+ const header = L2BlockHeader.from({
37
+ lastArchive: new AppendOnlyTreeSnapshot(checkpointHeader.lastArchiveRoot, l2BlockNumber),
38
+ contentCommitment: checkpointHeader.contentCommitment,
39
+ state: stateReference,
40
+ globalVariables,
41
+ totalFees: body.txEffects.reduce((accum, txEffect)=>accum.add(txEffect.transactionFee), Fr.ZERO),
42
+ totalManaUsed: checkpointHeader.totalManaUsed,
43
+ spongeBlobHash
44
+ });
45
+ const block = new L2Block(archive, header, body);
46
+ return PublishedL2Block.fromFields({
47
+ block,
48
+ l1,
49
+ attestations
50
+ });
51
+ }
14
52
  /**
15
53
  * Fetches new L2 blocks.
16
54
  * @param publicClient - The viem public client to use for transaction retrieval.
@@ -21,6 +59,7 @@ import { NoBlobBodiesFoundError } from './errors.js';
21
59
  * @returns An array of block; as well as the next eth block to search from.
22
60
  */ export async function retrieveBlocksFromRollup(rollup, publicClient, blobSinkClient, searchStartBlock, searchEndBlock, logger = createLogger('archiver')) {
23
61
  const retrievedBlocks = [];
62
+ let rollupConstants;
24
63
  do {
25
64
  if (searchStartBlock > searchEndBlock) {
26
65
  break;
@@ -34,7 +73,19 @@ import { NoBlobBodiesFoundError } from './errors.js';
34
73
  }
35
74
  const lastLog = l2BlockProposedLogs[l2BlockProposedLogs.length - 1];
36
75
  logger.debug(`Got ${l2BlockProposedLogs.length} L2 block processed logs for L2 blocks ${l2BlockProposedLogs[0].args.blockNumber}-${lastLog.args.blockNumber} between L1 blocks ${searchStartBlock}-${searchEndBlock}`);
37
- const newBlocks = await processL2BlockProposedLogs(rollup, publicClient, blobSinkClient, l2BlockProposedLogs, logger);
76
+ if (rollupConstants === undefined) {
77
+ const [chainId, version, targetCommitteeSize] = await Promise.all([
78
+ publicClient.getChainId(),
79
+ rollup.read.getVersion(),
80
+ rollup.read.getTargetCommitteeSize()
81
+ ]);
82
+ rollupConstants = {
83
+ chainId: new Fr(chainId),
84
+ version: new Fr(version),
85
+ targetCommitteeSize: Number(targetCommitteeSize)
86
+ };
87
+ }
88
+ const newBlocks = await processL2BlockProposedLogs(rollup, publicClient, blobSinkClient, l2BlockProposedLogs, rollupConstants, logger);
38
89
  retrievedBlocks.push(...newBlocks);
39
90
  searchStartBlock = lastLog.blockNumber + 1n;
40
91
  }while (searchStartBlock <= searchEndBlock)
@@ -47,26 +98,34 @@ import { NoBlobBodiesFoundError } from './errors.js';
47
98
  * @param publicClient - The viem public client to use for transaction retrieval.
48
99
  * @param logs - L2BlockProposed logs.
49
100
  * @returns - An array blocks.
50
- */ export async function processL2BlockProposedLogs(rollup, publicClient, blobSinkClient, logs, logger) {
101
+ */ async function processL2BlockProposedLogs(rollup, publicClient, blobSinkClient, logs, { chainId, version, targetCommitteeSize }, logger) {
51
102
  const retrievedBlocks = [];
52
103
  await asyncPool(10, logs, async (log)=>{
53
- const l2BlockNumber = log.args.blockNumber;
104
+ const l2BlockNumber = Number(log.args.blockNumber);
54
105
  const archive = log.args.archive;
55
106
  const archiveFromChain = await rollup.read.archiveAt([
56
- l2BlockNumber
107
+ BigInt(l2BlockNumber)
57
108
  ]);
58
109
  const blobHashes = log.args.versionedBlobHashes.map((blobHash)=>Buffer.from(blobHash.slice(2), 'hex'));
59
110
  // The value from the event and contract will match only if the block is in the chain.
60
111
  if (archive === archiveFromChain) {
61
- const block = await getBlockFromRollupTx(publicClient, blobSinkClient, log.transactionHash, blobHashes, l2BlockNumber, rollup.address, logger);
112
+ const block = await getBlockFromRollupTx(publicClient, blobSinkClient, log.transactionHash, blobHashes, l2BlockNumber, rollup.address, targetCommitteeSize, logger);
62
113
  const l1 = {
63
114
  blockNumber: log.blockNumber,
64
115
  blockHash: log.blockHash,
65
116
  timestamp: await getL1BlockTime(publicClient, log.blockNumber)
66
117
  };
67
118
  retrievedBlocks.push({
68
- data: block,
69
- l1
119
+ ...block,
120
+ l1,
121
+ chainId,
122
+ version
123
+ });
124
+ logger.trace(`Retrieved L2 block ${l2BlockNumber} from L1 tx ${log.transactionHash}`, {
125
+ l1BlockNumber: log.blockNumber,
126
+ l2BlockNumber,
127
+ archive: archive.toString(),
128
+ attestations: block.attestations
70
129
  });
71
130
  } else {
72
131
  logger.warn(`Ignoring L2 block ${l2BlockNumber} due to archive root mismatch`, {
@@ -85,31 +144,30 @@ export async function getL1BlockTime(publicClient, blockNumber) {
85
144
  return block.timestamp;
86
145
  }
87
146
  /**
88
- * Extracts the first 'propose' method calldata from a forwarder transaction's data.
89
- * @param forwarderData - The forwarder transaction input data
147
+ * Extracts the first 'propose' method calldata from a multicall3 transaction's data.
148
+ * @param multicall3Data - The multicall3 transaction input data
90
149
  * @param rollupAddress - The address of the rollup contract
91
150
  * @returns The calldata for the first 'propose' method call to the rollup contract
92
- */ function extractRollupProposeCalldata(forwarderData, rollupAddress) {
93
- // TODO(#11451): custom forwarders
94
- const { functionName: forwarderFunctionName, args: forwarderArgs } = decodeFunctionData({
95
- abi: ForwarderAbi,
96
- data: forwarderData
151
+ */ function extractRollupProposeCalldata(multicall3Data, rollupAddress) {
152
+ const { functionName: multicall3FunctionName, args: multicall3Args } = decodeFunctionData({
153
+ abi: multicall3Abi,
154
+ data: multicall3Data
97
155
  });
98
- if (forwarderFunctionName !== 'forward') {
99
- throw new Error(`Unexpected forwarder method called ${forwarderFunctionName}`);
156
+ if (multicall3FunctionName !== 'aggregate3') {
157
+ throw new Error(`Unexpected multicall3 method called ${multicall3FunctionName}`);
100
158
  }
101
- if (forwarderArgs.length !== 2) {
102
- throw new Error(`Unexpected number of arguments for forwarder`);
159
+ if (multicall3Args.length !== 1) {
160
+ throw new Error(`Unexpected number of arguments for multicall3`);
103
161
  }
104
- const [to, data] = forwarderArgs;
162
+ const [calls] = multicall3Args;
105
163
  // Find all rollup calls
106
164
  const rollupAddressLower = rollupAddress.toLowerCase();
107
- for(let i = 0; i < to.length; i++){
108
- const addr = to[i];
165
+ for(let i = 0; i < calls.length; i++){
166
+ const addr = calls[i].target;
109
167
  if (addr.toLowerCase() !== rollupAddressLower) {
110
168
  continue;
111
169
  }
112
- const callData = data[i];
170
+ const callData = calls[i].callData;
113
171
  try {
114
172
  const { functionName: rollupFunctionName } = decodeFunctionData({
115
173
  abi: RollupAbi,
@@ -118,11 +176,11 @@ export async function getL1BlockTime(publicClient, blockNumber) {
118
176
  if (rollupFunctionName === 'propose') {
119
177
  return callData;
120
178
  }
121
- } catch (err) {
179
+ } catch {
122
180
  continue;
123
181
  }
124
182
  }
125
- throw new Error(`Rollup address not found in forwarder args`);
183
+ throw new Error(`Rollup address not found in multicall3 args`);
126
184
  }
127
185
  /**
128
186
  * Gets block from the calldata of an L1 transaction.
@@ -130,9 +188,9 @@ export async function getL1BlockTime(publicClient, blockNumber) {
130
188
  * TODO: Add retries and error management.
131
189
  * @param publicClient - The viem public client to use for transaction retrieval.
132
190
  * @param txHash - Hash of the tx that published it.
133
- * @param l2BlockNum - L2 block number.
191
+ * @param l2BlockNumber - L2 block number.
134
192
  * @returns L2 block from the calldata, deserialized
135
- */ async function getBlockFromRollupTx(publicClient, blobSinkClient, txHash, blobHashes, l2BlockNum, rollupAddress, logger) {
193
+ */ async function getBlockFromRollupTx(publicClient, blobSinkClient, txHash, blobHashes, l2BlockNumber, rollupAddress, targetCommitteeSize, logger) {
136
194
  const { input: forwarderData, blockHash } = await publicClient.getTransaction({
137
195
  hash: txHash
138
196
  });
@@ -144,15 +202,27 @@ export async function getL1BlockTime(publicClient, blockNumber) {
144
202
  if (rollupFunctionName !== 'propose') {
145
203
  throw new Error(`Unexpected rollup method called ${rollupFunctionName}`);
146
204
  }
147
- const [decodedArgs] = rollupArgs;
148
- const header = BlockHeader.fromBuffer(Buffer.from(hexToBytes(decodedArgs.header)));
205
+ const [decodedArgs, packedAttestations, _signers, _blobInput] = rollupArgs;
206
+ const attestations = CommitteeAttestation.fromPacked(packedAttestations, targetCommitteeSize);
207
+ logger.trace(`Recovered propose calldata from tx ${txHash}`, {
208
+ l2BlockNumber,
209
+ archive: decodedArgs.archive,
210
+ stateReference: decodedArgs.stateReference,
211
+ header: decodedArgs.header,
212
+ blobHashes,
213
+ attestations,
214
+ packedAttestations,
215
+ targetCommitteeSize
216
+ });
217
+ const header = CheckpointHeader.fromViem(decodedArgs.header);
149
218
  const blobBodies = await blobSinkClient.getBlobSidecar(blockHash, blobHashes);
150
219
  if (blobBodies.length === 0) {
151
- throw new NoBlobBodiesFoundError(Number(l2BlockNum));
220
+ throw new NoBlobBodiesFoundError(l2BlockNumber);
152
221
  }
153
- let blockFields;
222
+ let blobFields;
154
223
  try {
155
- blockFields = Blob.toEncodedFields(blobBodies);
224
+ // Get the fields that were actually added in the checkpoint. And check the encoding of the fields.
225
+ blobFields = getBlobFieldsInCheckpoint(blobBodies.map((b)=>b.blob), true);
156
226
  } catch (err) {
157
227
  if (err instanceof BlobDeserializationError) {
158
228
  logger.fatal(err.message);
@@ -161,17 +231,26 @@ export async function getL1BlockTime(publicClient, blockNumber) {
161
231
  }
162
232
  throw err;
163
233
  }
164
- // The blob source gives us blockFields, and we must construct the body from them:
165
- const blockBody = Body.fromBlobFields(blockFields);
166
- const blockNumberFromHeader = header.globalVariables.blockNumber.toBigInt();
167
- if (blockNumberFromHeader !== l2BlockNum) {
168
- throw new Error(`Block number mismatch: expected ${l2BlockNum} but got ${blockNumberFromHeader}`);
169
- }
170
- const archive = AppendOnlyTreeSnapshot.fromBuffer(Buffer.concat([
171
- Buffer.from(hexToBytes(decodedArgs.archive)),
172
- numToUInt32BE(Number(l2BlockNum + 1n))
173
- ]));
174
- return new L2Block(archive, header, blockBody);
234
+ const archiveRoot = new Fr(Buffer.from(hexToBytes(decodedArgs.archive)));
235
+ const stateReference = StateReference.fromViem(decodedArgs.stateReference);
236
+ return {
237
+ l2BlockNumber,
238
+ archiveRoot,
239
+ stateReference,
240
+ header,
241
+ blobFields,
242
+ attestations
243
+ };
244
+ }
245
+ /** Given an L1 to L2 message, retrieves its corresponding event from the Inbox within a specific block range. */ export async function retrieveL1ToL2Message(inbox, leaf, fromBlock, toBlock) {
246
+ const logs = await inbox.getEvents.MessageSent({
247
+ hash: leaf.toString()
248
+ }, {
249
+ fromBlock,
250
+ toBlock
251
+ });
252
+ const messages = mapLogsInboxMessage(logs);
253
+ return messages.length > 0 ? messages[0] : undefined;
175
254
  }
176
255
  /**
177
256
  * Fetch L1 to L2 messages.
@@ -183,10 +262,7 @@ export async function getL1BlockTime(publicClient, blockNumber) {
183
262
  * @returns An array of InboxLeaf and next eth block to search from.
184
263
  */ export async function retrieveL1ToL2Messages(inbox, searchStartBlock, searchEndBlock) {
185
264
  const retrievedL1ToL2Messages = [];
186
- do {
187
- if (searchStartBlock > searchEndBlock) {
188
- break;
189
- }
265
+ while(searchStartBlock <= searchEndBlock){
190
266
  const messageSentLogs = (await inbox.getEvents.MessageSent({}, {
191
267
  fromBlock: searchStartBlock,
192
268
  toBlock: searchEndBlock
@@ -194,17 +270,23 @@ export async function getL1BlockTime(publicClient, blockNumber) {
194
270
  if (messageSentLogs.length === 0) {
195
271
  break;
196
272
  }
197
- for (const log of messageSentLogs){
198
- const { index, hash } = log.args;
199
- retrievedL1ToL2Messages.push(new InboxLeaf(index, Fr.fromHexString(hash)));
200
- }
201
- // handles the case when there are no new messages:
202
- searchStartBlock = (messageSentLogs.findLast((msgLog)=>!!msgLog)?.blockNumber || searchStartBlock) + 1n;
203
- }while (searchStartBlock <= searchEndBlock)
204
- return {
205
- lastProcessedL1BlockNumber: searchStartBlock - 1n,
206
- retrievedData: retrievedL1ToL2Messages
207
- };
273
+ retrievedL1ToL2Messages.push(...mapLogsInboxMessage(messageSentLogs));
274
+ searchStartBlock = messageSentLogs.at(-1).blockNumber + 1n;
275
+ }
276
+ return retrievedL1ToL2Messages;
277
+ }
278
+ function mapLogsInboxMessage(logs) {
279
+ return logs.map((log)=>{
280
+ const { index, hash, l2BlockNumber, rollingHash } = log.args;
281
+ return {
282
+ index: index,
283
+ leaf: Fr.fromHexString(hash),
284
+ l1BlockNumber: log.blockNumber,
285
+ l1BlockHash: Buffer32.fromString(log.blockHash),
286
+ l2BlockNumber: Number(l2BlockNumber),
287
+ rollingHash: Buffer16.fromString(rollingHash)
288
+ };
289
+ });
208
290
  }
209
291
  /** Retrieves L2ProofVerified events from the rollup contract. */ export async function retrieveL2ProofVerifiedEvents(publicClient, rollupAddress, searchStartBlock, searchEndBlock) {
210
292
  const logs = await publicClient.getLogs({
@@ -219,7 +301,7 @@ export async function getL1BlockTime(publicClient, blockNumber) {
219
301
  });
220
302
  return logs.map((log)=>({
221
303
  l1BlockNumber: log.blockNumber,
222
- l2BlockNumber: log.args.blockNumber,
304
+ l2BlockNumber: Number(log.args.blockNumber),
223
305
  proverId: Fr.fromHexString(log.args.proverId),
224
306
  txHash: log.transactionHash
225
307
  }));
@@ -260,11 +342,9 @@ export async function getL1BlockTime(publicClient, blockNumber) {
260
342
  });
261
343
  let proverId;
262
344
  let archiveRoot;
263
- let aggregationObject;
264
345
  let proof;
265
346
  if (functionName === 'submitEpochRootProof') {
266
347
  const [decodedArgs] = args;
267
- aggregationObject = Buffer.from(hexToBytes(decodedArgs.aggregationObject));
268
348
  proverId = Fr.fromHexString(decodedArgs.args.proverId);
269
349
  archiveRoot = Fr.fromHexString(decodedArgs.args.endArchive);
270
350
  proof = Proof.fromBuffer(Buffer.from(hexToBytes(decodedArgs.proof)));
@@ -276,7 +356,6 @@ export async function getL1BlockTime(publicClient, blockNumber) {
276
356
  }
277
357
  return {
278
358
  proverId,
279
- aggregationObject,
280
359
  archiveRoot,
281
360
  proof
282
361
  };
@@ -1,4 +1,12 @@
1
1
  export declare class NoBlobBodiesFoundError extends Error {
2
2
  constructor(l2BlockNum: number);
3
3
  }
4
+ export declare class InitialBlockNumberNotSequentialError extends Error {
5
+ readonly newBlockNumber: number;
6
+ readonly previousBlockNumber: number | undefined;
7
+ constructor(newBlockNumber: number, previousBlockNumber: number | undefined);
8
+ }
9
+ export declare class BlockNumberNotSequentialError extends Error {
10
+ constructor(newBlockNumber: number, previous: number | undefined);
11
+ }
4
12
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/archiver/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,UAAU,EAAE,MAAM;CAG/B"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/archiver/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,UAAU,EAAE,MAAM;CAG/B;AAED,qBAAa,oCAAqC,SAAQ,KAAK;aAE3C,cAAc,EAAE,MAAM;aACtB,mBAAmB,EAAE,MAAM,GAAG,SAAS;gBADvC,cAAc,EAAE,MAAM,EACtB,mBAAmB,EAAE,MAAM,GAAG,SAAS;CAQ1D;AAED,qBAAa,6BAA8B,SAAQ,KAAK;gBAC1C,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS;CAKjE"}
@@ -3,3 +3,15 @@ export class NoBlobBodiesFoundError extends Error {
3
3
  super(`No blob bodies found for block ${l2BlockNum}`);
4
4
  }
5
5
  }
6
+ export class InitialBlockNumberNotSequentialError extends Error {
7
+ newBlockNumber;
8
+ previousBlockNumber;
9
+ constructor(newBlockNumber, previousBlockNumber){
10
+ super(`Cannot insert new block ${newBlockNumber} given previous block number in store is ${previousBlockNumber ?? 'undefined'}`), this.newBlockNumber = newBlockNumber, this.previousBlockNumber = previousBlockNumber;
11
+ }
12
+ }
13
+ export class BlockNumberNotSequentialError extends Error {
14
+ constructor(newBlockNumber, previous){
15
+ super(`Cannot insert new block ${newBlockNumber} given previous block number in batch is ${previous ?? 'undefined'}`);
16
+ }
17
+ }
@@ -1,8 +1,7 @@
1
1
  export * from './archiver.js';
2
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';
3
+ export { type PublishedL2Block, type L1PublishedData } from './structs/published.js';
5
4
  export type { ArchiverDataStore } from './archiver_store.js';
6
- export { KVArchiverDataStore } from './kv_archiver_store/kv_archiver_store.js';
5
+ export { KVArchiverDataStore, ARCHIVER_DB_VERSION } from './kv_archiver_store/kv_archiver_store.js';
7
6
  export { ContractInstanceStore } from './kv_archiver_store/contract_instance_store.js';
8
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/archiver/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,kDAAkD,CAAC;AACvF,YAAY,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAC/E,OAAO,EAAE,qBAAqB,EAAE,MAAM,gDAAgD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/archiver/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACrF,YAAY,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AACpG,OAAO,EAAE,qBAAqB,EAAE,MAAM,gDAAgD,CAAC"}
@@ -1,5 +1,4 @@
1
1
  export * from './archiver.js';
2
2
  export * from './config.js';
3
- export { MemoryArchiverStore } from './memory_archiver_store/memory_archiver_store.js';
4
- export { KVArchiverDataStore } from './kv_archiver_store/kv_archiver_store.js';
3
+ export { KVArchiverDataStore, ARCHIVER_DB_VERSION } from './kv_archiver_store/kv_archiver_store.js';
5
4
  export { ContractInstanceStore } from './kv_archiver_store/contract_instance_store.js';
@@ -5,19 +5,25 @@ export declare class ArchiverInstrumentation {
5
5
  readonly tracer: Tracer;
6
6
  private blockHeight;
7
7
  private txCount;
8
- private syncDuration;
9
- private l1BlocksSynced;
10
8
  private l1BlockHeight;
11
9
  private proofsSubmittedDelay;
12
10
  private proofsSubmittedCount;
13
11
  private dbMetrics;
12
+ private pruneDuration;
14
13
  private pruneCount;
14
+ private syncDurationPerBlock;
15
+ private syncBlockCount;
16
+ private manaPerBlock;
17
+ private txsPerBlock;
18
+ private syncDurationPerMessage;
19
+ private syncMessageCount;
15
20
  private log;
16
21
  private constructor();
17
22
  static new(telemetry: TelemetryClient, lmdbStats?: LmdbStatsCallback): Promise<ArchiverInstrumentation>;
18
23
  isEnabled(): boolean;
19
24
  processNewBlocks(syncTimePerBlock: number, blocks: L2Block[]): void;
20
- processPrune(): void;
25
+ processNewMessages(count: number, syncPerMessageMs: number): void;
26
+ processPrune(duration: number): void;
21
27
  updateLastProvenBlock(blockNumber: number): void;
22
28
  processProofsVerified(logs: {
23
29
  proverId: string;