@aztec/world-state 0.0.1-commit.6d3c34e → 0.0.1-commit.7035c9bd6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/instrumentation/instrumentation.d.ts +1 -1
- package/dest/instrumentation/instrumentation.d.ts.map +1 -1
- package/dest/instrumentation/instrumentation.js +9 -2
- package/dest/native/fork_checkpoint.d.ts +7 -1
- package/dest/native/fork_checkpoint.d.ts.map +1 -1
- package/dest/native/fork_checkpoint.js +15 -3
- package/dest/native/merkle_trees_facade.d.ts +5 -5
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +21 -9
- package/dest/native/message.d.ts +14 -5
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/native_world_state.d.ts +7 -7
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +9 -8
- package/dest/native/native_world_state_instance.d.ts +3 -3
- package/dest/native/native_world_state_instance.d.ts.map +1 -1
- package/dest/native/native_world_state_instance.js +4 -4
- package/dest/synchronizer/config.d.ts +3 -5
- package/dest/synchronizer/config.d.ts.map +1 -1
- package/dest/synchronizer/config.js +7 -9
- package/dest/synchronizer/factory.d.ts +5 -4
- package/dest/synchronizer/factory.d.ts.map +1 -1
- package/dest/synchronizer/factory.js +5 -5
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +4 -5
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +91 -34
- package/dest/test/utils.d.ts +7 -7
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +5 -5
- package/dest/world-state-db/merkle_tree_db.d.ts +3 -12
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/package.json +10 -11
- package/src/instrumentation/instrumentation.ts +9 -1
- package/src/native/fork_checkpoint.ts +19 -3
- package/src/native/merkle_trees_facade.ts +24 -8
- package/src/native/message.ts +15 -4
- package/src/native/native_world_state.ts +22 -10
- package/src/native/native_world_state_instance.ts +6 -4
- package/src/synchronizer/config.ts +8 -19
- package/src/synchronizer/factory.ts +8 -2
- package/src/synchronizer/server_world_state_synchronizer.ts +113 -44
- package/src/test/utils.ts +6 -6
- package/src/world-state-db/merkle_tree_db.ts +2 -12
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { GENESIS_BLOCK_HEADER_HASH,
|
|
2
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
|
+
import { GENESIS_BLOCK_HEADER_HASH, INITIAL_CHECKPOINT_NUMBER, INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
2
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
4
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
5
5
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
6
6
|
import { elapsed } from '@aztec/foundation/timer';
|
|
7
7
|
import {
|
|
8
|
+
type BlockHash,
|
|
8
9
|
GENESIS_CHECKPOINT_HEADER_HASH,
|
|
10
|
+
type L2Block,
|
|
9
11
|
type L2BlockId,
|
|
10
|
-
type L2BlockNew,
|
|
11
12
|
type L2BlockSource,
|
|
12
13
|
L2BlockStream,
|
|
13
14
|
type L2BlockStreamEvent,
|
|
@@ -48,7 +49,6 @@ export class ServerWorldStateSynchronizer
|
|
|
48
49
|
private latestBlockNumberAtStart = BlockNumber.ZERO;
|
|
49
50
|
private historyToKeep: number | undefined;
|
|
50
51
|
private currentState: WorldStateRunningState = WorldStateRunningState.IDLE;
|
|
51
|
-
private latestBlockHashQuery: { blockNumber: BlockNumber; hash: string | undefined } | undefined = undefined;
|
|
52
52
|
|
|
53
53
|
private syncPromise = promiseWithResolvers<void>();
|
|
54
54
|
protected blockStream: L2BlockStream | undefined;
|
|
@@ -65,7 +65,7 @@ export class ServerWorldStateSynchronizer
|
|
|
65
65
|
private readonly log: Logger = createLogger('world_state'),
|
|
66
66
|
) {
|
|
67
67
|
this.merkleTreeCommitted = this.merkleTreeDb.getCommitted();
|
|
68
|
-
this.historyToKeep = config.
|
|
68
|
+
this.historyToKeep = config.worldStateCheckpointHistory < 1 ? undefined : config.worldStateCheckpointHistory;
|
|
69
69
|
this.log.info(
|
|
70
70
|
`Created world state synchroniser with block history of ${
|
|
71
71
|
this.historyToKeep === undefined ? 'infinity' : this.historyToKeep
|
|
@@ -102,11 +102,7 @@ export class ServerWorldStateSynchronizer
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
// Get the current latest block number
|
|
105
|
-
this.latestBlockNumberAtStart = BlockNumber(
|
|
106
|
-
await (this.config.worldStateProvenBlocksOnly
|
|
107
|
-
? this.l2BlockSource.getProvenBlockNumber()
|
|
108
|
-
: this.l2BlockSource.getBlockNumber()),
|
|
109
|
-
);
|
|
105
|
+
this.latestBlockNumberAtStart = BlockNumber(await this.l2BlockSource.getBlockNumber());
|
|
110
106
|
|
|
111
107
|
const blockToDownloadFrom = (await this.getLatestBlockNumber()) + 1;
|
|
112
108
|
|
|
@@ -130,7 +126,6 @@ export class ServerWorldStateSynchronizer
|
|
|
130
126
|
protected createBlockStream(): L2BlockStream {
|
|
131
127
|
const logger = createLogger('world-state:block_stream');
|
|
132
128
|
return new L2BlockStream(this.l2BlockSource, this, this, logger, {
|
|
133
|
-
proven: this.config.worldStateProvenBlocksOnly,
|
|
134
129
|
pollIntervalMS: this.config.worldStateBlockCheckIntervalMS,
|
|
135
130
|
batchSize: this.config.worldStateBlockRequestBatchSize,
|
|
136
131
|
ignoreCheckpoints: true,
|
|
@@ -183,13 +178,10 @@ export class ServerWorldStateSynchronizer
|
|
|
183
178
|
/**
|
|
184
179
|
* Forces an immediate sync.
|
|
185
180
|
* @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it.
|
|
186
|
-
* @param
|
|
181
|
+
* @param blockHash - If provided, verifies the block at targetBlockNumber matches this hash. On mismatch, triggers a resync (reorg detection).
|
|
187
182
|
* @returns A promise that resolves with the block number the world state was synced to
|
|
188
183
|
*/
|
|
189
|
-
public async syncImmediate(
|
|
190
|
-
targetBlockNumber?: BlockNumber,
|
|
191
|
-
skipThrowIfTargetNotReached?: boolean,
|
|
192
|
-
): Promise<BlockNumber> {
|
|
184
|
+
public async syncImmediate(targetBlockNumber?: BlockNumber, blockHash?: BlockHash): Promise<BlockNumber> {
|
|
193
185
|
if (this.currentState !== WorldStateRunningState.RUNNING) {
|
|
194
186
|
throw new Error(`World State is not running. Unable to perform sync.`);
|
|
195
187
|
}
|
|
@@ -201,7 +193,19 @@ export class ServerWorldStateSynchronizer
|
|
|
201
193
|
// If we have been given a block number to sync to and we have reached that number then return
|
|
202
194
|
const currentBlockNumber = await this.getLatestBlockNumber();
|
|
203
195
|
if (targetBlockNumber !== undefined && targetBlockNumber <= currentBlockNumber) {
|
|
204
|
-
|
|
196
|
+
if (blockHash === undefined) {
|
|
197
|
+
return currentBlockNumber;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// If a block hash was provided, verify we're on the expected fork
|
|
201
|
+
const currentHash = await this.getL2BlockHash(targetBlockNumber);
|
|
202
|
+
if (currentHash === blockHash.toString()) {
|
|
203
|
+
return currentBlockNumber;
|
|
204
|
+
}
|
|
205
|
+
// Hash mismatch: a reorg may have occurred, fall through to trigger sync
|
|
206
|
+
this.log.debug(
|
|
207
|
+
`World state block hash mismatch at ${targetBlockNumber} (expected ${blockHash}, got ${currentHash}). Triggering resync.`,
|
|
208
|
+
);
|
|
205
209
|
}
|
|
206
210
|
this.log.debug(`World State at ${currentBlockNumber} told to sync to ${targetBlockNumber ?? 'latest'}`);
|
|
207
211
|
|
|
@@ -219,7 +223,7 @@ export class ServerWorldStateSynchronizer
|
|
|
219
223
|
|
|
220
224
|
// If we have been given a block number to sync to and we have not reached that number then fail
|
|
221
225
|
const updatedBlockNumber = await this.getLatestBlockNumber();
|
|
222
|
-
if (
|
|
226
|
+
if (targetBlockNumber !== undefined && targetBlockNumber > updatedBlockNumber) {
|
|
223
227
|
throw new WorldStateSynchronizerError(
|
|
224
228
|
`Unable to sync to block number ${targetBlockNumber} (last synced is ${updatedBlockNumber})`,
|
|
225
229
|
{
|
|
@@ -233,6 +237,24 @@ export class ServerWorldStateSynchronizer
|
|
|
233
237
|
);
|
|
234
238
|
}
|
|
235
239
|
|
|
240
|
+
// If a block hash was provided, verify we're on the expected fork after syncing, throw otherwise
|
|
241
|
+
if (blockHash !== undefined && targetBlockNumber !== undefined) {
|
|
242
|
+
const updatedHash = await this.getL2BlockHash(targetBlockNumber);
|
|
243
|
+
if (updatedHash !== blockHash.toString()) {
|
|
244
|
+
throw new WorldStateSynchronizerError(
|
|
245
|
+
`Block hash mismatch at block ${targetBlockNumber} (expected ${blockHash} but got ${updatedHash})`,
|
|
246
|
+
{
|
|
247
|
+
cause: {
|
|
248
|
+
reason: 'block_hash_mismatch',
|
|
249
|
+
targetBlockNumber,
|
|
250
|
+
expectedHash: blockHash.toString(),
|
|
251
|
+
actualHash: updatedHash,
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
236
258
|
return updatedBlockNumber;
|
|
237
259
|
}
|
|
238
260
|
|
|
@@ -241,21 +263,24 @@ export class ServerWorldStateSynchronizer
|
|
|
241
263
|
if (number === BlockNumber.ZERO) {
|
|
242
264
|
return (await this.merkleTreeCommitted.getInitialHeader().hash()).toString();
|
|
243
265
|
}
|
|
244
|
-
|
|
245
|
-
this.latestBlockHashQuery = {
|
|
246
|
-
hash: await this.merkleTreeCommitted
|
|
247
|
-
.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(number))
|
|
248
|
-
.then(leaf => leaf?.toString()),
|
|
249
|
-
blockNumber: number,
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
return this.latestBlockHashQuery.hash;
|
|
266
|
+
return this.merkleTreeCommitted.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(number)).then(leaf => leaf?.toString());
|
|
253
267
|
}
|
|
254
268
|
|
|
255
269
|
/** Returns the latest L2 block number for each tip of the chain (latest, proven, finalized). */
|
|
256
270
|
public async getL2Tips(): Promise<L2Tips> {
|
|
257
271
|
const status = await this.merkleTreeDb.getStatusSummary();
|
|
258
|
-
const
|
|
272
|
+
const unfinalizedBlockHashPromise = this.getL2BlockHash(status.unfinalizedBlockNumber);
|
|
273
|
+
const finalizedBlockHashPromise = this.getL2BlockHash(status.finalizedBlockNumber);
|
|
274
|
+
|
|
275
|
+
const provenBlockNumber = this.provenBlockNumber ?? status.finalizedBlockNumber;
|
|
276
|
+
const provenBlockHashPromise =
|
|
277
|
+
this.provenBlockNumber === undefined ? finalizedBlockHashPromise : this.getL2BlockHash(this.provenBlockNumber);
|
|
278
|
+
|
|
279
|
+
const [unfinalizedBlockHash, finalizedBlockHash, provenBlockHash] = await Promise.all([
|
|
280
|
+
unfinalizedBlockHashPromise,
|
|
281
|
+
finalizedBlockHashPromise,
|
|
282
|
+
provenBlockHashPromise,
|
|
283
|
+
]);
|
|
259
284
|
const latestBlockId: L2BlockId = { number: status.unfinalizedBlockNumber, hash: unfinalizedBlockHash! };
|
|
260
285
|
|
|
261
286
|
// World state doesn't track checkpointed blocks or checkpoints themselves.
|
|
@@ -266,16 +291,16 @@ export class ServerWorldStateSynchronizer
|
|
|
266
291
|
proposed: latestBlockId,
|
|
267
292
|
checkpointed: {
|
|
268
293
|
block: { number: INITIAL_L2_BLOCK_NUM, hash: GENESIS_BLOCK_HEADER_HASH.toString() },
|
|
269
|
-
checkpoint: { number:
|
|
294
|
+
checkpoint: { number: INITIAL_CHECKPOINT_NUMBER, hash: genesisCheckpointHeaderHash },
|
|
270
295
|
},
|
|
271
296
|
finalized: {
|
|
272
|
-
block: { number: status.finalizedBlockNumber, hash: '' },
|
|
273
|
-
checkpoint: { number:
|
|
297
|
+
block: { number: status.finalizedBlockNumber, hash: finalizedBlockHash ?? '' },
|
|
298
|
+
checkpoint: { number: INITIAL_CHECKPOINT_NUMBER, hash: genesisCheckpointHeaderHash },
|
|
274
299
|
},
|
|
275
300
|
proven: {
|
|
276
|
-
block: { number:
|
|
277
|
-
checkpoint: { number:
|
|
278
|
-
},
|
|
301
|
+
block: { number: provenBlockNumber, hash: provenBlockHash ?? '' },
|
|
302
|
+
checkpoint: { number: INITIAL_CHECKPOINT_NUMBER, hash: genesisCheckpointHeaderHash },
|
|
303
|
+
},
|
|
279
304
|
};
|
|
280
305
|
}
|
|
281
306
|
|
|
@@ -302,8 +327,8 @@ export class ServerWorldStateSynchronizer
|
|
|
302
327
|
* @param l2Blocks - The L2 blocks to handle.
|
|
303
328
|
* @returns Whether the block handled was produced by this same node.
|
|
304
329
|
*/
|
|
305
|
-
private async handleL2Blocks(l2Blocks:
|
|
306
|
-
this.log.
|
|
330
|
+
private async handleL2Blocks(l2Blocks: L2Block[]) {
|
|
331
|
+
this.log.debug(`Handling L2 blocks ${l2Blocks[0].number} to ${l2Blocks.at(-1)!.number}`);
|
|
307
332
|
|
|
308
333
|
// Fetch the L1->L2 messages for the first block in a checkpoint.
|
|
309
334
|
const messagesForBlocks = new Map<BlockNumber, Fr[]>();
|
|
@@ -343,11 +368,13 @@ export class ServerWorldStateSynchronizer
|
|
|
343
368
|
* @param l1ToL2Messages - The L1 to L2 messages for the block.
|
|
344
369
|
* @returns Whether the block handled was produced by this same node.
|
|
345
370
|
*/
|
|
346
|
-
private async handleL2Block(l2Block:
|
|
347
|
-
this.log.
|
|
371
|
+
private async handleL2Block(l2Block: L2Block, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull> {
|
|
372
|
+
this.log.debug(`Pushing L2 block ${l2Block.number} to merkle tree db `, {
|
|
348
373
|
blockNumber: l2Block.number,
|
|
349
374
|
blockHash: await l2Block.hash().then(h => h.toString()),
|
|
350
375
|
l1ToL2Messages: l1ToL2Messages.map(msg => msg.toString()),
|
|
376
|
+
blockHeader: l2Block.header.toInspect(),
|
|
377
|
+
blockStats: l2Block.getStats(),
|
|
351
378
|
});
|
|
352
379
|
const result = await this.merkleTreeDb.handleL2BlockAndMessages(l2Block, l1ToL2Messages);
|
|
353
380
|
|
|
@@ -361,16 +388,59 @@ export class ServerWorldStateSynchronizer
|
|
|
361
388
|
|
|
362
389
|
private async handleChainFinalized(blockNumber: BlockNumber) {
|
|
363
390
|
this.log.verbose(`Finalized chain is now at block ${blockNumber}`);
|
|
391
|
+
// If the finalized block number is older than the oldest available block in world state,
|
|
392
|
+
// skip entirely. The finalized block number can jump backwards (e.g. when the finalization
|
|
393
|
+
// heuristic changes) and try to read block data that has already been pruned. When this
|
|
394
|
+
// happens, there is nothing useful to do — the native world state is already finalized
|
|
395
|
+
// past this point and pruning has already happened.
|
|
396
|
+
const currentSummary = await this.merkleTreeDb.getStatusSummary();
|
|
397
|
+
if (blockNumber < currentSummary.oldestHistoricalBlock || blockNumber < 1) {
|
|
398
|
+
this.log.trace(
|
|
399
|
+
`Finalized block ${blockNumber} is older than the oldest available block ${currentSummary.oldestHistoricalBlock}. Skipping.`,
|
|
400
|
+
);
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
364
403
|
const summary = await this.merkleTreeDb.setFinalized(blockNumber);
|
|
365
404
|
if (this.historyToKeep === undefined) {
|
|
366
405
|
return;
|
|
367
406
|
}
|
|
368
|
-
|
|
369
|
-
|
|
407
|
+
// Get the checkpointed block for the finalized block number
|
|
408
|
+
const finalisedCheckpoint = await this.l2BlockSource.getCheckpointedBlock(summary.finalizedBlockNumber);
|
|
409
|
+
if (finalisedCheckpoint === undefined) {
|
|
410
|
+
this.log.warn(
|
|
411
|
+
`Failed to retrieve checkpointed block for finalized block number: ${summary.finalizedBlockNumber}`,
|
|
412
|
+
);
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
// Compute the required historic checkpoint number
|
|
416
|
+
const newHistoricCheckpointNumber = finalisedCheckpoint.checkpointNumber - this.historyToKeep + 1;
|
|
417
|
+
if (newHistoricCheckpointNumber <= 1) {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
// Retrieve the historic checkpoint
|
|
421
|
+
const historicCheckpoints = await this.l2BlockSource.getCheckpoints(
|
|
422
|
+
CheckpointNumber(newHistoricCheckpointNumber),
|
|
423
|
+
1,
|
|
424
|
+
);
|
|
425
|
+
if (historicCheckpoints.length === 0 || historicCheckpoints[0] === undefined) {
|
|
426
|
+
this.log.warn(`Failed to retrieve checkpoint number ${newHistoricCheckpointNumber} from Archiver`);
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
const historicCheckpoint = historicCheckpoints[0];
|
|
430
|
+
if (historicCheckpoint.checkpoint.blocks.length === 0 || historicCheckpoint.checkpoint.blocks[0] === undefined) {
|
|
431
|
+
this.log.warn(`Retrieved checkpoint number ${newHistoricCheckpointNumber} has no blocks!`);
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
// Find the block at the start of the checkpoint and remove blocks up to this one
|
|
435
|
+
const newHistoricBlock = historicCheckpoint.checkpoint.blocks[0];
|
|
436
|
+
if (newHistoricBlock.number <= currentSummary.oldestHistoricalBlock) {
|
|
437
|
+
this.log.debug(
|
|
438
|
+
`Historic block ${newHistoricBlock.number} is not newer than oldest available ${currentSummary.oldestHistoricalBlock}. Skipping prune.`,
|
|
439
|
+
);
|
|
370
440
|
return;
|
|
371
441
|
}
|
|
372
|
-
this.log.verbose(`Pruning historic blocks to ${newHistoricBlock}`);
|
|
373
|
-
const status = await this.merkleTreeDb.removeHistoricalBlocks(BlockNumber(newHistoricBlock));
|
|
442
|
+
this.log.verbose(`Pruning historic blocks to ${newHistoricBlock.number}`);
|
|
443
|
+
const status = await this.merkleTreeDb.removeHistoricalBlocks(BlockNumber(newHistoricBlock.number));
|
|
374
444
|
this.log.debug(`World state summary `, status.summary);
|
|
375
445
|
}
|
|
376
446
|
|
|
@@ -381,9 +451,8 @@ export class ServerWorldStateSynchronizer
|
|
|
381
451
|
}
|
|
382
452
|
|
|
383
453
|
private async handleChainPruned(blockNumber: BlockNumber) {
|
|
384
|
-
this.log.
|
|
454
|
+
this.log.info(`Chain pruned to block ${blockNumber}`);
|
|
385
455
|
const status = await this.merkleTreeDb.unwindBlocks(blockNumber);
|
|
386
|
-
this.latestBlockHashQuery = undefined;
|
|
387
456
|
this.provenBlockNumber = undefined;
|
|
388
457
|
this.instrumentation.updateWorldStateMetrics(status);
|
|
389
458
|
}
|
package/src/test/utils.ts
CHANGED
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
6
6
|
} from '@aztec/constants';
|
|
7
7
|
import { asyncMap } from '@aztec/foundation/async-map';
|
|
8
|
-
import { BlockNumber, type CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
8
|
+
import { BlockNumber, type CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
|
|
9
9
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
10
10
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
11
|
-
import {
|
|
11
|
+
import { L2Block } from '@aztec/stdlib/block';
|
|
12
12
|
import type {
|
|
13
13
|
IndexedTreeId,
|
|
14
14
|
MerkleTreeReadOperations,
|
|
@@ -20,7 +20,7 @@ import { BlockHeader } from '@aztec/stdlib/tx';
|
|
|
20
20
|
|
|
21
21
|
import type { NativeWorldStateService } from '../native/native_world_state.js';
|
|
22
22
|
|
|
23
|
-
export async function updateBlockState(block:
|
|
23
|
+
export async function updateBlockState(block: L2Block, l1ToL2Messages: Fr[], fork: MerkleTreeWriteOperations) {
|
|
24
24
|
const insertData = async (
|
|
25
25
|
treeId: IndexedTreeId,
|
|
26
26
|
data: Buffer[][],
|
|
@@ -76,8 +76,8 @@ export async function mockBlock(
|
|
|
76
76
|
numL1ToL2Messages: number = NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
77
77
|
isFirstBlockInCheckpoint: boolean = true,
|
|
78
78
|
) {
|
|
79
|
-
const block = await
|
|
80
|
-
indexWithinCheckpoint: isFirstBlockInCheckpoint ? 0 : 1,
|
|
79
|
+
const block = await L2Block.random(blockNum, {
|
|
80
|
+
indexWithinCheckpoint: isFirstBlockInCheckpoint ? IndexWithinCheckpoint(0) : IndexWithinCheckpoint(1),
|
|
81
81
|
txsPerBlock: size,
|
|
82
82
|
txOptions: { maxEffects },
|
|
83
83
|
});
|
|
@@ -92,7 +92,7 @@ export async function mockBlock(
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
export async function mockEmptyBlock(blockNum: BlockNumber, fork: MerkleTreeWriteOperations) {
|
|
95
|
-
const l2Block =
|
|
95
|
+
const l2Block = L2Block.empty();
|
|
96
96
|
const l1ToL2Messages = Array(16).fill(0).map(Fr.zero);
|
|
97
97
|
|
|
98
98
|
l2Block.header.globalVariables.blockNumber = blockNum;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { MAX_NULLIFIERS_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX } from '@aztec/constants';
|
|
2
2
|
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
-
import type {
|
|
5
|
-
import type { L2BlockNew } from '@aztec/stdlib/block';
|
|
4
|
+
import type { L2Block } from '@aztec/stdlib/block';
|
|
6
5
|
import type {
|
|
7
6
|
ForkMerkleTreeOperations,
|
|
8
7
|
MerkleTreeReadOperations,
|
|
9
8
|
ReadonlyWorldStateAccess,
|
|
10
9
|
} from '@aztec/stdlib/interfaces/server';
|
|
11
|
-
import type { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
12
10
|
|
|
13
11
|
import type { WorldStateStatusFull, WorldStateStatusSummary } from '../native/message.js';
|
|
14
12
|
|
|
@@ -31,21 +29,13 @@ export const INITIAL_NULLIFIER_TREE_SIZE = 2 * MAX_NULLIFIERS_PER_TX;
|
|
|
31
29
|
|
|
32
30
|
export const INITIAL_PUBLIC_DATA_TREE_SIZE = 2 * MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX;
|
|
33
31
|
|
|
34
|
-
export type TreeSnapshots = {
|
|
35
|
-
[MerkleTreeId.NULLIFIER_TREE]: IndexedTreeSnapshot;
|
|
36
|
-
[MerkleTreeId.NOTE_HASH_TREE]: TreeSnapshot<Fr>;
|
|
37
|
-
[MerkleTreeId.PUBLIC_DATA_TREE]: IndexedTreeSnapshot;
|
|
38
|
-
[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: TreeSnapshot<Fr>;
|
|
39
|
-
[MerkleTreeId.ARCHIVE]: TreeSnapshot<Fr>;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
32
|
export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations, ReadonlyWorldStateAccess {
|
|
43
33
|
/**
|
|
44
34
|
* Handles a single L2 block (i.e. Inserts the new note hashes into the merkle tree).
|
|
45
35
|
* @param block - The L2 block to handle.
|
|
46
36
|
* @param l1ToL2Messages - The L1 to L2 messages for the block.
|
|
47
37
|
*/
|
|
48
|
-
handleL2BlockAndMessages(block:
|
|
38
|
+
handleL2BlockAndMessages(block: L2Block, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull>;
|
|
49
39
|
|
|
50
40
|
/**
|
|
51
41
|
* Gets a handle that allows reading the latest committed state
|