@aztec/aztec-node 5.0.0-private.20260319 → 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/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 +16 -4
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +15 -5
- 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/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 +128 -134
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +393 -820
- 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 +496 -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 +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/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 +5 -3
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/factory.js +12 -5
- package/dest/sentinel/sentinel.d.ts +145 -21
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +227 -105
- package/dest/sentinel/store.d.ts +8 -8
- package/dest/sentinel/store.d.ts.map +1 -1
- package/dest/sentinel/store.js +25 -17
- package/dest/test/index.d.ts +3 -3
- package/dest/test/index.d.ts.map +1 -1
- package/package.json +28 -26
- package/src/aztec-node/block_response_helpers.ts +161 -0
- package/src/aztec-node/config.ts +30 -7
- package/src/aztec-node/node_public_calls_simulator.ts +383 -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 +514 -1070
- package/src/bin/index.ts +19 -12
- package/src/factory.ts +656 -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 +360 -0
- package/src/sentinel/README.md +103 -0
- package/src/sentinel/config.ts +18 -6
- package/src/sentinel/factory.ts +21 -6
- package/src/sentinel/sentinel.ts +277 -130
- package/src/sentinel/store.ts +26 -18
- package/src/test/index.ts +2 -2
package/src/sentinel/sentinel.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
-
import {
|
|
2
|
+
import { CheckpointNumber, CheckpointProposalHash, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { countWhile, filterAsync, fromEntries, getEntries, mapValues } from '@aztec/foundation/collection';
|
|
4
4
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
6
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
7
|
-
import { L2TipsMemoryStore, type L2TipsStore } from '@aztec/kv-store/stores';
|
|
8
7
|
import type { P2PClient } from '@aztec/p2p';
|
|
9
8
|
import {
|
|
10
9
|
OffenseType,
|
|
@@ -12,16 +11,14 @@ import {
|
|
|
12
11
|
type WantToSlashArgs,
|
|
13
12
|
type Watcher,
|
|
14
13
|
type WatcherEmitter,
|
|
14
|
+
getOffenseTypeName,
|
|
15
15
|
} from '@aztec/slasher';
|
|
16
16
|
import type { SlasherConfig } from '@aztec/slasher/config';
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
type L2BlockStreamEvent,
|
|
21
|
-
type L2BlockStreamEventHandler,
|
|
22
|
-
getAttestationInfoFromPublishedCheckpoint,
|
|
23
|
-
} 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';
|
|
24
20
|
import { getEpochAtSlot, getSlotRangeForEpoch, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
21
|
+
import { ConsensusPayload, type CoordinationSignatureContext } from '@aztec/stdlib/p2p';
|
|
25
22
|
import type {
|
|
26
23
|
SingleValidatorStats,
|
|
27
24
|
ValidatorStats,
|
|
@@ -34,8 +31,16 @@ import type {
|
|
|
34
31
|
|
|
35
32
|
import EventEmitter from 'node:events';
|
|
36
33
|
|
|
34
|
+
import type { SentinelConfig } from './config.js';
|
|
37
35
|
import { SentinelStore } from './store.js';
|
|
38
36
|
|
|
37
|
+
export type SentinelRuntimeConfig = Pick<
|
|
38
|
+
SlasherConfig,
|
|
39
|
+
'slashInactivityTargetPercentage' | 'slashInactivityPenalty' | 'slashInactivityConsecutiveEpochThreshold'
|
|
40
|
+
> &
|
|
41
|
+
Pick<SentinelConfig, 'sentinelEpochEndBufferSlots'> &
|
|
42
|
+
Pick<ChainConfig, 'l1ChainId' | 'rollupAddress'>;
|
|
43
|
+
|
|
39
44
|
/** Maps a validator status to its category: proposer or attestation. */
|
|
40
45
|
function statusToCategory(status: ValidatorStatusInSlot): ValidatorStatusType {
|
|
41
46
|
switch (status) {
|
|
@@ -47,36 +52,105 @@ function statusToCategory(status: ValidatorStatusInSlot): ValidatorStatusType {
|
|
|
47
52
|
}
|
|
48
53
|
}
|
|
49
54
|
|
|
50
|
-
|
|
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 {
|
|
51
126
|
protected runningPromise: RunningPromise;
|
|
52
|
-
protected blockStream!: L2BlockStream;
|
|
53
|
-
protected l2TipsStore: L2TipsStore;
|
|
54
127
|
|
|
55
128
|
protected initialSlot: SlotNumber | undefined;
|
|
56
129
|
protected lastProcessedSlot: SlotNumber | undefined;
|
|
57
|
-
|
|
58
|
-
protected
|
|
59
|
-
SlotNumber,
|
|
60
|
-
{ checkpointNumber: CheckpointNumber; archive: string; attestors: EthAddress[] }
|
|
61
|
-
> = new Map();
|
|
130
|
+
/** Largest epoch number for which the end-of-epoch aggregator has run. */
|
|
131
|
+
protected lastEvaluatedEpoch: EpochNumber | undefined;
|
|
62
132
|
|
|
63
133
|
constructor(
|
|
64
134
|
protected epochCache: EpochCache,
|
|
65
135
|
protected archiver: L2BlockSource,
|
|
66
136
|
protected p2p: P2PClient,
|
|
67
137
|
protected store: SentinelStore,
|
|
68
|
-
protected
|
|
69
|
-
|
|
70
|
-
'slashInactivityTargetPercentage' | 'slashInactivityPenalty' | 'slashInactivityConsecutiveEpochThreshold'
|
|
71
|
-
>,
|
|
138
|
+
protected reexecutionTracker: CheckpointReexecutionTracker,
|
|
139
|
+
protected config: SentinelRuntimeConfig,
|
|
72
140
|
protected logger = createLogger('node:sentinel'),
|
|
73
141
|
) {
|
|
74
142
|
super();
|
|
75
|
-
this.l2TipsStore = new L2TipsMemoryStore();
|
|
76
143
|
const interval = (epochCache.getL1Constants().ethereumSlotDuration * 1000) / 4;
|
|
77
144
|
this.runningPromise = new RunningPromise(this.work.bind(this), logger, interval);
|
|
78
145
|
}
|
|
79
146
|
|
|
147
|
+
private getSignatureContext(): CoordinationSignatureContext {
|
|
148
|
+
return {
|
|
149
|
+
chainId: this.config.l1ChainId,
|
|
150
|
+
rollupAddress: this.config.rollupAddress,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
80
154
|
public updateConfig(config: Partial<SlasherConfig>) {
|
|
81
155
|
this.config = { ...this.config, ...config };
|
|
82
156
|
}
|
|
@@ -86,81 +160,85 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
86
160
|
this.runningPromise.start();
|
|
87
161
|
}
|
|
88
162
|
|
|
89
|
-
/**
|
|
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
|
+
*/
|
|
90
169
|
protected async init() {
|
|
91
|
-
this.initialSlot = this.
|
|
92
|
-
|
|
93
|
-
this.logger.info(`Starting validator sentinel with initial slot ${this.initialSlot} and block ${startingBlock}`);
|
|
94
|
-
this.blockStream = new L2BlockStream(this.archiver, this.l2TipsStore, this, this.logger, { startingBlock });
|
|
170
|
+
this.initialSlot = await this.getCurrentSlot();
|
|
171
|
+
this.logger.info(`Starting validator sentinel with initial slot ${this.initialSlot}`);
|
|
95
172
|
}
|
|
96
173
|
|
|
97
|
-
|
|
98
|
-
|
|
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();
|
|
99
183
|
}
|
|
100
184
|
|
|
101
|
-
public
|
|
102
|
-
|
|
103
|
-
if (event.type === 'chain-checkpointed') {
|
|
104
|
-
this.handleCheckpoint(event);
|
|
105
|
-
} else if (event.type === 'chain-proven') {
|
|
106
|
-
await this.handleChainProven(event);
|
|
107
|
-
}
|
|
185
|
+
public stop() {
|
|
186
|
+
return this.runningPromise.stop();
|
|
108
187
|
}
|
|
109
188
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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[];
|
|
202
|
+
}
|
|
203
|
+
| undefined
|
|
204
|
+
> {
|
|
205
|
+
const checkpoint = await this.archiver.getCheckpoint({ slot });
|
|
206
|
+
if (!checkpoint) {
|
|
207
|
+
return undefined;
|
|
113
208
|
}
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
209
|
+
const signatureContext = this.getSignatureContext();
|
|
210
|
+
const proposalPayloadHash = CheckpointProposalHash.fromBuffer(
|
|
211
|
+
ConsensusPayload.fromCheckpoint(checkpoint.checkpoint, signatureContext).getPayloadHash(),
|
|
212
|
+
);
|
|
213
|
+
return {
|
|
118
214
|
checkpointNumber: checkpoint.checkpoint.number,
|
|
119
215
|
archive: checkpoint.checkpoint.archive.root.toString(),
|
|
120
|
-
|
|
216
|
+
proposalPayloadHash,
|
|
217
|
+
attestors: getAttestationInfoFromPublishedCheckpoint(checkpoint, signatureContext)
|
|
121
218
|
.filter(a => a.status === 'recovered-from-signature')
|
|
122
219
|
.map(a => a.address!),
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Prune the archive map to only keep at most N entries
|
|
126
|
-
const historyLength = this.store.getHistoryLength();
|
|
127
|
-
if (this.slotNumberToCheckpoint.size > historyLength) {
|
|
128
|
-
const toDelete = Array.from(this.slotNumberToCheckpoint.keys())
|
|
129
|
-
.sort((a, b) => Number(a - b))
|
|
130
|
-
.slice(0, this.slotNumberToCheckpoint.size - historyLength);
|
|
131
|
-
for (const key of toDelete) {
|
|
132
|
-
this.slotNumberToCheckpoint.delete(key);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
220
|
+
};
|
|
135
221
|
}
|
|
136
222
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// TODO(palla/slash): We should only be computing proven performance if this is
|
|
149
|
-
// a full proof epoch and not a partial one, otherwise we'll end up with skewed stats.
|
|
150
|
-
const epoch = getEpochAtSlot(header.getSlot(), this.epochCache.getL1Constants());
|
|
151
|
-
this.logger.debug(`Computing proven performance for epoch ${epoch}`);
|
|
152
|
-
const performance = await this.computeProvenPerformance(epoch);
|
|
153
|
-
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);
|
|
154
232
|
|
|
155
|
-
await this.store.
|
|
156
|
-
await this.
|
|
233
|
+
await this.store.updateEpochPerformance(epoch, performance);
|
|
234
|
+
await this.handleEpochPerformance(epoch, performance);
|
|
157
235
|
}
|
|
158
236
|
|
|
159
|
-
protected async
|
|
237
|
+
protected async computeEpochPerformance(epoch: EpochNumber): Promise<ValidatorsEpochPerformance> {
|
|
160
238
|
const [fromSlot, toSlot] = getSlotRangeForEpoch(epoch, this.epochCache.getL1Constants());
|
|
161
239
|
const { committee, isEscapeHatchOpen } = await this.epochCache.getCommittee(fromSlot);
|
|
162
240
|
if (isEscapeHatchOpen) {
|
|
163
|
-
this.logger.info(`Skipping
|
|
241
|
+
this.logger.info(`Skipping epoch performance for epoch ${epoch} - escape hatch is open`);
|
|
164
242
|
return {};
|
|
165
243
|
}
|
|
166
244
|
if (!committee) {
|
|
@@ -202,8 +280,8 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
202
280
|
return true;
|
|
203
281
|
}
|
|
204
282
|
|
|
205
|
-
// Get all historical performance for this validator
|
|
206
|
-
const allPerformance = await this.store.
|
|
283
|
+
// Get all historical per-epoch performance for this validator
|
|
284
|
+
const allPerformance = await this.store.getEpochPerformance(validator);
|
|
207
285
|
|
|
208
286
|
// Sort by epoch descending to get most recent first, keep only epochs strictly before the current one, and get the first N
|
|
209
287
|
const pastEpochs = allPerformance.sort((a, b) => Number(b.epoch - a.epoch)).filter(p => p.epoch < currentEpoch);
|
|
@@ -219,16 +297,12 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
219
297
|
// Check that we have at least requiredConsecutiveEpochs and that all of them are above the inactivity threshold
|
|
220
298
|
return pastEpochs
|
|
221
299
|
.slice(0, requiredConsecutiveEpochs)
|
|
222
|
-
.every(p => p.missed / p.total >= this.config.slashInactivityTargetPercentage);
|
|
300
|
+
.every(p => (p.total === 0 ? false : p.missed / p.total >= this.config.slashInactivityTargetPercentage));
|
|
223
301
|
}
|
|
224
302
|
|
|
225
|
-
protected async
|
|
226
|
-
if (this.config.slashInactivityPenalty === 0n) {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
|
|
303
|
+
protected async handleEpochPerformance(epoch: EpochNumber, performance: ValidatorsEpochPerformance) {
|
|
230
304
|
const inactiveValidators = getEntries(performance)
|
|
231
|
-
.filter(([_, { missed, total }]) => missed / total >= this.config.slashInactivityTargetPercentage)
|
|
305
|
+
.filter(([_, { missed, total }]) => total > 0 && missed / total >= this.config.slashInactivityTargetPercentage)
|
|
232
306
|
.map(([address]) => address);
|
|
233
307
|
|
|
234
308
|
this.logger.debug(`Found ${inactiveValidators.length} inactive validators in epoch ${epoch}`, {
|
|
@@ -250,9 +324,17 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
250
324
|
}));
|
|
251
325
|
|
|
252
326
|
if (criminals.length > 0) {
|
|
253
|
-
this.logger.
|
|
254
|
-
`Identified ${criminals.length}
|
|
255
|
-
{
|
|
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
|
+
},
|
|
256
338
|
);
|
|
257
339
|
this.emit(WANT_TO_SLASH_EVENT, args);
|
|
258
340
|
}
|
|
@@ -262,26 +344,68 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
262
344
|
* Process data for two L2 slots ago.
|
|
263
345
|
* Note that we do not process historical data, since we rely on p2p data for processing,
|
|
264
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.
|
|
265
351
|
*/
|
|
266
352
|
public async work() {
|
|
267
|
-
const currentSlot = this.
|
|
353
|
+
const currentSlot = await this.getCurrentSlot();
|
|
268
354
|
try {
|
|
269
|
-
//
|
|
270
|
-
// Note we never `start` the blockstream, so it loops at the same pace as we do.
|
|
271
|
-
await this.blockStream.sync();
|
|
272
|
-
|
|
273
|
-
// 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).
|
|
274
356
|
const targetSlot = await this.isReadyToProcess(currentSlot);
|
|
275
|
-
|
|
276
|
-
// And process it if we are.
|
|
277
357
|
if (targetSlot !== false) {
|
|
278
358
|
await this.processSlot(targetSlot);
|
|
279
359
|
}
|
|
360
|
+
|
|
361
|
+
// End-of-epoch evaluation (lag = sentinelEpochEndBufferSlots beyond the epoch's last slot).
|
|
362
|
+
await this.processEpochEnds(currentSlot);
|
|
280
363
|
} catch (err) {
|
|
281
364
|
this.logger.error(`Failed to process slot ${currentSlot}`, err);
|
|
282
365
|
}
|
|
283
366
|
}
|
|
284
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
|
+
|
|
285
409
|
/**
|
|
286
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.
|
|
287
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.
|
|
@@ -315,7 +439,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
315
439
|
return false;
|
|
316
440
|
}
|
|
317
441
|
|
|
318
|
-
const archiverLastBlockHash = await this.
|
|
442
|
+
const archiverLastBlockHash = await this.archiver.getL2Tips().then(tip => tip.proposed.hash);
|
|
319
443
|
const p2pLastBlockHash = await this.p2p.getL2Tips().then(tips => tips.proposed.hash);
|
|
320
444
|
const isP2pSynced = archiverLastBlockHash === p2pLastBlockHash;
|
|
321
445
|
if (!isP2pSynced) {
|
|
@@ -350,49 +474,69 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
350
474
|
this.lastProcessedSlot = slot;
|
|
351
475
|
}
|
|
352
476
|
|
|
353
|
-
/**
|
|
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
|
+
*/
|
|
354
494
|
protected async getSlotActivity(slot: SlotNumber, epoch: EpochNumber, proposer: EthAddress, committee: EthAddress[]) {
|
|
355
495
|
this.logger.debug(`Computing stats for slot ${slot} at epoch ${epoch}`, { slot, epoch, proposer, committee });
|
|
356
496
|
|
|
357
|
-
//
|
|
358
|
-
|
|
359
|
-
//
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
// (contains the ones synced from mined checkpoints, which we may have missed from p2p).
|
|
363
|
-
const checkpoint = this.slotNumberToCheckpoint.get(slot);
|
|
364
|
-
const p2pAttested = await this.p2p.getCheckpointAttestationsForSlot(slot, checkpoint?.archive);
|
|
365
|
-
// 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);
|
|
366
502
|
const p2pAttestors = p2pAttested.map(a => a.getSender()).filter((s): s is EthAddress => s !== undefined);
|
|
367
503
|
const attestors = new Set(
|
|
368
504
|
[...p2pAttestors.map(a => a.toString()), ...(checkpoint?.attestors.map(a => a.toString()) ?? [])].filter(
|
|
369
|
-
addr => proposer.toString() !== addr,
|
|
505
|
+
addr => proposer.toString() !== addr,
|
|
370
506
|
),
|
|
371
507
|
);
|
|
372
508
|
|
|
373
|
-
//
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
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';
|
|
380
518
|
if (checkpoint) {
|
|
381
519
|
status = 'checkpoint-mined';
|
|
382
|
-
} else if (
|
|
383
|
-
status = 'checkpoint-
|
|
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';
|
|
384
526
|
} else {
|
|
385
|
-
// No
|
|
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".
|
|
386
529
|
const hasBlockProposals = await this.p2p.hasBlockProposalsForSlot(slot);
|
|
387
530
|
status = hasBlockProposals ? 'checkpoint-missed' : 'blocks-missed';
|
|
388
531
|
}
|
|
389
532
|
this.logger.debug(`Checkpoint status for slot ${slot}: ${status}`, { ...checkpoint, slot });
|
|
390
533
|
|
|
391
|
-
//
|
|
534
|
+
// Missing-attestor faults only apply when we have positive evidence the proposal was valid.
|
|
535
|
+
const attestorsExpected = status === 'checkpoint-mined' || status === 'checkpoint-valid';
|
|
392
536
|
const missedAttestors = new Set(
|
|
393
|
-
|
|
394
|
-
?
|
|
395
|
-
:
|
|
537
|
+
attestorsExpected
|
|
538
|
+
? committee.filter(v => !attestors.has(v.toString()) && !proposer.equals(v)).map(v => v.toString())
|
|
539
|
+
: [],
|
|
396
540
|
);
|
|
397
541
|
|
|
398
542
|
this.logger.debug(`Retrieved ${attestors.size} attestors out of ${committee.length} for slot ${slot}`, {
|
|
@@ -436,7 +580,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
436
580
|
? fromEntries(await Promise.all(validators.map(async v => [v.toString(), await this.store.getHistory(v)])))
|
|
437
581
|
: await this.store.getHistories();
|
|
438
582
|
|
|
439
|
-
const slotNow = this.
|
|
583
|
+
const slotNow = await this.getCurrentSlot();
|
|
440
584
|
fromSlot ??= SlotNumber(Math.max((this.lastProcessedSlot ?? slotNow) - this.store.getHistoryLength(), 0));
|
|
441
585
|
toSlot ??= this.lastProcessedSlot ?? slotNow;
|
|
442
586
|
|
|
@@ -464,7 +608,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
464
608
|
return undefined;
|
|
465
609
|
}
|
|
466
610
|
|
|
467
|
-
const slotNow = this.
|
|
611
|
+
const slotNow = await this.getCurrentSlot();
|
|
468
612
|
const effectiveFromSlot =
|
|
469
613
|
fromSlot ?? SlotNumber(Math.max((this.lastProcessedSlot ?? slotNow) - this.store.getHistoryLength(), 0));
|
|
470
614
|
const effectiveToSlot = toSlot ?? this.lastProcessedSlot ?? slotNow;
|
|
@@ -486,7 +630,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
486
630
|
|
|
487
631
|
return {
|
|
488
632
|
validator,
|
|
489
|
-
|
|
633
|
+
allTimeEpochPerformance: await this.store.getEpochPerformance(validatorAddress),
|
|
490
634
|
lastProcessedSlot: this.lastProcessedSlot,
|
|
491
635
|
initialSlot: this.initialSlot,
|
|
492
636
|
slotWindow: this.store.getHistoryLength(),
|
|
@@ -501,16 +645,19 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
501
645
|
): ValidatorStats {
|
|
502
646
|
let history = fromSlot ? allHistory.filter(h => BigInt(h.slot) >= fromSlot) : allHistory;
|
|
503
647
|
history = toSlot ? history.filter(h => BigInt(h.slot) <= toSlot) : history;
|
|
504
|
-
const lastProposal = history
|
|
505
|
-
.filter(h => h.status === 'checkpoint-proposed' || h.status === 'checkpoint-mined')
|
|
506
|
-
.at(-1);
|
|
648
|
+
const lastProposal = history.filter(h => h.status === 'checkpoint-valid' || h.status === 'checkpoint-mined').at(-1);
|
|
507
649
|
const lastAttestation = history.filter(h => h.status === 'attestation-sent').at(-1);
|
|
508
650
|
return {
|
|
509
651
|
address: EthAddress.fromString(address),
|
|
510
652
|
lastProposal: this.computeFromSlot(lastProposal?.slot),
|
|
511
653
|
lastAttestation: this.computeFromSlot(lastAttestation?.slot),
|
|
512
654
|
totalSlots: history.length,
|
|
513
|
-
missedProposals: this.computeMissed(history, 'proposer', [
|
|
655
|
+
missedProposals: this.computeMissed(history, 'proposer', [
|
|
656
|
+
'checkpoint-missed',
|
|
657
|
+
'blocks-missed',
|
|
658
|
+
'checkpoint-invalid',
|
|
659
|
+
'checkpoint-unvalidated',
|
|
660
|
+
]),
|
|
514
661
|
missedAttestations: this.computeMissed(history, 'attestation', ['attestation-missed']),
|
|
515
662
|
history,
|
|
516
663
|
};
|