@aztec/archiver 0.0.1-commit.b468ad8 → 0.0.1-commit.b64cb54f6
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.d.ts +7 -4
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +62 -110
- package/dest/errors.d.ts +7 -9
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +9 -14
- package/dest/factory.d.ts +3 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +15 -13
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/l1/bin/retrieve-calldata.js +36 -33
- package/dest/l1/calldata_retriever.d.ts +73 -50
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +190 -259
- package/dest/l1/data_retrieval.d.ts +9 -9
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +21 -19
- package/dest/l1/spire_proposer.d.ts +5 -5
- package/dest/l1/spire_proposer.d.ts.map +1 -1
- package/dest/l1/spire_proposer.js +9 -17
- package/dest/modules/data_source_base.d.ts +10 -5
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +29 -73
- package/dest/modules/data_store_updater.d.ts +22 -7
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +69 -29
- package/dest/modules/instrumentation.d.ts +15 -2
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +19 -2
- package/dest/modules/l1_synchronizer.d.ts +5 -8
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +41 -10
- package/dest/store/block_store.d.ts +29 -26
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +130 -78
- package/dest/store/kv_archiver_store.d.ts +34 -11
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +39 -9
- package/dest/store/l2_tips_cache.d.ts +19 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +89 -0
- package/dest/store/log_store.d.ts +1 -1
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +55 -35
- package/dest/store/message_store.js +1 -1
- package/dest/test/fake_l1_state.d.ts +13 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +84 -20
- package/dest/test/mock_archiver.d.ts +1 -1
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +3 -2
- package/dest/test/mock_l2_block_source.d.ts +21 -5
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +132 -86
- package/dest/test/mock_structs.d.ts +4 -1
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +13 -1
- package/dest/test/noop_l1_archiver.d.ts +4 -1
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +5 -1
- package/package.json +13 -13
- package/src/archiver.ts +74 -130
- package/src/errors.ts +10 -24
- package/src/factory.ts +29 -14
- package/src/index.ts +1 -0
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +46 -39
- package/src/l1/calldata_retriever.ts +249 -379
- package/src/l1/data_retrieval.ts +23 -25
- package/src/l1/spire_proposer.ts +7 -15
- package/src/modules/data_source_base.ts +56 -95
- package/src/modules/data_store_updater.ts +71 -30
- package/src/modules/instrumentation.ts +29 -2
- package/src/modules/l1_synchronizer.ts +46 -14
- package/src/store/block_store.ts +157 -105
- package/src/store/kv_archiver_store.ts +62 -12
- package/src/store/l2_tips_cache.ts +89 -0
- package/src/store/log_store.ts +93 -31
- package/src/store/message_store.ts +1 -1
- package/src/test/fake_l1_state.ts +110 -21
- package/src/test/mock_archiver.ts +3 -2
- package/src/test/mock_l2_block_source.ts +173 -81
- package/src/test/mock_structs.ts +20 -6
- package/src/test/noop_l1_archiver.ts +7 -1
|
@@ -3,6 +3,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { ContractClassPublishedEvent, PrivateFunctionBroadcastedEvent, UtilityFunctionBroadcastedEvent } from '@aztec/protocol-contracts/class-registry';
|
|
5
5
|
import { ContractInstancePublishedEvent, ContractInstanceUpdatedEvent } from '@aztec/protocol-contracts/instance-registry';
|
|
6
|
+
import { validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
6
7
|
import { computePublicBytecodeCommitment, isValidPrivateFunctionMembershipProof, isValidUtilityFunctionMembershipProof } from '@aztec/stdlib/contract';
|
|
7
8
|
import groupBy from 'lodash.groupby';
|
|
8
9
|
/** Operation type for contract data updates. */ var Operation = /*#__PURE__*/ function(Operation) {
|
|
@@ -12,33 +13,41 @@ import groupBy from 'lodash.groupby';
|
|
|
12
13
|
}(Operation || {});
|
|
13
14
|
/** Archiver helper module to handle updates to the data store. */ export class ArchiverDataStoreUpdater {
|
|
14
15
|
store;
|
|
16
|
+
l2TipsCache;
|
|
17
|
+
opts;
|
|
15
18
|
log;
|
|
16
|
-
constructor(store){
|
|
19
|
+
constructor(store, l2TipsCache, opts = {}){
|
|
17
20
|
this.store = store;
|
|
21
|
+
this.l2TipsCache = l2TipsCache;
|
|
22
|
+
this.opts = opts;
|
|
18
23
|
this.log = createLogger('archiver:store_updater');
|
|
19
24
|
}
|
|
20
25
|
/**
|
|
21
|
-
* Adds proposed
|
|
22
|
-
*
|
|
26
|
+
* Adds a proposed block to the store with contract class/instance extraction from logs.
|
|
27
|
+
* This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
|
|
23
28
|
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
|
|
24
29
|
* and individually broadcasted functions from the block logs.
|
|
25
30
|
*
|
|
26
|
-
* @param
|
|
31
|
+
* @param block - The proposed L2 block to add.
|
|
27
32
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
28
33
|
* @returns True if the operation is successful.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
await this.store.
|
|
34
|
+
*/ async addProposedBlock(block, pendingChainValidationStatus) {
|
|
35
|
+
const result = await this.store.transactionAsync(async ()=>{
|
|
36
|
+
await this.store.addProposedBlock(block);
|
|
32
37
|
const opResults = await Promise.all([
|
|
33
38
|
// Update the pending chain validation status if provided
|
|
34
39
|
pendingChainValidationStatus && this.store.setPendingChainValidationStatus(pendingChainValidationStatus),
|
|
35
|
-
// Add any logs emitted during the retrieved
|
|
36
|
-
this.store.addLogs(
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
// Add any logs emitted during the retrieved block
|
|
41
|
+
this.store.addLogs([
|
|
42
|
+
block
|
|
43
|
+
]),
|
|
44
|
+
// Unroll all logs emitted during the retrieved block and extract any contract classes and instances from it
|
|
45
|
+
this.addContractDataToDb(block)
|
|
39
46
|
]);
|
|
47
|
+
await this.l2TipsCache?.refresh();
|
|
40
48
|
return opResults.every(Boolean);
|
|
41
49
|
});
|
|
50
|
+
return result;
|
|
42
51
|
}
|
|
43
52
|
/**
|
|
44
53
|
* Reconciles local blocks with incoming checkpoints from L1.
|
|
@@ -50,12 +59,17 @@ import groupBy from 'lodash.groupby';
|
|
|
50
59
|
* @param checkpoints - The published checkpoints to add.
|
|
51
60
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
52
61
|
* @returns Result with information about any pruned blocks.
|
|
53
|
-
*/ addCheckpoints(checkpoints, pendingChainValidationStatus) {
|
|
54
|
-
|
|
62
|
+
*/ async addCheckpoints(checkpoints, pendingChainValidationStatus) {
|
|
63
|
+
for (const checkpoint of checkpoints){
|
|
64
|
+
validateCheckpoint(checkpoint.checkpoint, {
|
|
65
|
+
rollupManaLimit: this.opts?.rollupManaLimit
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
const result = await this.store.transactionAsync(async ()=>{
|
|
55
69
|
// Before adding checkpoints, check for conflicts with local blocks if any
|
|
56
70
|
const { prunedBlocks, lastAlreadyInsertedBlockNumber } = await this.pruneMismatchingLocalBlocks(checkpoints);
|
|
57
71
|
await this.store.addCheckpoints(checkpoints);
|
|
58
|
-
// Filter out blocks that were already inserted via
|
|
72
|
+
// Filter out blocks that were already inserted via addProposedBlock() to avoid duplicating logs/contract data
|
|
59
73
|
const newBlocks = checkpoints.flatMap((ch)=>ch.checkpoint.blocks).filter((b)=>lastAlreadyInsertedBlockNumber === undefined || b.number > lastAlreadyInsertedBlockNumber);
|
|
60
74
|
await Promise.all([
|
|
61
75
|
// Update the pending chain validation status if provided
|
|
@@ -65,11 +79,13 @@ import groupBy from 'lodash.groupby';
|
|
|
65
79
|
// Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
|
|
66
80
|
...newBlocks.map((block)=>this.addContractDataToDb(block))
|
|
67
81
|
]);
|
|
82
|
+
await this.l2TipsCache?.refresh();
|
|
68
83
|
return {
|
|
69
84
|
prunedBlocks,
|
|
70
85
|
lastAlreadyInsertedBlockNumber
|
|
71
86
|
};
|
|
72
87
|
});
|
|
88
|
+
return result;
|
|
73
89
|
}
|
|
74
90
|
/**
|
|
75
91
|
* Checks for local proposed blocks that do not match the ones to be checkpointed and prunes them.
|
|
@@ -113,7 +129,7 @@ import groupBy from 'lodash.groupby';
|
|
|
113
129
|
this.log.verbose(`Block number ${blockNumber} already inserted and matches checkpoint`, blockInfos);
|
|
114
130
|
lastAlreadyInsertedBlockNumber = blockNumber;
|
|
115
131
|
} else {
|
|
116
|
-
this.log.
|
|
132
|
+
this.log.info(`Conflict detected at block ${blockNumber} between checkpointed and local block`, blockInfos);
|
|
117
133
|
const prunedBlocks = await this.removeBlocksAfter(BlockNumber(blockNumber - 1));
|
|
118
134
|
return {
|
|
119
135
|
prunedBlocks,
|
|
@@ -147,15 +163,18 @@ import groupBy from 'lodash.groupby';
|
|
|
147
163
|
* @param blockNumber - Remove all blocks with number greater than this.
|
|
148
164
|
* @returns The removed blocks.
|
|
149
165
|
* @throws Error if any block to be removed is checkpointed.
|
|
150
|
-
*/ removeUncheckpointedBlocksAfter(blockNumber) {
|
|
151
|
-
|
|
166
|
+
*/ async removeUncheckpointedBlocksAfter(blockNumber) {
|
|
167
|
+
const result = await this.store.transactionAsync(async ()=>{
|
|
152
168
|
// Verify we're only removing uncheckpointed blocks
|
|
153
169
|
const lastCheckpointedBlockNumber = await this.store.getCheckpointedL2BlockNumber();
|
|
154
170
|
if (blockNumber < lastCheckpointedBlockNumber) {
|
|
155
171
|
throw new Error(`Cannot remove blocks after ${blockNumber} because checkpointed blocks exist up to ${lastCheckpointedBlockNumber}`);
|
|
156
172
|
}
|
|
157
|
-
|
|
173
|
+
const result = await this.removeBlocksAfter(blockNumber);
|
|
174
|
+
await this.l2TipsCache?.refresh();
|
|
175
|
+
return result;
|
|
158
176
|
});
|
|
177
|
+
return result;
|
|
159
178
|
}
|
|
160
179
|
/**
|
|
161
180
|
* Removes all blocks strictly after the given block number along with any logs and contract data.
|
|
@@ -179,17 +198,38 @@ import groupBy from 'lodash.groupby';
|
|
|
179
198
|
* @param checkpointNumber - Remove all checkpoints strictly after this one.
|
|
180
199
|
* @returns True if the operation is successful.
|
|
181
200
|
*/ async removeCheckpointsAfter(checkpointNumber) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
201
|
+
return await this.store.transactionAsync(async ()=>{
|
|
202
|
+
const { blocksRemoved = [] } = await this.store.removeCheckpointsAfter(checkpointNumber);
|
|
203
|
+
const opResults = await Promise.all([
|
|
204
|
+
// Prune rolls back to the last proven block, which is by definition valid
|
|
205
|
+
this.store.setPendingChainValidationStatus({
|
|
206
|
+
valid: true
|
|
207
|
+
}),
|
|
208
|
+
// Remove contract data for all blocks being removed
|
|
209
|
+
...blocksRemoved.map((block)=>this.removeContractDataFromDb(block)),
|
|
210
|
+
this.store.deleteLogs(blocksRemoved)
|
|
211
|
+
]);
|
|
212
|
+
await this.l2TipsCache?.refresh();
|
|
213
|
+
return opResults.every(Boolean);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Updates the proven checkpoint number and refreshes the L2 tips cache.
|
|
218
|
+
* @param checkpointNumber - The checkpoint number to set as proven.
|
|
219
|
+
*/ async setProvenCheckpointNumber(checkpointNumber) {
|
|
220
|
+
await this.store.transactionAsync(async ()=>{
|
|
221
|
+
await this.store.setProvenCheckpointNumber(checkpointNumber);
|
|
222
|
+
await this.l2TipsCache?.refresh();
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Updates the finalized checkpoint number and refreshes the L2 tips cache.
|
|
227
|
+
* @param checkpointNumber - The checkpoint number to set as finalized.
|
|
228
|
+
*/ async setFinalizedCheckpointNumber(checkpointNumber) {
|
|
229
|
+
await this.store.transactionAsync(async ()=>{
|
|
230
|
+
await this.store.setFinalizedCheckpointNumber(checkpointNumber);
|
|
231
|
+
await this.l2TipsCache?.refresh();
|
|
232
|
+
});
|
|
193
233
|
}
|
|
194
234
|
/** Extracts and stores contract data from a single block. */ addContractDataToDb(block) {
|
|
195
235
|
return this.updateContractDataOnDb(block, 0);
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import type { L2Block } from '@aztec/stdlib/block';
|
|
3
|
+
import type { CheckpointData } from '@aztec/stdlib/checkpoint';
|
|
4
|
+
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
2
5
|
import { type LmdbStatsCallback, type TelemetryClient, type Tracer } from '@aztec/telemetry-client';
|
|
3
6
|
export declare class ArchiverInstrumentation {
|
|
4
7
|
private telemetry;
|
|
5
8
|
readonly tracer: Tracer;
|
|
6
9
|
private blockHeight;
|
|
10
|
+
private checkpointHeight;
|
|
7
11
|
private txCount;
|
|
8
12
|
private l1BlockHeight;
|
|
9
13
|
private proofsSubmittedDelay;
|
|
@@ -18,6 +22,7 @@ export declare class ArchiverInstrumentation {
|
|
|
18
22
|
private syncDurationPerMessage;
|
|
19
23
|
private syncMessageCount;
|
|
20
24
|
private blockProposalTxTargetCount;
|
|
25
|
+
private checkpointL1InclusionDelay;
|
|
21
26
|
private log;
|
|
22
27
|
private constructor();
|
|
23
28
|
static new(telemetry: TelemetryClient, lmdbStats?: LmdbStatsCallback): Promise<ArchiverInstrumentation>;
|
|
@@ -25,7 +30,7 @@ export declare class ArchiverInstrumentation {
|
|
|
25
30
|
processNewBlocks(syncTimePerBlock: number, blocks: L2Block[]): void;
|
|
26
31
|
processNewMessages(count: number, syncPerMessageMs: number): void;
|
|
27
32
|
processPrune(duration: number): void;
|
|
28
|
-
|
|
33
|
+
updateLastProvenCheckpoint(checkpoint: CheckpointData): void;
|
|
29
34
|
processProofsVerified(logs: {
|
|
30
35
|
proverId: string;
|
|
31
36
|
l2BlockNumber: bigint;
|
|
@@ -33,5 +38,13 @@ export declare class ArchiverInstrumentation {
|
|
|
33
38
|
}[]): void;
|
|
34
39
|
updateL1BlockHeight(blockNumber: bigint): void;
|
|
35
40
|
recordBlockProposalTxTarget(target: string, usedTrace: boolean): void;
|
|
41
|
+
/**
|
|
42
|
+
* Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
|
|
43
|
+
*/
|
|
44
|
+
processCheckpointL1Timing(data: {
|
|
45
|
+
slotNumber: SlotNumber;
|
|
46
|
+
l1Timestamp: bigint;
|
|
47
|
+
l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'>;
|
|
48
|
+
}): void;
|
|
36
49
|
}
|
|
37
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
50
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlI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BQU0sQ0FBQztRQUNwQixXQUFXLEVBQUUsSUFBSSxDQUFDLGlCQUFpQixFQUFFLGVBQWUsR0FBRyxjQUFjLENBQUMsQ0FBQztLQUN4RSxHQUFHLElBQUksQ0FJUDtDQUNGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../../src/modules/instrumentation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../../src/modules/instrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAElE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAErE,OAAO,EAKL,KAAK,iBAAiB,EAEtB,KAAK,eAAe,EACpB,KAAK,MAAM,EAGZ,MAAM,yBAAyB,CAAC;AAEjC,qBAAa,uBAAuB;IA6BhC,OAAO,CAAC,SAAS;IA5BnB,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,gBAAgB,CAAQ;IAChC,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,aAAa,CAAQ;IAC7B,OAAO,CAAC,oBAAoB,CAAY;IACxC,OAAO,CAAC,oBAAoB,CAAgB;IAC5C,OAAO,CAAC,SAAS,CAAc;IAE/B,OAAO,CAAC,aAAa,CAAY;IACjC,OAAO,CAAC,UAAU,CAAgB;IAElC,OAAO,CAAC,oBAAoB,CAAY;IACxC,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,YAAY,CAAY;IAChC,OAAO,CAAC,WAAW,CAAY;IAE/B,OAAO,CAAC,sBAAsB,CAAY;IAC1C,OAAO,CAAC,gBAAgB,CAAgB;IAExC,OAAO,CAAC,0BAA0B,CAAgB;IAElD,OAAO,CAAC,0BAA0B,CAAY;IAE9C,OAAO,CAAC,GAAG,CAA4C;IAEvD,OAAO,eAsDN;IAED,OAAoB,GAAG,CAAC,SAAS,EAAE,eAAe,EAAE,SAAS,CAAC,EAAE,iBAAiB,oCAMhF;IAEM,SAAS,IAAI,OAAO,CAE1B;IAEM,gBAAgB,CAAC,gBAAgB,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QAWlE;IAEM,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,QAMhE;IAEM,YAAY,CAAC,QAAQ,EAAE,MAAM,QAGnC;IAEM,0BAA0B,CAAC,UAAU,EAAE,cAAc,QAI3D;IAEM,qBAAqB,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,QAW9F;IAEM,mBAAmB,CAAC,WAAW,EAAE,MAAM,QAE7C;IAEM,2BAA2B,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,QAKpE;IAED;;OAEG;IACI,yBAAyB,CAAC,IAAI,EAAE;QACrC,UAAU,EAAE,UAAU,CAAC;QACvB,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,IAAI,CAAC,iBAAiB,EAAE,eAAe,GAAG,cAAc,CAAC,CAAC;KACxE,GAAG,IAAI,CAIP;CACF"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
2
3
|
import { Attributes, LmdbMetrics, Metrics, createUpDownCounterWithDefault } from '@aztec/telemetry-client';
|
|
3
4
|
export class ArchiverInstrumentation {
|
|
4
5
|
telemetry;
|
|
5
6
|
tracer;
|
|
6
7
|
blockHeight;
|
|
8
|
+
checkpointHeight;
|
|
7
9
|
txCount;
|
|
8
10
|
l1BlockHeight;
|
|
9
11
|
proofsSubmittedDelay;
|
|
@@ -18,6 +20,7 @@ export class ArchiverInstrumentation {
|
|
|
18
20
|
syncDurationPerMessage;
|
|
19
21
|
syncMessageCount;
|
|
20
22
|
blockProposalTxTargetCount;
|
|
23
|
+
checkpointL1InclusionDelay;
|
|
21
24
|
log;
|
|
22
25
|
constructor(telemetry, lmdbStats){
|
|
23
26
|
this.telemetry = telemetry;
|
|
@@ -25,6 +28,7 @@ export class ArchiverInstrumentation {
|
|
|
25
28
|
this.tracer = telemetry.getTracer('Archiver');
|
|
26
29
|
const meter = telemetry.getMeter('Archiver');
|
|
27
30
|
this.blockHeight = meter.createGauge(Metrics.ARCHIVER_BLOCK_HEIGHT);
|
|
31
|
+
this.checkpointHeight = meter.createGauge(Metrics.ARCHIVER_CHECKPOINT_HEIGHT);
|
|
28
32
|
this.l1BlockHeight = meter.createGauge(Metrics.ARCHIVER_L1_BLOCK_HEIGHT);
|
|
29
33
|
this.txCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_TOTAL_TXS);
|
|
30
34
|
this.proofsSubmittedCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_ROLLUP_PROOF_COUNT, {
|
|
@@ -48,6 +52,7 @@ export class ArchiverInstrumentation {
|
|
|
48
52
|
false
|
|
49
53
|
]
|
|
50
54
|
});
|
|
55
|
+
this.checkpointL1InclusionDelay = meter.createHistogram(Metrics.ARCHIVER_CHECKPOINT_L1_INCLUSION_DELAY);
|
|
51
56
|
this.dbMetrics = new LmdbMetrics(meter, {
|
|
52
57
|
[Attributes.DB_DATA_TYPE]: 'archiver'
|
|
53
58
|
}, lmdbStats);
|
|
@@ -63,6 +68,7 @@ export class ArchiverInstrumentation {
|
|
|
63
68
|
processNewBlocks(syncTimePerBlock, blocks) {
|
|
64
69
|
this.syncDurationPerBlock.record(Math.ceil(syncTimePerBlock));
|
|
65
70
|
this.blockHeight.record(Math.max(...blocks.map((b)=>b.number)));
|
|
71
|
+
this.checkpointHeight.record(Math.max(...blocks.map((b)=>b.checkpointNumber)));
|
|
66
72
|
this.syncBlockCount.add(blocks.length);
|
|
67
73
|
for (const block of blocks){
|
|
68
74
|
this.txCount.add(block.body.txEffects.length);
|
|
@@ -81,8 +87,12 @@ export class ArchiverInstrumentation {
|
|
|
81
87
|
this.pruneCount.add(1);
|
|
82
88
|
this.pruneDuration.record(Math.ceil(duration));
|
|
83
89
|
}
|
|
84
|
-
|
|
85
|
-
|
|
90
|
+
updateLastProvenCheckpoint(checkpoint) {
|
|
91
|
+
const lastBlockNumberInCheckpoint = checkpoint.startBlock + checkpoint.blockCount - 1;
|
|
92
|
+
this.blockHeight.record(lastBlockNumberInCheckpoint, {
|
|
93
|
+
[Attributes.STATUS]: 'proven'
|
|
94
|
+
});
|
|
95
|
+
this.checkpointHeight.record(checkpoint.checkpointNumber, {
|
|
86
96
|
[Attributes.STATUS]: 'proven'
|
|
87
97
|
});
|
|
88
98
|
}
|
|
@@ -107,4 +117,11 @@ export class ArchiverInstrumentation {
|
|
|
107
117
|
[Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: usedTrace
|
|
108
118
|
});
|
|
109
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
|
|
122
|
+
*/ processCheckpointL1Timing(data) {
|
|
123
|
+
const slotStartTs = getTimestampForSlot(data.slotNumber, data.l1Constants);
|
|
124
|
+
const inclusionDelaySeconds = Number(data.l1Timestamp - slotStartTs);
|
|
125
|
+
this.checkpointL1InclusionDelay.record(inclusionDelaySeconds);
|
|
126
|
+
}
|
|
110
127
|
}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import type { BlobClientInterface } from '@aztec/blob-client/client';
|
|
2
2
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
3
3
|
import { InboxContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
4
|
-
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
5
4
|
import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
|
|
6
5
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
7
6
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
8
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
9
7
|
import { type Logger } from '@aztec/foundation/log';
|
|
10
8
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
11
9
|
import { type ArchiverEmitter } from '@aztec/stdlib/block';
|
|
12
10
|
import { type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
13
11
|
import { type Traceable, type Tracer } from '@aztec/telemetry-client';
|
|
14
12
|
import type { KVArchiverDataStore } from '../store/kv_archiver_store.js';
|
|
13
|
+
import type { L2TipsCache } from '../store/l2_tips_cache.js';
|
|
15
14
|
import type { ArchiverInstrumentation } from './instrumentation.js';
|
|
16
15
|
/**
|
|
17
16
|
* Handles L1 synchronization for the archiver.
|
|
@@ -22,7 +21,6 @@ export declare class ArchiverL1Synchronizer implements Traceable {
|
|
|
22
21
|
private readonly debugClient;
|
|
23
22
|
private readonly rollup;
|
|
24
23
|
private readonly inbox;
|
|
25
|
-
private readonly l1Addresses;
|
|
26
24
|
private readonly store;
|
|
27
25
|
private config;
|
|
28
26
|
private readonly blobClient;
|
|
@@ -37,16 +35,14 @@ export declare class ArchiverL1Synchronizer implements Traceable {
|
|
|
37
35
|
private l1Timestamp;
|
|
38
36
|
private readonly updater;
|
|
39
37
|
readonly tracer: Tracer;
|
|
40
|
-
constructor(publicClient: ViemPublicClient, debugClient: ViemPublicDebugClient, rollup: RollupContract, inbox: InboxContract,
|
|
41
|
-
slashingProposerAddress: EthAddress;
|
|
42
|
-
}, store: KVArchiverDataStore, config: {
|
|
38
|
+
constructor(publicClient: ViemPublicClient, debugClient: ViemPublicDebugClient, rollup: RollupContract, inbox: InboxContract, store: KVArchiverDataStore, config: {
|
|
43
39
|
batchSize: number;
|
|
44
40
|
skipValidateCheckpointAttestations?: boolean;
|
|
45
41
|
maxAllowedEthClientDriftSeconds: number;
|
|
46
42
|
}, blobClient: BlobClientInterface, epochCache: EpochCache, dateProvider: DateProvider, instrumentation: ArchiverInstrumentation, l1Constants: L1RollupConstants & {
|
|
47
43
|
l1StartBlockHash: Buffer32;
|
|
48
44
|
genesisArchiveRoot: Fr;
|
|
49
|
-
}, events: ArchiverEmitter, tracer: Tracer, log?: Logger);
|
|
45
|
+
}, events: ArchiverEmitter, tracer: Tracer, l2TipsCache?: L2TipsCache, log?: Logger);
|
|
50
46
|
/** Sets new config */
|
|
51
47
|
setConfig(newConfig: {
|
|
52
48
|
batchSize: number;
|
|
@@ -60,6 +56,7 @@ export declare class ArchiverL1Synchronizer implements Traceable {
|
|
|
60
56
|
/** Checks that the ethereum node we are connected to has a latest timestamp no more than the allowed drift. Throw if not. */
|
|
61
57
|
testEthereumNodeSynced(): Promise<void>;
|
|
62
58
|
syncFromL1(initialSyncComplete: boolean): Promise<void>;
|
|
59
|
+
private updateFinalizedCheckpoint;
|
|
63
60
|
private pruneUncheckpointedBlocks;
|
|
64
61
|
private canPrune;
|
|
65
62
|
private handleEpochPrune;
|
|
@@ -72,4 +69,4 @@ export declare class ArchiverL1Synchronizer implements Traceable {
|
|
|
72
69
|
private checkForNewCheckpointsBeforeL1SyncPoint;
|
|
73
70
|
private getCheckpointHeader;
|
|
74
71
|
}
|
|
75
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
72
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibDFfc3luY2hyb25pemVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbW9kdWxlcy9sMV9zeW5jaHJvbml6ZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsbUJBQW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AAE,MAAM,CAAC;QAClB,kCAAkC,CAAC,EAAE,OAAO,CAAC;QAC7C,+BAA+B,EAAE,MAAM,CAAC;KACzC,QAEA;IAED,wDAAwD;IACjD,gBAAgB,IAAI,MAAM,GAAG,SAAS,CAE5C;IAED,qDAAqD;IAC9C,cAAc,IAAI,MAAM,GAAG,SAAS,CAE1C;IAED,6HAA6H;IAChH,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC,CAYnD;IAGY,UAAU,CAAC,mBAAmB,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAiHnE;YAGa,yBAAyB;YAqBzB,yBAAyB;YAuCzB,QAAQ;YAeR,gBAAgB;IA4D9B,OAAO,CAAC,SAAS;YAWH,oBAAoB;YAuFpB,qBAAqB;YAkBrB,sBAAsB;YAyCtB,cAAc;YASd,iBAAiB;YAkXjB,uCAAuC;YA8CvC,mBAAmB;CAOlC"}
|
|
@@ -396,7 +396,6 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
396
396
|
debugClient;
|
|
397
397
|
rollup;
|
|
398
398
|
inbox;
|
|
399
|
-
l1Addresses;
|
|
400
399
|
store;
|
|
401
400
|
config;
|
|
402
401
|
blobClient;
|
|
@@ -435,12 +434,11 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
435
434
|
l1Timestamp;
|
|
436
435
|
updater;
|
|
437
436
|
tracer;
|
|
438
|
-
constructor(publicClient, debugClient, rollup, inbox,
|
|
437
|
+
constructor(publicClient, debugClient, rollup, inbox, store, config, blobClient, epochCache, dateProvider, instrumentation, l1Constants, events, tracer, l2TipsCache, log = createLogger('archiver:l1-sync')){
|
|
439
438
|
this.publicClient = publicClient;
|
|
440
439
|
this.debugClient = debugClient;
|
|
441
440
|
this.rollup = rollup;
|
|
442
441
|
this.inbox = inbox;
|
|
443
|
-
this.l1Addresses = l1Addresses;
|
|
444
442
|
this.store = store;
|
|
445
443
|
this.config = config;
|
|
446
444
|
this.blobClient = blobClient;
|
|
@@ -451,7 +449,9 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
451
449
|
this.events = events;
|
|
452
450
|
this.log = log;
|
|
453
451
|
_initProto(this);
|
|
454
|
-
this.updater = new ArchiverDataStoreUpdater(this.store
|
|
452
|
+
this.updater = new ArchiverDataStoreUpdater(this.store, l2TipsCache, {
|
|
453
|
+
rollupManaLimit: l1Constants.rollupManaLimit
|
|
454
|
+
});
|
|
455
455
|
this.tracer = tracer;
|
|
456
456
|
}
|
|
457
457
|
/** Sets new config */ setConfig(newConfig) {
|
|
@@ -555,6 +555,8 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
555
555
|
}
|
|
556
556
|
this.instrumentation.updateL1BlockHeight(currentL1BlockNumber);
|
|
557
557
|
}
|
|
558
|
+
// Update the finalized L2 checkpoint based on L1 finality.
|
|
559
|
+
await this.updateFinalizedCheckpoint();
|
|
558
560
|
// After syncing has completed, update the current l1 block number and timestamp,
|
|
559
561
|
// otherwise we risk announcing to the world that we've synced to a given point,
|
|
560
562
|
// but the corresponding blocks have not been processed (see #12631).
|
|
@@ -568,6 +570,28 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
568
570
|
l1BlockNumberAtEnd
|
|
569
571
|
});
|
|
570
572
|
}
|
|
573
|
+
/** Query L1 for its finalized block and update the finalized checkpoint accordingly. */ async updateFinalizedCheckpoint() {
|
|
574
|
+
try {
|
|
575
|
+
const finalizedL1Block = await this.publicClient.getBlock({
|
|
576
|
+
blockTag: 'finalized',
|
|
577
|
+
includeTransactions: false
|
|
578
|
+
});
|
|
579
|
+
const finalizedL1BlockNumber = finalizedL1Block.number;
|
|
580
|
+
const finalizedCheckpointNumber = await this.rollup.getProvenCheckpointNumber({
|
|
581
|
+
blockNumber: finalizedL1BlockNumber
|
|
582
|
+
});
|
|
583
|
+
const localFinalizedCheckpointNumber = await this.store.getFinalizedCheckpointNumber();
|
|
584
|
+
if (localFinalizedCheckpointNumber !== finalizedCheckpointNumber) {
|
|
585
|
+
await this.updater.setFinalizedCheckpointNumber(finalizedCheckpointNumber);
|
|
586
|
+
this.log.info(`Updated finalized chain to checkpoint ${finalizedCheckpointNumber}`, {
|
|
587
|
+
finalizedCheckpointNumber,
|
|
588
|
+
finalizedL1BlockNumber
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
} catch (err) {
|
|
592
|
+
this.log.warn(`Failed to update finalized checkpoint: ${err}`);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
571
595
|
/** Prune all proposed local blocks that should have been checkpointed by now. */ async pruneUncheckpointedBlocks(currentL1Timestamp) {
|
|
572
596
|
const [lastCheckpointedBlockNumber, lastProposedBlockNumber] = await Promise.all([
|
|
573
597
|
this.store.getCheckpointedL2BlockNumber(),
|
|
@@ -837,7 +861,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
837
861
|
if (provenCheckpointNumber === 0) {
|
|
838
862
|
const localProvenCheckpointNumber = await this.store.getProvenCheckpointNumber();
|
|
839
863
|
if (localProvenCheckpointNumber !== provenCheckpointNumber) {
|
|
840
|
-
await this.
|
|
864
|
+
await this.updater.setProvenCheckpointNumber(provenCheckpointNumber);
|
|
841
865
|
this.log.info(`Rolled back proven chain to checkpoint ${provenCheckpointNumber}`, {
|
|
842
866
|
provenCheckpointNumber
|
|
843
867
|
});
|
|
@@ -854,20 +878,20 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
854
878
|
if (localCheckpointForDestinationProvenCheckpointNumber && provenArchive.equals(localCheckpointForDestinationProvenCheckpointNumber.archive.root)) {
|
|
855
879
|
const localProvenCheckpointNumber = await this.store.getProvenCheckpointNumber();
|
|
856
880
|
if (localProvenCheckpointNumber !== provenCheckpointNumber) {
|
|
857
|
-
await this.
|
|
881
|
+
await this.updater.setProvenCheckpointNumber(provenCheckpointNumber);
|
|
858
882
|
this.log.info(`Updated proven chain to checkpoint ${provenCheckpointNumber}`, {
|
|
859
883
|
provenCheckpointNumber
|
|
860
884
|
});
|
|
861
885
|
const provenSlotNumber = localCheckpointForDestinationProvenCheckpointNumber.header.slotNumber;
|
|
862
886
|
const provenEpochNumber = getEpochAtSlot(provenSlotNumber, this.l1Constants);
|
|
863
|
-
const lastBlockNumberInCheckpoint = localCheckpointForDestinationProvenCheckpointNumber.startBlock + localCheckpointForDestinationProvenCheckpointNumber.
|
|
887
|
+
const lastBlockNumberInCheckpoint = localCheckpointForDestinationProvenCheckpointNumber.startBlock + localCheckpointForDestinationProvenCheckpointNumber.blockCount - 1;
|
|
864
888
|
this.events.emit(L2BlockSourceEvents.L2BlockProven, {
|
|
865
889
|
type: L2BlockSourceEvents.L2BlockProven,
|
|
866
890
|
blockNumber: BlockNumber(lastBlockNumberInCheckpoint),
|
|
867
891
|
slotNumber: provenSlotNumber,
|
|
868
892
|
epochNumber: provenEpochNumber
|
|
869
893
|
});
|
|
870
|
-
this.instrumentation.
|
|
894
|
+
this.instrumentation.updateLastProvenCheckpoint(localCheckpointForDestinationProvenCheckpointNumber);
|
|
871
895
|
} else {
|
|
872
896
|
this.log.trace(`Proven checkpoint ${provenCheckpointNumber} already stored.`);
|
|
873
897
|
}
|
|
@@ -945,7 +969,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
945
969
|
[searchStartBlock, searchEndBlock] = this.nextRange(searchEndBlock, currentL1BlockNumber);
|
|
946
970
|
this.log.trace(`Retrieving checkpoints from L1 block ${searchStartBlock} to ${searchEndBlock}`);
|
|
947
971
|
// TODO(md): Retrieve from blob client then from consensus client, then from peers
|
|
948
|
-
const retrievedCheckpoints = await execInSpan(this.tracer, 'Archiver.retrieveCheckpointsFromRollup', ()=>retrieveCheckpointsFromRollup(this.rollup, this.publicClient, this.debugClient, this.blobClient, searchStartBlock, searchEndBlock, this.
|
|
972
|
+
const retrievedCheckpoints = await execInSpan(this.tracer, 'Archiver.retrieveCheckpointsFromRollup', ()=>retrieveCheckpointsFromRollup(this.rollup, this.publicClient, this.debugClient, this.blobClient, searchStartBlock, searchEndBlock, this.instrumentation, this.log, !initialSyncComplete));
|
|
949
973
|
if (retrievedCheckpoints.length === 0) {
|
|
950
974
|
// We are not calling `setBlockSynchedL1BlockNumber` because it may cause sync issues if based off infura.
|
|
951
975
|
// See further details in earlier comments.
|
|
@@ -1008,6 +1032,13 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1008
1032
|
blocks: published.checkpoint.blocks.map((b)=>b.getStats())
|
|
1009
1033
|
});
|
|
1010
1034
|
}
|
|
1035
|
+
for (const published of validCheckpoints){
|
|
1036
|
+
this.instrumentation.processCheckpointL1Timing({
|
|
1037
|
+
slotNumber: published.checkpoint.header.slotNumber,
|
|
1038
|
+
l1Timestamp: published.l1.timestamp,
|
|
1039
|
+
l1Constants: this.l1Constants
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1011
1042
|
try {
|
|
1012
1043
|
const updatedValidationResult = rollupStatus.validationResult === initialValidationResult ? undefined : rollupStatus.validationResult;
|
|
1013
1044
|
const [processDuration, result] = await elapsed(()=>execInSpan(this.tracer, 'Archiver.addCheckpoints', ()=>this.updater.addCheckpoints(validCheckpoints, updatedValidationResult)));
|
|
@@ -1016,7 +1047,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1016
1047
|
if (result.prunedBlocks && result.prunedBlocks.length > 0) {
|
|
1017
1048
|
const prunedCheckpointNumber = result.prunedBlocks[0].checkpointNumber;
|
|
1018
1049
|
const prunedSlotNumber = result.prunedBlocks[0].header.globalVariables.slotNumber;
|
|
1019
|
-
this.log.
|
|
1050
|
+
this.log.info(`Pruned ${result.prunedBlocks.length} mismatching blocks for checkpoint ${prunedCheckpointNumber}`, {
|
|
1020
1051
|
prunedBlocks: result.prunedBlocks.map((b)=>b.toBlockInfo()),
|
|
1021
1052
|
prunedSlotNumber,
|
|
1022
1053
|
prunedCheckpointNumber
|