@aztec/archiver 3.0.0-devnet.2 → 3.0.0-devnet.2-patch.1
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/dest/archiver/archiver.d.ts +67 -60
- package/dest/archiver/archiver.d.ts.map +1 -1
- package/dest/archiver/archiver.js +391 -262
- package/dest/archiver/archiver_store.d.ts +21 -27
- package/dest/archiver/archiver_store.d.ts.map +1 -1
- package/dest/archiver/archiver_store_test_suite.d.ts +1 -1
- package/dest/archiver/archiver_store_test_suite.d.ts.map +1 -1
- package/dest/archiver/archiver_store_test_suite.js +125 -140
- package/dest/archiver/config.d.ts +3 -2
- package/dest/archiver/config.d.ts.map +1 -1
- package/dest/archiver/config.js +13 -1
- package/dest/archiver/errors.d.ts +1 -1
- package/dest/archiver/errors.d.ts.map +1 -1
- package/dest/archiver/index.d.ts +1 -1
- package/dest/archiver/instrumentation.d.ts +5 -3
- package/dest/archiver/instrumentation.d.ts.map +1 -1
- package/dest/archiver/instrumentation.js +11 -0
- package/dest/archiver/kv_archiver_store/block_store.d.ts +10 -9
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/block_store.js +9 -8
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +2 -2
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/contract_class_store.js +1 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +2 -2
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +23 -29
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.js +7 -15
- package/dest/archiver/kv_archiver_store/log_store.d.ts +3 -10
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/log_store.js +4 -26
- package/dest/archiver/kv_archiver_store/message_store.d.ts +6 -5
- package/dest/archiver/kv_archiver_store/message_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/message_store.js +15 -14
- package/dest/archiver/l1/bin/retrieve-calldata.d.ts +3 -0
- package/dest/archiver/l1/bin/retrieve-calldata.d.ts.map +1 -0
- package/dest/archiver/l1/bin/retrieve-calldata.js +147 -0
- package/dest/archiver/l1/calldata_retriever.d.ts +98 -0
- package/dest/archiver/l1/calldata_retriever.d.ts.map +1 -0
- package/dest/archiver/l1/calldata_retriever.js +403 -0
- package/dest/archiver/l1/data_retrieval.d.ts +87 -0
- package/dest/archiver/l1/data_retrieval.d.ts.map +1 -0
- package/dest/archiver/l1/data_retrieval.js +318 -0
- package/dest/archiver/l1/debug_tx.d.ts +19 -0
- package/dest/archiver/l1/debug_tx.d.ts.map +1 -0
- package/dest/archiver/l1/debug_tx.js +73 -0
- package/dest/archiver/l1/spire_proposer.d.ts +70 -0
- package/dest/archiver/l1/spire_proposer.d.ts.map +1 -0
- package/dest/archiver/l1/spire_proposer.js +157 -0
- package/dest/archiver/l1/trace_tx.d.ts +97 -0
- package/dest/archiver/l1/trace_tx.d.ts.map +1 -0
- package/dest/archiver/l1/trace_tx.js +91 -0
- package/dest/archiver/l1/types.d.ts +12 -0
- package/dest/archiver/l1/types.d.ts.map +1 -0
- package/dest/archiver/l1/types.js +3 -0
- package/dest/archiver/l1/validate_trace.d.ts +29 -0
- package/dest/archiver/l1/validate_trace.d.ts.map +1 -0
- package/dest/archiver/l1/validate_trace.js +150 -0
- package/dest/archiver/structs/data_retrieval.d.ts +1 -1
- package/dest/archiver/structs/inbox_message.d.ts +4 -4
- package/dest/archiver/structs/inbox_message.d.ts.map +1 -1
- package/dest/archiver/structs/inbox_message.js +6 -5
- package/dest/archiver/structs/published.d.ts +3 -2
- package/dest/archiver/structs/published.d.ts.map +1 -1
- package/dest/archiver/validation.d.ts +10 -4
- package/dest/archiver/validation.d.ts.map +1 -1
- package/dest/archiver/validation.js +29 -21
- package/dest/factory.d.ts +3 -5
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +3 -2
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/rpc/index.d.ts +2 -2
- package/dest/test/index.d.ts +1 -1
- package/dest/test/mock_archiver.d.ts +16 -8
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +19 -14
- package/dest/test/mock_l1_to_l2_message_source.d.ts +7 -6
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +10 -9
- package/dest/test/mock_l2_block_source.d.ts +15 -10
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +22 -9
- package/dest/test/mock_structs.d.ts +3 -2
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +9 -8
- package/package.json +18 -17
- package/src/archiver/archiver.ts +531 -345
- package/src/archiver/archiver_store.ts +24 -27
- package/src/archiver/archiver_store_test_suite.ts +151 -128
- package/src/archiver/config.ts +13 -7
- package/src/archiver/instrumentation.ts +16 -2
- package/src/archiver/kv_archiver_store/block_store.ts +18 -17
- package/src/archiver/kv_archiver_store/contract_class_store.ts +1 -1
- package/src/archiver/kv_archiver_store/contract_instance_store.ts +1 -1
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +23 -32
- package/src/archiver/kv_archiver_store/log_store.ts +4 -30
- package/src/archiver/kv_archiver_store/message_store.ts +21 -18
- package/src/archiver/l1/README.md +98 -0
- package/src/archiver/l1/bin/retrieve-calldata.ts +182 -0
- package/src/archiver/l1/calldata_retriever.ts +531 -0
- package/src/archiver/{data_retrieval.ts → l1/data_retrieval.ts} +196 -250
- package/src/archiver/l1/debug_tx.ts +99 -0
- package/src/archiver/l1/spire_proposer.ts +160 -0
- package/src/archiver/l1/trace_tx.ts +128 -0
- package/src/archiver/l1/types.ts +13 -0
- package/src/archiver/l1/validate_trace.ts +211 -0
- package/src/archiver/structs/inbox_message.ts +8 -8
- package/src/archiver/structs/published.ts +2 -1
- package/src/archiver/validation.ts +52 -27
- package/src/factory.ts +4 -5
- package/src/index.ts +1 -1
- package/src/test/fixtures/debug_traceTransaction-multicall3.json +88 -0
- package/src/test/fixtures/debug_traceTransaction-multiplePropose.json +153 -0
- package/src/test/fixtures/debug_traceTransaction-proxied.json +122 -0
- package/src/test/fixtures/trace_transaction-multicall3.json +65 -0
- package/src/test/fixtures/trace_transaction-multiplePropose.json +319 -0
- package/src/test/fixtures/trace_transaction-proxied.json +128 -0
- package/src/test/fixtures/trace_transaction-randomRevert.json +216 -0
- package/src/test/mock_archiver.ts +22 -16
- package/src/test/mock_l1_to_l2_message_source.ts +10 -9
- package/src/test/mock_l2_block_source.ts +32 -15
- package/src/test/mock_structs.ts +10 -9
- package/dest/archiver/data_retrieval.d.ts +0 -79
- package/dest/archiver/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/data_retrieval.js +0 -362
package/src/archiver/archiver.ts
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import type { BlobSinkClientInterface } from '@aztec/blob-sink/client';
|
|
2
|
+
import { GENESIS_BLOCK_HEADER_HASH } from '@aztec/constants';
|
|
2
3
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
type ViemPublicClient,
|
|
9
|
-
createEthereumChain,
|
|
10
|
-
} from '@aztec/ethereum';
|
|
4
|
+
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
5
|
+
import { BlockTagTooOldError, InboxContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
6
|
+
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
7
|
+
import type { L1BlockId } from '@aztec/ethereum/l1-types';
|
|
8
|
+
import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
|
|
11
9
|
import { maxBigint } from '@aztec/foundation/bigint';
|
|
10
|
+
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
12
11
|
import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
|
|
13
12
|
import { merge, pick } from '@aztec/foundation/collection';
|
|
13
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
14
14
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
15
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
16
15
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
16
|
+
import { type PromiseWithResolvers, promiseWithResolvers } from '@aztec/foundation/promise';
|
|
17
17
|
import { RunningPromise, makeLoggingErrorHandler } from '@aztec/foundation/running-promise';
|
|
18
|
-
import { sleep } from '@aztec/foundation/sleep';
|
|
19
18
|
import { count } from '@aztec/foundation/string';
|
|
20
19
|
import { DateProvider, Timer, elapsed } from '@aztec/foundation/timer';
|
|
21
20
|
import type { CustomRange } from '@aztec/kv-store';
|
|
@@ -33,12 +32,13 @@ import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
|
33
32
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
34
33
|
import {
|
|
35
34
|
type ArchiverEmitter,
|
|
36
|
-
|
|
37
|
-
type L2BlockId,
|
|
35
|
+
L2Block,
|
|
38
36
|
type L2BlockSource,
|
|
39
37
|
L2BlockSourceEvents,
|
|
40
38
|
type L2Tips,
|
|
39
|
+
PublishedL2Block,
|
|
41
40
|
} from '@aztec/stdlib/block';
|
|
41
|
+
import type { Checkpoint, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
42
42
|
import {
|
|
43
43
|
type ContractClassPublic,
|
|
44
44
|
type ContractDataSource,
|
|
@@ -60,11 +60,11 @@ import {
|
|
|
60
60
|
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
|
|
61
61
|
import type { L2LogsSource } from '@aztec/stdlib/interfaces/server';
|
|
62
62
|
import { ContractClassLog, type LogFilter, type PrivateLog, type PublicLog, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
63
|
-
import type
|
|
63
|
+
import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
64
|
+
import type { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
64
65
|
import { type BlockHeader, type IndexedTxEffect, TxHash, TxReceipt } from '@aztec/stdlib/tx';
|
|
65
66
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
66
67
|
import {
|
|
67
|
-
Attributes,
|
|
68
68
|
type TelemetryClient,
|
|
69
69
|
type Traceable,
|
|
70
70
|
type Tracer,
|
|
@@ -74,21 +74,21 @@ import {
|
|
|
74
74
|
|
|
75
75
|
import { EventEmitter } from 'events';
|
|
76
76
|
import groupBy from 'lodash.groupby';
|
|
77
|
-
import { type GetContractReturnType, createPublicClient, fallback, http } from 'viem';
|
|
77
|
+
import { type GetContractReturnType, type Hex, createPublicClient, fallback, http } from 'viem';
|
|
78
78
|
|
|
79
79
|
import type { ArchiverDataStore, ArchiverL1SynchPoint } from './archiver_store.js';
|
|
80
80
|
import type { ArchiverConfig } from './config.js';
|
|
81
|
+
import { InitialBlockNumberNotSequentialError, NoBlobBodiesFoundError } from './errors.js';
|
|
82
|
+
import { ArchiverInstrumentation } from './instrumentation.js';
|
|
81
83
|
import {
|
|
82
|
-
|
|
84
|
+
retrieveCheckpointsFromRollup,
|
|
83
85
|
retrieveL1ToL2Message,
|
|
84
86
|
retrieveL1ToL2Messages,
|
|
85
|
-
|
|
86
|
-
} from './data_retrieval.js';
|
|
87
|
-
import {
|
|
88
|
-
import { ArchiverInstrumentation } from './instrumentation.js';
|
|
87
|
+
retrievedToPublishedCheckpoint,
|
|
88
|
+
} from './l1/data_retrieval.js';
|
|
89
|
+
import { validateAndLogTraceAvailability } from './l1/validate_trace.js';
|
|
89
90
|
import type { InboxMessage } from './structs/inbox_message.js';
|
|
90
|
-
import type
|
|
91
|
-
import { type ValidateBlockResult, validateBlockAttestations } from './validation.js';
|
|
91
|
+
import { type ValidateBlockResult, validateCheckpointAttestations } from './validation.js';
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
94
|
* Helper interface to combine all sources this archiver implementation provides.
|
|
@@ -107,19 +107,29 @@ function mapArchiverConfig(config: Partial<ArchiverConfig>) {
|
|
|
107
107
|
pollingIntervalMs: config.archiverPollingIntervalMS,
|
|
108
108
|
batchSize: config.archiverBatchSize,
|
|
109
109
|
skipValidateBlockAttestations: config.skipValidateBlockAttestations,
|
|
110
|
+
maxAllowedEthClientDriftSeconds: config.maxAllowedEthClientDriftSeconds,
|
|
111
|
+
ethereumAllowNoDebugHosts: config.ethereumAllowNoDebugHosts,
|
|
110
112
|
};
|
|
111
113
|
}
|
|
112
114
|
|
|
115
|
+
type RollupStatus = {
|
|
116
|
+
provenCheckpointNumber: CheckpointNumber;
|
|
117
|
+
provenArchive: Hex;
|
|
118
|
+
pendingCheckpointNumber: CheckpointNumber;
|
|
119
|
+
pendingArchive: Hex;
|
|
120
|
+
validationResult: ValidateBlockResult | undefined;
|
|
121
|
+
lastRetrievedCheckpoint?: PublishedCheckpoint;
|
|
122
|
+
lastL1BlockWithCheckpoint?: bigint;
|
|
123
|
+
};
|
|
124
|
+
|
|
113
125
|
/**
|
|
114
|
-
* Pulls
|
|
126
|
+
* Pulls checkpoints in a non-blocking manner and provides interface for their retrieval.
|
|
115
127
|
* Responsible for handling robust L1 polling so that other components do not need to
|
|
116
128
|
* concern themselves with it.
|
|
117
129
|
*/
|
|
118
130
|
export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implements ArchiveSource, Traceable {
|
|
119
|
-
/**
|
|
120
|
-
|
|
121
|
-
*/
|
|
122
|
-
private runningPromise?: RunningPromise;
|
|
131
|
+
/** A loop in which we will be continually fetching new checkpoints. */
|
|
132
|
+
private runningPromise: RunningPromise;
|
|
123
133
|
|
|
124
134
|
private rollup: RollupContract;
|
|
125
135
|
private inbox: InboxContract;
|
|
@@ -129,12 +139,14 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
129
139
|
private l1BlockNumber: bigint | undefined;
|
|
130
140
|
private l1Timestamp: bigint | undefined;
|
|
131
141
|
private initialSyncComplete: boolean = false;
|
|
142
|
+
private initialSyncPromise: PromiseWithResolvers<void>;
|
|
132
143
|
|
|
133
144
|
public readonly tracer: Tracer;
|
|
134
145
|
|
|
135
146
|
/**
|
|
136
147
|
* Creates a new instance of the Archiver.
|
|
137
148
|
* @param publicClient - A client for interacting with the Ethereum node.
|
|
149
|
+
* @param debugClient - A client for interacting with the Ethereum node for debug/trace methods.
|
|
138
150
|
* @param rollupAddress - Ethereum address of the rollup contract.
|
|
139
151
|
* @param inboxAddress - Ethereum address of the inbox contract.
|
|
140
152
|
* @param registryAddress - Ethereum address of the registry contract.
|
|
@@ -144,11 +156,22 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
144
156
|
*/
|
|
145
157
|
constructor(
|
|
146
158
|
private readonly publicClient: ViemPublicClient,
|
|
147
|
-
private readonly
|
|
159
|
+
private readonly debugClient: ViemPublicDebugClient,
|
|
160
|
+
private readonly l1Addresses: Pick<
|
|
161
|
+
L1ContractAddresses,
|
|
162
|
+
'rollupAddress' | 'inboxAddress' | 'registryAddress' | 'governanceProposerAddress' | 'slashFactoryAddress'
|
|
163
|
+
> & { slashingProposerAddress: EthAddress },
|
|
148
164
|
readonly dataStore: ArchiverDataStore,
|
|
149
|
-
private config: {
|
|
165
|
+
private config: {
|
|
166
|
+
pollingIntervalMs: number;
|
|
167
|
+
batchSize: number;
|
|
168
|
+
skipValidateBlockAttestations?: boolean;
|
|
169
|
+
maxAllowedEthClientDriftSeconds: number;
|
|
170
|
+
ethereumAllowNoDebugHosts?: boolean;
|
|
171
|
+
},
|
|
150
172
|
private readonly blobSinkClient: BlobSinkClientInterface,
|
|
151
173
|
private readonly epochCache: EpochCache,
|
|
174
|
+
private readonly dateProvider: DateProvider,
|
|
152
175
|
private readonly instrumentation: ArchiverInstrumentation,
|
|
153
176
|
private readonly l1constants: L1RollupConstants & { l1StartBlockHash: Buffer32; genesisArchiveRoot: Fr },
|
|
154
177
|
private readonly log: Logger = createLogger('archiver'),
|
|
@@ -160,6 +183,16 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
160
183
|
|
|
161
184
|
this.rollup = new RollupContract(publicClient, l1Addresses.rollupAddress);
|
|
162
185
|
this.inbox = new InboxContract(publicClient, l1Addresses.inboxAddress);
|
|
186
|
+
this.initialSyncPromise = promiseWithResolvers();
|
|
187
|
+
|
|
188
|
+
// Running promise starts with a small interval inbetween runs, so all iterations needed for the initial sync
|
|
189
|
+
// are done as fast as possible. This then gets updated once the initial sync completes.
|
|
190
|
+
this.runningPromise = new RunningPromise(
|
|
191
|
+
() => this.sync(),
|
|
192
|
+
this.log,
|
|
193
|
+
this.config.pollingIntervalMs / 10,
|
|
194
|
+
makeLoggingErrorHandler(this.log, NoBlobBodiesFoundError, BlockTagTooOldError),
|
|
195
|
+
);
|
|
163
196
|
}
|
|
164
197
|
|
|
165
198
|
/**
|
|
@@ -182,14 +215,24 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
182
215
|
pollingInterval: config.viemPollingIntervalMS,
|
|
183
216
|
});
|
|
184
217
|
|
|
218
|
+
// Create debug client using debug RPC URLs if available, otherwise fall back to regular RPC URLs
|
|
219
|
+
const debugRpcUrls = config.l1DebugRpcUrls.length > 0 ? config.l1DebugRpcUrls : config.l1RpcUrls;
|
|
220
|
+
const debugClient = createPublicClient({
|
|
221
|
+
chain: chain.chainInfo,
|
|
222
|
+
transport: fallback(debugRpcUrls.map(url => http(url))),
|
|
223
|
+
pollingInterval: config.viemPollingIntervalMS,
|
|
224
|
+
}) as ViemPublicDebugClient;
|
|
225
|
+
|
|
185
226
|
const rollup = new RollupContract(publicClient, config.l1Contracts.rollupAddress);
|
|
186
227
|
|
|
187
|
-
const [l1StartBlock, l1GenesisTime, proofSubmissionEpochs, genesisArchiveRoot] =
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
228
|
+
const [l1StartBlock, l1GenesisTime, proofSubmissionEpochs, genesisArchiveRoot, slashingProposerAddress] =
|
|
229
|
+
await Promise.all([
|
|
230
|
+
rollup.getL1StartBlock(),
|
|
231
|
+
rollup.getL1GenesisTime(),
|
|
232
|
+
rollup.getProofSubmissionEpochs(),
|
|
233
|
+
rollup.getGenesisArchiveTreeRoot(),
|
|
234
|
+
rollup.getSlashingProposerAddress(),
|
|
235
|
+
] as const);
|
|
193
236
|
|
|
194
237
|
const l1StartBlockHash = await publicClient
|
|
195
238
|
.getBlock({ blockNumber: l1StartBlock, includeTransactions: false })
|
|
@@ -208,18 +251,28 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
208
251
|
genesisArchiveRoot: Fr.fromHexString(genesisArchiveRoot),
|
|
209
252
|
};
|
|
210
253
|
|
|
211
|
-
const opts = merge(
|
|
254
|
+
const opts = merge(
|
|
255
|
+
{
|
|
256
|
+
pollingIntervalMs: 10_000,
|
|
257
|
+
batchSize: 100,
|
|
258
|
+
maxAllowedEthClientDriftSeconds: 300,
|
|
259
|
+
ethereumAllowNoDebugHosts: false,
|
|
260
|
+
},
|
|
261
|
+
mapArchiverConfig(config),
|
|
262
|
+
);
|
|
212
263
|
|
|
213
264
|
const epochCache = deps.epochCache ?? (await EpochCache.create(config.l1Contracts.rollupAddress, config, deps));
|
|
214
265
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
215
266
|
|
|
216
267
|
const archiver = new Archiver(
|
|
217
268
|
publicClient,
|
|
218
|
-
|
|
269
|
+
debugClient,
|
|
270
|
+
{ ...config.l1Contracts, slashingProposerAddress },
|
|
219
271
|
archiverStore,
|
|
220
272
|
opts,
|
|
221
273
|
deps.blobSinkClient,
|
|
222
274
|
epochCache,
|
|
275
|
+
deps.dateProvider ?? new DateProvider(),
|
|
223
276
|
await ArchiverInstrumentation.new(telemetry, () => archiverStore.estimateSize()),
|
|
224
277
|
l1Constants,
|
|
225
278
|
);
|
|
@@ -237,62 +290,58 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
237
290
|
* @param blockUntilSynced - If true, blocks until the archiver has fully synced.
|
|
238
291
|
*/
|
|
239
292
|
public async start(blockUntilSynced: boolean): Promise<void> {
|
|
240
|
-
if (this.runningPromise) {
|
|
293
|
+
if (this.runningPromise.isRunning()) {
|
|
241
294
|
throw new Error('Archiver is already running');
|
|
242
295
|
}
|
|
243
296
|
|
|
244
297
|
await this.blobSinkClient.testSources();
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
this.log,
|
|
256
|
-
this.config.pollingIntervalMs,
|
|
257
|
-
makeLoggingErrorHandler(
|
|
258
|
-
this.log,
|
|
259
|
-
// Ignored errors will not log to the console
|
|
260
|
-
// We ignore NoBlobBodiesFound as the message may not have been passed to the blob sink yet
|
|
261
|
-
NoBlobBodiesFoundError,
|
|
262
|
-
),
|
|
298
|
+
await this.testEthereumNodeSynced();
|
|
299
|
+
await validateAndLogTraceAvailability(this.debugClient, this.config.ethereumAllowNoDebugHosts ?? false);
|
|
300
|
+
|
|
301
|
+
// Log initial state for the archiver
|
|
302
|
+
const { l1StartBlock } = this.l1constants;
|
|
303
|
+
const { blocksSynchedTo = l1StartBlock, messagesSynchedTo = l1StartBlock } = await this.store.getSynchPoint();
|
|
304
|
+
const currentL2Block = await this.getBlockNumber();
|
|
305
|
+
this.log.info(
|
|
306
|
+
`Starting archiver sync to rollup contract ${this.l1Addresses.rollupAddress.toString()} from L1 block ${blocksSynchedTo} and L2 block ${currentL2Block}`,
|
|
307
|
+
{ blocksSynchedTo, messagesSynchedTo, currentL2Block },
|
|
263
308
|
);
|
|
264
309
|
|
|
310
|
+
// Start sync loop, and return the wait for initial sync if we are asked to block until synced
|
|
265
311
|
this.runningPromise.start();
|
|
312
|
+
if (blockUntilSynced) {
|
|
313
|
+
return this.waitForInitialSync();
|
|
314
|
+
}
|
|
266
315
|
}
|
|
267
316
|
|
|
268
317
|
public syncImmediate() {
|
|
269
|
-
if (!this.runningPromise) {
|
|
270
|
-
throw new Error('Archiver is not running');
|
|
271
|
-
}
|
|
272
318
|
return this.runningPromise.trigger();
|
|
273
319
|
}
|
|
274
320
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
321
|
+
public waitForInitialSync() {
|
|
322
|
+
return this.initialSyncPromise.promise;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/** Checks that the ethereum node we are connected to has a latest timestamp no more than the allowed drift. Throw if not. */
|
|
326
|
+
private async testEthereumNodeSynced() {
|
|
327
|
+
const maxAllowedDelay = this.config.maxAllowedEthClientDriftSeconds;
|
|
328
|
+
if (maxAllowedDelay === 0) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
const { number, timestamp: l1Timestamp } = await this.publicClient.getBlock({ includeTransactions: false });
|
|
332
|
+
const currentTime = BigInt(this.dateProvider.nowInSeconds());
|
|
333
|
+
if (currentTime - l1Timestamp > BigInt(maxAllowedDelay)) {
|
|
334
|
+
throw new Error(
|
|
335
|
+
`Ethereum node is out of sync (last block synced ${number} at ${l1Timestamp} vs current time ${currentTime})`,
|
|
336
|
+
);
|
|
288
337
|
}
|
|
289
338
|
}
|
|
290
339
|
|
|
291
340
|
/**
|
|
292
341
|
* Fetches logs from L1 contracts and processes them.
|
|
293
342
|
*/
|
|
294
|
-
@trackSpan('Archiver.sync'
|
|
295
|
-
private async sync(
|
|
343
|
+
@trackSpan('Archiver.sync')
|
|
344
|
+
private async sync() {
|
|
296
345
|
/**
|
|
297
346
|
* We keep track of three "pointers" to L1 blocks:
|
|
298
347
|
* 1. the last L1 block that published an L2 block
|
|
@@ -302,8 +351,6 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
302
351
|
* We do this to deal with L1 data providers that are eventually consistent (e.g. Infura).
|
|
303
352
|
* We guard against seeing block X with no data at one point, and later, the provider processes the block and it has data.
|
|
304
353
|
* The archiver will stay back, until there's data on L1 that will move the pointers forward.
|
|
305
|
-
*
|
|
306
|
-
* This code does not handle reorgs.
|
|
307
354
|
*/
|
|
308
355
|
const { l1StartBlock, l1StartBlockHash } = this.l1constants;
|
|
309
356
|
const {
|
|
@@ -315,13 +362,12 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
315
362
|
const currentL1BlockNumber = currentL1Block.number;
|
|
316
363
|
const currentL1BlockHash = Buffer32.fromString(currentL1Block.hash);
|
|
317
364
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
}
|
|
365
|
+
this.log.trace(`Starting new archiver sync iteration`, {
|
|
366
|
+
blocksSynchedTo,
|
|
367
|
+
messagesSynchedTo,
|
|
368
|
+
currentL1BlockNumber,
|
|
369
|
+
currentL1BlockHash,
|
|
370
|
+
});
|
|
325
371
|
|
|
326
372
|
// ********** Ensuring Consistency of data pulled from L1 **********
|
|
327
373
|
|
|
@@ -351,28 +397,45 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
351
397
|
? (await this.publicClient.getBlock({ blockNumber: currentL1BlockNumber })).timestamp
|
|
352
398
|
: this.l1Timestamp;
|
|
353
399
|
|
|
354
|
-
//
|
|
400
|
+
// Warn if the latest L1 block timestamp is too old
|
|
401
|
+
const maxAllowedDelay = this.config.maxAllowedEthClientDriftSeconds;
|
|
402
|
+
const now = this.dateProvider.nowInSeconds();
|
|
403
|
+
if (maxAllowedDelay > 0 && Number(currentL1Timestamp) <= now - maxAllowedDelay) {
|
|
404
|
+
this.log.warn(
|
|
405
|
+
`Latest L1 block ${currentL1BlockNumber} timestamp ${currentL1Timestamp} is too old. Make sure your Ethereum node is synced.`,
|
|
406
|
+
{ currentL1BlockNumber, currentL1Timestamp, now, maxAllowedDelay },
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// ********** Events that are processed per checkpoint **********
|
|
355
411
|
if (currentL1BlockNumber > blocksSynchedTo) {
|
|
356
|
-
// First we retrieve new L2 blocks and store them in the DB. This will also update the
|
|
357
|
-
// pending chain validation status, proven
|
|
358
|
-
const rollupStatus = await this.
|
|
412
|
+
// First we retrieve new checkpoints and L2 blocks and store them in the DB. This will also update the
|
|
413
|
+
// pending chain validation status, proven checkpoint number, and synched L1 block number.
|
|
414
|
+
const rollupStatus = await this.handleCheckpoints(blocksSynchedTo, currentL1BlockNumber);
|
|
359
415
|
// Then we prune the current epoch if it'd reorg on next submission.
|
|
360
|
-
// Note that we don't do this before retrieving
|
|
361
|
-
//
|
|
416
|
+
// Note that we don't do this before retrieving checkpoints because we may need to retrieve
|
|
417
|
+
// checkpoints from more than 2 epochs ago, so we want to make sure we have the latest view of
|
|
362
418
|
// the chain locally before we start unwinding stuff. This can be optimized by figuring out
|
|
363
|
-
// up to which point we're pruning, and then requesting
|
|
419
|
+
// up to which point we're pruning, and then requesting checkpoints up to that point only.
|
|
364
420
|
const { rollupCanPrune } = await this.handleEpochPrune(
|
|
365
|
-
rollupStatus.
|
|
421
|
+
rollupStatus.provenCheckpointNumber,
|
|
366
422
|
currentL1BlockNumber,
|
|
367
423
|
currentL1Timestamp,
|
|
368
424
|
);
|
|
369
425
|
|
|
370
|
-
//
|
|
426
|
+
// If the last checkpoint we processed had an invalid attestation, we manually advance the L1 syncpoint
|
|
427
|
+
// past it, since otherwise we'll keep downloading it and reprocessing it on every iteration until
|
|
428
|
+
// we get a valid checkpoint to advance the syncpoint.
|
|
429
|
+
if (!rollupStatus.validationResult?.valid && rollupStatus.lastL1BlockWithCheckpoint !== undefined) {
|
|
430
|
+
await this.store.setBlockSynchedL1BlockNumber(rollupStatus.lastL1BlockWithCheckpoint);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// And lastly we check if we are missing any checkpoints behind us due to a possible L1 reorg.
|
|
371
434
|
// We only do this if rollup cant prune on the next submission. Otherwise we will end up
|
|
372
|
-
// re-syncing the
|
|
435
|
+
// re-syncing the checkpoints we have just unwound above. We also dont do this if the last checkpoint is invalid,
|
|
373
436
|
// since the archiver will rightfully refuse to sync up to it.
|
|
374
437
|
if (!rollupCanPrune && rollupStatus.validationResult?.valid) {
|
|
375
|
-
await this.
|
|
438
|
+
await this.checkForNewCheckpointsBeforeL1SyncPoint(rollupStatus, blocksSynchedTo, currentL1BlockNumber);
|
|
376
439
|
}
|
|
377
440
|
|
|
378
441
|
this.instrumentation.updateL1BlockHeight(currentL1BlockNumber);
|
|
@@ -383,14 +446,18 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
383
446
|
// but the corresponding blocks have not been processed (see #12631).
|
|
384
447
|
this.l1Timestamp = currentL1Timestamp;
|
|
385
448
|
this.l1BlockNumber = currentL1BlockNumber;
|
|
386
|
-
this.initialSyncComplete = true;
|
|
387
449
|
|
|
388
|
-
|
|
389
|
-
|
|
450
|
+
// We resolve the initial sync only once we've caught up with the latest L1 block number (with 1 block grace)
|
|
451
|
+
// so if the initial sync took too long, we still go for another iteration.
|
|
452
|
+
if (!this.initialSyncComplete && currentL1BlockNumber + 1n >= (await this.publicClient.getBlockNumber())) {
|
|
453
|
+
this.log.info(`Initial archiver sync to L1 block ${currentL1BlockNumber} complete`, {
|
|
390
454
|
l1BlockNumber: currentL1BlockNumber,
|
|
391
455
|
syncPoint: await this.store.getSynchPoint(),
|
|
392
456
|
...(await this.getL2Tips()),
|
|
393
457
|
});
|
|
458
|
+
this.runningPromise.setPollingIntervalMS(this.config.pollingIntervalMs);
|
|
459
|
+
this.initialSyncComplete = true;
|
|
460
|
+
this.initialSyncPromise.resolve();
|
|
394
461
|
}
|
|
395
462
|
}
|
|
396
463
|
|
|
@@ -408,43 +475,47 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
408
475
|
return result;
|
|
409
476
|
}
|
|
410
477
|
|
|
411
|
-
/** Checks if there'd be a reorg for the next
|
|
412
|
-
private async handleEpochPrune(
|
|
478
|
+
/** Checks if there'd be a reorg for the next checkpoint submission and start pruning now. */
|
|
479
|
+
private async handleEpochPrune(
|
|
480
|
+
provenCheckpointNumber: CheckpointNumber,
|
|
481
|
+
currentL1BlockNumber: bigint,
|
|
482
|
+
currentL1Timestamp: bigint,
|
|
483
|
+
) {
|
|
413
484
|
const rollupCanPrune = await this.canPrune(currentL1BlockNumber, currentL1Timestamp);
|
|
414
|
-
const
|
|
415
|
-
const canPrune =
|
|
485
|
+
const localPendingCheckpointNumber = await this.getSynchedCheckpointNumber();
|
|
486
|
+
const canPrune = localPendingCheckpointNumber > provenCheckpointNumber && rollupCanPrune;
|
|
416
487
|
|
|
417
488
|
if (canPrune) {
|
|
418
489
|
const timer = new Timer();
|
|
419
|
-
const pruneFrom =
|
|
490
|
+
const pruneFrom = CheckpointNumber(provenCheckpointNumber + 1);
|
|
420
491
|
|
|
421
|
-
const header = await this.
|
|
492
|
+
const header = await this.getCheckpointHeader(pruneFrom);
|
|
422
493
|
if (header === undefined) {
|
|
423
|
-
throw new Error(`Missing
|
|
494
|
+
throw new Error(`Missing checkpoint header ${pruneFrom}`);
|
|
424
495
|
}
|
|
425
496
|
|
|
426
|
-
const pruneFromSlotNumber = header.
|
|
427
|
-
const pruneFromEpochNumber = getEpochAtSlot(pruneFromSlotNumber, this.l1constants);
|
|
497
|
+
const pruneFromSlotNumber = header.slotNumber;
|
|
498
|
+
const pruneFromEpochNumber: EpochNumber = getEpochAtSlot(pruneFromSlotNumber, this.l1constants);
|
|
428
499
|
|
|
429
|
-
const
|
|
500
|
+
const checkpointsToUnwind = localPendingCheckpointNumber - provenCheckpointNumber;
|
|
430
501
|
|
|
431
|
-
const
|
|
502
|
+
const checkpoints = await this.getCheckpoints(pruneFrom, checkpointsToUnwind);
|
|
432
503
|
|
|
433
504
|
// Emit an event for listening services to react to the chain prune
|
|
434
505
|
this.emit(L2BlockSourceEvents.L2PruneDetected, {
|
|
435
506
|
type: L2BlockSourceEvents.L2PruneDetected,
|
|
436
507
|
epochNumber: pruneFromEpochNumber,
|
|
437
|
-
blocks,
|
|
508
|
+
blocks: checkpoints.flatMap(c => L2Block.fromCheckpoint(c)),
|
|
438
509
|
});
|
|
439
510
|
|
|
440
511
|
this.log.debug(
|
|
441
|
-
`L2 prune from ${
|
|
512
|
+
`L2 prune from ${provenCheckpointNumber + 1} to ${localPendingCheckpointNumber} will occur on next checkpoint submission.`,
|
|
442
513
|
);
|
|
443
|
-
await this.
|
|
514
|
+
await this.unwindCheckpoints(localPendingCheckpointNumber, checkpointsToUnwind);
|
|
444
515
|
this.log.warn(
|
|
445
|
-
`Unwound ${count(
|
|
446
|
-
`to ${
|
|
447
|
-
`Updated
|
|
516
|
+
`Unwound ${count(checkpointsToUnwind, 'checkpoint')} from checkpoint ${localPendingCheckpointNumber} ` +
|
|
517
|
+
`to ${provenCheckpointNumber} due to predicted reorg at L1 block ${currentL1BlockNumber}. ` +
|
|
518
|
+
`Updated latest checkpoint is ${await this.getSynchedCheckpointNumber()}.`,
|
|
448
519
|
);
|
|
449
520
|
this.instrumentation.processPrune(timer.ms());
|
|
450
521
|
// TODO(palla/reorg): Do we need to set the block synched L1 block number here?
|
|
@@ -491,7 +562,7 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
491
562
|
remoteMessagesState.totalMessagesInserted === localMessagesInserted &&
|
|
492
563
|
remoteMessagesState.messagesRollingHash.equals(localLastMessage?.rollingHash ?? Buffer16.ZERO)
|
|
493
564
|
) {
|
|
494
|
-
this.log.
|
|
565
|
+
this.log.trace(
|
|
495
566
|
`No L1 to L2 messages to query between L1 blocks ${messagesSyncPoint.l1BlockNumber} and ${currentL1BlockNumber}.`,
|
|
496
567
|
);
|
|
497
568
|
return;
|
|
@@ -545,7 +616,7 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
545
616
|
// Log stats for messages retrieved (if any).
|
|
546
617
|
if (messageCount > 0) {
|
|
547
618
|
this.log.info(
|
|
548
|
-
`Retrieved ${messageCount} new L1 to L2 messages up to message with index ${lastMessage?.index} for
|
|
619
|
+
`Retrieved ${messageCount} new L1 to L2 messages up to message with index ${lastMessage?.index} for checkpoint ${lastMessage?.checkpointNumber}`,
|
|
549
620
|
{ lastMessage, messageCount },
|
|
550
621
|
);
|
|
551
622
|
}
|
|
@@ -623,200 +694,225 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
623
694
|
return Buffer32.fromString(block.hash);
|
|
624
695
|
}
|
|
625
696
|
|
|
626
|
-
private async
|
|
627
|
-
const
|
|
697
|
+
private async handleCheckpoints(blocksSynchedTo: bigint, currentL1BlockNumber: bigint): Promise<RollupStatus> {
|
|
698
|
+
const localPendingCheckpointNumber = await this.getSynchedCheckpointNumber();
|
|
628
699
|
const initialValidationResult: ValidateBlockResult | undefined = await this.store.getPendingChainValidationStatus();
|
|
629
|
-
const [
|
|
630
|
-
|
|
700
|
+
const [
|
|
701
|
+
rollupProvenCheckpointNumber,
|
|
702
|
+
provenArchive,
|
|
703
|
+
rollupPendingCheckpointNumber,
|
|
704
|
+
pendingArchive,
|
|
705
|
+
archiveForLocalPendingCheckpointNumber,
|
|
706
|
+
] = await this.rollup.status(localPendingCheckpointNumber, { blockNumber: currentL1BlockNumber });
|
|
707
|
+
const provenCheckpointNumber = CheckpointNumber.fromBigInt(rollupProvenCheckpointNumber);
|
|
708
|
+
const pendingCheckpointNumber = CheckpointNumber.fromBigInt(rollupPendingCheckpointNumber);
|
|
631
709
|
const rollupStatus = {
|
|
632
|
-
|
|
710
|
+
provenCheckpointNumber,
|
|
633
711
|
provenArchive,
|
|
634
|
-
|
|
712
|
+
pendingCheckpointNumber,
|
|
635
713
|
pendingArchive,
|
|
636
714
|
validationResult: initialValidationResult,
|
|
637
715
|
};
|
|
638
716
|
this.log.trace(`Retrieved rollup status at current L1 block ${currentL1BlockNumber}.`, {
|
|
639
|
-
|
|
717
|
+
localPendingCheckpointNumber,
|
|
640
718
|
blocksSynchedTo,
|
|
641
719
|
currentL1BlockNumber,
|
|
642
|
-
|
|
720
|
+
archiveForLocalPendingCheckpointNumber,
|
|
643
721
|
...rollupStatus,
|
|
644
722
|
});
|
|
645
723
|
|
|
646
|
-
const
|
|
647
|
-
// Annoying edge case: if proven
|
|
648
|
-
// we need to set it to zero. This is an edge case because we dont have a
|
|
649
|
-
// so
|
|
650
|
-
if (
|
|
651
|
-
const
|
|
652
|
-
if (
|
|
653
|
-
await this.
|
|
654
|
-
this.log.info(`Rolled back proven chain to
|
|
724
|
+
const updateProvenCheckpoint = async () => {
|
|
725
|
+
// Annoying edge case: if proven checkpoint is moved back to 0 due to a reorg at the beginning of the chain,
|
|
726
|
+
// we need to set it to zero. This is an edge case because we dont have a checkpoint zero (initial checkpoint is one),
|
|
727
|
+
// so localCheckpointForDestinationProvenCheckpointNumber would not be found below.
|
|
728
|
+
if (provenCheckpointNumber === 0) {
|
|
729
|
+
const localProvenCheckpointNumber = await this.getProvenCheckpointNumber();
|
|
730
|
+
if (localProvenCheckpointNumber !== provenCheckpointNumber) {
|
|
731
|
+
await this.setProvenCheckpointNumber(provenCheckpointNumber);
|
|
732
|
+
this.log.info(`Rolled back proven chain to checkpoint ${provenCheckpointNumber}`, { provenCheckpointNumber });
|
|
655
733
|
}
|
|
656
734
|
}
|
|
657
735
|
|
|
658
|
-
const
|
|
736
|
+
const localCheckpointForDestinationProvenCheckpointNumber = await this.getCheckpoint(provenCheckpointNumber);
|
|
659
737
|
|
|
660
|
-
// Sanity check. I've hit what seems to be a state where the proven
|
|
661
|
-
// synched
|
|
662
|
-
const synched = await this.
|
|
663
|
-
if (
|
|
738
|
+
// Sanity check. I've hit what seems to be a state where the proven checkpoint is set to a value greater than the latest
|
|
739
|
+
// synched checkpoint when requesting L2Tips from the archiver. This is the only place where the proven checkpoint is set.
|
|
740
|
+
const synched = await this.getSynchedCheckpointNumber();
|
|
741
|
+
if (
|
|
742
|
+
localCheckpointForDestinationProvenCheckpointNumber &&
|
|
743
|
+
synched < localCheckpointForDestinationProvenCheckpointNumber.number
|
|
744
|
+
) {
|
|
664
745
|
this.log.error(
|
|
665
|
-
`Hit local
|
|
746
|
+
`Hit local checkpoint greater than last synched checkpoint: ${localCheckpointForDestinationProvenCheckpointNumber.number} > ${synched}`,
|
|
666
747
|
);
|
|
667
748
|
}
|
|
668
749
|
|
|
669
750
|
this.log.trace(
|
|
670
|
-
`Local
|
|
671
|
-
|
|
751
|
+
`Local checkpoint for remote proven checkpoint ${provenCheckpointNumber} is ${
|
|
752
|
+
localCheckpointForDestinationProvenCheckpointNumber?.archive.root.toString() ?? 'undefined'
|
|
672
753
|
}`,
|
|
673
754
|
);
|
|
674
755
|
|
|
756
|
+
const lastProvenBlockNumber = await this.getLastBlockNumberInCheckpoint(provenCheckpointNumber);
|
|
675
757
|
if (
|
|
676
|
-
|
|
677
|
-
provenArchive ===
|
|
758
|
+
localCheckpointForDestinationProvenCheckpointNumber &&
|
|
759
|
+
provenArchive === localCheckpointForDestinationProvenCheckpointNumber.archive.root.toString()
|
|
678
760
|
) {
|
|
679
|
-
const
|
|
680
|
-
if (
|
|
681
|
-
await this.
|
|
682
|
-
this.log.info(`Updated proven chain to
|
|
683
|
-
|
|
761
|
+
const localProvenCheckpointNumber = await this.getProvenCheckpointNumber();
|
|
762
|
+
if (localProvenCheckpointNumber !== provenCheckpointNumber) {
|
|
763
|
+
await this.setProvenCheckpointNumber(provenCheckpointNumber);
|
|
764
|
+
this.log.info(`Updated proven chain to checkpoint ${provenCheckpointNumber}`, {
|
|
765
|
+
provenCheckpointNumber,
|
|
684
766
|
});
|
|
685
|
-
const provenSlotNumber =
|
|
686
|
-
|
|
687
|
-
|
|
767
|
+
const provenSlotNumber = localCheckpointForDestinationProvenCheckpointNumber.header.slotNumber;
|
|
768
|
+
const provenEpochNumber: EpochNumber = getEpochAtSlot(provenSlotNumber, this.l1constants);
|
|
769
|
+
|
|
688
770
|
this.emit(L2BlockSourceEvents.L2BlockProven, {
|
|
689
771
|
type: L2BlockSourceEvents.L2BlockProven,
|
|
690
|
-
blockNumber:
|
|
772
|
+
blockNumber: lastProvenBlockNumber,
|
|
691
773
|
slotNumber: provenSlotNumber,
|
|
692
774
|
epochNumber: provenEpochNumber,
|
|
693
775
|
});
|
|
694
776
|
} else {
|
|
695
|
-
this.log.trace(`Proven
|
|
777
|
+
this.log.trace(`Proven checkpoint ${provenCheckpointNumber} already stored.`);
|
|
696
778
|
}
|
|
697
779
|
}
|
|
698
|
-
this.instrumentation.updateLastProvenBlock(
|
|
780
|
+
this.instrumentation.updateLastProvenBlock(lastProvenBlockNumber);
|
|
699
781
|
};
|
|
700
782
|
|
|
701
|
-
// This is an edge case that we only hit if there are no proposed
|
|
702
|
-
// If we have 0
|
|
703
|
-
const
|
|
704
|
-
if (
|
|
783
|
+
// This is an edge case that we only hit if there are no proposed checkpoints.
|
|
784
|
+
// If we have 0 checkpoints locally and there are no checkpoints onchain there is nothing to do.
|
|
785
|
+
const noCheckpoints = localPendingCheckpointNumber === 0 && pendingCheckpointNumber === 0;
|
|
786
|
+
if (noCheckpoints) {
|
|
705
787
|
await this.store.setBlockSynchedL1BlockNumber(currentL1BlockNumber);
|
|
706
788
|
this.log.debug(
|
|
707
|
-
`No
|
|
789
|
+
`No checkpoints to retrieve from ${blocksSynchedTo + 1n} to ${currentL1BlockNumber}, no checkpoints on chain`,
|
|
708
790
|
);
|
|
709
791
|
return rollupStatus;
|
|
710
792
|
}
|
|
711
793
|
|
|
712
|
-
await
|
|
794
|
+
await updateProvenCheckpoint();
|
|
713
795
|
|
|
714
796
|
// Related to the L2 reorgs of the pending chain. We are only interested in actually addressing a reorg if there
|
|
715
|
-
// are any state that could be impacted by it. If we have no
|
|
716
|
-
if (
|
|
717
|
-
const
|
|
718
|
-
if (
|
|
719
|
-
throw new Error(`Missing
|
|
797
|
+
// are any state that could be impacted by it. If we have no checkpoints, there is no impact.
|
|
798
|
+
if (localPendingCheckpointNumber > 0) {
|
|
799
|
+
const localPendingCheckpoint = await this.getCheckpoint(localPendingCheckpointNumber);
|
|
800
|
+
if (localPendingCheckpoint === undefined) {
|
|
801
|
+
throw new Error(`Missing checkpoint ${localPendingCheckpointNumber}`);
|
|
720
802
|
}
|
|
721
803
|
|
|
722
|
-
const localPendingArchiveRoot =
|
|
723
|
-
const
|
|
724
|
-
if (
|
|
804
|
+
const localPendingArchiveRoot = localPendingCheckpoint.archive.root.toString();
|
|
805
|
+
const noCheckpointSinceLast = localPendingCheckpoint && pendingArchive === localPendingArchiveRoot;
|
|
806
|
+
if (noCheckpointSinceLast) {
|
|
725
807
|
// We believe the following line causes a problem when we encounter L1 re-orgs.
|
|
726
808
|
// Basically, by setting the synched L1 block number here, we are saying that we have
|
|
727
|
-
// processed all
|
|
809
|
+
// processed all checkpoints up to the current L1 block number and we will not attempt to retrieve logs from
|
|
728
810
|
// this block again (or any blocks before).
|
|
729
|
-
// However, in the re-org scenario, our L1 node is temporarily lying to us and we end up potentially missing
|
|
811
|
+
// However, in the re-org scenario, our L1 node is temporarily lying to us and we end up potentially missing checkpoints.
|
|
730
812
|
// We must only set this block number based on actually retrieved logs.
|
|
731
813
|
// TODO(#8621): Tackle this properly when we handle L1 Re-orgs.
|
|
732
814
|
// await this.store.setBlockSynchedL1BlockNumber(currentL1BlockNumber);
|
|
733
|
-
this.log.debug(`No
|
|
815
|
+
this.log.debug(`No checkpoints to retrieve from ${blocksSynchedTo + 1n} to ${currentL1BlockNumber}`);
|
|
734
816
|
return rollupStatus;
|
|
735
817
|
}
|
|
736
818
|
|
|
737
|
-
const
|
|
738
|
-
if (!
|
|
739
|
-
// If our local pending
|
|
819
|
+
const localPendingCheckpointInChain = archiveForLocalPendingCheckpointNumber === localPendingArchiveRoot;
|
|
820
|
+
if (!localPendingCheckpointInChain) {
|
|
821
|
+
// If our local pending checkpoint tip is not in the chain on L1 a "prune" must have happened
|
|
740
822
|
// or the L1 have reorged.
|
|
741
823
|
// In any case, we have to figure out how far into the past the action will take us.
|
|
742
|
-
// For simplicity here, we will simply rewind until we end in a
|
|
824
|
+
// For simplicity here, we will simply rewind until we end in a checkpoint that is also on the chain on L1.
|
|
743
825
|
this.log.debug(
|
|
744
|
-
`L2 prune has been detected due to local pending
|
|
745
|
-
{
|
|
826
|
+
`L2 prune has been detected due to local pending checkpoint ${localPendingCheckpointNumber} not in chain`,
|
|
827
|
+
{ localPendingCheckpointNumber, localPendingArchiveRoot, archiveForLocalPendingCheckpointNumber },
|
|
746
828
|
);
|
|
747
829
|
|
|
748
|
-
let tipAfterUnwind =
|
|
830
|
+
let tipAfterUnwind = localPendingCheckpointNumber;
|
|
749
831
|
while (true) {
|
|
750
|
-
const
|
|
751
|
-
if (
|
|
832
|
+
const candidateCheckpoint = await this.getCheckpoint(tipAfterUnwind);
|
|
833
|
+
if (candidateCheckpoint === undefined) {
|
|
752
834
|
break;
|
|
753
835
|
}
|
|
754
836
|
|
|
755
|
-
const archiveAtContract = await this.rollup.archiveAt(
|
|
756
|
-
|
|
757
|
-
|
|
837
|
+
const archiveAtContract = await this.rollup.archiveAt(candidateCheckpoint.number);
|
|
838
|
+
this.log.trace(
|
|
839
|
+
`Checking local checkpoint ${candidateCheckpoint.number} with archive ${candidateCheckpoint.archive.root}`,
|
|
840
|
+
{
|
|
841
|
+
archiveAtContract,
|
|
842
|
+
archiveLocal: candidateCheckpoint.archive.root.toString(),
|
|
843
|
+
},
|
|
844
|
+
);
|
|
845
|
+
if (archiveAtContract === candidateCheckpoint.archive.root.toString()) {
|
|
758
846
|
break;
|
|
759
847
|
}
|
|
760
848
|
tipAfterUnwind--;
|
|
761
849
|
}
|
|
762
850
|
|
|
763
|
-
const
|
|
764
|
-
await this.
|
|
851
|
+
const checkpointsToUnwind = localPendingCheckpointNumber - tipAfterUnwind;
|
|
852
|
+
await this.unwindCheckpoints(localPendingCheckpointNumber, checkpointsToUnwind);
|
|
765
853
|
|
|
766
854
|
this.log.warn(
|
|
767
|
-
`Unwound ${count(
|
|
768
|
-
`due to mismatched
|
|
769
|
-
`Updated L2 latest
|
|
855
|
+
`Unwound ${count(checkpointsToUnwind, 'checkpoint')} from checkpoint ${localPendingCheckpointNumber} ` +
|
|
856
|
+
`due to mismatched checkpoint hashes at L1 block ${currentL1BlockNumber}. ` +
|
|
857
|
+
`Updated L2 latest checkpoint is ${await this.getSynchedCheckpointNumber()}.`,
|
|
770
858
|
);
|
|
771
859
|
}
|
|
772
860
|
}
|
|
773
861
|
|
|
774
|
-
// Retrieve
|
|
862
|
+
// Retrieve checkpoints in batches. Each batch is estimated to accommodate up to 'blockBatchSize' L1 blocks,
|
|
775
863
|
// computed using the L2 block time vs the L1 block time.
|
|
776
864
|
let searchStartBlock: bigint = blocksSynchedTo;
|
|
777
865
|
let searchEndBlock: bigint = blocksSynchedTo;
|
|
778
|
-
let
|
|
866
|
+
let lastRetrievedCheckpoint: PublishedCheckpoint | undefined;
|
|
867
|
+
let lastL1BlockWithCheckpoint: bigint | undefined = undefined;
|
|
779
868
|
|
|
780
869
|
do {
|
|
781
870
|
[searchStartBlock, searchEndBlock] = this.nextRange(searchEndBlock, currentL1BlockNumber);
|
|
782
871
|
|
|
783
|
-
this.log.trace(`Retrieving
|
|
872
|
+
this.log.trace(`Retrieving checkpoints from L1 block ${searchStartBlock} to ${searchEndBlock}`);
|
|
784
873
|
|
|
785
874
|
// TODO(md): Retrieve from blob sink then from consensus client, then from peers
|
|
786
|
-
const
|
|
875
|
+
const retrievedCheckpoints = await retrieveCheckpointsFromRollup(
|
|
787
876
|
this.rollup.getContract() as GetContractReturnType<typeof RollupAbi, ViemPublicClient>,
|
|
788
877
|
this.publicClient,
|
|
878
|
+
this.debugClient,
|
|
789
879
|
this.blobSinkClient,
|
|
790
880
|
searchStartBlock, // TODO(palla/reorg): If the L2 reorg was due to an L1 reorg, we need to start search earlier
|
|
791
881
|
searchEndBlock,
|
|
882
|
+
this.l1Addresses,
|
|
883
|
+
this.instrumentation,
|
|
792
884
|
this.log,
|
|
793
885
|
);
|
|
794
886
|
|
|
795
|
-
if (
|
|
887
|
+
if (retrievedCheckpoints.length === 0) {
|
|
796
888
|
// We are not calling `setBlockSynchedL1BlockNumber` because it may cause sync issues if based off infura.
|
|
797
889
|
// See further details in earlier comments.
|
|
798
|
-
this.log.trace(`Retrieved no new
|
|
890
|
+
this.log.trace(`Retrieved no new checkpoints from L1 block ${searchStartBlock} to ${searchEndBlock}`);
|
|
799
891
|
continue;
|
|
800
892
|
}
|
|
801
893
|
|
|
802
|
-
const lastProcessedL1BlockNumber = retrievedBlocks[retrievedBlocks.length - 1].l1.blockNumber;
|
|
803
894
|
this.log.debug(
|
|
804
|
-
`Retrieved ${
|
|
895
|
+
`Retrieved ${retrievedCheckpoints.length} new checkpoints between L1 blocks ${searchStartBlock} and ${searchEndBlock}`,
|
|
896
|
+
{
|
|
897
|
+
lastProcessedCheckpoint: retrievedCheckpoints[retrievedCheckpoints.length - 1].l1,
|
|
898
|
+
searchStartBlock,
|
|
899
|
+
searchEndBlock,
|
|
900
|
+
},
|
|
805
901
|
);
|
|
806
902
|
|
|
807
|
-
const
|
|
808
|
-
const
|
|
903
|
+
const publishedCheckpoints = await Promise.all(retrievedCheckpoints.map(b => retrievedToPublishedCheckpoint(b)));
|
|
904
|
+
const validCheckpoints: PublishedCheckpoint[] = [];
|
|
809
905
|
|
|
810
|
-
for (const
|
|
906
|
+
for (const published of publishedCheckpoints) {
|
|
811
907
|
const validationResult = this.config.skipValidateBlockAttestations
|
|
812
908
|
? { valid: true as const }
|
|
813
|
-
: await
|
|
909
|
+
: await validateCheckpointAttestations(published, this.epochCache, this.l1constants, this.log);
|
|
814
910
|
|
|
815
|
-
// Only update the validation result if it has changed, so we can keep track of the first invalid
|
|
816
|
-
// in case there is a sequence of more than one invalid
|
|
817
|
-
// There is an exception though: if
|
|
911
|
+
// Only update the validation result if it has changed, so we can keep track of the first invalid checkpoint
|
|
912
|
+
// in case there is a sequence of more than one invalid checkpoint, as we need to invalidate the first one.
|
|
913
|
+
// There is an exception though: if a checkpoint is invalidated and replaced with another invalid checkpoint,
|
|
818
914
|
// we need to update the validation result, since we need to be able to invalidate the new one.
|
|
819
|
-
// See test 'chain progresses if an invalid
|
|
915
|
+
// See test 'chain progresses if an invalid checkpoint is invalidated with an invalid one' for more info.
|
|
820
916
|
if (
|
|
821
917
|
rollupStatus.validationResult?.valid !== validationResult.valid ||
|
|
822
918
|
(!rollupStatus.validationResult.valid &&
|
|
@@ -827,9 +923,9 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
827
923
|
}
|
|
828
924
|
|
|
829
925
|
if (!validationResult.valid) {
|
|
830
|
-
this.log.warn(`Skipping
|
|
831
|
-
|
|
832
|
-
l1BlockNumber:
|
|
926
|
+
this.log.warn(`Skipping checkpoint ${published.checkpoint.number} due to invalid attestations`, {
|
|
927
|
+
checkpointHash: published.checkpoint.hash(),
|
|
928
|
+
l1BlockNumber: published.l1.blockNumber,
|
|
833
929
|
...pick(validationResult, 'reason'),
|
|
834
930
|
});
|
|
835
931
|
|
|
@@ -839,34 +935,56 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
839
935
|
validationResult,
|
|
840
936
|
});
|
|
841
937
|
|
|
842
|
-
// We keep consuming
|
|
843
|
-
// We just pretend the invalid ones are not there and keep consuming the next
|
|
844
|
-
// Note that this breaks if the committee ever attests to a descendant of an invalid
|
|
938
|
+
// We keep consuming checkpoints if we find an invalid one, since we do not listen for CheckpointInvalidated events
|
|
939
|
+
// We just pretend the invalid ones are not there and keep consuming the next checkpoints
|
|
940
|
+
// Note that this breaks if the committee ever attests to a descendant of an invalid checkpoint
|
|
845
941
|
continue;
|
|
846
942
|
}
|
|
847
943
|
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
944
|
+
// Check the inHash of the checkpoint against the l1->l2 messages.
|
|
945
|
+
// The messages should've been synced up to the currentL1BlockNumber and must be available for the published
|
|
946
|
+
// checkpoints we just retrieved.
|
|
947
|
+
const l1ToL2Messages = await this.getL1ToL2Messages(published.checkpoint.number);
|
|
948
|
+
const computedInHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
949
|
+
const publishedInHash = published.checkpoint.header.contentCommitment.inHash;
|
|
950
|
+
if (!computedInHash.equals(publishedInHash)) {
|
|
951
|
+
this.log.fatal(`Mismatch inHash for checkpoint ${published.checkpoint.number}`, {
|
|
952
|
+
checkpointHash: published.checkpoint.hash(),
|
|
953
|
+
l1BlockNumber: published.l1.blockNumber,
|
|
954
|
+
computedInHash,
|
|
955
|
+
publishedInHash,
|
|
956
|
+
});
|
|
957
|
+
// Throwing an error since this is most likely caused by a bug.
|
|
958
|
+
throw new Error(
|
|
959
|
+
`Mismatch inHash for checkpoint ${published.checkpoint.number}. Expected ${computedInHash} but got ${publishedInHash}`,
|
|
960
|
+
);
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
validCheckpoints.push(published);
|
|
964
|
+
this.log.debug(
|
|
965
|
+
`Ingesting new checkpoint ${published.checkpoint.number} with ${published.checkpoint.blocks.length} blocks`,
|
|
966
|
+
{
|
|
967
|
+
checkpointHash: published.checkpoint.hash(),
|
|
968
|
+
l1BlockNumber: published.l1.blockNumber,
|
|
969
|
+
...published.checkpoint.header.toInspect(),
|
|
970
|
+
blocks: published.checkpoint.blocks.map(b => b.getStats()),
|
|
971
|
+
},
|
|
972
|
+
);
|
|
855
973
|
}
|
|
856
974
|
|
|
857
975
|
try {
|
|
858
976
|
const updatedValidationResult =
|
|
859
977
|
rollupStatus.validationResult === initialValidationResult ? undefined : rollupStatus.validationResult;
|
|
860
|
-
const [processDuration] = await elapsed(() => this.
|
|
978
|
+
const [processDuration] = await elapsed(() => this.addCheckpoints(validCheckpoints, updatedValidationResult));
|
|
861
979
|
this.instrumentation.processNewBlocks(
|
|
862
|
-
processDuration /
|
|
863
|
-
|
|
980
|
+
processDuration / validCheckpoints.length,
|
|
981
|
+
validCheckpoints.flatMap(c => c.checkpoint.blocks),
|
|
864
982
|
);
|
|
865
983
|
} catch (err) {
|
|
866
984
|
if (err instanceof InitialBlockNumberNotSequentialError) {
|
|
867
985
|
const { previousBlockNumber, newBlockNumber } = err;
|
|
868
986
|
const previousBlock = previousBlockNumber
|
|
869
|
-
? await this.store.getPublishedBlock(previousBlockNumber)
|
|
987
|
+
? await this.store.getPublishedBlock(BlockNumber(previousBlockNumber))
|
|
870
988
|
: undefined;
|
|
871
989
|
const updatedL1SyncPoint = previousBlock?.l1.blockNumber ?? this.l1constants.l1StartBlock;
|
|
872
990
|
await this.store.setBlockSynchedL1BlockNumber(updatedL1SyncPoint);
|
|
@@ -883,56 +1001,56 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
883
1001
|
throw err;
|
|
884
1002
|
}
|
|
885
1003
|
|
|
886
|
-
for (const
|
|
887
|
-
this.log.info(`Downloaded
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
1004
|
+
for (const checkpoint of validCheckpoints) {
|
|
1005
|
+
this.log.info(`Downloaded checkpoint ${checkpoint.checkpoint.number}`, {
|
|
1006
|
+
checkpointHash: checkpoint.checkpoint.hash(),
|
|
1007
|
+
checkpointNumber: checkpoint.checkpoint.number,
|
|
1008
|
+
blockCount: checkpoint.checkpoint.blocks.length,
|
|
1009
|
+
txCount: checkpoint.checkpoint.blocks.reduce((acc, b) => acc + b.body.txEffects.length, 0),
|
|
1010
|
+
header: checkpoint.checkpoint.header.toInspect(),
|
|
1011
|
+
archiveRoot: checkpoint.checkpoint.archive.root.toString(),
|
|
1012
|
+
archiveNextLeafIndex: checkpoint.checkpoint.archive.nextAvailableLeafIndex,
|
|
894
1013
|
});
|
|
895
1014
|
}
|
|
896
|
-
|
|
1015
|
+
lastRetrievedCheckpoint = validCheckpoints.at(-1) ?? lastRetrievedCheckpoint;
|
|
1016
|
+
lastL1BlockWithCheckpoint = retrievedCheckpoints.at(-1)?.l1.blockNumber ?? lastL1BlockWithCheckpoint;
|
|
897
1017
|
} while (searchEndBlock < currentL1BlockNumber);
|
|
898
1018
|
|
|
899
1019
|
// Important that we update AFTER inserting the blocks.
|
|
900
|
-
await
|
|
1020
|
+
await updateProvenCheckpoint();
|
|
901
1021
|
|
|
902
|
-
return { ...rollupStatus,
|
|
1022
|
+
return { ...rollupStatus, lastRetrievedCheckpoint, lastL1BlockWithCheckpoint };
|
|
903
1023
|
}
|
|
904
1024
|
|
|
905
|
-
private async
|
|
906
|
-
status:
|
|
907
|
-
lastRetrievedBlock?: PublishedL2Block;
|
|
908
|
-
pendingBlockNumber: number;
|
|
909
|
-
},
|
|
1025
|
+
private async checkForNewCheckpointsBeforeL1SyncPoint(
|
|
1026
|
+
status: RollupStatus,
|
|
910
1027
|
blocksSynchedTo: bigint,
|
|
911
1028
|
currentL1BlockNumber: bigint,
|
|
912
1029
|
) {
|
|
913
|
-
const {
|
|
914
|
-
// Compare the last
|
|
1030
|
+
const { lastRetrievedCheckpoint, pendingCheckpointNumber } = status;
|
|
1031
|
+
// Compare the last checkpoint we have (either retrieved in this round or loaded from store) with what the
|
|
915
1032
|
// rollup contract told us was the latest one (pinned at the currentL1BlockNumber).
|
|
916
|
-
const
|
|
917
|
-
|
|
1033
|
+
const latestLocalCheckpointNumber =
|
|
1034
|
+
lastRetrievedCheckpoint?.checkpoint.number ?? (await this.getSynchedCheckpointNumber());
|
|
1035
|
+
if (latestLocalCheckpointNumber < pendingCheckpointNumber) {
|
|
918
1036
|
// Here we have consumed all logs until the `currentL1Block` we pinned at the beginning of the archiver loop,
|
|
919
|
-
// but still
|
|
920
|
-
// We suspect an L1 reorg that added
|
|
921
|
-
// last
|
|
922
|
-
// don't have one, we go back 2 L1 epochs, which is the deepest possible reorg (assuming Casper is working).
|
|
923
|
-
const
|
|
924
|
-
|
|
925
|
-
(
|
|
926
|
-
? await this.
|
|
1037
|
+
// but still haven't reached the pending checkpoint according to the call to the rollup contract.
|
|
1038
|
+
// We suspect an L1 reorg that added checkpoints *behind* us. If that is the case, it must have happened between
|
|
1039
|
+
// the last checkpoint we saw and the current one, so we reset the last synched L1 block number. In the edge case
|
|
1040
|
+
// we don't have one, we go back 2 L1 epochs, which is the deepest possible reorg (assuming Casper is working).
|
|
1041
|
+
const latestLocalCheckpoint =
|
|
1042
|
+
lastRetrievedCheckpoint ??
|
|
1043
|
+
(latestLocalCheckpointNumber > 0
|
|
1044
|
+
? await this.getPublishedCheckpoints(latestLocalCheckpointNumber, 1).then(([c]) => c)
|
|
927
1045
|
: undefined);
|
|
928
|
-
const targetL1BlockNumber =
|
|
929
|
-
const
|
|
1046
|
+
const targetL1BlockNumber = latestLocalCheckpoint?.l1.blockNumber ?? maxBigint(currentL1BlockNumber - 64n, 0n);
|
|
1047
|
+
const latestLocalCheckpointArchive = latestLocalCheckpoint?.checkpoint.archive.root.toString();
|
|
930
1048
|
this.log.warn(
|
|
931
|
-
`Failed to reach
|
|
1049
|
+
`Failed to reach checkpoint ${pendingCheckpointNumber} at ${currentL1BlockNumber} (latest is ${latestLocalCheckpointNumber}). ` +
|
|
932
1050
|
`Rolling back last synched L1 block number to ${targetL1BlockNumber}.`,
|
|
933
1051
|
{
|
|
934
|
-
|
|
935
|
-
|
|
1052
|
+
latestLocalCheckpointNumber,
|
|
1053
|
+
latestLocalCheckpointArchive,
|
|
936
1054
|
blocksSynchedTo,
|
|
937
1055
|
currentL1BlockNumber,
|
|
938
1056
|
...status,
|
|
@@ -940,18 +1058,15 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
940
1058
|
);
|
|
941
1059
|
await this.store.setBlockSynchedL1BlockNumber(targetL1BlockNumber);
|
|
942
1060
|
} else {
|
|
943
|
-
this.log.trace(`No new
|
|
944
|
-
|
|
945
|
-
|
|
1061
|
+
this.log.trace(`No new checkpoints behind L1 sync point to retrieve.`, {
|
|
1062
|
+
latestLocalCheckpointNumber,
|
|
1063
|
+
pendingCheckpointNumber,
|
|
946
1064
|
});
|
|
947
1065
|
}
|
|
948
1066
|
}
|
|
949
1067
|
|
|
950
1068
|
/** Resumes the archiver after a stop. */
|
|
951
1069
|
public resume() {
|
|
952
|
-
if (!this.runningPromise) {
|
|
953
|
-
throw new Error(`Archiver was never started`);
|
|
954
|
-
}
|
|
955
1070
|
if (this.runningPromise.isRunning()) {
|
|
956
1071
|
this.log.warn(`Archiver already running`);
|
|
957
1072
|
}
|
|
@@ -965,7 +1080,7 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
965
1080
|
*/
|
|
966
1081
|
public async stop(): Promise<void> {
|
|
967
1082
|
this.log.debug('Stopping...');
|
|
968
|
-
await this.runningPromise
|
|
1083
|
+
await this.runningPromise.stop();
|
|
969
1084
|
|
|
970
1085
|
this.log.info('Stopped.');
|
|
971
1086
|
return Promise.resolve();
|
|
@@ -991,49 +1106,45 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
991
1106
|
return Promise.resolve(this.l1Addresses.registryAddress);
|
|
992
1107
|
}
|
|
993
1108
|
|
|
994
|
-
public getL1BlockNumber(): bigint {
|
|
995
|
-
|
|
996
|
-
if (!l1BlockNumber) {
|
|
997
|
-
throw new Error('L1 block number not yet available. Complete an initial sync first.');
|
|
998
|
-
}
|
|
999
|
-
return l1BlockNumber;
|
|
1109
|
+
public getL1BlockNumber(): bigint | undefined {
|
|
1110
|
+
return this.l1BlockNumber;
|
|
1000
1111
|
}
|
|
1001
1112
|
|
|
1002
|
-
public getL1Timestamp(): Promise<bigint> {
|
|
1003
|
-
|
|
1004
|
-
if (!l1Timestamp) {
|
|
1005
|
-
throw new Error('L1 timestamp not yet available. Complete an initial sync first.');
|
|
1006
|
-
}
|
|
1007
|
-
return Promise.resolve(l1Timestamp);
|
|
1113
|
+
public getL1Timestamp(): Promise<bigint | undefined> {
|
|
1114
|
+
return Promise.resolve(this.l1Timestamp);
|
|
1008
1115
|
}
|
|
1009
1116
|
|
|
1010
|
-
public
|
|
1011
|
-
return
|
|
1117
|
+
public getL2SlotNumber(): Promise<SlotNumber | undefined> {
|
|
1118
|
+
return Promise.resolve(
|
|
1119
|
+
this.l1Timestamp === undefined ? undefined : getSlotAtTimestamp(this.l1Timestamp, this.l1constants),
|
|
1120
|
+
);
|
|
1012
1121
|
}
|
|
1013
1122
|
|
|
1014
|
-
public
|
|
1015
|
-
return
|
|
1123
|
+
public getL2EpochNumber(): Promise<EpochNumber | undefined> {
|
|
1124
|
+
return Promise.resolve(
|
|
1125
|
+
this.l1Timestamp === undefined ? undefined : getEpochNumberAtTimestamp(this.l1Timestamp, this.l1constants),
|
|
1126
|
+
);
|
|
1016
1127
|
}
|
|
1017
1128
|
|
|
1018
|
-
public async getBlocksForEpoch(epochNumber:
|
|
1129
|
+
public async getBlocksForEpoch(epochNumber: EpochNumber): Promise<L2Block[]> {
|
|
1019
1130
|
const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1constants);
|
|
1020
1131
|
const blocks: L2Block[] = [];
|
|
1021
1132
|
|
|
1022
1133
|
// Walk the list of blocks backwards and filter by slots matching the requested epoch.
|
|
1023
1134
|
// We'll typically ask for blocks for a very recent epoch, so we shouldn't need an index here.
|
|
1024
1135
|
let block = await this.getBlock(await this.store.getSynchedL2BlockNumber());
|
|
1025
|
-
const slot = (b: L2Block) => b.header.globalVariables.slotNumber
|
|
1136
|
+
const slot = (b: L2Block) => b.header.globalVariables.slotNumber;
|
|
1026
1137
|
while (block && slot(block) >= start) {
|
|
1027
1138
|
if (slot(block) <= end) {
|
|
1028
1139
|
blocks.push(block);
|
|
1029
1140
|
}
|
|
1030
|
-
block = await this.getBlock(block.number - 1);
|
|
1141
|
+
block = await this.getBlock(BlockNumber(block.number - 1));
|
|
1031
1142
|
}
|
|
1032
1143
|
|
|
1033
1144
|
return blocks.reverse();
|
|
1034
1145
|
}
|
|
1035
1146
|
|
|
1036
|
-
public async getBlockHeadersForEpoch(epochNumber:
|
|
1147
|
+
public async getBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
|
|
1037
1148
|
const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1constants);
|
|
1038
1149
|
const blocks: BlockHeader[] = [];
|
|
1039
1150
|
|
|
@@ -1041,20 +1152,21 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
1041
1152
|
// We'll typically ask for blocks for a very recent epoch, so we shouldn't need an index here.
|
|
1042
1153
|
let number = await this.store.getSynchedL2BlockNumber();
|
|
1043
1154
|
let header = await this.getBlockHeader(number);
|
|
1044
|
-
const slot = (b: BlockHeader) => b.globalVariables.slotNumber
|
|
1155
|
+
const slot = (b: BlockHeader) => b.globalVariables.slotNumber;
|
|
1045
1156
|
while (header && slot(header) >= start) {
|
|
1046
1157
|
if (slot(header) <= end) {
|
|
1047
1158
|
blocks.push(header);
|
|
1048
1159
|
}
|
|
1049
|
-
|
|
1160
|
+
number = BlockNumber(number - 1);
|
|
1161
|
+
header = await this.getBlockHeader(number);
|
|
1050
1162
|
}
|
|
1051
1163
|
return blocks.reverse();
|
|
1052
1164
|
}
|
|
1053
1165
|
|
|
1054
|
-
public async isEpochComplete(epochNumber:
|
|
1166
|
+
public async isEpochComplete(epochNumber: EpochNumber): Promise<boolean> {
|
|
1055
1167
|
// The epoch is complete if the current L2 block is the last one in the epoch (or later)
|
|
1056
1168
|
const header = await this.getBlockHeader('latest');
|
|
1057
|
-
const slot = header
|
|
1169
|
+
const slot = header ? header.globalVariables.slotNumber : undefined;
|
|
1058
1170
|
const [_startSlot, endSlot] = getSlotRangeForEpoch(epochNumber, this.l1constants);
|
|
1059
1171
|
if (slot && slot >= endSlot) {
|
|
1060
1172
|
return true;
|
|
@@ -1084,6 +1196,101 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
1084
1196
|
return this.initialSyncComplete;
|
|
1085
1197
|
}
|
|
1086
1198
|
|
|
1199
|
+
public async getPublishedCheckpoints(
|
|
1200
|
+
from: CheckpointNumber,
|
|
1201
|
+
limit: number,
|
|
1202
|
+
proven?: boolean,
|
|
1203
|
+
): Promise<PublishedCheckpoint[]> {
|
|
1204
|
+
// TODO: Implement this properly. This only works when we have one block per checkpoint.
|
|
1205
|
+
const blocks = await this.getPublishedBlocks(BlockNumber(from), limit, proven);
|
|
1206
|
+
return blocks.map(b => b.toPublishedCheckpoint());
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
public async getCheckpointByArchive(archive: Fr): Promise<Checkpoint | undefined> {
|
|
1210
|
+
// TODO: Implement this properly. This only works when we have one block per checkpoint.
|
|
1211
|
+
return (await this.getPublishedBlockByArchive(archive))?.block.toCheckpoint();
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
public async getCheckpoints(from: CheckpointNumber, limit: number, proven?: boolean): Promise<Checkpoint[]> {
|
|
1215
|
+
const published = await this.getPublishedCheckpoints(from, limit, proven);
|
|
1216
|
+
return published.map(p => p.checkpoint);
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
public async getCheckpoint(number: CheckpointNumber): Promise<Checkpoint | undefined> {
|
|
1220
|
+
if (number < 0) {
|
|
1221
|
+
number = await this.getSynchedCheckpointNumber();
|
|
1222
|
+
}
|
|
1223
|
+
if (number === 0) {
|
|
1224
|
+
return undefined;
|
|
1225
|
+
}
|
|
1226
|
+
const published = await this.getPublishedCheckpoints(number, 1);
|
|
1227
|
+
return published[0]?.checkpoint;
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
public async getCheckpointHeader(number: CheckpointNumber | 'latest'): Promise<CheckpointHeader | undefined> {
|
|
1231
|
+
if (number === 'latest') {
|
|
1232
|
+
number = await this.getSynchedCheckpointNumber();
|
|
1233
|
+
}
|
|
1234
|
+
if (number === 0) {
|
|
1235
|
+
return undefined;
|
|
1236
|
+
}
|
|
1237
|
+
const checkpoint = await this.getCheckpoint(number);
|
|
1238
|
+
return checkpoint?.header;
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
public getCheckpointNumber(): Promise<CheckpointNumber> {
|
|
1242
|
+
return this.getSynchedCheckpointNumber();
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
public async getSynchedCheckpointNumber(): Promise<CheckpointNumber> {
|
|
1246
|
+
// TODO: Create store and apis for checkpoints.
|
|
1247
|
+
// Checkpoint number will no longer be the same as the block number once we support multiple blocks per checkpoint.
|
|
1248
|
+
return CheckpointNumber(await this.store.getSynchedL2BlockNumber());
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
public async getProvenCheckpointNumber(): Promise<CheckpointNumber> {
|
|
1252
|
+
// TODO: Create store and apis for checkpoints.
|
|
1253
|
+
// Proven checkpoint number will no longer be the same as the proven block number once we support multiple blocks per checkpoint.
|
|
1254
|
+
return CheckpointNumber(await this.store.getProvenL2BlockNumber());
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
public setProvenCheckpointNumber(checkpointNumber: CheckpointNumber): Promise<void> {
|
|
1258
|
+
// TODO: Create store and apis for checkpoints.
|
|
1259
|
+
// Proven checkpoint number will no longer be the same as the proven block number once we support multiple blocks per checkpoint.
|
|
1260
|
+
return this.store.setProvenL2BlockNumber(BlockNumber.fromCheckpointNumber(checkpointNumber));
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
public unwindCheckpoints(from: CheckpointNumber, checkpointsToUnwind: number): Promise<boolean> {
|
|
1264
|
+
// TODO: Create store and apis for checkpoints.
|
|
1265
|
+
// This only works when we have one block per checkpoint.
|
|
1266
|
+
return this.store.unwindBlocks(BlockNumber.fromCheckpointNumber(from), checkpointsToUnwind);
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
public getLastBlockNumberInCheckpoint(checkpointNumber: CheckpointNumber): Promise<BlockNumber> {
|
|
1270
|
+
// TODO: Create store and apis for checkpoints.
|
|
1271
|
+
// Checkpoint number will no longer be the same as the block number once we support multiple blocks per checkpoint.
|
|
1272
|
+
return Promise.resolve(BlockNumber.fromCheckpointNumber(checkpointNumber));
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
public addCheckpoints(
|
|
1276
|
+
checkpoints: PublishedCheckpoint[],
|
|
1277
|
+
pendingChainValidationStatus?: ValidateBlockResult,
|
|
1278
|
+
): Promise<boolean> {
|
|
1279
|
+
// TODO: Create store and apis for checkpoints.
|
|
1280
|
+
// This only works when we have one block per checkpoint.
|
|
1281
|
+
return this.store.addBlocks(
|
|
1282
|
+
checkpoints.map(p => PublishedL2Block.fromPublishedCheckpoint(p)),
|
|
1283
|
+
pendingChainValidationStatus,
|
|
1284
|
+
);
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
public async getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]> {
|
|
1288
|
+
// TODO: Create store and apis for checkpoints.
|
|
1289
|
+
// This only works when we have one block per checkpoint.
|
|
1290
|
+
const blocks = await this.getBlocksForEpoch(epochNumber);
|
|
1291
|
+
return blocks.map(b => b.toCheckpoint());
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1087
1294
|
/**
|
|
1088
1295
|
* Gets up to `limit` amount of L2 blocks starting from `from`.
|
|
1089
1296
|
* @param from - Number of the first block to return (inclusive).
|
|
@@ -1091,12 +1298,12 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
1091
1298
|
* @param proven - If true, only return blocks that have been proven.
|
|
1092
1299
|
* @returns The requested L2 blocks.
|
|
1093
1300
|
*/
|
|
1094
|
-
public getBlocks(from:
|
|
1301
|
+
public getBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<L2Block[]> {
|
|
1095
1302
|
return this.getPublishedBlocks(from, limit, proven).then(blocks => blocks.map(b => b.block));
|
|
1096
1303
|
}
|
|
1097
1304
|
|
|
1098
1305
|
/** Equivalent to getBlocks but includes publish data. */
|
|
1099
|
-
public async getPublishedBlocks(from:
|
|
1306
|
+
public async getPublishedBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<PublishedL2Block[]> {
|
|
1100
1307
|
const limitWithProven = proven
|
|
1101
1308
|
? Math.min(limit, Math.max((await this.store.getProvenL2BlockNumber()) - from + 1, 0))
|
|
1102
1309
|
: limit;
|
|
@@ -1124,7 +1331,7 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
1124
1331
|
* @param number - The block number to return.
|
|
1125
1332
|
* @returns The requested L2 block.
|
|
1126
1333
|
*/
|
|
1127
|
-
public async getBlock(number:
|
|
1334
|
+
public async getBlock(number: BlockNumber): Promise<L2Block | undefined> {
|
|
1128
1335
|
// If the number provided is -ve, then return the latest block.
|
|
1129
1336
|
if (number < 0) {
|
|
1130
1337
|
number = await this.store.getSynchedL2BlockNumber();
|
|
@@ -1136,7 +1343,7 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
1136
1343
|
return publishedBlock?.block;
|
|
1137
1344
|
}
|
|
1138
1345
|
|
|
1139
|
-
public async getBlockHeader(number:
|
|
1346
|
+
public async getBlockHeader(number: BlockNumber | 'latest'): Promise<BlockHeader | undefined> {
|
|
1140
1347
|
if (number === 'latest') {
|
|
1141
1348
|
number = await this.store.getSynchedL2BlockNumber();
|
|
1142
1349
|
}
|
|
@@ -1155,16 +1362,6 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
1155
1362
|
return this.store.getSettledTxReceipt(txHash);
|
|
1156
1363
|
}
|
|
1157
1364
|
|
|
1158
|
-
/**
|
|
1159
|
-
* Retrieves all private logs from up to `limit` blocks, starting from the block number `from`.
|
|
1160
|
-
* @param from - The block number from which to begin retrieving logs.
|
|
1161
|
-
* @param limit - The maximum number of blocks to retrieve logs from.
|
|
1162
|
-
* @returns An array of private logs from the specified range of blocks.
|
|
1163
|
-
*/
|
|
1164
|
-
public getPrivateLogs(from: number, limit: number): Promise<PrivateLog[]> {
|
|
1165
|
-
return this.store.getPrivateLogs(from, limit);
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
1365
|
/**
|
|
1169
1366
|
* Gets all logs that match any of the received tags (i.e. logs with their first field equal to a tag).
|
|
1170
1367
|
* @param tags - The tags to filter the logs by.
|
|
@@ -1197,16 +1394,16 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
1197
1394
|
* Gets the number of the latest L2 block processed by the block source implementation.
|
|
1198
1395
|
* @returns The number of the latest L2 block processed by the block source implementation.
|
|
1199
1396
|
*/
|
|
1200
|
-
public getBlockNumber(): Promise<
|
|
1397
|
+
public getBlockNumber(): Promise<BlockNumber> {
|
|
1201
1398
|
return this.store.getSynchedL2BlockNumber();
|
|
1202
1399
|
}
|
|
1203
1400
|
|
|
1204
|
-
public getProvenBlockNumber(): Promise<
|
|
1401
|
+
public getProvenBlockNumber(): Promise<BlockNumber> {
|
|
1205
1402
|
return this.store.getProvenL2BlockNumber();
|
|
1206
1403
|
}
|
|
1207
1404
|
|
|
1208
1405
|
/** Forcefully updates the last proven block number. Use for testing. */
|
|
1209
|
-
public setProvenBlockNumber(blockNumber:
|
|
1406
|
+
public setProvenBlockNumber(blockNumber: BlockNumber): Promise<void> {
|
|
1210
1407
|
return this.store.setProvenL2BlockNumber(blockNumber);
|
|
1211
1408
|
}
|
|
1212
1409
|
|
|
@@ -1235,12 +1432,12 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
1235
1432
|
}
|
|
1236
1433
|
|
|
1237
1434
|
/**
|
|
1238
|
-
* Gets L1 to L2 message (to be) included in a given
|
|
1239
|
-
* @param
|
|
1435
|
+
* Gets L1 to L2 message (to be) included in a given checkpoint.
|
|
1436
|
+
* @param checkpointNumber - Checkpoint number to get messages for.
|
|
1240
1437
|
* @returns The L1 to L2 messages/leaves of the messages subtree (throws if not found).
|
|
1241
1438
|
*/
|
|
1242
|
-
getL1ToL2Messages(
|
|
1243
|
-
return this.store.getL1ToL2Messages(
|
|
1439
|
+
getL1ToL2Messages(checkpointNumber: CheckpointNumber): Promise<Fr[]> {
|
|
1440
|
+
return this.store.getL1ToL2Messages(checkpointNumber);
|
|
1244
1441
|
}
|
|
1245
1442
|
|
|
1246
1443
|
/**
|
|
@@ -1281,7 +1478,7 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
1281
1478
|
// TODO(#13569): Compute proper finalized block number based on L1 finalized block.
|
|
1282
1479
|
// We just force it 2 epochs worth of proven data for now.
|
|
1283
1480
|
// NOTE: update end-to-end/src/e2e_epochs/epochs_empty_blocks.test.ts as that uses finalized blocks in computations
|
|
1284
|
-
const finalizedBlockNumber = Math.max(provenBlockNumber - this.l1constants.epochDuration * 2, 0);
|
|
1481
|
+
const finalizedBlockNumber = BlockNumber(Math.max(provenBlockNumber - this.l1constants.epochDuration * 2, 0));
|
|
1285
1482
|
|
|
1286
1483
|
const [latestBlockHeader, provenBlockHeader, finalizedBlockHeader] = await Promise.all([
|
|
1287
1484
|
latestBlockNumber > 0 ? this.getBlockHeader(latestBlockNumber) : undefined,
|
|
@@ -1305,27 +1502,18 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
1305
1502
|
);
|
|
1306
1503
|
}
|
|
1307
1504
|
|
|
1308
|
-
const latestBlockHeaderHash = await latestBlockHeader?.hash();
|
|
1309
|
-
const provenBlockHeaderHash = await provenBlockHeader?.hash();
|
|
1310
|
-
const finalizedBlockHeaderHash = await finalizedBlockHeader?.hash();
|
|
1505
|
+
const latestBlockHeaderHash = (await latestBlockHeader?.hash()) ?? GENESIS_BLOCK_HEADER_HASH;
|
|
1506
|
+
const provenBlockHeaderHash = (await provenBlockHeader?.hash()) ?? GENESIS_BLOCK_HEADER_HASH;
|
|
1507
|
+
const finalizedBlockHeaderHash = (await finalizedBlockHeader?.hash()) ?? GENESIS_BLOCK_HEADER_HASH;
|
|
1311
1508
|
|
|
1312
1509
|
return {
|
|
1313
|
-
latest: {
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
} as L2BlockId,
|
|
1317
|
-
proven: {
|
|
1318
|
-
number: provenBlockNumber,
|
|
1319
|
-
hash: provenBlockHeaderHash?.toString(),
|
|
1320
|
-
} as L2BlockId,
|
|
1321
|
-
finalized: {
|
|
1322
|
-
number: finalizedBlockNumber,
|
|
1323
|
-
hash: finalizedBlockHeaderHash?.toString(),
|
|
1324
|
-
} as L2BlockId,
|
|
1510
|
+
latest: { number: latestBlockNumber, hash: latestBlockHeaderHash.toString() },
|
|
1511
|
+
proven: { number: provenBlockNumber, hash: provenBlockHeaderHash.toString() },
|
|
1512
|
+
finalized: { number: finalizedBlockNumber, hash: finalizedBlockHeaderHash.toString() },
|
|
1325
1513
|
};
|
|
1326
1514
|
}
|
|
1327
1515
|
|
|
1328
|
-
public async rollbackTo(targetL2BlockNumber:
|
|
1516
|
+
public async rollbackTo(targetL2BlockNumber: BlockNumber): Promise<void> {
|
|
1329
1517
|
const currentBlocks = await this.getL2Tips();
|
|
1330
1518
|
const currentL2Block = currentBlocks.latest.number;
|
|
1331
1519
|
const currentProvenBlock = currentBlocks.proven.number;
|
|
@@ -1340,17 +1528,18 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
|
|
|
1340
1528
|
throw new Error(`Target L2 block ${targetL2BlockNumber} not found`);
|
|
1341
1529
|
}
|
|
1342
1530
|
const targetL1BlockNumber = targetL2Block.l1.blockNumber;
|
|
1531
|
+
const targetCheckpointNumber = CheckpointNumber.fromBlockNumber(targetL2BlockNumber);
|
|
1343
1532
|
const targetL1BlockHash = await this.getL1BlockHash(targetL1BlockNumber);
|
|
1344
1533
|
this.log.info(`Unwinding ${blocksToUnwind} blocks from L2 block ${currentL2Block}`);
|
|
1345
|
-
await this.store.unwindBlocks(currentL2Block, blocksToUnwind);
|
|
1346
|
-
this.log.info(`Unwinding L1 to L2 messages to ${
|
|
1347
|
-
await this.store.
|
|
1534
|
+
await this.store.unwindBlocks(BlockNumber(currentL2Block), blocksToUnwind);
|
|
1535
|
+
this.log.info(`Unwinding L1 to L2 messages to checkpoint ${targetCheckpointNumber}`);
|
|
1536
|
+
await this.store.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
|
|
1348
1537
|
this.log.info(`Setting L1 syncpoints to ${targetL1BlockNumber}`);
|
|
1349
1538
|
await this.store.setBlockSynchedL1BlockNumber(targetL1BlockNumber);
|
|
1350
1539
|
await this.store.setMessageSynchedL1Block({ l1BlockNumber: targetL1BlockNumber, l1BlockHash: targetL1BlockHash });
|
|
1351
1540
|
if (targetL2BlockNumber < currentProvenBlock) {
|
|
1352
1541
|
this.log.info(`Clearing proven L2 block number`);
|
|
1353
|
-
await this.store.setProvenL2BlockNumber(
|
|
1542
|
+
await this.store.setProvenL2BlockNumber(BlockNumber.ZERO);
|
|
1354
1543
|
}
|
|
1355
1544
|
// TODO(palla/reorg): Set the finalized block when we add support for it.
|
|
1356
1545
|
// if (targetL2BlockNumber < currentFinalizedBlock) {
|
|
@@ -1398,7 +1587,7 @@ export class ArchiverStoreHelper
|
|
|
1398
1587
|
* Extracts and stores contract classes out of ContractClassPublished events emitted by the class registry contract.
|
|
1399
1588
|
* @param allLogs - All logs emitted in a bunch of blocks.
|
|
1400
1589
|
*/
|
|
1401
|
-
async #updatePublishedContractClasses(allLogs: ContractClassLog[], blockNum:
|
|
1590
|
+
async #updatePublishedContractClasses(allLogs: ContractClassLog[], blockNum: BlockNumber, operation: Operation) {
|
|
1402
1591
|
const contractClassPublishedEvents = allLogs
|
|
1403
1592
|
.filter(log => ContractClassPublishedEvent.isContractClassPublishedEvent(log))
|
|
1404
1593
|
.map(log => ContractClassPublishedEvent.fromLog(log));
|
|
@@ -1423,7 +1612,7 @@ export class ArchiverStoreHelper
|
|
|
1423
1612
|
* Extracts and stores contract instances out of ContractInstancePublished events emitted by the canonical deployer contract.
|
|
1424
1613
|
* @param allLogs - All logs emitted in a bunch of blocks.
|
|
1425
1614
|
*/
|
|
1426
|
-
async #updateDeployedContractInstances(allLogs: PrivateLog[], blockNum:
|
|
1615
|
+
async #updateDeployedContractInstances(allLogs: PrivateLog[], blockNum: BlockNumber, operation: Operation) {
|
|
1427
1616
|
const contractInstances = allLogs
|
|
1428
1617
|
.filter(log => ContractInstancePublishedEvent.isContractInstancePublishedEvent(log))
|
|
1429
1618
|
.map(log => ContractInstancePublishedEvent.fromLog(log))
|
|
@@ -1476,7 +1665,7 @@ export class ArchiverStoreHelper
|
|
|
1476
1665
|
* @param _blockNum - The block number
|
|
1477
1666
|
* @returns
|
|
1478
1667
|
*/
|
|
1479
|
-
async #storeBroadcastedIndividualFunctions(allLogs: ContractClassLog[], _blockNum:
|
|
1668
|
+
async #storeBroadcastedIndividualFunctions(allLogs: ContractClassLog[], _blockNum: BlockNumber) {
|
|
1480
1669
|
// Filter out private and utility function broadcast events
|
|
1481
1670
|
const privateFnEvents = allLogs
|
|
1482
1671
|
.filter(log => PrivateFunctionBroadcastedEvent.isPrivateFunctionBroadcastedEvent(log))
|
|
@@ -1566,7 +1755,7 @@ export class ArchiverStoreHelper
|
|
|
1566
1755
|
});
|
|
1567
1756
|
}
|
|
1568
1757
|
|
|
1569
|
-
public async unwindBlocks(from:
|
|
1758
|
+
public async unwindBlocks(from: BlockNumber, blocksToUnwind: number): Promise<boolean> {
|
|
1570
1759
|
const last = await this.getSynchedL2BlockNumber();
|
|
1571
1760
|
if (from != last) {
|
|
1572
1761
|
throw new Error(`Cannot unwind blocks from block ${from} when the last block is ${last}`);
|
|
@@ -1576,7 +1765,7 @@ export class ArchiverStoreHelper
|
|
|
1576
1765
|
}
|
|
1577
1766
|
|
|
1578
1767
|
// from - blocksToUnwind = the new head, so + 1 for what we need to remove
|
|
1579
|
-
const blocks = await this.getPublishedBlocks(from - blocksToUnwind + 1, blocksToUnwind);
|
|
1768
|
+
const blocks = await this.getPublishedBlocks(BlockNumber(from - blocksToUnwind + 1), blocksToUnwind);
|
|
1580
1769
|
|
|
1581
1770
|
const opResults = await Promise.all([
|
|
1582
1771
|
// Prune rolls back to the last proven block, which is by definition valid
|
|
@@ -1608,10 +1797,10 @@ export class ArchiverStoreHelper
|
|
|
1608
1797
|
return opResults.every(Boolean);
|
|
1609
1798
|
}
|
|
1610
1799
|
|
|
1611
|
-
getPublishedBlocks(from:
|
|
1800
|
+
getPublishedBlocks(from: BlockNumber, limit: number): Promise<PublishedL2Block[]> {
|
|
1612
1801
|
return this.store.getPublishedBlocks(from, limit);
|
|
1613
1802
|
}
|
|
1614
|
-
getPublishedBlock(number:
|
|
1803
|
+
getPublishedBlock(number: BlockNumber): Promise<PublishedL2Block | undefined> {
|
|
1615
1804
|
return this.store.getPublishedBlock(number);
|
|
1616
1805
|
}
|
|
1617
1806
|
getPublishedBlockByHash(blockHash: Fr): Promise<PublishedL2Block | undefined> {
|
|
@@ -1620,7 +1809,7 @@ export class ArchiverStoreHelper
|
|
|
1620
1809
|
getPublishedBlockByArchive(archive: Fr): Promise<PublishedL2Block | undefined> {
|
|
1621
1810
|
return this.store.getPublishedBlockByArchive(archive);
|
|
1622
1811
|
}
|
|
1623
|
-
getBlockHeaders(from:
|
|
1812
|
+
getBlockHeaders(from: BlockNumber, limit: number): Promise<BlockHeader[]> {
|
|
1624
1813
|
return this.store.getBlockHeaders(from, limit);
|
|
1625
1814
|
}
|
|
1626
1815
|
getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined> {
|
|
@@ -1638,15 +1827,12 @@ export class ArchiverStoreHelper
|
|
|
1638
1827
|
addL1ToL2Messages(messages: InboxMessage[]): Promise<void> {
|
|
1639
1828
|
return this.store.addL1ToL2Messages(messages);
|
|
1640
1829
|
}
|
|
1641
|
-
getL1ToL2Messages(
|
|
1642
|
-
return this.store.getL1ToL2Messages(
|
|
1830
|
+
getL1ToL2Messages(checkpointNumber: CheckpointNumber): Promise<Fr[]> {
|
|
1831
|
+
return this.store.getL1ToL2Messages(checkpointNumber);
|
|
1643
1832
|
}
|
|
1644
1833
|
getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined> {
|
|
1645
1834
|
return this.store.getL1ToL2MessageIndex(l1ToL2Message);
|
|
1646
1835
|
}
|
|
1647
|
-
getPrivateLogs(from: number, limit: number): Promise<PrivateLog[]> {
|
|
1648
|
-
return this.store.getPrivateLogs(from, limit);
|
|
1649
|
-
}
|
|
1650
1836
|
getLogsByTags(tags: Fr[], logsPerTag?: number): Promise<TxScopedL2Log[][]> {
|
|
1651
1837
|
return this.store.getLogsByTags(tags, logsPerTag);
|
|
1652
1838
|
}
|
|
@@ -1656,13 +1842,13 @@ export class ArchiverStoreHelper
|
|
|
1656
1842
|
getContractClassLogs(filter: LogFilter): Promise<GetContractClassLogsResponse> {
|
|
1657
1843
|
return this.store.getContractClassLogs(filter);
|
|
1658
1844
|
}
|
|
1659
|
-
getSynchedL2BlockNumber(): Promise<
|
|
1845
|
+
getSynchedL2BlockNumber(): Promise<BlockNumber> {
|
|
1660
1846
|
return this.store.getSynchedL2BlockNumber();
|
|
1661
1847
|
}
|
|
1662
|
-
getProvenL2BlockNumber(): Promise<
|
|
1848
|
+
getProvenL2BlockNumber(): Promise<BlockNumber> {
|
|
1663
1849
|
return this.store.getProvenL2BlockNumber();
|
|
1664
1850
|
}
|
|
1665
|
-
setProvenL2BlockNumber(l2BlockNumber:
|
|
1851
|
+
setProvenL2BlockNumber(l2BlockNumber: BlockNumber): Promise<void> {
|
|
1666
1852
|
return this.store.setProvenL2BlockNumber(l2BlockNumber);
|
|
1667
1853
|
}
|
|
1668
1854
|
setBlockSynchedL1BlockNumber(l1BlockNumber: bigint): Promise<void> {
|
|
@@ -1698,8 +1884,8 @@ export class ArchiverStoreHelper
|
|
|
1698
1884
|
estimateSize(): Promise<{ mappingSize: number; physicalFileSize: number; actualSize: number; numItems: number }> {
|
|
1699
1885
|
return this.store.estimateSize();
|
|
1700
1886
|
}
|
|
1701
|
-
|
|
1702
|
-
return this.store.
|
|
1887
|
+
rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber: CheckpointNumber): Promise<void> {
|
|
1888
|
+
return this.store.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
|
|
1703
1889
|
}
|
|
1704
1890
|
iterateL1ToL2Messages(range: CustomRange<bigint> = {}): AsyncIterableIterator<InboxMessage> {
|
|
1705
1891
|
return this.store.iterateL1ToL2Messages(range);
|