@aztec/archiver 0.0.1-commit.d431d1c → 0.0.1-commit.e3c1de76
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 +9 -0
- package/dest/archiver.d.ts +6 -5
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +34 -22
- package/dest/errors.d.ts +6 -1
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +8 -0
- package/dest/factory.d.ts +5 -2
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +7 -6
- package/dest/l1/bin/retrieve-calldata.js +2 -2
- package/dest/l1/data_retrieval.d.ts +1 -1
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +2 -2
- package/dest/l1/validate_trace.d.ts +6 -3
- package/dest/l1/validate_trace.d.ts.map +1 -1
- package/dest/l1/validate_trace.js +13 -9
- package/dest/modules/data_source_base.d.ts +17 -18
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +21 -52
- package/dest/modules/data_store_updater.d.ts +23 -19
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +47 -49
- package/dest/modules/instrumentation.d.ts +3 -3
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +17 -10
- package/dest/modules/l1_synchronizer.d.ts +1 -1
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +9 -10
- package/dest/store/block_store.d.ts +35 -21
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +81 -40
- package/dest/store/contract_class_store.d.ts +1 -1
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +11 -7
- package/dest/store/kv_archiver_store.d.ts +28 -24
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +20 -17
- package/dest/store/log_store.d.ts +4 -4
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +2 -2
- package/dest/test/fake_l1_state.d.ts +4 -4
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/index.js +3 -1
- package/dest/test/mock_archiver.js +1 -1
- package/dest/test/mock_l2_block_source.d.ts +20 -20
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +40 -41
- 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 +11 -9
- 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 +14 -13
- package/src/archiver.ts +46 -28
- package/src/errors.ts +12 -0
- package/src/factory.ts +7 -5
- package/src/l1/bin/retrieve-calldata.ts +7 -2
- package/src/l1/data_retrieval.ts +3 -3
- package/src/l1/validate_trace.ts +24 -6
- package/src/modules/data_source_base.ts +26 -77
- package/src/modules/data_store_updater.ts +59 -55
- package/src/modules/instrumentation.ts +17 -12
- package/src/modules/l1_synchronizer.ts +11 -12
- package/src/store/block_store.ts +107 -60
- package/src/store/contract_class_store.ts +11 -7
- package/src/store/kv_archiver_store.ts +36 -28
- package/src/store/log_store.ts +12 -12
- package/src/test/fake_l1_state.ts +2 -2
- package/src/test/index.ts +3 -0
- package/src/test/mock_archiver.ts +1 -1
- package/src/test/mock_l2_block_source.ts +54 -64
- package/src/test/mock_structs.ts +26 -10
- package/src/test/noop_l1_archiver.ts +109 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BlockNumber,
|
|
1
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import {
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
ContractInstancePublishedEvent,
|
|
11
11
|
ContractInstanceUpdatedEvent,
|
|
12
12
|
} from '@aztec/protocol-contracts/instance-registry';
|
|
13
|
-
import type {
|
|
13
|
+
import type { L2Block, ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
14
14
|
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
15
15
|
import {
|
|
16
16
|
type ExecutablePrivateFunctionWithMembershipProof,
|
|
@@ -35,7 +35,7 @@ enum Operation {
|
|
|
35
35
|
/** Result of adding checkpoints with information about any pruned blocks. */
|
|
36
36
|
type ReconcileCheckpointsResult = {
|
|
37
37
|
/** Blocks that were pruned due to conflict with L1 checkpoints. */
|
|
38
|
-
prunedBlocks:
|
|
38
|
+
prunedBlocks: L2Block[] | undefined;
|
|
39
39
|
/** Last block number that was already inserted locally, or undefined if none. */
|
|
40
40
|
lastAlreadyInsertedBlockNumber: BlockNumber | undefined;
|
|
41
41
|
};
|
|
@@ -47,17 +47,21 @@ export class ArchiverDataStoreUpdater {
|
|
|
47
47
|
constructor(private store: KVArchiverDataStore) {}
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
* Adds blocks to the store with contract class/instance extraction from logs.
|
|
50
|
+
* Adds proposed blocks to the store with contract class/instance extraction from logs.
|
|
51
|
+
* These are uncheckpointed blocks that have been proposed by the sequencer but not yet included in a checkpoint on L1.
|
|
51
52
|
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
|
|
52
53
|
* and individually broadcasted functions from the block logs.
|
|
53
54
|
*
|
|
54
|
-
* @param blocks - The L2 blocks to add.
|
|
55
|
+
* @param blocks - The proposed L2 blocks to add.
|
|
55
56
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
56
57
|
* @returns True if the operation is successful.
|
|
57
58
|
*/
|
|
58
|
-
public
|
|
59
|
+
public addProposedBlocks(
|
|
60
|
+
blocks: L2Block[],
|
|
61
|
+
pendingChainValidationStatus?: ValidateCheckpointResult,
|
|
62
|
+
): Promise<boolean> {
|
|
59
63
|
return this.store.transactionAsync(async () => {
|
|
60
|
-
await this.store.
|
|
64
|
+
await this.store.addProposedBlocks(blocks);
|
|
61
65
|
|
|
62
66
|
const opResults = await Promise.all([
|
|
63
67
|
// Update the pending chain validation status if provided
|
|
@@ -65,7 +69,7 @@ export class ArchiverDataStoreUpdater {
|
|
|
65
69
|
// Add any logs emitted during the retrieved blocks
|
|
66
70
|
this.store.addLogs(blocks),
|
|
67
71
|
// Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
|
|
68
|
-
...blocks.map(block => this.
|
|
72
|
+
...blocks.map(block => this.addContractDataToDb(block)),
|
|
69
73
|
]);
|
|
70
74
|
|
|
71
75
|
return opResults.every(Boolean);
|
|
@@ -74,7 +78,7 @@ export class ArchiverDataStoreUpdater {
|
|
|
74
78
|
|
|
75
79
|
/**
|
|
76
80
|
* Reconciles local blocks with incoming checkpoints from L1.
|
|
77
|
-
* Adds checkpoints to the store with contract class/instance extraction from logs.
|
|
81
|
+
* Adds new checkpoints to the store with contract class/instance extraction from logs.
|
|
78
82
|
* Prunes any local blocks that conflict with checkpoint data (by comparing archive roots).
|
|
79
83
|
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
|
|
80
84
|
* and individually broadcasted functions from the checkpoint block logs.
|
|
@@ -83,7 +87,7 @@ export class ArchiverDataStoreUpdater {
|
|
|
83
87
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
84
88
|
* @returns Result with information about any pruned blocks.
|
|
85
89
|
*/
|
|
86
|
-
public
|
|
90
|
+
public addCheckpoints(
|
|
87
91
|
checkpoints: PublishedCheckpoint[],
|
|
88
92
|
pendingChainValidationStatus?: ValidateCheckpointResult,
|
|
89
93
|
): Promise<ReconcileCheckpointsResult> {
|
|
@@ -93,7 +97,7 @@ export class ArchiverDataStoreUpdater {
|
|
|
93
97
|
|
|
94
98
|
await this.store.addCheckpoints(checkpoints);
|
|
95
99
|
|
|
96
|
-
// Filter out blocks that were already inserted via
|
|
100
|
+
// Filter out blocks that were already inserted via addProposedBlocks() to avoid duplicating logs/contract data
|
|
97
101
|
const newBlocks = checkpoints
|
|
98
102
|
.flatMap((ch: PublishedCheckpoint) => ch.checkpoint.blocks)
|
|
99
103
|
.filter(b => lastAlreadyInsertedBlockNumber === undefined || b.number > lastAlreadyInsertedBlockNumber);
|
|
@@ -104,7 +108,7 @@ export class ArchiverDataStoreUpdater {
|
|
|
104
108
|
// Add any logs emitted during the retrieved blocks
|
|
105
109
|
this.store.addLogs(newBlocks),
|
|
106
110
|
// Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
|
|
107
|
-
...newBlocks.map(block => this.
|
|
111
|
+
...newBlocks.map(block => this.addContractDataToDb(block)),
|
|
108
112
|
]);
|
|
109
113
|
|
|
110
114
|
return { prunedBlocks, lastAlreadyInsertedBlockNumber };
|
|
@@ -185,80 +189,80 @@ export class ArchiverDataStoreUpdater {
|
|
|
185
189
|
}
|
|
186
190
|
|
|
187
191
|
/**
|
|
188
|
-
* Removes all blocks strictly after the specified block number and cleans up associated contract data.
|
|
192
|
+
* Removes all uncheckpointed blocks strictly after the specified block number and cleans up associated contract data.
|
|
189
193
|
* This handles removal of provisionally added blocks along with their contract classes/instances.
|
|
194
|
+
* Verifies that each block being removed is not part of a stored checkpoint.
|
|
190
195
|
*
|
|
191
196
|
* @param blockNumber - Remove all blocks with number greater than this.
|
|
192
197
|
* @returns The removed blocks.
|
|
198
|
+
* @throws Error if any block to be removed is checkpointed.
|
|
193
199
|
*/
|
|
194
|
-
public
|
|
200
|
+
public removeUncheckpointedBlocksAfter(blockNumber: BlockNumber): Promise<L2Block[]> {
|
|
195
201
|
return this.store.transactionAsync(async () => {
|
|
196
|
-
//
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
]);
|
|
202
|
+
// Verify we're only removing uncheckpointed blocks
|
|
203
|
+
const lastCheckpointedBlockNumber = await this.store.getCheckpointedL2BlockNumber();
|
|
204
|
+
if (blockNumber < lastCheckpointedBlockNumber) {
|
|
205
|
+
throw new Error(
|
|
206
|
+
`Cannot remove blocks after ${blockNumber} because checkpointed blocks exist up to ${lastCheckpointedBlockNumber}`,
|
|
207
|
+
);
|
|
208
|
+
}
|
|
204
209
|
|
|
205
|
-
return
|
|
210
|
+
return await this.removeBlocksAfter(blockNumber);
|
|
206
211
|
});
|
|
207
212
|
}
|
|
208
213
|
|
|
209
214
|
/**
|
|
210
|
-
*
|
|
215
|
+
* Removes all blocks strictly after the given block number along with any logs and contract data.
|
|
216
|
+
* Does not remove their checkpoints.
|
|
217
|
+
*/
|
|
218
|
+
private async removeBlocksAfter(blockNumber: BlockNumber): Promise<L2Block[]> {
|
|
219
|
+
// First get the blocks to be removed so we can clean up contract data
|
|
220
|
+
const removedBlocks = await this.store.removeBlocksAfter(blockNumber);
|
|
221
|
+
|
|
222
|
+
// Clean up contract data and logs for the removed blocks
|
|
223
|
+
await Promise.all([
|
|
224
|
+
this.store.deleteLogs(removedBlocks),
|
|
225
|
+
...removedBlocks.map(block => this.removeContractDataFromDb(block)),
|
|
226
|
+
]);
|
|
227
|
+
|
|
228
|
+
return removedBlocks;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Removes all checkpoints after the given checkpoint number.
|
|
211
233
|
* Deletes ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated data
|
|
212
|
-
* that was stored for the
|
|
234
|
+
* that was stored for the removed checkpoints. Also removes ALL blocks (both checkpointed
|
|
235
|
+
* and uncheckpointed) after the last block of the given checkpoint.
|
|
213
236
|
*
|
|
214
|
-
* @param
|
|
215
|
-
* @param checkpointsToUnwind - The number of checkpoints to unwind.
|
|
237
|
+
* @param checkpointNumber - Remove all checkpoints strictly after this one.
|
|
216
238
|
* @returns True if the operation is successful.
|
|
217
239
|
*/
|
|
218
|
-
public async
|
|
219
|
-
|
|
220
|
-
throw new Error(`Cannot unwind ${checkpointsToUnwind} blocks`);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const last = await this.store.getSynchedCheckpointNumber();
|
|
224
|
-
if (from != last) {
|
|
225
|
-
throw new Error(`Cannot unwind checkpoints from checkpoint ${from} when the last checkpoint is ${last}`);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const blocks = [];
|
|
229
|
-
const lastCheckpointNumber = from + checkpointsToUnwind - 1;
|
|
230
|
-
for (let checkpointNumber = from; checkpointNumber <= lastCheckpointNumber; checkpointNumber++) {
|
|
231
|
-
const blocksForCheckpoint = await this.store.getBlocksForCheckpoint(checkpointNumber);
|
|
232
|
-
if (!blocksForCheckpoint) {
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
|
-
blocks.push(...blocksForCheckpoint);
|
|
236
|
-
}
|
|
240
|
+
public async removeCheckpointsAfter(checkpointNumber: CheckpointNumber): Promise<boolean> {
|
|
241
|
+
const { blocksRemoved = [] } = await this.store.removeCheckpointsAfter(checkpointNumber);
|
|
237
242
|
|
|
238
243
|
const opResults = await Promise.all([
|
|
239
244
|
// Prune rolls back to the last proven block, which is by definition valid
|
|
240
245
|
this.store.setPendingChainValidationStatus({ valid: true }),
|
|
241
|
-
// Remove contract data for all blocks being
|
|
242
|
-
...
|
|
243
|
-
this.store.deleteLogs(
|
|
244
|
-
this.store.unwindCheckpoints(from, checkpointsToUnwind),
|
|
246
|
+
// Remove contract data for all blocks being removed
|
|
247
|
+
...blocksRemoved.map(block => this.removeContractDataFromDb(block)),
|
|
248
|
+
this.store.deleteLogs(blocksRemoved),
|
|
245
249
|
]);
|
|
246
250
|
|
|
247
251
|
return opResults.every(Boolean);
|
|
248
252
|
}
|
|
249
253
|
|
|
250
254
|
/** Extracts and stores contract data from a single block. */
|
|
251
|
-
private
|
|
252
|
-
return this.
|
|
255
|
+
private addContractDataToDb(block: L2Block): Promise<boolean> {
|
|
256
|
+
return this.updateContractDataOnDb(block, Operation.Store);
|
|
253
257
|
}
|
|
254
258
|
|
|
255
259
|
/** Removes contract data associated with a block. */
|
|
256
|
-
private
|
|
257
|
-
return this.
|
|
260
|
+
private removeContractDataFromDb(block: L2Block): Promise<boolean> {
|
|
261
|
+
return this.updateContractDataOnDb(block, Operation.Delete);
|
|
258
262
|
}
|
|
259
263
|
|
|
260
264
|
/** Adds or remove contract data associated with a block. */
|
|
261
|
-
private async
|
|
265
|
+
private async updateContractDataOnDb(block: L2Block, operation: Operation): Promise<boolean> {
|
|
262
266
|
const contractClassLogs = block.body.txEffects.flatMap(txEffect => txEffect.contractClassLogs);
|
|
263
267
|
const privateLogs = block.body.txEffects.flatMap(txEffect => txEffect.privateLogs);
|
|
264
268
|
const publicLogs = block.body.txEffects.flatMap(txEffect => txEffect.publicLogs);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
-
import type {
|
|
2
|
+
import type { L2Block } from '@aztec/stdlib/block';
|
|
3
3
|
import {
|
|
4
4
|
Attributes,
|
|
5
5
|
type Gauge,
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
type TelemetryClient,
|
|
11
11
|
type Tracer,
|
|
12
12
|
type UpDownCounter,
|
|
13
|
+
createUpDownCounterWithDefault,
|
|
13
14
|
} from '@aztec/telemetry-client';
|
|
14
15
|
|
|
15
16
|
export class ArchiverInstrumentation {
|
|
@@ -48,15 +49,17 @@ export class ArchiverInstrumentation {
|
|
|
48
49
|
|
|
49
50
|
this.l1BlockHeight = meter.createGauge(Metrics.ARCHIVER_L1_BLOCK_HEIGHT);
|
|
50
51
|
|
|
51
|
-
this.txCount = meter
|
|
52
|
+
this.txCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_TOTAL_TXS);
|
|
52
53
|
|
|
53
|
-
this.proofsSubmittedCount = meter
|
|
54
|
+
this.proofsSubmittedCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_ROLLUP_PROOF_COUNT, {
|
|
55
|
+
[Attributes.PROOF_TIMED_OUT]: [true, false],
|
|
56
|
+
});
|
|
54
57
|
|
|
55
58
|
this.proofsSubmittedDelay = meter.createHistogram(Metrics.ARCHIVER_ROLLUP_PROOF_DELAY);
|
|
56
59
|
|
|
57
60
|
this.syncDurationPerBlock = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_BLOCK);
|
|
58
61
|
|
|
59
|
-
this.syncBlockCount = meter
|
|
62
|
+
this.syncBlockCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_BLOCK_COUNT);
|
|
60
63
|
|
|
61
64
|
this.manaPerBlock = meter.createHistogram(Metrics.ARCHIVER_MANA_PER_BLOCK);
|
|
62
65
|
|
|
@@ -64,13 +67,19 @@ export class ArchiverInstrumentation {
|
|
|
64
67
|
|
|
65
68
|
this.syncDurationPerMessage = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_MESSAGE);
|
|
66
69
|
|
|
67
|
-
this.syncMessageCount = meter
|
|
70
|
+
this.syncMessageCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_MESSAGE_COUNT);
|
|
68
71
|
|
|
69
72
|
this.pruneDuration = meter.createHistogram(Metrics.ARCHIVER_PRUNE_DURATION);
|
|
70
73
|
|
|
71
|
-
this.pruneCount = meter
|
|
74
|
+
this.pruneCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_PRUNE_COUNT);
|
|
72
75
|
|
|
73
|
-
this.blockProposalTxTargetCount =
|
|
76
|
+
this.blockProposalTxTargetCount = createUpDownCounterWithDefault(
|
|
77
|
+
meter,
|
|
78
|
+
Metrics.ARCHIVER_BLOCK_PROPOSAL_TX_TARGET_COUNT,
|
|
79
|
+
{
|
|
80
|
+
[Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: [true, false],
|
|
81
|
+
},
|
|
82
|
+
);
|
|
74
83
|
|
|
75
84
|
this.dbMetrics = new LmdbMetrics(
|
|
76
85
|
meter,
|
|
@@ -84,10 +93,6 @@ export class ArchiverInstrumentation {
|
|
|
84
93
|
public static async new(telemetry: TelemetryClient, lmdbStats?: LmdbStatsCallback) {
|
|
85
94
|
const instance = new ArchiverInstrumentation(telemetry, lmdbStats);
|
|
86
95
|
|
|
87
|
-
instance.syncBlockCount.add(0);
|
|
88
|
-
instance.syncMessageCount.add(0);
|
|
89
|
-
instance.pruneCount.add(0);
|
|
90
|
-
|
|
91
96
|
await instance.telemetry.flush();
|
|
92
97
|
|
|
93
98
|
return instance;
|
|
@@ -97,7 +102,7 @@ export class ArchiverInstrumentation {
|
|
|
97
102
|
return this.telemetry.isEnabled();
|
|
98
103
|
}
|
|
99
104
|
|
|
100
|
-
public processNewBlocks(syncTimePerBlock: number, blocks:
|
|
105
|
+
public processNewBlocks(syncTimePerBlock: number, blocks: L2Block[]) {
|
|
101
106
|
this.syncDurationPerBlock.record(Math.ceil(syncTimePerBlock));
|
|
102
107
|
this.blockHeight.record(Math.max(...blocks.map(b => b.number)));
|
|
103
108
|
this.syncBlockCount.add(blocks.length);
|
|
@@ -16,7 +16,7 @@ import { DateProvider, Timer, elapsed } from '@aztec/foundation/timer';
|
|
|
16
16
|
import { isDefined } from '@aztec/foundation/types';
|
|
17
17
|
import { type ArchiverEmitter, L2BlockSourceEvents, type ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
18
18
|
import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
19
|
-
import { type L1RollupConstants, getEpochAtSlot,
|
|
19
|
+
import { type L1RollupConstants, getEpochAtSlot, getSlotAtNextL1Block } from '@aztec/stdlib/epoch-helpers';
|
|
20
20
|
import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
21
21
|
import { type Traceable, type Tracer, execInSpan, trackSpan } from '@aztec/telemetry-client';
|
|
22
22
|
|
|
@@ -249,8 +249,7 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
249
249
|
const firstUncheckpointedBlockSlot = firstUncheckpointedBlockHeader?.getSlot();
|
|
250
250
|
|
|
251
251
|
// What's the slot at the next L1 block? All blocks for slots strictly before this one should've been checkpointed by now.
|
|
252
|
-
const
|
|
253
|
-
const slotAtNextL1Block = getSlotAtTimestamp(nextL1BlockTimestamp, this.l1Constants);
|
|
252
|
+
const slotAtNextL1Block = getSlotAtNextL1Block(currentL1Timestamp, this.l1Constants);
|
|
254
253
|
|
|
255
254
|
// Prune provisional blocks from slots that have ended without being checkpointed
|
|
256
255
|
if (firstUncheckpointedBlockSlot !== undefined && firstUncheckpointedBlockSlot < slotAtNextL1Block) {
|
|
@@ -258,7 +257,7 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
258
257
|
`Pruning blocks after block ${lastCheckpointedBlockNumber} due to slot ${firstUncheckpointedBlockSlot} not being checkpointed`,
|
|
259
258
|
{ firstUncheckpointedBlockHeader: firstUncheckpointedBlockHeader.toInspect(), slotAtNextL1Block },
|
|
260
259
|
);
|
|
261
|
-
const prunedBlocks = await this.updater.
|
|
260
|
+
const prunedBlocks = await this.updater.removeUncheckpointedBlocksAfter(lastCheckpointedBlockNumber);
|
|
262
261
|
|
|
263
262
|
if (prunedBlocks.length > 0) {
|
|
264
263
|
this.events.emit(L2BlockSourceEvents.L2PruneUncheckpointed, {
|
|
@@ -331,10 +330,10 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
331
330
|
this.log.debug(
|
|
332
331
|
`L2 prune from ${provenCheckpointNumber + 1} to ${localPendingCheckpointNumber} will occur on next checkpoint submission.`,
|
|
333
332
|
);
|
|
334
|
-
await this.updater.
|
|
333
|
+
await this.updater.removeCheckpointsAfter(provenCheckpointNumber);
|
|
335
334
|
this.log.warn(
|
|
336
|
-
`
|
|
337
|
-
`
|
|
335
|
+
`Removed ${count(checkpointsToUnwind, 'checkpoint')} after checkpoint ${provenCheckpointNumber} ` +
|
|
336
|
+
`due to predicted reorg at L1 block ${currentL1BlockNumber}. ` +
|
|
338
337
|
`Updated latest checkpoint is ${await this.store.getSynchedCheckpointNumber()}.`,
|
|
339
338
|
);
|
|
340
339
|
this.instrumentation.processPrune(timer.ms());
|
|
@@ -675,11 +674,11 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
675
674
|
tipAfterUnwind--;
|
|
676
675
|
}
|
|
677
676
|
|
|
678
|
-
const
|
|
679
|
-
await this.updater.
|
|
677
|
+
const checkpointsToRemove = localPendingCheckpointNumber - tipAfterUnwind;
|
|
678
|
+
await this.updater.removeCheckpointsAfter(CheckpointNumber(tipAfterUnwind));
|
|
680
679
|
|
|
681
680
|
this.log.warn(
|
|
682
|
-
`
|
|
681
|
+
`Removed ${count(checkpointsToRemove, 'checkpoint')} after checkpoint ${tipAfterUnwind} ` +
|
|
683
682
|
`due to mismatched checkpoint hashes at L1 block ${currentL1BlockNumber}. ` +
|
|
684
683
|
`Updated L2 latest checkpoint is ${await this.store.getSynchedCheckpointNumber()}.`,
|
|
685
684
|
);
|
|
@@ -806,8 +805,8 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
806
805
|
const updatedValidationResult =
|
|
807
806
|
rollupStatus.validationResult === initialValidationResult ? undefined : rollupStatus.validationResult;
|
|
808
807
|
const [processDuration, result] = await elapsed(() =>
|
|
809
|
-
execInSpan(this.tracer, 'Archiver.
|
|
810
|
-
this.updater.
|
|
808
|
+
execInSpan(this.tracer, 'Archiver.addCheckpoints', () =>
|
|
809
|
+
this.updater.addCheckpoints(validCheckpoints, updatedValidationResult),
|
|
811
810
|
),
|
|
812
811
|
);
|
|
813
812
|
this.instrumentation.processNewBlocks(
|