@aztec/archiver 0.0.1-commit.3895657bc → 0.0.1-commit.3e3d0c9cd
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 +3 -5
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +40 -17
- package/dest/errors.d.ts +21 -9
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +27 -14
- package/dest/factory.d.ts +2 -3
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +12 -12
- package/dest/modules/data_source_base.d.ts +5 -5
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +5 -5
- package/dest/modules/data_store_updater.d.ts +10 -5
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +22 -11
- package/dest/modules/l1_synchronizer.d.ts +2 -2
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +26 -1
- package/dest/store/block_store.d.ts +12 -13
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +61 -61
- package/dest/store/kv_archiver_store.d.ts +23 -10
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +30 -13
- package/dest/store/log_store.d.ts +6 -3
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +64 -7
- package/dest/store/message_store.d.ts +5 -1
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +13 -0
- package/dest/test/fake_l1_state.d.ts +8 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +39 -5
- package/dest/test/mock_l2_block_source.d.ts +3 -3
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +4 -4
- 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 +39 -18
- package/src/errors.ts +40 -24
- package/src/factory.ts +7 -7
- package/src/modules/data_source_base.ts +11 -6
- package/src/modules/data_store_updater.ts +23 -12
- package/src/modules/l1_synchronizer.ts +26 -2
- package/src/store/block_store.ts +72 -69
- package/src/store/kv_archiver_store.ts +38 -12
- package/src/store/log_store.ts +84 -16
- package/src/store/message_store.ts +19 -0
- package/src/test/fake_l1_state.ts +50 -9
- package/src/test/mock_l2_block_source.ts +9 -3
- package/src/test/noop_l1_archiver.ts +7 -1
|
@@ -52,29 +52,29 @@ export class ArchiverDataStoreUpdater {
|
|
|
52
52
|
) {}
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
|
-
* Adds proposed
|
|
56
|
-
*
|
|
55
|
+
* Adds a proposed block to the store with contract class/instance extraction from logs.
|
|
56
|
+
* This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
|
|
57
57
|
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events,
|
|
58
58
|
* and individually broadcasted functions from the block logs.
|
|
59
59
|
*
|
|
60
|
-
* @param
|
|
60
|
+
* @param block - The proposed L2 block to add.
|
|
61
61
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
62
62
|
* @returns True if the operation is successful.
|
|
63
63
|
*/
|
|
64
|
-
public async
|
|
65
|
-
|
|
64
|
+
public async addProposedBlock(
|
|
65
|
+
block: L2Block,
|
|
66
66
|
pendingChainValidationStatus?: ValidateCheckpointResult,
|
|
67
67
|
): Promise<boolean> {
|
|
68
68
|
const result = await this.store.transactionAsync(async () => {
|
|
69
|
-
await this.store.
|
|
69
|
+
await this.store.addProposedBlock(block);
|
|
70
70
|
|
|
71
71
|
const opResults = await Promise.all([
|
|
72
72
|
// Update the pending chain validation status if provided
|
|
73
73
|
pendingChainValidationStatus && this.store.setPendingChainValidationStatus(pendingChainValidationStatus),
|
|
74
|
-
// Add any logs emitted during the retrieved
|
|
75
|
-
this.store.addLogs(
|
|
76
|
-
// Unroll all logs emitted during the retrieved
|
|
77
|
-
|
|
74
|
+
// Add any logs emitted during the retrieved block
|
|
75
|
+
this.store.addLogs([block]),
|
|
76
|
+
// Unroll all logs emitted during the retrieved block and extract any contract classes and instances from it
|
|
77
|
+
this.addContractDataToDb(block),
|
|
78
78
|
]);
|
|
79
79
|
|
|
80
80
|
await this.l2TipsCache?.refresh();
|
|
@@ -108,7 +108,7 @@ export class ArchiverDataStoreUpdater {
|
|
|
108
108
|
|
|
109
109
|
await this.store.addCheckpoints(checkpoints);
|
|
110
110
|
|
|
111
|
-
// Filter out blocks that were already inserted via
|
|
111
|
+
// Filter out blocks that were already inserted via addProposedBlock() to avoid duplicating logs/contract data
|
|
112
112
|
const newBlocks = checkpoints
|
|
113
113
|
.flatMap((ch: PublishedCheckpoint) => ch.checkpoint.blocks)
|
|
114
114
|
.filter(b => lastAlreadyInsertedBlockNumber === undefined || b.number > lastAlreadyInsertedBlockNumber);
|
|
@@ -178,7 +178,7 @@ export class ArchiverDataStoreUpdater {
|
|
|
178
178
|
this.log.verbose(`Block number ${blockNumber} already inserted and matches checkpoint`, blockInfos);
|
|
179
179
|
lastAlreadyInsertedBlockNumber = blockNumber;
|
|
180
180
|
} else {
|
|
181
|
-
this.log.
|
|
181
|
+
this.log.info(`Conflict detected at block ${blockNumber} between checkpointed and local block`, blockInfos);
|
|
182
182
|
const prunedBlocks = await this.removeBlocksAfter(BlockNumber(blockNumber - 1));
|
|
183
183
|
return { prunedBlocks, lastAlreadyInsertedBlockNumber };
|
|
184
184
|
}
|
|
@@ -281,6 +281,17 @@ export class ArchiverDataStoreUpdater {
|
|
|
281
281
|
});
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
+
/**
|
|
285
|
+
* Updates the finalized checkpoint number and refreshes the L2 tips cache.
|
|
286
|
+
* @param checkpointNumber - The checkpoint number to set as finalized.
|
|
287
|
+
*/
|
|
288
|
+
public async setFinalizedCheckpointNumber(checkpointNumber: CheckpointNumber): Promise<void> {
|
|
289
|
+
await this.store.transactionAsync(async () => {
|
|
290
|
+
await this.store.setFinalizedCheckpointNumber(checkpointNumber);
|
|
291
|
+
await this.l2TipsCache?.refresh();
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
284
295
|
/** Extracts and stores contract data from a single block. */
|
|
285
296
|
private addContractDataToDb(block: L2Block): Promise<boolean> {
|
|
286
297
|
return this.updateContractDataOnDb(block, Operation.Store);
|
|
@@ -72,7 +72,6 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
72
72
|
private readonly l1Constants: L1RollupConstants & {
|
|
73
73
|
l1StartBlockHash: Buffer32;
|
|
74
74
|
genesisArchiveRoot: Fr;
|
|
75
|
-
rollupManaLimit?: number;
|
|
76
75
|
},
|
|
77
76
|
private readonly events: ArchiverEmitter,
|
|
78
77
|
tracer: Tracer,
|
|
@@ -217,6 +216,9 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
217
216
|
this.instrumentation.updateL1BlockHeight(currentL1BlockNumber);
|
|
218
217
|
}
|
|
219
218
|
|
|
219
|
+
// Update the finalized L2 checkpoint based on L1 finality.
|
|
220
|
+
await this.updateFinalizedCheckpoint();
|
|
221
|
+
|
|
220
222
|
// After syncing has completed, update the current l1 block number and timestamp,
|
|
221
223
|
// otherwise we risk announcing to the world that we've synced to a given point,
|
|
222
224
|
// but the corresponding blocks have not been processed (see #12631).
|
|
@@ -232,6 +234,27 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
232
234
|
});
|
|
233
235
|
}
|
|
234
236
|
|
|
237
|
+
/** Query L1 for its finalized block and update the finalized checkpoint accordingly. */
|
|
238
|
+
private async updateFinalizedCheckpoint(): Promise<void> {
|
|
239
|
+
try {
|
|
240
|
+
const finalizedL1Block = await this.publicClient.getBlock({ blockTag: 'finalized', includeTransactions: false });
|
|
241
|
+
const finalizedL1BlockNumber = finalizedL1Block.number;
|
|
242
|
+
const finalizedCheckpointNumber = await this.rollup.getProvenCheckpointNumber({
|
|
243
|
+
blockNumber: finalizedL1BlockNumber,
|
|
244
|
+
});
|
|
245
|
+
const localFinalizedCheckpointNumber = await this.store.getFinalizedCheckpointNumber();
|
|
246
|
+
if (localFinalizedCheckpointNumber !== finalizedCheckpointNumber) {
|
|
247
|
+
await this.updater.setFinalizedCheckpointNumber(finalizedCheckpointNumber);
|
|
248
|
+
this.log.info(`Updated finalized chain to checkpoint ${finalizedCheckpointNumber}`, {
|
|
249
|
+
finalizedCheckpointNumber,
|
|
250
|
+
finalizedL1BlockNumber,
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
} catch (err) {
|
|
254
|
+
this.log.warn(`Failed to update finalized checkpoint: ${err}`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
235
258
|
/** Prune all proposed local blocks that should have been checkpointed by now. */
|
|
236
259
|
private async pruneUncheckpointedBlocks(currentL1Timestamp: bigint) {
|
|
237
260
|
const [lastCheckpointedBlockNumber, lastProposedBlockNumber] = await Promise.all([
|
|
@@ -368,6 +391,7 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
368
391
|
const localMessagesInserted = await this.store.getTotalL1ToL2MessageCount();
|
|
369
392
|
const localLastMessage = await this.store.getLastL1ToL2Message();
|
|
370
393
|
const remoteMessagesState = await this.inbox.getState({ blockNumber: currentL1BlockNumber });
|
|
394
|
+
await this.store.setInboxTreeInProgress(remoteMessagesState.treeInProgress);
|
|
371
395
|
|
|
372
396
|
this.log.trace(`Retrieved remote inbox state at L1 block ${currentL1BlockNumber}.`, {
|
|
373
397
|
localMessagesInserted,
|
|
@@ -828,7 +852,7 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
828
852
|
const prunedCheckpointNumber = result.prunedBlocks[0].checkpointNumber;
|
|
829
853
|
const prunedSlotNumber = result.prunedBlocks[0].header.globalVariables.slotNumber;
|
|
830
854
|
|
|
831
|
-
this.log.
|
|
855
|
+
this.log.info(
|
|
832
856
|
`Pruned ${result.prunedBlocks.length} mismatching blocks for checkpoint ${prunedCheckpointNumber}`,
|
|
833
857
|
{ prunedBlocks: result.prunedBlocks.map(b => b.toBlockInfo()), prunedSlotNumber, prunedCheckpointNumber },
|
|
834
858
|
);
|
package/src/store/block_store.ts
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
serializeValidateCheckpointResult,
|
|
21
21
|
} from '@aztec/stdlib/block';
|
|
22
22
|
import { type CheckpointData, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
23
|
-
import type
|
|
23
|
+
import { type L1RollupConstants, getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
24
24
|
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
25
25
|
import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
|
|
26
26
|
import {
|
|
@@ -35,15 +35,14 @@ import {
|
|
|
35
35
|
} from '@aztec/stdlib/tx';
|
|
36
36
|
|
|
37
37
|
import {
|
|
38
|
+
BlockAlreadyCheckpointedError,
|
|
38
39
|
BlockArchiveNotConsistentError,
|
|
39
40
|
BlockIndexNotSequentialError,
|
|
40
41
|
BlockNotFoundError,
|
|
41
42
|
BlockNumberNotSequentialError,
|
|
42
43
|
CannotOverwriteCheckpointedBlockError,
|
|
43
44
|
CheckpointNotFoundError,
|
|
44
|
-
CheckpointNumberNotConsistentError,
|
|
45
45
|
CheckpointNumberNotSequentialError,
|
|
46
|
-
InitialBlockNumberNotSequentialError,
|
|
47
46
|
InitialCheckpointNumberNotSequentialError,
|
|
48
47
|
} from '../errors.js';
|
|
49
48
|
|
|
@@ -97,6 +96,9 @@ export class BlockStore {
|
|
|
97
96
|
/** Stores last proven checkpoint */
|
|
98
97
|
#lastProvenCheckpoint: AztecAsyncSingleton<number>;
|
|
99
98
|
|
|
99
|
+
/** Stores last finalized checkpoint (proven at or before the finalized L1 block) */
|
|
100
|
+
#lastFinalizedCheckpoint: AztecAsyncSingleton<number>;
|
|
101
|
+
|
|
100
102
|
/** Stores the pending chain validation status */
|
|
101
103
|
#pendingChainValidationStatus: AztecAsyncSingleton<Buffer>;
|
|
102
104
|
|
|
@@ -111,10 +113,7 @@ export class BlockStore {
|
|
|
111
113
|
|
|
112
114
|
#log = createLogger('archiver:block_store');
|
|
113
115
|
|
|
114
|
-
constructor(
|
|
115
|
-
private db: AztecAsyncKVStore,
|
|
116
|
-
private l1Constants: Pick<L1RollupConstants, 'epochDuration'>,
|
|
117
|
-
) {
|
|
116
|
+
constructor(private db: AztecAsyncKVStore) {
|
|
118
117
|
this.#blocks = db.openMap('archiver_blocks');
|
|
119
118
|
this.#blockTxs = db.openMap('archiver_block_txs');
|
|
120
119
|
this.#txEffects = db.openMap('archiver_tx_effects');
|
|
@@ -123,41 +122,42 @@ export class BlockStore {
|
|
|
123
122
|
this.#blockArchiveIndex = db.openMap('archiver_block_archive_index');
|
|
124
123
|
this.#lastSynchedL1Block = db.openSingleton('archiver_last_synched_l1_block');
|
|
125
124
|
this.#lastProvenCheckpoint = db.openSingleton('archiver_last_proven_l2_checkpoint');
|
|
125
|
+
this.#lastFinalizedCheckpoint = db.openSingleton('archiver_last_finalized_l2_checkpoint');
|
|
126
126
|
this.#pendingChainValidationStatus = db.openSingleton('archiver_pending_chain_validation_status');
|
|
127
127
|
this.#checkpoints = db.openMap('archiver_checkpoints');
|
|
128
128
|
this.#slotToCheckpoint = db.openMap('archiver_slot_to_checkpoint');
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
/**
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* TODO(#13569): Compute proper finalized block number based on L1 finalized block.
|
|
135
|
-
* TODO(palla/mbps): Even the provisional computation is wrong, since it should subtract checkpoints, not blocks
|
|
132
|
+
* Returns the finalized L2 block number. An L2 block is finalized when it was proven
|
|
133
|
+
* in an L1 block that has itself been finalized on Ethereum.
|
|
136
134
|
* @returns The finalized block number.
|
|
137
135
|
*/
|
|
138
136
|
async getFinalizedL2BlockNumber(): Promise<BlockNumber> {
|
|
139
|
-
const
|
|
140
|
-
|
|
137
|
+
const finalizedCheckpointNumber = await this.getFinalizedCheckpointNumber();
|
|
138
|
+
if (finalizedCheckpointNumber === INITIAL_CHECKPOINT_NUMBER - 1) {
|
|
139
|
+
return BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
|
|
140
|
+
}
|
|
141
|
+
const checkpointStorage = await this.#checkpoints.getAsync(finalizedCheckpointNumber);
|
|
142
|
+
if (!checkpointStorage) {
|
|
143
|
+
throw new CheckpointNotFoundError(finalizedCheckpointNumber);
|
|
144
|
+
}
|
|
145
|
+
return BlockNumber(checkpointStorage.startBlock + checkpointStorage.blockCount - 1);
|
|
141
146
|
}
|
|
142
147
|
|
|
143
148
|
/**
|
|
144
|
-
* Append new proposed
|
|
145
|
-
*
|
|
149
|
+
* Append a new proposed block to the store.
|
|
150
|
+
* This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
|
|
146
151
|
* For checkpointed blocks (already published to L1), use addCheckpoints() instead.
|
|
147
|
-
* @param
|
|
152
|
+
* @param block - The proposed L2 block to be added to the store.
|
|
148
153
|
* @returns True if the operation is successful.
|
|
149
154
|
*/
|
|
150
|
-
async
|
|
151
|
-
if (blocks.length === 0) {
|
|
152
|
-
return true;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
+
async addProposedBlock(block: L2Block, opts: { force?: boolean } = {}): Promise<boolean> {
|
|
155
156
|
return await this.db.transactionAsync(async () => {
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
const
|
|
160
|
-
const firstBlockLastArchive = blocks[0].header.lastArchive.root;
|
|
157
|
+
const blockNumber = block.number;
|
|
158
|
+
const blockCheckpointNumber = block.checkpointNumber;
|
|
159
|
+
const blockIndex = block.indexWithinCheckpoint;
|
|
160
|
+
const blockLastArchive = block.header.lastArchive.root;
|
|
161
161
|
|
|
162
162
|
// Extract the latest block and checkpoint numbers
|
|
163
163
|
const previousBlockNumber = await this.getLatestBlockNumber();
|
|
@@ -165,71 +165,52 @@ export class BlockStore {
|
|
|
165
165
|
|
|
166
166
|
// Verify we're not overwriting checkpointed blocks
|
|
167
167
|
const lastCheckpointedBlockNumber = await this.getCheckpointedL2BlockNumber();
|
|
168
|
-
if (!opts.force &&
|
|
169
|
-
|
|
168
|
+
if (!opts.force && blockNumber <= lastCheckpointedBlockNumber) {
|
|
169
|
+
// Check if the proposed block matches the already-checkpointed one
|
|
170
|
+
const existingBlock = await this.getBlock(BlockNumber(blockNumber));
|
|
171
|
+
if (existingBlock && existingBlock.archive.root.equals(block.archive.root)) {
|
|
172
|
+
throw new BlockAlreadyCheckpointedError(blockNumber);
|
|
173
|
+
}
|
|
174
|
+
throw new CannotOverwriteCheckpointedBlockError(blockNumber, lastCheckpointedBlockNumber);
|
|
170
175
|
}
|
|
171
176
|
|
|
172
|
-
// Check that the
|
|
173
|
-
if (!opts.force && previousBlockNumber !==
|
|
174
|
-
throw new
|
|
177
|
+
// Check that the block number is the expected one
|
|
178
|
+
if (!opts.force && previousBlockNumber !== blockNumber - 1) {
|
|
179
|
+
throw new BlockNumberNotSequentialError(blockNumber, previousBlockNumber);
|
|
175
180
|
}
|
|
176
181
|
|
|
177
182
|
// The same check as above but for checkpoints
|
|
178
|
-
if (!opts.force && previousCheckpointNumber !==
|
|
179
|
-
throw new
|
|
183
|
+
if (!opts.force && previousCheckpointNumber !== blockCheckpointNumber - 1) {
|
|
184
|
+
throw new CheckpointNumberNotSequentialError(blockCheckpointNumber, previousCheckpointNumber);
|
|
180
185
|
}
|
|
181
186
|
|
|
182
187
|
// Extract the previous block if there is one and see if it is for the same checkpoint or not
|
|
183
188
|
const previousBlockResult = await this.getBlock(previousBlockNumber);
|
|
184
189
|
|
|
185
|
-
let
|
|
190
|
+
let expectedBlockIndex = 0;
|
|
186
191
|
let previousBlockIndex: number | undefined = undefined;
|
|
187
192
|
if (previousBlockResult !== undefined) {
|
|
188
|
-
if (previousBlockResult.checkpointNumber ===
|
|
193
|
+
if (previousBlockResult.checkpointNumber === blockCheckpointNumber) {
|
|
189
194
|
// The previous block is for the same checkpoint, therefore our index should follow it
|
|
190
195
|
previousBlockIndex = previousBlockResult.indexWithinCheckpoint;
|
|
191
|
-
|
|
196
|
+
expectedBlockIndex = previousBlockIndex + 1;
|
|
192
197
|
}
|
|
193
|
-
if (!previousBlockResult.archive.root.equals(
|
|
198
|
+
if (!previousBlockResult.archive.root.equals(blockLastArchive)) {
|
|
194
199
|
throw new BlockArchiveNotConsistentError(
|
|
195
|
-
|
|
200
|
+
blockNumber,
|
|
196
201
|
previousBlockResult.number,
|
|
197
|
-
|
|
202
|
+
blockLastArchive,
|
|
198
203
|
previousBlockResult.archive.root,
|
|
199
204
|
);
|
|
200
205
|
}
|
|
201
206
|
}
|
|
202
207
|
|
|
203
|
-
// Now check that the
|
|
204
|
-
if (!opts.force &&
|
|
205
|
-
throw new BlockIndexNotSequentialError(
|
|
208
|
+
// Now check that the block has the expected index value
|
|
209
|
+
if (!opts.force && expectedBlockIndex !== blockIndex) {
|
|
210
|
+
throw new BlockIndexNotSequentialError(blockIndex, previousBlockIndex);
|
|
206
211
|
}
|
|
207
212
|
|
|
208
|
-
|
|
209
|
-
let previousBlock: L2Block | undefined = undefined;
|
|
210
|
-
for (const block of blocks) {
|
|
211
|
-
if (!opts.force && previousBlock) {
|
|
212
|
-
if (previousBlock.number + 1 !== block.number) {
|
|
213
|
-
throw new BlockNumberNotSequentialError(block.number, previousBlock.number);
|
|
214
|
-
}
|
|
215
|
-
if (previousBlock.indexWithinCheckpoint + 1 !== block.indexWithinCheckpoint) {
|
|
216
|
-
throw new BlockIndexNotSequentialError(block.indexWithinCheckpoint, previousBlock.indexWithinCheckpoint);
|
|
217
|
-
}
|
|
218
|
-
if (!previousBlock.archive.root.equals(block.header.lastArchive.root)) {
|
|
219
|
-
throw new BlockArchiveNotConsistentError(
|
|
220
|
-
block.number,
|
|
221
|
-
previousBlock.number,
|
|
222
|
-
block.header.lastArchive.root,
|
|
223
|
-
previousBlock.archive.root,
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
if (!opts.force && firstBlockCheckpointNumber !== block.checkpointNumber) {
|
|
228
|
-
throw new CheckpointNumberNotConsistentError(block.checkpointNumber, firstBlockCheckpointNumber);
|
|
229
|
-
}
|
|
230
|
-
previousBlock = block;
|
|
231
|
-
await this.addBlockToDatabase(block, block.checkpointNumber, block.indexWithinCheckpoint);
|
|
232
|
-
}
|
|
213
|
+
await this.addBlockToDatabase(block, block.checkpointNumber, block.indexWithinCheckpoint);
|
|
233
214
|
|
|
234
215
|
return true;
|
|
235
216
|
});
|
|
@@ -871,7 +852,10 @@ export class BlockStore {
|
|
|
871
852
|
* @param txHash - The hash of a tx we try to get the receipt for.
|
|
872
853
|
* @returns The requested tx receipt (or undefined if not found).
|
|
873
854
|
*/
|
|
874
|
-
async getSettledTxReceipt(
|
|
855
|
+
async getSettledTxReceipt(
|
|
856
|
+
txHash: TxHash,
|
|
857
|
+
l1Constants?: Pick<L1RollupConstants, 'epochDuration'>,
|
|
858
|
+
): Promise<TxReceipt | undefined> {
|
|
875
859
|
const txEffect = await this.getTxEffect(txHash);
|
|
876
860
|
if (!txEffect) {
|
|
877
861
|
return undefined;
|
|
@@ -880,10 +864,11 @@ export class BlockStore {
|
|
|
880
864
|
const blockNumber = BlockNumber(txEffect.l2BlockNumber);
|
|
881
865
|
|
|
882
866
|
// Use existing archiver methods to determine finalization level
|
|
883
|
-
const [provenBlockNumber, checkpointedBlockNumber, finalizedBlockNumber] = await Promise.all([
|
|
867
|
+
const [provenBlockNumber, checkpointedBlockNumber, finalizedBlockNumber, blockData] = await Promise.all([
|
|
884
868
|
this.getProvenBlockNumber(),
|
|
885
869
|
this.getCheckpointedL2BlockNumber(),
|
|
886
870
|
this.getFinalizedL2BlockNumber(),
|
|
871
|
+
this.getBlockData(blockNumber),
|
|
887
872
|
]);
|
|
888
873
|
|
|
889
874
|
let status: TxStatus;
|
|
@@ -897,6 +882,9 @@ export class BlockStore {
|
|
|
897
882
|
status = TxStatus.PROPOSED;
|
|
898
883
|
}
|
|
899
884
|
|
|
885
|
+
const epochNumber =
|
|
886
|
+
blockData && l1Constants ? getEpochAtSlot(blockData.header.globalVariables.slotNumber, l1Constants) : undefined;
|
|
887
|
+
|
|
900
888
|
return new TxReceipt(
|
|
901
889
|
txHash,
|
|
902
890
|
status,
|
|
@@ -905,6 +893,7 @@ export class BlockStore {
|
|
|
905
893
|
txEffect.data.transactionFee.toBigInt(),
|
|
906
894
|
txEffect.l2BlockHash,
|
|
907
895
|
blockNumber,
|
|
896
|
+
epochNumber,
|
|
908
897
|
);
|
|
909
898
|
}
|
|
910
899
|
|
|
@@ -976,6 +965,20 @@ export class BlockStore {
|
|
|
976
965
|
return result;
|
|
977
966
|
}
|
|
978
967
|
|
|
968
|
+
async getFinalizedCheckpointNumber(): Promise<CheckpointNumber> {
|
|
969
|
+
const [latestCheckpointNumber, finalizedCheckpointNumber] = await Promise.all([
|
|
970
|
+
this.getLatestCheckpointNumber(),
|
|
971
|
+
this.#lastFinalizedCheckpoint.getAsync(),
|
|
972
|
+
]);
|
|
973
|
+
return (finalizedCheckpointNumber ?? 0) > latestCheckpointNumber
|
|
974
|
+
? latestCheckpointNumber
|
|
975
|
+
: CheckpointNumber(finalizedCheckpointNumber ?? 0);
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
setFinalizedCheckpointNumber(checkpointNumber: CheckpointNumber) {
|
|
979
|
+
return this.#lastFinalizedCheckpoint.set(checkpointNumber);
|
|
980
|
+
}
|
|
981
|
+
|
|
979
982
|
#computeBlockRange(start: BlockNumber, limit: number): Required<Pick<Range<number>, 'start' | 'limit'>> {
|
|
980
983
|
if (limit < 1) {
|
|
981
984
|
throw new Error(`Invalid limit: ${limit}`);
|
|
@@ -71,9 +71,8 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
71
71
|
constructor(
|
|
72
72
|
private db: AztecAsyncKVStore,
|
|
73
73
|
logsMaxPageSize: number = 1000,
|
|
74
|
-
l1Constants: Pick<L1RollupConstants, 'epochDuration'>,
|
|
75
74
|
) {
|
|
76
|
-
this.#blockStore = new BlockStore(db
|
|
75
|
+
this.#blockStore = new BlockStore(db);
|
|
77
76
|
this.#logStore = new LogStore(db, this.#blockStore, logsMaxPageSize);
|
|
78
77
|
this.#messageStore = new MessageStore(db);
|
|
79
78
|
this.#contractClassStore = new ContractClassStore(db);
|
|
@@ -246,14 +245,14 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
246
245
|
}
|
|
247
246
|
|
|
248
247
|
/**
|
|
249
|
-
* Append new proposed
|
|
250
|
-
*
|
|
248
|
+
* Append a new proposed block to the store.
|
|
249
|
+
* This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
|
|
251
250
|
* For checkpointed blocks (already published to L1), use addCheckpoints() instead.
|
|
252
|
-
* @param
|
|
251
|
+
* @param block - The proposed L2 block to be added to the store.
|
|
253
252
|
* @returns True if the operation is successful.
|
|
254
253
|
*/
|
|
255
|
-
|
|
256
|
-
return this.#blockStore.
|
|
254
|
+
addProposedBlock(block: L2Block, opts: { force?: boolean } = {}): Promise<boolean> {
|
|
255
|
+
return this.#blockStore.addProposedBlock(block, opts);
|
|
257
256
|
}
|
|
258
257
|
|
|
259
258
|
/**
|
|
@@ -410,8 +409,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
410
409
|
* @param txHash - The hash of a tx we try to get the receipt for.
|
|
411
410
|
* @returns The requested tx receipt (or undefined if not found).
|
|
412
411
|
*/
|
|
413
|
-
getSettledTxReceipt(
|
|
414
|
-
|
|
412
|
+
getSettledTxReceipt(
|
|
413
|
+
txHash: TxHash,
|
|
414
|
+
l1Constants?: Pick<L1RollupConstants, 'epochDuration'>,
|
|
415
|
+
): Promise<TxReceipt | undefined> {
|
|
416
|
+
return this.#blockStore.getSettledTxReceipt(txHash, l1Constants);
|
|
415
417
|
}
|
|
416
418
|
|
|
417
419
|
/**
|
|
@@ -472,10 +474,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
472
474
|
* array implies no logs match that tag.
|
|
473
475
|
* @param tags - The tags to search for.
|
|
474
476
|
* @param page - The page number (0-indexed) for pagination. Returns at most 10 logs per tag per page.
|
|
477
|
+
* @param upToBlockNumber - If set, only return logs from blocks up to and including this block number.
|
|
475
478
|
*/
|
|
476
|
-
getPrivateLogsByTags(tags: SiloedTag[], page?: number): Promise<TxScopedL2Log[][]> {
|
|
479
|
+
getPrivateLogsByTags(tags: SiloedTag[], page?: number, upToBlockNumber?: BlockNumber): Promise<TxScopedL2Log[][]> {
|
|
477
480
|
try {
|
|
478
|
-
return this.#logStore.getPrivateLogsByTags(tags, page);
|
|
481
|
+
return this.#logStore.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
479
482
|
} catch (err) {
|
|
480
483
|
return Promise.reject(err);
|
|
481
484
|
}
|
|
@@ -487,14 +490,16 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
487
490
|
* @param contractAddress - The contract address to search logs for.
|
|
488
491
|
* @param tags - The tags to search for.
|
|
489
492
|
* @param page - The page number (0-indexed) for pagination. Returns at most 10 logs per tag per page.
|
|
493
|
+
* @param upToBlockNumber - If set, only return logs from blocks up to and including this block number.
|
|
490
494
|
*/
|
|
491
495
|
getPublicLogsByTagsFromContract(
|
|
492
496
|
contractAddress: AztecAddress,
|
|
493
497
|
tags: Tag[],
|
|
494
498
|
page?: number,
|
|
499
|
+
upToBlockNumber?: BlockNumber,
|
|
495
500
|
): Promise<TxScopedL2Log[][]> {
|
|
496
501
|
try {
|
|
497
|
-
return this.#logStore.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
502
|
+
return this.#logStore.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
498
503
|
} catch (err) {
|
|
499
504
|
return Promise.reject(err);
|
|
500
505
|
}
|
|
@@ -542,6 +547,22 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
542
547
|
await this.#blockStore.setProvenCheckpointNumber(checkpointNumber);
|
|
543
548
|
}
|
|
544
549
|
|
|
550
|
+
/**
|
|
551
|
+
* Gets the number of the latest finalized checkpoint processed.
|
|
552
|
+
* @returns The number of the latest finalized checkpoint processed.
|
|
553
|
+
*/
|
|
554
|
+
getFinalizedCheckpointNumber(): Promise<CheckpointNumber> {
|
|
555
|
+
return this.#blockStore.getFinalizedCheckpointNumber();
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Stores the number of the latest finalized checkpoint processed.
|
|
560
|
+
* @param checkpointNumber - The number of the latest finalized checkpoint processed.
|
|
561
|
+
*/
|
|
562
|
+
async setFinalizedCheckpointNumber(checkpointNumber: CheckpointNumber) {
|
|
563
|
+
await this.#blockStore.setFinalizedCheckpointNumber(checkpointNumber);
|
|
564
|
+
}
|
|
565
|
+
|
|
545
566
|
async setBlockSynchedL1BlockNumber(l1BlockNumber: bigint) {
|
|
546
567
|
await this.#blockStore.setSynchedL1BlockNumber(l1BlockNumber);
|
|
547
568
|
}
|
|
@@ -585,6 +606,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
585
606
|
return this.#messageStore.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
|
|
586
607
|
}
|
|
587
608
|
|
|
609
|
+
/** Persists the inbox tree-in-progress checkpoint number from L1 state. */
|
|
610
|
+
public setInboxTreeInProgress(value: bigint): Promise<void> {
|
|
611
|
+
return this.#messageStore.setInboxTreeInProgress(value);
|
|
612
|
+
}
|
|
613
|
+
|
|
588
614
|
/** Returns an async iterator to all L1 to L2 messages on the range. */
|
|
589
615
|
public iterateL1ToL2Messages(range: CustomRange<bigint> = {}): AsyncIterableIterator<InboxMessage> {
|
|
590
616
|
return this.#messageStore.iterateL1ToL2Messages(range);
|