@aztec/aztec-node 0.0.0-test.0 → 0.0.1-commit.001888fc
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 +22 -11
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +90 -15
- package/dest/aztec-node/node_metrics.d.ts +5 -1
- package/dest/aztec-node/node_metrics.d.ts.map +1 -1
- package/dest/aztec-node/node_metrics.js +20 -6
- package/dest/aztec-node/server.d.ts +132 -154
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +1292 -371
- package/dest/bin/index.d.ts +1 -1
- package/dest/bin/index.js +4 -2
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +0 -1
- package/dest/sentinel/config.d.ts +8 -0
- package/dest/sentinel/config.d.ts.map +1 -0
- package/dest/sentinel/config.js +29 -0
- package/dest/sentinel/factory.d.ts +9 -0
- package/dest/sentinel/factory.d.ts.map +1 -0
- package/dest/sentinel/factory.js +17 -0
- package/dest/sentinel/index.d.ts +3 -0
- package/dest/sentinel/index.d.ts.map +1 -0
- package/dest/sentinel/index.js +1 -0
- package/dest/sentinel/sentinel.d.ts +93 -0
- package/dest/sentinel/sentinel.d.ts.map +1 -0
- package/dest/sentinel/sentinel.js +429 -0
- package/dest/sentinel/store.d.ts +35 -0
- package/dest/sentinel/store.d.ts.map +1 -0
- package/dest/sentinel/store.js +174 -0
- package/dest/test/index.d.ts +31 -0
- package/dest/test/index.d.ts.map +1 -0
- package/dest/test/index.js +1 -0
- package/package.json +47 -35
- package/src/aztec-node/config.ts +149 -26
- package/src/aztec-node/node_metrics.ts +23 -6
- package/src/aztec-node/server.ts +1162 -467
- package/src/bin/index.ts +4 -2
- package/src/index.ts +0 -1
- package/src/sentinel/config.ts +37 -0
- package/src/sentinel/factory.ts +31 -0
- package/src/sentinel/index.ts +8 -0
- package/src/sentinel/sentinel.ts +543 -0
- package/src/sentinel/store.ts +185 -0
- package/src/test/index.ts +32 -0
- package/dest/aztec-node/http_rpc_server.d.ts +0 -8
- package/dest/aztec-node/http_rpc_server.d.ts.map +0 -1
- package/dest/aztec-node/http_rpc_server.js +0 -9
- package/src/aztec-node/http_rpc_server.ts +0 -11
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { countWhile, filterAsync, fromEntries, getEntries, mapValues } from '@aztec/foundation/collection';
|
|
3
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
+
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
6
|
+
import { L2TipsMemoryStore } from '@aztec/kv-store/stores';
|
|
7
|
+
import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
|
|
8
|
+
import { L2BlockStream, getAttestationInfoFromPublishedCheckpoint } from '@aztec/stdlib/block';
|
|
9
|
+
import { getEpochAtSlot, getSlotRangeForEpoch, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
10
|
+
import EventEmitter from 'node:events';
|
|
11
|
+
/** Maps a validator status to its category: proposer or attestation. */ function statusToCategory(status) {
|
|
12
|
+
switch(status){
|
|
13
|
+
case 'attestation-sent':
|
|
14
|
+
case 'attestation-missed':
|
|
15
|
+
return 'attestation';
|
|
16
|
+
default:
|
|
17
|
+
return 'proposer';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export class Sentinel extends EventEmitter {
|
|
21
|
+
epochCache;
|
|
22
|
+
archiver;
|
|
23
|
+
p2p;
|
|
24
|
+
store;
|
|
25
|
+
config;
|
|
26
|
+
logger;
|
|
27
|
+
runningPromise;
|
|
28
|
+
blockStream;
|
|
29
|
+
l2TipsStore;
|
|
30
|
+
initialSlot;
|
|
31
|
+
lastProcessedSlot;
|
|
32
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
33
|
+
slotNumberToCheckpoint;
|
|
34
|
+
constructor(epochCache, archiver, p2p, store, config, logger = createLogger('node:sentinel')){
|
|
35
|
+
super(), this.epochCache = epochCache, this.archiver = archiver, this.p2p = p2p, this.store = store, this.config = config, this.logger = logger, this.slotNumberToCheckpoint = new Map();
|
|
36
|
+
this.l2TipsStore = new L2TipsMemoryStore();
|
|
37
|
+
const interval = epochCache.getL1Constants().ethereumSlotDuration * 1000 / 4;
|
|
38
|
+
this.runningPromise = new RunningPromise(this.work.bind(this), logger, interval);
|
|
39
|
+
}
|
|
40
|
+
updateConfig(config) {
|
|
41
|
+
this.config = {
|
|
42
|
+
...this.config,
|
|
43
|
+
...config
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
async start() {
|
|
47
|
+
await this.init();
|
|
48
|
+
this.runningPromise.start();
|
|
49
|
+
}
|
|
50
|
+
/** Loads initial slot and initializes blockstream. We will not process anything at or before the initial slot. */ async init() {
|
|
51
|
+
this.initialSlot = this.epochCache.getEpochAndSlotNow().slot;
|
|
52
|
+
const startingBlock = BlockNumber(await this.archiver.getBlockNumber());
|
|
53
|
+
this.logger.info(`Starting validator sentinel with initial slot ${this.initialSlot} and block ${startingBlock}`);
|
|
54
|
+
this.blockStream = new L2BlockStream(this.archiver, this.l2TipsStore, this, this.logger, {
|
|
55
|
+
startingBlock
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
stop() {
|
|
59
|
+
return this.runningPromise.stop();
|
|
60
|
+
}
|
|
61
|
+
async handleBlockStreamEvent(event) {
|
|
62
|
+
await this.l2TipsStore.handleBlockStreamEvent(event);
|
|
63
|
+
if (event.type === 'chain-checkpointed') {
|
|
64
|
+
this.handleCheckpoint(event);
|
|
65
|
+
} else if (event.type === 'chain-proven') {
|
|
66
|
+
await this.handleChainProven(event);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
handleCheckpoint(event) {
|
|
70
|
+
if (event.type !== 'chain-checkpointed') {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const checkpoint = event.checkpoint;
|
|
74
|
+
// Store mapping from slot to archive, checkpoint number, and attestors
|
|
75
|
+
this.slotNumberToCheckpoint.set(checkpoint.checkpoint.header.slotNumber, {
|
|
76
|
+
checkpointNumber: checkpoint.checkpoint.number,
|
|
77
|
+
archive: checkpoint.checkpoint.archive.root.toString(),
|
|
78
|
+
attestors: getAttestationInfoFromPublishedCheckpoint(checkpoint).filter((a)=>a.status === 'recovered-from-signature').map((a)=>a.address)
|
|
79
|
+
});
|
|
80
|
+
// Prune the archive map to only keep at most N entries
|
|
81
|
+
const historyLength = this.store.getHistoryLength();
|
|
82
|
+
if (this.slotNumberToCheckpoint.size > historyLength) {
|
|
83
|
+
const toDelete = Array.from(this.slotNumberToCheckpoint.keys()).sort((a, b)=>Number(a - b)).slice(0, this.slotNumberToCheckpoint.size - historyLength);
|
|
84
|
+
for (const key of toDelete){
|
|
85
|
+
this.slotNumberToCheckpoint.delete(key);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async handleChainProven(event) {
|
|
90
|
+
if (event.type !== 'chain-proven') {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const blockNumber = event.block.number;
|
|
94
|
+
const header = await this.archiver.getBlockHeader(blockNumber);
|
|
95
|
+
if (!header) {
|
|
96
|
+
this.logger.error(`Failed to get block header ${blockNumber}`);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
// TODO(palla/slash): We should only be computing proven performance if this is
|
|
100
|
+
// a full proof epoch and not a partial one, otherwise we'll end up with skewed stats.
|
|
101
|
+
const epoch = getEpochAtSlot(header.getSlot(), this.epochCache.getL1Constants());
|
|
102
|
+
this.logger.debug(`Computing proven performance for epoch ${epoch}`);
|
|
103
|
+
const performance = await this.computeProvenPerformance(epoch);
|
|
104
|
+
this.logger.info(`Computed proven performance for epoch ${epoch}`, performance);
|
|
105
|
+
await this.store.updateProvenPerformance(epoch, performance);
|
|
106
|
+
await this.handleProvenPerformance(epoch, performance);
|
|
107
|
+
}
|
|
108
|
+
async computeProvenPerformance(epoch) {
|
|
109
|
+
const [fromSlot, toSlot] = getSlotRangeForEpoch(epoch, this.epochCache.getL1Constants());
|
|
110
|
+
const { committee, isEscapeHatchOpen } = await this.epochCache.getCommittee(fromSlot);
|
|
111
|
+
if (isEscapeHatchOpen) {
|
|
112
|
+
this.logger.info(`Skipping proven performance for epoch ${epoch} - escape hatch is open`);
|
|
113
|
+
return {};
|
|
114
|
+
}
|
|
115
|
+
if (!committee) {
|
|
116
|
+
this.logger.trace(`No committee found for slot ${fromSlot}`);
|
|
117
|
+
return {};
|
|
118
|
+
}
|
|
119
|
+
const stats = await this.computeStats({
|
|
120
|
+
fromSlot,
|
|
121
|
+
toSlot,
|
|
122
|
+
validators: committee
|
|
123
|
+
});
|
|
124
|
+
this.logger.debug(`Stats for epoch ${epoch}`, {
|
|
125
|
+
...stats,
|
|
126
|
+
fromSlot,
|
|
127
|
+
toSlot,
|
|
128
|
+
epoch
|
|
129
|
+
});
|
|
130
|
+
// Note that we are NOT using the total slots in the epoch as `total` here, since we only
|
|
131
|
+
// compute missed attestations over the blocks that had a proposal in them. So, let's say
|
|
132
|
+
// we have an epoch with 10 slots, but only 5 had a block proposal. A validator that was
|
|
133
|
+
// offline, assuming they were not picked as proposer, will then be reported as having missed
|
|
134
|
+
// 5/5 attestations. If we used the total, they'd be reported as 5/10, which would probably
|
|
135
|
+
// allow them to avoid being slashed.
|
|
136
|
+
return mapValues(stats.stats, (stat)=>({
|
|
137
|
+
missed: stat.missedAttestations.count + stat.missedProposals.count,
|
|
138
|
+
total: stat.missedAttestations.total + stat.missedProposals.total
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Checks if a validator has been inactive for the specified number of consecutive epochs for which we have data on it.
|
|
143
|
+
* @param validator The validator address to check
|
|
144
|
+
* @param currentEpoch Epochs strictly before the current one are evaluated only
|
|
145
|
+
* @param requiredConsecutiveEpochs Number of consecutive epochs required for slashing
|
|
146
|
+
*/ async checkPastInactivity(validator, currentEpoch, requiredConsecutiveEpochs) {
|
|
147
|
+
if (requiredConsecutiveEpochs === 0) {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
// Get all historical performance for this validator
|
|
151
|
+
const allPerformance = await this.store.getProvenPerformance(validator);
|
|
152
|
+
// Sort by epoch descending to get most recent first, keep only epochs strictly before the current one, and get the first N
|
|
153
|
+
const pastEpochs = allPerformance.sort((a, b)=>Number(b.epoch - a.epoch)).filter((p)=>p.epoch < currentEpoch);
|
|
154
|
+
// If we don't have enough historical data, don't slash
|
|
155
|
+
if (pastEpochs.length < requiredConsecutiveEpochs) {
|
|
156
|
+
this.logger.debug(`Not enough historical data for slashing ${validator} for inactivity (${allPerformance.length} epochs < ${requiredConsecutiveEpochs} required)`);
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
// Check that we have at least requiredConsecutiveEpochs and that all of them are above the inactivity threshold
|
|
160
|
+
return pastEpochs.slice(0, requiredConsecutiveEpochs).every((p)=>p.missed / p.total >= this.config.slashInactivityTargetPercentage);
|
|
161
|
+
}
|
|
162
|
+
async handleProvenPerformance(epoch, performance) {
|
|
163
|
+
if (this.config.slashInactivityPenalty === 0n) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const inactiveValidators = getEntries(performance).filter(([_, { missed, total }])=>missed / total >= this.config.slashInactivityTargetPercentage).map(([address])=>address);
|
|
167
|
+
this.logger.debug(`Found ${inactiveValidators.length} inactive validators in epoch ${epoch}`, {
|
|
168
|
+
inactiveValidators,
|
|
169
|
+
epoch,
|
|
170
|
+
inactivityTargetPercentage: this.config.slashInactivityTargetPercentage
|
|
171
|
+
});
|
|
172
|
+
const epochThreshold = this.config.slashInactivityConsecutiveEpochThreshold;
|
|
173
|
+
const criminals = await filterAsync(inactiveValidators, (address)=>this.checkPastInactivity(EthAddress.fromString(address), epoch, epochThreshold - 1));
|
|
174
|
+
const args = criminals.map((address)=>({
|
|
175
|
+
validator: EthAddress.fromString(address),
|
|
176
|
+
amount: this.config.slashInactivityPenalty,
|
|
177
|
+
offenseType: OffenseType.INACTIVITY,
|
|
178
|
+
epochOrSlot: BigInt(epoch)
|
|
179
|
+
}));
|
|
180
|
+
if (criminals.length > 0) {
|
|
181
|
+
this.logger.verbose(`Identified ${criminals.length} validators to slash due to inactivity in at least ${epochThreshold} consecutive epochs`, {
|
|
182
|
+
...args,
|
|
183
|
+
epochThreshold
|
|
184
|
+
});
|
|
185
|
+
this.emit(WANT_TO_SLASH_EVENT, args);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Process data for two L2 slots ago.
|
|
190
|
+
* Note that we do not process historical data, since we rely on p2p data for processing,
|
|
191
|
+
* and we don't have that data if we were offline during the period.
|
|
192
|
+
*/ async work() {
|
|
193
|
+
const { slot: currentSlot } = this.epochCache.getEpochAndSlotNow();
|
|
194
|
+
try {
|
|
195
|
+
// Manually sync the block stream to ensure we have the latest data.
|
|
196
|
+
// Note we never `start` the blockstream, so it loops at the same pace as we do.
|
|
197
|
+
await this.blockStream.sync();
|
|
198
|
+
// Check if we are ready to process data for two L2 slots ago.
|
|
199
|
+
const targetSlot = await this.isReadyToProcess(currentSlot);
|
|
200
|
+
// And process it if we are.
|
|
201
|
+
if (targetSlot !== false) {
|
|
202
|
+
await this.processSlot(targetSlot);
|
|
203
|
+
}
|
|
204
|
+
} catch (err) {
|
|
205
|
+
this.logger.error(`Failed to process slot ${currentSlot}`, err);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Check if we are ready to process data for two L2 slots ago, so we allow plenty of time for p2p to process all in-flight attestations.
|
|
210
|
+
* We also don't move past the archiver last synced L2 slot, as we don't want to process data that is not yet available.
|
|
211
|
+
* Last, we check the p2p is synced with the archiver, so it has pulled all attestations from it.
|
|
212
|
+
*/ async isReadyToProcess(currentSlot) {
|
|
213
|
+
if (currentSlot < 2) {
|
|
214
|
+
this.logger.trace(`Current slot ${currentSlot} too early.`);
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
const targetSlot = SlotNumber(currentSlot - 2);
|
|
218
|
+
if (this.lastProcessedSlot && this.lastProcessedSlot >= targetSlot) {
|
|
219
|
+
this.logger.trace(`Already processed slot ${targetSlot}`, {
|
|
220
|
+
lastProcessedSlot: this.lastProcessedSlot
|
|
221
|
+
});
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
if (this.initialSlot === undefined) {
|
|
225
|
+
this.logger.error(`Initial slot not loaded.`);
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
if (targetSlot <= this.initialSlot) {
|
|
229
|
+
this.logger.trace(`Refusing to process slot ${targetSlot} given initial slot ${this.initialSlot}`);
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
const syncedSlot = await this.archiver.getSyncedL2SlotNumber();
|
|
233
|
+
if (syncedSlot === undefined || syncedSlot < targetSlot) {
|
|
234
|
+
this.logger.debug(`Waiting for archiver to sync with L2 slot ${targetSlot}`, {
|
|
235
|
+
syncedSlot,
|
|
236
|
+
targetSlot
|
|
237
|
+
});
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
const archiverLastBlockHash = await this.l2TipsStore.getL2Tips().then((tip)=>tip.proposed.hash);
|
|
241
|
+
const p2pLastBlockHash = await this.p2p.getL2Tips().then((tips)=>tips.proposed.hash);
|
|
242
|
+
const isP2pSynced = archiverLastBlockHash === p2pLastBlockHash;
|
|
243
|
+
if (!isP2pSynced) {
|
|
244
|
+
this.logger.debug(`Waiting for P2P client to sync with archiver`, {
|
|
245
|
+
archiverLastBlockHash,
|
|
246
|
+
p2pLastBlockHash
|
|
247
|
+
});
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
return targetSlot;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Gathers committee and proposer data for a given slot, computes slot stats,
|
|
254
|
+
* and updates overall stats.
|
|
255
|
+
*/ async processSlot(slot) {
|
|
256
|
+
const { epoch, seed, committee, isEscapeHatchOpen } = await this.epochCache.getCommittee(slot);
|
|
257
|
+
if (isEscapeHatchOpen) {
|
|
258
|
+
this.logger.info(`Skipping slot ${slot} at epoch ${epoch} - escape hatch is open`);
|
|
259
|
+
this.lastProcessedSlot = slot;
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (!committee || committee.length === 0) {
|
|
263
|
+
this.logger.trace(`No committee found for slot ${slot} at epoch ${epoch}`);
|
|
264
|
+
this.lastProcessedSlot = slot;
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
const proposerIndex = this.epochCache.computeProposerIndex(slot, epoch, seed, BigInt(committee.length));
|
|
268
|
+
const proposer = committee[Number(proposerIndex)];
|
|
269
|
+
const stats = await this.getSlotActivity(slot, epoch, proposer, committee);
|
|
270
|
+
this.logger.verbose(`Updating L2 slot ${slot} observed activity`, stats);
|
|
271
|
+
await this.updateValidators(slot, stats);
|
|
272
|
+
this.lastProcessedSlot = slot;
|
|
273
|
+
}
|
|
274
|
+
/** Computes activity for a given slot. */ async getSlotActivity(slot, epoch, proposer, committee) {
|
|
275
|
+
this.logger.debug(`Computing stats for slot ${slot} at epoch ${epoch}`, {
|
|
276
|
+
slot,
|
|
277
|
+
epoch,
|
|
278
|
+
proposer,
|
|
279
|
+
committee
|
|
280
|
+
});
|
|
281
|
+
// Check if there is an L2 block in L1 for this L2 slot
|
|
282
|
+
// Here we get all checkpoint attestations for the checkpoint at the given slot,
|
|
283
|
+
// or all checkpoint attestations for all proposals in the slot if no checkpoint was mined.
|
|
284
|
+
// We gather from both p2p (contains the ones seen on the p2p layer) and archiver
|
|
285
|
+
// (contains the ones synced from mined checkpoints, which we may have missed from p2p).
|
|
286
|
+
const checkpoint = this.slotNumberToCheckpoint.get(slot);
|
|
287
|
+
const p2pAttested = await this.p2p.getCheckpointAttestationsForSlot(slot, checkpoint?.archive);
|
|
288
|
+
// Filter out attestations with invalid signatures
|
|
289
|
+
const p2pAttestors = p2pAttested.map((a)=>a.getSender()).filter((s)=>s !== undefined);
|
|
290
|
+
const attestors = new Set([
|
|
291
|
+
...p2pAttestors.map((a)=>a.toString()),
|
|
292
|
+
...checkpoint?.attestors.map((a)=>a.toString()) ?? []
|
|
293
|
+
].filter((addr)=>proposer.toString() !== addr));
|
|
294
|
+
// We assume that there was a block proposal if at least one of the validators (other than the proposer) attested to it.
|
|
295
|
+
// It could be the case that every single validator failed, and we could differentiate it by having
|
|
296
|
+
// this node re-execute every block proposal it sees and storing it in the attestation pool.
|
|
297
|
+
// But we'll leave that corner case out to reduce pressure on the node.
|
|
298
|
+
// TODO(palla/slash): This breaks if a given node has more than one validator in the current committee,
|
|
299
|
+
// since they will attest to their own proposal it even if it's not re-executable.
|
|
300
|
+
let status;
|
|
301
|
+
if (checkpoint) {
|
|
302
|
+
status = 'checkpoint-mined';
|
|
303
|
+
} else if (attestors.size > 0) {
|
|
304
|
+
status = 'checkpoint-proposed';
|
|
305
|
+
} else {
|
|
306
|
+
// No checkpoint on L1 and no checkpoint attestations seen. Check if block proposals were sent for this slot.
|
|
307
|
+
const hasBlockProposals = await this.p2p.hasBlockProposalsForSlot(slot);
|
|
308
|
+
status = hasBlockProposals ? 'checkpoint-missed' : 'blocks-missed';
|
|
309
|
+
}
|
|
310
|
+
this.logger.debug(`Checkpoint status for slot ${slot}: ${status}`, {
|
|
311
|
+
...checkpoint,
|
|
312
|
+
slot
|
|
313
|
+
});
|
|
314
|
+
// Get attestors that failed their checkpoint attestation duties, but only if there was a checkpoint proposed or mined
|
|
315
|
+
const missedAttestors = new Set(status === 'blocks-missed' || status === 'checkpoint-missed' ? [] : committee.filter((v)=>!attestors.has(v.toString()) && !proposer.equals(v)).map((v)=>v.toString()));
|
|
316
|
+
this.logger.debug(`Retrieved ${attestors.size} attestors out of ${committee.length} for slot ${slot}`, {
|
|
317
|
+
status,
|
|
318
|
+
proposer: proposer.toString(),
|
|
319
|
+
...checkpoint,
|
|
320
|
+
slot,
|
|
321
|
+
attestors: [
|
|
322
|
+
...attestors
|
|
323
|
+
],
|
|
324
|
+
missedAttestors: [
|
|
325
|
+
...missedAttestors
|
|
326
|
+
],
|
|
327
|
+
committee: committee.map((c)=>c.toString())
|
|
328
|
+
});
|
|
329
|
+
// Compute the status for each validator in the committee
|
|
330
|
+
const statusFor = (who)=>{
|
|
331
|
+
if (who === proposer.toString()) {
|
|
332
|
+
return status;
|
|
333
|
+
} else if (attestors.has(who)) {
|
|
334
|
+
return 'attestation-sent';
|
|
335
|
+
} else if (missedAttestors.has(who)) {
|
|
336
|
+
return 'attestation-missed';
|
|
337
|
+
} else {
|
|
338
|
+
return undefined;
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
return Object.fromEntries(committee.map((v)=>v.toString()).map((who)=>[
|
|
342
|
+
who,
|
|
343
|
+
statusFor(who)
|
|
344
|
+
]));
|
|
345
|
+
}
|
|
346
|
+
/** Push the status for each slot for each validator. */ updateValidators(slot, stats) {
|
|
347
|
+
return this.store.updateValidators(slot, stats);
|
|
348
|
+
}
|
|
349
|
+
/** Computes stats to be returned based on stored data. */ async computeStats({ fromSlot, toSlot, validators } = {}) {
|
|
350
|
+
const histories = validators ? fromEntries(await Promise.all(validators.map(async (v)=>[
|
|
351
|
+
v.toString(),
|
|
352
|
+
await this.store.getHistory(v)
|
|
353
|
+
]))) : await this.store.getHistories();
|
|
354
|
+
const slotNow = this.epochCache.getEpochAndSlotNow().slot;
|
|
355
|
+
fromSlot ??= SlotNumber(Math.max((this.lastProcessedSlot ?? slotNow) - this.store.getHistoryLength(), 0));
|
|
356
|
+
toSlot ??= this.lastProcessedSlot ?? slotNow;
|
|
357
|
+
const stats = mapValues(histories, (history, address)=>this.computeStatsForValidator(address, history ?? [], fromSlot, toSlot));
|
|
358
|
+
return {
|
|
359
|
+
stats,
|
|
360
|
+
lastProcessedSlot: this.lastProcessedSlot,
|
|
361
|
+
initialSlot: this.initialSlot,
|
|
362
|
+
slotWindow: this.store.getHistoryLength()
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
/** Computes stats for a single validator. */ async getValidatorStats(validatorAddress, fromSlot, toSlot) {
|
|
366
|
+
const history = await this.store.getHistory(validatorAddress);
|
|
367
|
+
if (!history || history.length === 0) {
|
|
368
|
+
return undefined;
|
|
369
|
+
}
|
|
370
|
+
const slotNow = this.epochCache.getEpochAndSlotNow().slot;
|
|
371
|
+
const effectiveFromSlot = fromSlot ?? SlotNumber(Math.max((this.lastProcessedSlot ?? slotNow) - this.store.getHistoryLength(), 0));
|
|
372
|
+
const effectiveToSlot = toSlot ?? this.lastProcessedSlot ?? slotNow;
|
|
373
|
+
const historyLength = BigInt(this.store.getHistoryLength());
|
|
374
|
+
if (BigInt(effectiveToSlot) - BigInt(effectiveFromSlot) > historyLength) {
|
|
375
|
+
throw new Error(`Slot range (${BigInt(effectiveToSlot) - BigInt(effectiveFromSlot)}) exceeds history length (${historyLength}). ` + `Requested range: ${effectiveFromSlot} to ${effectiveToSlot}.`);
|
|
376
|
+
}
|
|
377
|
+
const validator = this.computeStatsForValidator(validatorAddress.toString(), history, effectiveFromSlot, effectiveToSlot);
|
|
378
|
+
return {
|
|
379
|
+
validator,
|
|
380
|
+
allTimeProvenPerformance: await this.store.getProvenPerformance(validatorAddress),
|
|
381
|
+
lastProcessedSlot: this.lastProcessedSlot,
|
|
382
|
+
initialSlot: this.initialSlot,
|
|
383
|
+
slotWindow: this.store.getHistoryLength()
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
computeStatsForValidator(address, allHistory, fromSlot, toSlot) {
|
|
387
|
+
let history = fromSlot ? allHistory.filter((h)=>BigInt(h.slot) >= fromSlot) : allHistory;
|
|
388
|
+
history = toSlot ? history.filter((h)=>BigInt(h.slot) <= toSlot) : history;
|
|
389
|
+
const lastProposal = history.filter((h)=>h.status === 'checkpoint-proposed' || h.status === 'checkpoint-mined').at(-1);
|
|
390
|
+
const lastAttestation = history.filter((h)=>h.status === 'attestation-sent').at(-1);
|
|
391
|
+
return {
|
|
392
|
+
address: EthAddress.fromString(address),
|
|
393
|
+
lastProposal: this.computeFromSlot(lastProposal?.slot),
|
|
394
|
+
lastAttestation: this.computeFromSlot(lastAttestation?.slot),
|
|
395
|
+
totalSlots: history.length,
|
|
396
|
+
missedProposals: this.computeMissed(history, 'proposer', [
|
|
397
|
+
'checkpoint-missed',
|
|
398
|
+
'blocks-missed'
|
|
399
|
+
]),
|
|
400
|
+
missedAttestations: this.computeMissed(history, 'attestation', [
|
|
401
|
+
'attestation-missed'
|
|
402
|
+
]),
|
|
403
|
+
history
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
computeMissed(history, computeOverCategory, filter) {
|
|
407
|
+
const relevantHistory = history.filter((h)=>!computeOverCategory || statusToCategory(h.status) === computeOverCategory);
|
|
408
|
+
const filteredHistory = relevantHistory.filter((h)=>filter.includes(h.status));
|
|
409
|
+
return {
|
|
410
|
+
currentStreak: countWhile([
|
|
411
|
+
...relevantHistory
|
|
412
|
+
].reverse(), (h)=>filter.includes(h.status)),
|
|
413
|
+
rate: relevantHistory.length === 0 ? undefined : filteredHistory.length / relevantHistory.length,
|
|
414
|
+
count: filteredHistory.length,
|
|
415
|
+
total: relevantHistory.length
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
computeFromSlot(slot) {
|
|
419
|
+
if (slot === undefined) {
|
|
420
|
+
return undefined;
|
|
421
|
+
}
|
|
422
|
+
const timestamp = getTimestampForSlot(slot, this.epochCache.getL1Constants());
|
|
423
|
+
return {
|
|
424
|
+
timestamp,
|
|
425
|
+
slot,
|
|
426
|
+
date: new Date(Number(timestamp) * 1000).toISOString()
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
4
|
+
import type { ValidatorStatusHistory, ValidatorStatusInSlot, ValidatorsEpochPerformance } from '@aztec/stdlib/validators';
|
|
5
|
+
export declare class SentinelStore {
|
|
6
|
+
private store;
|
|
7
|
+
private config;
|
|
8
|
+
static readonly SCHEMA_VERSION = 3;
|
|
9
|
+
private readonly historyMap;
|
|
10
|
+
private readonly provenMap;
|
|
11
|
+
constructor(store: AztecAsyncKVStore, config: {
|
|
12
|
+
historyLength: number;
|
|
13
|
+
historicProvenPerformanceLength: number;
|
|
14
|
+
});
|
|
15
|
+
getHistoryLength(): number;
|
|
16
|
+
getHistoricProvenPerformanceLength(): number;
|
|
17
|
+
updateProvenPerformance(epoch: EpochNumber, performance: ValidatorsEpochPerformance): Promise<void>;
|
|
18
|
+
getProvenPerformance(who: EthAddress): Promise<{
|
|
19
|
+
missed: number;
|
|
20
|
+
total: number;
|
|
21
|
+
epoch: EpochNumber;
|
|
22
|
+
}[]>;
|
|
23
|
+
private pushValidatorProvenPerformanceForEpoch;
|
|
24
|
+
updateValidators(slot: SlotNumber, statuses: Record<`0x${string}`, ValidatorStatusInSlot | undefined>): Promise<void>;
|
|
25
|
+
private pushValidatorStatusForSlot;
|
|
26
|
+
getHistories(): Promise<Record<`0x${string}`, ValidatorStatusHistory>>;
|
|
27
|
+
getHistory(address: EthAddress): Promise<ValidatorStatusHistory | undefined>;
|
|
28
|
+
private serializePerformance;
|
|
29
|
+
private deserializePerformance;
|
|
30
|
+
private serializeHistory;
|
|
31
|
+
private deserializeHistory;
|
|
32
|
+
private statusToNumber;
|
|
33
|
+
private statusFromNumber;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RvcmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zZW50aW5lbC9zdG9yZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsV0FBVyxFQUFFLFVBQVUsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQzFFLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUUzRCxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBaUIsTUFBTSxpQkFBaUIsQ0FBQztBQUN4RSxPQUFPLEtBQUssRUFDVixzQkFBc0IsRUFDdEIscUJBQXFCLEVBQ3JCLDBCQUEwQixFQUMzQixNQUFNLDBCQUEwQixDQUFDO0FBRWxDLHFCQUFhLGFBQWE7SUFXdEIsT0FBTyxDQUFDLEtBQUs7SUFDYixPQUFPLENBQUMsTUFBTTtJQVhoQixnQkFBdUIsY0FBYyxLQUFLO0lBRzFDLE9BQU8sQ0FBQyxRQUFRLENBQUMsVUFBVSxDQUF1QztJQUlsRSxPQUFPLENBQUMsUUFBUSxDQUFDLFNBQVMsQ0FBdUM7SUFFakUsWUFDVSxLQUFLLEVBQUUsaUJBQWlCLEVBQ3hCLE1BQU0sRUFBRTtRQUFFLGFBQWEsRUFBRSxNQUFNLENBQUM7UUFBQywrQkFBK0IsRUFBRSxNQUFNLENBQUE7S0FBRSxFQUluRjtJQUVNLGdCQUFnQixXQUV0QjtJQUVNLGtDQUFrQyxXQUV4QztJQUVZLHVCQUF1QixDQUFDLEtBQUssRUFBRSxXQUFXLEVBQUUsV0FBVyxFQUFFLDBCQUEwQixpQkFNL0Y7SUFFWSxvQkFBb0IsQ0FBQyxHQUFHLEVBQUUsVUFBVSxHQUFHLE9BQU8sQ0FBQztRQUFFLE1BQU0sRUFBRSxNQUFNLENBQUM7UUFBQyxLQUFLLEVBQUUsTUFBTSxDQUFDO1FBQUMsS0FBSyxFQUFFLFdBQVcsQ0FBQTtLQUFFLEVBQUUsQ0FBQyxDQUduSDtZQUVhLHNDQUFzQztJQTZCdkMsZ0JBQWdCLENBQUMsSUFBSSxFQUFFLFVBQVUsRUFBRSxRQUFRLEVBQUUsTUFBTSxDQUFDLEtBQUssTUFBTSxFQUFFLEVBQUUscUJBQXFCLEdBQUcsU0FBUyxDQUFDLGlCQVFqSDtZQUVhLDBCQUEwQjtJQVEzQixZQUFZLElBQUksT0FBTyxDQUFDLE1BQU0sQ0FBQyxLQUFLLE1BQU0sRUFBRSxFQUFFLHNCQUFzQixDQUFDLENBQUMsQ0FNbEY7SUFFWSxVQUFVLENBQUMsT0FBTyxFQUFFLFVBQVUsR0FBRyxPQUFPLENBQUMsc0JBQXNCLEdBQUcsU0FBUyxDQUFDLENBR3hGO0lBRUQsT0FBTyxDQUFDLG9CQUFvQjtJQU01QixPQUFPLENBQUMsc0JBQXNCO0lBYTlCLE9BQU8sQ0FBQyxnQkFBZ0I7SUFNeEIsT0FBTyxDQUFDLGtCQUFrQjtJQVcxQixPQUFPLENBQUMsY0FBYztJQXFCdEIsT0FBTyxDQUFDLGdCQUFnQjtDQWtCekIifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/sentinel/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EACV,sBAAsB,EACtB,qBAAqB,EACrB,0BAA0B,EAC3B,MAAM,0BAA0B,CAAC;AAElC,qBAAa,aAAa;IAWtB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,MAAM;IAXhB,gBAAuB,cAAc,KAAK;IAG1C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAuC;IAIlE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAuC;IAEjE,YACU,KAAK,EAAE,iBAAiB,EACxB,MAAM,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,+BAA+B,EAAE,MAAM,CAAA;KAAE,EAInF;IAEM,gBAAgB,WAEtB;IAEM,kCAAkC,WAExC;IAEY,uBAAuB,CAAC,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,0BAA0B,iBAM/F;IAEY,oBAAoB,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,WAAW,CAAA;KAAE,EAAE,CAAC,CAGnH;YAEa,sCAAsC;IA6BvC,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,KAAK,MAAM,EAAE,EAAE,qBAAqB,GAAG,SAAS,CAAC,iBAQjH;YAEa,0BAA0B;IAQ3B,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,MAAM,EAAE,EAAE,sBAAsB,CAAC,CAAC,CAMlF;IAEY,UAAU,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,sBAAsB,GAAG,SAAS,CAAC,CAGxF;IAED,OAAO,CAAC,oBAAoB;IAM5B,OAAO,CAAC,sBAAsB;IAa9B,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,kBAAkB;IAW1B,OAAO,CAAC,cAAc;IAqBtB,OAAO,CAAC,gBAAgB;CAkBzB"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import { BufferReader, numToUInt8, numToUInt32BE, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
|
+
export class SentinelStore {
|
|
5
|
+
store;
|
|
6
|
+
config;
|
|
7
|
+
static SCHEMA_VERSION = 3;
|
|
8
|
+
// a map from validator address to their ValidatorStatusHistory
|
|
9
|
+
historyMap;
|
|
10
|
+
// a map from validator address to their historical proven epoch performance
|
|
11
|
+
// e.g. { validator: [{ epoch: 1, missed: 1, total: 10 }, { epoch: 2, missed: 3, total: 7 }, ...] }
|
|
12
|
+
provenMap;
|
|
13
|
+
constructor(store, config){
|
|
14
|
+
this.store = store;
|
|
15
|
+
this.config = config;
|
|
16
|
+
this.historyMap = store.openMap('sentinel-validator-status');
|
|
17
|
+
this.provenMap = store.openMap('sentinel-validator-proven');
|
|
18
|
+
}
|
|
19
|
+
getHistoryLength() {
|
|
20
|
+
return this.config.historyLength;
|
|
21
|
+
}
|
|
22
|
+
getHistoricProvenPerformanceLength() {
|
|
23
|
+
return this.config.historicProvenPerformanceLength;
|
|
24
|
+
}
|
|
25
|
+
async updateProvenPerformance(epoch, performance) {
|
|
26
|
+
await this.store.transactionAsync(async ()=>{
|
|
27
|
+
for (const [who, { missed, total }] of Object.entries(performance)){
|
|
28
|
+
await this.pushValidatorProvenPerformanceForEpoch({
|
|
29
|
+
who: EthAddress.fromString(who),
|
|
30
|
+
missed,
|
|
31
|
+
total,
|
|
32
|
+
epoch
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async getProvenPerformance(who) {
|
|
38
|
+
const currentPerformanceBuffer = await this.provenMap.getAsync(who.toString());
|
|
39
|
+
return currentPerformanceBuffer ? this.deserializePerformance(currentPerformanceBuffer) : [];
|
|
40
|
+
}
|
|
41
|
+
async pushValidatorProvenPerformanceForEpoch({ who, missed, total, epoch }) {
|
|
42
|
+
const currentPerformance = await this.getProvenPerformance(who);
|
|
43
|
+
const existingIndex = currentPerformance.findIndex((p)=>p.epoch === epoch);
|
|
44
|
+
if (existingIndex !== -1) {
|
|
45
|
+
currentPerformance[existingIndex] = {
|
|
46
|
+
missed,
|
|
47
|
+
total,
|
|
48
|
+
epoch
|
|
49
|
+
};
|
|
50
|
+
} else {
|
|
51
|
+
currentPerformance.push({
|
|
52
|
+
missed,
|
|
53
|
+
total,
|
|
54
|
+
epoch
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
// This should be sorted by epoch, but just in case.
|
|
58
|
+
// Since we keep the size small, this is not a big deal.
|
|
59
|
+
currentPerformance.sort((a, b)=>Number(a.epoch - b.epoch));
|
|
60
|
+
// keep the most recent `historicProvenPerformanceLength` entries.
|
|
61
|
+
const performanceToKeep = currentPerformance.slice(-this.config.historicProvenPerformanceLength);
|
|
62
|
+
await this.provenMap.set(who.toString(), this.serializePerformance(performanceToKeep));
|
|
63
|
+
}
|
|
64
|
+
async updateValidators(slot, statuses) {
|
|
65
|
+
await this.store.transactionAsync(async ()=>{
|
|
66
|
+
for (const [who, status] of Object.entries(statuses)){
|
|
67
|
+
if (status) {
|
|
68
|
+
await this.pushValidatorStatusForSlot(EthAddress.fromString(who), slot, status);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
async pushValidatorStatusForSlot(who, slot, status) {
|
|
74
|
+
await this.store.transactionAsync(async ()=>{
|
|
75
|
+
const currentHistory = await this.getHistory(who) ?? [];
|
|
76
|
+
const newHistory = [
|
|
77
|
+
...currentHistory,
|
|
78
|
+
{
|
|
79
|
+
slot,
|
|
80
|
+
status
|
|
81
|
+
}
|
|
82
|
+
].slice(-this.config.historyLength);
|
|
83
|
+
await this.historyMap.set(who.toString(), this.serializeHistory(newHistory));
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
async getHistories() {
|
|
87
|
+
const histories = {};
|
|
88
|
+
for await (const [address, history] of this.historyMap.entriesAsync()){
|
|
89
|
+
histories[address] = this.deserializeHistory(history);
|
|
90
|
+
}
|
|
91
|
+
return histories;
|
|
92
|
+
}
|
|
93
|
+
async getHistory(address) {
|
|
94
|
+
const data = await this.historyMap.getAsync(address.toString());
|
|
95
|
+
return data && this.deserializeHistory(data);
|
|
96
|
+
}
|
|
97
|
+
serializePerformance(performance) {
|
|
98
|
+
return serializeToBuffer(performance.map((p)=>[
|
|
99
|
+
numToUInt32BE(Number(p.epoch)),
|
|
100
|
+
numToUInt32BE(p.missed),
|
|
101
|
+
numToUInt32BE(p.total)
|
|
102
|
+
]));
|
|
103
|
+
}
|
|
104
|
+
deserializePerformance(buffer) {
|
|
105
|
+
const reader = new BufferReader(buffer);
|
|
106
|
+
const performance = [];
|
|
107
|
+
while(!reader.isEmpty()){
|
|
108
|
+
performance.push({
|
|
109
|
+
epoch: EpochNumber(reader.readNumber()),
|
|
110
|
+
missed: reader.readNumber(),
|
|
111
|
+
total: reader.readNumber()
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return performance;
|
|
115
|
+
}
|
|
116
|
+
serializeHistory(history) {
|
|
117
|
+
return serializeToBuffer(history.map((h)=>[
|
|
118
|
+
numToUInt32BE(Number(h.slot)),
|
|
119
|
+
numToUInt8(this.statusToNumber(h.status))
|
|
120
|
+
]));
|
|
121
|
+
}
|
|
122
|
+
deserializeHistory(buffer) {
|
|
123
|
+
const reader = new BufferReader(buffer);
|
|
124
|
+
const history = [];
|
|
125
|
+
while(!reader.isEmpty()){
|
|
126
|
+
const slot = SlotNumber(reader.readNumber());
|
|
127
|
+
const status = this.statusFromNumber(reader.readUInt8());
|
|
128
|
+
history.push({
|
|
129
|
+
slot,
|
|
130
|
+
status
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return history;
|
|
134
|
+
}
|
|
135
|
+
statusToNumber(status) {
|
|
136
|
+
switch(status){
|
|
137
|
+
case 'checkpoint-mined':
|
|
138
|
+
return 1;
|
|
139
|
+
case 'checkpoint-proposed':
|
|
140
|
+
return 2;
|
|
141
|
+
case 'checkpoint-missed':
|
|
142
|
+
return 3;
|
|
143
|
+
case 'attestation-sent':
|
|
144
|
+
return 4;
|
|
145
|
+
case 'attestation-missed':
|
|
146
|
+
return 5;
|
|
147
|
+
case 'blocks-missed':
|
|
148
|
+
return 6;
|
|
149
|
+
default:
|
|
150
|
+
{
|
|
151
|
+
const _exhaustive = status;
|
|
152
|
+
throw new Error(`Unknown status: ${status}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
statusFromNumber(status) {
|
|
157
|
+
switch(status){
|
|
158
|
+
case 1:
|
|
159
|
+
return 'checkpoint-mined';
|
|
160
|
+
case 2:
|
|
161
|
+
return 'checkpoint-proposed';
|
|
162
|
+
case 3:
|
|
163
|
+
return 'checkpoint-missed';
|
|
164
|
+
case 4:
|
|
165
|
+
return 'attestation-sent';
|
|
166
|
+
case 5:
|
|
167
|
+
return 'attestation-missed';
|
|
168
|
+
case 6:
|
|
169
|
+
return 'blocks-missed';
|
|
170
|
+
default:
|
|
171
|
+
throw new Error(`Unknown status: ${status}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|