@aztec/archiver 0.0.1-commit.f504929 → 0.0.1-commit.f650c0a5c
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 +12 -6
- package/dest/archiver.d.ts +7 -7
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +60 -22
- package/dest/config.d.ts +3 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +2 -1
- package/dest/errors.d.ts +34 -10
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +45 -16
- package/dest/factory.d.ts +4 -5
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +24 -21
- package/dest/l1/calldata_retriever.d.ts +1 -1
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +2 -1
- package/dest/l1/data_retrieval.d.ts +3 -3
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +14 -15
- package/dest/modules/data_source_base.d.ts +8 -6
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +11 -5
- package/dest/modules/data_store_updater.d.ts +18 -12
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +87 -77
- package/dest/modules/l1_synchronizer.d.ts +4 -2
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +163 -128
- package/dest/modules/validation.d.ts +1 -1
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +2 -2
- package/dest/store/block_store.d.ts +50 -16
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +288 -119
- package/dest/store/contract_class_store.d.ts +2 -3
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +7 -67
- 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 +45 -22
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +57 -27
- package/dest/store/l2_tips_cache.d.ts +2 -1
- package/dest/store/l2_tips_cache.d.ts.map +1 -1
- package/dest/store/l2_tips_cache.js +25 -5
- 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 +93 -16
- 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 +21 -9
- package/dest/test/fake_l1_state.d.ts +16 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +77 -8
- package/dest/test/mock_l1_to_l2_message_source.d.ts +1 -1
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +2 -1
- package/dest/test/mock_l2_block_source.d.ts +10 -4
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +35 -7
- 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 -2
- package/package.json +13 -13
- package/src/archiver.ts +73 -27
- package/src/config.ts +8 -1
- package/src/errors.ts +70 -26
- package/src/factory.ts +23 -15
- package/src/l1/calldata_retriever.ts +2 -1
- package/src/l1/data_retrieval.ts +8 -12
- package/src/modules/data_source_base.ts +26 -7
- package/src/modules/data_store_updater.ts +96 -107
- package/src/modules/l1_synchronizer.ts +182 -157
- package/src/modules/validation.ts +2 -2
- package/src/store/block_store.ts +370 -140
- package/src/store/contract_class_store.ts +8 -106
- package/src/store/contract_instance_store.ts +8 -5
- package/src/store/kv_archiver_store.ts +81 -39
- package/src/store/l2_tips_cache.ts +50 -11
- package/src/store/log_store.ts +126 -27
- package/src/store/message_store.ts +27 -10
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +103 -13
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +52 -5
- package/src/test/mock_structs.ts +20 -6
- package/src/test/noop_l1_archiver.ts +7 -2
|
@@ -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,KAAK,SAAS,EACd,SAAS,EAET,mBAAmB,EAEnB,OAAO,EACP,KAAK,wBAAwB,EAG9B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,
|
|
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,CAAC;AAC7B,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,oBAAoB,EAEzB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,m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G,OAAO,CAAC,IAAI,CAAC,CAOjG;CACF"}
|
|
@@ -7,17 +7,17 @@ import { BufferReader } from '@aztec/foundation/serialize';
|
|
|
7
7
|
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
|
-
import { L1PublishedData } from '@aztec/stdlib/checkpoint';
|
|
10
|
+
import { Checkpoint, 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, ProposedCheckpointNotSequentialError, ProposedCheckpointStaleError } 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
23
|
/** Map slot number to checkpoint number, for looking up checkpoints by slot range. */ #slotToCheckpoint;
|
|
@@ -25,14 +25,15 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
25
25
|
/** Tx hash to serialized IndexedTxEffect */ #txEffects;
|
|
26
26
|
/** Stores L1 block number in which the last processed L2 block was included */ #lastSynchedL1Block;
|
|
27
27
|
/** Stores last proven checkpoint */ #lastProvenCheckpoint;
|
|
28
|
+
/** Stores last finalized checkpoint (proven at or before the finalized L1 block) */ #lastFinalizedCheckpoint;
|
|
28
29
|
/** Stores the pending chain validation status */ #pendingChainValidationStatus;
|
|
29
30
|
/** Index mapping a contract's address (as a string) to its location in a block */ #contractIndex;
|
|
30
31
|
/** Index mapping block hash to block number */ #blockHashIndex;
|
|
31
32
|
/** Index mapping block archive to block number */ #blockArchiveIndex;
|
|
33
|
+
/** Singleton: assumes max 1-deep pipeline. For deeper pipelining, replace with a map keyed by checkpoint number. */ #proposedCheckpoint;
|
|
32
34
|
#log;
|
|
33
|
-
constructor(db
|
|
35
|
+
constructor(db){
|
|
34
36
|
this.db = db;
|
|
35
|
-
this.l1Constants = l1Constants;
|
|
36
37
|
this.#log = createLogger('archiver:block_store');
|
|
37
38
|
this.#blocks = db.openMap('archiver_blocks');
|
|
38
39
|
this.#blockTxs = db.openMap('archiver_block_txs');
|
|
@@ -42,95 +43,94 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
42
43
|
this.#blockArchiveIndex = db.openMap('archiver_block_archive_index');
|
|
43
44
|
this.#lastSynchedL1Block = db.openSingleton('archiver_last_synched_l1_block');
|
|
44
45
|
this.#lastProvenCheckpoint = db.openSingleton('archiver_last_proven_l2_checkpoint');
|
|
46
|
+
this.#lastFinalizedCheckpoint = db.openSingleton('archiver_last_finalized_l2_checkpoint');
|
|
45
47
|
this.#pendingChainValidationStatus = db.openSingleton('archiver_pending_chain_validation_status');
|
|
46
48
|
this.#checkpoints = db.openMap('archiver_checkpoints');
|
|
47
49
|
this.#slotToCheckpoint = db.openMap('archiver_slot_to_checkpoint');
|
|
50
|
+
this.#proposedCheckpoint = db.openSingleton('proposed_checkpoint_data');
|
|
48
51
|
}
|
|
49
52
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
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
|
|
53
|
+
* Returns the finalized L2 block number. An L2 block is finalized when it was proven
|
|
54
|
+
* in an L1 block that has itself been finalized on Ethereum.
|
|
54
55
|
* @returns The finalized block number.
|
|
55
56
|
*/ async getFinalizedL2BlockNumber() {
|
|
56
|
-
const
|
|
57
|
-
|
|
57
|
+
const finalizedCheckpointNumber = await this.getFinalizedCheckpointNumber();
|
|
58
|
+
if (finalizedCheckpointNumber === INITIAL_CHECKPOINT_NUMBER - 1) {
|
|
59
|
+
return BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
|
|
60
|
+
}
|
|
61
|
+
const checkpointStorage = await this.#checkpoints.getAsync(finalizedCheckpointNumber);
|
|
62
|
+
if (!checkpointStorage) {
|
|
63
|
+
throw new CheckpointNotFoundError(finalizedCheckpointNumber);
|
|
64
|
+
}
|
|
65
|
+
return BlockNumber(checkpointStorage.startBlock + checkpointStorage.blockCount - 1);
|
|
58
66
|
}
|
|
59
67
|
/**
|
|
60
|
-
* Append new proposed
|
|
61
|
-
*
|
|
68
|
+
* Append a new proposed block to the store.
|
|
69
|
+
* This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
|
|
62
70
|
* For checkpointed blocks (already published to L1), use addCheckpoints() instead.
|
|
63
|
-
* @param
|
|
71
|
+
* @param block - The proposed L2 block to be added to the store.
|
|
64
72
|
* @returns True if the operation is successful.
|
|
65
|
-
*/ async
|
|
66
|
-
if (blocks.length === 0) {
|
|
67
|
-
return true;
|
|
68
|
-
}
|
|
73
|
+
*/ async addProposedBlock(block, opts = {}) {
|
|
69
74
|
return await this.db.transactionAsync(async ()=>{
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
const firstBlockLastArchive = blocks[0].header.lastArchive.root;
|
|
75
|
+
const blockNumber = block.number;
|
|
76
|
+
const blockCheckpointNumber = block.checkpointNumber;
|
|
77
|
+
const blockIndex = block.indexWithinCheckpoint;
|
|
78
|
+
const blockLastArchive = block.header.lastArchive.root;
|
|
75
79
|
// Extract the latest block and checkpoint numbers
|
|
76
|
-
const previousBlockNumber = await this.
|
|
80
|
+
const previousBlockNumber = await this.getLatestL2BlockNumber();
|
|
81
|
+
const proposedCheckpointNumber = await this.getProposedCheckpointNumber();
|
|
77
82
|
const previousCheckpointNumber = await this.getLatestCheckpointNumber();
|
|
78
83
|
// Verify we're not overwriting checkpointed blocks
|
|
79
84
|
const lastCheckpointedBlockNumber = await this.getCheckpointedL2BlockNumber();
|
|
80
|
-
if (!opts.force &&
|
|
81
|
-
|
|
85
|
+
if (!opts.force && blockNumber <= lastCheckpointedBlockNumber) {
|
|
86
|
+
// Check if the proposed block matches the already-checkpointed one
|
|
87
|
+
const existingBlock = await this.getBlock(BlockNumber(blockNumber));
|
|
88
|
+
if (existingBlock && existingBlock.archive.root.equals(block.archive.root)) {
|
|
89
|
+
throw new BlockAlreadyCheckpointedError(blockNumber);
|
|
90
|
+
}
|
|
91
|
+
throw new CannotOverwriteCheckpointedBlockError(blockNumber, lastCheckpointedBlockNumber);
|
|
82
92
|
}
|
|
83
|
-
// Check that the
|
|
84
|
-
if (!opts.force && previousBlockNumber !==
|
|
85
|
-
throw new
|
|
93
|
+
// Check that the block number is the expected one
|
|
94
|
+
if (!opts.force && previousBlockNumber !== blockNumber - 1) {
|
|
95
|
+
throw new BlockNumberNotSequentialError(blockNumber, previousBlockNumber);
|
|
86
96
|
}
|
|
87
|
-
// The same check as above but for checkpoints
|
|
88
|
-
|
|
89
|
-
|
|
97
|
+
// The same check as above but for checkpoints. Accept the block if either the confirmed
|
|
98
|
+
// checkpoint or the pending (locally validated but not yet confirmed) checkpoint matches.
|
|
99
|
+
const expectedCheckpointNumber = blockCheckpointNumber - 1;
|
|
100
|
+
if (!opts.force && previousCheckpointNumber !== expectedCheckpointNumber && proposedCheckpointNumber !== expectedCheckpointNumber) {
|
|
101
|
+
const [reported, source] = proposedCheckpointNumber > previousCheckpointNumber ? [
|
|
102
|
+
proposedCheckpointNumber,
|
|
103
|
+
'proposed'
|
|
104
|
+
] : [
|
|
105
|
+
previousCheckpointNumber,
|
|
106
|
+
'confirmed'
|
|
107
|
+
];
|
|
108
|
+
throw new CheckpointNumberNotSequentialError(blockCheckpointNumber, reported, source);
|
|
90
109
|
}
|
|
91
110
|
// Extract the previous block if there is one and see if it is for the same checkpoint or not
|
|
92
111
|
const previousBlockResult = await this.getBlock(previousBlockNumber);
|
|
93
|
-
let
|
|
112
|
+
let expectedBlockIndex = 0;
|
|
94
113
|
let previousBlockIndex = undefined;
|
|
95
114
|
if (previousBlockResult !== undefined) {
|
|
96
|
-
if (previousBlockResult.checkpointNumber ===
|
|
115
|
+
if (previousBlockResult.checkpointNumber === blockCheckpointNumber) {
|
|
97
116
|
// The previous block is for the same checkpoint, therefore our index should follow it
|
|
98
117
|
previousBlockIndex = previousBlockResult.indexWithinCheckpoint;
|
|
99
|
-
|
|
118
|
+
expectedBlockIndex = previousBlockIndex + 1;
|
|
100
119
|
}
|
|
101
|
-
if (!previousBlockResult.archive.root.equals(
|
|
102
|
-
throw new BlockArchiveNotConsistentError(
|
|
120
|
+
if (!previousBlockResult.archive.root.equals(blockLastArchive)) {
|
|
121
|
+
throw new BlockArchiveNotConsistentError(blockNumber, previousBlockResult.number, blockLastArchive, previousBlockResult.archive.root);
|
|
103
122
|
}
|
|
104
123
|
}
|
|
105
|
-
// Now check that the
|
|
106
|
-
if (!opts.force &&
|
|
107
|
-
throw new BlockIndexNotSequentialError(
|
|
108
|
-
}
|
|
109
|
-
// Iterate over blocks array and insert them, checking that the block numbers and indexes are sequential. Also check they are for the correct checkpoint.
|
|
110
|
-
let previousBlock = undefined;
|
|
111
|
-
for (const block of blocks){
|
|
112
|
-
if (!opts.force && previousBlock) {
|
|
113
|
-
if (previousBlock.number + 1 !== block.number) {
|
|
114
|
-
throw new BlockNumberNotSequentialError(block.number, previousBlock.number);
|
|
115
|
-
}
|
|
116
|
-
if (previousBlock.indexWithinCheckpoint + 1 !== block.indexWithinCheckpoint) {
|
|
117
|
-
throw new BlockIndexNotSequentialError(block.indexWithinCheckpoint, previousBlock.indexWithinCheckpoint);
|
|
118
|
-
}
|
|
119
|
-
if (!previousBlock.archive.root.equals(block.header.lastArchive.root)) {
|
|
120
|
-
throw new BlockArchiveNotConsistentError(block.number, previousBlock.number, block.header.lastArchive.root, previousBlock.archive.root);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
if (!opts.force && firstBlockCheckpointNumber !== block.checkpointNumber) {
|
|
124
|
-
throw new CheckpointNumberNotConsistentError(block.checkpointNumber, firstBlockCheckpointNumber);
|
|
125
|
-
}
|
|
126
|
-
previousBlock = block;
|
|
127
|
-
await this.addBlockToDatabase(block, block.checkpointNumber, block.indexWithinCheckpoint);
|
|
124
|
+
// Now check that the block has the expected index value
|
|
125
|
+
if (!opts.force && expectedBlockIndex !== blockIndex) {
|
|
126
|
+
throw new BlockIndexNotSequentialError(blockIndex, previousBlockIndex);
|
|
128
127
|
}
|
|
128
|
+
await this.addBlockToDatabase(block, block.checkpointNumber, block.indexWithinCheckpoint);
|
|
129
129
|
return true;
|
|
130
130
|
});
|
|
131
131
|
}
|
|
132
132
|
/**
|
|
133
|
-
* Append new
|
|
133
|
+
* Append new checkpoints to the store's list.
|
|
134
134
|
* @param checkpoints - The L2 checkpoints to be added to the store.
|
|
135
135
|
* @returns True if the operation is successful.
|
|
136
136
|
*/ async addCheckpoints(checkpoints, opts = {}) {
|
|
@@ -138,32 +138,26 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
138
138
|
return true;
|
|
139
139
|
}
|
|
140
140
|
return await this.db.transactionAsync(async ()=>{
|
|
141
|
-
// Check that the checkpoint immediately before the first block to be added is present in the store.
|
|
142
141
|
const firstCheckpointNumber = checkpoints[0].checkpoint.number;
|
|
143
142
|
const previousCheckpointNumber = await this.getLatestCheckpointNumber();
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
previousCheckpointData = await this.getCheckpointData(previousCheckpointNumber);
|
|
152
|
-
if (previousCheckpointData === undefined) {
|
|
153
|
-
throw new CheckpointNotFoundError(previousCheckpointNumber);
|
|
143
|
+
// Handle already-stored checkpoints at the start of the batch.
|
|
144
|
+
// This can happen after an L1 reorg re-includes a checkpoint in a different L1 block.
|
|
145
|
+
// We accept them if archives match (same content) and update their L1 metadata.
|
|
146
|
+
if (!opts.force && firstCheckpointNumber <= previousCheckpointNumber) {
|
|
147
|
+
checkpoints = await this.skipOrUpdateAlreadyStoredCheckpoints(checkpoints, previousCheckpointNumber);
|
|
148
|
+
if (checkpoints.length === 0) {
|
|
149
|
+
return true;
|
|
154
150
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if (previousCheckpointData !== undefined) {
|
|
160
|
-
previousBlockNumber = BlockNumber(previousCheckpointData.startBlock + previousCheckpointData.blockCount - 1);
|
|
161
|
-
previousBlock = await this.getBlock(previousBlockNumber);
|
|
162
|
-
if (previousBlock === undefined) {
|
|
163
|
-
// We should be able to get the required previous block
|
|
164
|
-
throw new BlockNotFoundError(previousBlockNumber);
|
|
151
|
+
// Re-check sequentiality after skipping
|
|
152
|
+
const newFirstNumber = checkpoints[0].checkpoint.number;
|
|
153
|
+
if (previousCheckpointNumber !== newFirstNumber - 1) {
|
|
154
|
+
throw new InitialCheckpointNumberNotSequentialError(newFirstNumber, previousCheckpointNumber);
|
|
165
155
|
}
|
|
156
|
+
} else if (previousCheckpointNumber !== firstCheckpointNumber - 1 && !opts.force) {
|
|
157
|
+
throw new InitialCheckpointNumberNotSequentialError(firstCheckpointNumber, previousCheckpointNumber);
|
|
166
158
|
}
|
|
159
|
+
// Get the last block of the previous checkpoint for archive chaining
|
|
160
|
+
let previousBlock = await this.getPreviousCheckpointBlock(checkpoints[0].checkpoint.number);
|
|
167
161
|
// Iterate over checkpoints array and insert them, checking that the block numbers are sequential.
|
|
168
162
|
let previousCheckpoint = undefined;
|
|
169
163
|
for (const checkpoint of checkpoints){
|
|
@@ -171,33 +165,13 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
171
165
|
throw new CheckpointNumberNotSequentialError(checkpoint.checkpoint.number, previousCheckpoint.checkpoint.number);
|
|
172
166
|
}
|
|
173
167
|
previousCheckpoint = checkpoint;
|
|
174
|
-
//
|
|
168
|
+
// Validate block sequencing, indexes, and archive chaining
|
|
169
|
+
this.validateCheckpointBlocks(checkpoint.checkpoint.blocks, previousBlock);
|
|
170
|
+
// Store every block in the database (may already exist, but L1 data is authoritative)
|
|
175
171
|
for(let i = 0; i < checkpoint.checkpoint.blocks.length; i++){
|
|
176
|
-
|
|
177
|
-
if (previousBlock) {
|
|
178
|
-
// The blocks should have a sequential block number
|
|
179
|
-
if (previousBlock.number !== block.number - 1) {
|
|
180
|
-
throw new BlockNumberNotSequentialError(block.number, previousBlock.number);
|
|
181
|
-
}
|
|
182
|
-
// If the blocks are for the same checkpoint then they should have sequential indexes
|
|
183
|
-
if (previousBlock.checkpointNumber === block.checkpointNumber && previousBlock.indexWithinCheckpoint !== block.indexWithinCheckpoint - 1) {
|
|
184
|
-
throw new BlockIndexNotSequentialError(block.indexWithinCheckpoint, previousBlock.indexWithinCheckpoint);
|
|
185
|
-
}
|
|
186
|
-
if (!previousBlock.archive.root.equals(block.header.lastArchive.root)) {
|
|
187
|
-
throw new BlockArchiveNotConsistentError(block.number, previousBlock.number, block.header.lastArchive.root, previousBlock.archive.root);
|
|
188
|
-
}
|
|
189
|
-
} else {
|
|
190
|
-
// No previous block, must be block 1 at checkpoint index 0
|
|
191
|
-
if (block.indexWithinCheckpoint !== 0) {
|
|
192
|
-
throw new BlockIndexNotSequentialError(block.indexWithinCheckpoint, undefined);
|
|
193
|
-
}
|
|
194
|
-
if (block.number !== INITIAL_L2_BLOCK_NUM) {
|
|
195
|
-
throw new BlockNumberNotSequentialError(block.number, undefined);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
previousBlock = block;
|
|
199
|
-
await this.addBlockToDatabase(block, checkpoint.checkpoint.number, i);
|
|
172
|
+
await this.addBlockToDatabase(checkpoint.checkpoint.blocks[i], checkpoint.checkpoint.number, i);
|
|
200
173
|
}
|
|
174
|
+
previousBlock = checkpoint.checkpoint.blocks.at(-1);
|
|
201
175
|
// Store the checkpoint in the database
|
|
202
176
|
await this.#checkpoints.set(checkpoint.checkpoint.number, {
|
|
203
177
|
header: checkpoint.checkpoint.header.toBuffer(),
|
|
@@ -212,10 +186,95 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
212
186
|
// Update slot-to-checkpoint index
|
|
213
187
|
await this.#slotToCheckpoint.set(checkpoint.checkpoint.header.slotNumber, checkpoint.checkpoint.number);
|
|
214
188
|
}
|
|
189
|
+
// Clear the proposed checkpoint if any of the confirmed checkpoints match or supersede it
|
|
190
|
+
const lastConfirmedCheckpointNumber = checkpoints[checkpoints.length - 1].checkpoint.number;
|
|
191
|
+
await this.clearProposedCheckpointIfSuperseded(lastConfirmedCheckpointNumber);
|
|
215
192
|
await this.#lastSynchedL1Block.set(checkpoints[checkpoints.length - 1].l1.blockNumber);
|
|
216
193
|
return true;
|
|
217
194
|
});
|
|
218
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Handles checkpoints at the start of a batch that are already stored (e.g. due to L1 reorg).
|
|
198
|
+
* Verifies the archive root matches, updates L1 metadata, and returns only the new checkpoints.
|
|
199
|
+
*/ async skipOrUpdateAlreadyStoredCheckpoints(checkpoints, latestStored) {
|
|
200
|
+
let i = 0;
|
|
201
|
+
for(; i < checkpoints.length && checkpoints[i].checkpoint.number <= latestStored; i++){
|
|
202
|
+
const incoming = checkpoints[i];
|
|
203
|
+
const stored = await this.getCheckpointData(incoming.checkpoint.number);
|
|
204
|
+
if (!stored) {
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
// Verify the checkpoint content matches (archive root)
|
|
208
|
+
if (!stored.archive.root.equals(incoming.checkpoint.archive.root)) {
|
|
209
|
+
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}`);
|
|
210
|
+
}
|
|
211
|
+
// Update L1 metadata and attestations for the already-stored checkpoint
|
|
212
|
+
this.#log.warn(`Checkpoint ${incoming.checkpoint.number} already stored, updating L1 info ` + `(L1 block ${stored.l1.blockNumber} -> ${incoming.l1.blockNumber})`);
|
|
213
|
+
await this.#checkpoints.set(incoming.checkpoint.number, {
|
|
214
|
+
header: incoming.checkpoint.header.toBuffer(),
|
|
215
|
+
archive: incoming.checkpoint.archive.toBuffer(),
|
|
216
|
+
checkpointOutHash: incoming.checkpoint.getCheckpointOutHash().toBuffer(),
|
|
217
|
+
l1: incoming.l1.toBuffer(),
|
|
218
|
+
attestations: incoming.attestations.map((a)=>a.toBuffer()),
|
|
219
|
+
checkpointNumber: incoming.checkpoint.number,
|
|
220
|
+
startBlock: incoming.checkpoint.blocks[0].number,
|
|
221
|
+
blockCount: incoming.checkpoint.blocks.length
|
|
222
|
+
});
|
|
223
|
+
// Update the sync point to reflect the new L1 block
|
|
224
|
+
await this.#lastSynchedL1Block.set(incoming.l1.blockNumber);
|
|
225
|
+
}
|
|
226
|
+
return checkpoints.slice(i);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Gets the last block of the checkpoint before the given one.
|
|
230
|
+
* Returns undefined if there is no previous checkpoint (i.e. genesis).
|
|
231
|
+
*/ async getPreviousCheckpointBlock(checkpointNumber) {
|
|
232
|
+
const previousCheckpointNumber = CheckpointNumber(checkpointNumber - 1);
|
|
233
|
+
if (previousCheckpointNumber === INITIAL_CHECKPOINT_NUMBER - 1) {
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
const previousCheckpointData = await this.getCheckpointData(previousCheckpointNumber);
|
|
237
|
+
if (previousCheckpointData === undefined) {
|
|
238
|
+
throw new CheckpointNotFoundError(previousCheckpointNumber);
|
|
239
|
+
}
|
|
240
|
+
const previousBlockNumber = BlockNumber(previousCheckpointData.startBlock + previousCheckpointData.blockCount - 1);
|
|
241
|
+
const previousBlock = await this.getBlock(previousBlockNumber);
|
|
242
|
+
if (previousBlock === undefined) {
|
|
243
|
+
throw new BlockNotFoundError(previousBlockNumber);
|
|
244
|
+
}
|
|
245
|
+
return previousBlock;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Validates that blocks are sequential, have correct indexes, and chain via archive roots.
|
|
249
|
+
* This is the same validation used for both confirmed checkpoints (addCheckpoints) and
|
|
250
|
+
* proposed checkpoints (setProposedCheckpoint).
|
|
251
|
+
*/ validateCheckpointBlocks(blocks, previousBlock) {
|
|
252
|
+
for (const block of blocks){
|
|
253
|
+
if (previousBlock) {
|
|
254
|
+
if (previousBlock.number !== block.number - 1) {
|
|
255
|
+
throw new BlockNumberNotSequentialError(block.number, previousBlock.number);
|
|
256
|
+
}
|
|
257
|
+
if (previousBlock.checkpointNumber === block.checkpointNumber) {
|
|
258
|
+
if (previousBlock.indexWithinCheckpoint !== block.indexWithinCheckpoint - 1) {
|
|
259
|
+
throw new BlockIndexNotSequentialError(block.indexWithinCheckpoint, previousBlock.indexWithinCheckpoint);
|
|
260
|
+
}
|
|
261
|
+
} else if (block.indexWithinCheckpoint !== 0) {
|
|
262
|
+
throw new BlockIndexNotSequentialError(block.indexWithinCheckpoint, previousBlock.indexWithinCheckpoint);
|
|
263
|
+
}
|
|
264
|
+
if (!previousBlock.archive.root.equals(block.header.lastArchive.root)) {
|
|
265
|
+
throw new BlockArchiveNotConsistentError(block.number, previousBlock.number, block.header.lastArchive.root, previousBlock.archive.root);
|
|
266
|
+
}
|
|
267
|
+
} else {
|
|
268
|
+
if (block.indexWithinCheckpoint !== 0) {
|
|
269
|
+
throw new BlockIndexNotSequentialError(block.indexWithinCheckpoint, undefined);
|
|
270
|
+
}
|
|
271
|
+
if (block.number !== INITIAL_L2_BLOCK_NUM) {
|
|
272
|
+
throw new BlockNumberNotSequentialError(block.number, undefined);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
previousBlock = block;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
219
278
|
async addBlockToDatabase(block, checkpointNumber, indexWithinCheckpoint) {
|
|
220
279
|
const blockHash = await block.hash();
|
|
221
280
|
await this.#blocks.set(block.number, {
|
|
@@ -293,6 +352,11 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
293
352
|
await this.#checkpoints.delete(c);
|
|
294
353
|
this.#log.debug(`Removed checkpoint ${c}`);
|
|
295
354
|
}
|
|
355
|
+
// Clear any proposed checkpoint that was orphaned by the removal (its base chain no longer exists)
|
|
356
|
+
const proposedCheckpointNumber = await this.getProposedCheckpointNumber();
|
|
357
|
+
if (proposedCheckpointNumber > checkpointNumber) {
|
|
358
|
+
await this.#proposedCheckpoint.delete();
|
|
359
|
+
}
|
|
296
360
|
return {
|
|
297
361
|
blocksRemoved
|
|
298
362
|
};
|
|
@@ -385,7 +449,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
385
449
|
return await this.db.transactionAsync(async ()=>{
|
|
386
450
|
const removedBlocks = [];
|
|
387
451
|
// Get the latest block number to determine the range
|
|
388
|
-
const latestBlockNumber = await this.
|
|
452
|
+
const latestBlockNumber = await this.getLatestL2BlockNumber();
|
|
389
453
|
// Iterate from blockNumber + 1 to latestBlockNumber
|
|
390
454
|
for(let bn = blockNumber + 1; bn <= latestBlockNumber; bn++){
|
|
391
455
|
const block = await this.getBlock(BlockNumber(bn));
|
|
@@ -412,13 +476,6 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
412
476
|
return BlockNumber(checkpointStorage.startBlock + checkpointStorage.blockCount - 1);
|
|
413
477
|
}
|
|
414
478
|
}
|
|
415
|
-
async getLatestBlockNumber() {
|
|
416
|
-
const [latestBlocknumber] = await toArray(this.#blocks.keysAsync({
|
|
417
|
-
reverse: true,
|
|
418
|
-
limit: 1
|
|
419
|
-
}));
|
|
420
|
-
return typeof latestBlocknumber === 'number' ? BlockNumber(latestBlocknumber) : BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
|
|
421
|
-
}
|
|
422
479
|
async getLatestCheckpointNumber() {
|
|
423
480
|
const [latestCheckpointNumber] = await toArray(this.#checkpoints.keysAsync({
|
|
424
481
|
reverse: true,
|
|
@@ -429,6 +486,70 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
429
486
|
}
|
|
430
487
|
return CheckpointNumber(latestCheckpointNumber);
|
|
431
488
|
}
|
|
489
|
+
async hasProposedCheckpoint() {
|
|
490
|
+
const proposed = await this.#proposedCheckpoint.getAsync();
|
|
491
|
+
return proposed !== undefined;
|
|
492
|
+
}
|
|
493
|
+
/** Deletes the proposed checkpoint from storage. */ async deleteProposedCheckpoint() {
|
|
494
|
+
await this.#proposedCheckpoint.delete();
|
|
495
|
+
}
|
|
496
|
+
/** Clears the proposed checkpoint if the given confirmed checkpoint number supersedes it. */ async clearProposedCheckpointIfSuperseded(confirmedCheckpointNumber) {
|
|
497
|
+
const proposedCheckpointNumber = await this.getProposedCheckpointNumber();
|
|
498
|
+
if (proposedCheckpointNumber <= confirmedCheckpointNumber) {
|
|
499
|
+
await this.#proposedCheckpoint.delete();
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
/** Returns the proposed checkpoint data, or undefined if no proposed checkpoint exists. No fallback to confirmed. */ async getProposedCheckpointOnly() {
|
|
503
|
+
const stored = await this.#proposedCheckpoint.getAsync();
|
|
504
|
+
if (!stored) {
|
|
505
|
+
return undefined;
|
|
506
|
+
}
|
|
507
|
+
return this.convertToProposedCheckpointData(stored);
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Gets the checkpoint at the proposed tip
|
|
511
|
+
* - pending checkpoint if it exists
|
|
512
|
+
* - fallsback to latest confirmed checkpoint otherwise
|
|
513
|
+
* @returns CommonCheckpointData
|
|
514
|
+
*/ async getProposedCheckpoint() {
|
|
515
|
+
const stored = await this.#proposedCheckpoint.getAsync();
|
|
516
|
+
if (!stored) {
|
|
517
|
+
return this.getCheckpointData(await this.getLatestCheckpointNumber());
|
|
518
|
+
}
|
|
519
|
+
return this.convertToProposedCheckpointData(stored);
|
|
520
|
+
}
|
|
521
|
+
convertToProposedCheckpointData(stored) {
|
|
522
|
+
return {
|
|
523
|
+
checkpointNumber: CheckpointNumber(stored.checkpointNumber),
|
|
524
|
+
header: CheckpointHeader.fromBuffer(stored.header),
|
|
525
|
+
archive: AppendOnlyTreeSnapshot.fromBuffer(stored.archive),
|
|
526
|
+
checkpointOutHash: Fr.fromBuffer(stored.checkpointOutHash),
|
|
527
|
+
startBlock: BlockNumber(stored.startBlock),
|
|
528
|
+
blockCount: stored.blockCount,
|
|
529
|
+
totalManaUsed: BigInt(stored.totalManaUsed),
|
|
530
|
+
feeAssetPriceModifier: BigInt(stored.feeAssetPriceModifier)
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Attempts to get the proposedCheckpoint's number, if there is not one, then fallback to the latest confirmed checkpoint number.
|
|
535
|
+
* @returns CheckpointNumber
|
|
536
|
+
*/ async getProposedCheckpointNumber() {
|
|
537
|
+
const proposed = await this.getProposedCheckpoint();
|
|
538
|
+
if (!proposed) {
|
|
539
|
+
return await this.getLatestCheckpointNumber();
|
|
540
|
+
}
|
|
541
|
+
return CheckpointNumber(proposed.checkpointNumber);
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Attempts to get the proposedCheckpoint's block number, if there is not one, then fallback to the checkpointed block number
|
|
545
|
+
* @returns BlockNumber
|
|
546
|
+
*/ async getProposedCheckpointL2BlockNumber() {
|
|
547
|
+
const proposed = await this.getProposedCheckpoint();
|
|
548
|
+
if (!proposed) {
|
|
549
|
+
return await this.getCheckpointedL2BlockNumber();
|
|
550
|
+
}
|
|
551
|
+
return BlockNumber(proposed.startBlock + proposed.blockCount - 1);
|
|
552
|
+
}
|
|
432
553
|
async getCheckpointedBlock(number) {
|
|
433
554
|
const blockStorage = await this.#blocks.getAsync(number);
|
|
434
555
|
if (!blockStorage) {
|
|
@@ -653,17 +774,18 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
653
774
|
* Gets a receipt of a settled tx.
|
|
654
775
|
* @param txHash - The hash of a tx we try to get the receipt for.
|
|
655
776
|
* @returns The requested tx receipt (or undefined if not found).
|
|
656
|
-
*/ async getSettledTxReceipt(txHash) {
|
|
777
|
+
*/ async getSettledTxReceipt(txHash, l1Constants) {
|
|
657
778
|
const txEffect = await this.getTxEffect(txHash);
|
|
658
779
|
if (!txEffect) {
|
|
659
780
|
return undefined;
|
|
660
781
|
}
|
|
661
782
|
const blockNumber = BlockNumber(txEffect.l2BlockNumber);
|
|
662
783
|
// Use existing archiver methods to determine finalization level
|
|
663
|
-
const [provenBlockNumber, checkpointedBlockNumber, finalizedBlockNumber] = await Promise.all([
|
|
784
|
+
const [provenBlockNumber, checkpointedBlockNumber, finalizedBlockNumber, blockData] = await Promise.all([
|
|
664
785
|
this.getProvenBlockNumber(),
|
|
665
786
|
this.getCheckpointedL2BlockNumber(),
|
|
666
|
-
this.getFinalizedL2BlockNumber()
|
|
787
|
+
this.getFinalizedL2BlockNumber(),
|
|
788
|
+
this.getBlockData(blockNumber)
|
|
667
789
|
]);
|
|
668
790
|
let status;
|
|
669
791
|
if (blockNumber <= finalizedBlockNumber) {
|
|
@@ -675,7 +797,8 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
675
797
|
} else {
|
|
676
798
|
status = TxStatus.PROPOSED;
|
|
677
799
|
}
|
|
678
|
-
|
|
800
|
+
const epochNumber = blockData && l1Constants ? getEpochAtSlot(blockData.header.globalVariables.slotNumber, l1Constants) : undefined;
|
|
801
|
+
return new TxReceipt(txHash, status, TxReceipt.executionResultFromRevertCode(txEffect.data.revertCode), undefined, txEffect.data.transactionFee.toBigInt(), txEffect.l2BlockHash, blockNumber, epochNumber);
|
|
679
802
|
}
|
|
680
803
|
/**
|
|
681
804
|
* Looks up which block included the requested tx effect.
|
|
@@ -726,6 +849,42 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
726
849
|
setSynchedL1BlockNumber(l1BlockNumber) {
|
|
727
850
|
return this.#lastSynchedL1Block.set(l1BlockNumber);
|
|
728
851
|
}
|
|
852
|
+
/** Sets the proposed checkpoint (not yet L1-confirmed). Only accepts confirmed + 1.
|
|
853
|
+
* Computes archive and checkpointOutHash from the stored blocks. */ async setProposedCheckpoint(proposed) {
|
|
854
|
+
return await this.db.transactionAsync(async ()=>{
|
|
855
|
+
const current = await this.getProposedCheckpointNumber();
|
|
856
|
+
if (proposed.checkpointNumber <= current) {
|
|
857
|
+
throw new ProposedCheckpointStaleError(proposed.checkpointNumber, current);
|
|
858
|
+
}
|
|
859
|
+
const confirmed = await this.getLatestCheckpointNumber();
|
|
860
|
+
if (proposed.checkpointNumber !== confirmed + 1) {
|
|
861
|
+
throw new ProposedCheckpointNotSequentialError(proposed.checkpointNumber, confirmed);
|
|
862
|
+
}
|
|
863
|
+
// Ensure the previous checkpoint + blocks exist
|
|
864
|
+
const previousBlock = await this.getPreviousCheckpointBlock(proposed.checkpointNumber);
|
|
865
|
+
const blocks = [];
|
|
866
|
+
for(let i = 0; i < proposed.blockCount; i++){
|
|
867
|
+
const block = await this.getBlock(BlockNumber(proposed.startBlock + i));
|
|
868
|
+
if (!block) {
|
|
869
|
+
throw new BlockNotFoundError(proposed.startBlock + i);
|
|
870
|
+
}
|
|
871
|
+
blocks.push(block);
|
|
872
|
+
}
|
|
873
|
+
this.validateCheckpointBlocks(blocks, previousBlock);
|
|
874
|
+
const archive = blocks[blocks.length - 1].archive;
|
|
875
|
+
const checkpointOutHash = Checkpoint.getCheckpointOutHash(blocks);
|
|
876
|
+
await this.#proposedCheckpoint.set({
|
|
877
|
+
header: proposed.header.toBuffer(),
|
|
878
|
+
archive: archive.toBuffer(),
|
|
879
|
+
checkpointOutHash: checkpointOutHash.toBuffer(),
|
|
880
|
+
checkpointNumber: proposed.checkpointNumber,
|
|
881
|
+
startBlock: proposed.startBlock,
|
|
882
|
+
blockCount: proposed.blockCount,
|
|
883
|
+
totalManaUsed: proposed.totalManaUsed.toString(),
|
|
884
|
+
feeAssetPriceModifier: proposed.feeAssetPriceModifier.toString()
|
|
885
|
+
});
|
|
886
|
+
});
|
|
887
|
+
}
|
|
729
888
|
async getProvenCheckpointNumber() {
|
|
730
889
|
const [latestCheckpointNumber, provenCheckpointNumber] = await Promise.all([
|
|
731
890
|
this.getLatestCheckpointNumber(),
|
|
@@ -737,6 +896,16 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
737
896
|
const result = await this.#lastProvenCheckpoint.set(checkpointNumber);
|
|
738
897
|
return result;
|
|
739
898
|
}
|
|
899
|
+
async getFinalizedCheckpointNumber() {
|
|
900
|
+
const [latestCheckpointNumber, finalizedCheckpointNumber] = await Promise.all([
|
|
901
|
+
this.getLatestCheckpointNumber(),
|
|
902
|
+
this.#lastFinalizedCheckpoint.getAsync()
|
|
903
|
+
]);
|
|
904
|
+
return (finalizedCheckpointNumber ?? 0) > latestCheckpointNumber ? latestCheckpointNumber : CheckpointNumber(finalizedCheckpointNumber ?? 0);
|
|
905
|
+
}
|
|
906
|
+
setFinalizedCheckpointNumber(checkpointNumber) {
|
|
907
|
+
return this.#lastFinalizedCheckpoint.set(checkpointNumber);
|
|
908
|
+
}
|
|
740
909
|
#computeBlockRange(start, limit) {
|
|
741
910
|
if (limit < 1) {
|
|
742
911
|
throw new Error(`Invalid limit: ${limit}`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
3
|
-
import type { ContractClassPublic
|
|
3
|
+
import type { ContractClassPublic } from '@aztec/stdlib/contract';
|
|
4
4
|
/**
|
|
5
5
|
* LMDB-based contract class storage for the archiver.
|
|
6
6
|
*/
|
|
@@ -13,6 +13,5 @@ export declare class ContractClassStore {
|
|
|
13
13
|
getContractClass(id: Fr): Promise<ContractClassPublic | undefined>;
|
|
14
14
|
getBytecodeCommitment(id: Fr): Promise<Fr | undefined>;
|
|
15
15
|
getContractClassIds(): Promise<Fr[]>;
|
|
16
|
-
addFunctions(contractClassId: Fr, newPrivateFunctions: ExecutablePrivateFunctionWithMembershipProof[], newUtilityFunctions: UtilityFunctionWithMembershipProof[]): Promise<boolean>;
|
|
17
16
|
}
|
|
18
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
17
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udHJhY3RfY2xhc3Nfc3RvcmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zdG9yZS9jb250cmFjdF9jbGFzc19zdG9yZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFHcEQsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQWlCLE1BQU0saUJBQWlCLENBQUM7QUFDeEUsT0FBTyxLQUFLLEVBQUUsbUJBQW1CLEVBQXNDLE1BQU0sd0JBQXdCLENBQUM7QUFFdEc7O0dBRUc7QUFDSCxxQkFBYSxrQkFBa0I7O0lBSWpCLE9BQU8sQ0FBQyxFQUFFO0lBQXRCLFlBQW9CLEVBQUUsRUFBRSxpQkFBaUIsRUFHeEM7SUFFSyxnQkFBZ0IsQ0FDcEIsYUFBYSxFQUFFLG1CQUFtQixFQUNsQyxrQkFBa0IsRUFBRSxFQUFFLEVBQ3RCLFdBQVcsRUFBRSxNQUFNLEdBQ2xCLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FZZjtJQUVLLHFCQUFxQixDQUFDLGFBQWEsRUFBRSxtQkFBbUIsRUFBRSxXQUFXLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FRbEc7SUFFSyxnQkFBZ0IsQ0FBQyxFQUFFLEVBQUUsRUFBRSxHQUFHLE9BQU8sQ0FBQyxtQkFBbUIsR0FBRyxTQUFTLENBQUMsQ0FHdkU7SUFFSyxxQkFBcUIsQ0FBQyxFQUFFLEVBQUUsRUFBRSxHQUFHLE9BQU8sQ0FBQyxFQUFFLEdBQUcsU0FBUyxDQUFDLENBRzNEO0lBRUssbUJBQW1CLElBQUksT0FBTyxDQUFDLEVBQUUsRUFBRSxDQUFDLENBRXpDO0NBQ0YifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract_class_store.d.ts","sourceRoot":"","sources":["../../src/store/contract_class_store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAGpD,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"contract_class_store.d.ts","sourceRoot":"","sources":["../../src/store/contract_class_store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAGpD,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,mBAAmB,EAAsC,MAAM,wBAAwB,CAAC;AAEtG;;GAEG;AACH,qBAAa,kBAAkB;;IAIjB,OAAO,CAAC,EAAE;IAAtB,YAAoB,EAAE,EAAE,iBAAiB,EAGxC;IAEK,gBAAgB,CACpB,aAAa,EAAE,mBAAmB,EAClC,kBAAkB,EAAE,EAAE,EACtB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CAYf;IAEK,qBAAqB,CAAC,aAAa,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQlG;IAEK,gBAAgB,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAGvE;IAEK,qBAAqB,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC,CAG3D;IAEK,mBAAmB,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC,CAEzC;CACF"}
|