@aztec/archiver 0.0.1-commit.d1cd2107c → 0.0.1-commit.d1da697d6
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 +5 -7
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +56 -20
- 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 +3 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +19 -18
- 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 +2 -2
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +13 -14
- 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 +14 -11
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +78 -76
- package/dest/modules/l1_synchronizer.d.ts +4 -3
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +160 -127
- 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 +20 -8
- 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 +9 -4
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +32 -7
- 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 +62 -21
- package/src/config.ts +8 -1
- package/src/errors.ts +70 -26
- package/src/factory.ts +19 -14
- package/src/l1/calldata_retriever.ts +2 -1
- package/src/l1/data_retrieval.ts +7 -11
- package/src/modules/data_source_base.ts +26 -7
- package/src/modules/data_store_updater.ts +91 -107
- package/src/modules/l1_synchronizer.ts +174 -156
- 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 +26 -9
- 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 +46 -5
- package/src/test/noop_l1_archiver.ts +7 -1
package/src/store/block_store.ts
CHANGED
|
@@ -19,8 +19,16 @@ import {
|
|
|
19
19
|
deserializeValidateCheckpointResult,
|
|
20
20
|
serializeValidateCheckpointResult,
|
|
21
21
|
} from '@aztec/stdlib/block';
|
|
22
|
-
import {
|
|
23
|
-
|
|
22
|
+
import {
|
|
23
|
+
Checkpoint,
|
|
24
|
+
type CheckpointData,
|
|
25
|
+
type CommonCheckpointData,
|
|
26
|
+
L1PublishedData,
|
|
27
|
+
type ProposedCheckpointData,
|
|
28
|
+
type ProposedCheckpointInput,
|
|
29
|
+
PublishedCheckpoint,
|
|
30
|
+
} from '@aztec/stdlib/checkpoint';
|
|
31
|
+
import { type L1RollupConstants, getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
24
32
|
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
25
33
|
import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
|
|
26
34
|
import {
|
|
@@ -35,16 +43,17 @@ import {
|
|
|
35
43
|
} from '@aztec/stdlib/tx';
|
|
36
44
|
|
|
37
45
|
import {
|
|
46
|
+
BlockAlreadyCheckpointedError,
|
|
38
47
|
BlockArchiveNotConsistentError,
|
|
39
48
|
BlockIndexNotSequentialError,
|
|
40
49
|
BlockNotFoundError,
|
|
41
50
|
BlockNumberNotSequentialError,
|
|
42
51
|
CannotOverwriteCheckpointedBlockError,
|
|
43
52
|
CheckpointNotFoundError,
|
|
44
|
-
CheckpointNumberNotConsistentError,
|
|
45
53
|
CheckpointNumberNotSequentialError,
|
|
46
|
-
InitialBlockNumberNotSequentialError,
|
|
47
54
|
InitialCheckpointNumberNotSequentialError,
|
|
55
|
+
ProposedCheckpointNotSequentialError,
|
|
56
|
+
ProposedCheckpointStaleError,
|
|
48
57
|
} from '../errors.js';
|
|
49
58
|
|
|
50
59
|
export { TxReceipt, type TxEffect, type TxHash } from '@aztec/stdlib/tx';
|
|
@@ -59,17 +68,27 @@ type BlockStorage = {
|
|
|
59
68
|
indexWithinCheckpoint: number;
|
|
60
69
|
};
|
|
61
70
|
|
|
62
|
-
|
|
71
|
+
/** Checkpoint Storage shared between Checkpoints + Proposed Checkpoints */
|
|
72
|
+
type CommonCheckpointStorage = {
|
|
63
73
|
header: Buffer;
|
|
64
74
|
archive: Buffer;
|
|
65
75
|
checkpointOutHash: Buffer;
|
|
66
76
|
checkpointNumber: number;
|
|
67
77
|
startBlock: number;
|
|
68
78
|
blockCount: number;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
type CheckpointStorage = CommonCheckpointStorage & {
|
|
69
82
|
l1: Buffer;
|
|
70
83
|
attestations: Buffer[];
|
|
71
84
|
};
|
|
72
85
|
|
|
86
|
+
/** Storage format for a proposed checkpoint (attested but not yet L1-confirmed). */
|
|
87
|
+
type ProposedCheckpointStorage = CommonCheckpointStorage & {
|
|
88
|
+
totalManaUsed: string;
|
|
89
|
+
feeAssetPriceModifier: string;
|
|
90
|
+
};
|
|
91
|
+
|
|
73
92
|
export type RemoveCheckpointsResult = { blocksRemoved: L2Block[] | undefined };
|
|
74
93
|
|
|
75
94
|
/**
|
|
@@ -97,6 +116,9 @@ export class BlockStore {
|
|
|
97
116
|
/** Stores last proven checkpoint */
|
|
98
117
|
#lastProvenCheckpoint: AztecAsyncSingleton<number>;
|
|
99
118
|
|
|
119
|
+
/** Stores last finalized checkpoint (proven at or before the finalized L1 block) */
|
|
120
|
+
#lastFinalizedCheckpoint: AztecAsyncSingleton<number>;
|
|
121
|
+
|
|
100
122
|
/** Stores the pending chain validation status */
|
|
101
123
|
#pendingChainValidationStatus: AztecAsyncSingleton<Buffer>;
|
|
102
124
|
|
|
@@ -109,12 +131,12 @@ export class BlockStore {
|
|
|
109
131
|
/** Index mapping block archive to block number */
|
|
110
132
|
#blockArchiveIndex: AztecAsyncMap<string, number>;
|
|
111
133
|
|
|
134
|
+
/** Singleton: assumes max 1-deep pipeline. For deeper pipelining, replace with a map keyed by checkpoint number. */
|
|
135
|
+
#proposedCheckpoint: AztecAsyncSingleton<ProposedCheckpointStorage>;
|
|
136
|
+
|
|
112
137
|
#log = createLogger('archiver:block_store');
|
|
113
138
|
|
|
114
|
-
constructor(
|
|
115
|
-
private db: AztecAsyncKVStore,
|
|
116
|
-
private l1Constants: Pick<L1RollupConstants, 'epochDuration'>,
|
|
117
|
-
) {
|
|
139
|
+
constructor(private db: AztecAsyncKVStore) {
|
|
118
140
|
this.#blocks = db.openMap('archiver_blocks');
|
|
119
141
|
this.#blockTxs = db.openMap('archiver_block_txs');
|
|
120
142
|
this.#txEffects = db.openMap('archiver_tx_effects');
|
|
@@ -123,120 +145,114 @@ export class BlockStore {
|
|
|
123
145
|
this.#blockArchiveIndex = db.openMap('archiver_block_archive_index');
|
|
124
146
|
this.#lastSynchedL1Block = db.openSingleton('archiver_last_synched_l1_block');
|
|
125
147
|
this.#lastProvenCheckpoint = db.openSingleton('archiver_last_proven_l2_checkpoint');
|
|
148
|
+
this.#lastFinalizedCheckpoint = db.openSingleton('archiver_last_finalized_l2_checkpoint');
|
|
126
149
|
this.#pendingChainValidationStatus = db.openSingleton('archiver_pending_chain_validation_status');
|
|
127
150
|
this.#checkpoints = db.openMap('archiver_checkpoints');
|
|
128
151
|
this.#slotToCheckpoint = db.openMap('archiver_slot_to_checkpoint');
|
|
152
|
+
this.#proposedCheckpoint = db.openSingleton('proposed_checkpoint_data');
|
|
129
153
|
}
|
|
130
154
|
|
|
131
155
|
/**
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* TODO(#13569): Compute proper finalized block number based on L1 finalized block.
|
|
135
|
-
* TODO(palla/mbps): Even the provisional computation is wrong, since it should subtract checkpoints, not blocks
|
|
156
|
+
* Returns the finalized L2 block number. An L2 block is finalized when it was proven
|
|
157
|
+
* in an L1 block that has itself been finalized on Ethereum.
|
|
136
158
|
* @returns The finalized block number.
|
|
137
159
|
*/
|
|
138
160
|
async getFinalizedL2BlockNumber(): Promise<BlockNumber> {
|
|
139
|
-
const
|
|
140
|
-
|
|
161
|
+
const finalizedCheckpointNumber = await this.getFinalizedCheckpointNumber();
|
|
162
|
+
if (finalizedCheckpointNumber === INITIAL_CHECKPOINT_NUMBER - 1) {
|
|
163
|
+
return BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
|
|
164
|
+
}
|
|
165
|
+
const checkpointStorage = await this.#checkpoints.getAsync(finalizedCheckpointNumber);
|
|
166
|
+
if (!checkpointStorage) {
|
|
167
|
+
throw new CheckpointNotFoundError(finalizedCheckpointNumber);
|
|
168
|
+
}
|
|
169
|
+
return BlockNumber(checkpointStorage.startBlock + checkpointStorage.blockCount - 1);
|
|
141
170
|
}
|
|
142
171
|
|
|
143
172
|
/**
|
|
144
|
-
* Append new proposed
|
|
145
|
-
*
|
|
173
|
+
* Append a new proposed block to the store.
|
|
174
|
+
* This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
|
|
146
175
|
* For checkpointed blocks (already published to L1), use addCheckpoints() instead.
|
|
147
|
-
* @param
|
|
176
|
+
* @param block - The proposed L2 block to be added to the store.
|
|
148
177
|
* @returns True if the operation is successful.
|
|
149
178
|
*/
|
|
150
|
-
async
|
|
151
|
-
if (blocks.length === 0) {
|
|
152
|
-
return true;
|
|
153
|
-
}
|
|
154
|
-
|
|
179
|
+
async addProposedBlock(block: L2Block, opts: { force?: boolean } = {}): Promise<boolean> {
|
|
155
180
|
return await this.db.transactionAsync(async () => {
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
const
|
|
160
|
-
const firstBlockLastArchive = blocks[0].header.lastArchive.root;
|
|
181
|
+
const blockNumber = block.number;
|
|
182
|
+
const blockCheckpointNumber = block.checkpointNumber;
|
|
183
|
+
const blockIndex = block.indexWithinCheckpoint;
|
|
184
|
+
const blockLastArchive = block.header.lastArchive.root;
|
|
161
185
|
|
|
162
186
|
// Extract the latest block and checkpoint numbers
|
|
163
|
-
const previousBlockNumber = await this.
|
|
187
|
+
const previousBlockNumber = await this.getLatestL2BlockNumber();
|
|
188
|
+
const proposedCheckpointNumber = await this.getProposedCheckpointNumber();
|
|
164
189
|
const previousCheckpointNumber = await this.getLatestCheckpointNumber();
|
|
165
190
|
|
|
166
191
|
// Verify we're not overwriting checkpointed blocks
|
|
167
192
|
const lastCheckpointedBlockNumber = await this.getCheckpointedL2BlockNumber();
|
|
168
|
-
if (!opts.force &&
|
|
169
|
-
|
|
193
|
+
if (!opts.force && blockNumber <= lastCheckpointedBlockNumber) {
|
|
194
|
+
// Check if the proposed block matches the already-checkpointed one
|
|
195
|
+
const existingBlock = await this.getBlock(BlockNumber(blockNumber));
|
|
196
|
+
if (existingBlock && existingBlock.archive.root.equals(block.archive.root)) {
|
|
197
|
+
throw new BlockAlreadyCheckpointedError(blockNumber);
|
|
198
|
+
}
|
|
199
|
+
throw new CannotOverwriteCheckpointedBlockError(blockNumber, lastCheckpointedBlockNumber);
|
|
170
200
|
}
|
|
171
201
|
|
|
172
|
-
// Check that the
|
|
173
|
-
if (!opts.force && previousBlockNumber !==
|
|
174
|
-
throw new
|
|
202
|
+
// Check that the block number is the expected one
|
|
203
|
+
if (!opts.force && previousBlockNumber !== blockNumber - 1) {
|
|
204
|
+
throw new BlockNumberNotSequentialError(blockNumber, previousBlockNumber);
|
|
175
205
|
}
|
|
176
206
|
|
|
177
|
-
// The same check as above but for checkpoints
|
|
178
|
-
|
|
179
|
-
|
|
207
|
+
// The same check as above but for checkpoints. Accept the block if either the confirmed
|
|
208
|
+
// checkpoint or the pending (locally validated but not yet confirmed) checkpoint matches.
|
|
209
|
+
const expectedCheckpointNumber = blockCheckpointNumber - 1;
|
|
210
|
+
if (
|
|
211
|
+
!opts.force &&
|
|
212
|
+
previousCheckpointNumber !== expectedCheckpointNumber &&
|
|
213
|
+
proposedCheckpointNumber !== expectedCheckpointNumber
|
|
214
|
+
) {
|
|
215
|
+
const [reported, source]: [CheckpointNumber, 'confirmed' | 'proposed'] =
|
|
216
|
+
proposedCheckpointNumber > previousCheckpointNumber
|
|
217
|
+
? [proposedCheckpointNumber, 'proposed']
|
|
218
|
+
: [previousCheckpointNumber, 'confirmed'];
|
|
219
|
+
throw new CheckpointNumberNotSequentialError(blockCheckpointNumber, reported, source);
|
|
180
220
|
}
|
|
181
221
|
|
|
182
222
|
// Extract the previous block if there is one and see if it is for the same checkpoint or not
|
|
183
223
|
const previousBlockResult = await this.getBlock(previousBlockNumber);
|
|
184
224
|
|
|
185
|
-
let
|
|
225
|
+
let expectedBlockIndex = 0;
|
|
186
226
|
let previousBlockIndex: number | undefined = undefined;
|
|
187
227
|
if (previousBlockResult !== undefined) {
|
|
188
|
-
if (previousBlockResult.checkpointNumber ===
|
|
228
|
+
if (previousBlockResult.checkpointNumber === blockCheckpointNumber) {
|
|
189
229
|
// The previous block is for the same checkpoint, therefore our index should follow it
|
|
190
230
|
previousBlockIndex = previousBlockResult.indexWithinCheckpoint;
|
|
191
|
-
|
|
231
|
+
expectedBlockIndex = previousBlockIndex + 1;
|
|
192
232
|
}
|
|
193
|
-
if (!previousBlockResult.archive.root.equals(
|
|
233
|
+
if (!previousBlockResult.archive.root.equals(blockLastArchive)) {
|
|
194
234
|
throw new BlockArchiveNotConsistentError(
|
|
195
|
-
|
|
235
|
+
blockNumber,
|
|
196
236
|
previousBlockResult.number,
|
|
197
|
-
|
|
237
|
+
blockLastArchive,
|
|
198
238
|
previousBlockResult.archive.root,
|
|
199
239
|
);
|
|
200
240
|
}
|
|
201
241
|
}
|
|
202
242
|
|
|
203
|
-
// Now check that the
|
|
204
|
-
if (!opts.force &&
|
|
205
|
-
throw new BlockIndexNotSequentialError(
|
|
243
|
+
// Now check that the block has the expected index value
|
|
244
|
+
if (!opts.force && expectedBlockIndex !== blockIndex) {
|
|
245
|
+
throw new BlockIndexNotSequentialError(blockIndex, previousBlockIndex);
|
|
206
246
|
}
|
|
207
247
|
|
|
208
|
-
|
|
209
|
-
let previousBlock: L2Block | undefined = undefined;
|
|
210
|
-
for (const block of blocks) {
|
|
211
|
-
if (!opts.force && previousBlock) {
|
|
212
|
-
if (previousBlock.number + 1 !== block.number) {
|
|
213
|
-
throw new BlockNumberNotSequentialError(block.number, previousBlock.number);
|
|
214
|
-
}
|
|
215
|
-
if (previousBlock.indexWithinCheckpoint + 1 !== block.indexWithinCheckpoint) {
|
|
216
|
-
throw new BlockIndexNotSequentialError(block.indexWithinCheckpoint, previousBlock.indexWithinCheckpoint);
|
|
217
|
-
}
|
|
218
|
-
if (!previousBlock.archive.root.equals(block.header.lastArchive.root)) {
|
|
219
|
-
throw new BlockArchiveNotConsistentError(
|
|
220
|
-
block.number,
|
|
221
|
-
previousBlock.number,
|
|
222
|
-
block.header.lastArchive.root,
|
|
223
|
-
previousBlock.archive.root,
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
if (!opts.force && firstBlockCheckpointNumber !== block.checkpointNumber) {
|
|
228
|
-
throw new CheckpointNumberNotConsistentError(block.checkpointNumber, firstBlockCheckpointNumber);
|
|
229
|
-
}
|
|
230
|
-
previousBlock = block;
|
|
231
|
-
await this.addBlockToDatabase(block, block.checkpointNumber, block.indexWithinCheckpoint);
|
|
232
|
-
}
|
|
248
|
+
await this.addBlockToDatabase(block, block.checkpointNumber, block.indexWithinCheckpoint);
|
|
233
249
|
|
|
234
250
|
return true;
|
|
235
251
|
});
|
|
236
252
|
}
|
|
237
253
|
|
|
238
254
|
/**
|
|
239
|
-
* Append new
|
|
255
|
+
* Append new checkpoints to the store's list.
|
|
240
256
|
* @param checkpoints - The L2 checkpoints to be added to the store.
|
|
241
257
|
* @returns True if the operation is successful.
|
|
242
258
|
*/
|
|
@@ -246,37 +262,29 @@ export class BlockStore {
|
|
|
246
262
|
}
|
|
247
263
|
|
|
248
264
|
return await this.db.transactionAsync(async () => {
|
|
249
|
-
// Check that the checkpoint immediately before the first block to be added is present in the store.
|
|
250
265
|
const firstCheckpointNumber = checkpoints[0].checkpoint.number;
|
|
251
266
|
const previousCheckpointNumber = await this.getLatestCheckpointNumber();
|
|
252
267
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
// There should be a previous checkpoint
|
|
261
|
-
previousCheckpointData = await this.getCheckpointData(previousCheckpointNumber);
|
|
262
|
-
if (previousCheckpointData === undefined) {
|
|
263
|
-
throw new CheckpointNotFoundError(previousCheckpointNumber);
|
|
268
|
+
// Handle already-stored checkpoints at the start of the batch.
|
|
269
|
+
// This can happen after an L1 reorg re-includes a checkpoint in a different L1 block.
|
|
270
|
+
// We accept them if archives match (same content) and update their L1 metadata.
|
|
271
|
+
if (!opts.force && firstCheckpointNumber <= previousCheckpointNumber) {
|
|
272
|
+
checkpoints = await this.skipOrUpdateAlreadyStoredCheckpoints(checkpoints, previousCheckpointNumber);
|
|
273
|
+
if (checkpoints.length === 0) {
|
|
274
|
+
return true;
|
|
264
275
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
// If we have a previous checkpoint then we need to get the previous block number
|
|
271
|
-
if (previousCheckpointData !== undefined) {
|
|
272
|
-
previousBlockNumber = BlockNumber(previousCheckpointData.startBlock + previousCheckpointData.blockCount - 1);
|
|
273
|
-
previousBlock = await this.getBlock(previousBlockNumber);
|
|
274
|
-
if (previousBlock === undefined) {
|
|
275
|
-
// We should be able to get the required previous block
|
|
276
|
-
throw new BlockNotFoundError(previousBlockNumber);
|
|
276
|
+
// Re-check sequentiality after skipping
|
|
277
|
+
const newFirstNumber = checkpoints[0].checkpoint.number;
|
|
278
|
+
if (previousCheckpointNumber !== newFirstNumber - 1) {
|
|
279
|
+
throw new InitialCheckpointNumberNotSequentialError(newFirstNumber, previousCheckpointNumber);
|
|
277
280
|
}
|
|
281
|
+
} else if (previousCheckpointNumber !== firstCheckpointNumber - 1 && !opts.force) {
|
|
282
|
+
throw new InitialCheckpointNumberNotSequentialError(firstCheckpointNumber, previousCheckpointNumber);
|
|
278
283
|
}
|
|
279
284
|
|
|
285
|
+
// Get the last block of the previous checkpoint for archive chaining
|
|
286
|
+
let previousBlock = await this.getPreviousCheckpointBlock(checkpoints[0].checkpoint.number);
|
|
287
|
+
|
|
280
288
|
// Iterate over checkpoints array and insert them, checking that the block numbers are sequential.
|
|
281
289
|
let previousCheckpoint: PublishedCheckpoint | undefined = undefined;
|
|
282
290
|
for (const checkpoint of checkpoints) {
|
|
@@ -292,42 +300,14 @@ export class BlockStore {
|
|
|
292
300
|
}
|
|
293
301
|
previousCheckpoint = checkpoint;
|
|
294
302
|
|
|
295
|
-
//
|
|
296
|
-
|
|
297
|
-
const block = checkpoint.checkpoint.blocks[i];
|
|
298
|
-
if (previousBlock) {
|
|
299
|
-
// The blocks should have a sequential block number
|
|
300
|
-
if (previousBlock.number !== block.number - 1) {
|
|
301
|
-
throw new BlockNumberNotSequentialError(block.number, previousBlock.number);
|
|
302
|
-
}
|
|
303
|
-
// If the blocks are for the same checkpoint then they should have sequential indexes
|
|
304
|
-
if (
|
|
305
|
-
previousBlock.checkpointNumber === block.checkpointNumber &&
|
|
306
|
-
previousBlock.indexWithinCheckpoint !== block.indexWithinCheckpoint - 1
|
|
307
|
-
) {
|
|
308
|
-
throw new BlockIndexNotSequentialError(block.indexWithinCheckpoint, previousBlock.indexWithinCheckpoint);
|
|
309
|
-
}
|
|
310
|
-
if (!previousBlock.archive.root.equals(block.header.lastArchive.root)) {
|
|
311
|
-
throw new BlockArchiveNotConsistentError(
|
|
312
|
-
block.number,
|
|
313
|
-
previousBlock.number,
|
|
314
|
-
block.header.lastArchive.root,
|
|
315
|
-
previousBlock.archive.root,
|
|
316
|
-
);
|
|
317
|
-
}
|
|
318
|
-
} else {
|
|
319
|
-
// No previous block, must be block 1 at checkpoint index 0
|
|
320
|
-
if (block.indexWithinCheckpoint !== 0) {
|
|
321
|
-
throw new BlockIndexNotSequentialError(block.indexWithinCheckpoint, undefined);
|
|
322
|
-
}
|
|
323
|
-
if (block.number !== INITIAL_L2_BLOCK_NUM) {
|
|
324
|
-
throw new BlockNumberNotSequentialError(block.number, undefined);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
303
|
+
// Validate block sequencing, indexes, and archive chaining
|
|
304
|
+
this.validateCheckpointBlocks(checkpoint.checkpoint.blocks, previousBlock);
|
|
327
305
|
|
|
328
|
-
|
|
329
|
-
|
|
306
|
+
// Store every block in the database (may already exist, but L1 data is authoritative)
|
|
307
|
+
for (let i = 0; i < checkpoint.checkpoint.blocks.length; i++) {
|
|
308
|
+
await this.addBlockToDatabase(checkpoint.checkpoint.blocks[i], checkpoint.checkpoint.number, i);
|
|
330
309
|
}
|
|
310
|
+
previousBlock = checkpoint.checkpoint.blocks.at(-1);
|
|
331
311
|
|
|
332
312
|
// Store the checkpoint in the database
|
|
333
313
|
await this.#checkpoints.set(checkpoint.checkpoint.number, {
|
|
@@ -345,11 +325,121 @@ export class BlockStore {
|
|
|
345
325
|
await this.#slotToCheckpoint.set(checkpoint.checkpoint.header.slotNumber, checkpoint.checkpoint.number);
|
|
346
326
|
}
|
|
347
327
|
|
|
328
|
+
// Clear the proposed checkpoint if any of the confirmed checkpoints match or supersede it
|
|
329
|
+
const lastConfirmedCheckpointNumber = checkpoints[checkpoints.length - 1].checkpoint.number;
|
|
330
|
+
await this.clearProposedCheckpointIfSuperseded(lastConfirmedCheckpointNumber);
|
|
331
|
+
|
|
348
332
|
await this.#lastSynchedL1Block.set(checkpoints[checkpoints.length - 1].l1.blockNumber);
|
|
349
333
|
return true;
|
|
350
334
|
});
|
|
351
335
|
}
|
|
352
336
|
|
|
337
|
+
/**
|
|
338
|
+
* Handles checkpoints at the start of a batch that are already stored (e.g. due to L1 reorg).
|
|
339
|
+
* Verifies the archive root matches, updates L1 metadata, and returns only the new checkpoints.
|
|
340
|
+
*/
|
|
341
|
+
private async skipOrUpdateAlreadyStoredCheckpoints(
|
|
342
|
+
checkpoints: PublishedCheckpoint[],
|
|
343
|
+
latestStored: CheckpointNumber,
|
|
344
|
+
): Promise<PublishedCheckpoint[]> {
|
|
345
|
+
let i = 0;
|
|
346
|
+
for (; i < checkpoints.length && checkpoints[i].checkpoint.number <= latestStored; i++) {
|
|
347
|
+
const incoming = checkpoints[i];
|
|
348
|
+
const stored = await this.getCheckpointData(incoming.checkpoint.number);
|
|
349
|
+
if (!stored) {
|
|
350
|
+
// Should not happen if latestStored is correct, but be safe
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
353
|
+
// Verify the checkpoint content matches (archive root)
|
|
354
|
+
if (!stored.archive.root.equals(incoming.checkpoint.archive.root)) {
|
|
355
|
+
throw new Error(
|
|
356
|
+
`Checkpoint ${incoming.checkpoint.number} already exists in store but with a different archive root. ` +
|
|
357
|
+
`Stored: ${stored.archive.root}, incoming: ${incoming.checkpoint.archive.root}`,
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
// Update L1 metadata and attestations for the already-stored checkpoint
|
|
361
|
+
this.#log.warn(
|
|
362
|
+
`Checkpoint ${incoming.checkpoint.number} already stored, updating L1 info ` +
|
|
363
|
+
`(L1 block ${stored.l1.blockNumber} -> ${incoming.l1.blockNumber})`,
|
|
364
|
+
);
|
|
365
|
+
await this.#checkpoints.set(incoming.checkpoint.number, {
|
|
366
|
+
header: incoming.checkpoint.header.toBuffer(),
|
|
367
|
+
archive: incoming.checkpoint.archive.toBuffer(),
|
|
368
|
+
checkpointOutHash: incoming.checkpoint.getCheckpointOutHash().toBuffer(),
|
|
369
|
+
l1: incoming.l1.toBuffer(),
|
|
370
|
+
attestations: incoming.attestations.map(a => a.toBuffer()),
|
|
371
|
+
checkpointNumber: incoming.checkpoint.number,
|
|
372
|
+
startBlock: incoming.checkpoint.blocks[0].number,
|
|
373
|
+
blockCount: incoming.checkpoint.blocks.length,
|
|
374
|
+
});
|
|
375
|
+
// Update the sync point to reflect the new L1 block
|
|
376
|
+
await this.#lastSynchedL1Block.set(incoming.l1.blockNumber);
|
|
377
|
+
}
|
|
378
|
+
return checkpoints.slice(i);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Gets the last block of the checkpoint before the given one.
|
|
383
|
+
* Returns undefined if there is no previous checkpoint (i.e. genesis).
|
|
384
|
+
*/
|
|
385
|
+
private async getPreviousCheckpointBlock(checkpointNumber: CheckpointNumber): Promise<L2Block | undefined> {
|
|
386
|
+
const previousCheckpointNumber = CheckpointNumber(checkpointNumber - 1);
|
|
387
|
+
if (previousCheckpointNumber === INITIAL_CHECKPOINT_NUMBER - 1) {
|
|
388
|
+
return undefined;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const previousCheckpointData = await this.getCheckpointData(previousCheckpointNumber);
|
|
392
|
+
if (previousCheckpointData === undefined) {
|
|
393
|
+
throw new CheckpointNotFoundError(previousCheckpointNumber);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
const previousBlockNumber = BlockNumber(previousCheckpointData.startBlock + previousCheckpointData.blockCount - 1);
|
|
397
|
+
const previousBlock = await this.getBlock(previousBlockNumber);
|
|
398
|
+
if (previousBlock === undefined) {
|
|
399
|
+
throw new BlockNotFoundError(previousBlockNumber);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
return previousBlock;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Validates that blocks are sequential, have correct indexes, and chain via archive roots.
|
|
407
|
+
* This is the same validation used for both confirmed checkpoints (addCheckpoints) and
|
|
408
|
+
* proposed checkpoints (setProposedCheckpoint).
|
|
409
|
+
*/
|
|
410
|
+
private validateCheckpointBlocks(blocks: L2Block[], previousBlock: L2Block | undefined): void {
|
|
411
|
+
for (const block of blocks) {
|
|
412
|
+
if (previousBlock) {
|
|
413
|
+
if (previousBlock.number !== block.number - 1) {
|
|
414
|
+
throw new BlockNumberNotSequentialError(block.number, previousBlock.number);
|
|
415
|
+
}
|
|
416
|
+
if (previousBlock.checkpointNumber === block.checkpointNumber) {
|
|
417
|
+
if (previousBlock.indexWithinCheckpoint !== block.indexWithinCheckpoint - 1) {
|
|
418
|
+
throw new BlockIndexNotSequentialError(block.indexWithinCheckpoint, previousBlock.indexWithinCheckpoint);
|
|
419
|
+
}
|
|
420
|
+
} else if (block.indexWithinCheckpoint !== 0) {
|
|
421
|
+
throw new BlockIndexNotSequentialError(block.indexWithinCheckpoint, previousBlock.indexWithinCheckpoint);
|
|
422
|
+
}
|
|
423
|
+
if (!previousBlock.archive.root.equals(block.header.lastArchive.root)) {
|
|
424
|
+
throw new BlockArchiveNotConsistentError(
|
|
425
|
+
block.number,
|
|
426
|
+
previousBlock.number,
|
|
427
|
+
block.header.lastArchive.root,
|
|
428
|
+
previousBlock.archive.root,
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
} else {
|
|
432
|
+
if (block.indexWithinCheckpoint !== 0) {
|
|
433
|
+
throw new BlockIndexNotSequentialError(block.indexWithinCheckpoint, undefined);
|
|
434
|
+
}
|
|
435
|
+
if (block.number !== INITIAL_L2_BLOCK_NUM) {
|
|
436
|
+
throw new BlockNumberNotSequentialError(block.number, undefined);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
previousBlock = block;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
353
443
|
private async addBlockToDatabase(block: L2Block, checkpointNumber: number, indexWithinCheckpoint: number) {
|
|
354
444
|
const blockHash = await block.hash();
|
|
355
445
|
|
|
@@ -442,6 +532,12 @@ export class BlockStore {
|
|
|
442
532
|
this.#log.debug(`Removed checkpoint ${c}`);
|
|
443
533
|
}
|
|
444
534
|
|
|
535
|
+
// Clear any proposed checkpoint that was orphaned by the removal (its base chain no longer exists)
|
|
536
|
+
const proposedCheckpointNumber = await this.getProposedCheckpointNumber();
|
|
537
|
+
if (proposedCheckpointNumber > checkpointNumber) {
|
|
538
|
+
await this.#proposedCheckpoint.delete();
|
|
539
|
+
}
|
|
540
|
+
|
|
445
541
|
return { blocksRemoved };
|
|
446
542
|
});
|
|
447
543
|
}
|
|
@@ -547,7 +643,7 @@ export class BlockStore {
|
|
|
547
643
|
const removedBlocks: L2Block[] = [];
|
|
548
644
|
|
|
549
645
|
// Get the latest block number to determine the range
|
|
550
|
-
const latestBlockNumber = await this.
|
|
646
|
+
const latestBlockNumber = await this.getLatestL2BlockNumber();
|
|
551
647
|
|
|
552
648
|
// Iterate from blockNumber + 1 to latestBlockNumber
|
|
553
649
|
for (let bn = blockNumber + 1; bn <= latestBlockNumber; bn++) {
|
|
@@ -580,13 +676,6 @@ export class BlockStore {
|
|
|
580
676
|
}
|
|
581
677
|
}
|
|
582
678
|
|
|
583
|
-
async getLatestBlockNumber(): Promise<BlockNumber> {
|
|
584
|
-
const [latestBlocknumber] = await toArray(this.#blocks.keysAsync({ reverse: true, limit: 1 }));
|
|
585
|
-
return typeof latestBlocknumber === 'number'
|
|
586
|
-
? BlockNumber(latestBlocknumber)
|
|
587
|
-
: BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
|
|
588
|
-
}
|
|
589
|
-
|
|
590
679
|
async getLatestCheckpointNumber(): Promise<CheckpointNumber> {
|
|
591
680
|
const [latestCheckpointNumber] = await toArray(this.#checkpoints.keysAsync({ reverse: true, limit: 1 }));
|
|
592
681
|
if (latestCheckpointNumber === undefined) {
|
|
@@ -595,6 +684,84 @@ export class BlockStore {
|
|
|
595
684
|
return CheckpointNumber(latestCheckpointNumber);
|
|
596
685
|
}
|
|
597
686
|
|
|
687
|
+
async hasProposedCheckpoint(): Promise<boolean> {
|
|
688
|
+
const proposed = await this.#proposedCheckpoint.getAsync();
|
|
689
|
+
return proposed !== undefined;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
/** Deletes the proposed checkpoint from storage. */
|
|
693
|
+
async deleteProposedCheckpoint(): Promise<void> {
|
|
694
|
+
await this.#proposedCheckpoint.delete();
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
/** Clears the proposed checkpoint if the given confirmed checkpoint number supersedes it. */
|
|
698
|
+
async clearProposedCheckpointIfSuperseded(confirmedCheckpointNumber: CheckpointNumber): Promise<void> {
|
|
699
|
+
const proposedCheckpointNumber = await this.getProposedCheckpointNumber();
|
|
700
|
+
if (proposedCheckpointNumber <= confirmedCheckpointNumber) {
|
|
701
|
+
await this.#proposedCheckpoint.delete();
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/** Returns the proposed checkpoint data, or undefined if no proposed checkpoint exists. No fallback to confirmed. */
|
|
706
|
+
async getProposedCheckpointOnly(): Promise<ProposedCheckpointData | undefined> {
|
|
707
|
+
const stored = await this.#proposedCheckpoint.getAsync();
|
|
708
|
+
if (!stored) {
|
|
709
|
+
return undefined;
|
|
710
|
+
}
|
|
711
|
+
return this.convertToProposedCheckpointData(stored);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
/**
|
|
715
|
+
* Gets the checkpoint at the proposed tip
|
|
716
|
+
* - pending checkpoint if it exists
|
|
717
|
+
* - fallsback to latest confirmed checkpoint otherwise
|
|
718
|
+
* @returns CommonCheckpointData
|
|
719
|
+
*/
|
|
720
|
+
async getProposedCheckpoint(): Promise<CommonCheckpointData | undefined> {
|
|
721
|
+
const stored = await this.#proposedCheckpoint.getAsync();
|
|
722
|
+
if (!stored) {
|
|
723
|
+
return this.getCheckpointData(await this.getLatestCheckpointNumber());
|
|
724
|
+
}
|
|
725
|
+
return this.convertToProposedCheckpointData(stored);
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
private convertToProposedCheckpointData(stored: ProposedCheckpointStorage): ProposedCheckpointData {
|
|
729
|
+
return {
|
|
730
|
+
checkpointNumber: CheckpointNumber(stored.checkpointNumber),
|
|
731
|
+
header: CheckpointHeader.fromBuffer(stored.header),
|
|
732
|
+
archive: AppendOnlyTreeSnapshot.fromBuffer(stored.archive),
|
|
733
|
+
checkpointOutHash: Fr.fromBuffer(stored.checkpointOutHash),
|
|
734
|
+
startBlock: BlockNumber(stored.startBlock),
|
|
735
|
+
blockCount: stored.blockCount,
|
|
736
|
+
totalManaUsed: BigInt(stored.totalManaUsed),
|
|
737
|
+
feeAssetPriceModifier: BigInt(stored.feeAssetPriceModifier),
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/**
|
|
742
|
+
* Attempts to get the proposedCheckpoint's number, if there is not one, then fallback to the latest confirmed checkpoint number.
|
|
743
|
+
* @returns CheckpointNumber
|
|
744
|
+
*/
|
|
745
|
+
async getProposedCheckpointNumber(): Promise<CheckpointNumber> {
|
|
746
|
+
const proposed = await this.getProposedCheckpoint();
|
|
747
|
+
if (!proposed) {
|
|
748
|
+
return await this.getLatestCheckpointNumber();
|
|
749
|
+
}
|
|
750
|
+
return CheckpointNumber(proposed.checkpointNumber);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* Attempts to get the proposedCheckpoint's block number, if there is not one, then fallback to the checkpointed block number
|
|
755
|
+
* @returns BlockNumber
|
|
756
|
+
*/
|
|
757
|
+
async getProposedCheckpointL2BlockNumber(): Promise<BlockNumber> {
|
|
758
|
+
const proposed = await this.getProposedCheckpoint();
|
|
759
|
+
if (!proposed) {
|
|
760
|
+
return await this.getCheckpointedL2BlockNumber();
|
|
761
|
+
}
|
|
762
|
+
return BlockNumber(proposed.startBlock + proposed.blockCount - 1);
|
|
763
|
+
}
|
|
764
|
+
|
|
598
765
|
async getCheckpointedBlock(number: BlockNumber): Promise<CheckpointedL2Block | undefined> {
|
|
599
766
|
const blockStorage = await this.#blocks.getAsync(number);
|
|
600
767
|
if (!blockStorage) {
|
|
@@ -871,7 +1038,10 @@ export class BlockStore {
|
|
|
871
1038
|
* @param txHash - The hash of a tx we try to get the receipt for.
|
|
872
1039
|
* @returns The requested tx receipt (or undefined if not found).
|
|
873
1040
|
*/
|
|
874
|
-
async getSettledTxReceipt(
|
|
1041
|
+
async getSettledTxReceipt(
|
|
1042
|
+
txHash: TxHash,
|
|
1043
|
+
l1Constants?: Pick<L1RollupConstants, 'epochDuration'>,
|
|
1044
|
+
): Promise<TxReceipt | undefined> {
|
|
875
1045
|
const txEffect = await this.getTxEffect(txHash);
|
|
876
1046
|
if (!txEffect) {
|
|
877
1047
|
return undefined;
|
|
@@ -880,10 +1050,11 @@ export class BlockStore {
|
|
|
880
1050
|
const blockNumber = BlockNumber(txEffect.l2BlockNumber);
|
|
881
1051
|
|
|
882
1052
|
// Use existing archiver methods to determine finalization level
|
|
883
|
-
const [provenBlockNumber, checkpointedBlockNumber, finalizedBlockNumber] = await Promise.all([
|
|
1053
|
+
const [provenBlockNumber, checkpointedBlockNumber, finalizedBlockNumber, blockData] = await Promise.all([
|
|
884
1054
|
this.getProvenBlockNumber(),
|
|
885
1055
|
this.getCheckpointedL2BlockNumber(),
|
|
886
1056
|
this.getFinalizedL2BlockNumber(),
|
|
1057
|
+
this.getBlockData(blockNumber),
|
|
887
1058
|
]);
|
|
888
1059
|
|
|
889
1060
|
let status: TxStatus;
|
|
@@ -897,6 +1068,9 @@ export class BlockStore {
|
|
|
897
1068
|
status = TxStatus.PROPOSED;
|
|
898
1069
|
}
|
|
899
1070
|
|
|
1071
|
+
const epochNumber =
|
|
1072
|
+
blockData && l1Constants ? getEpochAtSlot(blockData.header.globalVariables.slotNumber, l1Constants) : undefined;
|
|
1073
|
+
|
|
900
1074
|
return new TxReceipt(
|
|
901
1075
|
txHash,
|
|
902
1076
|
status,
|
|
@@ -905,6 +1079,7 @@ export class BlockStore {
|
|
|
905
1079
|
txEffect.data.transactionFee.toBigInt(),
|
|
906
1080
|
txEffect.l2BlockHash,
|
|
907
1081
|
blockNumber,
|
|
1082
|
+
epochNumber,
|
|
908
1083
|
);
|
|
909
1084
|
}
|
|
910
1085
|
|
|
@@ -961,6 +1136,47 @@ export class BlockStore {
|
|
|
961
1136
|
return this.#lastSynchedL1Block.set(l1BlockNumber);
|
|
962
1137
|
}
|
|
963
1138
|
|
|
1139
|
+
/** Sets the proposed checkpoint (not yet L1-confirmed). Only accepts confirmed + 1.
|
|
1140
|
+
* Computes archive and checkpointOutHash from the stored blocks. */
|
|
1141
|
+
async setProposedCheckpoint(proposed: ProposedCheckpointInput) {
|
|
1142
|
+
return await this.db.transactionAsync(async () => {
|
|
1143
|
+
const current = await this.getProposedCheckpointNumber();
|
|
1144
|
+
if (proposed.checkpointNumber <= current) {
|
|
1145
|
+
throw new ProposedCheckpointStaleError(proposed.checkpointNumber, current);
|
|
1146
|
+
}
|
|
1147
|
+
const confirmed = await this.getLatestCheckpointNumber();
|
|
1148
|
+
if (proposed.checkpointNumber !== confirmed + 1) {
|
|
1149
|
+
throw new ProposedCheckpointNotSequentialError(proposed.checkpointNumber, confirmed);
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
// Ensure the previous checkpoint + blocks exist
|
|
1153
|
+
const previousBlock = await this.getPreviousCheckpointBlock(proposed.checkpointNumber);
|
|
1154
|
+
const blocks: L2Block[] = [];
|
|
1155
|
+
for (let i = 0; i < proposed.blockCount; i++) {
|
|
1156
|
+
const block = await this.getBlock(BlockNumber(proposed.startBlock + i));
|
|
1157
|
+
if (!block) {
|
|
1158
|
+
throw new BlockNotFoundError(proposed.startBlock + i);
|
|
1159
|
+
}
|
|
1160
|
+
blocks.push(block);
|
|
1161
|
+
}
|
|
1162
|
+
this.validateCheckpointBlocks(blocks, previousBlock);
|
|
1163
|
+
|
|
1164
|
+
const archive = blocks[blocks.length - 1].archive;
|
|
1165
|
+
const checkpointOutHash = Checkpoint.getCheckpointOutHash(blocks);
|
|
1166
|
+
|
|
1167
|
+
await this.#proposedCheckpoint.set({
|
|
1168
|
+
header: proposed.header.toBuffer(),
|
|
1169
|
+
archive: archive.toBuffer(),
|
|
1170
|
+
checkpointOutHash: checkpointOutHash.toBuffer(),
|
|
1171
|
+
checkpointNumber: proposed.checkpointNumber,
|
|
1172
|
+
startBlock: proposed.startBlock,
|
|
1173
|
+
blockCount: proposed.blockCount,
|
|
1174
|
+
totalManaUsed: proposed.totalManaUsed.toString(),
|
|
1175
|
+
feeAssetPriceModifier: proposed.feeAssetPriceModifier.toString(),
|
|
1176
|
+
});
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
|
|
964
1180
|
async getProvenCheckpointNumber(): Promise<CheckpointNumber> {
|
|
965
1181
|
const [latestCheckpointNumber, provenCheckpointNumber] = await Promise.all([
|
|
966
1182
|
this.getLatestCheckpointNumber(),
|
|
@@ -976,6 +1192,20 @@ export class BlockStore {
|
|
|
976
1192
|
return result;
|
|
977
1193
|
}
|
|
978
1194
|
|
|
1195
|
+
async getFinalizedCheckpointNumber(): Promise<CheckpointNumber> {
|
|
1196
|
+
const [latestCheckpointNumber, finalizedCheckpointNumber] = await Promise.all([
|
|
1197
|
+
this.getLatestCheckpointNumber(),
|
|
1198
|
+
this.#lastFinalizedCheckpoint.getAsync(),
|
|
1199
|
+
]);
|
|
1200
|
+
return (finalizedCheckpointNumber ?? 0) > latestCheckpointNumber
|
|
1201
|
+
? latestCheckpointNumber
|
|
1202
|
+
: CheckpointNumber(finalizedCheckpointNumber ?? 0);
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
setFinalizedCheckpointNumber(checkpointNumber: CheckpointNumber) {
|
|
1206
|
+
return this.#lastFinalizedCheckpoint.set(checkpointNumber);
|
|
1207
|
+
}
|
|
1208
|
+
|
|
979
1209
|
#computeBlockRange(start: BlockNumber, limit: number): Required<Pick<Range<number>, 'start' | 'limit'>> {
|
|
980
1210
|
if (limit < 1) {
|
|
981
1211
|
throw new Error(`Invalid limit: ${limit}`);
|