@aztec/aztec-node 0.0.1-commit.b655e406 → 0.0.1-commit.b8a057fa
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/aztec-node/block_response_helpers.d.ts +25 -0
- package/dest/aztec-node/block_response_helpers.d.ts.map +1 -0
- package/dest/aztec-node/block_response_helpers.js +112 -0
- package/dest/aztec-node/config.d.ts +26 -8
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +32 -8
- package/dest/aztec-node/node_metrics.d.ts +1 -1
- package/dest/aztec-node/node_metrics.d.ts.map +1 -1
- package/dest/aztec-node/node_metrics.js +9 -16
- package/dest/aztec-node/node_public_calls_simulator.d.ts +97 -0
- package/dest/aztec-node/node_public_calls_simulator.d.ts.map +1 -0
- package/dest/aztec-node/node_public_calls_simulator.js +351 -0
- package/dest/aztec-node/public_data_overrides.d.ts +13 -0
- package/dest/aztec-node/public_data_overrides.d.ts.map +1 -0
- package/dest/aztec-node/public_data_overrides.js +21 -0
- package/dest/aztec-node/register_node_rpc_handlers.d.ts +10 -0
- package/dest/aztec-node/register_node_rpc_handlers.d.ts.map +1 -0
- package/dest/aztec-node/register_node_rpc_handlers.js +31 -0
- package/dest/aztec-node/server.d.ts +163 -225
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +897 -703
- package/dest/bin/index.d.ts +1 -1
- package/dest/bin/index.js +15 -10
- package/dest/factory.d.ts +33 -0
- package/dest/factory.d.ts.map +1 -0
- package/dest/factory.js +523 -0
- package/dest/index.d.ts +3 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -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 +65 -0
- package/dest/modules/node_world_state_queries.d.ts.map +1 -0
- package/dest/modules/node_world_state_queries.js +272 -0
- package/dest/sentinel/config.d.ts +3 -2
- package/dest/sentinel/config.d.ts.map +1 -1
- package/dest/sentinel/config.js +15 -5
- package/dest/sentinel/factory.d.ts +6 -4
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/factory.js +13 -6
- package/dest/sentinel/index.d.ts +1 -1
- package/dest/sentinel/sentinel.d.ts +160 -34
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +285 -125
- package/dest/sentinel/store.d.ts +11 -10
- package/dest/sentinel/store.d.ts.map +1 -1
- package/dest/sentinel/store.js +36 -23
- package/dest/test/index.d.ts +3 -3
- package/dest/test/index.d.ts.map +1 -1
- package/package.json +32 -28
- package/src/aztec-node/block_response_helpers.ts +161 -0
- package/src/aztec-node/config.ts +64 -21
- package/src/aztec-node/node_metrics.ts +6 -17
- package/src/aztec-node/node_public_calls_simulator.ts +394 -0
- package/src/aztec-node/public_data_overrides.ts +35 -0
- package/src/aztec-node/register_node_rpc_handlers.ts +29 -0
- package/src/aztec-node/server.ts +689 -940
- package/src/bin/index.ts +19 -12
- package/src/factory.ts +688 -0
- package/src/index.ts +2 -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 +374 -0
- package/src/sentinel/README.md +103 -0
- package/src/sentinel/config.ts +18 -6
- package/src/sentinel/factory.ts +23 -13
- package/src/sentinel/sentinel.ts +358 -157
- package/src/sentinel/store.ts +43 -34
- package/src/test/index.ts +2 -2
package/src/sentinel/sentinel.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
+
import { CheckpointNumber, CheckpointProposalHash, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import { countWhile, filterAsync, fromEntries, getEntries, mapValues } from '@aztec/foundation/collection';
|
|
3
4
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
6
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
6
|
-
import { L2TipsMemoryStore, type L2TipsStore } from '@aztec/kv-store/stores';
|
|
7
7
|
import type { P2PClient } from '@aztec/p2p';
|
|
8
8
|
import {
|
|
9
9
|
OffenseType,
|
|
@@ -11,16 +11,14 @@ import {
|
|
|
11
11
|
type WantToSlashArgs,
|
|
12
12
|
type Watcher,
|
|
13
13
|
type WatcherEmitter,
|
|
14
|
+
getOffenseTypeName,
|
|
14
15
|
} from '@aztec/slasher';
|
|
15
16
|
import type { SlasherConfig } from '@aztec/slasher/config';
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
type L2BlockStreamEvent,
|
|
20
|
-
type L2BlockStreamEventHandler,
|
|
21
|
-
getAttestationInfoFromPublishedL2Block,
|
|
22
|
-
} from '@aztec/stdlib/block';
|
|
17
|
+
import { type L2BlockSource, getAttestationInfoFromPublishedCheckpoint } from '@aztec/stdlib/block';
|
|
18
|
+
import type { CheckpointReexecutionTracker } from '@aztec/stdlib/checkpoint';
|
|
19
|
+
import type { ChainConfig } from '@aztec/stdlib/config';
|
|
23
20
|
import { getEpochAtSlot, getSlotRangeForEpoch, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
21
|
+
import { ConsensusPayload, type CoordinationSignatureContext } from '@aztec/stdlib/p2p';
|
|
24
22
|
import type {
|
|
25
23
|
SingleValidatorStats,
|
|
26
24
|
ValidatorStats,
|
|
@@ -33,35 +31,126 @@ import type {
|
|
|
33
31
|
|
|
34
32
|
import EventEmitter from 'node:events';
|
|
35
33
|
|
|
34
|
+
import type { SentinelConfig } from './config.js';
|
|
36
35
|
import { SentinelStore } from './store.js';
|
|
37
36
|
|
|
38
|
-
export
|
|
37
|
+
export type SentinelRuntimeConfig = Pick<
|
|
38
|
+
SlasherConfig,
|
|
39
|
+
'slashInactivityTargetPercentage' | 'slashInactivityPenalty' | 'slashInactivityConsecutiveEpochThreshold'
|
|
40
|
+
> &
|
|
41
|
+
Pick<SentinelConfig, 'sentinelEpochEndBufferSlots'> &
|
|
42
|
+
Pick<ChainConfig, 'l1ChainId' | 'rollupAddress'>;
|
|
43
|
+
|
|
44
|
+
/** Maps a validator status to its category: proposer or attestation. */
|
|
45
|
+
function statusToCategory(status: ValidatorStatusInSlot): ValidatorStatusType {
|
|
46
|
+
switch (status) {
|
|
47
|
+
case 'attestation-sent':
|
|
48
|
+
case 'attestation-missed':
|
|
49
|
+
return 'attestation';
|
|
50
|
+
default:
|
|
51
|
+
return 'proposer';
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The Sentinel observes validator behaviour every L2 slot, classifies it into a per-slot status,
|
|
57
|
+
* aggregates those statuses into per-epoch performance once each epoch is fully observed, and
|
|
58
|
+
* emits inactivity slash payloads when a validator has been inactive for the configured number
|
|
59
|
+
* of consecutive epochs.
|
|
60
|
+
*
|
|
61
|
+
* ## Two cadences
|
|
62
|
+
*
|
|
63
|
+
* The sentinel runs `work()` every quarter L2 slot and drives two independent pipelines:
|
|
64
|
+
*
|
|
65
|
+
* 1. **Per-slot activity recording.** `processSlot(currentSlot - 2)` runs once per slot, with a
|
|
66
|
+
* two-slot lag to let P2P attestations settle and the archiver catch up. It classifies each
|
|
67
|
+
* committee member's behaviour for that slot via `getSlotActivity` and persists the result to
|
|
68
|
+
* `SentinelStore.historyMap` (sliding window of `sentinelHistoryLengthInEpochs * epochDuration`
|
|
69
|
+
* slots, default 24 epochs).
|
|
70
|
+
*
|
|
71
|
+
* 2. **Per-epoch evaluation.** `processEpochEnds(currentSlot)` runs every tick too. Once
|
|
72
|
+
* `sentinelEpochEndBufferSlots` (default 2) has elapsed past an epoch's last slot AND the
|
|
73
|
+
* per-slot recorder has covered that last slot, the sentinel calls `handleEpochEnd(epoch)`.
|
|
74
|
+
* That aggregates the slot-level statuses for the epoch into per-validator `{missed, total}`,
|
|
75
|
+
* persists it to `SentinelStore.epochMap` (default 2000-epoch window), and runs the slashing
|
|
76
|
+
* decision.
|
|
77
|
+
*
|
|
78
|
+
* Triggering per-epoch evaluation off local L2 state — rather than waiting for L1 proof
|
|
79
|
+
* publication — decouples slashing from prover availability.
|
|
80
|
+
*
|
|
81
|
+
* ## Six-case taxonomy in `getSlotActivity`
|
|
82
|
+
*
|
|
83
|
+
* For each slot, the sentinel assigns the proposer one of six statuses, ranked highest-confidence
|
|
84
|
+
* first:
|
|
85
|
+
*
|
|
86
|
+
* - `checkpoint-mined` — a checkpoint covering this slot has landed on L1
|
|
87
|
+
* (fetched on demand via `archiver.getCheckpoint({ slot })`).
|
|
88
|
+
* - `checkpoint-valid` — the local node re-executed a checkpoint proposal for this slot
|
|
89
|
+
* successfully (consulted via `CheckpointReexecutionTracker`).
|
|
90
|
+
* - `checkpoint-invalid` — the local node re-executed a checkpoint proposal for this slot
|
|
91
|
+
* and rejected it (e.g. header/archive/out-hash mismatch, limit
|
|
92
|
+
* breach). Proposer-fault.
|
|
93
|
+
* - `checkpoint-unvalidated` — the local node observed a checkpoint proposal but could not
|
|
94
|
+
* validate it (missing blocks/txs, timeouts). Treated as
|
|
95
|
+
* proposer-fault for slashing.
|
|
96
|
+
* - `checkpoint-missed` — block proposals seen on P2P but no checkpoint proposal at all.
|
|
97
|
+
* - `blocks-missed` — no block proposals seen for this slot.
|
|
98
|
+
*
|
|
99
|
+
* Missing-attestor faults are recorded only in `checkpoint-mined` and `checkpoint-valid`, where
|
|
100
|
+
* the local node has positive evidence the checkpoint was canonical or valid. In the other four
|
|
101
|
+
* cases the proposer is at fault and no attestor penalty applies.
|
|
102
|
+
*
|
|
103
|
+
* ## Re-execution tracker
|
|
104
|
+
*
|
|
105
|
+
* `CheckpointReexecutionTracker` is populated by the validator client's checkpoint proposal
|
|
106
|
+
* handler. Every early return in `validateCheckpointProposal` records an outcome
|
|
107
|
+
* (`valid` / `invalid` / `unvalidated`) keyed by slot.
|
|
108
|
+
*
|
|
109
|
+
* ## Inactivity slashing
|
|
110
|
+
*
|
|
111
|
+
* `handleEpochPerformance` filters the epoch's per-validator stats by
|
|
112
|
+
* `slashInactivityTargetPercentage` and then calls `checkPastInactivity` to require
|
|
113
|
+
* `slashInactivityConsecutiveEpochThreshold` consecutive past epochs over the same threshold
|
|
114
|
+
* (read from `SentinelStore.epochMap`). Only validators meeting both conditions are emitted as
|
|
115
|
+
* `WANT_TO_SLASH_EVENT` with `OffenseType.INACTIVITY`. The slot-level counters that feed this —
|
|
116
|
+
* `missedProposals` and `missedAttestations` — include the four proposer-fault statuses plus
|
|
117
|
+
* `attestation-missed`.
|
|
118
|
+
*
|
|
119
|
+
* ## Escape hatch
|
|
120
|
+
*
|
|
121
|
+
* If `epochCache.getCommittee(slot)` reports `isEscapeHatchOpen`, per-slot recording is skipped
|
|
122
|
+
* (no history entries for that slot) and per-epoch evaluation writes an empty performance map
|
|
123
|
+
* (no slashing).
|
|
124
|
+
*/
|
|
125
|
+
export class Sentinel extends (EventEmitter as new () => WatcherEmitter) implements Watcher {
|
|
39
126
|
protected runningPromise: RunningPromise;
|
|
40
|
-
protected blockStream!: L2BlockStream;
|
|
41
|
-
protected l2TipsStore: L2TipsStore;
|
|
42
127
|
|
|
43
|
-
protected initialSlot:
|
|
44
|
-
protected lastProcessedSlot:
|
|
45
|
-
|
|
46
|
-
|
|
128
|
+
protected initialSlot: SlotNumber | undefined;
|
|
129
|
+
protected lastProcessedSlot: SlotNumber | undefined;
|
|
130
|
+
/** Largest epoch number for which the end-of-epoch aggregator has run. */
|
|
131
|
+
protected lastEvaluatedEpoch: EpochNumber | undefined;
|
|
47
132
|
|
|
48
133
|
constructor(
|
|
49
134
|
protected epochCache: EpochCache,
|
|
50
135
|
protected archiver: L2BlockSource,
|
|
51
136
|
protected p2p: P2PClient,
|
|
52
137
|
protected store: SentinelStore,
|
|
53
|
-
protected
|
|
54
|
-
|
|
55
|
-
'slashInactivityTargetPercentage' | 'slashInactivityPenalty' | 'slashInactivityConsecutiveEpochThreshold'
|
|
56
|
-
>,
|
|
138
|
+
protected reexecutionTracker: CheckpointReexecutionTracker,
|
|
139
|
+
protected config: SentinelRuntimeConfig,
|
|
57
140
|
protected logger = createLogger('node:sentinel'),
|
|
58
141
|
) {
|
|
59
142
|
super();
|
|
60
|
-
this.l2TipsStore = new L2TipsMemoryStore();
|
|
61
143
|
const interval = (epochCache.getL1Constants().ethereumSlotDuration * 1000) / 4;
|
|
62
144
|
this.runningPromise = new RunningPromise(this.work.bind(this), logger, interval);
|
|
63
145
|
}
|
|
64
146
|
|
|
147
|
+
private getSignatureContext(): CoordinationSignatureContext {
|
|
148
|
+
return {
|
|
149
|
+
chainId: this.config.l1ChainId,
|
|
150
|
+
rollupAddress: this.config.rollupAddress,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
65
154
|
public updateConfig(config: Partial<SlasherConfig>) {
|
|
66
155
|
this.config = { ...this.config, ...config };
|
|
67
156
|
}
|
|
@@ -71,78 +160,97 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
71
160
|
this.runningPromise.start();
|
|
72
161
|
}
|
|
73
162
|
|
|
74
|
-
/**
|
|
163
|
+
/**
|
|
164
|
+
* Loads the initial slot. We will not process anything at or before the initial slot. Floors at the
|
|
165
|
+
* archiver's synced L2 slot so the sentinel keeps making forward progress when L1 is advancing but L2 has no
|
|
166
|
+
* activity (the synced slot is driven by L1 sync, not by L2 blocks). Falls back to the wallclock if the
|
|
167
|
+
* archiver isn't ready yet (cold start).
|
|
168
|
+
*/
|
|
75
169
|
protected async init() {
|
|
76
|
-
this.initialSlot = this.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
170
|
+
this.initialSlot = await this.getCurrentSlot();
|
|
171
|
+
this.logger.info(`Starting validator sentinel with initial slot ${this.initialSlot}`);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Returns the L2 slot the sentinel should treat as "current": the archiver's last fully
|
|
176
|
+
* synced L2 slot, falling back to the wallclock slot when the archiver isn't ready yet
|
|
177
|
+
* (cold start). Anchoring to the synced slot keeps timing arithmetic (initial floor,
|
|
178
|
+
* per-slot lag, end-of-epoch buffer, stats-range fallback) from speculating ahead of where
|
|
179
|
+
* L1 actually is.
|
|
180
|
+
*/
|
|
181
|
+
protected async getCurrentSlot(): Promise<SlotNumber> {
|
|
182
|
+
return (await this.archiver.getSyncedL2SlotNumber()) ?? this.epochCache.getSlotNow();
|
|
80
183
|
}
|
|
81
184
|
|
|
82
185
|
public stop() {
|
|
83
186
|
return this.runningPromise.stop();
|
|
84
187
|
}
|
|
85
188
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
// Prune the archive map to only keep at most N entries
|
|
101
|
-
const historyLength = this.store.getHistoryLength();
|
|
102
|
-
if (this.slotNumberToBlock.size > historyLength) {
|
|
103
|
-
const toDelete = Array.from(this.slotNumberToBlock.keys())
|
|
104
|
-
.sort((a, b) => Number(a - b))
|
|
105
|
-
.slice(0, this.slotNumberToBlock.size - historyLength);
|
|
106
|
-
for (const key of toDelete) {
|
|
107
|
-
this.slotNumberToBlock.delete(key);
|
|
108
|
-
}
|
|
189
|
+
/**
|
|
190
|
+
* Fetches the L1-confirmed checkpoint covering a slot (if any) and derives the slot-level data the
|
|
191
|
+
* activity classifier needs: the checkpoint number, archive root, consensus payload hash (used to fetch
|
|
192
|
+
* matching p2p attestations regardless of feeAssetPriceModifier variants), and the recovered attestor set.
|
|
193
|
+
* Reads on demand so the result is always against the canonical chain — a reorged-out checkpoint simply
|
|
194
|
+
* stops being returned, with no stale mapping to clean up.
|
|
195
|
+
*/
|
|
196
|
+
protected async getCheckpointForSlot(slot: SlotNumber): Promise<
|
|
197
|
+
| {
|
|
198
|
+
checkpointNumber: CheckpointNumber;
|
|
199
|
+
archive: string;
|
|
200
|
+
proposalPayloadHash: CheckpointProposalHash;
|
|
201
|
+
attestors: EthAddress[];
|
|
109
202
|
}
|
|
110
|
-
|
|
111
|
-
|
|
203
|
+
| undefined
|
|
204
|
+
> {
|
|
205
|
+
const checkpoint = await this.archiver.getCheckpoint({ slot });
|
|
206
|
+
if (!checkpoint) {
|
|
207
|
+
return undefined;
|
|
112
208
|
}
|
|
209
|
+
const signatureContext = this.getSignatureContext();
|
|
210
|
+
const proposalPayloadHash = CheckpointProposalHash.fromBuffer(
|
|
211
|
+
ConsensusPayload.fromCheckpoint(checkpoint.checkpoint, signatureContext).getPayloadHash(),
|
|
212
|
+
);
|
|
213
|
+
return {
|
|
214
|
+
checkpointNumber: checkpoint.checkpoint.number,
|
|
215
|
+
archive: checkpoint.checkpoint.archive.root.toString(),
|
|
216
|
+
proposalPayloadHash,
|
|
217
|
+
attestors: getAttestationInfoFromPublishedCheckpoint(checkpoint, signatureContext)
|
|
218
|
+
.filter(a => a.status === 'recovered-from-signature')
|
|
219
|
+
.map(a => a.address!),
|
|
220
|
+
};
|
|
113
221
|
}
|
|
114
222
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// TODO(palla/slash): We should only be computing proven performance if this is
|
|
127
|
-
// a full proof epoch and not a partial one, otherwise we'll end up with skewed stats.
|
|
128
|
-
const epoch = getEpochAtSlot(block.header.getSlot(), this.epochCache.getL1Constants());
|
|
129
|
-
this.logger.debug(`Computing proven performance for epoch ${epoch}`);
|
|
130
|
-
const performance = await this.computeProvenPerformance(epoch);
|
|
131
|
-
this.logger.info(`Computed proven performance for epoch ${epoch}`, performance);
|
|
223
|
+
/**
|
|
224
|
+
* Called once per epoch, after the configured end-of-epoch buffer has elapsed beyond the
|
|
225
|
+
* epoch's last slot. Computes per-epoch performance from the slot-level history collected
|
|
226
|
+
* by `processSlot` and emits any inactivity slash payloads.
|
|
227
|
+
*/
|
|
228
|
+
protected async handleEpochEnd(epoch: EpochNumber) {
|
|
229
|
+
this.logger.debug(`Computing epoch performance for epoch ${epoch}`);
|
|
230
|
+
const performance = await this.computeEpochPerformance(epoch);
|
|
231
|
+
this.logger.info(`Computed epoch performance for epoch ${epoch}`, performance);
|
|
132
232
|
|
|
133
|
-
await this.store.
|
|
134
|
-
await this.
|
|
233
|
+
await this.store.updateEpochPerformance(epoch, performance);
|
|
234
|
+
await this.handleEpochPerformance(epoch, performance);
|
|
135
235
|
}
|
|
136
236
|
|
|
137
|
-
protected async
|
|
237
|
+
protected async computeEpochPerformance(epoch: EpochNumber): Promise<ValidatorsEpochPerformance> {
|
|
138
238
|
const [fromSlot, toSlot] = getSlotRangeForEpoch(epoch, this.epochCache.getL1Constants());
|
|
139
|
-
const { committee } = await this.epochCache.getCommittee(fromSlot);
|
|
239
|
+
const { committee, isEscapeHatchOpen } = await this.epochCache.getCommittee(fromSlot);
|
|
240
|
+
if (isEscapeHatchOpen) {
|
|
241
|
+
this.logger.info(`Skipping epoch performance for epoch ${epoch} - escape hatch is open`);
|
|
242
|
+
return {};
|
|
243
|
+
}
|
|
140
244
|
if (!committee) {
|
|
141
245
|
this.logger.trace(`No committee found for slot ${fromSlot}`);
|
|
142
246
|
return {};
|
|
143
247
|
}
|
|
144
248
|
|
|
145
|
-
const stats = await this.computeStats({
|
|
249
|
+
const stats = await this.computeStats({
|
|
250
|
+
fromSlot,
|
|
251
|
+
toSlot,
|
|
252
|
+
validators: committee,
|
|
253
|
+
});
|
|
146
254
|
this.logger.debug(`Stats for epoch ${epoch}`, { ...stats, fromSlot, toSlot, epoch });
|
|
147
255
|
|
|
148
256
|
// Note that we are NOT using the total slots in the epoch as `total` here, since we only
|
|
@@ -165,39 +273,36 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
165
273
|
*/
|
|
166
274
|
protected async checkPastInactivity(
|
|
167
275
|
validator: EthAddress,
|
|
168
|
-
currentEpoch:
|
|
276
|
+
currentEpoch: EpochNumber,
|
|
169
277
|
requiredConsecutiveEpochs: number,
|
|
170
278
|
): Promise<boolean> {
|
|
171
279
|
if (requiredConsecutiveEpochs === 0) {
|
|
172
280
|
return true;
|
|
173
281
|
}
|
|
174
282
|
|
|
175
|
-
// Get all historical performance for this validator
|
|
176
|
-
const allPerformance = await this.store.
|
|
283
|
+
// Get all historical per-epoch performance for this validator
|
|
284
|
+
const allPerformance = await this.store.getEpochPerformance(validator);
|
|
285
|
+
|
|
286
|
+
// Sort by epoch descending to get most recent first, keep only epochs strictly before the current one, and get the first N
|
|
287
|
+
const pastEpochs = allPerformance.sort((a, b) => Number(b.epoch - a.epoch)).filter(p => p.epoch < currentEpoch);
|
|
177
288
|
|
|
178
289
|
// If we don't have enough historical data, don't slash
|
|
179
|
-
if (
|
|
290
|
+
if (pastEpochs.length < requiredConsecutiveEpochs) {
|
|
180
291
|
this.logger.debug(
|
|
181
292
|
`Not enough historical data for slashing ${validator} for inactivity (${allPerformance.length} epochs < ${requiredConsecutiveEpochs} required)`,
|
|
182
293
|
);
|
|
183
294
|
return false;
|
|
184
295
|
}
|
|
185
296
|
|
|
186
|
-
//
|
|
187
|
-
return
|
|
188
|
-
.sort((a, b) => Number(b.epoch - a.epoch))
|
|
189
|
-
.filter(p => p.epoch < currentEpoch)
|
|
297
|
+
// Check that we have at least requiredConsecutiveEpochs and that all of them are above the inactivity threshold
|
|
298
|
+
return pastEpochs
|
|
190
299
|
.slice(0, requiredConsecutiveEpochs)
|
|
191
|
-
.every(p => p.missed / p.total >= this.config.slashInactivityTargetPercentage);
|
|
300
|
+
.every(p => (p.total === 0 ? false : p.missed / p.total >= this.config.slashInactivityTargetPercentage));
|
|
192
301
|
}
|
|
193
302
|
|
|
194
|
-
protected async
|
|
195
|
-
if (this.config.slashInactivityPenalty === 0n) {
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
|
|
303
|
+
protected async handleEpochPerformance(epoch: EpochNumber, performance: ValidatorsEpochPerformance) {
|
|
199
304
|
const inactiveValidators = getEntries(performance)
|
|
200
|
-
.filter(([_, { missed, total }]) => missed / total >= this.config.slashInactivityTargetPercentage)
|
|
305
|
+
.filter(([_, { missed, total }]) => total > 0 && missed / total >= this.config.slashInactivityTargetPercentage)
|
|
201
306
|
.map(([address]) => address);
|
|
202
307
|
|
|
203
308
|
this.logger.debug(`Found ${inactiveValidators.length} inactive validators in epoch ${epoch}`, {
|
|
@@ -215,13 +320,21 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
215
320
|
validator: EthAddress.fromString(address),
|
|
216
321
|
amount: this.config.slashInactivityPenalty,
|
|
217
322
|
offenseType: OffenseType.INACTIVITY,
|
|
218
|
-
epochOrSlot: epoch,
|
|
323
|
+
epochOrSlot: BigInt(epoch),
|
|
219
324
|
}));
|
|
220
325
|
|
|
221
326
|
if (criminals.length > 0) {
|
|
222
|
-
this.logger.
|
|
223
|
-
`Identified ${criminals.length}
|
|
224
|
-
{
|
|
327
|
+
this.logger.info(
|
|
328
|
+
`Identified ${criminals.length} inactivity offenses in at least ${epochThreshold} consecutive epochs`,
|
|
329
|
+
{
|
|
330
|
+
offenses: args.map(arg => ({
|
|
331
|
+
validator: arg.validator.toString(),
|
|
332
|
+
amount: arg.amount,
|
|
333
|
+
offenseType: getOffenseTypeName(arg.offenseType),
|
|
334
|
+
epochOrSlot: arg.epochOrSlot,
|
|
335
|
+
})),
|
|
336
|
+
epochThreshold,
|
|
337
|
+
},
|
|
225
338
|
);
|
|
226
339
|
this.emit(WANT_TO_SLASH_EVENT, args);
|
|
227
340
|
}
|
|
@@ -231,33 +344,80 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
231
344
|
* Process data for two L2 slots ago.
|
|
232
345
|
* Note that we do not process historical data, since we rely on p2p data for processing,
|
|
233
346
|
* and we don't have that data if we were offline during the period.
|
|
347
|
+
*
|
|
348
|
+
* `currentSlot` is anchored to the archiver's last synced L2 slot rather than the wallclock,
|
|
349
|
+
* so the per-slot lag (`isReadyToProcess`) and the end-of-epoch buffer (`processEpochEnds`)
|
|
350
|
+
* advance with archiver.
|
|
234
351
|
*/
|
|
235
352
|
public async work() {
|
|
236
|
-
const
|
|
353
|
+
const currentSlot = await this.getCurrentSlot();
|
|
237
354
|
try {
|
|
238
|
-
//
|
|
239
|
-
// Note we never `start` the blockstream, so it loops at the same pace as we do.
|
|
240
|
-
await this.blockStream.sync();
|
|
241
|
-
|
|
242
|
-
// Check if we are ready to process data for two L2 slots ago.
|
|
355
|
+
// Per-slot activity recording (lag = 2 slots for P2P attestation settlement).
|
|
243
356
|
const targetSlot = await this.isReadyToProcess(currentSlot);
|
|
244
|
-
|
|
245
|
-
// And process it if we are.
|
|
246
357
|
if (targetSlot !== false) {
|
|
247
358
|
await this.processSlot(targetSlot);
|
|
248
359
|
}
|
|
360
|
+
|
|
361
|
+
// End-of-epoch evaluation (lag = sentinelEpochEndBufferSlots beyond the epoch's last slot).
|
|
362
|
+
await this.processEpochEnds(currentSlot);
|
|
249
363
|
} catch (err) {
|
|
250
364
|
this.logger.error(`Failed to process slot ${currentSlot}`, err);
|
|
251
365
|
}
|
|
252
366
|
}
|
|
253
367
|
|
|
368
|
+
/**
|
|
369
|
+
* After the configured buffer has elapsed past an epoch's last slot, runs the end-of-epoch
|
|
370
|
+
* aggregator for that epoch. Catches up if multiple epochs become eligible at once.
|
|
371
|
+
*/
|
|
372
|
+
protected async processEpochEnds(currentSlot: SlotNumber) {
|
|
373
|
+
const constants = this.epochCache.getL1Constants();
|
|
374
|
+
const buffer = this.config.sentinelEpochEndBufferSlots;
|
|
375
|
+
if (currentSlot < buffer) {
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
if (this.initialSlot === undefined) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// We can close epoch E iff:
|
|
383
|
+
// - the per-slot recorder has covered the epoch's last slot (lastProcessedSlot ≥ toSlot(E))
|
|
384
|
+
// - the buffer has elapsed past the epoch's last slot (currentSlot − buffer ≥ toSlot(E))
|
|
385
|
+
// - the epoch is not in the past relative to when the sentinel started (toSlot(E) > initialSlot)
|
|
386
|
+
if (this.lastProcessedSlot === undefined) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
const slotForBuffer = SlotNumber(currentSlot - buffer);
|
|
390
|
+
|
|
391
|
+
// First eligible epoch to close is the one after lastEvaluatedEpoch, or the epoch containing
|
|
392
|
+
// the initial slot if we haven't evaluated any yet (the initialSlot epoch may be partial — we
|
|
393
|
+
// don't try to evaluate it, we start from initialSlot's epoch + 1).
|
|
394
|
+
const startEpoch =
|
|
395
|
+
this.lastEvaluatedEpoch !== undefined
|
|
396
|
+
? EpochNumber(this.lastEvaluatedEpoch + 1)
|
|
397
|
+
: EpochNumber(getEpochAtSlot(this.initialSlot, constants) + 1);
|
|
398
|
+
|
|
399
|
+
for (let epoch = startEpoch; ; epoch = EpochNumber(epoch + 1)) {
|
|
400
|
+
const [, toSlot] = getSlotRangeForEpoch(epoch, constants);
|
|
401
|
+
if (toSlot > this.lastProcessedSlot || toSlot > slotForBuffer) {
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
await this.handleEpochEnd(epoch);
|
|
405
|
+
this.lastEvaluatedEpoch = epoch;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
254
409
|
/**
|
|
255
410
|
* 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.
|
|
256
411
|
* 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.
|
|
257
412
|
* Last, we check the p2p is synced with the archiver, so it has pulled all attestations from it.
|
|
258
413
|
*/
|
|
259
|
-
protected async isReadyToProcess(currentSlot:
|
|
260
|
-
|
|
414
|
+
protected async isReadyToProcess(currentSlot: SlotNumber): Promise<SlotNumber | false> {
|
|
415
|
+
if (currentSlot < 2) {
|
|
416
|
+
this.logger.trace(`Current slot ${currentSlot} too early.`);
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
const targetSlot = SlotNumber(currentSlot - 2);
|
|
261
421
|
if (this.lastProcessedSlot && this.lastProcessedSlot >= targetSlot) {
|
|
262
422
|
this.logger.trace(`Already processed slot ${targetSlot}`, { lastProcessedSlot: this.lastProcessedSlot });
|
|
263
423
|
return false;
|
|
@@ -273,14 +433,14 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
273
433
|
return false;
|
|
274
434
|
}
|
|
275
435
|
|
|
276
|
-
const
|
|
277
|
-
if (
|
|
278
|
-
this.logger.debug(`Waiting for archiver to sync with L2 slot ${targetSlot}`, {
|
|
436
|
+
const syncedSlot = await this.archiver.getSyncedL2SlotNumber();
|
|
437
|
+
if (syncedSlot === undefined || syncedSlot < targetSlot) {
|
|
438
|
+
this.logger.debug(`Waiting for archiver to sync with L2 slot ${targetSlot}`, { syncedSlot, targetSlot });
|
|
279
439
|
return false;
|
|
280
440
|
}
|
|
281
441
|
|
|
282
|
-
const archiverLastBlockHash = await this.
|
|
283
|
-
const p2pLastBlockHash = await this.p2p.getL2Tips().then(tips => tips.
|
|
442
|
+
const archiverLastBlockHash = await this.archiver.getL2Tips().then(tip => tip.proposed.hash);
|
|
443
|
+
const p2pLastBlockHash = await this.p2p.getL2Tips().then(tips => tips.proposed.hash);
|
|
284
444
|
const isP2pSynced = archiverLastBlockHash === p2pLastBlockHash;
|
|
285
445
|
if (!isP2pSynced) {
|
|
286
446
|
this.logger.debug(`Waiting for P2P client to sync with archiver`, { archiverLastBlockHash, p2pLastBlockHash });
|
|
@@ -294,8 +454,13 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
294
454
|
* Gathers committee and proposer data for a given slot, computes slot stats,
|
|
295
455
|
* and updates overall stats.
|
|
296
456
|
*/
|
|
297
|
-
protected async processSlot(slot:
|
|
298
|
-
const { epoch, seed, committee } = await this.epochCache.getCommittee(slot);
|
|
457
|
+
protected async processSlot(slot: SlotNumber) {
|
|
458
|
+
const { epoch, seed, committee, isEscapeHatchOpen } = await this.epochCache.getCommittee(slot);
|
|
459
|
+
if (isEscapeHatchOpen) {
|
|
460
|
+
this.logger.info(`Skipping slot ${slot} at epoch ${epoch} - escape hatch is open`);
|
|
461
|
+
this.lastProcessedSlot = slot;
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
299
464
|
if (!committee || committee.length === 0) {
|
|
300
465
|
this.logger.trace(`No committee found for slot ${slot} at epoch ${epoch}`);
|
|
301
466
|
this.lastProcessedSlot = slot;
|
|
@@ -309,46 +474,75 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
309
474
|
this.lastProcessedSlot = slot;
|
|
310
475
|
}
|
|
311
476
|
|
|
312
|
-
/**
|
|
313
|
-
|
|
477
|
+
/**
|
|
478
|
+
* Computes activity for a given slot using the six-case taxonomy.
|
|
479
|
+
*
|
|
480
|
+
* Proposer status:
|
|
481
|
+
* - case 6 `checkpoint-mined` — a checkpoint covering this slot has landed on L1.
|
|
482
|
+
* - case 5 `checkpoint-valid` — the local node re-executed a checkpoint proposal for this
|
|
483
|
+
* slot successfully.
|
|
484
|
+
* - case 4 `checkpoint-invalid` — the local node re-executed a checkpoint proposal for this
|
|
485
|
+
* slot and rejected it.
|
|
486
|
+
* - case 3 `checkpoint-unvalidated` — the local node observed a checkpoint proposal for this
|
|
487
|
+
* slot but could not validate it (missing data, timeouts).
|
|
488
|
+
* - case 2 `checkpoint-missed` — block proposals seen on P2P but no checkpoint proposal.
|
|
489
|
+
* - case 1 `blocks-missed` — no block proposals seen for this slot.
|
|
490
|
+
*
|
|
491
|
+
* Missing-attestor penalties apply only in cases 5 and 6, where the local node has positive
|
|
492
|
+
* evidence the checkpoint was valid or has been canonicalised on L1.
|
|
493
|
+
*/
|
|
494
|
+
protected async getSlotActivity(slot: SlotNumber, epoch: EpochNumber, proposer: EthAddress, committee: EthAddress[]) {
|
|
314
495
|
this.logger.debug(`Computing stats for slot ${slot} at epoch ${epoch}`, { slot, epoch, proposer, committee });
|
|
315
496
|
|
|
316
|
-
//
|
|
317
|
-
|
|
318
|
-
//
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
// (contains the ones synced from mined blocks, which we may have missed from p2p).
|
|
322
|
-
const block = this.slotNumberToBlock.get(slot);
|
|
323
|
-
const p2pAttested = await this.p2p.getAttestationsForSlot(slot, block?.archive);
|
|
324
|
-
// Filter out attestations with invalid signatures
|
|
497
|
+
// Gather attestors from both p2p (live attestations) and the archiver (signers on the
|
|
498
|
+
// checkpoint if one has landed on L1). Fetched on demand so it always reflects the canonical chain.
|
|
499
|
+
// Used regardless of which case applies.
|
|
500
|
+
const checkpoint = await this.getCheckpointForSlot(slot);
|
|
501
|
+
const p2pAttested = await this.p2p.getCheckpointAttestationsForSlot(slot, checkpoint?.proposalPayloadHash);
|
|
325
502
|
const p2pAttestors = p2pAttested.map(a => a.getSender()).filter((s): s is EthAddress => s !== undefined);
|
|
326
503
|
const attestors = new Set(
|
|
327
|
-
[...p2pAttestors.map(a => a.toString()), ...(
|
|
328
|
-
addr => proposer.toString() !== addr,
|
|
504
|
+
[...p2pAttestors.map(a => a.toString()), ...(checkpoint?.attestors.map(a => a.toString()) ?? [])].filter(
|
|
505
|
+
addr => proposer.toString() !== addr,
|
|
329
506
|
),
|
|
330
507
|
);
|
|
331
508
|
|
|
332
|
-
//
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
509
|
+
// Determine the proposer status from the six-case taxonomy.
|
|
510
|
+
const reexecutionOutcome = this.reexecutionTracker.getOutcomeForSlot(slot);
|
|
511
|
+
let status:
|
|
512
|
+
| 'checkpoint-mined'
|
|
513
|
+
| 'checkpoint-valid'
|
|
514
|
+
| 'checkpoint-invalid'
|
|
515
|
+
| 'checkpoint-unvalidated'
|
|
516
|
+
| 'checkpoint-missed'
|
|
517
|
+
| 'blocks-missed';
|
|
518
|
+
if (checkpoint) {
|
|
519
|
+
status = 'checkpoint-mined';
|
|
520
|
+
} else if (reexecutionOutcome === 'valid') {
|
|
521
|
+
status = 'checkpoint-valid';
|
|
522
|
+
} else if (reexecutionOutcome === 'invalid') {
|
|
523
|
+
status = 'checkpoint-invalid';
|
|
524
|
+
} else if (reexecutionOutcome === 'unvalidated') {
|
|
525
|
+
status = 'checkpoint-unvalidated';
|
|
526
|
+
} else {
|
|
527
|
+
// No L1 checkpoint, no local re-execution outcome for this slot. Distinguish "proposer
|
|
528
|
+
// sent block proposals but never made a checkpoint" from "proposer sent nothing".
|
|
529
|
+
const hasBlockProposals = await this.p2p.hasBlockProposalsForSlot(slot);
|
|
530
|
+
status = hasBlockProposals ? 'checkpoint-missed' : 'blocks-missed';
|
|
531
|
+
}
|
|
532
|
+
this.logger.debug(`Checkpoint status for slot ${slot}: ${status}`, { ...checkpoint, slot });
|
|
340
533
|
|
|
341
|
-
//
|
|
534
|
+
// Missing-attestor faults only apply when we have positive evidence the proposal was valid.
|
|
535
|
+
const attestorsExpected = status === 'checkpoint-mined' || status === 'checkpoint-valid';
|
|
342
536
|
const missedAttestors = new Set(
|
|
343
|
-
|
|
344
|
-
?
|
|
345
|
-
:
|
|
537
|
+
attestorsExpected
|
|
538
|
+
? committee.filter(v => !attestors.has(v.toString()) && !proposer.equals(v)).map(v => v.toString())
|
|
539
|
+
: [],
|
|
346
540
|
);
|
|
347
541
|
|
|
348
542
|
this.logger.debug(`Retrieved ${attestors.size} attestors out of ${committee.length} for slot ${slot}`, {
|
|
349
|
-
|
|
543
|
+
status,
|
|
350
544
|
proposer: proposer.toString(),
|
|
351
|
-
...
|
|
545
|
+
...checkpoint,
|
|
352
546
|
slot,
|
|
353
547
|
attestors: [...attestors],
|
|
354
548
|
missedAttestors: [...missedAttestors],
|
|
@@ -358,7 +552,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
358
552
|
// Compute the status for each validator in the committee
|
|
359
553
|
const statusFor = (who: `0x${string}`): ValidatorStatusInSlot | undefined => {
|
|
360
554
|
if (who === proposer.toString()) {
|
|
361
|
-
return
|
|
555
|
+
return status;
|
|
362
556
|
} else if (attestors.has(who)) {
|
|
363
557
|
return 'attestation-sent';
|
|
364
558
|
} else if (missedAttestors.has(who)) {
|
|
@@ -372,7 +566,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
372
566
|
}
|
|
373
567
|
|
|
374
568
|
/** Push the status for each slot for each validator. */
|
|
375
|
-
protected updateValidators(slot:
|
|
569
|
+
protected updateValidators(slot: SlotNumber, stats: Record<`0x${string}`, ValidatorStatusInSlot | undefined>) {
|
|
376
570
|
return this.store.updateValidators(slot, stats);
|
|
377
571
|
}
|
|
378
572
|
|
|
@@ -381,13 +575,13 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
381
575
|
fromSlot,
|
|
382
576
|
toSlot,
|
|
383
577
|
validators,
|
|
384
|
-
}: { fromSlot?:
|
|
578
|
+
}: { fromSlot?: SlotNumber; toSlot?: SlotNumber; validators?: EthAddress[] } = {}): Promise<ValidatorsStats> {
|
|
385
579
|
const histories = validators
|
|
386
580
|
? fromEntries(await Promise.all(validators.map(async v => [v.toString(), await this.store.getHistory(v)])))
|
|
387
581
|
: await this.store.getHistories();
|
|
388
582
|
|
|
389
|
-
const slotNow = this.
|
|
390
|
-
fromSlot ??= (this.lastProcessedSlot ?? slotNow) -
|
|
583
|
+
const slotNow = await this.getCurrentSlot();
|
|
584
|
+
fromSlot ??= SlotNumber(Math.max((this.lastProcessedSlot ?? slotNow) - this.store.getHistoryLength(), 0));
|
|
391
585
|
toSlot ??= this.lastProcessedSlot ?? slotNow;
|
|
392
586
|
|
|
393
587
|
const stats = mapValues(histories, (history, address) =>
|
|
@@ -405,8 +599,8 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
405
599
|
/** Computes stats for a single validator. */
|
|
406
600
|
public async getValidatorStats(
|
|
407
601
|
validatorAddress: EthAddress,
|
|
408
|
-
fromSlot?:
|
|
409
|
-
toSlot?:
|
|
602
|
+
fromSlot?: SlotNumber,
|
|
603
|
+
toSlot?: SlotNumber,
|
|
410
604
|
): Promise<SingleValidatorStats | undefined> {
|
|
411
605
|
const history = await this.store.getHistory(validatorAddress);
|
|
412
606
|
|
|
@@ -414,14 +608,15 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
414
608
|
return undefined;
|
|
415
609
|
}
|
|
416
610
|
|
|
417
|
-
const slotNow = this.
|
|
418
|
-
const effectiveFromSlot =
|
|
611
|
+
const slotNow = await this.getCurrentSlot();
|
|
612
|
+
const effectiveFromSlot =
|
|
613
|
+
fromSlot ?? SlotNumber(Math.max((this.lastProcessedSlot ?? slotNow) - this.store.getHistoryLength(), 0));
|
|
419
614
|
const effectiveToSlot = toSlot ?? this.lastProcessedSlot ?? slotNow;
|
|
420
615
|
|
|
421
616
|
const historyLength = BigInt(this.store.getHistoryLength());
|
|
422
|
-
if (effectiveToSlot - effectiveFromSlot > historyLength) {
|
|
617
|
+
if (BigInt(effectiveToSlot) - BigInt(effectiveFromSlot) > historyLength) {
|
|
423
618
|
throw new Error(
|
|
424
|
-
`Slot range (${effectiveToSlot - effectiveFromSlot}) exceeds history length (${historyLength}). ` +
|
|
619
|
+
`Slot range (${BigInt(effectiveToSlot) - BigInt(effectiveFromSlot)}) exceeds history length (${historyLength}). ` +
|
|
425
620
|
`Requested range: ${effectiveFromSlot} to ${effectiveToSlot}.`,
|
|
426
621
|
);
|
|
427
622
|
}
|
|
@@ -432,11 +627,10 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
432
627
|
effectiveFromSlot,
|
|
433
628
|
effectiveToSlot,
|
|
434
629
|
);
|
|
435
|
-
const allTimeProvenPerformance = await this.store.getProvenPerformance(validatorAddress);
|
|
436
630
|
|
|
437
631
|
return {
|
|
438
632
|
validator,
|
|
439
|
-
|
|
633
|
+
allTimeEpochPerformance: await this.store.getEpochPerformance(validatorAddress),
|
|
440
634
|
lastProcessedSlot: this.lastProcessedSlot,
|
|
441
635
|
initialSlot: this.initialSlot,
|
|
442
636
|
slotWindow: this.store.getHistoryLength(),
|
|
@@ -446,19 +640,24 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
446
640
|
protected computeStatsForValidator(
|
|
447
641
|
address: `0x${string}`,
|
|
448
642
|
allHistory: ValidatorStatusHistory,
|
|
449
|
-
fromSlot?:
|
|
450
|
-
toSlot?:
|
|
643
|
+
fromSlot?: SlotNumber,
|
|
644
|
+
toSlot?: SlotNumber,
|
|
451
645
|
): ValidatorStats {
|
|
452
|
-
let history = fromSlot ? allHistory.filter(h => h.slot >= fromSlot) : allHistory;
|
|
453
|
-
history = toSlot ? history.filter(h => h.slot <= toSlot) : history;
|
|
454
|
-
const lastProposal = history.filter(h => h.status === '
|
|
646
|
+
let history = fromSlot ? allHistory.filter(h => BigInt(h.slot) >= fromSlot) : allHistory;
|
|
647
|
+
history = toSlot ? history.filter(h => BigInt(h.slot) <= toSlot) : history;
|
|
648
|
+
const lastProposal = history.filter(h => h.status === 'checkpoint-valid' || h.status === 'checkpoint-mined').at(-1);
|
|
455
649
|
const lastAttestation = history.filter(h => h.status === 'attestation-sent').at(-1);
|
|
456
650
|
return {
|
|
457
651
|
address: EthAddress.fromString(address),
|
|
458
652
|
lastProposal: this.computeFromSlot(lastProposal?.slot),
|
|
459
653
|
lastAttestation: this.computeFromSlot(lastAttestation?.slot),
|
|
460
654
|
totalSlots: history.length,
|
|
461
|
-
missedProposals: this.computeMissed(history, '
|
|
655
|
+
missedProposals: this.computeMissed(history, 'proposer', [
|
|
656
|
+
'checkpoint-missed',
|
|
657
|
+
'blocks-missed',
|
|
658
|
+
'checkpoint-invalid',
|
|
659
|
+
'checkpoint-unvalidated',
|
|
660
|
+
]),
|
|
462
661
|
missedAttestations: this.computeMissed(history, 'attestation', ['attestation-missed']),
|
|
463
662
|
history,
|
|
464
663
|
};
|
|
@@ -466,10 +665,12 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
466
665
|
|
|
467
666
|
protected computeMissed(
|
|
468
667
|
history: ValidatorStatusHistory,
|
|
469
|
-
|
|
668
|
+
computeOverCategory: ValidatorStatusType | undefined,
|
|
470
669
|
filter: ValidatorStatusInSlot[],
|
|
471
670
|
) {
|
|
472
|
-
const relevantHistory = history.filter(
|
|
671
|
+
const relevantHistory = history.filter(
|
|
672
|
+
h => !computeOverCategory || statusToCategory(h.status) === computeOverCategory,
|
|
673
|
+
);
|
|
473
674
|
const filteredHistory = relevantHistory.filter(h => filter.includes(h.status));
|
|
474
675
|
return {
|
|
475
676
|
currentStreak: countWhile([...relevantHistory].reverse(), h => filter.includes(h.status)),
|
|
@@ -479,7 +680,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
479
680
|
};
|
|
480
681
|
}
|
|
481
682
|
|
|
482
|
-
protected computeFromSlot(slot:
|
|
683
|
+
protected computeFromSlot(slot: SlotNumber | undefined) {
|
|
483
684
|
if (slot === undefined) {
|
|
484
685
|
return undefined;
|
|
485
686
|
}
|