@aztec/world-state 0.0.1-commit.2448fdb → 0.0.1-commit.2606882
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/native/merkle_trees_facade.d.ts +5 -2
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +24 -7
- package/dest/native/message.d.ts +2 -3
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/native_world_state.d.ts +31 -5
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +80 -27
- package/dest/native/native_world_state_instance.d.ts +5 -4
- package/dest/native/native_world_state_instance.d.ts.map +1 -1
- package/dest/native/native_world_state_instance.js +32 -25
- package/dest/native/world_state_ops_queue.js +5 -5
- package/dest/synchronizer/config.d.ts +1 -1
- package/dest/synchronizer/config.d.ts.map +1 -1
- package/dest/synchronizer/config.js +9 -10
- package/dest/synchronizer/factory.d.ts +5 -5
- package/dest/synchronizer/factory.d.ts.map +1 -1
- package/dest/synchronizer/factory.js +7 -6
- 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 +27 -17
- package/dest/testing.d.ts +4 -3
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +10 -6
- package/dest/world-state-db/merkle_tree_db.d.ts +1 -10
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/package.json +12 -11
- package/src/native/merkle_trees_facade.ts +27 -9
- package/src/native/message.ts +1 -2
- package/src/native/native_world_state.ts +98 -34
- package/src/native/native_world_state_instance.ts +38 -28
- package/src/native/world_state_ops_queue.ts +5 -5
- package/src/synchronizer/config.ts +14 -10
- package/src/synchronizer/factory.ts +13 -11
- package/src/synchronizer/server_world_state_synchronizer.ts +18 -19
- package/src/testing.ts +8 -9
- package/src/world-state-db/merkle_tree_db.ts +0 -10
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { INITIAL_CHECKPOINT_NUMBER } from '@aztec/constants';
|
|
2
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';
|
|
@@ -287,10 +287,15 @@ export class ServerWorldStateSynchronizer
|
|
|
287
287
|
// but we use a block stream so we need to provide 'local' L2Tips.
|
|
288
288
|
// We configure the block stream to ignore checkpoints and set checkpoint values to genesis here.
|
|
289
289
|
const genesisCheckpointHeaderHash = GENESIS_CHECKPOINT_HEADER_HASH.toString();
|
|
290
|
+
const initialBlockHash = (await this.merkleTreeCommitted.getInitialHeader().hash()).toString();
|
|
290
291
|
return {
|
|
291
292
|
proposed: latestBlockId,
|
|
292
293
|
checkpointed: {
|
|
293
|
-
block: { number:
|
|
294
|
+
block: { number: BlockNumber.ZERO, hash: initialBlockHash },
|
|
295
|
+
checkpoint: { number: INITIAL_CHECKPOINT_NUMBER, hash: genesisCheckpointHeaderHash },
|
|
296
|
+
},
|
|
297
|
+
proposedCheckpoint: {
|
|
298
|
+
block: { number: BlockNumber.ZERO, hash: initialBlockHash },
|
|
294
299
|
checkpoint: { number: INITIAL_CHECKPOINT_NUMBER, hash: genesisCheckpointHeaderHash },
|
|
295
300
|
},
|
|
296
301
|
finalized: {
|
|
@@ -387,7 +392,7 @@ export class ServerWorldStateSynchronizer
|
|
|
387
392
|
}
|
|
388
393
|
|
|
389
394
|
private async handleChainFinalized(blockNumber: BlockNumber) {
|
|
390
|
-
this.log.verbose(`
|
|
395
|
+
this.log.verbose(`Finalized chain is now at block ${blockNumber}`);
|
|
391
396
|
// If the finalized block number is older than the oldest available block in world state,
|
|
392
397
|
// skip entirely. The finalized block number can jump backwards (e.g. when the finalization
|
|
393
398
|
// heuristic changes) and try to read block data that has already been pruned. When this
|
|
@@ -401,37 +406,29 @@ export class ServerWorldStateSynchronizer
|
|
|
401
406
|
return;
|
|
402
407
|
}
|
|
403
408
|
const summary = await this.merkleTreeDb.setFinalized(blockNumber);
|
|
404
|
-
this.log.info(`World state finalized chain updated`, {
|
|
405
|
-
finalizedBlockNumber: summary.finalizedBlockNumber,
|
|
406
|
-
unfinalizedBlockNumber: summary.unfinalizedBlockNumber,
|
|
407
|
-
oldestHistoricalBlock: summary.oldestHistoricalBlock,
|
|
408
|
-
});
|
|
409
409
|
if (this.historyToKeep === undefined) {
|
|
410
410
|
return;
|
|
411
411
|
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
if (finalisedCheckpoint === undefined) {
|
|
412
|
+
const finalisedBlockData = await this.l2BlockSource.getBlockData({ number: summary.finalizedBlockNumber });
|
|
413
|
+
if (finalisedBlockData === undefined) {
|
|
415
414
|
this.log.warn(
|
|
416
415
|
`Failed to retrieve checkpointed block for finalized block number: ${summary.finalizedBlockNumber}`,
|
|
417
416
|
);
|
|
418
417
|
return;
|
|
419
418
|
}
|
|
420
419
|
// Compute the required historic checkpoint number
|
|
421
|
-
const newHistoricCheckpointNumber =
|
|
420
|
+
const newHistoricCheckpointNumber = finalisedBlockData.checkpointNumber - this.historyToKeep + 1;
|
|
422
421
|
if (newHistoricCheckpointNumber <= 1) {
|
|
423
422
|
return;
|
|
424
423
|
}
|
|
425
424
|
// Retrieve the historic checkpoint
|
|
426
|
-
const
|
|
427
|
-
CheckpointNumber(newHistoricCheckpointNumber),
|
|
428
|
-
|
|
429
|
-
)
|
|
430
|
-
if (historicCheckpoints.length === 0 || historicCheckpoints[0] === undefined) {
|
|
425
|
+
const historicCheckpoint = await this.l2BlockSource.getCheckpoint({
|
|
426
|
+
number: CheckpointNumber(newHistoricCheckpointNumber),
|
|
427
|
+
});
|
|
428
|
+
if (!historicCheckpoint) {
|
|
431
429
|
this.log.warn(`Failed to retrieve checkpoint number ${newHistoricCheckpointNumber} from Archiver`);
|
|
432
430
|
return;
|
|
433
431
|
}
|
|
434
|
-
const historicCheckpoint = historicCheckpoints[0];
|
|
435
432
|
if (historicCheckpoint.checkpoint.blocks.length === 0 || historicCheckpoint.checkpoint.blocks[0] === undefined) {
|
|
436
433
|
this.log.warn(`Retrieved checkpoint number ${newHistoricCheckpointNumber} has no blocks!`);
|
|
437
434
|
return;
|
|
@@ -458,7 +455,9 @@ export class ServerWorldStateSynchronizer
|
|
|
458
455
|
private async handleChainPruned(blockNumber: BlockNumber) {
|
|
459
456
|
this.log.info(`Chain pruned to block ${blockNumber}`);
|
|
460
457
|
const status = await this.merkleTreeDb.unwindBlocks(blockNumber);
|
|
461
|
-
this.provenBlockNumber
|
|
458
|
+
if (this.provenBlockNumber !== undefined && this.provenBlockNumber > blockNumber) {
|
|
459
|
+
this.provenBlockNumber = undefined;
|
|
460
|
+
}
|
|
462
461
|
this.instrumentation.updateWorldStateMetrics(status);
|
|
463
462
|
}
|
|
464
463
|
|
package/src/testing.ts
CHANGED
|
@@ -3,22 +3,19 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
3
3
|
import { computeFeePayerBalanceLeafSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
4
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
5
|
import { MerkleTreeId, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
6
|
+
import type { GenesisData } from '@aztec/stdlib/world-state';
|
|
6
7
|
|
|
7
8
|
import { NativeWorldStateService } from './native/index.js';
|
|
8
9
|
|
|
9
|
-
async function generateGenesisValues(
|
|
10
|
-
if (!prefilledPublicData.length) {
|
|
10
|
+
async function generateGenesisValues(genesis: GenesisData) {
|
|
11
|
+
if (!genesis.prefilledPublicData.length && genesis.genesisTimestamp === 0n) {
|
|
11
12
|
return {
|
|
12
13
|
genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT),
|
|
13
14
|
};
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
// Create a temporary world state to compute the genesis values.
|
|
17
|
-
const ws = await NativeWorldStateService.tmp(
|
|
18
|
-
undefined /* rollupAddress */,
|
|
19
|
-
true /* cleanupTmpDir */,
|
|
20
|
-
prefilledPublicData,
|
|
21
|
-
);
|
|
18
|
+
const ws = await NativeWorldStateService.tmp(undefined /* rollupAddress */, true /* cleanupTmpDir */, genesis);
|
|
22
19
|
const genesisArchiveRoot = new Fr((await ws.getCommitted().getTreeInfo(MerkleTreeId.ARCHIVE)).root);
|
|
23
20
|
await ws.close();
|
|
24
21
|
|
|
@@ -33,6 +30,7 @@ export async function getGenesisValues(
|
|
|
33
30
|
initialAccounts: AztecAddress[],
|
|
34
31
|
initialAccountFeeJuice = defaultInitialAccountFeeJuice,
|
|
35
32
|
genesisPublicData: PublicDataTreeLeaf[] = [],
|
|
33
|
+
genesisTimestamp: bigint = 0n,
|
|
36
34
|
) {
|
|
37
35
|
// Top up the accounts with fee juice.
|
|
38
36
|
let prefilledPublicData = await Promise.all(
|
|
@@ -46,11 +44,12 @@ export async function getGenesisValues(
|
|
|
46
44
|
|
|
47
45
|
prefilledPublicData.sort((a, b) => (b.slot.lt(a.slot) ? 1 : -1));
|
|
48
46
|
|
|
49
|
-
const
|
|
47
|
+
const genesis: GenesisData = { prefilledPublicData, genesisTimestamp };
|
|
48
|
+
const { genesisArchiveRoot } = await generateGenesisValues(genesis);
|
|
50
49
|
|
|
51
50
|
return {
|
|
52
51
|
genesisArchiveRoot,
|
|
53
|
-
|
|
52
|
+
genesis,
|
|
54
53
|
fundingNeeded: BigInt(initialAccounts.length) * initialAccountFeeJuice.toBigInt(),
|
|
55
54
|
};
|
|
56
55
|
}
|
|
@@ -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 { IndexedTreeSnapshot, TreeSnapshot } from '@aztec/merkle-tree';
|
|
5
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,14 +29,6 @@ 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).
|