@aztec/aztec-node 5.0.0-rc.1 → 5.0.0-rc.2
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/aztec-node/config.d.ts +3 -1
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +5 -0
- package/dest/aztec-node/node_public_calls_simulator.d.ts +90 -0
- package/dest/aztec-node/node_public_calls_simulator.d.ts.map +1 -0
- package/dest/aztec-node/node_public_calls_simulator.js +346 -0
- package/dest/aztec-node/server.d.ts +68 -65
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +153 -1161
- package/dest/bin/index.js +2 -2
- package/dest/factory.d.ts +33 -0
- package/dest/factory.d.ts.map +1 -0
- package/dest/factory.js +496 -0
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/modules/block_parameter.d.ts +25 -0
- package/dest/modules/block_parameter.d.ts.map +1 -0
- package/dest/modules/block_parameter.js +100 -0
- package/dest/modules/node_block_provider.d.ts +19 -0
- package/dest/modules/node_block_provider.d.ts.map +1 -0
- package/dest/modules/node_block_provider.js +112 -0
- package/dest/modules/node_tx_receipt.d.ts +24 -0
- package/dest/modules/node_tx_receipt.d.ts.map +1 -0
- package/dest/modules/node_tx_receipt.js +70 -0
- package/dest/modules/node_world_state_queries.d.ts +61 -0
- package/dest/modules/node_world_state_queries.d.ts.map +1 -0
- package/dest/modules/node_world_state_queries.js +257 -0
- package/dest/sentinel/factory.d.ts +3 -3
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/factory.js +8 -1
- package/dest/sentinel/sentinel.d.ts +21 -21
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +27 -47
- package/package.json +28 -27
- package/src/aztec-node/config.ts +7 -0
- package/src/aztec-node/node_public_calls_simulator.ts +383 -0
- package/src/aztec-node/server.ts +221 -1342
- package/src/bin/index.ts +7 -2
- package/src/factory.ts +656 -0
- package/src/index.ts +1 -0
- package/src/modules/block_parameter.ts +93 -0
- package/src/modules/node_block_provider.ts +149 -0
- package/src/modules/node_tx_receipt.ts +115 -0
- package/src/modules/node_world_state_queries.ts +360 -0
- package/src/sentinel/README.md +3 -3
- package/src/sentinel/factory.ts +15 -3
- package/src/sentinel/sentinel.ts +34 -72
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { chunkBy } from '@aztec/foundation/collection';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
+
import { MembershipWitness } from '@aztec/foundation/trees';
|
|
6
|
+
import { inspectBlockParameter } from '@aztec/stdlib/block';
|
|
7
|
+
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
8
|
+
import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
9
|
+
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
10
|
+
import { normalizeBlockParameter } from './block_parameter.js';
|
|
11
|
+
/**
|
|
12
|
+
* Serves the node's Merkle-tree and membership-witness queries against committed world-state at a
|
|
13
|
+
* requested block. Extracted from `AztecNodeService` so the block-resolution and reorg-aware sync logic
|
|
14
|
+
* can be unit-tested without standing up the whole node, and to keep `server.ts` smaller.
|
|
15
|
+
*/ export class NodeWorldStateQueries {
|
|
16
|
+
worldStateSynchronizer;
|
|
17
|
+
blockSource;
|
|
18
|
+
l1ToL2MessageSource;
|
|
19
|
+
log;
|
|
20
|
+
constructor(deps){
|
|
21
|
+
this.worldStateSynchronizer = deps.worldStateSynchronizer;
|
|
22
|
+
this.blockSource = deps.blockSource;
|
|
23
|
+
this.l1ToL2MessageSource = deps.l1ToL2MessageSource;
|
|
24
|
+
this.log = deps.log ?? createLogger('node:world-state-queries');
|
|
25
|
+
}
|
|
26
|
+
async findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
27
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
28
|
+
const maybeIndices = await committedDb.findLeafIndices(treeId, leafValues.map((x)=>x.toBuffer()));
|
|
29
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
30
|
+
const definedIndices = maybeIndices.filter((x)=>x !== undefined);
|
|
31
|
+
// Now we find the block numbers for the defined indices
|
|
32
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
33
|
+
// Build a map from leaf index to block number
|
|
34
|
+
const indexToBlockNumber = new Map();
|
|
35
|
+
for(let i = 0; i < definedIndices.length; i++){
|
|
36
|
+
const blockNumber = blockNumbers[i];
|
|
37
|
+
if (blockNumber === undefined) {
|
|
38
|
+
throw new Error(`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`);
|
|
39
|
+
}
|
|
40
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
41
|
+
}
|
|
42
|
+
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
43
|
+
const uniqueBlockNumbers = [
|
|
44
|
+
...new Set(indexToBlockNumber.values())
|
|
45
|
+
];
|
|
46
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
47
|
+
const blockHashes = await Promise.all(uniqueBlockNumbers.map((blockNumber)=>{
|
|
48
|
+
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
49
|
+
}));
|
|
50
|
+
// Build a map from block number to block hash
|
|
51
|
+
const blockNumberToHash = new Map();
|
|
52
|
+
for(let i = 0; i < uniqueBlockNumbers.length; i++){
|
|
53
|
+
const blockHash = blockHashes[i];
|
|
54
|
+
if (blockHash === undefined) {
|
|
55
|
+
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
56
|
+
}
|
|
57
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
58
|
+
}
|
|
59
|
+
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
60
|
+
return maybeIndices.map((index)=>{
|
|
61
|
+
if (index === undefined) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
65
|
+
if (blockNumber === undefined) {
|
|
66
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
67
|
+
}
|
|
68
|
+
const l2BlockHash = blockNumberToHash.get(blockNumber);
|
|
69
|
+
if (l2BlockHash === undefined) {
|
|
70
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
l2BlockNumber: blockNumber,
|
|
74
|
+
l2BlockHash,
|
|
75
|
+
data: index
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
async getBlockHashMembershipWitness(referenceBlock, blockHash) {
|
|
80
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
81
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
82
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
83
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
84
|
+
if (referenceBlockNumber === BlockNumber.ZERO) {
|
|
85
|
+
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
89
|
+
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
90
|
+
blockHash
|
|
91
|
+
]);
|
|
92
|
+
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
93
|
+
}
|
|
94
|
+
async getNoteHashMembershipWitness(referenceBlock, noteHash) {
|
|
95
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
96
|
+
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
|
|
97
|
+
noteHash
|
|
98
|
+
]);
|
|
99
|
+
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
100
|
+
}
|
|
101
|
+
async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
|
|
102
|
+
const db = await this.getWorldState(referenceBlock);
|
|
103
|
+
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
|
|
104
|
+
l1ToL2Message
|
|
105
|
+
]);
|
|
106
|
+
if (!witness) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
// REFACTOR: Return a MembershipWitness object
|
|
110
|
+
return [
|
|
111
|
+
witness.index,
|
|
112
|
+
witness.path
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
async getL1ToL2MessageCheckpoint(l1ToL2Message) {
|
|
116
|
+
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
117
|
+
return messageIndex !== undefined ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Returns all the L2 to L1 messages in an epoch (empty array if the epoch is not found). The public
|
|
121
|
+
* `AztecNodeService.getL2ToL1Messages` that delegates here is deprecated in favor of
|
|
122
|
+
* {@link getL2ToL1MembershipWitness}.
|
|
123
|
+
* @param epoch - The epoch at which to get the data.
|
|
124
|
+
*/ async getL2ToL1Messages(epoch) {
|
|
125
|
+
const blocks = await this.blockSource.getBlocks({
|
|
126
|
+
epoch,
|
|
127
|
+
onlyCheckpointed: true
|
|
128
|
+
});
|
|
129
|
+
const blocksInCheckpoints = chunkBy(blocks, (block)=>block.header.globalVariables.slotNumber);
|
|
130
|
+
return blocksInCheckpoints.map((slotBlocks)=>slotBlocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Returns the L2-to-L1 membership witness for a message in `txHash`. Passthrough to the
|
|
134
|
+
* archiver's locally-cached resolver — see {@link Archiver.getL2ToL1MembershipWitness}.
|
|
135
|
+
*/ getL2ToL1MembershipWitness(txHash, message, messageIndexInTx) {
|
|
136
|
+
return this.blockSource.getL2ToL1MembershipWitness(txHash, message, messageIndexInTx);
|
|
137
|
+
}
|
|
138
|
+
async getNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
139
|
+
const db = await this.getWorldState(referenceBlock);
|
|
140
|
+
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
|
|
141
|
+
nullifier.toBuffer()
|
|
142
|
+
]);
|
|
143
|
+
if (!witness) {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
const { index, path } = witness;
|
|
147
|
+
const leafPreimage = await db.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
148
|
+
if (!leafPreimage) {
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
return new NullifierMembershipWitness(index, leafPreimage, path);
|
|
152
|
+
}
|
|
153
|
+
async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
154
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
155
|
+
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
156
|
+
if (!findResult) {
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
const { index, alreadyPresent } = findResult;
|
|
160
|
+
if (alreadyPresent) {
|
|
161
|
+
throw new Error(`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`);
|
|
162
|
+
}
|
|
163
|
+
const preimageData = await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
164
|
+
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
165
|
+
return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
|
|
166
|
+
}
|
|
167
|
+
async getPublicDataWitness(referenceBlock, leafSlot) {
|
|
168
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
169
|
+
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
170
|
+
if (!lowLeafResult) {
|
|
171
|
+
return undefined;
|
|
172
|
+
} else {
|
|
173
|
+
const preimage = await committedDb.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
174
|
+
const path = await committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
175
|
+
return new PublicDataWitness(lowLeafResult.index, preimage, path);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
async getPublicStorageAt(referenceBlock, contract, slot) {
|
|
179
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
180
|
+
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
181
|
+
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
182
|
+
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
183
|
+
return Fr.ZERO;
|
|
184
|
+
}
|
|
185
|
+
const preimage = await committedDb.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
186
|
+
return preimage.leaf.value;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
190
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
191
|
+
* @returns An instance of a committed MerkleTreeOperations
|
|
192
|
+
*/ async getWorldState(block) {
|
|
193
|
+
const query = normalizeBlockParameter(block);
|
|
194
|
+
// When the request anchors on a specific block hash, resolve it against the archiver up front and
|
|
195
|
+
// drive the world-state sync to that exact block number and hash. Resolving against the archiver
|
|
196
|
+
// first fails fast with a clear reorg error if the hash is unknown, and passing the hash to the
|
|
197
|
+
// synchronizer makes the sync reorg-aware: it barriers until the archive-tree commit for that block
|
|
198
|
+
// has landed and verifies it matches the requested fork, instead of syncing to bare latest height
|
|
199
|
+
// and then racing the snapshot read below against an in-flight archive-tree write.
|
|
200
|
+
const requestedHash = 'hash' in query ? query.hash : undefined;
|
|
201
|
+
const anchorBlockNumber = requestedHash !== undefined ? await this.resolveBlockNumber(query) : undefined;
|
|
202
|
+
let blockSyncedTo = BlockNumber.ZERO;
|
|
203
|
+
try {
|
|
204
|
+
// Attempt to sync the world state if necessary
|
|
205
|
+
blockSyncedTo = await this.#syncWorldState(anchorBlockNumber, requestedHash);
|
|
206
|
+
} catch (err) {
|
|
207
|
+
this.log.error(`Error getting world state: ${err}`);
|
|
208
|
+
}
|
|
209
|
+
if ('tag' in query && query.tag === 'proposed') {
|
|
210
|
+
this.log.debug(`Using committed db for latest block, world state synced upto ${blockSyncedTo}`);
|
|
211
|
+
return this.worldStateSynchronizer.getCommitted();
|
|
212
|
+
}
|
|
213
|
+
const blockNumber = anchorBlockNumber ?? await this.resolveBlockNumber(query);
|
|
214
|
+
// Check it's within world state sync range
|
|
215
|
+
if (blockNumber > blockSyncedTo) {
|
|
216
|
+
throw new Error(`Queried block ${inspectBlockParameter(block)} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
217
|
+
}
|
|
218
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
219
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
220
|
+
// Double-check world-state synced to the same block hash as was requested.
|
|
221
|
+
// Block 0 is skipped: the snapshot returned by `getSnapshot(0)` is the *pre*-genesis archive
|
|
222
|
+
// (size 0), so leaf 0 is not yet inserted from that snapshot's view even though block 0's hash
|
|
223
|
+
// does live at archive index 0 in the committed tree. The genesis hash is already validated by
|
|
224
|
+
// the archiver when it resolves the hash query to block number 0.
|
|
225
|
+
if (requestedHash !== undefined && blockNumber !== BlockNumber.ZERO) {
|
|
226
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
227
|
+
if (!blockHash || !requestedHash.equals(blockHash)) {
|
|
228
|
+
throw new Error(`Block hash ${requestedHash.toString()} not found in world state at block number ${blockNumber} (world state has ${blockHash?.toString() ?? 'no hash'} at that index, genesis header hash is ${this.blockSource.getGenesisBlockHash().toString()}). If the node API has been queried with anchor block hash possibly a reorg has occurred.`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return snapshot;
|
|
232
|
+
}
|
|
233
|
+
/** Resolves any {@link BlockParameter} variant to a concrete block number. */ async resolveBlockNumber(block) {
|
|
234
|
+
const query = normalizeBlockParameter(block);
|
|
235
|
+
const blockNumber = await this.blockSource.getBlockNumber(query);
|
|
236
|
+
if (blockNumber === undefined) {
|
|
237
|
+
if ('hash' in query) {
|
|
238
|
+
throw new Error(`Block hash ${query.hash.toString()} not found when querying world state. If the node API has been queried with anchor block hash possibly a reorg has occurred.`);
|
|
239
|
+
}
|
|
240
|
+
if ('archive' in query) {
|
|
241
|
+
throw new Error(`Block with archive ${query.archive.toString()} not found.`);
|
|
242
|
+
}
|
|
243
|
+
throw new Error(`Block not found for ${inspectBlockParameter(block)}.`);
|
|
244
|
+
}
|
|
245
|
+
return blockNumber;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Ensure the world state is synced.
|
|
249
|
+
* @param targetBlockNumber - Block to sync up to. Defaults to the latest block known to the archiver.
|
|
250
|
+
* @param blockHash - If provided, the synchronizer verifies the block at `targetBlockNumber` matches this
|
|
251
|
+
* hash, resyncing (and so detecting reorgs) if it does not yet match or has been reorged away.
|
|
252
|
+
* @returns A promise that fulfils once the world state is synced
|
|
253
|
+
*/ async #syncWorldState(targetBlockNumber, blockHash) {
|
|
254
|
+
const target = targetBlockNumber ?? await this.blockSource.getBlockNumber();
|
|
255
|
+
return await this.worldStateSynchronizer.syncImmediate(target, blockHash);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
@@ -3,9 +3,9 @@ import type { P2PClient } from '@aztec/p2p';
|
|
|
3
3
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
4
4
|
import type { CheckpointReexecutionTracker } from '@aztec/stdlib/checkpoint';
|
|
5
5
|
import type { ChainConfig } from '@aztec/stdlib/config';
|
|
6
|
-
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
6
|
+
import type { SlasherConfig, ValidatorClientConfig } from '@aztec/stdlib/interfaces/server';
|
|
7
7
|
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
8
8
|
import type { SentinelConfig } from './config.js';
|
|
9
9
|
import { Sentinel } from './sentinel.js';
|
|
10
|
-
export declare function createSentinel(epochCache: EpochCache, archiver: L2BlockSource, p2p: P2PClient, reexecutionTracker: CheckpointReexecutionTracker, config: SentinelConfig & DataStoreConfig & SlasherConfig & Pick<ChainConfig, 'l1ChainId' | 'rollupAddress'>, logger?: import("@aztec/foundation/log").Logger): Promise<Sentinel | undefined>;
|
|
11
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
10
|
+
export declare function createSentinel(epochCache: EpochCache, archiver: L2BlockSource, p2p: P2PClient, reexecutionTracker: CheckpointReexecutionTracker, config: SentinelConfig & DataStoreConfig & SlasherConfig & Pick<ChainConfig, 'l1ChainId' | 'rollupAddress'> & Pick<ValidatorClientConfig, 'disableValidator'>, logger?: import("@aztec/foundation/log").Logger): Promise<Sentinel | undefined>;
|
|
11
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmFjdG9yeS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vL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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/sentinel/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/sentinel/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAC5F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,wBAAsB,cAAc,CAClC,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,aAAa,EACvB,GAAG,EAAE,SAAS,EACd,kBAAkB,EAAE,4BAA4B,EAChD,MAAM,EAAE,cAAc,GACpB,eAAe,GACf,aAAa,GACb,IAAI,CAAC,WAAW,EAAE,WAAW,GAAG,eAAe,CAAC,GAChD,IAAI,CAAC,qBAAqB,EAAE,kBAAkB,CAAC,EACjD,MAAM,yCAAgC,GACrC,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAoB/B"}
|
package/dest/sentinel/factory.js
CHANGED
|
@@ -3,9 +3,16 @@ import { createStore } from '@aztec/kv-store/lmdb-v2';
|
|
|
3
3
|
import { Sentinel } from './sentinel.js';
|
|
4
4
|
import { SentinelStore } from './store.js';
|
|
5
5
|
export async function createSentinel(epochCache, archiver, p2p, reexecutionTracker, config, logger = createLogger('node:sentinel')) {
|
|
6
|
-
|
|
6
|
+
const runsValidator = !config.disableValidator;
|
|
7
|
+
if (!runsValidator && !config.sentinelEnabled) {
|
|
8
|
+
logger.verbose('Sentinel is disabled');
|
|
7
9
|
return undefined;
|
|
8
10
|
}
|
|
11
|
+
if (runsValidator) {
|
|
12
|
+
logger.info('Enabling sentinel since this node runs a validator');
|
|
13
|
+
} else {
|
|
14
|
+
logger.info('Enabling sentinel from SENTINEL_ENABLED configuration');
|
|
15
|
+
}
|
|
9
16
|
const kvStore = await createStore('sentinel', SentinelStore.SCHEMA_VERSION, config, logger.getBindings());
|
|
10
17
|
const storeHistoryLength = config.sentinelHistoryLengthInEpochs * epochCache.getL1Constants().epochDuration;
|
|
11
18
|
const storeHistoricEpochPerformanceLength = config.sentinelHistoricEpochPerformanceLengthInEpochs;
|
|
@@ -2,11 +2,10 @@ import type { EpochCache } from '@aztec/epoch-cache';
|
|
|
2
2
|
import { CheckpointNumber, CheckpointProposalHash, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
4
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
5
|
-
import { type L2TipsStore } from '@aztec/kv-store/stores';
|
|
6
5
|
import type { P2PClient } from '@aztec/p2p';
|
|
7
6
|
import { type Watcher, type WatcherEmitter } from '@aztec/slasher';
|
|
8
7
|
import type { SlasherConfig } from '@aztec/slasher/config';
|
|
9
|
-
import { type L2BlockSource
|
|
8
|
+
import { type L2BlockSource } from '@aztec/stdlib/block';
|
|
10
9
|
import type { CheckpointReexecutionTracker } from '@aztec/stdlib/checkpoint';
|
|
11
10
|
import type { ChainConfig } from '@aztec/stdlib/config';
|
|
12
11
|
import type { SingleValidatorStats, ValidatorStats, ValidatorStatusHistory, ValidatorStatusInSlot, ValidatorStatusType, ValidatorsEpochPerformance, ValidatorsStats } from '@aztec/stdlib/validators';
|
|
@@ -46,7 +45,7 @@ declare const Sentinel_base: new () => WatcherEmitter;
|
|
|
46
45
|
* first:
|
|
47
46
|
*
|
|
48
47
|
* - `checkpoint-mined` — a checkpoint covering this slot has landed on L1
|
|
49
|
-
* (
|
|
48
|
+
* (fetched on demand via `archiver.getCheckpoint({ slot })`).
|
|
50
49
|
* - `checkpoint-valid` — the local node re-executed a checkpoint proposal for this slot
|
|
51
50
|
* successfully (consulted via `CheckpointReexecutionTracker`).
|
|
52
51
|
* - `checkpoint-invalid` — the local node re-executed a checkpoint proposal for this slot
|
|
@@ -84,7 +83,7 @@ declare const Sentinel_base: new () => WatcherEmitter;
|
|
|
84
83
|
* (no history entries for that slot) and per-epoch evaluation writes an empty performance map
|
|
85
84
|
* (no slashing).
|
|
86
85
|
*/
|
|
87
|
-
export declare class Sentinel extends Sentinel_base implements
|
|
86
|
+
export declare class Sentinel extends Sentinel_base implements Watcher {
|
|
88
87
|
protected epochCache: EpochCache;
|
|
89
88
|
protected archiver: L2BlockSource;
|
|
90
89
|
protected p2p: P2PClient;
|
|
@@ -93,29 +92,19 @@ export declare class Sentinel extends Sentinel_base implements L2BlockStreamEven
|
|
|
93
92
|
protected config: SentinelRuntimeConfig;
|
|
94
93
|
protected logger: import("@aztec/foundation/log").Logger;
|
|
95
94
|
protected runningPromise: RunningPromise;
|
|
96
|
-
protected blockStream: L2BlockStream;
|
|
97
|
-
protected l2TipsStore: L2TipsStore;
|
|
98
95
|
protected initialSlot: SlotNumber | undefined;
|
|
99
96
|
protected lastProcessedSlot: SlotNumber | undefined;
|
|
100
97
|
/** Largest epoch number for which the end-of-epoch aggregator has run. */
|
|
101
98
|
protected lastEvaluatedEpoch: EpochNumber | undefined;
|
|
102
|
-
protected slotNumberToCheckpoint: Map<SlotNumber, {
|
|
103
|
-
checkpointNumber: CheckpointNumber;
|
|
104
|
-
archive: string;
|
|
105
|
-
/** Hex keccak256 of the consensus payload bytes; used to fetch matching p2p attestations. */
|
|
106
|
-
proposalPayloadHash: CheckpointProposalHash;
|
|
107
|
-
attestors: EthAddress[];
|
|
108
|
-
}>;
|
|
109
99
|
constructor(epochCache: EpochCache, archiver: L2BlockSource, p2p: P2PClient, store: SentinelStore, reexecutionTracker: CheckpointReexecutionTracker, config: SentinelRuntimeConfig, logger?: import("@aztec/foundation/log").Logger);
|
|
110
100
|
private getSignatureContext;
|
|
111
101
|
updateConfig(config: Partial<SlasherConfig>): void;
|
|
112
102
|
start(): Promise<void>;
|
|
113
103
|
/**
|
|
114
|
-
* Loads initial slot
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
* (cold start).
|
|
104
|
+
* Loads the initial slot. We will not process anything at or before the initial slot. Floors at the
|
|
105
|
+
* archiver's synced L2 slot so the sentinel keeps making forward progress when L1 is advancing but L2 has no
|
|
106
|
+
* activity (the synced slot is driven by L1 sync, not by L2 blocks). Falls back to the wallclock if the
|
|
107
|
+
* archiver isn't ready yet (cold start).
|
|
119
108
|
*/
|
|
120
109
|
protected init(): Promise<void>;
|
|
121
110
|
/**
|
|
@@ -127,8 +116,19 @@ export declare class Sentinel extends Sentinel_base implements L2BlockStreamEven
|
|
|
127
116
|
*/
|
|
128
117
|
protected getCurrentSlot(): Promise<SlotNumber>;
|
|
129
118
|
stop(): Promise<void>;
|
|
130
|
-
|
|
131
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Fetches the L1-confirmed checkpoint covering a slot (if any) and derives the slot-level data the
|
|
121
|
+
* activity classifier needs: the checkpoint number, archive root, consensus payload hash (used to fetch
|
|
122
|
+
* matching p2p attestations regardless of feeAssetPriceModifier variants), and the recovered attestor set.
|
|
123
|
+
* Reads on demand so the result is always against the canonical chain — a reorged-out checkpoint simply
|
|
124
|
+
* stops being returned, with no stale mapping to clean up.
|
|
125
|
+
*/
|
|
126
|
+
protected getCheckpointForSlot(slot: SlotNumber): Promise<{
|
|
127
|
+
checkpointNumber: CheckpointNumber;
|
|
128
|
+
archive: string;
|
|
129
|
+
proposalPayloadHash: CheckpointProposalHash;
|
|
130
|
+
attestors: EthAddress[];
|
|
131
|
+
} | undefined>;
|
|
132
132
|
/**
|
|
133
133
|
* Called once per epoch, after the configured end-of-epoch buffer has elapsed beyond the
|
|
134
134
|
* epoch's last slot. Computes per-epoch performance from the slot-level history collected
|
|
@@ -214,4 +214,4 @@ export declare class Sentinel extends Sentinel_base implements L2BlockStreamEven
|
|
|
214
214
|
} | undefined;
|
|
215
215
|
}
|
|
216
216
|
export {};
|
|
217
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
217
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VudGluZWwuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zZW50aW5lbC9zZW50aW5lbC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUNyRCxPQUFPLEVBQUUsZ0JBQWdCLEVBQUUsc0JBQXNCLEVBQUUsV0FBVyxFQUFFLFVBQVUsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBRXBILE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUUzRCxPQUFPLEVBQUUsY0FBYyxFQUFFLE1BQU0sbUNBQW1DLENBQUM7QUFD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xHQUNsQixjQUFjLENBbUJoQjtJQUVELFNBQVMsQ0FBQyxhQUFhLENBQ3JCLE9BQU8sRUFBRSxzQkFBc0IsRUFDL0IsbUJBQW1CLEVBQUUsbUJBQW1CLEdBQUcsU0FBUyxFQUNwRCxNQUFNLEVBQUUscUJBQXFCLEVBQUU7Ozs7O01BWWhDO0lBRUQsU0FBUyxDQUFDLGVBQWUsQ0FBQyxJQUFJLEVBQUUsVUFBVSxHQUFHLFNBQVM7Ozs7a0JBTXJEO0NBQ0YifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentinel.d.ts","sourceRoot":"","sources":["../../src/sentinel/sentinel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,
|
|
1
|
+
{"version":3,"file":"sentinel.d.ts","sourceRoot":"","sources":["../../src/sentinel/sentinel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAEpH,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAIL,KAAK,OAAO,EACZ,KAAK,cAAc,EAEpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,KAAK,aAAa,EAA6C,MAAM,qBAAqB,CAAC;AACpG,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGxD,OAAO,KAAK,EACV,oBA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E,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE;;OAwElH;IAED,wDAAwD;IACxD,SAAS,CAAC,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,MAAM,EAAE,EAAE,qBAAqB,GAAG,SAAS,CAAC,iBAE3G;IAED,0DAA0D;IAC7C,YAAY,CAAC,EACxB,QAAQ,EACR,MAAM,EACN,UAAU,EACX,GAAE;QAAE,QAAQ,CAAC,EAAE,UAAU,CAAC;QAAC,MAAM,CAAC,EAAE,UAAU,CAAC;QAAC,UAAU,CAAC,EAAE,UAAU,EAAE,CAAA;KAAO,GAAG,OAAO,CAAC,eAAe,CAAC,CAmB3G;IAED,6CAA6C;IAChC,iBAAiB,CAC5B,gBAAgB,EAAE,UAAU,EAC5B,QAAQ,CAAC,EAAE,UAAU,EACrB,MAAM,CAAC,EAAE,UAAU,GAClB,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAkC3C;IAED,SAAS,CAAC,wBAAwB,CAChC,OAAO,EAAE,KAAK,MAAM,EAAE,EACtB,UAAU,EAAE,sBAAsB,EAClC,QAAQ,CAAC,EAAE,UAAU,EACrB,MAAM,CAAC,EAAE,UAAU,GAClB,cAAc,CAmBhB;IAED,SAAS,CAAC,aAAa,CACrB,OAAO,EAAE,sBAAsB,EAC/B,mBAAmB,EAAE,mBAAmB,GAAG,SAAS,EACpD,MAAM,EAAE,qBAAqB,EAAE;;;;;MAYhC;IAED,SAAS,CAAC,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS;;;;kBAMrD;CACF"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CheckpointProposalHash, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { countWhile, filterAsync, fromEntries, getEntries, mapValues } from '@aztec/foundation/collection';
|
|
3
3
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
5
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
6
|
-
import { L2TipsMemoryStore } from '@aztec/kv-store/stores';
|
|
7
6
|
import { OffenseType, WANT_TO_SLASH_EVENT, getOffenseTypeName } from '@aztec/slasher';
|
|
8
|
-
import {
|
|
7
|
+
import { getAttestationInfoFromPublishedCheckpoint } from '@aztec/stdlib/block';
|
|
9
8
|
import { getEpochAtSlot, getSlotRangeForEpoch, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
10
9
|
import { ConsensusPayload } from '@aztec/stdlib/p2p';
|
|
11
10
|
import EventEmitter from 'node:events';
|
|
@@ -50,7 +49,7 @@ import EventEmitter from 'node:events';
|
|
|
50
49
|
* first:
|
|
51
50
|
*
|
|
52
51
|
* - `checkpoint-mined` — a checkpoint covering this slot has landed on L1
|
|
53
|
-
* (
|
|
52
|
+
* (fetched on demand via `archiver.getCheckpoint({ slot })`).
|
|
54
53
|
* - `checkpoint-valid` — the local node re-executed a checkpoint proposal for this slot
|
|
55
54
|
* successfully (consulted via `CheckpointReexecutionTracker`).
|
|
56
55
|
* - `checkpoint-invalid` — the local node re-executed a checkpoint proposal for this slot
|
|
@@ -96,15 +95,11 @@ import EventEmitter from 'node:events';
|
|
|
96
95
|
config;
|
|
97
96
|
logger;
|
|
98
97
|
runningPromise;
|
|
99
|
-
blockStream;
|
|
100
|
-
l2TipsStore;
|
|
101
98
|
initialSlot;
|
|
102
99
|
lastProcessedSlot;
|
|
103
100
|
/** Largest epoch number for which the end-of-epoch aggregator has run. */ lastEvaluatedEpoch;
|
|
104
|
-
slotNumberToCheckpoint;
|
|
105
101
|
constructor(epochCache, archiver, p2p, store, reexecutionTracker, config, logger = createLogger('node:sentinel')){
|
|
106
|
-
super(), this.epochCache = epochCache, this.archiver = archiver, this.p2p = p2p, this.store = store, this.reexecutionTracker = reexecutionTracker, this.config = config, this.logger = logger
|
|
107
|
-
this.l2TipsStore = new L2TipsMemoryStore(archiver.getGenesisBlockHash());
|
|
102
|
+
super(), this.epochCache = epochCache, this.archiver = archiver, this.p2p = p2p, this.store = store, this.reexecutionTracker = reexecutionTracker, this.config = config, this.logger = logger;
|
|
108
103
|
const interval = epochCache.getL1Constants().ethereumSlotDuration * 1000 / 4;
|
|
109
104
|
this.runningPromise = new RunningPromise(this.work.bind(this), logger, interval);
|
|
110
105
|
}
|
|
@@ -125,18 +120,13 @@ import EventEmitter from 'node:events';
|
|
|
125
120
|
this.runningPromise.start();
|
|
126
121
|
}
|
|
127
122
|
/**
|
|
128
|
-
* Loads initial slot
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* (cold start).
|
|
123
|
+
* Loads the initial slot. We will not process anything at or before the initial slot. Floors at the
|
|
124
|
+
* archiver's synced L2 slot so the sentinel keeps making forward progress when L1 is advancing but L2 has no
|
|
125
|
+
* activity (the synced slot is driven by L1 sync, not by L2 blocks). Falls back to the wallclock if the
|
|
126
|
+
* archiver isn't ready yet (cold start).
|
|
133
127
|
*/ async init() {
|
|
134
128
|
this.initialSlot = await this.getCurrentSlot();
|
|
135
|
-
|
|
136
|
-
this.logger.info(`Starting validator sentinel with initial slot ${this.initialSlot} and block ${startingBlock}`);
|
|
137
|
-
this.blockStream = new L2BlockStream(this.archiver, this.l2TipsStore, this, this.logger, {
|
|
138
|
-
startingBlock
|
|
139
|
-
});
|
|
129
|
+
this.logger.info(`Starting validator sentinel with initial slot ${this.initialSlot}`);
|
|
140
130
|
}
|
|
141
131
|
/**
|
|
142
132
|
* Returns the L2 slot the sentinel should treat as "current": the archiver's last fully
|
|
@@ -150,35 +140,27 @@ import EventEmitter from 'node:events';
|
|
|
150
140
|
stop() {
|
|
151
141
|
return this.runningPromise.stop();
|
|
152
142
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
143
|
+
/**
|
|
144
|
+
* Fetches the L1-confirmed checkpoint covering a slot (if any) and derives the slot-level data the
|
|
145
|
+
* activity classifier needs: the checkpoint number, archive root, consensus payload hash (used to fetch
|
|
146
|
+
* matching p2p attestations regardless of feeAssetPriceModifier variants), and the recovered attestor set.
|
|
147
|
+
* Reads on demand so the result is always against the canonical chain — a reorged-out checkpoint simply
|
|
148
|
+
* stops being returned, with no stale mapping to clean up.
|
|
149
|
+
*/ async getCheckpointForSlot(slot) {
|
|
150
|
+
const checkpoint = await this.archiver.getCheckpoint({
|
|
151
|
+
slot
|
|
152
|
+
});
|
|
153
|
+
if (!checkpoint) {
|
|
154
|
+
return undefined;
|
|
162
155
|
}
|
|
163
|
-
const checkpoint = event.checkpoint;
|
|
164
|
-
// Store mapping from slot to archive, checkpoint number, attestors, and the consensus payload
|
|
165
|
-
// hash (used to query matching p2p attestations regardless of feeAssetPriceModifier variants).
|
|
166
156
|
const signatureContext = this.getSignatureContext();
|
|
167
157
|
const proposalPayloadHash = CheckpointProposalHash.fromBuffer(ConsensusPayload.fromCheckpoint(checkpoint.checkpoint, signatureContext).getPayloadHash());
|
|
168
|
-
|
|
158
|
+
return {
|
|
169
159
|
checkpointNumber: checkpoint.checkpoint.number,
|
|
170
160
|
archive: checkpoint.checkpoint.archive.root.toString(),
|
|
171
161
|
proposalPayloadHash,
|
|
172
162
|
attestors: getAttestationInfoFromPublishedCheckpoint(checkpoint, signatureContext).filter((a)=>a.status === 'recovered-from-signature').map((a)=>a.address)
|
|
173
|
-
}
|
|
174
|
-
// Prune the archive map to only keep at most N entries
|
|
175
|
-
const historyLength = this.store.getHistoryLength();
|
|
176
|
-
if (this.slotNumberToCheckpoint.size > historyLength) {
|
|
177
|
-
const toDelete = Array.from(this.slotNumberToCheckpoint.keys()).sort((a, b)=>Number(a - b)).slice(0, this.slotNumberToCheckpoint.size - historyLength);
|
|
178
|
-
for (const key of toDelete){
|
|
179
|
-
this.slotNumberToCheckpoint.delete(key);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
163
|
+
};
|
|
182
164
|
}
|
|
183
165
|
/**
|
|
184
166
|
* Called once per epoch, after the configured end-of-epoch buffer has elapsed beyond the
|
|
@@ -284,9 +266,6 @@ import EventEmitter from 'node:events';
|
|
|
284
266
|
*/ async work() {
|
|
285
267
|
const currentSlot = await this.getCurrentSlot();
|
|
286
268
|
try {
|
|
287
|
-
// Manually sync the block stream to ensure we have the latest data.
|
|
288
|
-
// Note we never `start` the blockstream, so it loops at the same pace as we do.
|
|
289
|
-
await this.blockStream.sync();
|
|
290
269
|
// Per-slot activity recording (lag = 2 slots for P2P attestation settlement).
|
|
291
270
|
const targetSlot = await this.isReadyToProcess(currentSlot);
|
|
292
271
|
if (targetSlot !== false) {
|
|
@@ -363,7 +342,7 @@ import EventEmitter from 'node:events';
|
|
|
363
342
|
});
|
|
364
343
|
return false;
|
|
365
344
|
}
|
|
366
|
-
const archiverLastBlockHash = await this.
|
|
345
|
+
const archiverLastBlockHash = await this.archiver.getL2Tips().then((tip)=>tip.proposed.hash);
|
|
367
346
|
const p2pLastBlockHash = await this.p2p.getL2Tips().then((tips)=>tips.proposed.hash);
|
|
368
347
|
const isP2pSynced = archiverLastBlockHash === p2pLastBlockHash;
|
|
369
348
|
if (!isP2pSynced) {
|
|
@@ -421,8 +400,9 @@ import EventEmitter from 'node:events';
|
|
|
421
400
|
committee
|
|
422
401
|
});
|
|
423
402
|
// Gather attestors from both p2p (live attestations) and the archiver (signers on the
|
|
424
|
-
// checkpoint if one has landed on L1).
|
|
425
|
-
|
|
403
|
+
// checkpoint if one has landed on L1). Fetched on demand so it always reflects the canonical chain.
|
|
404
|
+
// Used regardless of which case applies.
|
|
405
|
+
const checkpoint = await this.getCheckpointForSlot(slot);
|
|
426
406
|
const p2pAttested = await this.p2p.getCheckpointAttestationsForSlot(slot, checkpoint?.proposalPayloadHash);
|
|
427
407
|
const p2pAttestors = p2pAttested.map((a)=>a.getSender()).filter((s)=>s !== undefined);
|
|
428
408
|
const attestors = new Set([
|