@aztec/archiver 0.0.1-commit.f295ac2 → 0.0.1-commit.f504929
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 +10 -6
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +50 -111
- 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 +16 -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 +35 -32
- 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 +24 -22
- 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/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 +25 -21
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +48 -123
- package/dest/modules/data_store_updater.d.ts +31 -20
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +79 -60
- package/dest/modules/instrumentation.d.ts +17 -4
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +36 -12
- package/dest/modules/l1_synchronizer.d.ts +4 -8
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +23 -19
- package/dest/store/block_store.d.ts +50 -32
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +147 -54
- 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 +52 -29
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +49 -23
- 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 +17 -8
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +77 -43
- package/dest/test/fake_l1_state.d.ts +9 -4
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +56 -18
- package/dest/test/index.js +3 -1
- 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 +36 -21
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +151 -109
- 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 +71 -136
- package/src/errors.ts +12 -0
- package/src/factory.ts +30 -14
- package/src/index.ts +1 -0
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +45 -33
- package/src/l1/calldata_retriever.ts +249 -379
- package/src/l1/data_retrieval.ts +27 -29
- package/src/l1/spire_proposer.ts +7 -15
- package/src/l1/validate_trace.ts +24 -6
- package/src/modules/data_source_base.ts +81 -167
- package/src/modules/data_store_updater.ts +92 -63
- package/src/modules/instrumentation.ts +46 -14
- package/src/modules/l1_synchronizer.ts +26 -24
- package/src/store/block_store.ts +188 -92
- package/src/store/contract_class_store.ts +11 -7
- package/src/store/kv_archiver_store.ts +85 -36
- package/src/store/l2_tips_cache.ts +89 -0
- package/src/store/log_store.ts +134 -49
- package/src/test/fake_l1_state.ts +77 -19
- package/src/test/index.ts +3 -0
- package/src/test/mock_archiver.ts +3 -2
- package/src/test/mock_l2_block_source.ts +196 -126
- package/src/test/mock_structs.ts +26 -10
- package/src/test/noop_l1_archiver.ts +109 -0
|
@@ -6,19 +6,21 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
6
6
|
import { BufferReader } from '@aztec/foundation/serialize';
|
|
7
7
|
import { bufferToHex } from '@aztec/foundation/string';
|
|
8
8
|
import { isDefined } from '@aztec/foundation/types';
|
|
9
|
-
import { Body, CheckpointedL2Block, CommitteeAttestation,
|
|
9
|
+
import { Body, CheckpointedL2Block, CommitteeAttestation, L2Block, deserializeValidateCheckpointResult, serializeValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
10
10
|
import { L1PublishedData } from '@aztec/stdlib/checkpoint';
|
|
11
11
|
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
12
12
|
import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
|
|
13
|
-
import { BlockHeader, TxHash, TxReceipt, deserializeIndexedTxEffect, serializeIndexedTxEffect } from '@aztec/stdlib/tx';
|
|
14
|
-
import { BlockArchiveNotConsistentError, BlockIndexNotSequentialError, BlockNotFoundError, BlockNumberNotSequentialError, CheckpointNotFoundError, CheckpointNumberNotConsistentError, CheckpointNumberNotSequentialError, InitialBlockNumberNotSequentialError, InitialCheckpointNumberNotSequentialError } from '../errors.js';
|
|
13
|
+
import { BlockHeader, TxHash, TxReceipt, TxStatus, deserializeIndexedTxEffect, serializeIndexedTxEffect } from '@aztec/stdlib/tx';
|
|
14
|
+
import { BlockArchiveNotConsistentError, BlockIndexNotSequentialError, BlockNotFoundError, BlockNumberNotSequentialError, CannotOverwriteCheckpointedBlockError, CheckpointNotFoundError, CheckpointNumberNotConsistentError, CheckpointNumberNotSequentialError, InitialBlockNumberNotSequentialError, InitialCheckpointNumberNotSequentialError } from '../errors.js';
|
|
15
15
|
export { TxReceipt } from '@aztec/stdlib/tx';
|
|
16
16
|
/**
|
|
17
17
|
* LMDB-based block storage for the archiver.
|
|
18
18
|
*/ export class BlockStore {
|
|
19
19
|
db;
|
|
20
|
+
l1Constants;
|
|
20
21
|
/** Map block number to block data */ #blocks;
|
|
21
22
|
/** Map checkpoint number to checkpoint data */ #checkpoints;
|
|
23
|
+
/** Map slot number to checkpoint number, for looking up checkpoints by slot range. */ #slotToCheckpoint;
|
|
22
24
|
/** Map block hash to list of tx hashes */ #blockTxs;
|
|
23
25
|
/** Tx hash to serialized IndexedTxEffect */ #txEffects;
|
|
24
26
|
/** Stores L1 block number in which the last processed L2 block was included */ #lastSynchedL1Block;
|
|
@@ -28,8 +30,9 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
28
30
|
/** Index mapping block hash to block number */ #blockHashIndex;
|
|
29
31
|
/** Index mapping block archive to block number */ #blockArchiveIndex;
|
|
30
32
|
#log;
|
|
31
|
-
constructor(db){
|
|
33
|
+
constructor(db, l1Constants){
|
|
32
34
|
this.db = db;
|
|
35
|
+
this.l1Constants = l1Constants;
|
|
33
36
|
this.#log = createLogger('archiver:block_store');
|
|
34
37
|
this.#blocks = db.openMap('archiver_blocks');
|
|
35
38
|
this.#blockTxs = db.openMap('archiver_block_txs');
|
|
@@ -41,12 +44,25 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
41
44
|
this.#lastProvenCheckpoint = db.openSingleton('archiver_last_proven_l2_checkpoint');
|
|
42
45
|
this.#pendingChainValidationStatus = db.openSingleton('archiver_pending_chain_validation_status');
|
|
43
46
|
this.#checkpoints = db.openMap('archiver_checkpoints');
|
|
47
|
+
this.#slotToCheckpoint = db.openMap('archiver_slot_to_checkpoint');
|
|
44
48
|
}
|
|
45
49
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
50
|
+
* Computes the finalized block number based on the proven block number.
|
|
51
|
+
* A block is considered finalized when it's 2 epochs behind the proven block.
|
|
52
|
+
* TODO(#13569): Compute proper finalized block number based on L1 finalized block.
|
|
53
|
+
* TODO(palla/mbps): Even the provisional computation is wrong, since it should subtract checkpoints, not blocks
|
|
54
|
+
* @returns The finalized block number.
|
|
55
|
+
*/ async getFinalizedL2BlockNumber() {
|
|
56
|
+
const provenBlockNumber = await this.getProvenBlockNumber();
|
|
57
|
+
return BlockNumber(Math.max(provenBlockNumber - this.l1Constants.epochDuration * 2, 0));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Append new proposed blocks to the store's list. All blocks must be for the 'current' checkpoint.
|
|
61
|
+
* These are uncheckpointed blocks that have been proposed by the sequencer but not yet included in a checkpoint on L1.
|
|
62
|
+
* For checkpointed blocks (already published to L1), use addCheckpoints() instead.
|
|
63
|
+
* @param blocks - The proposed L2 blocks to be added to the store.
|
|
48
64
|
* @returns True if the operation is successful.
|
|
49
|
-
*/ async
|
|
65
|
+
*/ async addProposedBlocks(blocks, opts = {}) {
|
|
50
66
|
if (blocks.length === 0) {
|
|
51
67
|
return true;
|
|
52
68
|
}
|
|
@@ -59,6 +75,11 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
59
75
|
// Extract the latest block and checkpoint numbers
|
|
60
76
|
const previousBlockNumber = await this.getLatestBlockNumber();
|
|
61
77
|
const previousCheckpointNumber = await this.getLatestCheckpointNumber();
|
|
78
|
+
// Verify we're not overwriting checkpointed blocks
|
|
79
|
+
const lastCheckpointedBlockNumber = await this.getCheckpointedL2BlockNumber();
|
|
80
|
+
if (!opts.force && firstBlockNumber <= lastCheckpointedBlockNumber) {
|
|
81
|
+
throw new CannotOverwriteCheckpointedBlockError(firstBlockNumber, lastCheckpointedBlockNumber);
|
|
82
|
+
}
|
|
62
83
|
// Check that the first block number is the expected one
|
|
63
84
|
if (!opts.force && previousBlockNumber !== firstBlockNumber - 1) {
|
|
64
85
|
throw new InitialBlockNumberNotSequentialError(firstBlockNumber, previousBlockNumber);
|
|
@@ -136,7 +157,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
136
157
|
let previousBlock = undefined;
|
|
137
158
|
// If we have a previous checkpoint then we need to get the previous block number
|
|
138
159
|
if (previousCheckpointData !== undefined) {
|
|
139
|
-
previousBlockNumber = BlockNumber(previousCheckpointData.startBlock + previousCheckpointData.
|
|
160
|
+
previousBlockNumber = BlockNumber(previousCheckpointData.startBlock + previousCheckpointData.blockCount - 1);
|
|
140
161
|
previousBlock = await this.getBlock(previousBlockNumber);
|
|
141
162
|
if (previousBlock === undefined) {
|
|
142
163
|
// We should be able to get the required previous block
|
|
@@ -181,19 +202,22 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
181
202
|
await this.#checkpoints.set(checkpoint.checkpoint.number, {
|
|
182
203
|
header: checkpoint.checkpoint.header.toBuffer(),
|
|
183
204
|
archive: checkpoint.checkpoint.archive.toBuffer(),
|
|
205
|
+
checkpointOutHash: checkpoint.checkpoint.getCheckpointOutHash().toBuffer(),
|
|
184
206
|
l1: checkpoint.l1.toBuffer(),
|
|
185
207
|
attestations: checkpoint.attestations.map((attestation)=>attestation.toBuffer()),
|
|
186
208
|
checkpointNumber: checkpoint.checkpoint.number,
|
|
187
209
|
startBlock: checkpoint.checkpoint.blocks[0].number,
|
|
188
|
-
|
|
210
|
+
blockCount: checkpoint.checkpoint.blocks.length
|
|
189
211
|
});
|
|
212
|
+
// Update slot-to-checkpoint index
|
|
213
|
+
await this.#slotToCheckpoint.set(checkpoint.checkpoint.header.slotNumber, checkpoint.checkpoint.number);
|
|
190
214
|
}
|
|
191
215
|
await this.#lastSynchedL1Block.set(checkpoints[checkpoints.length - 1].l1.blockNumber);
|
|
192
216
|
return true;
|
|
193
217
|
});
|
|
194
218
|
}
|
|
195
219
|
async addBlockToDatabase(block, checkpointNumber, indexWithinCheckpoint) {
|
|
196
|
-
const blockHash =
|
|
220
|
+
const blockHash = await block.hash();
|
|
197
221
|
await this.#blocks.set(block.number, {
|
|
198
222
|
header: block.header.toBuffer(),
|
|
199
223
|
blockHash: blockHash.toBuffer(),
|
|
@@ -228,41 +252,50 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
228
252
|
await this.#blockArchiveIndex.delete(block.archive.root.toString());
|
|
229
253
|
}
|
|
230
254
|
/**
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
|
|
235
|
-
* @returns True if the operation is successful
|
|
236
|
-
*/ async unwindCheckpoints(from, checkpointsToUnwind) {
|
|
255
|
+
* Removes all checkpoints with checkpoint number > checkpointNumber.
|
|
256
|
+
* Also removes ALL blocks (both checkpointed and uncheckpointed) after the last block of the given checkpoint.
|
|
257
|
+
* @param checkpointNumber - Remove all checkpoints strictly after this one.
|
|
258
|
+
*/ async removeCheckpointsAfter(checkpointNumber) {
|
|
237
259
|
return await this.db.transactionAsync(async ()=>{
|
|
238
|
-
const
|
|
239
|
-
if (
|
|
240
|
-
|
|
260
|
+
const latestCheckpointNumber = await this.getLatestCheckpointNumber();
|
|
261
|
+
if (checkpointNumber >= latestCheckpointNumber) {
|
|
262
|
+
this.#log.warn(`No checkpoints to remove after ${checkpointNumber} (latest is ${latestCheckpointNumber})`);
|
|
263
|
+
return {
|
|
264
|
+
blocksRemoved: undefined
|
|
265
|
+
};
|
|
241
266
|
}
|
|
267
|
+
// If the proven checkpoint is beyond the target, update it
|
|
242
268
|
const proven = await this.getProvenCheckpointNumber();
|
|
243
|
-
if (
|
|
244
|
-
|
|
269
|
+
if (proven > checkpointNumber) {
|
|
270
|
+
this.#log.warn(`Updating proven checkpoint ${proven} to last valid checkpoint ${checkpointNumber}`);
|
|
271
|
+
await this.setProvenCheckpointNumber(checkpointNumber);
|
|
245
272
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
273
|
+
// Find the last block number to keep (last block of the given checkpoint, or 0 if no checkpoint)
|
|
274
|
+
let lastBlockToKeep;
|
|
275
|
+
if (checkpointNumber <= 0) {
|
|
276
|
+
lastBlockToKeep = BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
|
|
277
|
+
} else {
|
|
278
|
+
const targetCheckpoint = await this.#checkpoints.getAsync(checkpointNumber);
|
|
279
|
+
if (!targetCheckpoint) {
|
|
280
|
+
throw new Error(`Target checkpoint ${checkpointNumber} not found in store`);
|
|
252
281
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
this.#
|
|
282
|
+
lastBlockToKeep = BlockNumber(targetCheckpoint.startBlock + targetCheckpoint.blockCount - 1);
|
|
283
|
+
}
|
|
284
|
+
// Remove all blocks after lastBlockToKeep (both checkpointed and uncheckpointed)
|
|
285
|
+
const blocksRemoved = await this.removeBlocksAfter(lastBlockToKeep);
|
|
286
|
+
// Remove all checkpoints after the target
|
|
287
|
+
for(let c = latestCheckpointNumber; c > checkpointNumber; c = CheckpointNumber(c - 1)){
|
|
288
|
+
const checkpointStorage = await this.#checkpoints.getAsync(c);
|
|
289
|
+
if (checkpointStorage) {
|
|
290
|
+
const slotNumber = CheckpointHeader.fromBuffer(checkpointStorage.header).slotNumber;
|
|
291
|
+
await this.#slotToCheckpoint.delete(slotNumber);
|
|
263
292
|
}
|
|
293
|
+
await this.#checkpoints.delete(c);
|
|
294
|
+
this.#log.debug(`Removed checkpoint ${c}`);
|
|
264
295
|
}
|
|
265
|
-
return
|
|
296
|
+
return {
|
|
297
|
+
blocksRemoved
|
|
298
|
+
};
|
|
266
299
|
});
|
|
267
300
|
}
|
|
268
301
|
async getCheckpointData(checkpointNumber) {
|
|
@@ -283,17 +316,30 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
283
316
|
}
|
|
284
317
|
return checkpoints;
|
|
285
318
|
}
|
|
319
|
+
/** Returns checkpoint data for all checkpoints whose slot falls within the given range (inclusive). */ async getCheckpointDataForSlotRange(startSlot, endSlot) {
|
|
320
|
+
const result = [];
|
|
321
|
+
for await (const [, checkpointNumber] of this.#slotToCheckpoint.entriesAsync({
|
|
322
|
+
start: startSlot,
|
|
323
|
+
end: endSlot + 1
|
|
324
|
+
})){
|
|
325
|
+
const checkpointStorage = await this.#checkpoints.getAsync(checkpointNumber);
|
|
326
|
+
if (checkpointStorage) {
|
|
327
|
+
result.push(this.checkpointDataFromCheckpointStorage(checkpointStorage));
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return result;
|
|
331
|
+
}
|
|
286
332
|
checkpointDataFromCheckpointStorage(checkpointStorage) {
|
|
287
|
-
|
|
333
|
+
return {
|
|
288
334
|
header: CheckpointHeader.fromBuffer(checkpointStorage.header),
|
|
289
335
|
archive: AppendOnlyTreeSnapshot.fromBuffer(checkpointStorage.archive),
|
|
336
|
+
checkpointOutHash: Fr.fromBuffer(checkpointStorage.checkpointOutHash),
|
|
290
337
|
checkpointNumber: CheckpointNumber(checkpointStorage.checkpointNumber),
|
|
291
|
-
startBlock: checkpointStorage.startBlock,
|
|
292
|
-
|
|
338
|
+
startBlock: BlockNumber(checkpointStorage.startBlock),
|
|
339
|
+
blockCount: checkpointStorage.blockCount,
|
|
293
340
|
l1: L1PublishedData.fromBuffer(checkpointStorage.l1),
|
|
294
|
-
attestations: checkpointStorage.attestations
|
|
341
|
+
attestations: checkpointStorage.attestations.map((buf)=>CommitteeAttestation.fromBuffer(buf))
|
|
295
342
|
};
|
|
296
|
-
return data;
|
|
297
343
|
}
|
|
298
344
|
async getBlocksForCheckpoint(checkpointNumber) {
|
|
299
345
|
const checkpoint = await this.#checkpoints.getAsync(checkpointNumber);
|
|
@@ -302,7 +348,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
302
348
|
}
|
|
303
349
|
const blocksForCheckpoint = await toArray(this.#blocks.entriesAsync({
|
|
304
350
|
start: checkpoint.startBlock,
|
|
305
|
-
end: checkpoint.startBlock + checkpoint.
|
|
351
|
+
end: checkpoint.startBlock + checkpoint.blockCount
|
|
306
352
|
}));
|
|
307
353
|
const converted = await Promise.all(blocksForCheckpoint.map((x)=>this.getBlockFromBlockStorage(x[0], x[1])));
|
|
308
354
|
return converted.filter(isDefined);
|
|
@@ -332,9 +378,10 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
332
378
|
}
|
|
333
379
|
/**
|
|
334
380
|
* Removes all blocks with block number > blockNumber.
|
|
381
|
+
* Does not remove any associated checkpoints.
|
|
335
382
|
* @param blockNumber - The block number to remove after.
|
|
336
383
|
* @returns The removed blocks (for event emission).
|
|
337
|
-
*/ async
|
|
384
|
+
*/ async removeBlocksAfter(blockNumber) {
|
|
338
385
|
return await this.db.transactionAsync(async ()=>{
|
|
339
386
|
const removedBlocks = [];
|
|
340
387
|
// Get the latest block number to determine the range
|
|
@@ -362,7 +409,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
362
409
|
if (!checkpointStorage) {
|
|
363
410
|
throw new CheckpointNotFoundError(provenCheckpointNumber);
|
|
364
411
|
} else {
|
|
365
|
-
return BlockNumber(checkpointStorage.startBlock + checkpointStorage.
|
|
412
|
+
return BlockNumber(checkpointStorage.startBlock + checkpointStorage.blockCount - 1);
|
|
366
413
|
}
|
|
367
414
|
}
|
|
368
415
|
async getLatestBlockNumber() {
|
|
@@ -444,6 +491,28 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
444
491
|
}
|
|
445
492
|
}
|
|
446
493
|
/**
|
|
494
|
+
* Gets block metadata (without tx data) by block number.
|
|
495
|
+
* @param blockNumber - The number of the block to return.
|
|
496
|
+
* @returns The requested block data.
|
|
497
|
+
*/ async getBlockData(blockNumber) {
|
|
498
|
+
const blockStorage = await this.#blocks.getAsync(blockNumber);
|
|
499
|
+
if (!blockStorage || !blockStorage.header) {
|
|
500
|
+
return undefined;
|
|
501
|
+
}
|
|
502
|
+
return this.getBlockDataFromBlockStorage(blockStorage);
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Gets block metadata (without tx data) by archive root.
|
|
506
|
+
* @param archive - The archive root of the block to return.
|
|
507
|
+
* @returns The requested block data.
|
|
508
|
+
*/ async getBlockDataByArchive(archive) {
|
|
509
|
+
const blockNumber = await this.#blockArchiveIndex.getAsync(archive.toString());
|
|
510
|
+
if (blockNumber === undefined) {
|
|
511
|
+
return undefined;
|
|
512
|
+
}
|
|
513
|
+
return this.getBlockData(BlockNumber(blockNumber));
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
447
516
|
* Gets an L2 block.
|
|
448
517
|
* @param blockNumber - The number of the block to return.
|
|
449
518
|
* @returns The requested L2 block.
|
|
@@ -533,12 +602,19 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
533
602
|
];
|
|
534
603
|
}
|
|
535
604
|
}
|
|
605
|
+
getBlockDataFromBlockStorage(blockStorage) {
|
|
606
|
+
return {
|
|
607
|
+
header: BlockHeader.fromBuffer(blockStorage.header),
|
|
608
|
+
archive: AppendOnlyTreeSnapshot.fromBuffer(blockStorage.archive),
|
|
609
|
+
blockHash: Fr.fromBuffer(blockStorage.blockHash),
|
|
610
|
+
checkpointNumber: CheckpointNumber(blockStorage.checkpointNumber),
|
|
611
|
+
indexWithinCheckpoint: IndexWithinCheckpoint(blockStorage.indexWithinCheckpoint)
|
|
612
|
+
};
|
|
613
|
+
}
|
|
536
614
|
async getBlockFromBlockStorage(blockNumber, blockStorage) {
|
|
537
|
-
const header =
|
|
538
|
-
|
|
539
|
-
const
|
|
540
|
-
header.setHash(Fr.fromBuffer(blockHash));
|
|
541
|
-
const blockHashString = bufferToHex(blockHash);
|
|
615
|
+
const { header, archive, blockHash, checkpointNumber, indexWithinCheckpoint } = this.getBlockDataFromBlockStorage(blockStorage);
|
|
616
|
+
header.setHash(blockHash);
|
|
617
|
+
const blockHashString = bufferToHex(blockStorage.blockHash);
|
|
542
618
|
const blockTxsBuffer = await this.#blockTxs.getAsync(blockHashString);
|
|
543
619
|
if (blockTxsBuffer === undefined) {
|
|
544
620
|
this.#log.warn(`Could not find body for block ${header.globalVariables.blockNumber} ${blockHash}`);
|
|
@@ -556,7 +632,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
556
632
|
txEffects.push(deserializeIndexedTxEffect(txEffect).data);
|
|
557
633
|
}
|
|
558
634
|
const body = new Body(txEffects);
|
|
559
|
-
const block = new
|
|
635
|
+
const block = new L2Block(archive, header, body, checkpointNumber, indexWithinCheckpoint);
|
|
560
636
|
if (block.number !== blockNumber) {
|
|
561
637
|
throw new Error(`Block number mismatch when retrieving block from archive (expected ${blockNumber} but got ${block.number} with hash ${blockHashString})`);
|
|
562
638
|
}
|
|
@@ -582,7 +658,24 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
582
658
|
if (!txEffect) {
|
|
583
659
|
return undefined;
|
|
584
660
|
}
|
|
585
|
-
|
|
661
|
+
const blockNumber = BlockNumber(txEffect.l2BlockNumber);
|
|
662
|
+
// Use existing archiver methods to determine finalization level
|
|
663
|
+
const [provenBlockNumber, checkpointedBlockNumber, finalizedBlockNumber] = await Promise.all([
|
|
664
|
+
this.getProvenBlockNumber(),
|
|
665
|
+
this.getCheckpointedL2BlockNumber(),
|
|
666
|
+
this.getFinalizedL2BlockNumber()
|
|
667
|
+
]);
|
|
668
|
+
let status;
|
|
669
|
+
if (blockNumber <= finalizedBlockNumber) {
|
|
670
|
+
status = TxStatus.FINALIZED;
|
|
671
|
+
} else if (blockNumber <= provenBlockNumber) {
|
|
672
|
+
status = TxStatus.PROVEN;
|
|
673
|
+
} else if (blockNumber <= checkpointedBlockNumber) {
|
|
674
|
+
status = TxStatus.CHECKPOINTED;
|
|
675
|
+
} else {
|
|
676
|
+
status = TxStatus.PROPOSED;
|
|
677
|
+
}
|
|
678
|
+
return new TxReceipt(txHash, status, TxReceipt.executionResultFromRevertCode(txEffect.data.revertCode), undefined, txEffect.data.transactionFee.toBigInt(), txEffect.l2BlockHash, blockNumber);
|
|
586
679
|
}
|
|
587
680
|
/**
|
|
588
681
|
* Looks up which block included the requested tx effect.
|
|
@@ -615,7 +708,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
615
708
|
if (!checkpoint) {
|
|
616
709
|
return BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
|
|
617
710
|
}
|
|
618
|
-
return BlockNumber(checkpoint.startBlock + checkpoint.
|
|
711
|
+
return BlockNumber(checkpoint.startBlock + checkpoint.blockCount - 1);
|
|
619
712
|
}
|
|
620
713
|
async getLatestL2BlockNumber() {
|
|
621
714
|
const [lastBlockNumber] = await toArray(this.#blocks.keysAsync({
|
|
@@ -15,4 +15,4 @@ export declare class ContractClassStore {
|
|
|
15
15
|
getContractClassIds(): Promise<Fr[]>;
|
|
16
16
|
addFunctions(contractClassId: Fr, newPrivateFunctions: ExecutablePrivateFunctionWithMembershipProof[], newUtilityFunctions: UtilityFunctionWithMembershipProof[]): Promise<boolean>;
|
|
17
17
|
}
|
|
18
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
18
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udHJhY3RfY2xhc3Nfc3RvcmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zdG9yZS9jb250cmFjdF9jbGFzc19zdG9yZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFHcEQsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQWlCLE1BQU0saUJBQWlCLENBQUM7QUFFeEUsT0FBTyxLQUFLLEVBQ1YsbUJBQW1CLEVBRW5CLDRDQUE0QyxFQUM1QyxrQ0FB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E,EACnE,mBAAmB,EAAE,kCAAkC,EAAE,GACxD,OAAO,CAAC,OAAO,CAAC,CAyBlB;CACF"}
|
|
@@ -15,17 +15,21 @@ import { Vector } from '@aztec/stdlib/types';
|
|
|
15
15
|
this.#bytecodeCommitments = db.openMap('archiver_bytecode_commitments');
|
|
16
16
|
}
|
|
17
17
|
async addContractClass(contractClass, bytecodeCommitment, blockNumber) {
|
|
18
|
-
await this
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
await this.db.transactionAsync(async ()=>{
|
|
19
|
+
await this.#contractClasses.setIfNotExists(contractClass.id.toString(), serializeContractClassPublic({
|
|
20
|
+
...contractClass,
|
|
21
|
+
l2BlockNumber: blockNumber
|
|
22
|
+
}));
|
|
23
|
+
await this.#bytecodeCommitments.setIfNotExists(contractClass.id.toString(), bytecodeCommitment.toBuffer());
|
|
24
|
+
});
|
|
23
25
|
}
|
|
24
26
|
async deleteContractClasses(contractClass, blockNumber) {
|
|
25
27
|
const restoredContractClass = await this.#contractClasses.getAsync(contractClass.id.toString());
|
|
26
28
|
if (restoredContractClass && deserializeContractClassPublic(restoredContractClass).l2BlockNumber >= blockNumber) {
|
|
27
|
-
await this
|
|
28
|
-
|
|
29
|
+
await this.db.transactionAsync(async ()=>{
|
|
30
|
+
await this.#contractClasses.delete(contractClass.id.toString());
|
|
31
|
+
await this.#bytecodeCommitments.delete(contractClass.id.toString());
|
|
32
|
+
});
|
|
29
33
|
}
|
|
30
34
|
}
|
|
31
35
|
async getContractClass(id) {
|