@aztec/world-state 0.0.1-commit.181e2d196 → 0.0.1-commit.189eedb3
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 +4 -3
- package/dest/instrumentation/instrumentation.d.ts.map +1 -1
- package/dest/instrumentation/instrumentation.js +4 -9
- 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/ipc_world_state_instance.d.ts +87 -0
- package/dest/native/ipc_world_state_instance.d.ts.map +1 -0
- package/dest/native/ipc_world_state_instance.js +660 -0
- package/dest/native/merkle_trees_facade.d.ts +11 -7
- package/dest/native/merkle_trees_facade.d.ts.map +1 -1
- package/dest/native/merkle_trees_facade.js +62 -114
- package/dest/native/message.d.ts +14 -222
- package/dest/native/message.d.ts.map +1 -1
- package/dest/native/message.js +0 -42
- package/dest/native/native_world_state.d.ts +19 -7
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +113 -58
- package/dest/native/native_world_state_instance.d.ts +58 -41
- package/dest/native/native_world_state_instance.d.ts.map +1 -1
- package/dest/native/native_world_state_instance.js +5 -202
- 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 +1 -1
- package/dest/synchronizer/config.d.ts.map +1 -1
- package/dest/synchronizer/config.js +9 -10
- package/dest/synchronizer/factory.d.ts +5 -5
- package/dest/synchronizer/factory.d.ts.map +1 -1
- package/dest/synchronizer/factory.js +7 -6
- package/dest/synchronizer/server_world_state_synchronizer.d.ts +4 -4
- package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/server_world_state_synchronizer.js +71 -19
- package/dest/testing.d.ts +4 -3
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +10 -6
- package/dest/world-state-db/merkle_tree_db.d.ts +1 -10
- package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
- package/package.json +14 -11
- package/src/instrumentation/instrumentation.ts +6 -18
- package/src/native/fork_checkpoint.ts +19 -3
- package/src/native/ipc_world_state_instance.ts +830 -0
- package/src/native/merkle_trees_facade.ts +88 -108
- package/src/native/message.ts +13 -287
- package/src/native/native_world_state.ts +129 -97
- package/src/native/native_world_state_instance.ts +96 -280
- package/src/native/world_state_operation.ts +33 -0
- package/src/synchronizer/config.ts +14 -10
- package/src/synchronizer/factory.ts +12 -11
- package/src/synchronizer/server_world_state_synchronizer.ts +74 -24
- package/src/testing.ts +8 -9
- package/src/world-state-db/merkle_tree_db.ts +0 -10
- 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
|
@@ -1,203 +1,6 @@
|
|
|
1
|
-
import { ARCHIVE_HEIGHT, DomainSeparator, L1_TO_L2_MSG_TREE_HEIGHT, MAX_NULLIFIERS_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, NOTE_HASH_TREE_HEIGHT, NULLIFIER_TREE_HEIGHT, PUBLIC_DATA_TREE_HEIGHT } from '@aztec/constants';
|
|
2
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import { NativeWorldState as BaseNativeWorldState, MsgpackChannel } from '@aztec/native';
|
|
4
|
-
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
5
|
-
import assert from 'assert';
|
|
6
|
-
import { cpus } from 'os';
|
|
7
|
-
import { WorldStateMessageType, isWithCanonical, isWithForkId, isWithRevision } from './message.js';
|
|
8
|
-
import { WorldStateOpsQueue } from './world_state_ops_queue.js';
|
|
9
|
-
const MAX_WORLD_STATE_THREADS = +(process.env.HARDWARE_CONCURRENCY || '16');
|
|
10
1
|
/**
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
instrumentation;
|
|
17
|
-
log;
|
|
18
|
-
open;
|
|
19
|
-
// We maintain a map of queue to fork
|
|
20
|
-
queues;
|
|
21
|
-
instance;
|
|
22
|
-
/** Creates a new native WorldState instance */ constructor(dataDir, wsTreeMapSizes, prefilledPublicData = [], instrumentation, bindings, log = createLogger('world-state:database', bindings)){
|
|
23
|
-
this.dataDir = dataDir;
|
|
24
|
-
this.wsTreeMapSizes = wsTreeMapSizes;
|
|
25
|
-
this.prefilledPublicData = prefilledPublicData;
|
|
26
|
-
this.instrumentation = instrumentation;
|
|
27
|
-
this.log = log;
|
|
28
|
-
this.open = true;
|
|
29
|
-
this.queues = new Map();
|
|
30
|
-
const threads = Math.min(cpus().length, MAX_WORLD_STATE_THREADS);
|
|
31
|
-
log.info(`Creating world state data store at directory ${dataDir} with map sizes ${JSON.stringify(wsTreeMapSizes)} and ${threads} threads.`);
|
|
32
|
-
const prefilledPublicDataBufferArray = prefilledPublicData.map((d)=>[
|
|
33
|
-
d.slot.toBuffer(),
|
|
34
|
-
d.value.toBuffer()
|
|
35
|
-
]);
|
|
36
|
-
const ws = new BaseNativeWorldState(dataDir, {
|
|
37
|
-
[MerkleTreeId.NULLIFIER_TREE]: NULLIFIER_TREE_HEIGHT,
|
|
38
|
-
[MerkleTreeId.NOTE_HASH_TREE]: NOTE_HASH_TREE_HEIGHT,
|
|
39
|
-
[MerkleTreeId.PUBLIC_DATA_TREE]: PUBLIC_DATA_TREE_HEIGHT,
|
|
40
|
-
[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: L1_TO_L2_MSG_TREE_HEIGHT,
|
|
41
|
-
[MerkleTreeId.ARCHIVE]: ARCHIVE_HEIGHT
|
|
42
|
-
}, {
|
|
43
|
-
[MerkleTreeId.NULLIFIER_TREE]: 2 * MAX_NULLIFIERS_PER_TX,
|
|
44
|
-
[MerkleTreeId.PUBLIC_DATA_TREE]: 2 * MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX
|
|
45
|
-
}, prefilledPublicDataBufferArray, DomainSeparator.BLOCK_HEADER_HASH, {
|
|
46
|
-
[MerkleTreeId.NULLIFIER_TREE]: wsTreeMapSizes.nullifierTreeMapSizeKb,
|
|
47
|
-
[MerkleTreeId.NOTE_HASH_TREE]: wsTreeMapSizes.noteHashTreeMapSizeKb,
|
|
48
|
-
[MerkleTreeId.PUBLIC_DATA_TREE]: wsTreeMapSizes.publicDataTreeMapSizeKb,
|
|
49
|
-
[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: wsTreeMapSizes.messageTreeMapSizeKb,
|
|
50
|
-
[MerkleTreeId.ARCHIVE]: wsTreeMapSizes.archiveTreeMapSizeKb
|
|
51
|
-
}, threads);
|
|
52
|
-
this.instance = new MsgpackChannel(ws);
|
|
53
|
-
// Manually create the queue for the canonical fork
|
|
54
|
-
this.queues.set(0, new WorldStateOpsQueue());
|
|
55
|
-
}
|
|
56
|
-
getDataDir() {
|
|
57
|
-
return this.dataDir;
|
|
58
|
-
}
|
|
59
|
-
clone() {
|
|
60
|
-
return new NativeWorldState(this.dataDir, this.wsTreeMapSizes, this.prefilledPublicData, this.instrumentation, this.log.getBindings(), this.log);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Gets the native WorldState handle from the underlying native instance.
|
|
64
|
-
* We call the getHandle() method on the native WorldState to get a NAPI External
|
|
65
|
-
* that wraps the underlying C++ WorldState pointer.
|
|
66
|
-
* @returns The NAPI External handle to the native WorldState instance,since
|
|
67
|
-
* the NAPI external type is opaque, we return any (we could also use an opaque symbol type)
|
|
68
|
-
*/ getHandle() {
|
|
69
|
-
const worldStateWrapper = this.instance.dest;
|
|
70
|
-
if (!worldStateWrapper) {
|
|
71
|
-
throw new Error('No WorldStateWrapper found');
|
|
72
|
-
}
|
|
73
|
-
if (typeof worldStateWrapper.getHandle !== 'function') {
|
|
74
|
-
throw new Error('WorldStateWrapper does not have getHandle method');
|
|
75
|
-
}
|
|
76
|
-
// Call getHandle() to get the NAPI External
|
|
77
|
-
try {
|
|
78
|
-
return worldStateWrapper.getHandle();
|
|
79
|
-
} catch (error) {
|
|
80
|
-
this.log.error('Failed to get native WorldState handle', error);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Sends a message to the native instance and returns the response.
|
|
85
|
-
* @param messageType - The type of message to send
|
|
86
|
-
* @param body - The message body
|
|
87
|
-
* @param responseHandler - A callback accepting the response, executed on the job queue
|
|
88
|
-
* @param errorHandler - A callback called on request error, executed on the job queue
|
|
89
|
-
* @returns The response to the message
|
|
90
|
-
*/ async call(messageType, body, // allows for the pre-processing of responses on the job queue before being passed back
|
|
91
|
-
responseHandler = (response)=>response, errorHandler = (_)=>{}) {
|
|
92
|
-
// Here we determine which fork the request is being executed against and whether it requires uncommitted data
|
|
93
|
-
// We use the fork Id to select the appropriate request queue and the uncommitted data flag to pass to the queue
|
|
94
|
-
let forkId = -1;
|
|
95
|
-
// We assume it includes uncommitted unless explicitly told otherwise
|
|
96
|
-
let committedOnly = false;
|
|
97
|
-
// Canonical requests ALWAYS go against the canonical fork
|
|
98
|
-
// These include things like block syncs/unwinds etc
|
|
99
|
-
// These requests don't contain a fork ID
|
|
100
|
-
if (isWithCanonical(body)) {
|
|
101
|
-
forkId = 0;
|
|
102
|
-
} else if (isWithForkId(body)) {
|
|
103
|
-
forkId = body.forkId;
|
|
104
|
-
} else if (isWithRevision(body)) {
|
|
105
|
-
forkId = body.revision.forkId;
|
|
106
|
-
committedOnly = body.revision.includeUncommitted === false;
|
|
107
|
-
} else {
|
|
108
|
-
const _ = body;
|
|
109
|
-
throw new Error(`Unable to determine forkId for message=${WorldStateMessageType[messageType]}`);
|
|
110
|
-
}
|
|
111
|
-
// Get the queue or create a new one
|
|
112
|
-
let requestQueue = this.queues.get(forkId);
|
|
113
|
-
if (requestQueue === undefined) {
|
|
114
|
-
requestQueue = new WorldStateOpsQueue();
|
|
115
|
-
this.queues.set(forkId, requestQueue);
|
|
116
|
-
}
|
|
117
|
-
// Enqueue the request and wait for the response
|
|
118
|
-
const response = await requestQueue.execute(async ()=>{
|
|
119
|
-
assert.notEqual(messageType, WorldStateMessageType.CLOSE, 'Use close() to close the native instance');
|
|
120
|
-
assert.equal(this.open, true, 'Native instance is closed');
|
|
121
|
-
let response;
|
|
122
|
-
try {
|
|
123
|
-
response = await this._sendMessage(messageType, body);
|
|
124
|
-
} catch (error) {
|
|
125
|
-
errorHandler(error.message);
|
|
126
|
-
throw error;
|
|
127
|
-
}
|
|
128
|
-
return responseHandler(response);
|
|
129
|
-
}, messageType, committedOnly);
|
|
130
|
-
// If the request was to delete the fork then we clean it up here
|
|
131
|
-
if (messageType === WorldStateMessageType.DELETE_FORK) {
|
|
132
|
-
await requestQueue.stop();
|
|
133
|
-
this.queues.delete(forkId);
|
|
134
|
-
}
|
|
135
|
-
return response;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Stops the native instance.
|
|
139
|
-
*/ async close() {
|
|
140
|
-
if (!this.open) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
this.open = false;
|
|
144
|
-
const queue = this.queues.get(0);
|
|
145
|
-
await queue.execute(async ()=>{
|
|
146
|
-
await this._sendMessage(WorldStateMessageType.CLOSE, {
|
|
147
|
-
canonical: true
|
|
148
|
-
});
|
|
149
|
-
}, WorldStateMessageType.CLOSE, false);
|
|
150
|
-
await queue.stop();
|
|
151
|
-
}
|
|
152
|
-
async _sendMessage(messageType, body) {
|
|
153
|
-
let logMetadata = {};
|
|
154
|
-
if (body) {
|
|
155
|
-
if ('treeId' in body) {
|
|
156
|
-
logMetadata['treeId'] = MerkleTreeId[body.treeId];
|
|
157
|
-
}
|
|
158
|
-
if ('revision' in body) {
|
|
159
|
-
logMetadata = {
|
|
160
|
-
...logMetadata,
|
|
161
|
-
...body.revision
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
if ('forkId' in body) {
|
|
165
|
-
logMetadata['forkId'] = body.forkId;
|
|
166
|
-
}
|
|
167
|
-
if ('blockNumber' in body) {
|
|
168
|
-
logMetadata['blockNumber'] = body.blockNumber;
|
|
169
|
-
}
|
|
170
|
-
if ('toBlockNumber' in body) {
|
|
171
|
-
logMetadata['toBlockNumber'] = body.toBlockNumber;
|
|
172
|
-
}
|
|
173
|
-
if ('leafIndex' in body) {
|
|
174
|
-
logMetadata['leafIndex'] = body.leafIndex;
|
|
175
|
-
}
|
|
176
|
-
if ('blockHeaderHash' in body) {
|
|
177
|
-
logMetadata['blockHeaderHash'] = '0x' + body.blockHeaderHash.toString('hex');
|
|
178
|
-
}
|
|
179
|
-
if ('leaves' in body) {
|
|
180
|
-
logMetadata['leavesCount'] = body.leaves.length;
|
|
181
|
-
}
|
|
182
|
-
// sync operation
|
|
183
|
-
if ('paddedNoteHashes' in body) {
|
|
184
|
-
logMetadata['notesCount'] = body.paddedNoteHashes.length;
|
|
185
|
-
logMetadata['nullifiersCount'] = body.paddedNullifiers.length;
|
|
186
|
-
logMetadata['l1ToL2MessagesCount'] = body.paddedL1ToL2Messages.length;
|
|
187
|
-
logMetadata['publicDataWritesCount'] = body.publicDataWrites.length;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
try {
|
|
191
|
-
const { duration, response } = await this.instance.sendMessage(messageType, body);
|
|
192
|
-
this.log.trace(`Call ${WorldStateMessageType[messageType]} took (ms)`, {
|
|
193
|
-
duration,
|
|
194
|
-
...logMetadata
|
|
195
|
-
});
|
|
196
|
-
this.instrumentation.recordRoundTrip(duration.totalUs, messageType);
|
|
197
|
-
return response;
|
|
198
|
-
} catch (error) {
|
|
199
|
-
this.log.error(`Call ${WorldStateMessageType[messageType]} failed: ${error}`, error, logMetadata);
|
|
200
|
-
throw error;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
2
|
+
* Backend-agnostic handle to a running aztec-wsdb world state, accessed by the TS layer.
|
|
3
|
+
*
|
|
4
|
+
* The legacy in-process NAPI implementation has been removed; the C++ AVM (NAPI) now connects to
|
|
5
|
+
* the same aztec-wsdb process using the IPC path returned by {@link getIpcPath}.
|
|
6
|
+
*/ export { };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Names of the world-state operations, used as labels for instrumentation and
|
|
3
|
+
* logging. (Read/write ordering is enforced server-side by the wsdb scheduler,
|
|
4
|
+
* so there is no longer a client-side operation queue.)
|
|
5
|
+
*/
|
|
6
|
+
export type WorldStateOperationName = 'getTreeInfo' | 'getStateReference' | 'getInitialStateReference' | 'getLeafValue' | 'getLeafPreimage' | 'getSiblingPath' | 'getBlockNumbersForLeafIndices' | 'findLeafIndices' | 'findLowLeaf' | 'findSiblingPaths' | 'appendLeaves' | 'batchInsert' | 'sequentialInsert' | 'updateArchive' | 'syncBlock' | 'createFork' | 'deleteFork' | 'finalizeBlocks' | 'unwindBlocks' | 'removeHistoricalBlocks' | 'getStatus' | 'createCheckpoint' | 'commitCheckpoint' | 'revertCheckpoint' | 'commitAllCheckpoints' | 'revertAllCheckpoints' | 'copyStores';
|
|
7
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid29ybGRfc3RhdGVfb3BlcmF0aW9uLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbmF0aXZlL3dvcmxkX3N0YXRlX29wZXJhdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7OztHQUlHO0FBQ0gsTUFBTSxNQUFNLHVCQUF1QixHQUMvQixhQUFhLEdBQ2IsbUJBQW1CLEdBQ25CLDBCQUEwQixHQUMxQixjQUFjLEdBQ2QsaUJBQWlCLEdBQ2pCLGdCQUFnQixHQUNoQiwrQkFBK0IsR0FDL0IsaUJBQWlCLEdBQ2pCLGFBQWEsR0FDYixrQkFBa0IsR0FDbEIsY0FBYyxHQUNkLGFBQWEsR0FDYixrQkFBa0IsR0FDbEIsZUFBZSxHQUNmLFdBQVcsR0FDWCxZQUFZLEdBQ1osWUFBWSxHQUNaLGdCQUFnQixHQUNoQixjQUFjLEdBQ2Qsd0JBQXdCLEdBQ3hCLFdBQVcsR0FDWCxrQkFBa0IsR0FDbEIsa0JBQWtCLEdBQ2xCLGtCQUFrQixHQUNsQixzQkFBc0IsR0FDdEIsc0JBQXNCLEdBQ3RCLFlBQVksQ0FBQyJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"world_state_operation.d.ts","sourceRoot":"","sources":["../../src/native/world_state_operation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GAC/B,aAAa,GACb,mBAAmB,GACnB,0BAA0B,GAC1B,cAAc,GACd,iBAAiB,GACjB,gBAAgB,GAChB,+BAA+B,GAC/B,iBAAiB,GACjB,aAAa,GACb,kBAAkB,GAClB,cAAc,GACd,aAAa,GACb,kBAAkB,GAClB,eAAe,GACf,WAAW,GACX,YAAY,GACZ,YAAY,GACZ,gBAAgB,GAChB,cAAc,GACd,wBAAwB,GACxB,WAAW,GACX,kBAAkB,GAClB,kBAAkB,GAClB,kBAAkB,GAClB,sBAAsB,GACtB,sBAAsB,GACtB,YAAY,CAAC"}
|
|
@@ -28,4 +28,4 @@ export declare const worldStateConfigMappings: ConfigMappingsType<WorldStateConf
|
|
|
28
28
|
* @returns The configuration values for the world state synchronizer.
|
|
29
29
|
*/
|
|
30
30
|
export declare function getWorldStateConfigFromEnv(): WorldStateConfig;
|
|
31
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
31
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlnLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3luY2hyb25pemVyL2NvbmZpZy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQ0wsS0FBSyxrQkFBa0IsRUFJeEIsTUFBTSwwQkFBMEIsQ0FBQztBQUVsQyxxREFBcUQ7QUFDckQsTUFBTSxXQUFXLGdCQUFnQjtJQUMvQix1Q0FBdUM7SUFDdkMsOEJBQThCLEVBQUUsTUFBTSxDQUFDO0lBRXZDLDJGQUEyRjtJQUMzRiwrQkFBK0IsQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUV6QyxtSkFBbUo7SUFDbkoscUJBQXFCLENBQUMsRUFBRSxNQUFNLENBQUM7SUFFL0IsMkpBQTJKO0lBQzNKLG9CQUFvQixDQUFDLEVBQUUsTUFBTSxDQUFDO0lBRTlCLDZKQUE2SjtJQUM3SixzQkFBc0IsQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUVoQyw2SkFBNko7SUFDN0oscUJBQXFCLENBQUMsRUFBRSxNQUFNLENBQUM7SUFFL0IsMkpBQTJKO0lBQzNKLG9CQUFvQixDQUFDLEVBQUUsTUFBTSxDQUFDO0lBRTlCLCtKQUErSjtJQUMvSix1QkFBdUIsQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUVqQywyR0FBMkc7SUFDM0csdUJBQXVCLENBQUMsRUFBRSxNQUFNLENBQUM7SUFFakMscUVBQXFFO0lBQ3JFLDJCQUEyQixFQUFFLE1BQU0sQ0FBQztDQUNyQztBQUVELGVBQU8sTUFBTSx3QkFBd0IsRUFBRSxrQkFBa0IsQ0FBQyxnQkFBZ0IsQ0F5RHpFLENBQUM7QUFFRjs7O0dBR0c7QUFDSCx3QkFBZ0IsMEJBQTBCLElBQUksZ0JBQWdCLENBRTdEIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/synchronizer/config.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/synchronizer/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAIxB,MAAM,0BAA0B,CAAC;AAElC,qDAAqD;AACrD,MAAM,WAAW,gBAAgB;IAC/B,uCAAuC;IACvC,8BAA8B,EAAE,MAAM,CAAC;IAEvC,2FAA2F;IAC3F,+BAA+B,CAAC,EAAE,MAAM,CAAC;IAEzC,mJAAmJ;IACnJ,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B,2JAA2J;IAC3J,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B,6JAA6J;IAC7J,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAEhC,6JAA6J;IAC7J,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B,2JAA2J;IAC3J,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B,+JAA+J;IAC/J,uBAAuB,CAAC,EAAE,MAAM,CAAC;IAEjC,2GAA2G;IAC3G,uBAAuB,CAAC,EAAE,MAAM,CAAC;IAEjC,qEAAqE;IACrE,2BAA2B,EAAE,MAAM,CAAC;CACrC;AAED,eAAO,MAAM,wBAAwB,EAAE,kBAAkB,CAAC,gBAAgB,CAyDzE,CAAC;AAEF;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,gBAAgB,CAE7D"}
|
|
@@ -1,44 +1,43 @@
|
|
|
1
|
-
import { getConfigFromMappings, numberConfigHelper } from '@aztec/foundation/config';
|
|
1
|
+
import { getConfigFromMappings, numberConfigHelper, optionalNumberConfigHelper } from '@aztec/foundation/config';
|
|
2
2
|
export const worldStateConfigMappings = {
|
|
3
3
|
worldStateBlockCheckIntervalMS: {
|
|
4
4
|
env: 'WS_BLOCK_CHECK_INTERVAL_MS',
|
|
5
|
-
|
|
6
|
-
defaultValue: 100,
|
|
5
|
+
...numberConfigHelper(100),
|
|
7
6
|
description: 'The frequency in which to check.'
|
|
8
7
|
},
|
|
9
8
|
worldStateBlockRequestBatchSize: {
|
|
10
9
|
env: 'WS_BLOCK_REQUEST_BATCH_SIZE',
|
|
11
|
-
|
|
10
|
+
...optionalNumberConfigHelper(),
|
|
12
11
|
description: 'Size of the batch for each get-blocks request from the synchronizer to the archiver.'
|
|
13
12
|
},
|
|
14
13
|
worldStateDbMapSizeKb: {
|
|
15
14
|
env: 'WS_DB_MAP_SIZE_KB',
|
|
16
|
-
|
|
15
|
+
...optionalNumberConfigHelper(),
|
|
17
16
|
description: 'The maximum possible size of the world state DB in KB. Overwrites the general dataStoreMapSizeKb.'
|
|
18
17
|
},
|
|
19
18
|
archiveTreeMapSizeKb: {
|
|
20
19
|
env: 'ARCHIVE_TREE_MAP_SIZE_KB',
|
|
21
|
-
|
|
20
|
+
...optionalNumberConfigHelper(),
|
|
22
21
|
description: 'The maximum possible size of the world state archive tree in KB. Overwrites the general worldStateDbMapSizeKb.'
|
|
23
22
|
},
|
|
24
23
|
nullifierTreeMapSizeKb: {
|
|
25
24
|
env: 'NULLIFIER_TREE_MAP_SIZE_KB',
|
|
26
|
-
|
|
25
|
+
...optionalNumberConfigHelper(),
|
|
27
26
|
description: 'The maximum possible size of the world state nullifier tree in KB. Overwrites the general worldStateDbMapSizeKb.'
|
|
28
27
|
},
|
|
29
28
|
noteHashTreeMapSizeKb: {
|
|
30
29
|
env: 'NOTE_HASH_TREE_MAP_SIZE_KB',
|
|
31
|
-
|
|
30
|
+
...optionalNumberConfigHelper(),
|
|
32
31
|
description: 'The maximum possible size of the world state note hash tree in KB. Overwrites the general worldStateDbMapSizeKb.'
|
|
33
32
|
},
|
|
34
33
|
messageTreeMapSizeKb: {
|
|
35
34
|
env: 'MESSAGE_TREE_MAP_SIZE_KB',
|
|
36
|
-
|
|
35
|
+
...optionalNumberConfigHelper(),
|
|
37
36
|
description: 'The maximum possible size of the world state message tree in KB. Overwrites the general worldStateDbMapSizeKb.'
|
|
38
37
|
},
|
|
39
38
|
publicDataTreeMapSizeKb: {
|
|
40
39
|
env: 'PUBLIC_DATA_TREE_MAP_SIZE_KB',
|
|
41
|
-
|
|
40
|
+
...optionalNumberConfigHelper(),
|
|
42
41
|
description: 'The maximum possible size of the world state public data tree in KB. Overwrites the general worldStateDbMapSizeKb.'
|
|
43
42
|
},
|
|
44
43
|
worldStateDataDirectory: {
|
|
@@ -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
|
|
5
|
+
import { type GenesisData } from '@aztec/stdlib/world-state';
|
|
6
6
|
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
7
7
|
import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
|
|
8
8
|
import { NativeWorldStateService } from '../native/native_world_state.js';
|
|
@@ -15,6 +15,6 @@ export interface WorldStateTreeMapSizes {
|
|
|
15
15
|
messageTreeMapSizeKb: number;
|
|
16
16
|
publicDataTreeMapSizeKb: number;
|
|
17
17
|
}
|
|
18
|
-
export declare function createWorldStateSynchronizer(config: WorldStateConfig & DataStoreConfig, l2BlockSource: L2BlockSource & L1ToL2MessageSource,
|
|
19
|
-
export declare function createWorldState(config: Pick<WorldStateConfig, 'worldStateDataDirectory' | 'worldStateDbMapSizeKb' | 'archiveTreeMapSizeKb' | 'nullifierTreeMapSizeKb' | 'noteHashTreeMapSizeKb' | 'messageTreeMapSizeKb' | 'publicDataTreeMapSizeKb'> & Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKb' | '
|
|
20
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
18
|
+
export declare function createWorldStateSynchronizer(config: WorldStateConfig & DataStoreConfig, l2BlockSource: L2BlockSource & L1ToL2MessageSource, genesisOrNativeWorldState: GenesisData | NativeWorldStateService, client?: TelemetryClient, bindings?: LoggerBindings): Promise<ServerWorldStateSynchronizer>;
|
|
19
|
+
export declare function createWorldState(config: Pick<WorldStateConfig, 'worldStateDataDirectory' | 'worldStateDbMapSizeKb' | 'archiveTreeMapSizeKb' | 'nullifierTreeMapSizeKb' | 'noteHashTreeMapSizeKb' | 'messageTreeMapSizeKb' | 'publicDataTreeMapSizeKb'> & Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKb' | 'rollupAddress'>, genesis?: GenesisData, instrumentation?: WorldStateInstrumentation, bindings?: LoggerBindings): Promise<NativeWorldStateService>;
|
|
20
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmFjdG9yeS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3N5bmNocm9uaXplci9mYWN0b3J5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGNBQWMsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBQzVELE9BQU8sS0FBSyxFQUFFLGFBQWEsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBQ3pELE9BQU8sS0FBSyxFQUFFLGVBQWUsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBQzlELE9BQU8sS0FBSyxFQUFFLG1CQUFtQixFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFDbkUsT0FBTyxFQUFzQixLQUFLLFdBQVcsRUFBaUIsTUFBTSwyQkFBMkIsQ0FBQztBQUNoRyxPQUFPLEVBQUUsS0FBSyxlQUFlLEVBQXNCLE1BQU0seUJBQXlCLENBQUM7QUFFbkYsT0FBTyxFQUFFLHlCQUF5QixFQUFFLE1BQU0sdUNBQXVDLENBQUM7QUFDbEYsT0FBTyxFQUFFLHVCQUF1QixFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDMUUsT0FBTyxLQUFLLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxhQUFhLENBQUM7QUFDcEQsT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AyB,CAC5B,GACC,IAAI,CAAC,eAAe,EAAE,eAAe,GAAG,oBAAoB,GAAG,eAAe,CAAC,EACjF,OAAO,GAAE,WAAgC,EACzC,eAAe,GAAE,yBAA+E,EAChG,QAAQ,CAAC,EAAE,cAAc,oCAkC1B"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { EMPTY_GENESIS_DATA, isGenesisData } from '@aztec/stdlib/world-state';
|
|
1
2
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
2
3
|
import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
|
|
3
4
|
import { NativeWorldStateService } from '../native/native_world_state.js';
|
|
4
5
|
import { ServerWorldStateSynchronizer } from './server_world_state_synchronizer.js';
|
|
5
|
-
export async function createWorldStateSynchronizer(config, l2BlockSource,
|
|
6
|
+
export async function createWorldStateSynchronizer(config, l2BlockSource, genesisOrNativeWorldState, client = getTelemetryClient(), bindings) {
|
|
6
7
|
const instrumentation = new WorldStateInstrumentation(client);
|
|
7
|
-
const merkleTrees = await createWorldState(config,
|
|
8
|
+
const merkleTrees = isGenesisData(genesisOrNativeWorldState) ? await createWorldState(config, genesisOrNativeWorldState, instrumentation, bindings) : genesisOrNativeWorldState;
|
|
8
9
|
return new ServerWorldStateSynchronizer(merkleTrees, l2BlockSource, config, instrumentation);
|
|
9
10
|
}
|
|
10
|
-
export async function createWorldState(config,
|
|
11
|
+
export async function createWorldState(config, genesis = EMPTY_GENESIS_DATA, instrumentation = new WorldStateInstrumentation(getTelemetryClient()), bindings) {
|
|
11
12
|
const dataDirectory = config.worldStateDataDirectory ?? config.dataDirectory;
|
|
12
13
|
const dataStoreMapSizeKb = config.worldStateDbMapSizeKb ?? config.dataStoreMapSizeKb;
|
|
13
14
|
const wsTreeMapSizes = {
|
|
@@ -17,13 +18,13 @@ export async function createWorldState(config, prefilledPublicData = [], instrum
|
|
|
17
18
|
messageTreeMapSizeKb: config.messageTreeMapSizeKb ?? dataStoreMapSizeKb,
|
|
18
19
|
publicDataTreeMapSizeKb: config.publicDataTreeMapSizeKb ?? dataStoreMapSizeKb
|
|
19
20
|
};
|
|
20
|
-
if (!config.
|
|
21
|
+
if (!config.rollupAddress) {
|
|
21
22
|
throw new Error('Rollup address is required to create a world state synchronizer.');
|
|
22
23
|
}
|
|
23
24
|
// If a data directory is provided in config, then create a persistent store.
|
|
24
|
-
const merkleTrees = dataDirectory ? await NativeWorldStateService.new(config.
|
|
25
|
+
const merkleTrees = dataDirectory ? await NativeWorldStateService.new(config.rollupAddress, dataDirectory, wsTreeMapSizes, genesis, instrumentation, bindings) : await NativeWorldStateService.tmp(![
|
|
25
26
|
'true',
|
|
26
27
|
'1'
|
|
27
|
-
].includes(process.env.DEBUG_WORLD_STATE),
|
|
28
|
+
].includes(process.env.DEBUG_WORLD_STATE), genesis, instrumentation, bindings);
|
|
28
29
|
return merkleTrees;
|
|
29
30
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { type Logger } from '@aztec/foundation/log';
|
|
3
|
-
import { type L2BlockSource, L2BlockStream, type L2BlockStreamEvent, type L2BlockStreamEventHandler, type L2BlockStreamLocalDataProvider, type L2Tips } from '@aztec/stdlib/block';
|
|
3
|
+
import { type BlockHash, type L2BlockSource, L2BlockStream, type L2BlockStreamEvent, type L2BlockStreamEventHandler, type L2BlockStreamLocalDataProvider, type L2Tips } from '@aztec/stdlib/block';
|
|
4
4
|
import { type WorldStateSynchronizer, type WorldStateSynchronizerStatus } from '@aztec/stdlib/interfaces/server';
|
|
5
5
|
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
6
6
|
import type { SnapshotDataKeys } from '@aztec/stdlib/snapshots';
|
|
@@ -45,10 +45,10 @@ export declare class ServerWorldStateSynchronizer implements WorldStateSynchroni
|
|
|
45
45
|
/**
|
|
46
46
|
* Forces an immediate sync.
|
|
47
47
|
* @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it.
|
|
48
|
-
* @param
|
|
48
|
+
* @param blockHash - If provided, verifies the block at targetBlockNumber matches this hash. On mismatch, triggers a resync (reorg detection).
|
|
49
49
|
* @returns A promise that resolves with the block number the world state was synced to
|
|
50
50
|
*/
|
|
51
|
-
syncImmediate(targetBlockNumber?: BlockNumber,
|
|
51
|
+
syncImmediate(targetBlockNumber?: BlockNumber, blockHash?: BlockHash): Promise<BlockNumber>;
|
|
52
52
|
/** Returns the L2 block hash for a given number. Used by the L2BlockStream for detecting reorgs. */
|
|
53
53
|
getL2BlockHash(number: BlockNumber): Promise<string | undefined>;
|
|
54
54
|
/** Returns the latest L2 block number for each tip of the chain (latest, proven, finalized). */
|
|
@@ -66,4 +66,4 @@ export declare class ServerWorldStateSynchronizer implements WorldStateSynchroni
|
|
|
66
66
|
*/
|
|
67
67
|
private setCurrentState;
|
|
68
68
|
}
|
|
69
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
69
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VydmVyX3dvcmxkX3N0YXRlX3N5bmNocm9uaXplci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3N5bmNocm9uaXplci9zZXJ2ZXJfd29ybGRfc3RhdGVfc3luY2hyb25pemVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxXQUFXLEVBQW9CLE1BQU0saUNBQWlDLENBQUM7QUFFaEYsT0FBTyxFQUFFLEtBQUssTUFBTSxFQUFnQixNQUFNLHVCQUF1QixDQUFDO0FBR2xFLE9BQU8sRUFDTCxLQUFLLFNBQVMsRUFJZCxLQUFLLGFBQWEsRUFDbEIsYUFBYSxFQUNiLEtBQUssa0JBQWtCLEVBQ3ZCLEtBQUsseUJBQXlCLEVBQzlCLEtBQUssOEJBQThCLEVBQ25DLEtBQUssTUFBTSxFQUNaLE1BQU0scUJB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UFDVSxhQUFhLENBQUMsaUJBQWlCLENBQUMsRUFBRSxXQUFXLEVBQUUsU0FBUyxDQUFDLEVBQUUsU0FBUyxHQUFHLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0EyRXZHO0lBRUQsb0dBQW9HO0lBQ3ZGLGNBQWMsQ0FBQyxNQUFNLEVBQUUsV0FBVyxHQUFHLE9BQU8sQ0FBQyxNQUFNLEdBQUcsU0FBUyxDQUFDLENBSzVFO0lBRUQsZ0dBQWdHO0lBQ25GLFNBQVMsSUFBSSxPQUFPLENBQUMsTUFBTSxDQUFDLENBd0N4QztJQUVELG9EQUFvRDtJQUN2QyxzQkFBc0IsQ0FBQyxLQUFLLEVBQUUsa0JBQWtCLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQWU1RTtZQU9hLGNBQWM7WUF5Q2QsYUFBYTtZQWtCYixvQkFBb0I7SUF1RGxDLE9BQU8sQ0FBQyxpQkFBaUI7WUFNWCxpQkFBaUI7SUFTL0I7OztPQUdHO0lBQ0gsT0FBTyxDQUFDLGVBQWU7Q0FJeEIifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server_world_state_synchronizer.d.ts","sourceRoot":"","sources":["../../src/synchronizer/server_world_state_synchronizer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAoB,MAAM,iCAAiC,CAAC;AAEhF,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAGlE,OAAO,
|
|
1
|
+
{"version":3,"file":"server_world_state_synchronizer.d.ts","sourceRoot":"","sources":["../../src/synchronizer/server_world_state_synchronizer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAoB,MAAM,iCAAiC,CAAC;AAEhF,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAGlE,OAAO,EACL,KAAK,SAAS,EAId,KAAK,aAAa,EAClB,aAAa,EACb,KAAK,kBAAkB,EACvB,KAAK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|
+
import { INITIAL_CHECKPOINT_NUMBER } from '@aztec/constants';
|
|
2
2
|
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
@@ -130,9 +130,9 @@ import { WorldStateSynchronizerError } from './errors.js';
|
|
|
130
130
|
/**
|
|
131
131
|
* Forces an immediate sync.
|
|
132
132
|
* @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it.
|
|
133
|
-
* @param
|
|
133
|
+
* @param blockHash - If provided, verifies the block at targetBlockNumber matches this hash. On mismatch, triggers a resync (reorg detection).
|
|
134
134
|
* @returns A promise that resolves with the block number the world state was synced to
|
|
135
|
-
*/ async syncImmediate(targetBlockNumber,
|
|
135
|
+
*/ async syncImmediate(targetBlockNumber, blockHash) {
|
|
136
136
|
if (this.currentState !== WorldStateRunningState.RUNNING) {
|
|
137
137
|
throw new Error(`World State is not running. Unable to perform sync.`);
|
|
138
138
|
}
|
|
@@ -142,7 +142,16 @@ import { WorldStateSynchronizerError } from './errors.js';
|
|
|
142
142
|
// If we have been given a block number to sync to and we have reached that number then return
|
|
143
143
|
const currentBlockNumber = await this.getLatestBlockNumber();
|
|
144
144
|
if (targetBlockNumber !== undefined && targetBlockNumber <= currentBlockNumber) {
|
|
145
|
-
|
|
145
|
+
if (blockHash === undefined) {
|
|
146
|
+
return currentBlockNumber;
|
|
147
|
+
}
|
|
148
|
+
// If a block hash was provided, verify we're on the expected fork
|
|
149
|
+
const currentHash = await this.getL2BlockHash(targetBlockNumber);
|
|
150
|
+
if (currentHash === blockHash.toString()) {
|
|
151
|
+
return currentBlockNumber;
|
|
152
|
+
}
|
|
153
|
+
// Hash mismatch: a reorg may have occurred, fall through to trigger sync
|
|
154
|
+
this.log.debug(`World state block hash mismatch at ${targetBlockNumber} (expected ${blockHash}, got ${currentHash}). Triggering resync.`);
|
|
146
155
|
}
|
|
147
156
|
this.log.debug(`World State at ${currentBlockNumber} told to sync to ${targetBlockNumber ?? 'latest'}`);
|
|
148
157
|
// If the archiver is behind the target block, force an archiver sync
|
|
@@ -157,7 +166,7 @@ import { WorldStateSynchronizerError } from './errors.js';
|
|
|
157
166
|
await this.blockStream.sync();
|
|
158
167
|
// If we have been given a block number to sync to and we have not reached that number then fail
|
|
159
168
|
const updatedBlockNumber = await this.getLatestBlockNumber();
|
|
160
|
-
if (
|
|
169
|
+
if (targetBlockNumber !== undefined && targetBlockNumber > updatedBlockNumber) {
|
|
161
170
|
throw new WorldStateSynchronizerError(`Unable to sync to block number ${targetBlockNumber} (last synced is ${updatedBlockNumber})`, {
|
|
162
171
|
cause: {
|
|
163
172
|
reason: 'block_not_available',
|
|
@@ -167,6 +176,20 @@ import { WorldStateSynchronizerError } from './errors.js';
|
|
|
167
176
|
}
|
|
168
177
|
});
|
|
169
178
|
}
|
|
179
|
+
// If a block hash was provided, verify we're on the expected fork after syncing, throw otherwise
|
|
180
|
+
if (blockHash !== undefined && targetBlockNumber !== undefined) {
|
|
181
|
+
const updatedHash = await this.getL2BlockHash(targetBlockNumber);
|
|
182
|
+
if (updatedHash !== blockHash.toString()) {
|
|
183
|
+
throw new WorldStateSynchronizerError(`Block hash mismatch at block ${targetBlockNumber} (expected ${blockHash} but got ${updatedHash})`, {
|
|
184
|
+
cause: {
|
|
185
|
+
reason: 'block_hash_mismatch',
|
|
186
|
+
targetBlockNumber,
|
|
187
|
+
expectedHash: blockHash.toString(),
|
|
188
|
+
actualHash: updatedHash
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
170
193
|
return updatedBlockNumber;
|
|
171
194
|
}
|
|
172
195
|
/** Returns the L2 block hash for a given number. Used by the L2BlockStream for detecting reorgs. */ async getL2BlockHash(number) {
|
|
@@ -194,15 +217,26 @@ import { WorldStateSynchronizerError } from './errors.js';
|
|
|
194
217
|
// but we use a block stream so we need to provide 'local' L2Tips.
|
|
195
218
|
// We configure the block stream to ignore checkpoints and set checkpoint values to genesis here.
|
|
196
219
|
const genesisCheckpointHeaderHash = GENESIS_CHECKPOINT_HEADER_HASH.toString();
|
|
220
|
+
const initialBlockHash = (await this.merkleTreeCommitted.getInitialHeader().hash()).toString();
|
|
197
221
|
return {
|
|
198
222
|
proposed: latestBlockId,
|
|
199
223
|
checkpointed: {
|
|
200
224
|
block: {
|
|
201
|
-
number:
|
|
202
|
-
hash:
|
|
225
|
+
number: BlockNumber.ZERO,
|
|
226
|
+
hash: initialBlockHash
|
|
203
227
|
},
|
|
204
228
|
checkpoint: {
|
|
205
|
-
number:
|
|
229
|
+
number: INITIAL_CHECKPOINT_NUMBER,
|
|
230
|
+
hash: genesisCheckpointHeaderHash
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
proposedCheckpoint: {
|
|
234
|
+
block: {
|
|
235
|
+
number: BlockNumber.ZERO,
|
|
236
|
+
hash: initialBlockHash
|
|
237
|
+
},
|
|
238
|
+
checkpoint: {
|
|
239
|
+
number: INITIAL_CHECKPOINT_NUMBER,
|
|
206
240
|
hash: genesisCheckpointHeaderHash
|
|
207
241
|
}
|
|
208
242
|
},
|
|
@@ -212,7 +246,7 @@ import { WorldStateSynchronizerError } from './errors.js';
|
|
|
212
246
|
hash: finalizedBlockHash ?? ''
|
|
213
247
|
},
|
|
214
248
|
checkpoint: {
|
|
215
|
-
number:
|
|
249
|
+
number: INITIAL_CHECKPOINT_NUMBER,
|
|
216
250
|
hash: genesisCheckpointHeaderHash
|
|
217
251
|
}
|
|
218
252
|
},
|
|
@@ -222,7 +256,7 @@ import { WorldStateSynchronizerError } from './errors.js';
|
|
|
222
256
|
hash: provenBlockHash ?? ''
|
|
223
257
|
},
|
|
224
258
|
checkpoint: {
|
|
225
|
-
number:
|
|
259
|
+
number: INITIAL_CHECKPOINT_NUMBER,
|
|
226
260
|
hash: genesisCheckpointHeaderHash
|
|
227
261
|
}
|
|
228
262
|
}
|
|
@@ -296,34 +330,50 @@ import { WorldStateSynchronizerError } from './errors.js';
|
|
|
296
330
|
}
|
|
297
331
|
async handleChainFinalized(blockNumber) {
|
|
298
332
|
this.log.verbose(`Finalized chain is now at block ${blockNumber}`);
|
|
333
|
+
// If the finalized block number is older than the oldest available block in world state,
|
|
334
|
+
// skip entirely. The finalized block number can jump backwards (e.g. when the finalization
|
|
335
|
+
// heuristic changes) and try to read block data that has already been pruned. When this
|
|
336
|
+
// happens, there is nothing useful to do — the native world state is already finalized
|
|
337
|
+
// past this point and pruning has already happened.
|
|
338
|
+
const currentSummary = await this.merkleTreeDb.getStatusSummary();
|
|
339
|
+
if (blockNumber < currentSummary.oldestHistoricalBlock || blockNumber < 1) {
|
|
340
|
+
this.log.trace(`Finalized block ${blockNumber} is older than the oldest available block ${currentSummary.oldestHistoricalBlock}. Skipping.`);
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
299
343
|
const summary = await this.merkleTreeDb.setFinalized(blockNumber);
|
|
300
344
|
if (this.historyToKeep === undefined) {
|
|
301
345
|
return;
|
|
302
346
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
347
|
+
const finalisedBlockData = await this.l2BlockSource.getBlockData({
|
|
348
|
+
number: summary.finalizedBlockNumber
|
|
349
|
+
});
|
|
350
|
+
if (finalisedBlockData === undefined) {
|
|
306
351
|
this.log.warn(`Failed to retrieve checkpointed block for finalized block number: ${summary.finalizedBlockNumber}`);
|
|
307
352
|
return;
|
|
308
353
|
}
|
|
309
354
|
// Compute the required historic checkpoint number
|
|
310
|
-
const newHistoricCheckpointNumber =
|
|
355
|
+
const newHistoricCheckpointNumber = finalisedBlockData.checkpointNumber - this.historyToKeep + 1;
|
|
311
356
|
if (newHistoricCheckpointNumber <= 1) {
|
|
312
357
|
return;
|
|
313
358
|
}
|
|
314
359
|
// Retrieve the historic checkpoint
|
|
315
|
-
const
|
|
316
|
-
|
|
360
|
+
const historicCheckpoint = await this.l2BlockSource.getCheckpoint({
|
|
361
|
+
number: CheckpointNumber(newHistoricCheckpointNumber)
|
|
362
|
+
});
|
|
363
|
+
if (!historicCheckpoint) {
|
|
317
364
|
this.log.warn(`Failed to retrieve checkpoint number ${newHistoricCheckpointNumber} from Archiver`);
|
|
318
365
|
return;
|
|
319
366
|
}
|
|
320
|
-
const historicCheckpoint = historicCheckpoints[0];
|
|
321
367
|
if (historicCheckpoint.checkpoint.blocks.length === 0 || historicCheckpoint.checkpoint.blocks[0] === undefined) {
|
|
322
368
|
this.log.warn(`Retrieved checkpoint number ${newHistoricCheckpointNumber} has no blocks!`);
|
|
323
369
|
return;
|
|
324
370
|
}
|
|
325
371
|
// Find the block at the start of the checkpoint and remove blocks up to this one
|
|
326
372
|
const newHistoricBlock = historicCheckpoint.checkpoint.blocks[0];
|
|
373
|
+
if (newHistoricBlock.number <= currentSummary.oldestHistoricalBlock) {
|
|
374
|
+
this.log.debug(`Historic block ${newHistoricBlock.number} is not newer than oldest available ${currentSummary.oldestHistoricalBlock}. Skipping prune.`);
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
327
377
|
this.log.verbose(`Pruning historic blocks to ${newHistoricBlock.number}`);
|
|
328
378
|
const status = await this.merkleTreeDb.removeHistoricalBlocks(BlockNumber(newHistoricBlock.number));
|
|
329
379
|
this.log.debug(`World state summary `, status.summary);
|
|
@@ -334,9 +384,11 @@ import { WorldStateSynchronizerError } from './errors.js';
|
|
|
334
384
|
return Promise.resolve();
|
|
335
385
|
}
|
|
336
386
|
async handleChainPruned(blockNumber) {
|
|
337
|
-
this.log.
|
|
387
|
+
this.log.info(`Chain pruned to block ${blockNumber}`);
|
|
338
388
|
const status = await this.merkleTreeDb.unwindBlocks(blockNumber);
|
|
339
|
-
this.provenBlockNumber
|
|
389
|
+
if (this.provenBlockNumber !== undefined && this.provenBlockNumber > blockNumber) {
|
|
390
|
+
this.provenBlockNumber = undefined;
|
|
391
|
+
}
|
|
340
392
|
this.instrumentation.updateWorldStateMetrics(status);
|
|
341
393
|
}
|
|
342
394
|
/**
|