@aztec/world-state 0.0.1-commit.d431d1c → 0.0.1-commit.d939eb5aa
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 +7 -6
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +17 -9
- package/dest/native/message.d.ts +13 -5
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/native_world_state.d.ts +10 -8
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +18 -12
- package/dest/native/native_world_state_instance.d.ts +5 -5
- package/dest/native/native_world_state_instance.d.ts.map +1 -1
- package/dest/native/native_world_state_instance.js +8 -7
- package/dest/native/world_state_ops_queue.js +5 -5
- package/dest/synchronizer/config.d.ts +3 -5
- package/dest/synchronizer/config.d.ts.map +1 -1
- package/dest/synchronizer/config.js +14 -16
- package/dest/synchronizer/factory.d.ts +6 -5
- package/dest/synchronizer/factory.d.ts.map +1 -1
- package/dest/synchronizer/factory.js +6 -5
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +4 -4
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +92 -22
- 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/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 +3 -12
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/package.json +9 -10
- package/src/instrumentation/instrumentation.ts +9 -1
- package/src/native/fork_checkpoint.ts +19 -3
- package/src/native/merkle_trees_facade.ts +24 -12
- package/src/native/message.ts +14 -4
- package/src/native/native_world_state.ts +22 -16
- package/src/native/native_world_state_instance.ts +14 -8
- package/src/native/world_state_ops_queue.ts +5 -5
- package/src/synchronizer/config.ts +15 -26
- package/src/synchronizer/factory.ts +13 -7
- package/src/synchronizer/server_world_state_synchronizer.ts +105 -30
- package/src/test/utils.ts +4 -4
- package/src/testing.ts +8 -9
- package/src/world-state-db/merkle_tree_db.ts +2 -12
package/dest/test/utils.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { BlockNumber, type CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import {
|
|
3
|
+
import { L2Block } from '@aztec/stdlib/block';
|
|
4
4
|
import type { MerkleTreeReadOperations, MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
5
5
|
import { mockCheckpointAndMessages } from '@aztec/stdlib/testing';
|
|
6
6
|
import type { NativeWorldStateService } from '../native/native_world_state.js';
|
|
7
|
-
export declare function updateBlockState(block:
|
|
7
|
+
export declare function updateBlockState(block: L2Block, l1ToL2Messages: Fr[], fork: MerkleTreeWriteOperations): Promise<void>;
|
|
8
8
|
export declare function mockBlock(blockNum: BlockNumber, size: number, fork: MerkleTreeWriteOperations, maxEffects?: number | undefined, numL1ToL2Messages?: number, isFirstBlockInCheckpoint?: boolean): Promise<{
|
|
9
|
-
block:
|
|
9
|
+
block: L2Block;
|
|
10
10
|
messages: Fr[];
|
|
11
11
|
}>;
|
|
12
12
|
export declare function mockEmptyBlock(blockNum: BlockNumber, fork: MerkleTreeWriteOperations): Promise<{
|
|
13
|
-
block:
|
|
13
|
+
block: L2Block;
|
|
14
14
|
messages: Fr[];
|
|
15
15
|
}>;
|
|
16
16
|
export declare function mockBlocks(from: BlockNumber, count: number, numTxs: number, worldState: NativeWorldStateService): Promise<{
|
|
17
|
-
blocks:
|
|
17
|
+
blocks: L2Block[];
|
|
18
18
|
messages: Fr[][];
|
|
19
19
|
}>;
|
|
20
20
|
export declare function mockCheckpoint(checkpointNumber: CheckpointNumber, fork: MerkleTreeWriteOperations, options?: Partial<Parameters<typeof mockCheckpointAndMessages>[1]>): Promise<{
|
|
@@ -23,4 +23,4 @@ export declare function mockCheckpoint(checkpointNumber: CheckpointNumber, fork:
|
|
|
23
23
|
}>;
|
|
24
24
|
export declare function assertSameState(forkA: MerkleTreeReadOperations, forkB: MerkleTreeReadOperations): Promise<void>;
|
|
25
25
|
export declare function compareChains(left: MerkleTreeReadOperations, right: MerkleTreeReadOperations): Promise<void>;
|
|
26
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
26
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0L3V0aWxzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQU9BLE9BQU8sRUFBRSxXQUFXLEVBQUUsS0FBSyxnQkFBZ0IsRUFBeUIsTUFBTSxpQ0FBaUMsQ0FBQztBQUU1RyxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDcEQsT0FBTyxFQUFFLE9BQU8sRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBQzlDLE9BQU8sS0FBSyxFQUVWLHdCQUF3QixFQUN4Qix5QkFBeUIsRUFDMUIsTUFBTSxpQ0FBaUMsQ0FBQztBQUN6QyxPQUFPLEVBQUUseUJBQXlCLEVBQXNCLE1BQU0sdUJBQXVCLENBQUM7QUFJdEYsT0FBTyxLQUFLLEVBQUUsdUJBQXVCLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUUvRSx3QkFBc0IsZ0JBQWdCLENBQUMsS0FBSyxF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C,CAAC,CAAC,CAAM;;;GAOvE;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,wBAAwB,EAAE,KAAK,EAAE,wBAAwB,iBAQrG;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE,wBAAwB,EAAE,KAAK,EAAE,wBAAwB,iBAYlG"}
|
package/dest/test/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ import { asyncMap } from '@aztec/foundation/async-map';
|
|
|
3
3
|
import { BlockNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
|
|
4
4
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
5
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
|
-
import {
|
|
6
|
+
import { L2Block } from '@aztec/stdlib/block';
|
|
7
7
|
import { mockCheckpointAndMessages, mockL1ToL2Messages } from '@aztec/stdlib/testing';
|
|
8
8
|
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
9
9
|
import { BlockHeader } from '@aztec/stdlib/tx';
|
|
@@ -35,7 +35,7 @@ export async function updateBlockState(block, l1ToL2Messages, fork) {
|
|
|
35
35
|
block.archive = new AppendOnlyTreeSnapshot(Fr.fromBuffer(archiveState.root), Number(archiveState.size));
|
|
36
36
|
}
|
|
37
37
|
export async function mockBlock(blockNum, size, fork, maxEffects = 1000, numL1ToL2Messages = NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, isFirstBlockInCheckpoint = true) {
|
|
38
|
-
const block = await
|
|
38
|
+
const block = await L2Block.random(blockNum, {
|
|
39
39
|
indexWithinCheckpoint: isFirstBlockInCheckpoint ? IndexWithinCheckpoint(0) : IndexWithinCheckpoint(1),
|
|
40
40
|
txsPerBlock: size,
|
|
41
41
|
txOptions: {
|
|
@@ -50,7 +50,7 @@ export async function mockBlock(blockNum, size, fork, maxEffects = 1000, numL1To
|
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
export async function mockEmptyBlock(blockNum, fork) {
|
|
53
|
-
const l2Block =
|
|
53
|
+
const l2Block = L2Block.empty();
|
|
54
54
|
const l1ToL2Messages = Array(16).fill(0).map(Fr.zero);
|
|
55
55
|
l2Block.header.globalVariables.blockNumber = blockNum;
|
|
56
56
|
await updateBlockState(l2Block, l1ToL2Messages, fork);
|
package/dest/testing.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
3
|
import { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
4
|
+
import type { GenesisData } from '@aztec/stdlib/world-state';
|
|
4
5
|
export declare const defaultInitialAccountFeeJuice: Fr;
|
|
5
|
-
export declare function getGenesisValues(initialAccounts: AztecAddress[], initialAccountFeeJuice?: Fr, genesisPublicData?: PublicDataTreeLeaf[]): Promise<{
|
|
6
|
+
export declare function getGenesisValues(initialAccounts: AztecAddress[], initialAccountFeeJuice?: Fr, genesisPublicData?: PublicDataTreeLeaf[], genesisTimestamp?: bigint): Promise<{
|
|
6
7
|
genesisArchiveRoot: Fr;
|
|
7
|
-
|
|
8
|
+
genesis: GenesisData;
|
|
8
9
|
fundingNeeded: bigint;
|
|
9
10
|
}>;
|
|
10
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
11
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdGluZy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3Rlc3RpbmcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBRXBELE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQ2hFLE9BQU8sRUFBZ0Isa0JBQWtCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUN2RSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSwyQkFBMkIsQ0FBQztBQXFCN0QsZUFBTyxNQUFNLDZCQUE2QixJQUFxQixDQUFDO0FBRWhFLHdCQUFzQixnQkFBZ0IsQ0FDcEMsZUFBZSxFQUFFLFlBQVksRUFBRSxFQUMvQixzQkFBc0IsS0FBZ0MsRUFDdEQsaUJBQWlCLEdBQUUsa0JBQWtCLEVBQU8sRUFDNUMsZ0JBQWdCLEdBQUUsTUFBVzs7OztHQXNCOUIifQ==
|
package/dest/testing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAgB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAgB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAqB7D,eAAO,MAAM,6BAA6B,IAAqB,CAAC;AAEhE,wBAAsB,gBAAgB,CACpC,eAAe,EAAE,YAAY,EAAE,EAC/B,sBAAsB,KAAgC,EACtD,iBAAiB,GAAE,kBAAkB,EAAO,EAC5C,gBAAgB,GAAE,MAAW;;;;GAsB9B"}
|
package/dest/testing.js
CHANGED
|
@@ -3,14 +3,14 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
3
3
|
import { computeFeePayerBalanceLeafSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
4
4
|
import { MerkleTreeId, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
5
5
|
import { NativeWorldStateService } from './native/index.js';
|
|
6
|
-
async function generateGenesisValues(
|
|
7
|
-
if (!prefilledPublicData.length) {
|
|
6
|
+
async function generateGenesisValues(genesis) {
|
|
7
|
+
if (!genesis.prefilledPublicData.length && genesis.genesisTimestamp === 0n) {
|
|
8
8
|
return {
|
|
9
9
|
genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT)
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
// Create a temporary world state to compute the genesis values.
|
|
13
|
-
const ws = await NativeWorldStateService.tmp(undefined /* rollupAddress */ , true,
|
|
13
|
+
const ws = await NativeWorldStateService.tmp(undefined /* rollupAddress */ , true, genesis);
|
|
14
14
|
const genesisArchiveRoot = new Fr((await ws.getCommitted().getTreeInfo(MerkleTreeId.ARCHIVE)).root);
|
|
15
15
|
await ws.close();
|
|
16
16
|
return {
|
|
@@ -18,16 +18,20 @@ async function generateGenesisValues(prefilledPublicData) {
|
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
export const defaultInitialAccountFeeJuice = new Fr(10n ** 22n);
|
|
21
|
-
export async function getGenesisValues(initialAccounts, initialAccountFeeJuice = defaultInitialAccountFeeJuice, genesisPublicData = []) {
|
|
21
|
+
export async function getGenesisValues(initialAccounts, initialAccountFeeJuice = defaultInitialAccountFeeJuice, genesisPublicData = [], genesisTimestamp = 0n) {
|
|
22
22
|
// Top up the accounts with fee juice.
|
|
23
23
|
let prefilledPublicData = await Promise.all(initialAccounts.map(async (address)=>new PublicDataTreeLeaf(await computeFeePayerBalanceLeafSlot(address), initialAccountFeeJuice)));
|
|
24
24
|
// Add user-defined public data
|
|
25
25
|
prefilledPublicData = prefilledPublicData.concat(genesisPublicData);
|
|
26
26
|
prefilledPublicData.sort((a, b)=>b.slot.lt(a.slot) ? 1 : -1);
|
|
27
|
-
const
|
|
27
|
+
const genesis = {
|
|
28
|
+
prefilledPublicData,
|
|
29
|
+
genesisTimestamp
|
|
30
|
+
};
|
|
31
|
+
const { genesisArchiveRoot } = await generateGenesisValues(genesis);
|
|
28
32
|
return {
|
|
29
33
|
genesisArchiveRoot,
|
|
30
|
-
|
|
34
|
+
genesis,
|
|
31
35
|
fundingNeeded: BigInt(initialAccounts.length) * initialAccountFeeJuice.toBigInt()
|
|
32
36
|
};
|
|
33
37
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import type {
|
|
4
|
-
import type { L2BlockNew } from '@aztec/stdlib/block';
|
|
3
|
+
import type { L2Block } from '@aztec/stdlib/block';
|
|
5
4
|
import type { ForkMerkleTreeOperations, MerkleTreeReadOperations, ReadonlyWorldStateAccess } from '@aztec/stdlib/interfaces/server';
|
|
6
|
-
import type { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
7
5
|
import type { WorldStateStatusFull, WorldStateStatusSummary } from '../native/message.js';
|
|
8
6
|
/**
|
|
9
7
|
*
|
|
@@ -22,20 +20,13 @@ import type { WorldStateStatusFull, WorldStateStatusSummary } from '../native/me
|
|
|
22
20
|
*/
|
|
23
21
|
export declare const INITIAL_NULLIFIER_TREE_SIZE: number;
|
|
24
22
|
export declare const INITIAL_PUBLIC_DATA_TREE_SIZE: number;
|
|
25
|
-
export type TreeSnapshots = {
|
|
26
|
-
[MerkleTreeId.NULLIFIER_TREE]: IndexedTreeSnapshot;
|
|
27
|
-
[MerkleTreeId.NOTE_HASH_TREE]: TreeSnapshot<Fr>;
|
|
28
|
-
[MerkleTreeId.PUBLIC_DATA_TREE]: IndexedTreeSnapshot;
|
|
29
|
-
[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: TreeSnapshot<Fr>;
|
|
30
|
-
[MerkleTreeId.ARCHIVE]: TreeSnapshot<Fr>;
|
|
31
|
-
};
|
|
32
23
|
export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations, ReadonlyWorldStateAccess {
|
|
33
24
|
/**
|
|
34
25
|
* Handles a single L2 block (i.e. Inserts the new note hashes into the merkle tree).
|
|
35
26
|
* @param block - The L2 block to handle.
|
|
36
27
|
* @param l1ToL2Messages - The L1 to L2 messages for the block.
|
|
37
28
|
*/
|
|
38
|
-
handleL2BlockAndMessages(block:
|
|
29
|
+
handleL2BlockAndMessages(block: L2Block, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull>;
|
|
39
30
|
/**
|
|
40
31
|
* Gets a handle that allows reading the latest committed state
|
|
41
32
|
*/
|
|
@@ -68,4 +59,4 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations, Reado
|
|
|
68
59
|
/** Deletes the db. */
|
|
69
60
|
clear(): Promise<void>;
|
|
70
61
|
}
|
|
71
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
62
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVya2xlX3RyZWVfZGIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93b3JsZC1zdGF0ZS1kYi9tZXJrbGVfdHJlZV9kYi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNuRSxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUN6RCxPQUFPLEtBQUssRUFBRSxPQUFPLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUNuRCxPQUFPLEtBQUssRUFDVix3QkFBd0IsRUFDeEIsd0JBQXdCLEVBQ3hCLHdCQUF3QixFQUN6QixNQUFNLGlDQUFpQyxDQUFDO0FBRXpDLE9BQU8sS0FBSyxFQUFFLG9CQ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_tree_db.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"merkle_tree_db.d.ts","sourceRoot":"","sources":["../../src/world-state-db/merkle_tree_db.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EACV,wBAAwB,EACxB,wBAAwB,EACxB,wBAAwB,EACzB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,KAAK,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAE1F;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,2BAA2B,QAA4B,CAAC;AAErE,eAAO,MAAM,6BAA6B,QAAmD,CAAC;AAE9F,MAAM,WAAW,uBAAwB,SAAQ,wBAAwB,EAAE,wBAAwB;IACjG;;;;OAIG;IACH,wBAAwB,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAE9F;;OAEG;IACH,YAAY,IAAI,wBAAwB,CAAC;IAEzC;;;;OAIG;IACH,sBAAsB,CAAC,aAAa,EAAE,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAElF;;;;OAIG;IACH,YAAY,CAAC,aAAa,EAAE,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAExE;;;;OAIG;IACH,YAAY,CAAC,aAAa,EAAE,WAAW,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAE3E;;;OAGG;IACH,gBAAgB,IAAI,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAErD,yBAAyB;IACzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB,sBAAsB;IACtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/world-state",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.d939eb5aa",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -64,19 +64,18 @@
|
|
|
64
64
|
]
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@aztec/constants": "0.0.1-commit.
|
|
68
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
69
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
70
|
-
"@aztec/
|
|
71
|
-
"@aztec/
|
|
72
|
-
"@aztec/
|
|
73
|
-
"@aztec/
|
|
74
|
-
"@aztec/telemetry-client": "0.0.1-commit.d431d1c",
|
|
67
|
+
"@aztec/constants": "0.0.1-commit.d939eb5aa",
|
|
68
|
+
"@aztec/foundation": "0.0.1-commit.d939eb5aa",
|
|
69
|
+
"@aztec/kv-store": "0.0.1-commit.d939eb5aa",
|
|
70
|
+
"@aztec/native": "0.0.1-commit.d939eb5aa",
|
|
71
|
+
"@aztec/protocol-contracts": "0.0.1-commit.d939eb5aa",
|
|
72
|
+
"@aztec/stdlib": "0.0.1-commit.d939eb5aa",
|
|
73
|
+
"@aztec/telemetry-client": "0.0.1-commit.d939eb5aa",
|
|
75
74
|
"tslib": "^2.4.0",
|
|
76
75
|
"zod": "^3.23.8"
|
|
77
76
|
},
|
|
78
77
|
"devDependencies": {
|
|
79
|
-
"@aztec/archiver": "0.0.1-commit.
|
|
78
|
+
"@aztec/archiver": "0.0.1-commit.d939eb5aa",
|
|
80
79
|
"@jest/globals": "^30.0.0",
|
|
81
80
|
"@types/jest": "^30.0.0",
|
|
82
81
|
"@types/node": "^22.15.17",
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
Metrics,
|
|
8
8
|
type TelemetryClient,
|
|
9
9
|
type UpDownCounter,
|
|
10
|
+
createUpDownCounterWithDefault,
|
|
10
11
|
} from '@aztec/telemetry-client';
|
|
11
12
|
|
|
12
13
|
import {
|
|
@@ -63,7 +64,14 @@ export class WorldStateInstrumentation {
|
|
|
63
64
|
|
|
64
65
|
this.requestHistogram = meter.createHistogram(Metrics.WORLD_STATE_REQUEST_TIME);
|
|
65
66
|
|
|
66
|
-
this.criticalErrors = meter
|
|
67
|
+
this.criticalErrors = createUpDownCounterWithDefault(meter, Metrics.WORLD_STATE_CRITICAL_ERROR_COUNT, {
|
|
68
|
+
[Attributes.ERROR_TYPE]: [
|
|
69
|
+
'synch_pending_block',
|
|
70
|
+
'finalize_block',
|
|
71
|
+
'prune_pending_block',
|
|
72
|
+
'prune_historical_block',
|
|
73
|
+
],
|
|
74
|
+
});
|
|
67
75
|
}
|
|
68
76
|
|
|
69
77
|
private updateTreeStats(treeDbStats: TreeDBStats, treeMeta: TreeMeta, tree: MerkleTreeId) {
|
|
@@ -3,11 +3,14 @@ import type { MerkleTreeCheckpointOperations } from '@aztec/stdlib/interfaces/se
|
|
|
3
3
|
export class ForkCheckpoint {
|
|
4
4
|
private completed = false;
|
|
5
5
|
|
|
6
|
-
private constructor(
|
|
6
|
+
private constructor(
|
|
7
|
+
private readonly fork: MerkleTreeCheckpointOperations,
|
|
8
|
+
public readonly depth: number,
|
|
9
|
+
) {}
|
|
7
10
|
|
|
8
11
|
static async new(fork: MerkleTreeCheckpointOperations): Promise<ForkCheckpoint> {
|
|
9
|
-
await fork.createCheckpoint();
|
|
10
|
-
return new ForkCheckpoint(fork);
|
|
12
|
+
const depth = await fork.createCheckpoint();
|
|
13
|
+
return new ForkCheckpoint(fork, depth);
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
async commit(): Promise<void> {
|
|
@@ -27,4 +30,17 @@ export class ForkCheckpoint {
|
|
|
27
30
|
await this.fork.revertCheckpoint();
|
|
28
31
|
this.completed = true;
|
|
29
32
|
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Reverts this checkpoint and any nested checkpoints created on top of it,
|
|
36
|
+
* leaving the checkpoint depth at the level it was before this checkpoint was created.
|
|
37
|
+
*/
|
|
38
|
+
async revertToCheckpoint(): Promise<void> {
|
|
39
|
+
if (this.completed) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
await this.fork.revertAllCheckpointsTo(this.depth - 1);
|
|
44
|
+
this.completed = true;
|
|
45
|
+
}
|
|
30
46
|
}
|
|
@@ -4,6 +4,7 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
4
4
|
import { serializeToBuffer } from '@aztec/foundation/serialize';
|
|
5
5
|
import { sleep } from '@aztec/foundation/sleep';
|
|
6
6
|
import { type IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
|
|
7
|
+
import { BlockHash } from '@aztec/stdlib/block';
|
|
7
8
|
import type {
|
|
8
9
|
BatchInsertionResult,
|
|
9
10
|
IndexedTreeId,
|
|
@@ -118,7 +119,7 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations {
|
|
|
118
119
|
|
|
119
120
|
const leaf = deserializeLeafValue(resp);
|
|
120
121
|
if (leaf instanceof Fr) {
|
|
121
|
-
return leaf as any;
|
|
122
|
+
return treeId === MerkleTreeId.ARCHIVE ? (new BlockHash(leaf) as any) : (leaf as any);
|
|
122
123
|
} else {
|
|
123
124
|
return leaf.toBuffer() as any;
|
|
124
125
|
}
|
|
@@ -228,7 +229,7 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
228
229
|
|
|
229
230
|
async appendLeaves<ID extends MerkleTreeId>(treeId: ID, leaves: MerkleTreeLeafType<ID>[]): Promise<void> {
|
|
230
231
|
await this.instance.call(WorldStateMessageType.APPEND_LEAVES, {
|
|
231
|
-
leaves: leaves.map(leaf => leaf as any),
|
|
232
|
+
leaves: leaves.map(leaf => serializeLeaf(hydrateLeaf(treeId, leaf as any))),
|
|
232
233
|
forkId: this.revision.forkId,
|
|
233
234
|
treeId,
|
|
234
235
|
});
|
|
@@ -304,7 +305,7 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
304
305
|
}
|
|
305
306
|
}
|
|
306
307
|
|
|
307
|
-
async [Symbol.
|
|
308
|
+
async [Symbol.asyncDispose](): Promise<void> {
|
|
308
309
|
if (this.opts.closeDelayMs) {
|
|
309
310
|
void sleep(this.opts.closeDelayMs)
|
|
310
311
|
.then(() => this.close())
|
|
@@ -319,9 +320,10 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
319
320
|
}
|
|
320
321
|
}
|
|
321
322
|
|
|
322
|
-
public async createCheckpoint(): Promise<
|
|
323
|
+
public async createCheckpoint(): Promise<number> {
|
|
323
324
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
324
|
-
await this.instance.call(WorldStateMessageType.CREATE_CHECKPOINT, { forkId: this.revision.forkId });
|
|
325
|
+
const resp = await this.instance.call(WorldStateMessageType.CREATE_CHECKPOINT, { forkId: this.revision.forkId });
|
|
326
|
+
return resp.depth;
|
|
325
327
|
}
|
|
326
328
|
|
|
327
329
|
public async commitCheckpoint(): Promise<void> {
|
|
@@ -334,20 +336,28 @@ export class MerkleTreesForkFacade extends MerkleTreesFacade implements MerkleTr
|
|
|
334
336
|
await this.instance.call(WorldStateMessageType.REVERT_CHECKPOINT, { forkId: this.revision.forkId });
|
|
335
337
|
}
|
|
336
338
|
|
|
337
|
-
public async
|
|
339
|
+
public async commitAllCheckpointsTo(depth: number): Promise<void> {
|
|
338
340
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
339
|
-
await this.instance.call(WorldStateMessageType.COMMIT_ALL_CHECKPOINTS, {
|
|
341
|
+
await this.instance.call(WorldStateMessageType.COMMIT_ALL_CHECKPOINTS, {
|
|
342
|
+
forkId: this.revision.forkId,
|
|
343
|
+
depth,
|
|
344
|
+
});
|
|
340
345
|
}
|
|
341
346
|
|
|
342
|
-
public async
|
|
347
|
+
public async revertAllCheckpointsTo(depth: number): Promise<void> {
|
|
343
348
|
assert.notEqual(this.revision.forkId, 0, 'Fork ID must be set');
|
|
344
|
-
await this.instance.call(WorldStateMessageType.REVERT_ALL_CHECKPOINTS, {
|
|
349
|
+
await this.instance.call(WorldStateMessageType.REVERT_ALL_CHECKPOINTS, {
|
|
350
|
+
forkId: this.revision.forkId,
|
|
351
|
+
depth,
|
|
352
|
+
});
|
|
345
353
|
}
|
|
346
354
|
}
|
|
347
355
|
|
|
348
|
-
function hydrateLeaf
|
|
356
|
+
function hydrateLeaf(treeId: MerkleTreeId, leaf: Fr | BlockHash | Buffer) {
|
|
349
357
|
if (leaf instanceof Fr) {
|
|
350
358
|
return leaf;
|
|
359
|
+
} else if (leaf instanceof BlockHash) {
|
|
360
|
+
return leaf.toFr();
|
|
351
361
|
} else if (treeId === MerkleTreeId.NULLIFIER_TREE) {
|
|
352
362
|
return NullifierLeaf.fromBuffer(leaf);
|
|
353
363
|
} else if (treeId === MerkleTreeId.PUBLIC_DATA_TREE) {
|
|
@@ -357,8 +367,10 @@ function hydrateLeaf<ID extends MerkleTreeId>(treeId: ID, leaf: Fr | Buffer) {
|
|
|
357
367
|
}
|
|
358
368
|
}
|
|
359
369
|
|
|
360
|
-
export function serializeLeaf(leaf: Fr | NullifierLeaf | PublicDataTreeLeaf): SerializedLeafValue {
|
|
361
|
-
if (leaf instanceof
|
|
370
|
+
export function serializeLeaf(leaf: Fr | BlockHash | NullifierLeaf | PublicDataTreeLeaf): SerializedLeafValue {
|
|
371
|
+
if (leaf instanceof BlockHash) {
|
|
372
|
+
return leaf.toBuffer();
|
|
373
|
+
} else if (leaf instanceof Fr) {
|
|
362
374
|
return leaf.toBuffer();
|
|
363
375
|
} else if (leaf instanceof NullifierLeaf) {
|
|
364
376
|
return { nullifier: leaf.nullifier.toBuffer() };
|
package/src/native/message.ts
CHANGED
|
@@ -283,6 +283,16 @@ interface WithForkId {
|
|
|
283
283
|
forkId: number;
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
+
interface CreateCheckpointResponse {
|
|
287
|
+
depth: number;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** Request to commit/revert all checkpoints down to a target depth. The resulting depth after the operation equals the given depth. */
|
|
291
|
+
interface CheckpointDepthRequest extends WithForkId {
|
|
292
|
+
/** The target depth after the operation. All checkpoints above this depth are committed/reverted. */
|
|
293
|
+
depth: number;
|
|
294
|
+
}
|
|
295
|
+
|
|
286
296
|
interface WithWorldStateRevision {
|
|
287
297
|
revision: WorldStateRevision;
|
|
288
298
|
}
|
|
@@ -412,7 +422,7 @@ interface UpdateArchiveRequest extends WithForkId {
|
|
|
412
422
|
interface SyncBlockRequest extends WithCanonicalForkId {
|
|
413
423
|
blockNumber: BlockNumber;
|
|
414
424
|
blockStateRef: BlockStateReference;
|
|
415
|
-
blockHeaderHash:
|
|
425
|
+
blockHeaderHash: Buffer;
|
|
416
426
|
paddedNoteHashes: readonly SerializedLeafValue[];
|
|
417
427
|
paddedL1ToL2Messages: readonly SerializedLeafValue[];
|
|
418
428
|
paddedNullifiers: readonly SerializedLeafValue[];
|
|
@@ -486,8 +496,8 @@ export type WorldStateRequest = {
|
|
|
486
496
|
[WorldStateMessageType.CREATE_CHECKPOINT]: WithForkId;
|
|
487
497
|
[WorldStateMessageType.COMMIT_CHECKPOINT]: WithForkId;
|
|
488
498
|
[WorldStateMessageType.REVERT_CHECKPOINT]: WithForkId;
|
|
489
|
-
[WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]:
|
|
490
|
-
[WorldStateMessageType.REVERT_ALL_CHECKPOINTS]:
|
|
499
|
+
[WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]: CheckpointDepthRequest;
|
|
500
|
+
[WorldStateMessageType.REVERT_ALL_CHECKPOINTS]: CheckpointDepthRequest;
|
|
491
501
|
|
|
492
502
|
[WorldStateMessageType.COPY_STORES]: CopyStoresRequest;
|
|
493
503
|
|
|
@@ -528,7 +538,7 @@ export type WorldStateResponse = {
|
|
|
528
538
|
|
|
529
539
|
[WorldStateMessageType.GET_STATUS]: WorldStateStatusSummary;
|
|
530
540
|
|
|
531
|
-
[WorldStateMessageType.CREATE_CHECKPOINT]:
|
|
541
|
+
[WorldStateMessageType.CREATE_CHECKPOINT]: CreateCheckpointResponse;
|
|
532
542
|
[WorldStateMessageType.COMMIT_CHECKPOINT]: void;
|
|
533
543
|
[WorldStateMessageType.REVERT_CHECKPOINT]: void;
|
|
534
544
|
[WorldStateMessageType.COMMIT_ALL_CHECKPOINTS]: void;
|
|
@@ -4,9 +4,9 @@ import { fromEntries, padArrayEnd } from '@aztec/foundation/collection';
|
|
|
4
4
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
5
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
6
|
import { tryRmDir } from '@aztec/foundation/fs';
|
|
7
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
8
|
-
import type {
|
|
9
|
-
import { DatabaseVersionManager } from '@aztec/stdlib/database-version';
|
|
7
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
8
|
+
import type { L2Block } from '@aztec/stdlib/block';
|
|
9
|
+
import { DatabaseVersionManager } from '@aztec/stdlib/database-version/manager';
|
|
10
10
|
import type {
|
|
11
11
|
IndexedTreeId,
|
|
12
12
|
MerkleTreeReadOperations,
|
|
@@ -14,8 +14,8 @@ import type {
|
|
|
14
14
|
} from '@aztec/stdlib/interfaces/server';
|
|
15
15
|
import type { SnapshotDataKeys } from '@aztec/stdlib/snapshots';
|
|
16
16
|
import { MerkleTreeId, NullifierLeaf, type NullifierLeafPreimage, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
17
|
-
import { BlockHeader, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
|
|
18
|
-
import { WorldStateRevision } from '@aztec/stdlib/world-state';
|
|
17
|
+
import { BlockHeader, GlobalVariables, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
|
|
18
|
+
import { EMPTY_GENESIS_DATA, type GenesisData, WorldStateRevision } from '@aztec/stdlib/world-state';
|
|
19
19
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
20
20
|
|
|
21
21
|
import assert from 'assert/strict';
|
|
@@ -52,7 +52,8 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
52
52
|
protected constructor(
|
|
53
53
|
protected instance: NativeWorldState,
|
|
54
54
|
protected readonly worldStateInstrumentation: WorldStateInstrumentation,
|
|
55
|
-
protected readonly log: Logger
|
|
55
|
+
protected readonly log: Logger,
|
|
56
|
+
private readonly genesis: GenesisData = EMPTY_GENESIS_DATA,
|
|
56
57
|
private readonly cleanup = () => Promise.resolve(),
|
|
57
58
|
) {}
|
|
58
59
|
|
|
@@ -60,11 +61,12 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
60
61
|
rollupAddress: EthAddress,
|
|
61
62
|
dataDir: string,
|
|
62
63
|
wsTreeMapSizes: WorldStateTreeMapSizes,
|
|
63
|
-
|
|
64
|
+
genesis: GenesisData = EMPTY_GENESIS_DATA,
|
|
64
65
|
instrumentation = new WorldStateInstrumentation(getTelemetryClient()),
|
|
65
|
-
|
|
66
|
+
bindings?: LoggerBindings,
|
|
66
67
|
cleanup = () => Promise.resolve(),
|
|
67
68
|
): Promise<NativeWorldStateService> {
|
|
69
|
+
const log = createLogger('world-state:database', bindings);
|
|
68
70
|
const worldStateDirectory = join(dataDir, WORLD_STATE_DIR);
|
|
69
71
|
// Create a version manager to handle versioning
|
|
70
72
|
const versionManager = new DatabaseVersionManager({
|
|
@@ -72,12 +74,12 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
72
74
|
rollupAddress,
|
|
73
75
|
dataDirectory: worldStateDirectory,
|
|
74
76
|
onOpen: (dir: string) => {
|
|
75
|
-
return Promise.resolve(new NativeWorldState(dir, wsTreeMapSizes,
|
|
77
|
+
return Promise.resolve(new NativeWorldState(dir, wsTreeMapSizes, genesis, instrumentation, bindings));
|
|
76
78
|
},
|
|
77
79
|
});
|
|
78
80
|
|
|
79
81
|
const [instance] = await versionManager.open();
|
|
80
|
-
const worldState = new this(instance, instrumentation, log, cleanup);
|
|
82
|
+
const worldState = new this(instance, instrumentation, log, genesis, cleanup);
|
|
81
83
|
try {
|
|
82
84
|
await worldState.init();
|
|
83
85
|
} catch (e) {
|
|
@@ -91,10 +93,11 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
91
93
|
static async tmp(
|
|
92
94
|
rollupAddress = EthAddress.ZERO,
|
|
93
95
|
cleanupTmpDir = true,
|
|
94
|
-
|
|
96
|
+
genesis: GenesisData = EMPTY_GENESIS_DATA,
|
|
95
97
|
instrumentation = new WorldStateInstrumentation(getTelemetryClient()),
|
|
98
|
+
bindings?: LoggerBindings,
|
|
96
99
|
): Promise<NativeWorldStateService> {
|
|
97
|
-
const log = createLogger('world-state:database');
|
|
100
|
+
const log = createLogger('world-state:database', bindings);
|
|
98
101
|
const dataDir = await mkdtemp(join(tmpdir(), 'aztec-world-state-'));
|
|
99
102
|
const dbMapSizeKb = 10 * 1024 * 1024;
|
|
100
103
|
const worldStateTreeMapSizes: WorldStateTreeMapSizes = {
|
|
@@ -116,7 +119,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
116
119
|
}
|
|
117
120
|
};
|
|
118
121
|
|
|
119
|
-
return this.new(rollupAddress, dataDir, worldStateTreeMapSizes,
|
|
122
|
+
return this.new(rollupAddress, dataDir, worldStateTreeMapSizes, genesis, instrumentation, bindings, cleanup);
|
|
120
123
|
}
|
|
121
124
|
|
|
122
125
|
protected async init() {
|
|
@@ -184,7 +187,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
184
187
|
return this.initialHeader!;
|
|
185
188
|
}
|
|
186
189
|
|
|
187
|
-
public async handleL2BlockAndMessages(l2Block:
|
|
190
|
+
public async handleL2BlockAndMessages(l2Block: L2Block, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull> {
|
|
188
191
|
const isFirstBlock = l2Block.indexWithinCheckpoint === 0;
|
|
189
192
|
if (!isFirstBlock && l1ToL2Messages.length > 0) {
|
|
190
193
|
throw new Error(
|
|
@@ -220,7 +223,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
220
223
|
WorldStateMessageType.SYNC_BLOCK,
|
|
221
224
|
{
|
|
222
225
|
blockNumber: l2Block.number,
|
|
223
|
-
blockHeaderHash: await l2Block.hash(),
|
|
226
|
+
blockHeaderHash: (await l2Block.hash()).toBuffer(),
|
|
224
227
|
paddedL1ToL2Messages: paddedL1ToL2Messages.map(serializeLeaf),
|
|
225
228
|
paddedNoteHashes: paddedNoteHashes.map(serializeLeaf),
|
|
226
229
|
paddedNullifiers: paddedNullifiers.map(serializeLeaf),
|
|
@@ -244,7 +247,10 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
244
247
|
|
|
245
248
|
private async buildInitialHeader(): Promise<BlockHeader> {
|
|
246
249
|
const state = await this.getInitialStateReference();
|
|
247
|
-
return BlockHeader.empty({
|
|
250
|
+
return BlockHeader.empty({
|
|
251
|
+
state,
|
|
252
|
+
globalVariables: GlobalVariables.empty({ timestamp: this.genesis.genesisTimestamp }),
|
|
253
|
+
});
|
|
248
254
|
}
|
|
249
255
|
|
|
250
256
|
private sanitizeAndCacheSummaryFromFull(response: WorldStateStatusFull) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ARCHIVE_HEIGHT,
|
|
3
|
-
|
|
3
|
+
DomainSeparator,
|
|
4
4
|
L1_TO_L2_MSG_TREE_HEIGHT,
|
|
5
5
|
MAX_NULLIFIERS_PER_TX,
|
|
6
6
|
MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
NULLIFIER_TREE_HEIGHT,
|
|
9
9
|
PUBLIC_DATA_TREE_HEIGHT,
|
|
10
10
|
} from '@aztec/constants';
|
|
11
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
11
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
12
12
|
import { NativeWorldState as BaseNativeWorldState, MsgpackChannel } from '@aztec/native';
|
|
13
13
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
14
|
-
import type
|
|
14
|
+
import { EMPTY_GENESIS_DATA, type GenesisData } from '@aztec/stdlib/world-state';
|
|
15
15
|
|
|
16
16
|
import assert from 'assert';
|
|
17
17
|
import { cpus } from 'os';
|
|
@@ -55,9 +55,10 @@ export class NativeWorldState implements NativeWorldStateInstance {
|
|
|
55
55
|
constructor(
|
|
56
56
|
private readonly dataDir: string,
|
|
57
57
|
private readonly wsTreeMapSizes: WorldStateTreeMapSizes,
|
|
58
|
-
private readonly
|
|
58
|
+
private readonly genesis: GenesisData = EMPTY_GENESIS_DATA,
|
|
59
59
|
private readonly instrumentation: WorldStateInstrumentation,
|
|
60
|
-
|
|
60
|
+
bindings?: LoggerBindings,
|
|
61
|
+
private readonly log: Logger = createLogger('world-state:database', bindings),
|
|
61
62
|
) {
|
|
62
63
|
const threads = Math.min(cpus().length, MAX_WORLD_STATE_THREADS);
|
|
63
64
|
log.info(
|
|
@@ -65,7 +66,10 @@ export class NativeWorldState implements NativeWorldStateInstance {
|
|
|
65
66
|
wsTreeMapSizes,
|
|
66
67
|
)} and ${threads} threads.`,
|
|
67
68
|
);
|
|
68
|
-
const prefilledPublicDataBufferArray = prefilledPublicData.map(d => [
|
|
69
|
+
const prefilledPublicDataBufferArray = genesis.prefilledPublicData.map(d => [
|
|
70
|
+
d.slot.toBuffer(),
|
|
71
|
+
d.value.toBuffer(),
|
|
72
|
+
]);
|
|
69
73
|
const ws = new BaseNativeWorldState(
|
|
70
74
|
dataDir,
|
|
71
75
|
{
|
|
@@ -80,7 +84,8 @@ export class NativeWorldState implements NativeWorldStateInstance {
|
|
|
80
84
|
[MerkleTreeId.PUBLIC_DATA_TREE]: 2 * MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
81
85
|
},
|
|
82
86
|
prefilledPublicDataBufferArray,
|
|
83
|
-
|
|
87
|
+
DomainSeparator.BLOCK_HEADER_HASH,
|
|
88
|
+
Number(genesis.genesisTimestamp),
|
|
84
89
|
{
|
|
85
90
|
[MerkleTreeId.NULLIFIER_TREE]: wsTreeMapSizes.nullifierTreeMapSizeKb,
|
|
86
91
|
[MerkleTreeId.NOTE_HASH_TREE]: wsTreeMapSizes.noteHashTreeMapSizeKb,
|
|
@@ -103,8 +108,9 @@ export class NativeWorldState implements NativeWorldStateInstance {
|
|
|
103
108
|
return new NativeWorldState(
|
|
104
109
|
this.dataDir,
|
|
105
110
|
this.wsTreeMapSizes,
|
|
106
|
-
this.
|
|
111
|
+
this.genesis,
|
|
107
112
|
this.instrumentation,
|
|
113
|
+
this.log.getBindings(),
|
|
108
114
|
this.log,
|
|
109
115
|
);
|
|
110
116
|
}
|