@aztec/archiver 0.0.1-commit.7035c9bd6 → 0.0.1-commit.71324e566
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 +6 -4
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +32 -14
- package/dest/config.js +1 -1
- package/dest/errors.d.ts +14 -2
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +18 -2
- package/dest/factory.d.ts +2 -2
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +7 -6
- 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 +4 -2
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +6 -0
- package/dest/modules/data_store_updater.d.ts +5 -7
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +56 -65
- package/dest/modules/instrumentation.d.ts +4 -2
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +17 -6
- package/dest/modules/l1_synchronizer.d.ts +3 -2
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +131 -124
- 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 +39 -4
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +232 -63
- 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 +26 -16
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +29 -16
- 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 +27 -7
- 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 +2 -4
- package/dest/store/message_store.d.ts +3 -3
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +9 -10
- package/dest/test/fake_l1_state.d.ts +9 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +41 -6
- 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 +7 -2
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +28 -3
- package/dest/test/noop_l1_archiver.d.ts +1 -1
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +0 -1
- package/package.json +13 -13
- package/src/archiver.ts +43 -19
- package/src/config.ts +1 -1
- package/src/errors.ts +30 -2
- package/src/factory.ts +12 -7
- package/src/l1/calldata_retriever.ts +2 -1
- package/src/l1/data_retrieval.ts +8 -12
- package/src/modules/data_source_base.ts +15 -1
- package/src/modules/data_store_updater.ts +68 -95
- package/src/modules/instrumentation.ts +19 -7
- package/src/modules/l1_synchronizer.ts +145 -151
- package/src/modules/validation.ts +2 -2
- package/src/store/block_store.ts +301 -74
- 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 +48 -32
- package/src/store/l2_tips_cache.ts +58 -13
- package/src/store/log_store.ts +2 -5
- package/src/store/message_store.ts +10 -12
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +56 -7
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +37 -2
- package/src/test/noop_l1_archiver.ts +0 -1
|
@@ -6,13 +6,13 @@ 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, L2Block, deserializeValidateCheckpointResult, serializeValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
10
|
-
import { L1PublishedData } from '@aztec/stdlib/checkpoint';
|
|
9
|
+
import { BlockHash, Body, CheckpointedL2Block, CommitteeAttestation, L2Block, deserializeValidateCheckpointResult, serializeValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
10
|
+
import { Checkpoint, L1PublishedData } from '@aztec/stdlib/checkpoint';
|
|
11
11
|
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
12
12
|
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
13
13
|
import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
|
|
14
14
|
import { BlockHeader, TxHash, TxReceipt, TxStatus, deserializeIndexedTxEffect, serializeIndexedTxEffect } from '@aztec/stdlib/tx';
|
|
15
|
-
import { BlockAlreadyCheckpointedError, BlockArchiveNotConsistentError, BlockIndexNotSequentialError, BlockNotFoundError, BlockNumberNotSequentialError, CannotOverwriteCheckpointedBlockError, CheckpointNotFoundError, CheckpointNumberNotSequentialError, InitialCheckpointNumberNotSequentialError } from '../errors.js';
|
|
15
|
+
import { BlockAlreadyCheckpointedError, BlockArchiveNotConsistentError, BlockIndexNotSequentialError, BlockNotFoundError, BlockNumberNotSequentialError, CannotOverwriteCheckpointedBlockError, CheckpointNotFoundError, CheckpointNumberNotSequentialError, InitialCheckpointNumberNotSequentialError, ProposedCheckpointNotSequentialError, ProposedCheckpointStaleError } from '../errors.js';
|
|
16
16
|
export { TxReceipt } from '@aztec/stdlib/tx';
|
|
17
17
|
/**
|
|
18
18
|
* LMDB-based block storage for the archiver.
|
|
@@ -30,6 +30,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
30
30
|
/** Index mapping a contract's address (as a string) to its location in a block */ #contractIndex;
|
|
31
31
|
/** Index mapping block hash to block number */ #blockHashIndex;
|
|
32
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;
|
|
33
34
|
#log;
|
|
34
35
|
constructor(db){
|
|
35
36
|
this.db = db;
|
|
@@ -46,6 +47,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
46
47
|
this.#pendingChainValidationStatus = db.openSingleton('archiver_pending_chain_validation_status');
|
|
47
48
|
this.#checkpoints = db.openMap('archiver_checkpoints');
|
|
48
49
|
this.#slotToCheckpoint = db.openMap('archiver_slot_to_checkpoint');
|
|
50
|
+
this.#proposedCheckpoint = db.openSingleton('proposed_checkpoint_data');
|
|
49
51
|
}
|
|
50
52
|
/**
|
|
51
53
|
* Returns the finalized L2 block number. An L2 block is finalized when it was proven
|
|
@@ -75,7 +77,8 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
75
77
|
const blockIndex = block.indexWithinCheckpoint;
|
|
76
78
|
const blockLastArchive = block.header.lastArchive.root;
|
|
77
79
|
// Extract the latest block and checkpoint numbers
|
|
78
|
-
const previousBlockNumber = await this.
|
|
80
|
+
const previousBlockNumber = await this.getLatestL2BlockNumber();
|
|
81
|
+
const proposedCheckpointNumber = await this.getProposedCheckpointNumber();
|
|
79
82
|
const previousCheckpointNumber = await this.getLatestCheckpointNumber();
|
|
80
83
|
// Verify we're not overwriting checkpointed blocks
|
|
81
84
|
const lastCheckpointedBlockNumber = await this.getCheckpointedL2BlockNumber();
|
|
@@ -91,9 +94,18 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
91
94
|
if (!opts.force && previousBlockNumber !== blockNumber - 1) {
|
|
92
95
|
throw new BlockNumberNotSequentialError(blockNumber, previousBlockNumber);
|
|
93
96
|
}
|
|
94
|
-
// The same check as above but for checkpoints
|
|
95
|
-
|
|
96
|
-
|
|
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);
|
|
97
109
|
}
|
|
98
110
|
// Extract the previous block if there is one and see if it is for the same checkpoint or not
|
|
99
111
|
const previousBlockResult = await this.getBlock(previousBlockNumber);
|
|
@@ -118,7 +130,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
118
130
|
});
|
|
119
131
|
}
|
|
120
132
|
/**
|
|
121
|
-
* Append new
|
|
133
|
+
* Append new checkpoints to the store's list.
|
|
122
134
|
* @param checkpoints - The L2 checkpoints to be added to the store.
|
|
123
135
|
* @returns True if the operation is successful.
|
|
124
136
|
*/ async addCheckpoints(checkpoints, opts = {}) {
|
|
@@ -126,32 +138,26 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
126
138
|
return true;
|
|
127
139
|
}
|
|
128
140
|
return await this.db.transactionAsync(async ()=>{
|
|
129
|
-
// Check that the checkpoint immediately before the first block to be added is present in the store.
|
|
130
141
|
const firstCheckpointNumber = checkpoints[0].checkpoint.number;
|
|
131
142
|
const previousCheckpointNumber = await this.getLatestCheckpointNumber();
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
previousCheckpointData = await this.getCheckpointData(previousCheckpointNumber);
|
|
140
|
-
if (previousCheckpointData === undefined) {
|
|
141
|
-
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;
|
|
142
150
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (previousCheckpointData !== undefined) {
|
|
148
|
-
previousBlockNumber = BlockNumber(previousCheckpointData.startBlock + previousCheckpointData.blockCount - 1);
|
|
149
|
-
previousBlock = await this.getBlock(previousBlockNumber);
|
|
150
|
-
if (previousBlock === undefined) {
|
|
151
|
-
// We should be able to get the required previous block
|
|
152
|
-
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);
|
|
153
155
|
}
|
|
156
|
+
} else if (previousCheckpointNumber !== firstCheckpointNumber - 1 && !opts.force) {
|
|
157
|
+
throw new InitialCheckpointNumberNotSequentialError(firstCheckpointNumber, previousCheckpointNumber);
|
|
154
158
|
}
|
|
159
|
+
// Get the last block of the previous checkpoint for archive chaining
|
|
160
|
+
let previousBlock = await this.getPreviousCheckpointBlock(checkpoints[0].checkpoint.number);
|
|
155
161
|
// Iterate over checkpoints array and insert them, checking that the block numbers are sequential.
|
|
156
162
|
let previousCheckpoint = undefined;
|
|
157
163
|
for (const checkpoint of checkpoints){
|
|
@@ -159,33 +165,13 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
159
165
|
throw new CheckpointNumberNotSequentialError(checkpoint.checkpoint.number, previousCheckpoint.checkpoint.number);
|
|
160
166
|
}
|
|
161
167
|
previousCheckpoint = checkpoint;
|
|
162
|
-
//
|
|
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)
|
|
163
171
|
for(let i = 0; i < checkpoint.checkpoint.blocks.length; i++){
|
|
164
|
-
|
|
165
|
-
if (previousBlock) {
|
|
166
|
-
// The blocks should have a sequential block number
|
|
167
|
-
if (previousBlock.number !== block.number - 1) {
|
|
168
|
-
throw new BlockNumberNotSequentialError(block.number, previousBlock.number);
|
|
169
|
-
}
|
|
170
|
-
// If the blocks are for the same checkpoint then they should have sequential indexes
|
|
171
|
-
if (previousBlock.checkpointNumber === block.checkpointNumber && previousBlock.indexWithinCheckpoint !== block.indexWithinCheckpoint - 1) {
|
|
172
|
-
throw new BlockIndexNotSequentialError(block.indexWithinCheckpoint, previousBlock.indexWithinCheckpoint);
|
|
173
|
-
}
|
|
174
|
-
if (!previousBlock.archive.root.equals(block.header.lastArchive.root)) {
|
|
175
|
-
throw new BlockArchiveNotConsistentError(block.number, previousBlock.number, block.header.lastArchive.root, previousBlock.archive.root);
|
|
176
|
-
}
|
|
177
|
-
} else {
|
|
178
|
-
// No previous block, must be block 1 at checkpoint index 0
|
|
179
|
-
if (block.indexWithinCheckpoint !== 0) {
|
|
180
|
-
throw new BlockIndexNotSequentialError(block.indexWithinCheckpoint, undefined);
|
|
181
|
-
}
|
|
182
|
-
if (block.number !== INITIAL_L2_BLOCK_NUM) {
|
|
183
|
-
throw new BlockNumberNotSequentialError(block.number, undefined);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
previousBlock = block;
|
|
187
|
-
await this.addBlockToDatabase(block, checkpoint.checkpoint.number, i);
|
|
172
|
+
await this.addBlockToDatabase(checkpoint.checkpoint.blocks[i], checkpoint.checkpoint.number, i);
|
|
188
173
|
}
|
|
174
|
+
previousBlock = checkpoint.checkpoint.blocks.at(-1);
|
|
189
175
|
// Store the checkpoint in the database
|
|
190
176
|
await this.#checkpoints.set(checkpoint.checkpoint.number, {
|
|
191
177
|
header: checkpoint.checkpoint.header.toBuffer(),
|
|
@@ -200,10 +186,95 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
200
186
|
// Update slot-to-checkpoint index
|
|
201
187
|
await this.#slotToCheckpoint.set(checkpoint.checkpoint.header.slotNumber, checkpoint.checkpoint.number);
|
|
202
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);
|
|
203
192
|
await this.#lastSynchedL1Block.set(checkpoints[checkpoints.length - 1].l1.blockNumber);
|
|
204
193
|
return true;
|
|
205
194
|
});
|
|
206
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
|
+
}
|
|
207
278
|
async addBlockToDatabase(block, checkpointNumber, indexWithinCheckpoint) {
|
|
208
279
|
const blockHash = await block.hash();
|
|
209
280
|
await this.#blocks.set(block.number, {
|
|
@@ -281,6 +352,11 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
281
352
|
await this.#checkpoints.delete(c);
|
|
282
353
|
this.#log.debug(`Removed checkpoint ${c}`);
|
|
283
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
|
+
}
|
|
284
360
|
return {
|
|
285
361
|
blocksRemoved
|
|
286
362
|
};
|
|
@@ -373,7 +449,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
373
449
|
return await this.db.transactionAsync(async ()=>{
|
|
374
450
|
const removedBlocks = [];
|
|
375
451
|
// Get the latest block number to determine the range
|
|
376
|
-
const latestBlockNumber = await this.
|
|
452
|
+
const latestBlockNumber = await this.getLatestL2BlockNumber();
|
|
377
453
|
// Iterate from blockNumber + 1 to latestBlockNumber
|
|
378
454
|
for(let bn = blockNumber + 1; bn <= latestBlockNumber; bn++){
|
|
379
455
|
const block = await this.getBlock(BlockNumber(bn));
|
|
@@ -400,13 +476,6 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
400
476
|
return BlockNumber(checkpointStorage.startBlock + checkpointStorage.blockCount - 1);
|
|
401
477
|
}
|
|
402
478
|
}
|
|
403
|
-
async getLatestBlockNumber() {
|
|
404
|
-
const [latestBlocknumber] = await toArray(this.#blocks.keysAsync({
|
|
405
|
-
reverse: true,
|
|
406
|
-
limit: 1
|
|
407
|
-
}));
|
|
408
|
-
return typeof latestBlocknumber === 'number' ? BlockNumber(latestBlocknumber) : BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
|
|
409
|
-
}
|
|
410
479
|
async getLatestCheckpointNumber() {
|
|
411
480
|
const [latestCheckpointNumber] = await toArray(this.#checkpoints.keysAsync({
|
|
412
481
|
reverse: true,
|
|
@@ -417,6 +486,70 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
417
486
|
}
|
|
418
487
|
return CheckpointNumber(latestCheckpointNumber);
|
|
419
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
|
+
}
|
|
420
553
|
async getCheckpointedBlock(number) {
|
|
421
554
|
const blockStorage = await this.#blocks.getAsync(number);
|
|
422
555
|
if (!blockStorage) {
|
|
@@ -594,7 +727,7 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
594
727
|
return {
|
|
595
728
|
header: BlockHeader.fromBuffer(blockStorage.header),
|
|
596
729
|
archive: AppendOnlyTreeSnapshot.fromBuffer(blockStorage.archive),
|
|
597
|
-
blockHash:
|
|
730
|
+
blockHash: BlockHash.fromBuffer(blockStorage.blockHash),
|
|
598
731
|
checkpointNumber: CheckpointNumber(blockStorage.checkpointNumber),
|
|
599
732
|
indexWithinCheckpoint: IndexWithinCheckpoint(blockStorage.indexWithinCheckpoint)
|
|
600
733
|
};
|
|
@@ -716,6 +849,42 @@ export { TxReceipt } from '@aztec/stdlib/tx';
|
|
|
716
849
|
setSynchedL1BlockNumber(l1BlockNumber) {
|
|
717
850
|
return this.#lastSynchedL1Block.set(l1BlockNumber);
|
|
718
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
|
+
}
|
|
719
888
|
async getProvenCheckpointNumber() {
|
|
720
889
|
const [latestCheckpointNumber, provenCheckpointNumber] = await Promise.all([
|
|
721
890
|
this.getLatestCheckpointNumber(),
|
|
@@ -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"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import { toArray } from '@aztec/foundation/iterable';
|
|
3
3
|
import { BufferReader, numToUInt8, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
|
-
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
5
|
-
import { Vector } from '@aztec/stdlib/types';
|
|
6
4
|
/**
|
|
7
5
|
* LMDB-based contract class storage for the archiver.
|
|
8
6
|
*/ export class ContractClassStore {
|
|
@@ -16,11 +14,15 @@ import { Vector } from '@aztec/stdlib/types';
|
|
|
16
14
|
}
|
|
17
15
|
async addContractClass(contractClass, bytecodeCommitment, blockNumber) {
|
|
18
16
|
await this.db.transactionAsync(async ()=>{
|
|
19
|
-
|
|
17
|
+
const key = contractClass.id.toString();
|
|
18
|
+
if (await this.#contractClasses.hasAsync(key)) {
|
|
19
|
+
throw new Error(`Contract class ${key} already exists, cannot add again at block ${blockNumber}`);
|
|
20
|
+
}
|
|
21
|
+
await this.#contractClasses.set(key, serializeContractClassPublic({
|
|
20
22
|
...contractClass,
|
|
21
23
|
l2BlockNumber: blockNumber
|
|
22
24
|
}));
|
|
23
|
-
await this.#bytecodeCommitments.
|
|
25
|
+
await this.#bytecodeCommitments.set(key, bytecodeCommitment.toBuffer());
|
|
24
26
|
});
|
|
25
27
|
}
|
|
26
28
|
async deleteContractClasses(contractClass, blockNumber) {
|
|
@@ -46,38 +48,9 @@ import { Vector } from '@aztec/stdlib/types';
|
|
|
46
48
|
async getContractClassIds() {
|
|
47
49
|
return (await toArray(this.#contractClasses.keysAsync())).map((key)=>Fr.fromHexString(key));
|
|
48
50
|
}
|
|
49
|
-
async addFunctions(contractClassId, newPrivateFunctions, newUtilityFunctions) {
|
|
50
|
-
await this.db.transactionAsync(async ()=>{
|
|
51
|
-
const existingClassBuffer = await this.#contractClasses.getAsync(contractClassId.toString());
|
|
52
|
-
if (!existingClassBuffer) {
|
|
53
|
-
throw new Error(`Unknown contract class ${contractClassId} when adding private functions to store`);
|
|
54
|
-
}
|
|
55
|
-
const existingClass = deserializeContractClassPublic(existingClassBuffer);
|
|
56
|
-
const { privateFunctions: existingPrivateFns, utilityFunctions: existingUtilityFns } = existingClass;
|
|
57
|
-
const updatedClass = {
|
|
58
|
-
...existingClass,
|
|
59
|
-
privateFunctions: [
|
|
60
|
-
...existingPrivateFns,
|
|
61
|
-
...newPrivateFunctions.filter((newFn)=>!existingPrivateFns.some((f)=>f.selector.equals(newFn.selector)))
|
|
62
|
-
],
|
|
63
|
-
utilityFunctions: [
|
|
64
|
-
...existingUtilityFns,
|
|
65
|
-
...newUtilityFunctions.filter((newFn)=>!existingUtilityFns.some((f)=>f.selector.equals(newFn.selector)))
|
|
66
|
-
]
|
|
67
|
-
};
|
|
68
|
-
await this.#contractClasses.set(contractClassId.toString(), serializeContractClassPublic(updatedClass));
|
|
69
|
-
});
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
51
|
}
|
|
73
52
|
function serializeContractClassPublic(contractClass) {
|
|
74
|
-
return serializeToBuffer(contractClass.l2BlockNumber, numToUInt8(contractClass.version), contractClass.artifactHash, contractClass.
|
|
75
|
-
}
|
|
76
|
-
function serializePrivateFunction(fn) {
|
|
77
|
-
return serializeToBuffer(fn.selector, fn.vkHash, fn.bytecode.length, fn.bytecode, fn.functionMetadataHash, fn.artifactMetadataHash, fn.utilityFunctionsTreeRoot, new Vector(fn.privateFunctionTreeSiblingPath), fn.privateFunctionTreeLeafIndex, new Vector(fn.artifactTreeSiblingPath), fn.artifactTreeLeafIndex);
|
|
78
|
-
}
|
|
79
|
-
function serializeUtilityFunction(fn) {
|
|
80
|
-
return serializeToBuffer(fn.selector, fn.bytecode.length, fn.bytecode, fn.functionMetadataHash, fn.artifactMetadataHash, fn.privateFunctionsArtifactTreeRoot, new Vector(fn.artifactTreeSiblingPath), fn.artifactTreeLeafIndex);
|
|
53
|
+
return serializeToBuffer(contractClass.l2BlockNumber, numToUInt8(contractClass.version), contractClass.artifactHash, contractClass.packedBytecode.length, contractClass.packedBytecode, contractClass.privateFunctionsRoot);
|
|
81
54
|
}
|
|
82
55
|
function deserializeContractClassPublic(buffer) {
|
|
83
56
|
const reader = BufferReader.asReader(buffer);
|
|
@@ -85,40 +58,7 @@ function deserializeContractClassPublic(buffer) {
|
|
|
85
58
|
l2BlockNumber: reader.readNumber(),
|
|
86
59
|
version: reader.readUInt8(),
|
|
87
60
|
artifactHash: reader.readObject(Fr),
|
|
88
|
-
privateFunctions: reader.readVector({
|
|
89
|
-
fromBuffer: deserializePrivateFunction
|
|
90
|
-
}),
|
|
91
|
-
utilityFunctions: reader.readVector({
|
|
92
|
-
fromBuffer: deserializeUtilityFunction
|
|
93
|
-
}),
|
|
94
61
|
packedBytecode: reader.readBuffer(),
|
|
95
62
|
privateFunctionsRoot: reader.readObject(Fr)
|
|
96
63
|
};
|
|
97
64
|
}
|
|
98
|
-
function deserializePrivateFunction(buffer) {
|
|
99
|
-
const reader = BufferReader.asReader(buffer);
|
|
100
|
-
return {
|
|
101
|
-
selector: reader.readObject(FunctionSelector),
|
|
102
|
-
vkHash: reader.readObject(Fr),
|
|
103
|
-
bytecode: reader.readBuffer(),
|
|
104
|
-
functionMetadataHash: reader.readObject(Fr),
|
|
105
|
-
artifactMetadataHash: reader.readObject(Fr),
|
|
106
|
-
utilityFunctionsTreeRoot: reader.readObject(Fr),
|
|
107
|
-
privateFunctionTreeSiblingPath: reader.readVector(Fr),
|
|
108
|
-
privateFunctionTreeLeafIndex: reader.readNumber(),
|
|
109
|
-
artifactTreeSiblingPath: reader.readVector(Fr),
|
|
110
|
-
artifactTreeLeafIndex: reader.readNumber()
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
function deserializeUtilityFunction(buffer) {
|
|
114
|
-
const reader = BufferReader.asReader(buffer);
|
|
115
|
-
return {
|
|
116
|
-
selector: reader.readObject(FunctionSelector),
|
|
117
|
-
bytecode: reader.readBuffer(),
|
|
118
|
-
functionMetadataHash: reader.readObject(Fr),
|
|
119
|
-
artifactMetadataHash: reader.readObject(Fr),
|
|
120
|
-
privateFunctionsArtifactTreeRoot: reader.readObject(Fr),
|
|
121
|
-
artifactTreeSiblingPath: reader.readVector(Fr),
|
|
122
|
-
artifactTreeLeafIndex: reader.readNumber()
|
|
123
|
-
};
|
|
124
|
-
}
|
|
@@ -21,4 +21,4 @@ export declare class ContractInstanceStore {
|
|
|
21
21
|
getContractInstanceDeploymentBlockNumber(address: AztecAddress): Promise<number | undefined>;
|
|
22
22
|
}
|
|
23
23
|
export {};
|
|
24
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
24
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udHJhY3RfaW5zdGFuY2Vfc3RvcmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zdG9yZS9jb250cmFjdF9pbnN0YW5jZV9zdG9yZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUN6RCxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBaUIsTUFBTSxpQkFBaUIsQ0FBQztBQUN4RSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEVBQ0wsS0FBSyxpQ0FBaUMsRUFDdEMsS0FBSywyQkFBMkIsRUFHakMsTUFBTSx3QkFBd0IsQ0FBQztBQUNoQyxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUVsRCxLQUFLLHlCQUF5QixHQUFHLENBQUMsTUFBTSxFQUFFLE1BQU0sQ0FBQyxHQUFHLENBQUMsTUFBTSxFQUFFLE1BQU0sRUFBRSxNQUFNLENBQUMsQ0FBQztBQUU3RTs7R0FFRztBQUNILHFCQUFhLHFCQUFxQjs7SUFLcEIsT0FBTyxDQUFDLEVBQUU7SUFBdEIsWUFBb0IsRUFBRSxFQUFFLGlCQUFpQixFQUl4QztJQUVELG1CQUFtQixDQUFDLGdCQUFnQixFQUFFLDJCQUEyQixFQUFFLFdBQVcsRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQVdyRztJQUVELHNCQUFzQixDQUFDLGdCQUFnQixFQUFFLDJCQUEyQixHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FLbkY7SUFFRCxZQUFZLENBQUMsZUFBZSxFQUFFLFlBQVksRUFBRSxTQUFTLEVBQUUsTUFBTSxFQUFFLFFBQVEsQ0FBQyxFQUFFLE1BQU0sR0FBRyx5QkFBeUIsQ0FNM0c7SUFFRCx5QkFBeUIsQ0FDdkIsc0JBQXNCLEVBQUUsaUNBQWlDLEVBQ3pELFNBQVMsRUFBRSxNQUFNLEVBQ2pCLFFBQVEsRUFBRSxNQUFNLEdBQ2YsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUtmO0lBRUQsNEJBQTRCLENBQzFCLHNCQUFzQixFQUFFLGlDQUFpQyxFQUN6RCxTQUFTLEVBQUUsTUFBTSxFQUNqQixRQUFRLEVBQUUsTUFBTSxHQUNmLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FFZjtJQUVLLGlDQUFpQyxDQUFDLE9BQU8sRUFBRSxZQUFZLEVBQUUsU0FBUyxFQUFFLE1BQU0sRUFBRSxlQUFlLEVBQUUsRUFBRSxHQUFHLE9BQU8sQ0FBQyxFQUFFLENBQUMsQ0FvQmxIO0lBRUssbUJBQW1CLENBQ3ZCLE9BQU8sRUFBRSxZQUFZLEVBQ3JCLFNBQVMsRUFBRSxNQUFNLEdBQ2hCLE9BQU8sQ0FBQywyQkFBMkIsR0FBRyxTQUFTLENBQUMsQ0FhbEQ7SUFFRCx3Q0FBd0MsQ0FBQyxPQUFPLEVBQUUsWUFBWSxHQUFHLE9BQU8sQ0FBQyxNQUFNLEdBQUcsU0FBUyxDQUFDLENBRTNGO0NBQ0YifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract_instance_store.d.ts","sourceRoot":"","sources":["../../src/store/contract_instance_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EACL,KAAK,iCAAiC,EACtC,KAAK,2BAA2B,EAGjC,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,KAAK,yBAAyB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAE7E;;GAEG;AACH,qBAAa,qBAAqB;;IAKpB,OAAO,CAAC,EAAE;IAAtB,YAAoB,EAAE,EAAE,iBAAiB,EAIxC;IAED,mBAAmB,CAAC,gBAAgB,EAAE,2BAA2B,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"contract_instance_store.d.ts","sourceRoot":"","sources":["../../src/store/contract_instance_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EACL,KAAK,iCAAiC,EACtC,KAAK,2BAA2B,EAGjC,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,KAAK,yBAAyB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAE7E;;GAEG;AACH,qBAAa,qBAAqB;;IAKpB,OAAO,CAAC,EAAE;IAAtB,YAAoB,EAAE,EAAE,iBAAiB,EAIxC;IAED,mBAAmB,CAAC,gBAAgB,EAAE,2BAA2B,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAWrG;IAED,sBAAsB,CAAC,gBAAgB,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC,CAKnF;IAED,YAAY,CAAC,eAAe,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,yBAAyB,CAM3G;IAED,yBAAyB,CACvB,sBAAsB,EAAE,iCAAiC,EACzD,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAKf;IAED,4BAA4B,CAC1B,sBAAsB,EAAE,iCAAiC,EACzD,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAEf;IAEK,iCAAiC,CAAC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,CAoBlH;IAEK,mBAAmB,CACvB,OAAO,EAAE,YAAY,EACrB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,2BAA2B,GAAG,SAAS,CAAC,CAalD;IAED,wCAAwC,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAE3F;CACF"}
|
|
@@ -14,8 +14,12 @@ import { SerializableContractInstance, SerializableContractInstanceUpdate } from
|
|
|
14
14
|
}
|
|
15
15
|
addContractInstance(contractInstance, blockNumber) {
|
|
16
16
|
return this.db.transactionAsync(async ()=>{
|
|
17
|
-
|
|
18
|
-
await this.#
|
|
17
|
+
const key = contractInstance.address.toString();
|
|
18
|
+
if (await this.#contractInstances.hasAsync(key)) {
|
|
19
|
+
throw new Error(`Contract instance at ${key} already exists (deployed at block ${await this.#contractInstancePublishedAt.getAsync(key)}), cannot add again at block ${blockNumber}`);
|
|
20
|
+
}
|
|
21
|
+
await this.#contractInstances.set(key, new SerializableContractInstance(contractInstance).toBuffer());
|
|
22
|
+
await this.#contractInstancePublishedAt.set(key, blockNumber);
|
|
19
23
|
});
|
|
20
24
|
}
|
|
21
25
|
deleteContractInstance(contractInstance) {
|