@aztec/world-state 0.0.1-commit.b655e406 → 0.0.1-commit.b8a057fa
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/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/instrumentation/instrumentation.d.ts +4 -3
- package/dest/instrumentation/instrumentation.d.ts.map +1 -1
- package/dest/instrumentation/instrumentation.js +21 -50
- package/dest/native/bench_metrics.d.ts +1 -1
- package/dest/native/bench_metrics.d.ts.map +1 -1
- 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/index.d.ts +2 -1
- package/dest/native/index.d.ts.map +1 -1
- package/dest/native/index.js +1 -0
- package/dest/native/ipc_world_state_instance.d.ts +89 -0
- package/dest/native/ipc_world_state_instance.d.ts.map +1 -0
- package/dest/native/ipc_world_state_instance.js +661 -0
- package/dest/native/merkle_trees_facade.d.ts +18 -8
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +90 -111
- package/dest/native/message.d.ts +22 -228
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/message.js +14 -55
- package/dest/native/native_world_state.d.ts +30 -15
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +133 -66
- package/dest/native/native_world_state_instance.d.ts +56 -33
- package/dest/native/native_world_state_instance.d.ts.map +1 -1
- package/dest/native/native_world_state_instance.js +1 -182
- 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 +3 -5
- package/dest/synchronizer/config.d.ts.map +1 -1
- package/dest/synchronizer/config.js +15 -18
- package/dest/synchronizer/errors.d.ts +8 -1
- package/dest/synchronizer/errors.d.ts.map +1 -1
- package/dest/synchronizer/errors.js +8 -1
- package/dest/synchronizer/factory.d.ts +6 -5
- package/dest/synchronizer/factory.d.ts.map +1 -1
- package/dest/synchronizer/factory.js +7 -6
- package/dest/synchronizer/index.d.ts +2 -1
- package/dest/synchronizer/index.d.ts.map +1 -1
- package/dest/synchronizer/index.js +1 -0
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +20 -32
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +181 -85
- package/dest/test/index.d.ts +1 -1
- package/dest/test/utils.d.ts +12 -5
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +59 -50
- package/dest/testing.d.ts +5 -4
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +15 -8
- package/dest/world-state-db/index.d.ts +1 -1
- package/dest/world-state-db/merkle_tree_db.d.ts +9 -19
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/package.json +16 -13
- package/src/index.ts +1 -0
- package/src/instrumentation/instrumentation.ts +23 -59
- package/src/native/fork_checkpoint.ts +19 -3
- package/src/native/index.ts +1 -0
- package/src/native/ipc_world_state_instance.ts +834 -0
- package/src/native/merkle_trees_facade.ts +118 -104
- package/src/native/message.ts +33 -305
- package/src/native/native_world_state.ts +179 -108
- package/src/native/native_world_state_instance.ts +94 -251
- package/src/native/world_state_operation.ts +33 -0
- package/src/synchronizer/config.ts +16 -23
- package/src/synchronizer/errors.ts +8 -0
- package/src/synchronizer/factory.ts +18 -11
- package/src/synchronizer/index.ts +1 -0
- package/src/synchronizer/server_world_state_synchronizer.ts +219 -111
- package/src/test/utils.ts +96 -92
- package/src/testing.ts +13 -11
- package/src/world-state-db/merkle_tree_db.ts +12 -19
- package/dest/native/world_state_ops_queue.d.ts +0 -19
- package/dest/native/world_state_ops_queue.d.ts.map +0 -1
- package/dest/native/world_state_ops_queue.js +0 -146
- package/src/native/world_state_ops_queue.ts +0 -190
package/src/test/utils.ts
CHANGED
|
@@ -4,122 +4,109 @@ import {
|
|
|
4
4
|
NULLIFIER_SUBTREE_HEIGHT,
|
|
5
5
|
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
6
6
|
} from '@aztec/constants';
|
|
7
|
+
import { asyncMap } from '@aztec/foundation/async-map';
|
|
8
|
+
import { BlockNumber, type CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
|
|
7
9
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
8
|
-
import { Fr } from '@aztec/foundation/
|
|
10
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
9
11
|
import { L2Block } from '@aztec/stdlib/block';
|
|
10
12
|
import type {
|
|
11
13
|
IndexedTreeId,
|
|
12
14
|
MerkleTreeReadOperations,
|
|
13
15
|
MerkleTreeWriteOperations,
|
|
14
16
|
} from '@aztec/stdlib/interfaces/server';
|
|
17
|
+
import { mockCheckpointAndMessages, mockL1ToL2Messages } from '@aztec/stdlib/testing';
|
|
15
18
|
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
19
|
+
import { BlockHeader } from '@aztec/stdlib/tx';
|
|
16
20
|
|
|
17
21
|
import type { NativeWorldStateService } from '../native/native_world_state.js';
|
|
18
22
|
|
|
19
|
-
export async function
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const l1ToL2MessagesPadded = padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
|
|
59
|
-
|
|
60
|
-
const noteHashInsert = fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
|
|
61
|
-
const messageInsert = fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
|
|
62
|
-
await Promise.all([publicDataInsert, nullifierInsert, noteHashInsert, messageInsert]);
|
|
63
|
-
}
|
|
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
|
+
const l1ToL2MessagesPadded =
|
|
54
|
+
block.indexWithinCheckpoint === 0
|
|
55
|
+
? padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP)
|
|
56
|
+
: l1ToL2Messages;
|
|
57
|
+
|
|
58
|
+
const noteHashInsert = fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
|
|
59
|
+
const messageInsert = fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
|
|
60
|
+
await Promise.all([publicDataInsert, nullifierInsert, noteHashInsert, messageInsert]);
|
|
64
61
|
|
|
65
62
|
const state = await fork.getStateReference();
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
|
|
64
|
+
// Capture the archive root *before* appending this block so the header's lastArchive chains off the previous block.
|
|
65
|
+
// sync_block now verifies lastArchive against the committed archive root, so a block carrying an unchained value
|
|
66
|
+
// (e.g. the random lastArchive from L2Block.random) would be rejected as a divergence from the canonical chain.
|
|
67
|
+
const previousArchive = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
68
|
+
block.header = BlockHeader.from({
|
|
69
|
+
...block.header,
|
|
70
|
+
state,
|
|
71
|
+
lastArchive: new AppendOnlyTreeSnapshot(Fr.fromBuffer(previousArchive.root), Number(previousArchive.size)),
|
|
72
|
+
});
|
|
73
|
+
await fork.updateArchive(block.header);
|
|
68
74
|
|
|
69
75
|
const archiveState = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
70
76
|
|
|
71
|
-
|
|
77
|
+
block.archive = new AppendOnlyTreeSnapshot(Fr.fromBuffer(archiveState.root), Number(archiveState.size));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export async function mockBlock(
|
|
81
|
+
blockNum: BlockNumber,
|
|
82
|
+
size: number,
|
|
83
|
+
fork: MerkleTreeWriteOperations,
|
|
84
|
+
maxEffects: number | undefined = 1000, // Defaults to the maximum tx effects.
|
|
85
|
+
numL1ToL2Messages: number = NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
86
|
+
isFirstBlockInCheckpoint: boolean = true,
|
|
87
|
+
) {
|
|
88
|
+
const block = await L2Block.random(blockNum, {
|
|
89
|
+
indexWithinCheckpoint: isFirstBlockInCheckpoint ? IndexWithinCheckpoint(0) : IndexWithinCheckpoint(1),
|
|
90
|
+
txsPerBlock: size,
|
|
91
|
+
txOptions: { maxEffects },
|
|
92
|
+
});
|
|
93
|
+
const l1ToL2Messages = mockL1ToL2Messages(numL1ToL2Messages);
|
|
94
|
+
|
|
95
|
+
await updateBlockState(block, l1ToL2Messages, fork);
|
|
72
96
|
|
|
73
97
|
return {
|
|
74
|
-
block
|
|
98
|
+
block,
|
|
75
99
|
messages: l1ToL2Messages,
|
|
76
100
|
};
|
|
77
101
|
}
|
|
78
102
|
|
|
79
|
-
export async function mockEmptyBlock(blockNum:
|
|
103
|
+
export async function mockEmptyBlock(blockNum: BlockNumber, fork: MerkleTreeWriteOperations) {
|
|
80
104
|
const l2Block = L2Block.empty();
|
|
81
105
|
const l1ToL2Messages = Array(16).fill(0).map(Fr.zero);
|
|
82
106
|
|
|
83
107
|
l2Block.header.globalVariables.blockNumber = blockNum;
|
|
84
108
|
|
|
85
|
-
|
|
86
|
-
{
|
|
87
|
-
const noteHashesPadded = l2Block.body.txEffects.flatMap(txEffect =>
|
|
88
|
-
padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX),
|
|
89
|
-
);
|
|
90
|
-
await fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
|
|
91
|
-
|
|
92
|
-
const l1ToL2MessagesPadded = padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
|
|
93
|
-
await fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Sync the indexed trees
|
|
97
|
-
{
|
|
98
|
-
// We insert the public data tree leaves with one batch per tx to avoid updating the same key twice
|
|
99
|
-
for (const txEffect of l2Block.body.txEffects) {
|
|
100
|
-
await fork.batchInsert(
|
|
101
|
-
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
102
|
-
txEffect.publicDataWrites.map(write => write.toBuffer()),
|
|
103
|
-
0,
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
const nullifiersPadded = padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX);
|
|
107
|
-
|
|
108
|
-
await fork.batchInsert(
|
|
109
|
-
MerkleTreeId.NULLIFIER_TREE,
|
|
110
|
-
nullifiersPadded.map(nullifier => nullifier.toBuffer()),
|
|
111
|
-
NULLIFIER_SUBTREE_HEIGHT,
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const state = await fork.getStateReference();
|
|
117
|
-
l2Block.header.state = state;
|
|
118
|
-
await fork.updateArchive(l2Block.getBlockHeader());
|
|
119
|
-
|
|
120
|
-
const archiveState = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
121
|
-
|
|
122
|
-
l2Block.archive = new AppendOnlyTreeSnapshot(Fr.fromBuffer(archiveState.root), Number(archiveState.size));
|
|
109
|
+
await updateBlockState(l2Block, l1ToL2Messages, fork);
|
|
123
110
|
|
|
124
111
|
return {
|
|
125
112
|
block: l2Block,
|
|
@@ -127,13 +114,18 @@ export async function mockEmptyBlock(blockNum: number, fork: MerkleTreeWriteOper
|
|
|
127
114
|
};
|
|
128
115
|
}
|
|
129
116
|
|
|
130
|
-
export async function mockBlocks(
|
|
131
|
-
|
|
117
|
+
export async function mockBlocks(
|
|
118
|
+
from: BlockNumber,
|
|
119
|
+
count: number,
|
|
120
|
+
numTxs: number,
|
|
121
|
+
worldState: NativeWorldStateService,
|
|
122
|
+
) {
|
|
123
|
+
const tempFork = await worldState.fork(BlockNumber(from - 1));
|
|
132
124
|
|
|
133
125
|
const blocks = [];
|
|
134
126
|
const messagesArray = [];
|
|
135
127
|
for (let blockNumber = from; blockNumber < from + count; blockNumber++) {
|
|
136
|
-
const { block, messages } = await mockBlock(blockNumber, numTxs, tempFork);
|
|
128
|
+
const { block, messages } = await mockBlock(BlockNumber(blockNumber), numTxs, tempFork);
|
|
137
129
|
blocks.push(block);
|
|
138
130
|
messagesArray.push(messages);
|
|
139
131
|
}
|
|
@@ -143,6 +135,18 @@ export async function mockBlocks(from: number, count: number, numTxs: number, wo
|
|
|
143
135
|
return { blocks, messages: messagesArray };
|
|
144
136
|
}
|
|
145
137
|
|
|
138
|
+
export async function mockCheckpoint(
|
|
139
|
+
checkpointNumber: CheckpointNumber,
|
|
140
|
+
fork: MerkleTreeWriteOperations,
|
|
141
|
+
options: Partial<Parameters<typeof mockCheckpointAndMessages>[1]> = {},
|
|
142
|
+
) {
|
|
143
|
+
const { checkpoint, messages } = await mockCheckpointAndMessages(checkpointNumber, options);
|
|
144
|
+
await asyncMap(checkpoint.blocks, async (block, i) => {
|
|
145
|
+
await updateBlockState(block, i === 0 ? messages : [], fork);
|
|
146
|
+
});
|
|
147
|
+
return { checkpoint, messages };
|
|
148
|
+
}
|
|
149
|
+
|
|
146
150
|
export async function assertSameState(forkA: MerkleTreeReadOperations, forkB: MerkleTreeReadOperations) {
|
|
147
151
|
const nativeStateRef = await forkA.getStateReference();
|
|
148
152
|
const nativeArchive = await forkA.getTreeInfo(MerkleTreeId.ARCHIVE);
|
package/src/testing.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
|
|
2
|
-
import { Fr } from '@aztec/foundation/
|
|
2
|
+
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
);
|
|
17
|
+
// Compute the genesis values on a throwaway world state. The archive root derives only from the
|
|
18
|
+
// prefilled public data and the genesis timestamp, so the fsync-off ephemeral store (no version
|
|
19
|
+
// manager, no crash-recoverability) produces an identical root while skipping the fsync overhead
|
|
20
|
+
// that `tmp` pays. close() removes the tmpdir.
|
|
21
|
+
const ws = await NativeWorldStateService.ephemeral(genesis);
|
|
22
22
|
const genesisArchiveRoot = new Fr((await ws.getCommitted().getTreeInfo(MerkleTreeId.ARCHIVE)).root);
|
|
23
23
|
await ws.close();
|
|
24
24
|
|
|
@@ -33,6 +33,7 @@ export async function getGenesisValues(
|
|
|
33
33
|
initialAccounts: AztecAddress[],
|
|
34
34
|
initialAccountFeeJuice = defaultInitialAccountFeeJuice,
|
|
35
35
|
genesisPublicData: PublicDataTreeLeaf[] = [],
|
|
36
|
+
genesisTimestamp: bigint = 0n,
|
|
36
37
|
) {
|
|
37
38
|
// Top up the accounts with fee juice.
|
|
38
39
|
let prefilledPublicData = await Promise.all(
|
|
@@ -46,11 +47,12 @@ export async function getGenesisValues(
|
|
|
46
47
|
|
|
47
48
|
prefilledPublicData.sort((a, b) => (b.slot.lt(a.slot) ? 1 : -1));
|
|
48
49
|
|
|
49
|
-
const
|
|
50
|
+
const genesis: GenesisData = { prefilledPublicData, genesisTimestamp };
|
|
51
|
+
const { genesisArchiveRoot } = await generateGenesisValues(genesis);
|
|
50
52
|
|
|
51
53
|
return {
|
|
52
54
|
genesisArchiveRoot,
|
|
53
|
-
|
|
55
|
+
genesis,
|
|
54
56
|
fundingNeeded: BigInt(initialAccounts.length) * initialAccountFeeJuice.toBigInt(),
|
|
55
57
|
};
|
|
56
58
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { MAX_NULLIFIERS_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX } from '@aztec/constants';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
2
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
4
|
import type { L2Block } from '@aztec/stdlib/block';
|
|
5
|
-
import type {
|
|
6
|
-
|
|
5
|
+
import type {
|
|
6
|
+
ForkMerkleTreeOperations,
|
|
7
|
+
MerkleTreeReadOperations,
|
|
8
|
+
ReadonlyWorldStateAccess,
|
|
9
|
+
} from '@aztec/stdlib/interfaces/server';
|
|
7
10
|
|
|
8
11
|
import type { WorldStateStatusFull, WorldStateStatusSummary } from '../native/message.js';
|
|
9
12
|
|
|
@@ -26,23 +29,13 @@ export const INITIAL_NULLIFIER_TREE_SIZE = 2 * MAX_NULLIFIERS_PER_TX;
|
|
|
26
29
|
|
|
27
30
|
export const INITIAL_PUBLIC_DATA_TREE_SIZE = 2 * MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX;
|
|
28
31
|
|
|
29
|
-
export
|
|
30
|
-
[MerkleTreeId.NULLIFIER_TREE]: IndexedTreeSnapshot;
|
|
31
|
-
[MerkleTreeId.NOTE_HASH_TREE]: TreeSnapshot<Fr>;
|
|
32
|
-
[MerkleTreeId.PUBLIC_DATA_TREE]: IndexedTreeSnapshot;
|
|
33
|
-
[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: TreeSnapshot<Fr>;
|
|
34
|
-
[MerkleTreeId.ARCHIVE]: TreeSnapshot<Fr>;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
32
|
+
export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations, ReadonlyWorldStateAccess {
|
|
38
33
|
/**
|
|
39
34
|
* Handles a single L2 block (i.e. Inserts the new note hashes into the merkle tree).
|
|
40
35
|
* @param block - The L2 block to handle.
|
|
41
36
|
* @param l1ToL2Messages - The L1 to L2 messages for the block.
|
|
42
|
-
* @param isFirstBlock - Whether the block is the first block in a checkpoint. Temporary hack to only insert l1 to l2
|
|
43
|
-
* messages for the first block in a checkpoint. TODO(#17027) Remove this.
|
|
44
37
|
*/
|
|
45
|
-
handleL2BlockAndMessages(block: L2Block, l1ToL2Messages: Fr[]
|
|
38
|
+
handleL2BlockAndMessages(block: L2Block, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull>;
|
|
46
39
|
|
|
47
40
|
/**
|
|
48
41
|
* Gets a handle that allows reading the latest committed state
|
|
@@ -54,21 +47,21 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
|
|
|
54
47
|
* @param toBlockNumber The block number of the new oldest historical block
|
|
55
48
|
* @returns The new WorldStateStatus
|
|
56
49
|
*/
|
|
57
|
-
removeHistoricalBlocks(toBlockNumber:
|
|
50
|
+
removeHistoricalBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
|
|
58
51
|
|
|
59
52
|
/**
|
|
60
53
|
* Removes all pending blocks down to but not including the given block number
|
|
61
54
|
* @param toBlockNumber The block number of the new tip of the pending chain,
|
|
62
55
|
* @returns The new WorldStateStatus
|
|
63
56
|
*/
|
|
64
|
-
unwindBlocks(toBlockNumber:
|
|
57
|
+
unwindBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
|
|
65
58
|
|
|
66
59
|
/**
|
|
67
60
|
* Advances the finalized block number to be the number provided
|
|
68
61
|
* @param toBlockNumber The block number that is now the tip of the finalized chain
|
|
69
62
|
* @returns The new WorldStateStatus
|
|
70
63
|
*/
|
|
71
|
-
setFinalized(toBlockNumber:
|
|
64
|
+
setFinalized(toBlockNumber: BlockNumber): Promise<WorldStateStatusSummary>;
|
|
72
65
|
|
|
73
66
|
/**
|
|
74
67
|
* Gets the current status summary of the database.
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { WorldStateMessageType } from './message.js';
|
|
2
|
-
export declare const MUTATING_MSG_TYPES: Set<WorldStateMessageType>;
|
|
3
|
-
export declare class WorldStateOpsQueue {
|
|
4
|
-
private requests;
|
|
5
|
-
private inFlightMutatingCount;
|
|
6
|
-
private inFlightCount;
|
|
7
|
-
private stopPromise?;
|
|
8
|
-
private stopResolve?;
|
|
9
|
-
private requestId;
|
|
10
|
-
private ops;
|
|
11
|
-
execute(request: () => Promise<any>, messageType: WorldStateMessageType, committedOnly: boolean): Promise<any>;
|
|
12
|
-
private executeMutating;
|
|
13
|
-
private executeNonMutatingUncommitted;
|
|
14
|
-
private executeNonMutatingCommitted;
|
|
15
|
-
private checkAndEnqueue;
|
|
16
|
-
private sendEnqueuedRequest;
|
|
17
|
-
stop(): Promise<void>;
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=world_state_ops_queue.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"world_state_ops_queue.d.ts","sourceRoot":"","sources":["../../src/native/world_state_ops_queue.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAyBrD,eAAO,MAAM,kBAAkB,4BAgB7B,CAAC;AAGH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,qBAAqB,CAAK;IAClC,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,WAAW,CAAC,CAAgB;IACpC,OAAO,CAAC,WAAW,CAAC,CAAa;IACjC,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,GAAG,CAAwC;IAI5C,OAAO,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,EAAE,WAAW,EAAE,qBAAqB,EAAE,aAAa,EAAE,OAAO;IAyBtG,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,6BAA6B;IAYrC,OAAO,CAAC,2BAA2B;IAUnC,OAAO,CAAC,eAAe;IAyCvB,OAAO,CAAC,mBAAmB;IAgBpB,IAAI;CAiBZ"}
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
2
|
-
import { WorldStateMessageType } from './message.js';
|
|
3
|
-
// These are the set of message types that implement mutating operations
|
|
4
|
-
// Messages of these types require exclusive access to their given forks
|
|
5
|
-
export const MUTATING_MSG_TYPES = new Set([
|
|
6
|
-
WorldStateMessageType.APPEND_LEAVES,
|
|
7
|
-
WorldStateMessageType.BATCH_INSERT,
|
|
8
|
-
WorldStateMessageType.SEQUENTIAL_INSERT,
|
|
9
|
-
WorldStateMessageType.UPDATE_ARCHIVE,
|
|
10
|
-
WorldStateMessageType.COMMIT,
|
|
11
|
-
WorldStateMessageType.ROLLBACK,
|
|
12
|
-
WorldStateMessageType.SYNC_BLOCK,
|
|
13
|
-
WorldStateMessageType.CREATE_FORK,
|
|
14
|
-
WorldStateMessageType.DELETE_FORK,
|
|
15
|
-
WorldStateMessageType.FINALIZE_BLOCKS,
|
|
16
|
-
WorldStateMessageType.UNWIND_BLOCKS,
|
|
17
|
-
WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS,
|
|
18
|
-
WorldStateMessageType.CREATE_CHECKPOINT,
|
|
19
|
-
WorldStateMessageType.COMMIT_CHECKPOINT,
|
|
20
|
-
WorldStateMessageType.REVERT_CHECKPOINT
|
|
21
|
-
]);
|
|
22
|
-
// This class implements the per-fork operation queue
|
|
23
|
-
export class WorldStateOpsQueue {
|
|
24
|
-
requests = [];
|
|
25
|
-
inFlightMutatingCount = 0;
|
|
26
|
-
inFlightCount = 0;
|
|
27
|
-
stopPromise;
|
|
28
|
-
stopResolve;
|
|
29
|
-
requestId = 0;
|
|
30
|
-
ops = new Map();
|
|
31
|
-
// The primary public api, this is where an operation is queued
|
|
32
|
-
// We return a promise that will ultimately be resolved/rejected with the response/error generated by the 'request' argument
|
|
33
|
-
execute(request, messageType, committedOnly) {
|
|
34
|
-
if (this.stopResolve !== undefined) {
|
|
35
|
-
throw new Error('Unable to send request to world state, queue already stopped');
|
|
36
|
-
}
|
|
37
|
-
const op = {
|
|
38
|
-
requestId: this.requestId++,
|
|
39
|
-
mutating: MUTATING_MSG_TYPES.has(messageType),
|
|
40
|
-
request,
|
|
41
|
-
promise: promiseWithResolvers()
|
|
42
|
-
};
|
|
43
|
-
this.ops.set(op.requestId, op);
|
|
44
|
-
// Perform the appropriate action based upon the queueing rules
|
|
45
|
-
if (op.mutating) {
|
|
46
|
-
this.executeMutating(op);
|
|
47
|
-
} else if (committedOnly === false) {
|
|
48
|
-
this.executeNonMutatingUncommitted(op);
|
|
49
|
-
} else {
|
|
50
|
-
this.executeNonMutatingCommitted(op);
|
|
51
|
-
}
|
|
52
|
-
return op.promise.promise;
|
|
53
|
-
}
|
|
54
|
-
// Mutating requests need exclusive access
|
|
55
|
-
executeMutating(op) {
|
|
56
|
-
// If nothing is in flight then we send the request immediately
|
|
57
|
-
// Otherwise add to the queue
|
|
58
|
-
if (this.inFlightCount === 0) {
|
|
59
|
-
this.sendEnqueuedRequest(op);
|
|
60
|
-
} else {
|
|
61
|
-
this.requests.push(op);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
// Non mutating requests including uncommitted state
|
|
65
|
-
executeNonMutatingUncommitted(op) {
|
|
66
|
-
// If there are no mutating requests in flight and there is nothing queued
|
|
67
|
-
// then send the request immediately
|
|
68
|
-
// If a mutating request is in flight then we must wait
|
|
69
|
-
// If a mutating request is not in flight but something is queued then it must be a mutating request
|
|
70
|
-
if (this.inFlightMutatingCount == 0 && this.requests.length == 0) {
|
|
71
|
-
this.sendEnqueuedRequest(op);
|
|
72
|
-
} else {
|
|
73
|
-
this.requests.push(op);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
executeNonMutatingCommitted(op) {
|
|
77
|
-
// This is a non-mutating request for committed data
|
|
78
|
-
// It can always be sent
|
|
79
|
-
op.request().then(op.promise.resolve, op.promise.reject).finally(()=>{
|
|
80
|
-
this.ops.delete(op.requestId);
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
checkAndEnqueue(completedOp) {
|
|
84
|
-
// As request has completed
|
|
85
|
-
// First we decrements the relevant in flight counters
|
|
86
|
-
if (completedOp.mutating) {
|
|
87
|
-
--this.inFlightMutatingCount;
|
|
88
|
-
}
|
|
89
|
-
--this.inFlightCount;
|
|
90
|
-
// If there are still requests in flight then do nothing further
|
|
91
|
-
if (this.inFlightCount != 0) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
// No requests in flight, send next queued requests
|
|
95
|
-
// We loop and send:
|
|
96
|
-
// 1 mutating request if it is next in the queue
|
|
97
|
-
// As many non-mutating requests as we encounter until
|
|
98
|
-
// we exhaust the queue or we reach a mutating request
|
|
99
|
-
while(this.requests.length > 0){
|
|
100
|
-
const next = this.requests[0];
|
|
101
|
-
if (next.mutating) {
|
|
102
|
-
if (this.inFlightCount == 0) {
|
|
103
|
-
// send the mutating request
|
|
104
|
-
this.requests.shift();
|
|
105
|
-
this.sendEnqueuedRequest(next);
|
|
106
|
-
}
|
|
107
|
-
break;
|
|
108
|
-
} else {
|
|
109
|
-
// not mutating, send and go round again
|
|
110
|
-
this.requests.shift();
|
|
111
|
-
this.sendEnqueuedRequest(next);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
// If the queue is empty, there is nothing in flight and we have been told to stop, then resolve the stop promise
|
|
115
|
-
if (this.inFlightCount == 0 && this.stopResolve !== undefined) {
|
|
116
|
-
this.stopResolve();
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
sendEnqueuedRequest(op) {
|
|
120
|
-
// Here we increment the in flight counts before sending
|
|
121
|
-
++this.inFlightCount;
|
|
122
|
-
if (op.mutating) {
|
|
123
|
-
++this.inFlightMutatingCount;
|
|
124
|
-
}
|
|
125
|
-
// Make the request and pass the response/error through to the stored promise
|
|
126
|
-
op.request().then(op.promise.resolve, op.promise.reject).finally(()=>{
|
|
127
|
-
this.checkAndEnqueue(op);
|
|
128
|
-
this.ops.delete(op.requestId);
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
stop() {
|
|
132
|
-
// If there is already a stop promise then return it
|
|
133
|
-
if (this.stopPromise) {
|
|
134
|
-
return this.stopPromise;
|
|
135
|
-
}
|
|
136
|
-
// Otherwise create a new one and capture the resolve method
|
|
137
|
-
this.stopPromise = new Promise((resolve)=>{
|
|
138
|
-
this.stopResolve = resolve;
|
|
139
|
-
});
|
|
140
|
-
// If no outstanding requests then immediately resolve the promise
|
|
141
|
-
if (this.requests.length == 0 && this.inFlightCount == 0 && this.stopResolve !== undefined) {
|
|
142
|
-
this.stopResolve();
|
|
143
|
-
}
|
|
144
|
-
return this.stopPromise;
|
|
145
|
-
}
|
|
146
|
-
}
|