@aztec-labs/world-state 6.0.0-nightly.20260829
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/README.md +40 -0
- package/dest/index.d.ts +6 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +5 -0
- package/dest/instrumentation/instrumentation.d.ts +25 -0
- package/dest/instrumentation/instrumentation.d.ts.map +1 -0
- package/dest/instrumentation/instrumentation.js +96 -0
- package/dest/native/bench_metrics.d.ts +23 -0
- package/dest/native/bench_metrics.d.ts.map +1 -0
- package/dest/native/bench_metrics.js +81 -0
- package/dest/native/fork_checkpoint.d.ts +16 -0
- package/dest/native/fork_checkpoint.d.ts.map +1 -0
- package/dest/native/fork_checkpoint.js +38 -0
- package/dest/native/index.d.ts +4 -0
- package/dest/native/index.d.ts.map +1 -0
- package/dest/native/index.js +3 -0
- package/dest/native/ipc_world_state_instance.d.ts +91 -0
- package/dest/native/ipc_world_state_instance.d.ts.map +1 -0
- package/dest/native/ipc_world_state_instance.js +672 -0
- package/dest/native/merkle_trees_facade.d.ts +58 -0
- package/dest/native/merkle_trees_facade.d.ts.map +1 -0
- package/dest/native/merkle_trees_facade.js +250 -0
- package/dest/native/message.d.ts +145 -0
- package/dest/native/message.d.ts.map +1 -0
- package/dest/native/message.js +150 -0
- package/dest/native/native_world_state.d.ts +77 -0
- package/dest/native/native_world_state.d.ts.map +1 -0
- package/dest/native/native_world_state.js +350 -0
- package/dest/native/native_world_state_instance.d.ts +63 -0
- package/dest/native/native_world_state_instance.d.ts.map +1 -0
- package/dest/native/native_world_state_instance.js +1 -0
- package/dest/native/world_state_operation.d.ts +7 -0
- package/dest/native/world_state_operation.d.ts.map +1 -0
- package/dest/native/world_state_operation.js +5 -0
- package/dest/synchronizer/config.d.ts +31 -0
- package/dest/synchronizer/config.d.ts.map +1 -0
- package/dest/synchronizer/config.js +61 -0
- package/dest/synchronizer/errors.d.ts +11 -0
- package/dest/synchronizer/errors.d.ts.map +1 -0
- package/dest/synchronizer/errors.js +12 -0
- package/dest/synchronizer/factory.d.ts +20 -0
- package/dest/synchronizer/factory.d.ts.map +1 -0
- package/dest/synchronizer/factory.js +30 -0
- package/dest/synchronizer/index.d.ts +4 -0
- package/dest/synchronizer/index.d.ts.map +1 -0
- package/dest/synchronizer/index.js +3 -0
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +83 -0
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -0
- package/dest/synchronizer/server_world_state_synchronizer.js +434 -0
- package/dest/test/index.d.ts +2 -0
- package/dest/test/index.d.ts.map +1 -0
- package/dest/test/index.js +1 -0
- package/dest/test/utils.d.ts +35 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +118 -0
- package/dest/testing.d.ts +11 -0
- package/dest/testing.d.ts.map +1 -0
- package/dest/testing.js +48 -0
- package/dest/world-state-db/index.d.ts +3 -0
- package/dest/world-state-db/index.d.ts.map +1 -0
- package/dest/world-state-db/index.js +1 -0
- package/dest/world-state-db/merkle_tree_db.d.ts +65 -0
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -0
- package/dest/world-state-db/merkle_tree_db.js +17 -0
- package/package.json +98 -0
- package/src/index.ts +5 -0
- package/src/instrumentation/instrumentation.ts +150 -0
- package/src/native/bench_metrics.ts +91 -0
- package/src/native/fork_checkpoint.ts +46 -0
- package/src/native/index.ts +3 -0
- package/src/native/ipc_world_state_instance.ts +849 -0
- package/src/native/merkle_trees_facade.ts +375 -0
- package/src/native/message.ts +287 -0
- package/src/native/native_world_state.ts +435 -0
- package/src/native/native_world_state_instance.ts +104 -0
- package/src/native/world_state_operation.ts +33 -0
- package/src/synchronizer/config.ts +106 -0
- package/src/synchronizer/errors.ts +13 -0
- package/src/synchronizer/factory.ts +83 -0
- package/src/synchronizer/index.ts +3 -0
- package/src/synchronizer/server_world_state_synchronizer.ts +525 -0
- package/src/test/index.ts +1 -0
- package/src/test/utils.ts +184 -0
- package/src/testing.ts +65 -0
- package/src/world-state-db/index.ts +3 -0
- package/src/world-state-db/merkle_tree_db.ts +80 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MAX_L1_TO_L2_MSGS_PER_CHECKPOINT,
|
|
3
|
+
MAX_NOTE_HASHES_PER_TX,
|
|
4
|
+
MAX_NULLIFIERS_PER_TX,
|
|
5
|
+
NULLIFIER_SUBTREE_HEIGHT,
|
|
6
|
+
} from '@aztec-labs/constants';
|
|
7
|
+
import { asyncMap } from '@aztec-labs/foundation/async-map';
|
|
8
|
+
import { BlockNumber, type CheckpointNumber, IndexWithinCheckpoint } from '@aztec-labs/foundation/branded-types';
|
|
9
|
+
import { padArrayEnd } from '@aztec-labs/foundation/collection';
|
|
10
|
+
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
11
|
+
import { L2Block } from '@aztec-labs/stdlib/block';
|
|
12
|
+
import type {
|
|
13
|
+
IndexedTreeId,
|
|
14
|
+
MerkleTreeReadOperations,
|
|
15
|
+
MerkleTreeWriteOperations,
|
|
16
|
+
} from '@aztec-labs/stdlib/interfaces/server';
|
|
17
|
+
import { mockCheckpointAndMessages, mockL1ToL2Messages } from '@aztec-labs/stdlib/testing';
|
|
18
|
+
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec-labs/stdlib/trees';
|
|
19
|
+
import { BlockHeader } from '@aztec-labs/stdlib/tx';
|
|
20
|
+
|
|
21
|
+
import type { NativeWorldStateService } from '../native/native_world_state.js';
|
|
22
|
+
|
|
23
|
+
export async function updateBlockState(block: L2Block, l1ToL2Messages: Fr[], fork: MerkleTreeWriteOperations) {
|
|
24
|
+
const insertData = async (
|
|
25
|
+
treeId: IndexedTreeId,
|
|
26
|
+
data: Buffer[][],
|
|
27
|
+
subTreeHeight: number,
|
|
28
|
+
fork: MerkleTreeWriteOperations,
|
|
29
|
+
) => {
|
|
30
|
+
for (const dataBatch of data) {
|
|
31
|
+
await fork.batchInsert(treeId, dataBatch, subTreeHeight);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const publicDataInsert = insertData(
|
|
36
|
+
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
37
|
+
block.body.txEffects.map(txEffect => txEffect.publicDataWrites.map(write => write.toBuffer())),
|
|
38
|
+
0,
|
|
39
|
+
fork,
|
|
40
|
+
);
|
|
41
|
+
const nullifierInsert = insertData(
|
|
42
|
+
MerkleTreeId.NULLIFIER_TREE,
|
|
43
|
+
block.body.txEffects.map(txEffect =>
|
|
44
|
+
padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map(nullifier => nullifier.toBuffer()),
|
|
45
|
+
),
|
|
46
|
+
NULLIFIER_SUBTREE_HEIGHT,
|
|
47
|
+
fork,
|
|
48
|
+
);
|
|
49
|
+
const noteHashesPadded = block.body.txEffects.flatMap(txEffect =>
|
|
50
|
+
padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX),
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
// Every block appends its real message leaves unpadded at compact indices.
|
|
54
|
+
const noteHashInsert = fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
|
|
55
|
+
const messageInsert = fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2Messages);
|
|
56
|
+
await Promise.all([publicDataInsert, nullifierInsert, noteHashInsert, messageInsert]);
|
|
57
|
+
|
|
58
|
+
const state = await fork.getStateReference();
|
|
59
|
+
|
|
60
|
+
// Capture the archive root *before* appending this block so the header's lastArchive chains off the previous block.
|
|
61
|
+
// sync_block now verifies lastArchive against the committed archive root, so a block carrying an unchained value
|
|
62
|
+
// (e.g. the random lastArchive from L2Block.random) would be rejected as a divergence from the canonical chain.
|
|
63
|
+
const previousArchive = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
64
|
+
block.header = BlockHeader.from({
|
|
65
|
+
...block.header,
|
|
66
|
+
state,
|
|
67
|
+
lastArchive: new AppendOnlyTreeSnapshot(Fr.fromBuffer(previousArchive.root), Number(previousArchive.size)),
|
|
68
|
+
});
|
|
69
|
+
await fork.updateArchive(block.header);
|
|
70
|
+
|
|
71
|
+
const archiveState = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
72
|
+
|
|
73
|
+
block.archive = new AppendOnlyTreeSnapshot(Fr.fromBuffer(archiveState.root), Number(archiveState.size));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function mockBlock(
|
|
77
|
+
blockNum: BlockNumber,
|
|
78
|
+
size: number,
|
|
79
|
+
fork: MerkleTreeWriteOperations,
|
|
80
|
+
maxEffects: number | undefined = 1000, // Defaults to the maximum tx effects.
|
|
81
|
+
numL1ToL2Messages: number = MAX_L1_TO_L2_MSGS_PER_CHECKPOINT,
|
|
82
|
+
isFirstBlockInCheckpoint: boolean = true,
|
|
83
|
+
) {
|
|
84
|
+
return mockBlockWithIndex(blockNum, isFirstBlockInCheckpoint ? 0 : 1, size, fork, numL1ToL2Messages, maxEffects);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Builds a mock L2 block at an explicit position within its checkpoint, applying its state (including its L1-to-L2
|
|
89
|
+
* message bundle) to the given fork. Unlike {@link mockBlock}, the caller chooses the `indexWithinCheckpoint`, so
|
|
90
|
+
* non-first blocks can carry message bundles — exercising the per-block message insertion path.
|
|
91
|
+
*/
|
|
92
|
+
export async function mockBlockWithIndex(
|
|
93
|
+
blockNum: BlockNumber,
|
|
94
|
+
indexWithinCheckpoint: number,
|
|
95
|
+
size: number,
|
|
96
|
+
fork: MerkleTreeWriteOperations,
|
|
97
|
+
numL1ToL2Messages: number = MAX_L1_TO_L2_MSGS_PER_CHECKPOINT,
|
|
98
|
+
maxEffects: number | undefined = 1000, // Defaults to the maximum tx effects.
|
|
99
|
+
) {
|
|
100
|
+
const block = await L2Block.random(blockNum, {
|
|
101
|
+
indexWithinCheckpoint: IndexWithinCheckpoint(indexWithinCheckpoint),
|
|
102
|
+
txsPerBlock: size,
|
|
103
|
+
txOptions: { maxEffects },
|
|
104
|
+
});
|
|
105
|
+
const l1ToL2Messages = mockL1ToL2Messages(numL1ToL2Messages);
|
|
106
|
+
|
|
107
|
+
await updateBlockState(block, l1ToL2Messages, fork);
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
block,
|
|
111
|
+
messages: l1ToL2Messages,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export async function mockEmptyBlock(blockNum: BlockNumber, fork: MerkleTreeWriteOperations) {
|
|
116
|
+
const l2Block = L2Block.empty();
|
|
117
|
+
const l1ToL2Messages = Array(16).fill(0).map(Fr.zero);
|
|
118
|
+
|
|
119
|
+
l2Block.header.globalVariables.blockNumber = blockNum;
|
|
120
|
+
|
|
121
|
+
await updateBlockState(l2Block, l1ToL2Messages, fork);
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
block: l2Block,
|
|
125
|
+
messages: l1ToL2Messages,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export async function mockBlocks(
|
|
130
|
+
from: BlockNumber,
|
|
131
|
+
count: number,
|
|
132
|
+
numTxs: number,
|
|
133
|
+
worldState: NativeWorldStateService,
|
|
134
|
+
) {
|
|
135
|
+
const tempFork = await worldState.fork(BlockNumber(from - 1));
|
|
136
|
+
|
|
137
|
+
const blocks = [];
|
|
138
|
+
const messagesArray = [];
|
|
139
|
+
for (let blockNumber = from; blockNumber < from + count; blockNumber++) {
|
|
140
|
+
const { block, messages } = await mockBlock(BlockNumber(blockNumber), numTxs, tempFork);
|
|
141
|
+
blocks.push(block);
|
|
142
|
+
messagesArray.push(messages);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
await tempFork.close();
|
|
146
|
+
|
|
147
|
+
return { blocks, messages: messagesArray };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export async function mockCheckpoint(
|
|
151
|
+
checkpointNumber: CheckpointNumber,
|
|
152
|
+
fork: MerkleTreeWriteOperations,
|
|
153
|
+
options: Partial<Parameters<typeof mockCheckpointAndMessages>[1]> = {},
|
|
154
|
+
) {
|
|
155
|
+
const { checkpoint, messages } = await mockCheckpointAndMessages(checkpointNumber, options);
|
|
156
|
+
await asyncMap(checkpoint.blocks, async (block, i) => {
|
|
157
|
+
await updateBlockState(block, i === 0 ? messages : [], fork);
|
|
158
|
+
});
|
|
159
|
+
return { checkpoint, messages };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export async function assertSameState(forkA: MerkleTreeReadOperations, forkB: MerkleTreeReadOperations) {
|
|
163
|
+
const nativeStateRef = await forkA.getStateReference();
|
|
164
|
+
const nativeArchive = await forkA.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
165
|
+
const legacyStateRef = await forkB.getStateReference();
|
|
166
|
+
const legacyArchive = await forkB.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
167
|
+
|
|
168
|
+
expect(nativeStateRef).toEqual(legacyStateRef);
|
|
169
|
+
expect(nativeArchive).toEqual(legacyArchive);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export async function compareChains(left: MerkleTreeReadOperations, right: MerkleTreeReadOperations) {
|
|
173
|
+
for (const treeId of [
|
|
174
|
+
MerkleTreeId.ARCHIVE,
|
|
175
|
+
MerkleTreeId.L1_TO_L2_MESSAGE_TREE,
|
|
176
|
+
MerkleTreeId.NOTE_HASH_TREE,
|
|
177
|
+
MerkleTreeId.NULLIFIER_TREE,
|
|
178
|
+
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
179
|
+
]) {
|
|
180
|
+
expect(await left.getTreeInfo(treeId)).toEqual(await right.getTreeInfo(treeId));
|
|
181
|
+
|
|
182
|
+
expect(await left.getSiblingPath(treeId, 0n)).toEqual(await right.getSiblingPath(treeId, 0n));
|
|
183
|
+
}
|
|
184
|
+
}
|
package/src/testing.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { GENESIS_ARCHIVE_ROOT } from '@aztec-labs/constants';
|
|
2
|
+
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
3
|
+
import { computeFeePayerBalanceLeafSlot } from '@aztec-labs/protocol-contracts/fee-juice';
|
|
4
|
+
import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
|
|
5
|
+
import { MerkleTreeId, PublicDataTreeLeaf } from '@aztec-labs/stdlib/trees';
|
|
6
|
+
import type { GenesisData } from '@aztec-labs/stdlib/world-state';
|
|
7
|
+
|
|
8
|
+
import { NativeWorldStateService } from './native/index.js';
|
|
9
|
+
|
|
10
|
+
async function generateGenesisValues(genesis: GenesisData) {
|
|
11
|
+
// The GENESIS_ARCHIVE_ROOT constant reflects the canonical empty genesis (no public data, no prefilled nullifiers,
|
|
12
|
+
// timestamp 0), so we can only short-circuit when this genesis adds none of those on top.
|
|
13
|
+
if (!genesis.prefilledPublicData.length && genesis.genesisTimestamp === 0n && !genesis.prefilledNullifiers?.length) {
|
|
14
|
+
return {
|
|
15
|
+
genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Compute the genesis values on a throwaway world state. The archive root derives deterministically from the
|
|
20
|
+
// prefilled public data, the prefilled nullifiers, and the genesis timestamp, so the fsync-off ephemeral store (no
|
|
21
|
+
// version manager, no crash-recoverability) produces an identical root while skipping the fsync overhead that `tmp`
|
|
22
|
+
// pays. close() removes the tmpdir.
|
|
23
|
+
const ws = await NativeWorldStateService.ephemeral(genesis);
|
|
24
|
+
const genesisArchiveRoot = new Fr((await ws.getCommitted().getTreeInfo(MerkleTreeId.ARCHIVE)).root);
|
|
25
|
+
await ws.close();
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
genesisArchiveRoot,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const defaultInitialAccountFeeJuice = new Fr(10n ** 22n);
|
|
33
|
+
|
|
34
|
+
export async function getGenesisValues(
|
|
35
|
+
initialAccounts: AztecAddress[],
|
|
36
|
+
initialAccountFeeJuice = defaultInitialAccountFeeJuice,
|
|
37
|
+
genesisPublicData: PublicDataTreeLeaf[] = [],
|
|
38
|
+
genesisTimestamp: bigint = 0n,
|
|
39
|
+
prefilledNullifiers: Fr[] = [],
|
|
40
|
+
) {
|
|
41
|
+
// Top up the accounts with fee juice.
|
|
42
|
+
let prefilledPublicData = await Promise.all(
|
|
43
|
+
initialAccounts.map(
|
|
44
|
+
async address => new PublicDataTreeLeaf(await computeFeePayerBalanceLeafSlot(address), initialAccountFeeJuice),
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
// Add user-defined public data
|
|
49
|
+
prefilledPublicData = prefilledPublicData.concat(genesisPublicData);
|
|
50
|
+
|
|
51
|
+
prefilledPublicData.sort((a, b) => (b.slot.lt(a.slot) ? 1 : -1));
|
|
52
|
+
|
|
53
|
+
// The indexed nullifier tree requires its prefilled leaves to be unique and strictly increasing, so sort ascending
|
|
54
|
+
// here (a copy, to avoid mutating the caller's array) rather than relying on the caller's ordering.
|
|
55
|
+
const sortedNullifiers = [...prefilledNullifiers].sort((a, b) => (a.toBigInt() < b.toBigInt() ? -1 : 1));
|
|
56
|
+
|
|
57
|
+
const genesis: GenesisData = { prefilledPublicData, prefilledNullifiers: sortedNullifiers, genesisTimestamp };
|
|
58
|
+
const { genesisArchiveRoot } = await generateGenesisValues(genesis);
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
genesisArchiveRoot,
|
|
62
|
+
genesis,
|
|
63
|
+
fundingNeeded: BigInt(initialAccounts.length) * initialAccountFeeJuice.toBigInt(),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { MAX_NULLIFIERS_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX } from '@aztec-labs/constants';
|
|
2
|
+
import type { BlockNumber } from '@aztec-labs/foundation/branded-types';
|
|
3
|
+
import type { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
4
|
+
import type { L2Block } from '@aztec-labs/stdlib/block';
|
|
5
|
+
import type {
|
|
6
|
+
ForkMerkleTreeOperations,
|
|
7
|
+
MerkleTreeReadOperations,
|
|
8
|
+
ReadonlyWorldStateAccess,
|
|
9
|
+
} from '@aztec-labs/stdlib/interfaces/server';
|
|
10
|
+
|
|
11
|
+
import type { WorldStateStatusFull, WorldStateStatusSummary } from '../native/message.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @remarks Short explanation:
|
|
16
|
+
* The nullifier tree must be initially padded as the pre-populated 0 index prevents efficient subtree insertion.
|
|
17
|
+
* Padding with some values solves this issue.
|
|
18
|
+
*
|
|
19
|
+
* @remarks Thorough explanation:
|
|
20
|
+
* There needs to be an initial (0,0,0) leaf in the tree, so that when we insert the first 'proper' leaf, we can
|
|
21
|
+
* prove that any value greater than 0 doesn't exist in the tree yet. We prefill/pad the tree with "the number of
|
|
22
|
+
* leaves that are added by one block" so that the first 'proper' block can insert a full subtree.
|
|
23
|
+
*
|
|
24
|
+
* Without this padding, there would be a leaf (0,0,0) at leaf index 0, making it really difficult to insert e.g.
|
|
25
|
+
* 1024 leaves for the first block, because there's only neat space for 1023 leaves after 0. By padding with 1023
|
|
26
|
+
* more leaves, we can then insert the first block of 1024 leaves into indices 1024:2047.
|
|
27
|
+
*/
|
|
28
|
+
export const INITIAL_NULLIFIER_TREE_SIZE = 2 * MAX_NULLIFIERS_PER_TX;
|
|
29
|
+
|
|
30
|
+
export const INITIAL_PUBLIC_DATA_TREE_SIZE = 2 * MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX;
|
|
31
|
+
|
|
32
|
+
export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations, ReadonlyWorldStateAccess {
|
|
33
|
+
/**
|
|
34
|
+
* Handles a single L2 block: inserts its note hashes, nullifiers, public data writes, and the block's L1-to-L2
|
|
35
|
+
* message bundle into the merkle trees. Any block may carry a message bundle and transition the L1-to-L2 message
|
|
36
|
+
* tree, not just the first block of a checkpoint. The bundle's real (unpadded, compact) leaves are appended as
|
|
37
|
+
* given, matching how the circuits build the tree.
|
|
38
|
+
* @param block - The L2 block to handle.
|
|
39
|
+
* @param l1ToL2Messages - The L1 to L2 messages for the block.
|
|
40
|
+
*/
|
|
41
|
+
handleL2BlockAndMessages(block: L2Block, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Gets a handle that allows reading the latest committed state
|
|
45
|
+
*/
|
|
46
|
+
getCommitted(): MerkleTreeReadOperations;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Removes all historical snapshots up to but not including the given block number
|
|
50
|
+
* @param toBlockNumber The block number of the new oldest historical block
|
|
51
|
+
* @returns The new WorldStateStatus
|
|
52
|
+
*/
|
|
53
|
+
removeHistoricalBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Removes all pending blocks down to but not including the given block number
|
|
57
|
+
* @param toBlockNumber The block number of the new tip of the pending chain,
|
|
58
|
+
* @returns The new WorldStateStatus
|
|
59
|
+
*/
|
|
60
|
+
unwindBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Advances the finalized block number to be the number provided
|
|
64
|
+
* @param toBlockNumber The block number that is now the tip of the finalized chain
|
|
65
|
+
* @returns The new WorldStateStatus
|
|
66
|
+
*/
|
|
67
|
+
setFinalized(toBlockNumber: BlockNumber): Promise<WorldStateStatusSummary>;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Gets the current status summary of the database.
|
|
71
|
+
* @returns The current WorldStateStatus.
|
|
72
|
+
*/
|
|
73
|
+
getStatusSummary(): Promise<WorldStateStatusSummary>;
|
|
74
|
+
|
|
75
|
+
/** Stops the database */
|
|
76
|
+
close(): Promise<void>;
|
|
77
|
+
|
|
78
|
+
/** Deletes the db. */
|
|
79
|
+
clear(): Promise<void>;
|
|
80
|
+
}
|