@aztec/archiver 0.0.1-commit.8afd444 → 0.0.1-commit.8c0b8ff
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 +73 -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 +31 -24
- 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 +4 -7
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +9 -13
- 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 +113 -40
- package/dest/modules/instrumentation.d.ts +4 -2
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +9 -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 +40 -10
- package/dest/store/block_store.d.ts +30 -26
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +180 -83
- 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 +6 -2
- package/dest/store/contract_instance_store.d.ts +1 -1
- package/dest/store/contract_instance_store.d.ts.map +1 -1
- package/dest/store/contract_instance_store.js +6 -2
- package/dest/store/kv_archiver_store.d.ts +37 -15
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +42 -13
- 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 +103 -45
- package/dest/store/message_store.js +1 -1
- package/dest/test/fake_l1_state.d.ts +20 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +97 -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 +88 -130
- package/src/errors.ts +10 -24
- package/src/factory.ts +45 -21
- 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 +6 -16
- package/src/l1/spire_proposer.ts +7 -15
- package/src/modules/data_source_base.ts +56 -95
- package/src/modules/data_store_updater.ts +123 -43
- package/src/modules/instrumentation.ts +9 -2
- package/src/modules/l1_synchronizer.ts +47 -14
- package/src/store/block_store.ts +219 -110
- package/src/store/contract_class_store.ts +7 -3
- package/src/store/contract_instance_store.ts +8 -5
- package/src/store/kv_archiver_store.ts +66 -20
- package/src/store/l2_tips_cache.ts +89 -0
- package/src/store/log_store.ts +159 -43
- package/src/store/message_store.ts +1 -1
- package/src/test/fake_l1_state.ts +125 -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
|
@@ -2,22 +2,11 @@ import { BlockNumber, CheckpointNumber, SlotNumber } from '@aztec/foundation/bra
|
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
4
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
-
import { BlockHash, CheckpointedL2Block, L2Block, type ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
6
|
-
import {
|
|
7
|
-
import type
|
|
8
|
-
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
9
|
-
import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
|
|
5
|
+
import { type BlockData, BlockHash, CheckpointedL2Block, L2Block, type ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
6
|
+
import { type CheckpointData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
7
|
+
import { type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
10
8
|
import { BlockHeader, type IndexedTxEffect, TxHash, TxReceipt } from '@aztec/stdlib/tx';
|
|
11
9
|
export { TxReceipt, type TxEffect, type TxHash } from '@aztec/stdlib/tx';
|
|
12
|
-
export type CheckpointData = {
|
|
13
|
-
checkpointNumber: CheckpointNumber;
|
|
14
|
-
header: CheckpointHeader;
|
|
15
|
-
archive: AppendOnlyTreeSnapshot;
|
|
16
|
-
startBlock: number;
|
|
17
|
-
numBlocks: number;
|
|
18
|
-
l1: L1PublishedData;
|
|
19
|
-
attestations: Buffer[];
|
|
20
|
-
};
|
|
21
10
|
export type RemoveCheckpointsResult = {
|
|
22
11
|
blocksRemoved: L2Block[] | undefined;
|
|
23
12
|
};
|
|
@@ -27,24 +16,21 @@ export type RemoveCheckpointsResult = {
|
|
|
27
16
|
export declare class BlockStore {
|
|
28
17
|
#private;
|
|
29
18
|
private db;
|
|
30
|
-
|
|
31
|
-
constructor(db: AztecAsyncKVStore, l1Constants: Pick<L1RollupConstants, 'epochDuration'>);
|
|
19
|
+
constructor(db: AztecAsyncKVStore);
|
|
32
20
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* TODO(#13569): Compute proper finalized block number based on L1 finalized block.
|
|
36
|
-
* TODO(palla/mbps): Even the provisional computation is wrong, since it should subtract checkpoints, not blocks
|
|
21
|
+
* Returns the finalized L2 block number. An L2 block is finalized when it was proven
|
|
22
|
+
* in an L1 block that has itself been finalized on Ethereum.
|
|
37
23
|
* @returns The finalized block number.
|
|
38
24
|
*/
|
|
39
25
|
getFinalizedL2BlockNumber(): Promise<BlockNumber>;
|
|
40
26
|
/**
|
|
41
|
-
* Append new proposed
|
|
42
|
-
*
|
|
27
|
+
* Append a new proposed block to the store.
|
|
28
|
+
* This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
|
|
43
29
|
* For checkpointed blocks (already published to L1), use addCheckpoints() instead.
|
|
44
|
-
* @param
|
|
30
|
+
* @param block - The proposed L2 block to be added to the store.
|
|
45
31
|
* @returns True if the operation is successful.
|
|
46
32
|
*/
|
|
47
|
-
|
|
33
|
+
addProposedBlock(block: L2Block, opts?: {
|
|
48
34
|
force?: boolean;
|
|
49
35
|
}): Promise<boolean>;
|
|
50
36
|
/**
|
|
@@ -55,6 +41,7 @@ export declare class BlockStore {
|
|
|
55
41
|
addCheckpoints(checkpoints: PublishedCheckpoint[], opts?: {
|
|
56
42
|
force?: boolean;
|
|
57
43
|
}): Promise<boolean>;
|
|
44
|
+
private skipOrUpdateAlreadyStoredCheckpoints;
|
|
58
45
|
private addBlockToDatabase;
|
|
59
46
|
private deleteBlock;
|
|
60
47
|
/**
|
|
@@ -65,6 +52,8 @@ export declare class BlockStore {
|
|
|
65
52
|
removeCheckpointsAfter(checkpointNumber: CheckpointNumber): Promise<RemoveCheckpointsResult>;
|
|
66
53
|
getCheckpointData(checkpointNumber: CheckpointNumber): Promise<CheckpointData | undefined>;
|
|
67
54
|
getRangeOfCheckpoints(from: CheckpointNumber, limit: number): Promise<CheckpointData[]>;
|
|
55
|
+
/** Returns checkpoint data for all checkpoints whose slot falls within the given range (inclusive). */
|
|
56
|
+
getCheckpointDataForSlotRange(startSlot: SlotNumber, endSlot: SlotNumber): Promise<CheckpointData[]>;
|
|
68
57
|
private checkpointDataFromCheckpointStorage;
|
|
69
58
|
getBlocksForCheckpoint(checkpointNumber: CheckpointNumber): Promise<L2Block[] | undefined>;
|
|
70
59
|
/**
|
|
@@ -101,6 +90,18 @@ export declare class BlockStore {
|
|
|
101
90
|
* @returns The requested L2 blocks
|
|
102
91
|
*/
|
|
103
92
|
getBlocks(start: BlockNumber, limit: number): AsyncIterableIterator<L2Block>;
|
|
93
|
+
/**
|
|
94
|
+
* Gets block metadata (without tx data) by block number.
|
|
95
|
+
* @param blockNumber - The number of the block to return.
|
|
96
|
+
* @returns The requested block data.
|
|
97
|
+
*/
|
|
98
|
+
getBlockData(blockNumber: BlockNumber): Promise<BlockData | undefined>;
|
|
99
|
+
/**
|
|
100
|
+
* Gets block metadata (without tx data) by archive root.
|
|
101
|
+
* @param archive - The archive root of the block to return.
|
|
102
|
+
* @returns The requested block data.
|
|
103
|
+
*/
|
|
104
|
+
getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined>;
|
|
104
105
|
/**
|
|
105
106
|
* Gets an L2 block.
|
|
106
107
|
* @param blockNumber - The number of the block to return.
|
|
@@ -139,6 +140,7 @@ export declare class BlockStore {
|
|
|
139
140
|
*/
|
|
140
141
|
getBlockHeaders(start: BlockNumber, limit: number): AsyncIterableIterator<BlockHeader>;
|
|
141
142
|
private getBlockStorages;
|
|
143
|
+
private getBlockDataFromBlockStorage;
|
|
142
144
|
private getBlockFromBlockStorage;
|
|
143
145
|
/**
|
|
144
146
|
* Gets a tx effect.
|
|
@@ -151,7 +153,7 @@ export declare class BlockStore {
|
|
|
151
153
|
* @param txHash - The hash of a tx we try to get the receipt for.
|
|
152
154
|
* @returns The requested tx receipt (or undefined if not found).
|
|
153
155
|
*/
|
|
154
|
-
getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined>;
|
|
156
|
+
getSettledTxReceipt(txHash: TxHash, l1Constants?: Pick<L1RollupConstants, 'epochDuration'>): Promise<TxReceipt | undefined>;
|
|
155
157
|
/**
|
|
156
158
|
* Looks up which block included the requested tx effect.
|
|
157
159
|
* @param txHash - The txHash of the tx.
|
|
@@ -178,6 +180,8 @@ export declare class BlockStore {
|
|
|
178
180
|
setSynchedL1BlockNumber(l1BlockNumber: bigint): Promise<boolean>;
|
|
179
181
|
getProvenCheckpointNumber(): Promise<CheckpointNumber>;
|
|
180
182
|
setProvenCheckpointNumber(checkpointNumber: CheckpointNumber): Promise<boolean>;
|
|
183
|
+
getFinalizedCheckpointNumber(): Promise<CheckpointNumber>;
|
|
184
|
+
setFinalizedCheckpointNumber(checkpointNumber: CheckpointNumber): Promise<boolean>;
|
|
181
185
|
/**
|
|
182
186
|
* Gets the pending chain validation status.
|
|
183
187
|
* @returns The validation status or undefined if not set.
|
|
@@ -189,4 +193,4 @@ export declare class BlockStore {
|
|
|
189
193
|
*/
|
|
190
194
|
setPendingChainValidationStatus(status: ValidateCheckpointResult | undefined): Promise<void>;
|
|
191
195
|
}
|
|
192
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
196
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmxvY2tfc3RvcmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4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MsQ0FROUQ7SUFFRCw0QkFBNEIsQ0FBQyxnQkFBZ0IsRUFBRSxnQkFBZ0Isb0JBRTlEO0lBY0Q7OztPQUdHO0lBQ0csK0JBQStCLElBQUksT0FBTyxDQUFDLHdCQUF3QixHQUFHLFNBQVMsQ0FBQyxDQU1yRjtJQUVEOzs7T0FHRztJQUNHLCtCQUErQixDQUFDLE1BQU0sRUFBRSx3QkFBd0IsR0FBRyxTQUFTLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQU9qRztDQUNGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block_store.d.ts","sourceRoot":"","sources":["../../src/store/block_store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAyB,UAAU,EAAE,MAAM,iCAAiC,CAAC;AACnH,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAMpD,OAAO,KAAK,EAAE,iBAAiB,EAA6C,MAAM,iBAAiB,CAAC;AACpG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EACL,SAAS,EAET,mBAAmB,EAEnB,OAAO,EACP,KAAK,wBAAwB,EAG9B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"block_store.d.ts","sourceRoot":"","sources":["../../src/store/block_store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAyB,UAAU,EAAE,MAAM,iCAAiC,CAAC;AACnH,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAMpD,OAAO,KAAK,EAAE,iBAAiB,EAA6C,MAAM,iBAAiB,CAAC;AACpG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EACL,KAAK,SAAS,EACd,SAAS,EAET,mBAAmB,EAEnB,OAAO,EACP,KAAK,wBAAwB,EAG9B,MAAM,qBAAqB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CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,CAE5G;IAED;;;OAGG;IACG,4BAA4B,IAAI,OAAO,CAAC,WAAW,CAAC,CAOzD;IAEK,sBAAsB,IAAI,OAAO,CAAC,WAAW,CAAC,CAGnD;IAED;;;OAGG;IACH,uBAAuB,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAErD;IAED,uBAAuB,CAAC,aAAa,EAAE,MAAM,oBAE5C;IAEK,yBAAyB,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAQ3D;IAEK,yBAAyB,CAAC,gBAAgB,EAAE,gBAAgB,oBAGjE;IAEK,4BAA4B,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAQ9D;IAED,4BAA4B,CAAC,gBAAgB,EAAE,gBAAgB,oBAE9D;IAcD;;;OAGG;IACG,+BAA+B,IAAI,OAAO,CAAC,wBAAwB,GAAG,SAAS,CAAC,CAMrF;IAED;;;OAGG;IACG,+BAA+B,CAAC,MAAM,EAAE,wBAAwB,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAOjG;CACF"}
|
|
@@ -8,30 +8,31 @@ import { bufferToHex } from '@aztec/foundation/string';
|
|
|
8
8
|
import { isDefined } from '@aztec/foundation/types';
|
|
9
9
|
import { Body, CheckpointedL2Block, CommitteeAttestation, L2Block, deserializeValidateCheckpointResult, serializeValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
10
10
|
import { L1PublishedData } from '@aztec/stdlib/checkpoint';
|
|
11
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
11
12
|
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
12
13
|
import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
|
|
13
14
|
import { BlockHeader, TxHash, TxReceipt, TxStatus, deserializeIndexedTxEffect, serializeIndexedTxEffect } from '@aztec/stdlib/tx';
|
|
14
|
-
import { BlockArchiveNotConsistentError, BlockIndexNotSequentialError, BlockNotFoundError, BlockNumberNotSequentialError, CannotOverwriteCheckpointedBlockError, CheckpointNotFoundError,
|
|
15
|
+
import { BlockAlreadyCheckpointedError, BlockArchiveNotConsistentError, BlockIndexNotSequentialError, BlockNotFoundError, BlockNumberNotSequentialError, CannotOverwriteCheckpointedBlockError, CheckpointNotFoundError, CheckpointNumberNotSequentialError, InitialCheckpointNumberNotSequentialError } from '../errors.js';
|
|
15
16
|
export { TxReceipt } from '@aztec/stdlib/tx';
|
|
16
17
|
/**
|
|
17
18
|
* LMDB-based block storage for the archiver.
|
|
18
19
|
*/ export class BlockStore {
|
|
19
20
|
db;
|
|
20
|
-
l1Constants;
|
|
21
21
|
/** Map block number to block data */ #blocks;
|
|
22
22
|
/** Map checkpoint number to checkpoint data */ #checkpoints;
|
|
23
|
+
/** Map slot number to checkpoint number, for looking up checkpoints by slot range. */ #slotToCheckpoint;
|
|
23
24
|
/** Map block hash to list of tx hashes */ #blockTxs;
|
|
24
25
|
/** Tx hash to serialized IndexedTxEffect */ #txEffects;
|
|
25
26
|
/** Stores L1 block number in which the last processed L2 block was included */ #lastSynchedL1Block;
|
|
26
27
|
/** Stores last proven checkpoint */ #lastProvenCheckpoint;
|
|
28
|
+
/** Stores last finalized checkpoint (proven at or before the finalized L1 block) */ #lastFinalizedCheckpoint;
|
|
27
29
|
/** Stores the pending chain validation status */ #pendingChainValidationStatus;
|
|
28
30
|
/** Index mapping a contract's address (as a string) to its location in a block */ #contractIndex;
|
|
29
31
|
/** Index mapping block hash to block number */ #blockHashIndex;
|
|
30
32
|
/** Index mapping block archive to block number */ #blockArchiveIndex;
|
|
31
33
|
#log;
|
|
32
|
-
constructor(db
|
|
34
|
+
constructor(db){
|
|
33
35
|
this.db = db;
|
|
34
|
-
this.l1Constants = l1Constants;
|
|
35
36
|
this.#log = createLogger('archiver:block_store');
|
|
36
37
|
this.#blocks = db.openMap('archiver_blocks');
|
|
37
38
|
this.#blockTxs = db.openMap('archiver_block_txs');
|
|
@@ -41,89 +42,78 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
41
42
|
this.#blockArchiveIndex = db.openMap('archiver_block_archive_index');
|
|
42
43
|
this.#lastSynchedL1Block = db.openSingleton('archiver_last_synched_l1_block');
|
|
43
44
|
this.#lastProvenCheckpoint = db.openSingleton('archiver_last_proven_l2_checkpoint');
|
|
45
|
+
this.#lastFinalizedCheckpoint = db.openSingleton('archiver_last_finalized_l2_checkpoint');
|
|
44
46
|
this.#pendingChainValidationStatus = db.openSingleton('archiver_pending_chain_validation_status');
|
|
45
47
|
this.#checkpoints = db.openMap('archiver_checkpoints');
|
|
48
|
+
this.#slotToCheckpoint = db.openMap('archiver_slot_to_checkpoint');
|
|
46
49
|
}
|
|
47
50
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* TODO(#13569): Compute proper finalized block number based on L1 finalized block.
|
|
51
|
-
* TODO(palla/mbps): Even the provisional computation is wrong, since it should subtract checkpoints, not blocks
|
|
51
|
+
* Returns the finalized L2 block number. An L2 block is finalized when it was proven
|
|
52
|
+
* in an L1 block that has itself been finalized on Ethereum.
|
|
52
53
|
* @returns The finalized block number.
|
|
53
54
|
*/ async getFinalizedL2BlockNumber() {
|
|
54
|
-
const
|
|
55
|
-
|
|
55
|
+
const finalizedCheckpointNumber = await this.getFinalizedCheckpointNumber();
|
|
56
|
+
if (finalizedCheckpointNumber === INITIAL_CHECKPOINT_NUMBER - 1) {
|
|
57
|
+
return BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
|
|
58
|
+
}
|
|
59
|
+
const checkpointStorage = await this.#checkpoints.getAsync(finalizedCheckpointNumber);
|
|
60
|
+
if (!checkpointStorage) {
|
|
61
|
+
throw new CheckpointNotFoundError(finalizedCheckpointNumber);
|
|
62
|
+
}
|
|
63
|
+
return BlockNumber(checkpointStorage.startBlock + checkpointStorage.blockCount - 1);
|
|
56
64
|
}
|
|
57
65
|
/**
|
|
58
|
-
* Append new proposed
|
|
59
|
-
*
|
|
66
|
+
* Append a new proposed block to the store.
|
|
67
|
+
* This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
|
|
60
68
|
* For checkpointed blocks (already published to L1), use addCheckpoints() instead.
|
|
61
|
-
* @param
|
|
69
|
+
* @param block - The proposed L2 block to be added to the store.
|
|
62
70
|
* @returns True if the operation is successful.
|
|
63
|
-
*/ async
|
|
64
|
-
if (blocks.length === 0) {
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
71
|
+
*/ async addProposedBlock(block, opts = {}) {
|
|
67
72
|
return await this.db.transactionAsync(async ()=>{
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
const firstBlockLastArchive = blocks[0].header.lastArchive.root;
|
|
73
|
+
const blockNumber = block.number;
|
|
74
|
+
const blockCheckpointNumber = block.checkpointNumber;
|
|
75
|
+
const blockIndex = block.indexWithinCheckpoint;
|
|
76
|
+
const blockLastArchive = block.header.lastArchive.root;
|
|
73
77
|
// Extract the latest block and checkpoint numbers
|
|
74
78
|
const previousBlockNumber = await this.getLatestBlockNumber();
|
|
75
79
|
const previousCheckpointNumber = await this.getLatestCheckpointNumber();
|
|
76
80
|
// Verify we're not overwriting checkpointed blocks
|
|
77
81
|
const lastCheckpointedBlockNumber = await this.getCheckpointedL2BlockNumber();
|
|
78
|
-
if (!opts.force &&
|
|
79
|
-
|
|
82
|
+
if (!opts.force && blockNumber <= lastCheckpointedBlockNumber) {
|
|
83
|
+
// Check if the proposed block matches the already-checkpointed one
|
|
84
|
+
const existingBlock = await this.getBlock(BlockNumber(blockNumber));
|
|
85
|
+
if (existingBlock && existingBlock.archive.root.equals(block.archive.root)) {
|
|
86
|
+
throw new BlockAlreadyCheckpointedError(blockNumber);
|
|
87
|
+
}
|
|
88
|
+
throw new CannotOverwriteCheckpointedBlockError(blockNumber, lastCheckpointedBlockNumber);
|
|
80
89
|
}
|
|
81
|
-
// Check that the
|
|
82
|
-
if (!opts.force && previousBlockNumber !==
|
|
83
|
-
throw new
|
|
90
|
+
// Check that the block number is the expected one
|
|
91
|
+
if (!opts.force && previousBlockNumber !== blockNumber - 1) {
|
|
92
|
+
throw new BlockNumberNotSequentialError(blockNumber, previousBlockNumber);
|
|
84
93
|
}
|
|
85
94
|
// The same check as above but for checkpoints
|
|
86
|
-
if (!opts.force && previousCheckpointNumber !==
|
|
87
|
-
throw new
|
|
95
|
+
if (!opts.force && previousCheckpointNumber !== blockCheckpointNumber - 1) {
|
|
96
|
+
throw new CheckpointNumberNotSequentialError(blockCheckpointNumber, previousCheckpointNumber);
|
|
88
97
|
}
|
|
89
98
|
// Extract the previous block if there is one and see if it is for the same checkpoint or not
|
|
90
99
|
const previousBlockResult = await this.getBlock(previousBlockNumber);
|
|
91
|
-
let
|
|
100
|
+
let expectedBlockIndex = 0;
|
|
92
101
|
let previousBlockIndex = undefined;
|
|
93
102
|
if (previousBlockResult !== undefined) {
|
|
94
|
-
if (previousBlockResult.checkpointNumber ===
|
|
103
|
+
if (previousBlockResult.checkpointNumber === blockCheckpointNumber) {
|
|
95
104
|
// The previous block is for the same checkpoint, therefore our index should follow it
|
|
96
105
|
previousBlockIndex = previousBlockResult.indexWithinCheckpoint;
|
|
97
|
-
|
|
106
|
+
expectedBlockIndex = previousBlockIndex + 1;
|
|
98
107
|
}
|
|
99
|
-
if (!previousBlockResult.archive.root.equals(
|
|
100
|
-
throw new BlockArchiveNotConsistentError(
|
|
108
|
+
if (!previousBlockResult.archive.root.equals(blockLastArchive)) {
|
|
109
|
+
throw new BlockArchiveNotConsistentError(blockNumber, previousBlockResult.number, blockLastArchive, previousBlockResult.archive.root);
|
|
101
110
|
}
|
|
102
111
|
}
|
|
103
|
-
// Now check that the
|
|
104
|
-
if (!opts.force &&
|
|
105
|
-
throw new BlockIndexNotSequentialError(
|
|
106
|
-
}
|
|
107
|
-
// Iterate over blocks array and insert them, checking that the block numbers and indexes are sequential. Also check they are for the correct checkpoint.
|
|
108
|
-
let previousBlock = undefined;
|
|
109
|
-
for (const block of blocks){
|
|
110
|
-
if (!opts.force && previousBlock) {
|
|
111
|
-
if (previousBlock.number + 1 !== block.number) {
|
|
112
|
-
throw new BlockNumberNotSequentialError(block.number, previousBlock.number);
|
|
113
|
-
}
|
|
114
|
-
if (previousBlock.indexWithinCheckpoint + 1 !== block.indexWithinCheckpoint) {
|
|
115
|
-
throw new BlockIndexNotSequentialError(block.indexWithinCheckpoint, previousBlock.indexWithinCheckpoint);
|
|
116
|
-
}
|
|
117
|
-
if (!previousBlock.archive.root.equals(block.header.lastArchive.root)) {
|
|
118
|
-
throw new BlockArchiveNotConsistentError(block.number, previousBlock.number, block.header.lastArchive.root, previousBlock.archive.root);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (!opts.force && firstBlockCheckpointNumber !== block.checkpointNumber) {
|
|
122
|
-
throw new CheckpointNumberNotConsistentError(block.checkpointNumber, firstBlockCheckpointNumber);
|
|
123
|
-
}
|
|
124
|
-
previousBlock = block;
|
|
125
|
-
await this.addBlockToDatabase(block, block.checkpointNumber, block.indexWithinCheckpoint);
|
|
112
|
+
// Now check that the block has the expected index value
|
|
113
|
+
if (!opts.force && expectedBlockIndex !== blockIndex) {
|
|
114
|
+
throw new BlockIndexNotSequentialError(blockIndex, previousBlockIndex);
|
|
126
115
|
}
|
|
116
|
+
await this.addBlockToDatabase(block, block.checkpointNumber, block.indexWithinCheckpoint);
|
|
127
117
|
return true;
|
|
128
118
|
});
|
|
129
119
|
}
|
|
@@ -136,26 +126,39 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
136
126
|
return true;
|
|
137
127
|
}
|
|
138
128
|
return await this.db.transactionAsync(async ()=>{
|
|
139
|
-
// Check that the checkpoint immediately before the first block to be added is present in the store.
|
|
140
129
|
const firstCheckpointNumber = checkpoints[0].checkpoint.number;
|
|
141
130
|
const previousCheckpointNumber = await this.getLatestCheckpointNumber();
|
|
142
|
-
|
|
131
|
+
// Handle already-stored checkpoints at the start of the batch.
|
|
132
|
+
// This can happen after an L1 reorg re-includes a checkpoint in a different L1 block.
|
|
133
|
+
// We accept them if archives match (same content) and update their L1 metadata.
|
|
134
|
+
if (!opts.force && firstCheckpointNumber <= previousCheckpointNumber) {
|
|
135
|
+
checkpoints = await this.skipOrUpdateAlreadyStoredCheckpoints(checkpoints, previousCheckpointNumber);
|
|
136
|
+
if (checkpoints.length === 0) {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
// Re-check sequentiality after skipping
|
|
140
|
+
const newFirstNumber = checkpoints[0].checkpoint.number;
|
|
141
|
+
if (previousCheckpointNumber !== newFirstNumber - 1) {
|
|
142
|
+
throw new InitialCheckpointNumberNotSequentialError(newFirstNumber, previousCheckpointNumber);
|
|
143
|
+
}
|
|
144
|
+
} else if (previousCheckpointNumber !== firstCheckpointNumber - 1 && !opts.force) {
|
|
143
145
|
throw new InitialCheckpointNumberNotSequentialError(firstCheckpointNumber, previousCheckpointNumber);
|
|
144
146
|
}
|
|
145
147
|
// Extract the previous checkpoint if there is one
|
|
148
|
+
const currentFirstCheckpointNumber = checkpoints[0].checkpoint.number;
|
|
146
149
|
let previousCheckpointData = undefined;
|
|
147
|
-
if (
|
|
150
|
+
if (currentFirstCheckpointNumber - 1 !== INITIAL_CHECKPOINT_NUMBER - 1) {
|
|
148
151
|
// There should be a previous checkpoint
|
|
149
|
-
previousCheckpointData = await this.getCheckpointData(
|
|
152
|
+
previousCheckpointData = await this.getCheckpointData(CheckpointNumber(currentFirstCheckpointNumber - 1));
|
|
150
153
|
if (previousCheckpointData === undefined) {
|
|
151
|
-
throw new CheckpointNotFoundError(
|
|
154
|
+
throw new CheckpointNotFoundError(CheckpointNumber(currentFirstCheckpointNumber - 1));
|
|
152
155
|
}
|
|
153
156
|
}
|
|
154
157
|
let previousBlockNumber = undefined;
|
|
155
158
|
let previousBlock = undefined;
|
|
156
159
|
// If we have a previous checkpoint then we need to get the previous block number
|
|
157
160
|
if (previousCheckpointData !== undefined) {
|
|
158
|
-
previousBlockNumber = BlockNumber(previousCheckpointData.startBlock + previousCheckpointData.
|
|
161
|
+
previousBlockNumber = BlockNumber(previousCheckpointData.startBlock + previousCheckpointData.blockCount - 1);
|
|
159
162
|
previousBlock = await this.getBlock(previousBlockNumber);
|
|
160
163
|
if (previousBlock === undefined) {
|
|
161
164
|
// We should be able to get the required previous block
|
|
@@ -200,17 +203,52 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
200
203
|
await this.#checkpoints.set(checkpoint.checkpoint.number, {
|
|
201
204
|
header: checkpoint.checkpoint.header.toBuffer(),
|
|
202
205
|
archive: checkpoint.checkpoint.archive.toBuffer(),
|
|
206
|
+
checkpointOutHash: checkpoint.checkpoint.getCheckpointOutHash().toBuffer(),
|
|
203
207
|
l1: checkpoint.l1.toBuffer(),
|
|
204
208
|
attestations: checkpoint.attestations.map((attestation)=>attestation.toBuffer()),
|
|
205
209
|
checkpointNumber: checkpoint.checkpoint.number,
|
|
206
210
|
startBlock: checkpoint.checkpoint.blocks[0].number,
|
|
207
|
-
|
|
211
|
+
blockCount: checkpoint.checkpoint.blocks.length
|
|
208
212
|
});
|
|
213
|
+
// Update slot-to-checkpoint index
|
|
214
|
+
await this.#slotToCheckpoint.set(checkpoint.checkpoint.header.slotNumber, checkpoint.checkpoint.number);
|
|
209
215
|
}
|
|
210
216
|
await this.#lastSynchedL1Block.set(checkpoints[checkpoints.length - 1].l1.blockNumber);
|
|
211
217
|
return true;
|
|
212
218
|
});
|
|
213
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Handles checkpoints at the start of a batch that are already stored (e.g. due to L1 reorg).
|
|
222
|
+
* Verifies the archive root matches, updates L1 metadata, and returns only the new checkpoints.
|
|
223
|
+
*/ async skipOrUpdateAlreadyStoredCheckpoints(checkpoints, latestStored) {
|
|
224
|
+
let i = 0;
|
|
225
|
+
for(; i < checkpoints.length && checkpoints[i].checkpoint.number <= latestStored; i++){
|
|
226
|
+
const incoming = checkpoints[i];
|
|
227
|
+
const stored = await this.getCheckpointData(incoming.checkpoint.number);
|
|
228
|
+
if (!stored) {
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
// Verify the checkpoint content matches (archive root)
|
|
232
|
+
if (!stored.archive.root.equals(incoming.checkpoint.archive.root)) {
|
|
233
|
+
throw new Error(`Checkpoint ${incoming.checkpoint.number} already exists in store but with a different archive root. ` + `Stored: ${stored.archive.root}, incoming: ${incoming.checkpoint.archive.root}`);
|
|
234
|
+
}
|
|
235
|
+
// Update L1 metadata and attestations for the already-stored checkpoint
|
|
236
|
+
this.#log.warn(`Checkpoint ${incoming.checkpoint.number} already stored, updating L1 info ` + `(L1 block ${stored.l1.blockNumber} -> ${incoming.l1.blockNumber})`);
|
|
237
|
+
await this.#checkpoints.set(incoming.checkpoint.number, {
|
|
238
|
+
header: incoming.checkpoint.header.toBuffer(),
|
|
239
|
+
archive: incoming.checkpoint.archive.toBuffer(),
|
|
240
|
+
checkpointOutHash: incoming.checkpoint.getCheckpointOutHash().toBuffer(),
|
|
241
|
+
l1: incoming.l1.toBuffer(),
|
|
242
|
+
attestations: incoming.attestations.map((a)=>a.toBuffer()),
|
|
243
|
+
checkpointNumber: incoming.checkpoint.number,
|
|
244
|
+
startBlock: incoming.checkpoint.blocks[0].number,
|
|
245
|
+
blockCount: incoming.checkpoint.blocks.length
|
|
246
|
+
});
|
|
247
|
+
// Update the sync point to reflect the new L1 block
|
|
248
|
+
await this.#lastSynchedL1Block.set(incoming.l1.blockNumber);
|
|
249
|
+
}
|
|
250
|
+
return checkpoints.slice(i);
|
|
251
|
+
}
|
|
214
252
|
async addBlockToDatabase(block, checkpointNumber, indexWithinCheckpoint) {
|
|
215
253
|
const blockHash = await block.hash();
|
|
216
254
|
await this.#blocks.set(block.number, {
|
|
@@ -274,12 +312,17 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
274
312
|
if (!targetCheckpoint) {
|
|
275
313
|
throw new Error(`Target checkpoint ${checkpointNumber} not found in store`);
|
|
276
314
|
}
|
|
277
|
-
lastBlockToKeep = BlockNumber(targetCheckpoint.startBlock + targetCheckpoint.
|
|
315
|
+
lastBlockToKeep = BlockNumber(targetCheckpoint.startBlock + targetCheckpoint.blockCount - 1);
|
|
278
316
|
}
|
|
279
317
|
// Remove all blocks after lastBlockToKeep (both checkpointed and uncheckpointed)
|
|
280
318
|
const blocksRemoved = await this.removeBlocksAfter(lastBlockToKeep);
|
|
281
319
|
// Remove all checkpoints after the target
|
|
282
320
|
for(let c = latestCheckpointNumber; c > checkpointNumber; c = CheckpointNumber(c - 1)){
|
|
321
|
+
const checkpointStorage = await this.#checkpoints.getAsync(c);
|
|
322
|
+
if (checkpointStorage) {
|
|
323
|
+
const slotNumber = CheckpointHeader.fromBuffer(checkpointStorage.header).slotNumber;
|
|
324
|
+
await this.#slotToCheckpoint.delete(slotNumber);
|
|
325
|
+
}
|
|
283
326
|
await this.#checkpoints.delete(c);
|
|
284
327
|
this.#log.debug(`Removed checkpoint ${c}`);
|
|
285
328
|
}
|
|
@@ -306,17 +349,30 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
306
349
|
}
|
|
307
350
|
return checkpoints;
|
|
308
351
|
}
|
|
352
|
+
/** Returns checkpoint data for all checkpoints whose slot falls within the given range (inclusive). */ async getCheckpointDataForSlotRange(startSlot, endSlot) {
|
|
353
|
+
const result = [];
|
|
354
|
+
for await (const [, checkpointNumber] of this.#slotToCheckpoint.entriesAsync({
|
|
355
|
+
start: startSlot,
|
|
356
|
+
end: endSlot + 1
|
|
357
|
+
})){
|
|
358
|
+
const checkpointStorage = await this.#checkpoints.getAsync(checkpointNumber);
|
|
359
|
+
if (checkpointStorage) {
|
|
360
|
+
result.push(this.checkpointDataFromCheckpointStorage(checkpointStorage));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return result;
|
|
364
|
+
}
|
|
309
365
|
checkpointDataFromCheckpointStorage(checkpointStorage) {
|
|
310
|
-
|
|
366
|
+
return {
|
|
311
367
|
header: CheckpointHeader.fromBuffer(checkpointStorage.header),
|
|
312
368
|
archive: AppendOnlyTreeSnapshot.fromBuffer(checkpointStorage.archive),
|
|
369
|
+
checkpointOutHash: Fr.fromBuffer(checkpointStorage.checkpointOutHash),
|
|
313
370
|
checkpointNumber: CheckpointNumber(checkpointStorage.checkpointNumber),
|
|
314
|
-
startBlock: checkpointStorage.startBlock,
|
|
315
|
-
|
|
371
|
+
startBlock: BlockNumber(checkpointStorage.startBlock),
|
|
372
|
+
blockCount: checkpointStorage.blockCount,
|
|
316
373
|
l1: L1PublishedData.fromBuffer(checkpointStorage.l1),
|
|
317
|
-
attestations: checkpointStorage.attestations
|
|
374
|
+
attestations: checkpointStorage.attestations.map((buf)=>CommitteeAttestation.fromBuffer(buf))
|
|
318
375
|
};
|
|
319
|
-
return data;
|
|
320
376
|
}
|
|
321
377
|
async getBlocksForCheckpoint(checkpointNumber) {
|
|
322
378
|
const checkpoint = await this.#checkpoints.getAsync(checkpointNumber);
|
|
@@ -325,7 +381,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
325
381
|
}
|
|
326
382
|
const blocksForCheckpoint = await toArray(this.#blocks.entriesAsync({
|
|
327
383
|
start: checkpoint.startBlock,
|
|
328
|
-
end: checkpoint.startBlock + checkpoint.
|
|
384
|
+
end: checkpoint.startBlock + checkpoint.blockCount
|
|
329
385
|
}));
|
|
330
386
|
const converted = await Promise.all(blocksForCheckpoint.map((x)=>this.getBlockFromBlockStorage(x[0], x[1])));
|
|
331
387
|
return converted.filter(isDefined);
|
|
@@ -386,7 +442,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
386
442
|
if (!checkpointStorage) {
|
|
387
443
|
throw new CheckpointNotFoundError(provenCheckpointNumber);
|
|
388
444
|
} else {
|
|
389
|
-
return BlockNumber(checkpointStorage.startBlock + checkpointStorage.
|
|
445
|
+
return BlockNumber(checkpointStorage.startBlock + checkpointStorage.blockCount - 1);
|
|
390
446
|
}
|
|
391
447
|
}
|
|
392
448
|
async getLatestBlockNumber() {
|
|
@@ -468,6 +524,28 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
468
524
|
}
|
|
469
525
|
}
|
|
470
526
|
/**
|
|
527
|
+
* Gets block metadata (without tx data) by block number.
|
|
528
|
+
* @param blockNumber - The number of the block to return.
|
|
529
|
+
* @returns The requested block data.
|
|
530
|
+
*/ async getBlockData(blockNumber) {
|
|
531
|
+
const blockStorage = await this.#blocks.getAsync(blockNumber);
|
|
532
|
+
if (!blockStorage || !blockStorage.header) {
|
|
533
|
+
return undefined;
|
|
534
|
+
}
|
|
535
|
+
return this.getBlockDataFromBlockStorage(blockStorage);
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Gets block metadata (without tx data) by archive root.
|
|
539
|
+
* @param archive - The archive root of the block to return.
|
|
540
|
+
* @returns The requested block data.
|
|
541
|
+
*/ async getBlockDataByArchive(archive) {
|
|
542
|
+
const blockNumber = await this.#blockArchiveIndex.getAsync(archive.toString());
|
|
543
|
+
if (blockNumber === undefined) {
|
|
544
|
+
return undefined;
|
|
545
|
+
}
|
|
546
|
+
return this.getBlockData(BlockNumber(blockNumber));
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
471
549
|
* Gets an L2 block.
|
|
472
550
|
* @param blockNumber - The number of the block to return.
|
|
473
551
|
* @returns The requested L2 block.
|
|
@@ -557,12 +635,19 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
557
635
|
];
|
|
558
636
|
}
|
|
559
637
|
}
|
|
638
|
+
getBlockDataFromBlockStorage(blockStorage) {
|
|
639
|
+
return {
|
|
640
|
+
header: BlockHeader.fromBuffer(blockStorage.header),
|
|
641
|
+
archive: AppendOnlyTreeSnapshot.fromBuffer(blockStorage.archive),
|
|
642
|
+
blockHash: Fr.fromBuffer(blockStorage.blockHash),
|
|
643
|
+
checkpointNumber: CheckpointNumber(blockStorage.checkpointNumber),
|
|
644
|
+
indexWithinCheckpoint: IndexWithinCheckpoint(blockStorage.indexWithinCheckpoint)
|
|
645
|
+
};
|
|
646
|
+
}
|
|
560
647
|
async getBlockFromBlockStorage(blockNumber, blockStorage) {
|
|
561
|
-
const header =
|
|
562
|
-
|
|
563
|
-
const
|
|
564
|
-
header.setHash(Fr.fromBuffer(blockHash));
|
|
565
|
-
const blockHashString = bufferToHex(blockHash);
|
|
648
|
+
const { header, archive, blockHash, checkpointNumber, indexWithinCheckpoint } = this.getBlockDataFromBlockStorage(blockStorage);
|
|
649
|
+
header.setHash(blockHash);
|
|
650
|
+
const blockHashString = bufferToHex(blockStorage.blockHash);
|
|
566
651
|
const blockTxsBuffer = await this.#blockTxs.getAsync(blockHashString);
|
|
567
652
|
if (blockTxsBuffer === undefined) {
|
|
568
653
|
this.#log.warn(`Could not find body for block ${header.globalVariables.blockNumber} ${blockHash}`);
|
|
@@ -580,7 +665,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
580
665
|
txEffects.push(deserializeIndexedTxEffect(txEffect).data);
|
|
581
666
|
}
|
|
582
667
|
const body = new Body(txEffects);
|
|
583
|
-
const block = new L2Block(archive, header, body,
|
|
668
|
+
const block = new L2Block(archive, header, body, checkpointNumber, indexWithinCheckpoint);
|
|
584
669
|
if (block.number !== blockNumber) {
|
|
585
670
|
throw new Error(`Block number mismatch when retrieving block from archive (expected ${blockNumber} but got ${block.number} with hash ${blockHashString})`);
|
|
586
671
|
}
|
|
@@ -601,17 +686,18 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
601
686
|
* Gets a receipt of a settled tx.
|
|
602
687
|
* @param txHash - The hash of a tx we try to get the receipt for.
|
|
603
688
|
* @returns The requested tx receipt (or undefined if not found).
|
|
604
|
-
*/ async getSettledTxReceipt(txHash) {
|
|
689
|
+
*/ async getSettledTxReceipt(txHash, l1Constants) {
|
|
605
690
|
const txEffect = await this.getTxEffect(txHash);
|
|
606
691
|
if (!txEffect) {
|
|
607
692
|
return undefined;
|
|
608
693
|
}
|
|
609
694
|
const blockNumber = BlockNumber(txEffect.l2BlockNumber);
|
|
610
695
|
// Use existing archiver methods to determine finalization level
|
|
611
|
-
const [provenBlockNumber, checkpointedBlockNumber, finalizedBlockNumber] = await Promise.all([
|
|
696
|
+
const [provenBlockNumber, checkpointedBlockNumber, finalizedBlockNumber, blockData] = await Promise.all([
|
|
612
697
|
this.getProvenBlockNumber(),
|
|
613
698
|
this.getCheckpointedL2BlockNumber(),
|
|
614
|
-
this.getFinalizedL2BlockNumber()
|
|
699
|
+
this.getFinalizedL2BlockNumber(),
|
|
700
|
+
this.getBlockData(blockNumber)
|
|
615
701
|
]);
|
|
616
702
|
let status;
|
|
617
703
|
if (blockNumber <= finalizedBlockNumber) {
|
|
@@ -623,7 +709,8 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
623
709
|
} else {
|
|
624
710
|
status = TxStatus.PROPOSED;
|
|
625
711
|
}
|
|
626
|
-
|
|
712
|
+
const epochNumber = blockData && l1Constants ? getEpochAtSlot(blockData.header.globalVariables.slotNumber, l1Constants) : undefined;
|
|
713
|
+
return new TxReceipt(txHash, status, TxReceipt.executionResultFromRevertCode(txEffect.data.revertCode), undefined, txEffect.data.transactionFee.toBigInt(), txEffect.l2BlockHash, blockNumber, epochNumber);
|
|
627
714
|
}
|
|
628
715
|
/**
|
|
629
716
|
* Looks up which block included the requested tx effect.
|
|
@@ -656,7 +743,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
656
743
|
if (!checkpoint) {
|
|
657
744
|
return BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
|
|
658
745
|
}
|
|
659
|
-
return BlockNumber(checkpoint.startBlock + checkpoint.
|
|
746
|
+
return BlockNumber(checkpoint.startBlock + checkpoint.blockCount - 1);
|
|
660
747
|
}
|
|
661
748
|
async getLatestL2BlockNumber() {
|
|
662
749
|
const [lastBlockNumber] = await toArray(this.#blocks.keysAsync({
|
|
@@ -685,6 +772,16 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
685
772
|
const result = await this.#lastProvenCheckpoint.set(checkpointNumber);
|
|
686
773
|
return result;
|
|
687
774
|
}
|
|
775
|
+
async getFinalizedCheckpointNumber() {
|
|
776
|
+
const [latestCheckpointNumber, finalizedCheckpointNumber] = await Promise.all([
|
|
777
|
+
this.getLatestCheckpointNumber(),
|
|
778
|
+
this.#lastFinalizedCheckpoint.getAsync()
|
|
779
|
+
]);
|
|
780
|
+
return (finalizedCheckpointNumber ?? 0) > latestCheckpointNumber ? latestCheckpointNumber : CheckpointNumber(finalizedCheckpointNumber ?? 0);
|
|
781
|
+
}
|
|
782
|
+
setFinalizedCheckpointNumber(checkpointNumber) {
|
|
783
|
+
return this.#lastFinalizedCheckpoint.set(checkpointNumber);
|
|
784
|
+
}
|
|
688
785
|
#computeBlockRange(start, limit) {
|
|
689
786
|
if (limit < 1) {
|
|
690
787
|
throw new Error(`Invalid limit: ${limit}`);
|