@aztec/archiver 0.0.1-commit.fcb71a6 → 0.0.1-commit.ff7989d6c
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 +156 -22
- package/dest/archiver.d.ts +139 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +699 -0
- package/dest/{archiver/config.d.ts → config.d.ts} +9 -1
- package/dest/config.d.ts.map +1 -0
- package/dest/{archiver/config.js → config.js} +11 -2
- package/dest/errors.d.ts +41 -0
- package/dest/errors.d.ts.map +1 -0
- package/dest/{archiver/errors.js → errors.js} +8 -0
- package/dest/factory.d.ts +9 -7
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +94 -11
- package/dest/index.d.ts +11 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +9 -3
- package/dest/interfaces.d.ts +9 -0
- package/dest/interfaces.d.ts.map +1 -0
- package/dest/interfaces.js +3 -0
- package/dest/{archiver/l1 → l1}/bin/retrieve-calldata.d.ts +1 -1
- package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/bin/retrieve-calldata.js +17 -18
- package/dest/{archiver/l1 → l1}/calldata_retriever.d.ts +9 -3
- package/dest/l1/calldata_retriever.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/calldata_retriever.js +19 -6
- package/dest/l1/data_retrieval.d.ts +89 -0
- package/dest/l1/data_retrieval.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/data_retrieval.js +39 -57
- package/dest/{archiver/l1 → l1}/debug_tx.d.ts +1 -1
- package/dest/l1/debug_tx.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/spire_proposer.d.ts +1 -1
- package/dest/l1/spire_proposer.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/trace_tx.d.ts +1 -1
- package/dest/l1/trace_tx.d.ts.map +1 -0
- package/dest/l1/types.d.ts +12 -0
- package/dest/l1/types.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/validate_trace.d.ts +6 -3
- package/dest/l1/validate_trace.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/validate_trace.js +14 -10
- package/dest/modules/data_source_base.d.ts +89 -0
- package/dest/modules/data_source_base.d.ts.map +1 -0
- package/dest/modules/data_source_base.js +216 -0
- package/dest/modules/data_store_updater.d.ts +80 -0
- package/dest/modules/data_store_updater.d.ts.map +1 -0
- package/dest/modules/data_store_updater.js +323 -0
- package/dest/modules/instrumentation.d.ts +39 -0
- package/dest/modules/instrumentation.d.ts.map +1 -0
- package/dest/{archiver → modules}/instrumentation.js +33 -67
- package/dest/modules/l1_synchronizer.d.ts +76 -0
- package/dest/modules/l1_synchronizer.d.ts.map +1 -0
- package/dest/modules/l1_synchronizer.js +1112 -0
- package/dest/modules/validation.d.ts +17 -0
- package/dest/modules/validation.d.ts.map +1 -0
- package/dest/{archiver → modules}/validation.js +7 -1
- package/dest/store/block_store.d.ts +196 -0
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/block_store.js +228 -62
- package/dest/store/contract_class_store.d.ts +18 -0
- package/dest/store/contract_class_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_class_store.js +12 -8
- package/dest/store/contract_instance_store.d.ts +24 -0
- package/dest/store/contract_instance_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +1 -1
- package/dest/store/kv_archiver_store.d.ts +354 -0
- package/dest/store/kv_archiver_store.d.ts.map +1 -0
- package/dest/store/kv_archiver_store.js +464 -0
- package/dest/store/l2_tips_cache.d.ts +19 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +89 -0
- package/dest/store/log_store.d.ts +54 -0
- package/dest/store/log_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/log_store.js +146 -91
- package/dest/{archiver/kv_archiver_store → store}/message_store.d.ts +1 -1
- package/dest/store/message_store.d.ts.map +1 -0
- package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
- package/dest/structs/data_retrieval.d.ts.map +1 -0
- package/dest/structs/inbox_message.d.ts +15 -0
- package/dest/structs/inbox_message.d.ts.map +1 -0
- package/dest/{archiver/structs → structs}/published.d.ts +1 -1
- package/dest/structs/published.d.ts.map +1 -0
- package/dest/test/fake_l1_state.d.ts +193 -0
- package/dest/test/fake_l1_state.d.ts.map +1 -0
- package/dest/test/fake_l1_state.js +389 -0
- package/dest/test/index.d.ts +2 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +4 -1
- package/dest/test/mock_archiver.d.ts +2 -2
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +3 -3
- package/dest/test/mock_l1_to_l2_message_source.d.ts +2 -2
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +12 -3
- package/dest/test/mock_l2_block_source.d.ts +39 -17
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +232 -83
- package/dest/test/mock_structs.d.ts +78 -3
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +140 -7
- package/dest/test/noop_l1_archiver.d.ts +23 -0
- package/dest/test/noop_l1_archiver.d.ts.map +1 -0
- package/dest/test/noop_l1_archiver.js +68 -0
- package/package.json +16 -17
- package/src/archiver.ts +443 -0
- package/src/{archiver/config.ts → config.ts} +13 -2
- package/src/{archiver/errors.ts → errors.ts} +12 -0
- package/src/factory.ts +140 -11
- package/src/index.ts +11 -3
- package/src/interfaces.ts +9 -0
- package/src/{archiver/l1 → l1}/bin/retrieve-calldata.ts +16 -17
- package/src/{archiver/l1 → l1}/calldata_retriever.ts +28 -6
- package/src/{archiver/l1 → l1}/data_retrieval.ts +60 -74
- package/src/{archiver/l1 → l1}/validate_trace.ts +25 -7
- package/src/modules/data_source_base.ts +328 -0
- package/src/modules/data_store_updater.ts +448 -0
- package/src/{archiver → modules}/instrumentation.ts +33 -70
- package/src/modules/l1_synchronizer.ts +932 -0
- package/src/{archiver → modules}/validation.ts +11 -6
- package/src/{archiver/kv_archiver_store → store}/block_store.ts +293 -100
- package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +12 -8
- package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +1 -1
- package/src/{archiver/kv_archiver_store → store}/kv_archiver_store.ts +273 -40
- package/src/store/l2_tips_cache.ts +89 -0
- package/src/{archiver/kv_archiver_store → store}/log_store.ts +242 -121
- package/src/test/fake_l1_state.ts +607 -0
- package/src/test/index.ts +4 -0
- package/src/test/mock_archiver.ts +4 -3
- package/src/test/mock_l1_to_l2_message_source.ts +10 -4
- package/src/test/mock_l2_block_source.ts +276 -90
- package/src/test/mock_structs.ts +269 -8
- package/src/test/noop_l1_archiver.ts +109 -0
- package/dest/archiver/archiver.d.ts +0 -304
- package/dest/archiver/archiver.d.ts.map +0 -1
- package/dest/archiver/archiver.js +0 -1645
- package/dest/archiver/archiver_store.d.ts +0 -308
- package/dest/archiver/archiver_store.d.ts.map +0 -1
- package/dest/archiver/archiver_store.js +0 -4
- package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
- package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
- package/dest/archiver/archiver_store_test_suite.js +0 -2770
- package/dest/archiver/config.d.ts.map +0 -1
- package/dest/archiver/errors.d.ts +0 -36
- package/dest/archiver/errors.d.ts.map +0 -1
- package/dest/archiver/index.d.ts +0 -7
- package/dest/archiver/index.d.ts.map +0 -1
- package/dest/archiver/index.js +0 -4
- package/dest/archiver/instrumentation.d.ts +0 -37
- package/dest/archiver/instrumentation.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -157
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -158
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -313
- package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -45
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
- package/dest/archiver/l1/bin/retrieve-calldata.d.ts.map +0 -1
- package/dest/archiver/l1/calldata_retriever.d.ts.map +0 -1
- package/dest/archiver/l1/data_retrieval.d.ts +0 -90
- package/dest/archiver/l1/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/l1/debug_tx.d.ts.map +0 -1
- package/dest/archiver/l1/spire_proposer.d.ts.map +0 -1
- package/dest/archiver/l1/trace_tx.d.ts.map +0 -1
- package/dest/archiver/l1/types.d.ts +0 -12
- package/dest/archiver/l1/types.d.ts.map +0 -1
- package/dest/archiver/l1/validate_trace.d.ts.map +0 -1
- package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/structs/inbox_message.d.ts +0 -15
- package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
- package/dest/archiver/structs/published.d.ts.map +0 -1
- package/dest/archiver/validation.d.ts +0 -17
- package/dest/archiver/validation.d.ts.map +0 -1
- package/dest/rpc/index.d.ts +0 -9
- package/dest/rpc/index.d.ts.map +0 -1
- package/dest/rpc/index.js +0 -15
- package/src/archiver/archiver.ts +0 -2157
- package/src/archiver/archiver_store.ts +0 -372
- package/src/archiver/archiver_store_test_suite.ts +0 -2843
- package/src/archiver/index.ts +0 -6
- package/src/rpc/index.ts +0 -16
- /package/dest/{archiver/l1 → l1}/debug_tx.js +0 -0
- /package/dest/{archiver/l1 → l1}/spire_proposer.js +0 -0
- /package/dest/{archiver/l1 → l1}/trace_tx.js +0 -0
- /package/dest/{archiver/l1 → l1}/types.js +0 -0
- /package/dest/{archiver/kv_archiver_store → store}/message_store.js +0 -0
- /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
- /package/dest/{archiver/structs → structs}/inbox_message.js +0 -0
- /package/dest/{archiver/structs → structs}/published.js +0 -0
- /package/src/{archiver/l1 → l1}/README.md +0 -0
- /package/src/{archiver/l1 → l1}/debug_tx.ts +0 -0
- /package/src/{archiver/l1 → l1}/spire_proposer.ts +0 -0
- /package/src/{archiver/l1 → l1}/trace_tx.ts +0 -0
- /package/src/{archiver/l1 → l1}/types.ts +0 -0
- /package/src/{archiver/kv_archiver_store → store}/message_store.ts +0 -0
- /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
- /package/src/{archiver/structs → structs}/inbox_message.ts +0 -0
- /package/src/{archiver/structs → structs}/published.ts +0 -0
package/src/archiver.ts
ADDED
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
import type { BlobClientInterface } from '@aztec/blob-client/client';
|
|
2
|
+
import { EpochCache } from '@aztec/epoch-cache';
|
|
3
|
+
import { BlockTagTooOldError, RollupContract } from '@aztec/ethereum/contracts';
|
|
4
|
+
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
5
|
+
import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
|
|
6
|
+
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
7
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
8
|
+
import { merge } from '@aztec/foundation/collection';
|
|
9
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
10
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
11
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
12
|
+
import { type PromiseWithResolvers, promiseWithResolvers } from '@aztec/foundation/promise';
|
|
13
|
+
import { RunningPromise, makeLoggingErrorHandler } from '@aztec/foundation/running-promise';
|
|
14
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
15
|
+
import {
|
|
16
|
+
type ArchiverEmitter,
|
|
17
|
+
L2Block,
|
|
18
|
+
type L2BlockSink,
|
|
19
|
+
type L2Tips,
|
|
20
|
+
type ValidateCheckpointResult,
|
|
21
|
+
} from '@aztec/stdlib/block';
|
|
22
|
+
import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
23
|
+
import {
|
|
24
|
+
type L1RollupConstants,
|
|
25
|
+
getEpochNumberAtTimestamp,
|
|
26
|
+
getSlotAtNextL1Block,
|
|
27
|
+
getSlotAtTimestamp,
|
|
28
|
+
getSlotRangeForEpoch,
|
|
29
|
+
getTimestampRangeForEpoch,
|
|
30
|
+
} from '@aztec/stdlib/epoch-helpers';
|
|
31
|
+
import { type TelemetryClient, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';
|
|
32
|
+
|
|
33
|
+
import { type ArchiverConfig, mapArchiverConfig } from './config.js';
|
|
34
|
+
import { NoBlobBodiesFoundError } from './errors.js';
|
|
35
|
+
import { validateAndLogTraceAvailability } from './l1/validate_trace.js';
|
|
36
|
+
import { ArchiverDataSourceBase } from './modules/data_source_base.js';
|
|
37
|
+
import { ArchiverDataStoreUpdater } from './modules/data_store_updater.js';
|
|
38
|
+
import type { ArchiverInstrumentation } from './modules/instrumentation.js';
|
|
39
|
+
import type { ArchiverL1Synchronizer } from './modules/l1_synchronizer.js';
|
|
40
|
+
import type { KVArchiverDataStore } from './store/kv_archiver_store.js';
|
|
41
|
+
import { L2TipsCache } from './store/l2_tips_cache.js';
|
|
42
|
+
|
|
43
|
+
/** Export ArchiverEmitter for use in factory and tests. */
|
|
44
|
+
export type { ArchiverEmitter };
|
|
45
|
+
|
|
46
|
+
/** Request to add a block to the archiver, queued for processing by the sync loop. */
|
|
47
|
+
type AddBlockRequest = {
|
|
48
|
+
block: L2Block;
|
|
49
|
+
resolve: () => void;
|
|
50
|
+
reject: (err: Error) => void;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type ArchiverDeps = {
|
|
54
|
+
telemetry?: TelemetryClient;
|
|
55
|
+
blobClient: BlobClientInterface;
|
|
56
|
+
epochCache?: EpochCache;
|
|
57
|
+
dateProvider?: DateProvider;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Pulls checkpoints in a non-blocking manner and provides interface for their retrieval.
|
|
62
|
+
* Responsible for handling robust L1 polling so that other components do not need to
|
|
63
|
+
* concern themselves with it.
|
|
64
|
+
*/
|
|
65
|
+
export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Traceable {
|
|
66
|
+
/** Event emitter for archiver events (L2BlockProven, L2PruneUnproven, L2PruneUncheckpointed, etc). */
|
|
67
|
+
public readonly events: ArchiverEmitter;
|
|
68
|
+
|
|
69
|
+
/** A loop in which we will be continually fetching new checkpoints. */
|
|
70
|
+
protected runningPromise: RunningPromise;
|
|
71
|
+
|
|
72
|
+
/** L1 synchronizer that handles fetching checkpoints and messages from L1. */
|
|
73
|
+
private readonly synchronizer: ArchiverL1Synchronizer;
|
|
74
|
+
|
|
75
|
+
private initialSyncComplete: boolean = false;
|
|
76
|
+
private initialSyncPromise: PromiseWithResolvers<void>;
|
|
77
|
+
|
|
78
|
+
/** Queue of blocks to be added to the store, processed by the sync loop. */
|
|
79
|
+
private blockQueue: AddBlockRequest[] = [];
|
|
80
|
+
|
|
81
|
+
/** Helper to handle updates to the store */
|
|
82
|
+
private readonly updater: ArchiverDataStoreUpdater;
|
|
83
|
+
|
|
84
|
+
/** In-memory cache for L2 chain tips. */
|
|
85
|
+
private readonly l2TipsCache: L2TipsCache;
|
|
86
|
+
|
|
87
|
+
public readonly tracer: Tracer;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Creates a new instance of the Archiver.
|
|
91
|
+
* @param publicClient - A client for interacting with the Ethereum node.
|
|
92
|
+
* @param debugClient - A client for interacting with the Ethereum node for debug/trace methods.
|
|
93
|
+
* @param rollup - Rollup contract instance.
|
|
94
|
+
* @param inbox - Inbox contract instance.
|
|
95
|
+
* @param l1Addresses - L1 contract addresses (registry, governance proposer, slash factory, slashing proposer).
|
|
96
|
+
* @param dataStore - An archiver data store for storage & retrieval of blocks, encrypted logs & contract data.
|
|
97
|
+
* @param config - Archiver configuration options.
|
|
98
|
+
* @param blobClient - Client for retrieving blob data.
|
|
99
|
+
* @param epochCache - Cache for epoch-related data.
|
|
100
|
+
* @param dateProvider - Provider for current date/time.
|
|
101
|
+
* @param instrumentation - Instrumentation for metrics and tracing.
|
|
102
|
+
* @param l1Constants - L1 rollup constants.
|
|
103
|
+
* @param log - A logger.
|
|
104
|
+
*/
|
|
105
|
+
constructor(
|
|
106
|
+
private readonly publicClient: ViemPublicClient,
|
|
107
|
+
private readonly debugClient: ViemPublicDebugClient,
|
|
108
|
+
private readonly rollup: RollupContract,
|
|
109
|
+
private readonly l1Addresses: Pick<
|
|
110
|
+
L1ContractAddresses,
|
|
111
|
+
'registryAddress' | 'governanceProposerAddress' | 'slashFactoryAddress'
|
|
112
|
+
> & { slashingProposerAddress: EthAddress },
|
|
113
|
+
readonly dataStore: KVArchiverDataStore,
|
|
114
|
+
private config: {
|
|
115
|
+
pollingIntervalMs: number;
|
|
116
|
+
batchSize: number;
|
|
117
|
+
skipValidateCheckpointAttestations?: boolean;
|
|
118
|
+
maxAllowedEthClientDriftSeconds: number;
|
|
119
|
+
ethereumAllowNoDebugHosts?: boolean;
|
|
120
|
+
},
|
|
121
|
+
private readonly blobClient: BlobClientInterface,
|
|
122
|
+
instrumentation: ArchiverInstrumentation,
|
|
123
|
+
protected override readonly l1Constants: L1RollupConstants & { l1StartBlockHash: Buffer32; genesisArchiveRoot: Fr },
|
|
124
|
+
synchronizer: ArchiverL1Synchronizer,
|
|
125
|
+
events: ArchiverEmitter,
|
|
126
|
+
l2TipsCache?: L2TipsCache,
|
|
127
|
+
private readonly log: Logger = createLogger('archiver'),
|
|
128
|
+
) {
|
|
129
|
+
super(dataStore, l1Constants);
|
|
130
|
+
|
|
131
|
+
this.tracer = instrumentation.tracer;
|
|
132
|
+
this.initialSyncPromise = promiseWithResolvers();
|
|
133
|
+
this.synchronizer = synchronizer;
|
|
134
|
+
this.events = events;
|
|
135
|
+
this.l2TipsCache = l2TipsCache ?? new L2TipsCache(this.dataStore.blockStore);
|
|
136
|
+
this.updater = new ArchiverDataStoreUpdater(this.dataStore, this.l2TipsCache);
|
|
137
|
+
|
|
138
|
+
// Running promise starts with a small interval inbetween runs, so all iterations needed for the initial sync
|
|
139
|
+
// are done as fast as possible. This then gets updated once the initial sync completes.
|
|
140
|
+
this.runningPromise = new RunningPromise(
|
|
141
|
+
() => this.sync(),
|
|
142
|
+
this.log,
|
|
143
|
+
this.config.pollingIntervalMs / 10,
|
|
144
|
+
makeLoggingErrorHandler(this.log, NoBlobBodiesFoundError, BlockTagTooOldError),
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Updates archiver config */
|
|
149
|
+
public updateConfig(newConfig: Partial<ArchiverConfig>) {
|
|
150
|
+
this.config = merge(this.config, mapArchiverConfig(newConfig));
|
|
151
|
+
this.synchronizer.setConfig(this.config);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Starts sync process.
|
|
156
|
+
* @param blockUntilSynced - If true, blocks until the archiver has fully synced.
|
|
157
|
+
*/
|
|
158
|
+
public async start(blockUntilSynced: boolean): Promise<void> {
|
|
159
|
+
if (this.runningPromise.isRunning()) {
|
|
160
|
+
throw new Error('Archiver is already running');
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
await this.blobClient.testSources();
|
|
164
|
+
await this.synchronizer.testEthereumNodeSynced();
|
|
165
|
+
await validateAndLogTraceAvailability(
|
|
166
|
+
this.debugClient,
|
|
167
|
+
this.config.ethereumAllowNoDebugHosts ?? false,
|
|
168
|
+
this.log.getBindings(),
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
// Log initial state for the archiver
|
|
172
|
+
const { l1StartBlock } = this.l1Constants;
|
|
173
|
+
const { blocksSynchedTo = l1StartBlock, messagesSynchedTo = l1StartBlock } = await this.store.getSynchPoint();
|
|
174
|
+
const currentL2Checkpoint = await this.getSynchedCheckpointNumber();
|
|
175
|
+
this.log.info(
|
|
176
|
+
`Starting archiver sync to rollup contract ${this.rollup.address} from L1 block ${blocksSynchedTo} and L2 checkpoint ${currentL2Checkpoint}`,
|
|
177
|
+
{ blocksSynchedTo, messagesSynchedTo, currentL2Checkpoint },
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
// Start sync loop, and return the wait for initial sync if we are asked to block until synced
|
|
181
|
+
this.runningPromise.start();
|
|
182
|
+
if (blockUntilSynced) {
|
|
183
|
+
return this.waitForInitialSync();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
public syncImmediate() {
|
|
188
|
+
return this.runningPromise.trigger();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Queues a block to be added to the archiver store and triggers processing.
|
|
193
|
+
* The block will be processed by the sync loop.
|
|
194
|
+
* Implements the L2BlockSink interface.
|
|
195
|
+
* @param block - The L2 block to add.
|
|
196
|
+
* @returns A promise that resolves when the block has been added to the store, or rejects on error.
|
|
197
|
+
*/
|
|
198
|
+
public addBlock(block: L2Block): Promise<void> {
|
|
199
|
+
return new Promise<void>((resolve, reject) => {
|
|
200
|
+
this.blockQueue.push({ block, resolve, reject });
|
|
201
|
+
this.log.debug(`Queued block ${block.number} for processing`);
|
|
202
|
+
// Trigger an immediate sync, but don't wait for it - the promise resolves when the block is processed
|
|
203
|
+
this.syncImmediate().catch(err => {
|
|
204
|
+
this.log.error(`Sync immediate call failed: ${err}`);
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Processes all queued blocks, adding them to the store.
|
|
211
|
+
* Called at the beginning of each sync iteration.
|
|
212
|
+
* Blocks are processed in the order they were queued.
|
|
213
|
+
*/
|
|
214
|
+
private async processQueuedBlocks(): Promise<void> {
|
|
215
|
+
if (this.blockQueue.length === 0) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Take all blocks from the queue
|
|
220
|
+
const queuedItems = this.blockQueue.splice(0, this.blockQueue.length);
|
|
221
|
+
this.log.debug(`Processing ${queuedItems.length} queued block(s)`);
|
|
222
|
+
|
|
223
|
+
// Calculate slot threshold for validation
|
|
224
|
+
const l1Timestamp = this.synchronizer.getL1Timestamp();
|
|
225
|
+
const slotAtNextL1Block =
|
|
226
|
+
l1Timestamp === undefined ? undefined : getSlotAtNextL1Block(l1Timestamp, this.l1Constants);
|
|
227
|
+
|
|
228
|
+
// Process each block individually to properly resolve/reject each promise
|
|
229
|
+
for (const { block, resolve, reject } of queuedItems) {
|
|
230
|
+
const blockSlot = block.header.globalVariables.slotNumber;
|
|
231
|
+
if (slotAtNextL1Block !== undefined && blockSlot < slotAtNextL1Block) {
|
|
232
|
+
this.log.warn(
|
|
233
|
+
`Rejecting proposed block ${block.number} for past slot ${blockSlot} (current is ${slotAtNextL1Block})`,
|
|
234
|
+
{ block: block.toBlockInfo(), l1Timestamp, slotAtNextL1Block },
|
|
235
|
+
);
|
|
236
|
+
reject(new Error(`Block ${block.number} is for past slot ${blockSlot} (current is ${slotAtNextL1Block})`));
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
try {
|
|
241
|
+
await this.updater.addProposedBlocks([block]);
|
|
242
|
+
this.log.debug(`Added block ${block.number} to store`);
|
|
243
|
+
resolve();
|
|
244
|
+
} catch (err: any) {
|
|
245
|
+
this.log.error(`Failed to add block ${block.number} to store: ${err.message}`);
|
|
246
|
+
reject(err);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
public waitForInitialSync() {
|
|
252
|
+
return this.initialSyncPromise.promise;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Fetches logs from L1 contracts and processes them.
|
|
257
|
+
*/
|
|
258
|
+
@trackSpan('Archiver.sync')
|
|
259
|
+
private async sync() {
|
|
260
|
+
// Process any queued blocks first, before doing L1 sync
|
|
261
|
+
await this.processQueuedBlocks();
|
|
262
|
+
// Now perform L1 sync
|
|
263
|
+
await this.syncFromL1();
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
private async syncFromL1() {
|
|
267
|
+
// Delegate to the L1 synchronizer
|
|
268
|
+
await this.synchronizer.syncFromL1(this.initialSyncComplete);
|
|
269
|
+
|
|
270
|
+
// Check if we've completed initial sync
|
|
271
|
+
const currentL1BlockNumber = this.synchronizer.getL1BlockNumber();
|
|
272
|
+
if (currentL1BlockNumber !== undefined && !this.initialSyncComplete) {
|
|
273
|
+
const l1BlockNumberAtEnd = await this.publicClient.getBlockNumber();
|
|
274
|
+
if (currentL1BlockNumber + 1n >= l1BlockNumberAtEnd) {
|
|
275
|
+
this.log.info(`Initial archiver sync to L1 block ${currentL1BlockNumber} complete`, {
|
|
276
|
+
l1BlockNumber: currentL1BlockNumber,
|
|
277
|
+
syncPoint: await this.store.getSynchPoint(),
|
|
278
|
+
...(await this.getL2Tips()),
|
|
279
|
+
});
|
|
280
|
+
this.runningPromise.setPollingIntervalMS(this.config.pollingIntervalMs);
|
|
281
|
+
this.initialSyncComplete = true;
|
|
282
|
+
this.initialSyncPromise.resolve();
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** Resumes the archiver after a stop. */
|
|
288
|
+
public resume() {
|
|
289
|
+
if (this.runningPromise.isRunning()) {
|
|
290
|
+
this.log.warn(`Archiver already running`);
|
|
291
|
+
}
|
|
292
|
+
this.log.info(`Restarting archiver`);
|
|
293
|
+
this.runningPromise.start();
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Stops the archiver.
|
|
298
|
+
* @returns A promise signalling completion of the stop process.
|
|
299
|
+
*/
|
|
300
|
+
public async stop(): Promise<void> {
|
|
301
|
+
this.log.debug('Stopping...');
|
|
302
|
+
await this.runningPromise.stop();
|
|
303
|
+
|
|
304
|
+
this.log.info('Stopped.');
|
|
305
|
+
return Promise.resolve();
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
public backupTo(destPath: string): Promise<string> {
|
|
309
|
+
return this.dataStore.backupTo(destPath);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
public getL1Constants(): Promise<L1RollupConstants> {
|
|
313
|
+
return Promise.resolve(this.l1Constants);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
public getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
|
|
317
|
+
return Promise.resolve({ genesisArchiveRoot: this.l1Constants.genesisArchiveRoot });
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
public getRollupAddress(): Promise<EthAddress> {
|
|
321
|
+
return Promise.resolve(EthAddress.fromString(this.rollup.address));
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
public getRegistryAddress(): Promise<EthAddress> {
|
|
325
|
+
return Promise.resolve(this.l1Addresses.registryAddress);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
public getL1BlockNumber(): bigint | undefined {
|
|
329
|
+
return this.synchronizer.getL1BlockNumber();
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
public getL1Timestamp(): Promise<bigint | undefined> {
|
|
333
|
+
return Promise.resolve(this.synchronizer.getL1Timestamp());
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
public getL2SlotNumber(): Promise<SlotNumber | undefined> {
|
|
337
|
+
const l1Timestamp = this.synchronizer.getL1Timestamp();
|
|
338
|
+
return Promise.resolve(l1Timestamp === undefined ? undefined : getSlotAtTimestamp(l1Timestamp, this.l1Constants));
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
public getL2EpochNumber(): Promise<EpochNumber | undefined> {
|
|
342
|
+
const l1Timestamp = this.synchronizer.getL1Timestamp();
|
|
343
|
+
return Promise.resolve(
|
|
344
|
+
l1Timestamp === undefined ? undefined : getEpochNumberAtTimestamp(l1Timestamp, this.l1Constants),
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
public async isEpochComplete(epochNumber: EpochNumber): Promise<boolean> {
|
|
349
|
+
// The epoch is complete if the current checkpointed L2 block is the last one in the epoch (or later).
|
|
350
|
+
// We use the checkpointed block number (synced from L1) instead of 'latest' to avoid returning true
|
|
351
|
+
// prematurely when proposed blocks have been pushed to the archiver but not yet checkpointed on L1.
|
|
352
|
+
const checkpointedBlockNumber = await this.getCheckpointedL2BlockNumber();
|
|
353
|
+
const header = checkpointedBlockNumber > 0 ? await this.getBlockHeader(checkpointedBlockNumber) : undefined;
|
|
354
|
+
const slot = header ? header.globalVariables.slotNumber : undefined;
|
|
355
|
+
const [_startSlot, endSlot] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
|
|
356
|
+
if (slot && slot >= endSlot) {
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// If we haven't run an initial sync, just return false.
|
|
361
|
+
const l1Timestamp = this.synchronizer.getL1Timestamp();
|
|
362
|
+
if (l1Timestamp === undefined) {
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// If not, the epoch may also be complete if the L2 slot has passed without a block
|
|
367
|
+
// We compute this based on the end timestamp for the given epoch and the timestamp of the last L1 block
|
|
368
|
+
const [_startTimestamp, endTimestamp] = getTimestampRangeForEpoch(epochNumber, this.l1Constants);
|
|
369
|
+
|
|
370
|
+
// For this computation, we throw in a few extra seconds just for good measure,
|
|
371
|
+
// since we know the next L1 block won't be mined within this range. Remember that
|
|
372
|
+
// l1timestamp is the timestamp of the last l1 block we've seen, so this relies on
|
|
373
|
+
// the fact that L1 won't mine two blocks within this time of each other.
|
|
374
|
+
// TODO(palla/reorg): Is the above a safe assumption?
|
|
375
|
+
const leeway = 1n;
|
|
376
|
+
return l1Timestamp + leeway >= endTimestamp;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** Returns whether the archiver has completed an initial sync run successfully. */
|
|
380
|
+
public isInitialSyncComplete(): boolean {
|
|
381
|
+
return this.initialSyncComplete;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
public removeCheckpointsAfter(checkpointNumber: CheckpointNumber): Promise<boolean> {
|
|
385
|
+
return this.updater.removeCheckpointsAfter(checkpointNumber);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/** Used by TXE to add checkpoints directly without syncing from L1. */
|
|
389
|
+
public async addCheckpoints(
|
|
390
|
+
checkpoints: PublishedCheckpoint[],
|
|
391
|
+
pendingChainValidationStatus?: ValidateCheckpointResult,
|
|
392
|
+
): Promise<boolean> {
|
|
393
|
+
await this.updater.addCheckpoints(checkpoints, pendingChainValidationStatus);
|
|
394
|
+
return true;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
public getL2Tips(): Promise<L2Tips> {
|
|
398
|
+
return this.l2TipsCache.getL2Tips();
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
public async rollbackTo(targetL2BlockNumber: BlockNumber): Promise<void> {
|
|
402
|
+
// TODO(pw/mbps): This still assumes 1 block per checkpoint
|
|
403
|
+
const currentBlocks = await this.getL2Tips();
|
|
404
|
+
const currentL2Block = currentBlocks.proposed.number;
|
|
405
|
+
const currentProvenBlock = currentBlocks.proven.block.number;
|
|
406
|
+
|
|
407
|
+
if (targetL2BlockNumber >= currentL2Block) {
|
|
408
|
+
throw new Error(`Target L2 block ${targetL2BlockNumber} must be less than current L2 block ${currentL2Block}`);
|
|
409
|
+
}
|
|
410
|
+
const targetL2Block = await this.store.getCheckpointedBlock(targetL2BlockNumber);
|
|
411
|
+
if (!targetL2Block) {
|
|
412
|
+
throw new Error(`Target L2 block ${targetL2BlockNumber} not found`);
|
|
413
|
+
}
|
|
414
|
+
const targetL1BlockNumber = targetL2Block.l1.blockNumber;
|
|
415
|
+
const targetCheckpointNumber = targetL2Block.checkpointNumber;
|
|
416
|
+
const targetL1Block = await this.publicClient.getBlock({
|
|
417
|
+
blockNumber: targetL1BlockNumber,
|
|
418
|
+
includeTransactions: false,
|
|
419
|
+
});
|
|
420
|
+
if (!targetL1Block) {
|
|
421
|
+
throw new Error(`Missing L1 block ${targetL1BlockNumber}`);
|
|
422
|
+
}
|
|
423
|
+
const targetL1BlockHash = Buffer32.fromString(targetL1Block.hash);
|
|
424
|
+
this.log.info(
|
|
425
|
+
`Removing checkpoints after checkpoint ${targetCheckpointNumber} (target block ${targetL2BlockNumber})`,
|
|
426
|
+
);
|
|
427
|
+
await this.updater.removeCheckpointsAfter(targetCheckpointNumber);
|
|
428
|
+
this.log.info(`Rolling back L1 to L2 messages to checkpoint ${targetCheckpointNumber}`);
|
|
429
|
+
await this.store.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
|
|
430
|
+
this.log.info(`Setting L1 syncpoints to ${targetL1BlockNumber}`);
|
|
431
|
+
await this.store.setCheckpointSynchedL1BlockNumber(targetL1BlockNumber);
|
|
432
|
+
await this.store.setMessageSynchedL1Block({ l1BlockNumber: targetL1BlockNumber, l1BlockHash: targetL1BlockHash });
|
|
433
|
+
if (targetL2BlockNumber < currentProvenBlock) {
|
|
434
|
+
this.log.info(`Clearing proven L2 block number`);
|
|
435
|
+
await this.updater.setProvenCheckpointNumber(CheckpointNumber.ZERO);
|
|
436
|
+
}
|
|
437
|
+
// TODO(palla/reorg): Set the finalized block when we add support for it.
|
|
438
|
+
// if (targetL2BlockNumber < currentFinalizedBlock) {
|
|
439
|
+
// this.log.info(`Clearing finalized L2 block number`);
|
|
440
|
+
// await this.store.setFinalizedL2BlockNumber(0);
|
|
441
|
+
// }
|
|
442
|
+
}
|
|
443
|
+
}
|
|
@@ -46,8 +46,8 @@ export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
|
|
|
46
46
|
parseEnv: (val: string | undefined) => (val ? +val : undefined),
|
|
47
47
|
description: 'The maximum possible size of the archiver DB in KB. Overwrites the general dataStoreMapSizeKb.',
|
|
48
48
|
},
|
|
49
|
-
|
|
50
|
-
description: '
|
|
49
|
+
skipValidateCheckpointAttestations: {
|
|
50
|
+
description: 'Skip validating checkpoint attestations (for testing purposes only)',
|
|
51
51
|
...booleanConfigHelper(false),
|
|
52
52
|
},
|
|
53
53
|
maxAllowedEthClientDriftSeconds: {
|
|
@@ -82,3 +82,14 @@ export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
|
|
|
82
82
|
export function getArchiverConfigFromEnv(): ArchiverConfig {
|
|
83
83
|
return getConfigFromMappings<ArchiverConfig>(archiverConfigMappings);
|
|
84
84
|
}
|
|
85
|
+
|
|
86
|
+
/** Extracts the archiver-specific configuration from the full ArchiverConfig */
|
|
87
|
+
export function mapArchiverConfig(config: Partial<ArchiverConfig>) {
|
|
88
|
+
return {
|
|
89
|
+
pollingIntervalMs: config.archiverPollingIntervalMS,
|
|
90
|
+
batchSize: config.archiverBatchSize,
|
|
91
|
+
skipValidateCheckpointAttestations: config.skipValidateCheckpointAttestations,
|
|
92
|
+
maxAllowedEthClientDriftSeconds: config.maxAllowedEthClientDriftSeconds,
|
|
93
|
+
ethereumAllowNoDebugHosts: config.ethereumAllowNoDebugHosts,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
@@ -88,3 +88,15 @@ export class BlockNotFoundError extends Error {
|
|
|
88
88
|
super(`Failed to find expected block number ${blockNumber}`);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
+
|
|
92
|
+
export class CannotOverwriteCheckpointedBlockError extends Error {
|
|
93
|
+
constructor(
|
|
94
|
+
public readonly blockNumber: number,
|
|
95
|
+
public readonly lastCheckpointedBlock: number,
|
|
96
|
+
) {
|
|
97
|
+
super(
|
|
98
|
+
`Cannot add block ${blockNumber}: would overwrite checkpointed data (checkpointed up to block ${lastCheckpointedBlock})`,
|
|
99
|
+
);
|
|
100
|
+
this.name = 'CannotOverwriteCheckpointedBlockError';
|
|
101
|
+
}
|
|
102
|
+
}
|
package/src/factory.ts
CHANGED
|
@@ -1,36 +1,52 @@
|
|
|
1
|
+
import { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
+
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
3
|
+
import { InboxContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
4
|
+
import type { ViemPublicDebugClient } from '@aztec/ethereum/types';
|
|
1
5
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import {
|
|
6
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
7
|
+
import { merge } from '@aztec/foundation/collection';
|
|
8
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
9
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
3
10
|
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
4
11
|
import { createStore } from '@aztec/kv-store/lmdb-v2';
|
|
5
12
|
import { protocolContractNames } from '@aztec/protocol-contracts';
|
|
6
13
|
import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
|
|
7
14
|
import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi';
|
|
15
|
+
import type { ArchiverEmitter } from '@aztec/stdlib/block';
|
|
8
16
|
import { type ContractClassPublic, computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
|
|
17
|
+
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
18
|
+
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
9
19
|
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
|
|
20
|
+
import { EventEmitter } from 'events';
|
|
21
|
+
import { createPublicClient, fallback, http } from 'viem';
|
|
22
|
+
|
|
23
|
+
import { Archiver, type ArchiverDeps } from './archiver.js';
|
|
24
|
+
import { type ArchiverConfig, mapArchiverConfig } from './config.js';
|
|
25
|
+
import { ArchiverInstrumentation } from './modules/instrumentation.js';
|
|
26
|
+
import { ArchiverL1Synchronizer } from './modules/l1_synchronizer.js';
|
|
27
|
+
import { ARCHIVER_DB_VERSION, KVArchiverDataStore } from './store/kv_archiver_store.js';
|
|
28
|
+
import { L2TipsCache } from './store/l2_tips_cache.js';
|
|
13
29
|
|
|
14
30
|
export const ARCHIVER_STORE_NAME = 'archiver';
|
|
15
31
|
|
|
16
32
|
/** Creates an archiver store. */
|
|
17
33
|
export async function createArchiverStore(
|
|
18
34
|
userConfig: Pick<ArchiverConfig, 'archiverStoreMapSizeKb' | 'maxLogs'> & DataStoreConfig,
|
|
35
|
+
l1Constants: Pick<L1RollupConstants, 'epochDuration'>,
|
|
19
36
|
) {
|
|
20
37
|
const config = {
|
|
21
38
|
...userConfig,
|
|
22
39
|
dataStoreMapSizeKb: userConfig.archiverStoreMapSizeKb ?? userConfig.dataStoreMapSizeKb,
|
|
23
40
|
};
|
|
24
|
-
const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config
|
|
25
|
-
return new KVArchiverDataStore(store, config.maxLogs);
|
|
41
|
+
const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config);
|
|
42
|
+
return new KVArchiverDataStore(store, config.maxLogs, l1Constants);
|
|
26
43
|
}
|
|
27
44
|
|
|
28
45
|
/**
|
|
29
46
|
* Creates a local archiver.
|
|
30
47
|
* @param config - The archiver configuration.
|
|
31
|
-
* @param
|
|
48
|
+
* @param deps - The archiver dependencies (blobClient, epochCache, dateProvider, telemetry).
|
|
32
49
|
* @param opts - The options.
|
|
33
|
-
* @param telemetry - The telemetry client.
|
|
34
50
|
* @returns The local archiver.
|
|
35
51
|
*/
|
|
36
52
|
export async function createArchiver(
|
|
@@ -38,12 +54,125 @@ export async function createArchiver(
|
|
|
38
54
|
deps: ArchiverDeps,
|
|
39
55
|
opts: { blockUntilSync: boolean } = { blockUntilSync: true },
|
|
40
56
|
): Promise<Archiver> {
|
|
41
|
-
const archiverStore = await createArchiverStore(config);
|
|
57
|
+
const archiverStore = await createArchiverStore(config, { epochDuration: config.aztecEpochDuration });
|
|
42
58
|
await registerProtocolContracts(archiverStore);
|
|
43
|
-
|
|
59
|
+
|
|
60
|
+
// Create Ethereum clients
|
|
61
|
+
const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
62
|
+
const publicClient = createPublicClient({
|
|
63
|
+
chain: chain.chainInfo,
|
|
64
|
+
transport: fallback(config.l1RpcUrls.map(url => http(url, { batch: false }))),
|
|
65
|
+
pollingInterval: config.viemPollingIntervalMS,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Create debug client using debug RPC URLs if available, otherwise fall back to regular RPC URLs
|
|
69
|
+
const debugRpcUrls = config.l1DebugRpcUrls.length > 0 ? config.l1DebugRpcUrls : config.l1RpcUrls;
|
|
70
|
+
const debugClient = createPublicClient({
|
|
71
|
+
chain: chain.chainInfo,
|
|
72
|
+
transport: fallback(debugRpcUrls.map(url => http(url, { batch: false }))),
|
|
73
|
+
pollingInterval: config.viemPollingIntervalMS,
|
|
74
|
+
}) as ViemPublicDebugClient;
|
|
75
|
+
|
|
76
|
+
// Create L1 contract instances
|
|
77
|
+
const rollup = new RollupContract(publicClient, config.l1Contracts.rollupAddress);
|
|
78
|
+
const inbox = new InboxContract(publicClient, config.l1Contracts.inboxAddress);
|
|
79
|
+
|
|
80
|
+
// Fetch L1 constants from rollup contract
|
|
81
|
+
const [
|
|
82
|
+
l1StartBlock,
|
|
83
|
+
l1GenesisTime,
|
|
84
|
+
proofSubmissionEpochs,
|
|
85
|
+
genesisArchiveRoot,
|
|
86
|
+
slashingProposerAddress,
|
|
87
|
+
targetCommitteeSize,
|
|
88
|
+
] = await Promise.all([
|
|
89
|
+
rollup.getL1StartBlock(),
|
|
90
|
+
rollup.getL1GenesisTime(),
|
|
91
|
+
rollup.getProofSubmissionEpochs(),
|
|
92
|
+
rollup.getGenesisArchiveTreeRoot(),
|
|
93
|
+
rollup.getSlashingProposerAddress(),
|
|
94
|
+
rollup.getTargetCommitteeSize(),
|
|
95
|
+
] as const);
|
|
96
|
+
|
|
97
|
+
const l1StartBlockHash = await publicClient
|
|
98
|
+
.getBlock({ blockNumber: l1StartBlock, includeTransactions: false })
|
|
99
|
+
.then(block => Buffer32.fromString(block.hash));
|
|
100
|
+
|
|
101
|
+
const { aztecEpochDuration: epochDuration, aztecSlotDuration: slotDuration, ethereumSlotDuration } = config;
|
|
102
|
+
|
|
103
|
+
const l1Constants = {
|
|
104
|
+
l1StartBlockHash,
|
|
105
|
+
l1StartBlock,
|
|
106
|
+
l1GenesisTime,
|
|
107
|
+
epochDuration,
|
|
108
|
+
slotDuration,
|
|
109
|
+
ethereumSlotDuration,
|
|
110
|
+
proofSubmissionEpochs: Number(proofSubmissionEpochs),
|
|
111
|
+
targetCommitteeSize,
|
|
112
|
+
genesisArchiveRoot: Fr.fromString(genesisArchiveRoot.toString()),
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const archiverConfig = merge(
|
|
116
|
+
{
|
|
117
|
+
pollingIntervalMs: 10_000,
|
|
118
|
+
batchSize: 100,
|
|
119
|
+
maxAllowedEthClientDriftSeconds: 300,
|
|
120
|
+
ethereumAllowNoDebugHosts: false,
|
|
121
|
+
},
|
|
122
|
+
mapArchiverConfig(config),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const epochCache = deps.epochCache ?? (await EpochCache.create(config.l1Contracts.rollupAddress, config, deps));
|
|
126
|
+
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
127
|
+
const instrumentation = await ArchiverInstrumentation.new(telemetry, () => archiverStore.estimateSize());
|
|
128
|
+
|
|
129
|
+
// Create the event emitter that will be shared by archiver and synchronizer
|
|
130
|
+
const events = new EventEmitter() as ArchiverEmitter;
|
|
131
|
+
|
|
132
|
+
// Create L2 tips cache shared by archiver and synchronizer
|
|
133
|
+
const l2TipsCache = new L2TipsCache(archiverStore.blockStore);
|
|
134
|
+
|
|
135
|
+
// Create the L1 synchronizer
|
|
136
|
+
const synchronizer = new ArchiverL1Synchronizer(
|
|
137
|
+
publicClient,
|
|
138
|
+
debugClient,
|
|
139
|
+
rollup,
|
|
140
|
+
inbox,
|
|
141
|
+
{ ...config.l1Contracts, slashingProposerAddress },
|
|
142
|
+
archiverStore,
|
|
143
|
+
archiverConfig,
|
|
144
|
+
deps.blobClient,
|
|
145
|
+
epochCache,
|
|
146
|
+
deps.dateProvider ?? new DateProvider(),
|
|
147
|
+
instrumentation,
|
|
148
|
+
l1Constants,
|
|
149
|
+
events,
|
|
150
|
+
instrumentation.tracer,
|
|
151
|
+
l2TipsCache,
|
|
152
|
+
undefined, // log (use default)
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
const archiver = new Archiver(
|
|
156
|
+
publicClient,
|
|
157
|
+
debugClient,
|
|
158
|
+
rollup,
|
|
159
|
+
{ ...config.l1Contracts, slashingProposerAddress },
|
|
160
|
+
archiverStore,
|
|
161
|
+
archiverConfig,
|
|
162
|
+
deps.blobClient,
|
|
163
|
+
instrumentation,
|
|
164
|
+
l1Constants,
|
|
165
|
+
synchronizer,
|
|
166
|
+
events,
|
|
167
|
+
l2TipsCache,
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
await archiver.start(opts.blockUntilSync);
|
|
171
|
+
return archiver;
|
|
44
172
|
}
|
|
45
173
|
|
|
46
|
-
|
|
174
|
+
/** Registers protocol contracts in the archiver store. */
|
|
175
|
+
export async function registerProtocolContracts(store: KVArchiverDataStore) {
|
|
47
176
|
const blockNumber = 0;
|
|
48
177
|
for (const name of protocolContractNames) {
|
|
49
178
|
const provider = new BundledProtocolContractsProvider();
|