@aztec/world-state 0.0.1-commit.8c0b8ff → 0.0.1-commit.8cb2d04d8

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.
Files changed (35) hide show
  1. package/dest/native/merkle_trees_facade.d.ts +3 -2
  2. package/dest/native/merkle_trees_facade.d.ts.map +1 -1
  3. package/dest/native/merkle_trees_facade.js +8 -3
  4. package/dest/native/message.d.ts +2 -3
  5. package/dest/native/message.d.ts.map +1 -1
  6. package/dest/native/native_world_state.d.ts +7 -5
  7. package/dest/native/native_world_state.d.ts.map +1 -1
  8. package/dest/native/native_world_state.js +16 -11
  9. package/dest/native/native_world_state_instance.d.ts +4 -4
  10. package/dest/native/native_world_state_instance.d.ts.map +1 -1
  11. package/dest/native/native_world_state_instance.js +7 -6
  12. package/dest/native/world_state_ops_queue.js +5 -5
  13. package/dest/synchronizer/config.js +7 -7
  14. package/dest/synchronizer/factory.d.ts +5 -5
  15. package/dest/synchronizer/factory.d.ts.map +1 -1
  16. package/dest/synchronizer/factory.js +6 -5
  17. package/dest/synchronizer/server_world_state_synchronizer.d.ts +1 -1
  18. package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
  19. package/dest/synchronizer/server_world_state_synchronizer.js +16 -9
  20. package/dest/testing.d.ts +4 -3
  21. package/dest/testing.d.ts.map +1 -1
  22. package/dest/testing.js +10 -6
  23. package/dest/world-state-db/merkle_tree_db.d.ts +1 -10
  24. package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
  25. package/package.json +9 -10
  26. package/src/native/merkle_trees_facade.ts +10 -5
  27. package/src/native/message.ts +1 -2
  28. package/src/native/native_world_state.ts +14 -20
  29. package/src/native/native_world_state_instance.ts +8 -4
  30. package/src/native/world_state_ops_queue.ts +5 -5
  31. package/src/synchronizer/config.ts +7 -7
  32. package/src/synchronizer/factory.ts +7 -7
  33. package/src/synchronizer/server_world_state_synchronizer.ts +10 -8
  34. package/src/testing.ts +8 -9
  35. package/src/world-state-db/merkle_tree_db.ts +0 -10
@@ -1,8 +1,8 @@
1
1
  import type { LoggerBindings } from '@aztec/foundation/log';
2
- import type { DataStoreConfig } from '@aztec/kv-store/config';
3
2
  import type { L2BlockSource } from '@aztec/stdlib/block';
3
+ import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
4
4
  import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
5
- import type { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
5
+ import { EMPTY_GENESIS_DATA, type GenesisData } from '@aztec/stdlib/world-state';
6
6
  import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
7
7
 
8
8
  import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
@@ -21,12 +21,12 @@ export interface WorldStateTreeMapSizes {
21
21
  export async function createWorldStateSynchronizer(
22
22
  config: WorldStateConfig & DataStoreConfig,
23
23
  l2BlockSource: L2BlockSource & L1ToL2MessageSource,
24
- prefilledPublicData: PublicDataTreeLeaf[] = [],
24
+ genesis: GenesisData = EMPTY_GENESIS_DATA,
25
25
  client: TelemetryClient = getTelemetryClient(),
26
26
  bindings?: LoggerBindings,
27
27
  ) {
28
28
  const instrumentation = new WorldStateInstrumentation(client);
29
- const merkleTrees = await createWorldState(config, prefilledPublicData, instrumentation, bindings);
29
+ const merkleTrees = await createWorldState(config, genesis, instrumentation, bindings);
30
30
  return new ServerWorldStateSynchronizer(merkleTrees, l2BlockSource, config, instrumentation);
31
31
  }
32
32
 
@@ -42,7 +42,7 @@ export async function createWorldState(
42
42
  | 'publicDataTreeMapSizeKb'
43
43
  > &
44
44
  Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKb' | 'l1Contracts'>,
45
- prefilledPublicData: PublicDataTreeLeaf[] = [],
45
+ genesis: GenesisData = EMPTY_GENESIS_DATA,
46
46
  instrumentation: WorldStateInstrumentation = new WorldStateInstrumentation(getTelemetryClient()),
47
47
  bindings?: LoggerBindings,
48
48
  ) {
@@ -66,14 +66,14 @@ export async function createWorldState(
66
66
  config.l1Contracts.rollupAddress,
67
67
  dataDirectory,
68
68
  wsTreeMapSizes,
69
- prefilledPublicData,
69
+ genesis,
70
70
  instrumentation,
71
71
  bindings,
72
72
  )
73
73
  : await NativeWorldStateService.tmp(
74
74
  config.l1Contracts.rollupAddress,
75
75
  !['true', '1'].includes(process.env.DEBUG_WORLD_STATE!),
76
- prefilledPublicData,
76
+ genesis,
77
77
  instrumentation,
78
78
  bindings,
79
79
  );
@@ -1,4 +1,4 @@
1
- import { GENESIS_BLOCK_HEADER_HASH, INITIAL_CHECKPOINT_NUMBER, INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
1
+ import { INITIAL_CHECKPOINT_NUMBER, INITIAL_L2_BLOCK_NUM } 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';
@@ -6,6 +6,7 @@ import { promiseWithResolvers } from '@aztec/foundation/promise';
6
6
  import { elapsed } from '@aztec/foundation/timer';
7
7
  import {
8
8
  type BlockHash,
9
+ GENESIS_BLOCK_HEADER_HASH,
9
10
  GENESIS_CHECKPOINT_HEADER_HASH,
10
11
  type L2Block,
11
12
  type L2BlockId,
@@ -293,6 +294,10 @@ export class ServerWorldStateSynchronizer
293
294
  block: { number: INITIAL_L2_BLOCK_NUM, hash: GENESIS_BLOCK_HEADER_HASH.toString() },
294
295
  checkpoint: { number: INITIAL_CHECKPOINT_NUMBER, hash: genesisCheckpointHeaderHash },
295
296
  },
297
+ proposedCheckpoint: {
298
+ block: { number: INITIAL_L2_BLOCK_NUM, hash: GENESIS_BLOCK_HEADER_HASH.toString() },
299
+ checkpoint: { number: INITIAL_CHECKPOINT_NUMBER, hash: genesisCheckpointHeaderHash },
300
+ },
296
301
  finalized: {
297
302
  block: { number: status.finalizedBlockNumber, hash: finalizedBlockHash ?? '' },
298
303
  checkpoint: { number: INITIAL_CHECKPOINT_NUMBER, hash: genesisCheckpointHeaderHash },
@@ -387,7 +392,7 @@ export class ServerWorldStateSynchronizer
387
392
  }
388
393
 
389
394
  private async handleChainFinalized(blockNumber: BlockNumber) {
390
- this.log.verbose(`Updating world state finalized chain to block ${blockNumber}`);
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,11 +406,6 @@ 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
  }
@@ -458,7 +458,9 @@ export class ServerWorldStateSynchronizer
458
458
  private async handleChainPruned(blockNumber: BlockNumber) {
459
459
  this.log.info(`Chain pruned to block ${blockNumber}`);
460
460
  const status = await this.merkleTreeDb.unwindBlocks(blockNumber);
461
- this.provenBlockNumber = undefined;
461
+ if (this.provenBlockNumber !== undefined && this.provenBlockNumber > blockNumber) {
462
+ this.provenBlockNumber = undefined;
463
+ }
462
464
  this.instrumentation.updateWorldStateMetrics(status);
463
465
  }
464
466
 
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(prefilledPublicData: PublicDataTreeLeaf[]) {
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 { genesisArchiveRoot } = await generateGenesisValues(prefilledPublicData);
47
+ const genesis: GenesisData = { prefilledPublicData, genesisTimestamp };
48
+ const { genesisArchiveRoot } = await generateGenesisValues(genesis);
50
49
 
51
50
  return {
52
51
  genesisArchiveRoot,
53
- prefilledPublicData,
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).