@aztec/world-state 0.0.1-commit.d431d1c → 0.0.1-commit.dbf9cec
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/merkle_trees_facade.d.ts +2 -2
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +1 -1
- package/dest/native/message.d.ts +3 -2
- 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 +4 -3
- 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 +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +32 -11
- package/dest/test/utils.d.ts +6 -6
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +3 -3
- package/dest/world-state-db/merkle_tree_db.d.ts +3 -3
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/package.json +10 -10
- package/src/instrumentation/instrumentation.ts +9 -1
- package/src/native/merkle_trees_facade.ts +1 -1
- package/src/native/message.ts +2 -1
- 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 +7 -1
- package/src/synchronizer/server_world_state_synchronizer.ts +39 -17
- package/src/test/utils.ts +4 -4
- package/src/world-state-db/merkle_tree_db.ts +2 -2
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { GENESIS_BLOCK_HEADER_HASH, INITIAL_L2_BLOCK_NUM, INITIAL_L2_CHECKPOINT_NUM } from '@aztec/constants';
|
|
2
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
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
8
|
GENESIS_CHECKPOINT_HEADER_HASH,
|
|
9
|
+
type L2Block,
|
|
9
10
|
type L2BlockId,
|
|
10
|
-
type L2BlockNew,
|
|
11
11
|
type L2BlockSource,
|
|
12
12
|
L2BlockStream,
|
|
13
13
|
type L2BlockStreamEvent,
|
|
@@ -64,7 +64,7 @@ export class ServerWorldStateSynchronizer
|
|
|
64
64
|
private readonly log: Logger = createLogger('world_state'),
|
|
65
65
|
) {
|
|
66
66
|
this.merkleTreeCommitted = this.merkleTreeDb.getCommitted();
|
|
67
|
-
this.historyToKeep = config.
|
|
67
|
+
this.historyToKeep = config.worldStateCheckpointHistory < 1 ? undefined : config.worldStateCheckpointHistory;
|
|
68
68
|
this.log.info(
|
|
69
69
|
`Created world state synchroniser with block history of ${
|
|
70
70
|
this.historyToKeep === undefined ? 'infinity' : this.historyToKeep
|
|
@@ -101,11 +101,7 @@ export class ServerWorldStateSynchronizer
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
// Get the current latest block number
|
|
104
|
-
this.latestBlockNumberAtStart = BlockNumber(
|
|
105
|
-
await (this.config.worldStateProvenBlocksOnly
|
|
106
|
-
? this.l2BlockSource.getProvenBlockNumber()
|
|
107
|
-
: this.l2BlockSource.getBlockNumber()),
|
|
108
|
-
);
|
|
104
|
+
this.latestBlockNumberAtStart = BlockNumber(await this.l2BlockSource.getBlockNumber());
|
|
109
105
|
|
|
110
106
|
const blockToDownloadFrom = (await this.getLatestBlockNumber()) + 1;
|
|
111
107
|
|
|
@@ -129,7 +125,6 @@ export class ServerWorldStateSynchronizer
|
|
|
129
125
|
protected createBlockStream(): L2BlockStream {
|
|
130
126
|
const logger = createLogger('world-state:block_stream');
|
|
131
127
|
return new L2BlockStream(this.l2BlockSource, this, this, logger, {
|
|
132
|
-
proven: this.config.worldStateProvenBlocksOnly,
|
|
133
128
|
pollIntervalMS: this.config.worldStateBlockCheckIntervalMS,
|
|
134
129
|
batchSize: this.config.worldStateBlockRequestBatchSize,
|
|
135
130
|
ignoreCheckpoints: true,
|
|
@@ -304,8 +299,8 @@ export class ServerWorldStateSynchronizer
|
|
|
304
299
|
* @param l2Blocks - The L2 blocks to handle.
|
|
305
300
|
* @returns Whether the block handled was produced by this same node.
|
|
306
301
|
*/
|
|
307
|
-
private async handleL2Blocks(l2Blocks:
|
|
308
|
-
this.log.
|
|
302
|
+
private async handleL2Blocks(l2Blocks: L2Block[]) {
|
|
303
|
+
this.log.debug(`Handling L2 blocks ${l2Blocks[0].number} to ${l2Blocks.at(-1)!.number}`);
|
|
309
304
|
|
|
310
305
|
// Fetch the L1->L2 messages for the first block in a checkpoint.
|
|
311
306
|
const messagesForBlocks = new Map<BlockNumber, Fr[]>();
|
|
@@ -345,11 +340,13 @@ export class ServerWorldStateSynchronizer
|
|
|
345
340
|
* @param l1ToL2Messages - The L1 to L2 messages for the block.
|
|
346
341
|
* @returns Whether the block handled was produced by this same node.
|
|
347
342
|
*/
|
|
348
|
-
private async handleL2Block(l2Block:
|
|
349
|
-
this.log.
|
|
343
|
+
private async handleL2Block(l2Block: L2Block, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull> {
|
|
344
|
+
this.log.debug(`Pushing L2 block ${l2Block.number} to merkle tree db `, {
|
|
350
345
|
blockNumber: l2Block.number,
|
|
351
346
|
blockHash: await l2Block.hash().then(h => h.toString()),
|
|
352
347
|
l1ToL2Messages: l1ToL2Messages.map(msg => msg.toString()),
|
|
348
|
+
blockHeader: l2Block.header.toInspect(),
|
|
349
|
+
blockStats: l2Block.getStats(),
|
|
353
350
|
});
|
|
354
351
|
const result = await this.merkleTreeDb.handleL2BlockAndMessages(l2Block, l1ToL2Messages);
|
|
355
352
|
|
|
@@ -367,12 +364,37 @@ export class ServerWorldStateSynchronizer
|
|
|
367
364
|
if (this.historyToKeep === undefined) {
|
|
368
365
|
return;
|
|
369
366
|
}
|
|
370
|
-
|
|
371
|
-
|
|
367
|
+
// Get the checkpointed block for the finalized block number
|
|
368
|
+
const finalisedCheckpoint = await this.l2BlockSource.getCheckpointedBlock(summary.finalizedBlockNumber);
|
|
369
|
+
if (finalisedCheckpoint === undefined) {
|
|
370
|
+
this.log.warn(
|
|
371
|
+
`Failed to retrieve checkpointed block for finalized block number: ${summary.finalizedBlockNumber}`,
|
|
372
|
+
);
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
// Compute the required historic checkpoint number
|
|
376
|
+
const newHistoricCheckpointNumber = finalisedCheckpoint.checkpointNumber - this.historyToKeep + 1;
|
|
377
|
+
if (newHistoricCheckpointNumber <= 1) {
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
// Retrieve the historic checkpoint
|
|
381
|
+
const historicCheckpoints = await this.l2BlockSource.getCheckpoints(
|
|
382
|
+
CheckpointNumber(newHistoricCheckpointNumber),
|
|
383
|
+
1,
|
|
384
|
+
);
|
|
385
|
+
if (historicCheckpoints.length === 0 || historicCheckpoints[0] === undefined) {
|
|
386
|
+
this.log.warn(`Failed to retrieve checkpoint number ${newHistoricCheckpointNumber} from Archiver`);
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
const historicCheckpoint = historicCheckpoints[0];
|
|
390
|
+
if (historicCheckpoint.checkpoint.blocks.length === 0 || historicCheckpoint.checkpoint.blocks[0] === undefined) {
|
|
391
|
+
this.log.warn(`Retrieved checkpoint number ${newHistoricCheckpointNumber} has no blocks!`);
|
|
372
392
|
return;
|
|
373
393
|
}
|
|
374
|
-
|
|
375
|
-
const
|
|
394
|
+
// Find the block at the start of the checkpoint and remove blocks up to this one
|
|
395
|
+
const newHistoricBlock = historicCheckpoint.checkpoint.blocks[0];
|
|
396
|
+
this.log.verbose(`Pruning historic blocks to ${newHistoricBlock.number}`);
|
|
397
|
+
const status = await this.merkleTreeDb.removeHistoricalBlocks(BlockNumber(newHistoricBlock.number));
|
|
376
398
|
this.log.debug(`World state summary `, status.summary);
|
|
377
399
|
}
|
|
378
400
|
|
package/src/test/utils.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { asyncMap } from '@aztec/foundation/async-map';
|
|
|
8
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,7 +76,7 @@ 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
|
|
79
|
+
const block = await L2Block.random(blockNum, {
|
|
80
80
|
indexWithinCheckpoint: isFirstBlockInCheckpoint ? IndexWithinCheckpoint(0) : IndexWithinCheckpoint(1),
|
|
81
81
|
txsPerBlock: size,
|
|
82
82
|
txOptions: { maxEffects },
|
|
@@ -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;
|
|
@@ -2,7 +2,7 @@ import { MAX_NULLIFIERS_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX } f
|
|
|
2
2
|
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
4
|
import type { IndexedTreeSnapshot, TreeSnapshot } from '@aztec/merkle-tree';
|
|
5
|
-
import type {
|
|
5
|
+
import type { L2Block } from '@aztec/stdlib/block';
|
|
6
6
|
import type {
|
|
7
7
|
ForkMerkleTreeOperations,
|
|
8
8
|
MerkleTreeReadOperations,
|
|
@@ -45,7 +45,7 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations, Reado
|
|
|
45
45
|
* @param block - The L2 block to handle.
|
|
46
46
|
* @param l1ToL2Messages - The L1 to L2 messages for the block.
|
|
47
47
|
*/
|
|
48
|
-
handleL2BlockAndMessages(block:
|
|
48
|
+
handleL2BlockAndMessages(block: L2Block, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull>;
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Gets a handle that allows reading the latest committed state
|