@aztec/archiver 0.0.1-commit.d431d1c → 0.0.1-commit.d58ff9d0
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.
- package/README.md +28 -11
- package/dest/archiver.d.ts +80 -21
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +347 -167
- package/dest/config.d.ts +7 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +38 -14
- package/dest/errors.d.ts +60 -9
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +88 -13
- package/dest/factory.d.ts +13 -6
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +59 -39
- package/dest/index.d.ts +12 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +11 -2
- package/dest/l1/bin/retrieve-calldata.js +35 -32
- package/dest/l1/calldata_retriever.d.ts +81 -50
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +202 -260
- package/dest/l1/data_retrieval.d.ts +32 -18
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +45 -50
- package/dest/l1/spire_proposer.d.ts +5 -5
- package/dest/l1/spire_proposer.d.ts.map +1 -1
- package/dest/l1/spire_proposer.js +9 -17
- package/dest/l1/trace_tx.d.ts +12 -66
- package/dest/l1/trace_tx.d.ts.map +1 -1
- package/dest/l1/validate_historical_logs.d.ts +23 -0
- package/dest/l1/validate_historical_logs.d.ts.map +1 -0
- package/dest/l1/validate_historical_logs.js +108 -0
- package/dest/l1/validate_trace.d.ts +6 -3
- package/dest/l1/validate_trace.d.ts.map +1 -1
- package/dest/l1/validate_trace.js +13 -9
- package/dest/modules/contract_data_source_adapter.d.ts +25 -0
- package/dest/modules/contract_data_source_adapter.d.ts.map +1 -0
- package/dest/modules/contract_data_source_adapter.js +32 -0
- package/dest/modules/data_source_base.d.ts +75 -48
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +251 -220
- package/dest/modules/data_store_updater.d.ts +65 -29
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +242 -153
- package/dest/modules/instrumentation.d.ts +30 -4
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +83 -20
- package/dest/modules/l1_synchronizer.d.ts +16 -14
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +493 -225
- package/dest/modules/outbox_trees_resolver.d.ts +62 -0
- package/dest/modules/outbox_trees_resolver.d.ts.map +1 -0
- package/dest/modules/outbox_trees_resolver.js +162 -0
- package/dest/modules/validation.d.ts +30 -7
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +35 -17
- package/dest/store/block_store.d.ts +200 -75
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +802 -276
- package/dest/store/contract_class_store.d.ts +17 -4
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +51 -73
- package/dest/store/contract_instance_store.d.ts +28 -1
- package/dest/store/contract_instance_store.d.ts.map +1 -1
- package/dest/store/contract_instance_store.js +54 -2
- package/dest/store/data_stores.d.ts +68 -0
- package/dest/store/data_stores.d.ts.map +1 -0
- package/dest/store/data_stores.js +54 -0
- package/dest/store/function_names_cache.d.ts +17 -0
- package/dest/store/function_names_cache.d.ts.map +1 -0
- package/dest/store/function_names_cache.js +30 -0
- package/dest/store/l2_tips_cache.d.ts +25 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +26 -0
- package/dest/store/log_store.d.ts +42 -37
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +262 -388
- package/dest/store/log_store_codec.d.ts +78 -0
- package/dest/store/log_store_codec.d.ts.map +1 -0
- package/dest/store/log_store_codec.js +110 -0
- package/dest/store/message_store.d.ts +11 -1
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +51 -9
- package/dest/test/fake_l1_state.d.ts +28 -4
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +166 -32
- package/dest/test/index.js +3 -1
- package/dest/test/mock_archiver.d.ts +1 -1
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +3 -2
- package/dest/test/mock_l2_block_source.d.ts +65 -51
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +309 -215
- package/dest/test/mock_structs.d.ts +6 -2
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +26 -12
- package/dest/test/noop_l1_archiver.d.ts +34 -0
- package/dest/test/noop_l1_archiver.d.ts.map +1 -0
- package/dest/test/noop_l1_archiver.js +88 -0
- package/package.json +15 -14
- package/src/archiver.ts +458 -198
- package/src/config.ts +43 -13
- package/src/errors.ts +134 -21
- package/src/factory.ts +87 -36
- package/src/index.ts +19 -2
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +45 -33
- package/src/l1/calldata_retriever.ts +267 -379
- package/src/l1/data_retrieval.ts +70 -74
- package/src/l1/spire_proposer.ts +7 -15
- package/src/l1/validate_historical_logs.ts +140 -0
- package/src/l1/validate_trace.ts +24 -6
- package/src/modules/contract_data_source_adapter.ts +46 -0
- package/src/modules/data_source_base.ts +336 -288
- package/src/modules/data_store_updater.ts +287 -187
- package/src/modules/instrumentation.ts +86 -21
- package/src/modules/l1_synchronizer.ts +667 -278
- package/src/modules/outbox_trees_resolver.ts +199 -0
- package/src/modules/validation.ts +80 -23
- package/src/store/block_store.ts +984 -352
- package/src/store/contract_class_store.ts +57 -107
- package/src/store/contract_instance_store.ts +68 -5
- package/src/store/data_stores.ts +104 -0
- package/src/store/function_names_cache.ts +37 -0
- package/src/store/l2_tips_cache.ts +35 -0
- package/src/store/log_store.ts +305 -500
- package/src/store/log_store_codec.ts +143 -0
- package/src/store/message_store.ts +60 -10
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +215 -44
- package/src/test/index.ts +3 -0
- package/src/test/mock_archiver.ts +3 -2
- package/src/test/mock_l2_block_source.ts +381 -246
- package/src/test/mock_structs.ts +50 -17
- package/src/test/noop_l1_archiver.ts +158 -0
- package/dest/store/kv_archiver_store.d.ts +0 -336
- package/dest/store/kv_archiver_store.d.ts.map +0 -1
- package/dest/store/kv_archiver_store.js +0 -443
- package/src/store/kv_archiver_store.ts +0 -631
package/src/config.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { type BlobClientConfig, blobClientConfigMapping } from '@aztec/blob-client/client/config';
|
|
2
2
|
import { type L1ContractsConfig, l1ContractsConfigMappings } from '@aztec/ethereum/config';
|
|
3
|
-
import { l1ContractAddressesMapping } from '@aztec/ethereum/l1-contract-addresses';
|
|
4
3
|
import { type L1ReaderConfig, l1ReaderConfigMappings } from '@aztec/ethereum/l1-reader';
|
|
5
4
|
import {
|
|
6
5
|
type ConfigMappingsType,
|
|
7
6
|
booleanConfigHelper,
|
|
8
7
|
getConfigFromMappings,
|
|
9
8
|
numberConfigHelper,
|
|
9
|
+
optionalNumberConfigHelper,
|
|
10
10
|
} from '@aztec/foundation/config';
|
|
11
|
-
import { type ChainConfig, chainConfigMappings } from '@aztec/stdlib/config';
|
|
11
|
+
import { type ChainConfig, type SequencerConfig, chainConfigMappings } from '@aztec/stdlib/config';
|
|
12
12
|
import type { ArchiverSpecificConfig } from '@aztec/stdlib/interfaces/server';
|
|
13
|
+
import { DEFAULT_ORPHAN_PRUNE_NO_PROPOSAL_TOLERANCE } from '@aztec/stdlib/timetable';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* The archiver configuration.
|
|
@@ -22,7 +23,8 @@ export type ArchiverConfig = ArchiverSpecificConfig &
|
|
|
22
23
|
L1ReaderConfig &
|
|
23
24
|
L1ContractsConfig &
|
|
24
25
|
BlobClientConfig &
|
|
25
|
-
ChainConfig
|
|
26
|
+
ChainConfig &
|
|
27
|
+
Pick<SequencerConfig, 'blockDurationMs' | 'checkpointProposalSyncGraceSeconds'>;
|
|
26
28
|
|
|
27
29
|
export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
|
|
28
30
|
...blobClientConfigMapping,
|
|
@@ -36,20 +38,31 @@ export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
|
|
|
36
38
|
description: 'The number of L2 blocks the archiver will attempt to download at a time.',
|
|
37
39
|
...numberConfigHelper(100),
|
|
38
40
|
},
|
|
39
|
-
maxLogs: {
|
|
40
|
-
env: 'ARCHIVER_MAX_LOGS',
|
|
41
|
-
description: 'The max number of logs that can be obtained in 1 "getPublicLogs" call.',
|
|
42
|
-
...numberConfigHelper(1_000),
|
|
43
|
-
},
|
|
44
41
|
archiverStoreMapSizeKb: {
|
|
45
42
|
env: 'ARCHIVER_STORE_MAP_SIZE_KB',
|
|
46
|
-
|
|
43
|
+
...optionalNumberConfigHelper(),
|
|
47
44
|
description: 'The maximum possible size of the archiver DB in KB. Overwrites the general dataStoreMapSizeKb.',
|
|
48
45
|
},
|
|
46
|
+
blockDurationMs: {
|
|
47
|
+
env: 'SEQ_BLOCK_DURATION_MS',
|
|
48
|
+
description:
|
|
49
|
+
'Duration per block in milliseconds when building multiple blocks per slot. Used to derive orphan proposed block pruning timing.',
|
|
50
|
+
...optionalNumberConfigHelper(),
|
|
51
|
+
},
|
|
52
|
+
checkpointProposalSyncGraceSeconds: {
|
|
53
|
+
env: 'CHECKPOINT_PROPOSAL_SYNC_GRACE_SECONDS',
|
|
54
|
+
description:
|
|
55
|
+
'Consensus grace in seconds for a received checkpoint proposal to materialize into local proposed state.',
|
|
56
|
+
...optionalNumberConfigHelper(),
|
|
57
|
+
},
|
|
49
58
|
skipValidateCheckpointAttestations: {
|
|
50
59
|
description: 'Skip validating checkpoint attestations (for testing purposes only)',
|
|
51
60
|
...booleanConfigHelper(false),
|
|
52
61
|
},
|
|
62
|
+
skipPromoteProposedCheckpointDuringL1Sync: {
|
|
63
|
+
description: 'Skip promoting proposed checkpoints during L1 sync (for testing purposes only)',
|
|
64
|
+
...booleanConfigHelper(false),
|
|
65
|
+
},
|
|
53
66
|
maxAllowedEthClientDriftSeconds: {
|
|
54
67
|
env: 'MAX_ALLOWED_ETH_CLIENT_DRIFT_SECONDS',
|
|
55
68
|
description: 'Maximum allowed drift in seconds between the Ethereum client and current time.',
|
|
@@ -60,6 +73,23 @@ export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
|
|
|
60
73
|
description: 'Whether to allow starting the archiver without debug/trace method support on Ethereum hosts',
|
|
61
74
|
...booleanConfigHelper(true),
|
|
62
75
|
},
|
|
76
|
+
archiverSkipHistoricalLogsCheck: {
|
|
77
|
+
env: 'ARCHIVER_SKIP_HISTORICAL_LOGS_CHECK',
|
|
78
|
+
description:
|
|
79
|
+
'Skip the startup check that probes the L1 RPC for historical Rollup contract logs. ' +
|
|
80
|
+
'Set to true to bypass the check when the connected RPC node is known to prune old logs.',
|
|
81
|
+
...booleanConfigHelper(false),
|
|
82
|
+
},
|
|
83
|
+
orphanPruneNoProposalTolerance: {
|
|
84
|
+
env: 'ARCHIVER_ORPHAN_PRUNE_NO_PROPOSAL_TOLERANCE',
|
|
85
|
+
description: 'Local tolerance in seconds before pruning an orphan block when no checkpoint proposal was received.',
|
|
86
|
+
...numberConfigHelper(DEFAULT_ORPHAN_PRUNE_NO_PROPOSAL_TOLERANCE),
|
|
87
|
+
},
|
|
88
|
+
skipOrphanProposedBlockPruning: {
|
|
89
|
+
env: 'ARCHIVER_SKIP_ORPHAN_PROPOSED_BLOCK_PRUNING',
|
|
90
|
+
description: 'Skip pruning orphan proposed blocks that have no matching proposed checkpoint.',
|
|
91
|
+
...booleanConfigHelper(false),
|
|
92
|
+
},
|
|
63
93
|
...chainConfigMappings,
|
|
64
94
|
...l1ReaderConfigMappings,
|
|
65
95
|
viemPollingIntervalMS: {
|
|
@@ -68,10 +98,6 @@ export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
|
|
|
68
98
|
...numberConfigHelper(1000),
|
|
69
99
|
},
|
|
70
100
|
...l1ContractsConfigMappings,
|
|
71
|
-
l1Contracts: {
|
|
72
|
-
description: 'The deployed L1 contract addresses',
|
|
73
|
-
nested: l1ContractAddressesMapping,
|
|
74
|
-
},
|
|
75
101
|
};
|
|
76
102
|
|
|
77
103
|
/**
|
|
@@ -89,7 +115,11 @@ export function mapArchiverConfig(config: Partial<ArchiverConfig>) {
|
|
|
89
115
|
pollingIntervalMs: config.archiverPollingIntervalMS,
|
|
90
116
|
batchSize: config.archiverBatchSize,
|
|
91
117
|
skipValidateCheckpointAttestations: config.skipValidateCheckpointAttestations,
|
|
118
|
+
skipPromoteProposedCheckpointDuringL1Sync: config.skipPromoteProposedCheckpointDuringL1Sync,
|
|
92
119
|
maxAllowedEthClientDriftSeconds: config.maxAllowedEthClientDriftSeconds,
|
|
93
120
|
ethereumAllowNoDebugHosts: config.ethereumAllowNoDebugHosts,
|
|
121
|
+
skipHistoricalLogsCheck: config.archiverSkipHistoricalLogsCheck,
|
|
122
|
+
orphanPruneNoProposalTolerance: config.orphanPruneNoProposalTolerance,
|
|
123
|
+
skipOrphanProposedBlockPruning: config.skipOrphanProposedBlockPruning,
|
|
94
124
|
};
|
|
95
125
|
}
|
package/src/errors.ts
CHANGED
|
@@ -1,29 +1,17 @@
|
|
|
1
|
+
import type { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import type { Fr } from '@aztec/foundation/schemas';
|
|
2
3
|
|
|
3
4
|
export class NoBlobBodiesFoundError extends Error {
|
|
4
5
|
constructor(l2BlockNum: number) {
|
|
5
6
|
super(`No blob bodies found for block ${l2BlockNum}`);
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export class InitialBlockNumberNotSequentialError extends Error {
|
|
10
|
-
constructor(
|
|
11
|
-
public readonly newBlockNumber: number,
|
|
12
|
-
public readonly previousBlockNumber: number | undefined,
|
|
13
|
-
) {
|
|
14
|
-
super(
|
|
15
|
-
`Cannot insert new block ${newBlockNumber} given previous block number in store is ${
|
|
16
|
-
previousBlockNumber ?? 'undefined'
|
|
17
|
-
}`,
|
|
18
|
-
);
|
|
7
|
+
this.name = 'NoBlobBodiesFoundError';
|
|
19
8
|
}
|
|
20
9
|
}
|
|
21
10
|
|
|
22
11
|
export class BlockNumberNotSequentialError extends Error {
|
|
23
12
|
constructor(newBlockNumber: number, previous: number | undefined) {
|
|
24
|
-
super(
|
|
25
|
-
|
|
26
|
-
);
|
|
13
|
+
super(`Cannot insert new block ${newBlockNumber} given previous block number is ${previous ?? 'undefined'}`);
|
|
14
|
+
this.name = 'BlockNumberNotSequentialError';
|
|
27
15
|
}
|
|
28
16
|
}
|
|
29
17
|
|
|
@@ -37,22 +25,35 @@ export class InitialCheckpointNumberNotSequentialError extends Error {
|
|
|
37
25
|
previousCheckpointNumber ?? 'undefined'
|
|
38
26
|
}`,
|
|
39
27
|
);
|
|
28
|
+
this.name = 'InitialCheckpointNumberNotSequentialError';
|
|
40
29
|
}
|
|
41
30
|
}
|
|
42
31
|
|
|
43
32
|
export class CheckpointNumberNotSequentialError extends Error {
|
|
44
|
-
constructor(
|
|
33
|
+
constructor(
|
|
34
|
+
public readonly newCheckpointNumber: CheckpointNumber,
|
|
35
|
+
public readonly previousCheckpointNumber: CheckpointNumber | undefined,
|
|
36
|
+
source?: 'proposed' | 'confirmed',
|
|
37
|
+
) {
|
|
38
|
+
const qualifier = source ? `${source} ` : '';
|
|
45
39
|
super(
|
|
46
|
-
`Cannot insert new checkpoint ${newCheckpointNumber} given previous checkpoint number
|
|
40
|
+
`Cannot insert new checkpoint ${newCheckpointNumber} given previous ${qualifier}checkpoint number is ${previousCheckpointNumber ?? 'undefined'}`,
|
|
47
41
|
);
|
|
42
|
+
this.name = 'CheckpointNumberNotSequentialError';
|
|
48
43
|
}
|
|
49
44
|
}
|
|
50
45
|
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
/** Thrown when a proposed block carries a checkpoint number that does not follow the latest one. */
|
|
47
|
+
export class BlockCheckpointNumberNotSequentialError extends Error {
|
|
48
|
+
constructor(
|
|
49
|
+
blockNumber: BlockNumber,
|
|
50
|
+
blockCheckpointNumber: CheckpointNumber,
|
|
51
|
+
previous: CheckpointNumber | undefined,
|
|
52
|
+
) {
|
|
53
53
|
super(
|
|
54
|
-
`Cannot insert block for
|
|
54
|
+
`Cannot insert new block ${blockNumber} for checkpoint ${blockCheckpointNumber} given previous checkpoint number is ${previous ?? 'undefined'}`,
|
|
55
55
|
);
|
|
56
|
+
this.name = 'BlockCheckpointNumberNotSequentialError';
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
|
|
@@ -61,6 +62,7 @@ export class BlockIndexNotSequentialError extends Error {
|
|
|
61
62
|
super(
|
|
62
63
|
`Cannot insert new block at checkpoint index ${newBlockIndex} given previous block index is ${previousBlockIndex ?? 'undefined'}`,
|
|
63
64
|
);
|
|
65
|
+
this.name = 'BlockIndexNotSequentialError';
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
68
|
|
|
@@ -74,17 +76,128 @@ export class BlockArchiveNotConsistentError extends Error {
|
|
|
74
76
|
super(
|
|
75
77
|
`Cannot insert new block number ${newBlockNumber} with archive ${newBlockArchive.toString()} previous block number is ${previousBlockNumber ?? 'undefined'}, previous archive is ${previousBlockArchive?.toString() ?? 'undefined'}`,
|
|
76
78
|
);
|
|
79
|
+
this.name = 'BlockArchiveNotConsistentError';
|
|
77
80
|
}
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
export class CheckpointNotFoundError extends Error {
|
|
81
84
|
constructor(checkpointNumber: number) {
|
|
82
85
|
super(`Failed to find expected checkpoint number ${checkpointNumber}`);
|
|
86
|
+
this.name = 'CheckpointNotFoundError';
|
|
83
87
|
}
|
|
84
88
|
}
|
|
85
89
|
|
|
86
90
|
export class BlockNotFoundError extends Error {
|
|
87
91
|
constructor(blockNumber: number) {
|
|
88
92
|
super(`Failed to find expected block number ${blockNumber}`);
|
|
93
|
+
this.name = 'BlockNotFoundError';
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Thrown when a proposed block matches a block that was already checkpointed. This is expected for late proposals. */
|
|
98
|
+
export class BlockAlreadyCheckpointedError extends Error {
|
|
99
|
+
constructor(public readonly blockNumber: number) {
|
|
100
|
+
super(`Block ${blockNumber} has already been checkpointed with the same content`);
|
|
101
|
+
this.name = 'BlockAlreadyCheckpointedError';
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Thrown when L1 to L2 messages are requested for a checkpoint whose message tree hasn't been sealed yet. */
|
|
106
|
+
export class L1ToL2MessagesNotReadyError extends Error {
|
|
107
|
+
constructor(
|
|
108
|
+
public readonly checkpointNumber: number,
|
|
109
|
+
public readonly inboxTreeInProgress: bigint,
|
|
110
|
+
) {
|
|
111
|
+
super(
|
|
112
|
+
`Cannot get L1 to L2 messages for checkpoint ${checkpointNumber}: ` +
|
|
113
|
+
`inbox tree in progress is ${inboxTreeInProgress}, messages not yet sealed`,
|
|
114
|
+
);
|
|
115
|
+
this.name = 'L1ToL2MessagesNotReadyError';
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Thrown when a proposed checkpoint number is stale (already processed). */
|
|
120
|
+
export class ProposedCheckpointStaleError extends Error {
|
|
121
|
+
constructor(
|
|
122
|
+
public readonly proposedCheckpointNumber: number,
|
|
123
|
+
public readonly currentProposedNumber: number,
|
|
124
|
+
) {
|
|
125
|
+
super(`Stale proposed checkpoint ${proposedCheckpointNumber}: current proposed is ${currentProposedNumber}`);
|
|
126
|
+
this.name = 'ProposedCheckpointStaleError';
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Thrown when a proposed checkpoint number is not the expected latestTip + 1. */
|
|
131
|
+
export class ProposedCheckpointNotSequentialError extends Error {
|
|
132
|
+
constructor(
|
|
133
|
+
public readonly proposedCheckpointNumber: number,
|
|
134
|
+
public readonly latestTipNumber: number,
|
|
135
|
+
) {
|
|
136
|
+
super(
|
|
137
|
+
`Proposed checkpoint ${proposedCheckpointNumber} is not sequential: expected ${latestTipNumber + 1} (latest tip + 1, where tip is highest of confirmed or pending)`,
|
|
138
|
+
);
|
|
139
|
+
this.name = 'ProposedCheckpointNotSequentialError';
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Thrown when a proposed checkpoint or block L2 slot has already expired on L1. */
|
|
144
|
+
export class BlockOrCheckpointSlotExpiredError extends Error {
|
|
145
|
+
constructor(
|
|
146
|
+
public readonly slot: number,
|
|
147
|
+
public readonly nextSlotStart: bigint,
|
|
148
|
+
public readonly l1TimestampSynced: bigint | undefined,
|
|
149
|
+
) {
|
|
150
|
+
super(
|
|
151
|
+
`Checkpoint or block for slot ${slot} is expired: L1 synced to ${l1TimestampSynced} which is past the next slot start ${nextSlotStart}. ` +
|
|
152
|
+
`If the checkpoint still lands via a late L1 tx, the archiver will pick it up via normal L1-sync (not the pending-queue shortcut).`,
|
|
153
|
+
);
|
|
154
|
+
this.name = 'BlockOrCheckpointSlotExpiredError';
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Thrown when attempting to promote a proposed checkpoint but no proposed checkpoint exists in the store. */
|
|
159
|
+
export class NoProposedCheckpointToPromoteError extends Error {
|
|
160
|
+
constructor() {
|
|
161
|
+
super('Cannot promote proposed checkpoint: no proposed checkpoint exists');
|
|
162
|
+
this.name = 'NoProposedCheckpointToPromoteError';
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Thrown when the archive root of the proposed checkpoint does not match the expected one. */
|
|
167
|
+
export class ProposedCheckpointArchiveRootMismatchError extends Error {
|
|
168
|
+
constructor(
|
|
169
|
+
public readonly expectedArchiveRoot: Fr,
|
|
170
|
+
public readonly actualArchiveRoot: Fr,
|
|
171
|
+
) {
|
|
172
|
+
super(
|
|
173
|
+
`Cannot promote proposed checkpoint: archive root mismatch (expected ${expectedArchiveRoot}, got ${actualArchiveRoot})`,
|
|
174
|
+
);
|
|
175
|
+
this.name = 'ProposedCheckpointArchiveRootMismatchError';
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Thrown when the proposed checkpoint does not directly follow the latest confirmed checkpoint. */
|
|
180
|
+
export class ProposedCheckpointPromotionNotSequentialError extends Error {
|
|
181
|
+
constructor(
|
|
182
|
+
public readonly proposedCheckpointNumber: number,
|
|
183
|
+
public readonly latestCheckpointNumber: number,
|
|
184
|
+
) {
|
|
185
|
+
super(
|
|
186
|
+
`Cannot promote proposed checkpoint: not sequential (latest ${latestCheckpointNumber}, proposed ${proposedCheckpointNumber})`,
|
|
187
|
+
);
|
|
188
|
+
this.name = 'ProposedCheckpointPromotionNotSequentialError';
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Thrown when a proposed block conflicts with an already checkpointed block (different content). */
|
|
193
|
+
export class CannotOverwriteCheckpointedBlockError extends Error {
|
|
194
|
+
constructor(
|
|
195
|
+
public readonly blockNumber: number,
|
|
196
|
+
public readonly lastCheckpointedBlock: number,
|
|
197
|
+
) {
|
|
198
|
+
super(
|
|
199
|
+
`Cannot add block ${blockNumber}: would overwrite checkpointed data (checkpointed up to block ${lastCheckpointedBlock})`,
|
|
200
|
+
);
|
|
201
|
+
this.name = 'CannotOverwriteCheckpointedBlockError';
|
|
89
202
|
}
|
|
90
203
|
}
|
package/src/factory.ts
CHANGED
|
@@ -1,43 +1,52 @@
|
|
|
1
1
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
2
2
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
3
|
-
import {
|
|
3
|
+
import { makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
4
|
+
import { InboxContract, OutboxContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
5
|
+
import { pickL1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
4
6
|
import type { ViemPublicDebugClient } from '@aztec/ethereum/types';
|
|
5
7
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
6
8
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
7
9
|
import { merge } from '@aztec/foundation/collection';
|
|
8
10
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
9
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
10
11
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
11
|
-
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
12
12
|
import { createStore } from '@aztec/kv-store/lmdb-v2';
|
|
13
13
|
import { protocolContractNames } from '@aztec/protocol-contracts';
|
|
14
14
|
import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
|
|
15
15
|
import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi';
|
|
16
|
-
import type { ArchiverEmitter } from '@aztec/stdlib/block';
|
|
17
|
-
import {
|
|
16
|
+
import type { ArchiverEmitter, BlockHash } from '@aztec/stdlib/block';
|
|
17
|
+
import { DEFAULT_BLOCK_DURATION_MS } from '@aztec/stdlib/config';
|
|
18
|
+
import { type ContractClassPublicWithCommitment, computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
|
|
19
|
+
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
20
|
+
import {
|
|
21
|
+
DEFAULT_ORPHAN_PRUNE_NO_PROPOSAL_TOLERANCE,
|
|
22
|
+
getDefaultCheckpointProposalSyncGrace,
|
|
23
|
+
} from '@aztec/stdlib/timetable';
|
|
24
|
+
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
18
25
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
19
26
|
|
|
20
27
|
import { EventEmitter } from 'events';
|
|
21
|
-
import { createPublicClient
|
|
28
|
+
import { createPublicClient } from 'viem';
|
|
22
29
|
|
|
23
30
|
import { Archiver, type ArchiverDeps } from './archiver.js';
|
|
24
31
|
import { type ArchiverConfig, mapArchiverConfig } from './config.js';
|
|
25
32
|
import { ArchiverInstrumentation } from './modules/instrumentation.js';
|
|
26
33
|
import { ArchiverL1Synchronizer } from './modules/l1_synchronizer.js';
|
|
27
|
-
import { ARCHIVER_DB_VERSION,
|
|
34
|
+
import { ARCHIVER_DB_VERSION, type ArchiverDataStores, createArchiverDataStores } from './store/data_stores.js';
|
|
35
|
+
import { L2TipsCache } from './store/l2_tips_cache.js';
|
|
28
36
|
|
|
29
37
|
export const ARCHIVER_STORE_NAME = 'archiver';
|
|
30
38
|
|
|
31
39
|
/** Creates an archiver store. */
|
|
32
40
|
export async function createArchiverStore(
|
|
33
|
-
userConfig: Pick<ArchiverConfig, 'archiverStoreMapSizeKb'
|
|
34
|
-
|
|
41
|
+
userConfig: Pick<ArchiverConfig, 'archiverStoreMapSizeKb'> & DataStoreConfig,
|
|
42
|
+
genesisBlockHash: BlockHash,
|
|
43
|
+
): Promise<ArchiverDataStores> {
|
|
35
44
|
const config = {
|
|
36
45
|
...userConfig,
|
|
37
46
|
dataStoreMapSizeKb: userConfig.archiverStoreMapSizeKb ?? userConfig.dataStoreMapSizeKb,
|
|
38
47
|
};
|
|
39
|
-
const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config
|
|
40
|
-
return
|
|
48
|
+
const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config);
|
|
49
|
+
return createArchiverDataStores(store, genesisBlockHash);
|
|
41
50
|
}
|
|
42
51
|
|
|
43
52
|
/**
|
|
@@ -45,21 +54,27 @@ export async function createArchiverStore(
|
|
|
45
54
|
* @param config - The archiver configuration.
|
|
46
55
|
* @param deps - The archiver dependencies (blobClient, epochCache, dateProvider, telemetry).
|
|
47
56
|
* @param opts - The options.
|
|
57
|
+
* @param initialHeader - The genesis block header from world-state, used to answer block-0 queries.
|
|
58
|
+
* @param initialBlockHash - Precomputed hash of `initialHeader`. Hoisted to the caller so the archiver
|
|
59
|
+
* can expose `getGenesisBlockHash()` synchronously.
|
|
48
60
|
* @returns The local archiver.
|
|
49
61
|
*/
|
|
50
62
|
export async function createArchiver(
|
|
51
63
|
config: ArchiverConfig & DataStoreConfig,
|
|
52
64
|
deps: ArchiverDeps,
|
|
53
65
|
opts: { blockUntilSync: boolean } = { blockUntilSync: true },
|
|
66
|
+
initialHeader: BlockHeader,
|
|
67
|
+
initialBlockHash: BlockHash,
|
|
54
68
|
): Promise<Archiver> {
|
|
55
|
-
const archiverStore = await createArchiverStore(config);
|
|
69
|
+
const archiverStore = await createArchiverStore(config, initialBlockHash);
|
|
56
70
|
await registerProtocolContracts(archiverStore);
|
|
57
71
|
|
|
58
72
|
// Create Ethereum clients
|
|
59
73
|
const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
74
|
+
const httpTimeout = config.l1HttpTimeoutMS;
|
|
60
75
|
const publicClient = createPublicClient({
|
|
61
76
|
chain: chain.chainInfo,
|
|
62
|
-
transport:
|
|
77
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: httpTimeout }),
|
|
63
78
|
pollingInterval: config.viemPollingIntervalMS,
|
|
64
79
|
});
|
|
65
80
|
|
|
@@ -67,23 +82,33 @@ export async function createArchiver(
|
|
|
67
82
|
const debugRpcUrls = config.l1DebugRpcUrls.length > 0 ? config.l1DebugRpcUrls : config.l1RpcUrls;
|
|
68
83
|
const debugClient = createPublicClient({
|
|
69
84
|
chain: chain.chainInfo,
|
|
70
|
-
transport:
|
|
85
|
+
transport: makeL1HttpTransport(debugRpcUrls, { timeout: httpTimeout }),
|
|
71
86
|
pollingInterval: config.viemPollingIntervalMS,
|
|
72
87
|
}) as ViemPublicDebugClient;
|
|
73
88
|
|
|
74
89
|
// Create L1 contract instances
|
|
75
|
-
const rollup = new RollupContract(publicClient, config.
|
|
76
|
-
const inbox = new InboxContract(publicClient, config.
|
|
90
|
+
const rollup = new RollupContract(publicClient, config.rollupAddress);
|
|
91
|
+
const inbox = new InboxContract(publicClient, config.inboxAddress);
|
|
92
|
+
const outbox = new OutboxContract(publicClient, config.outboxAddress);
|
|
77
93
|
|
|
78
94
|
// Fetch L1 constants from rollup contract
|
|
79
|
-
const [
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
95
|
+
const [
|
|
96
|
+
l1StartBlock,
|
|
97
|
+
l1GenesisTime,
|
|
98
|
+
proofSubmissionEpochs,
|
|
99
|
+
genesisArchiveRoot,
|
|
100
|
+
slashingProposerAddress,
|
|
101
|
+
targetCommitteeSize,
|
|
102
|
+
rollupManaLimit,
|
|
103
|
+
] = await Promise.all([
|
|
104
|
+
rollup.getL1StartBlock(),
|
|
105
|
+
rollup.getL1GenesisTime(),
|
|
106
|
+
rollup.getProofSubmissionEpochs(),
|
|
107
|
+
rollup.getGenesisArchiveTreeRoot(),
|
|
108
|
+
rollup.getSlashingProposerAddress(),
|
|
109
|
+
rollup.getTargetCommitteeSize(),
|
|
110
|
+
rollup.getManaLimit(),
|
|
111
|
+
] as const);
|
|
87
112
|
|
|
88
113
|
const l1StartBlockHash = await publicClient
|
|
89
114
|
.getBlock({ blockNumber: l1StartBlock, includeTransactions: false })
|
|
@@ -99,7 +124,9 @@ export async function createArchiver(
|
|
|
99
124
|
slotDuration,
|
|
100
125
|
ethereumSlotDuration,
|
|
101
126
|
proofSubmissionEpochs: Number(proofSubmissionEpochs),
|
|
127
|
+
targetCommitteeSize,
|
|
102
128
|
genesisArchiveRoot: Fr.fromString(genesisArchiveRoot.toString()),
|
|
129
|
+
rollupManaLimit: Number(rollupManaLimit),
|
|
103
130
|
};
|
|
104
131
|
|
|
105
132
|
const archiverConfig = merge(
|
|
@@ -108,24 +135,35 @@ export async function createArchiver(
|
|
|
108
135
|
batchSize: 100,
|
|
109
136
|
maxAllowedEthClientDriftSeconds: 300,
|
|
110
137
|
ethereumAllowNoDebugHosts: false,
|
|
138
|
+
skipHistoricalLogsCheck: false,
|
|
139
|
+
checkpointProposalSyncGrace:
|
|
140
|
+
config.checkpointProposalSyncGraceSeconds ??
|
|
141
|
+
getDefaultCheckpointProposalSyncGrace((config.blockDurationMs ?? DEFAULT_BLOCK_DURATION_MS) / 1000),
|
|
142
|
+
orphanPruneNoProposalTolerance: DEFAULT_ORPHAN_PRUNE_NO_PROPOSAL_TOLERANCE,
|
|
143
|
+
skipOrphanProposedBlockPruning: false,
|
|
144
|
+
blockDuration: (config.blockDurationMs ?? DEFAULT_BLOCK_DURATION_MS) / 1000,
|
|
111
145
|
},
|
|
112
146
|
mapArchiverConfig(config),
|
|
113
147
|
);
|
|
114
148
|
|
|
115
|
-
const epochCache = deps.epochCache ?? (await EpochCache.create(config.
|
|
149
|
+
const epochCache = deps.epochCache ?? (await EpochCache.create(config.rollupAddress, config, deps));
|
|
116
150
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
117
|
-
const instrumentation = await ArchiverInstrumentation.new(telemetry, () => archiverStore.estimateSize());
|
|
151
|
+
const instrumentation = await ArchiverInstrumentation.new(telemetry, () => archiverStore.db.estimateSize());
|
|
118
152
|
|
|
119
153
|
// Create the event emitter that will be shared by archiver and synchronizer
|
|
120
154
|
const events = new EventEmitter() as ArchiverEmitter;
|
|
121
155
|
|
|
156
|
+
// Create L2 tips cache shared by archiver and synchronizer. The genesis block hash is dynamic —
|
|
157
|
+
// it depends on the injected initial header (genesisTimestamp + prefilled state). Hoisted to the
|
|
158
|
+
// caller so we can pass the same value to the archiver and expose it via `getGenesisBlockHash()`.
|
|
159
|
+
const l2TipsCache = new L2TipsCache(archiverStore.blocks, initialBlockHash);
|
|
160
|
+
|
|
122
161
|
// Create the L1 synchronizer
|
|
123
162
|
const synchronizer = new ArchiverL1Synchronizer(
|
|
124
163
|
publicClient,
|
|
125
164
|
debugClient,
|
|
126
165
|
rollup,
|
|
127
166
|
inbox,
|
|
128
|
-
{ ...config.l1Contracts, slashingProposerAddress },
|
|
129
167
|
archiverStore,
|
|
130
168
|
archiverConfig,
|
|
131
169
|
deps.blobClient,
|
|
@@ -135,13 +173,16 @@ export async function createArchiver(
|
|
|
135
173
|
l1Constants,
|
|
136
174
|
events,
|
|
137
175
|
instrumentation.tracer,
|
|
176
|
+
l2TipsCache,
|
|
177
|
+
undefined, // log (use default)
|
|
138
178
|
);
|
|
139
179
|
|
|
140
180
|
const archiver = new Archiver(
|
|
141
181
|
publicClient,
|
|
142
182
|
debugClient,
|
|
143
183
|
rollup,
|
|
144
|
-
|
|
184
|
+
outbox,
|
|
185
|
+
{ ...pickL1ContractAddresses(config), slashingProposerAddress },
|
|
145
186
|
archiverStore,
|
|
146
187
|
archiverConfig,
|
|
147
188
|
deps.blobClient,
|
|
@@ -149,30 +190,40 @@ export async function createArchiver(
|
|
|
149
190
|
l1Constants,
|
|
150
191
|
synchronizer,
|
|
151
192
|
events,
|
|
193
|
+
initialHeader,
|
|
194
|
+
initialBlockHash,
|
|
195
|
+
l2TipsCache,
|
|
196
|
+
deps.dateProvider ?? new DateProvider(),
|
|
152
197
|
);
|
|
153
198
|
|
|
154
199
|
await archiver.start(opts.blockUntilSync);
|
|
155
200
|
return archiver;
|
|
156
201
|
}
|
|
157
202
|
|
|
158
|
-
|
|
203
|
+
/** Registers protocol contracts in the archiver store. Idempotent — skips contracts that already exist (e.g. on node restart). */
|
|
204
|
+
export async function registerProtocolContracts(stores: ArchiverDataStores) {
|
|
159
205
|
const blockNumber = 0;
|
|
160
206
|
for (const name of protocolContractNames) {
|
|
161
207
|
const provider = new BundledProtocolContractsProvider();
|
|
162
208
|
const contract = await provider.getProtocolContractArtifact(name);
|
|
163
|
-
|
|
209
|
+
|
|
210
|
+
// Skip if already registered (happens on node restart with a persisted store).
|
|
211
|
+
if (await stores.contractClasses.getContractClass(contract.contractClass.id)) {
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const publicBytecodeCommitment = await computePublicBytecodeCommitment(contract.contractClass.packedBytecode);
|
|
216
|
+
const contractClassPublic: ContractClassPublicWithCommitment = {
|
|
164
217
|
...contract.contractClass,
|
|
165
|
-
|
|
166
|
-
utilityFunctions: [],
|
|
218
|
+
publicBytecodeCommitment,
|
|
167
219
|
};
|
|
168
220
|
|
|
169
221
|
const publicFunctionSignatures = contract.artifact.functions
|
|
170
222
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
171
223
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
172
224
|
|
|
173
|
-
await
|
|
174
|
-
|
|
175
|
-
await
|
|
176
|
-
await store.addContractInstances([contract.instance], BlockNumber(blockNumber));
|
|
225
|
+
await stores.functionNames.register(publicFunctionSignatures);
|
|
226
|
+
await stores.contractClasses.addContractClasses([contractClassPublic], BlockNumber(blockNumber));
|
|
227
|
+
await stores.contractInstances.addContractInstances([contract.instance], BlockNumber(blockNumber));
|
|
177
228
|
}
|
|
178
229
|
}
|
package/src/index.ts
CHANGED
|
@@ -4,9 +4,26 @@ export * from './archiver.js';
|
|
|
4
4
|
export * from './modules/data_source_base.js';
|
|
5
5
|
export * from './modules/data_store_updater.js';
|
|
6
6
|
export * from './config.js';
|
|
7
|
+
export * from './errors.js';
|
|
7
8
|
|
|
8
9
|
export { type L1PublishedData } from './structs/published.js';
|
|
9
|
-
export {
|
|
10
|
+
export {
|
|
11
|
+
ARCHIVER_DB_VERSION,
|
|
12
|
+
type ArchiverDataStores,
|
|
13
|
+
type ArchiverL1SynchPoint,
|
|
14
|
+
backupArchiverDataStores,
|
|
15
|
+
createArchiverDataStores,
|
|
16
|
+
createContractDataSource,
|
|
17
|
+
getArchiverSynchPoint,
|
|
18
|
+
} from './store/data_stores.js';
|
|
19
|
+
export { FunctionNamesCache } from './store/function_names_cache.js';
|
|
20
|
+
export { ArchiverContractDataSourceAdapter } from './modules/contract_data_source_adapter.js';
|
|
21
|
+
export { BlockStore } from './store/block_store.js';
|
|
22
|
+
export { LogStore } from './store/log_store.js';
|
|
23
|
+
export { MessageStore } from './store/message_store.js';
|
|
24
|
+
export { ContractClassStore } from './store/contract_class_store.js';
|
|
10
25
|
export { ContractInstanceStore } from './store/contract_instance_store.js';
|
|
26
|
+
export { L2TipsCache } from './store/l2_tips_cache.js';
|
|
11
27
|
|
|
12
|
-
export {
|
|
28
|
+
export { retrieveL2ProofVerifiedEvents } from './l1/data_retrieval.js';
|
|
29
|
+
export { CalldataRetriever } from './l1/calldata_retriever.js';
|