@aztec/aztec-node 0.0.1-commit.a072138 → 0.0.1-commit.a4600f49
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 +23 -8
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +26 -8
- 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 +143 -135
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +497 -730
- 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 +12 -5
- package/dest/sentinel/sentinel.d.ts +146 -22
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +266 -118
- package/dest/sentinel/store.d.ts +8 -8
- package/dest/sentinel/store.d.ts.map +1 -1
- package/dest/sentinel/store.js +33 -21
- package/dest/test/index.d.ts +3 -3
- package/dest/test/index.d.ts.map +1 -1
- package/package.json +28 -25
- package/src/aztec-node/block_response_helpers.ts +161 -0
- package/src/aztec-node/config.ts +55 -16
- 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 +644 -939
- 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 +22 -7
- package/src/sentinel/sentinel.ts +316 -136
- package/src/sentinel/store.ts +35 -27
- 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,38 +31,126 @@ 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
|
|
|
39
|
-
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 {
|
|
40
126
|
protected runningPromise: RunningPromise;
|
|
41
|
-
protected blockStream!: L2BlockStream;
|
|
42
|
-
protected l2TipsStore: L2TipsStore;
|
|
43
127
|
|
|
44
128
|
protected initialSlot: SlotNumber | undefined;
|
|
45
129
|
protected lastProcessedSlot: SlotNumber | undefined;
|
|
46
|
-
|
|
47
|
-
protected
|
|
48
|
-
SlotNumber,
|
|
49
|
-
{ checkpointNumber: CheckpointNumber; archive: string; attestors: EthAddress[] }
|
|
50
|
-
> = new Map();
|
|
130
|
+
/** Largest epoch number for which the end-of-epoch aggregator has run. */
|
|
131
|
+
protected lastEvaluatedEpoch: EpochNumber | undefined;
|
|
51
132
|
|
|
52
133
|
constructor(
|
|
53
134
|
protected epochCache: EpochCache,
|
|
54
135
|
protected archiver: L2BlockSource,
|
|
55
136
|
protected p2p: P2PClient,
|
|
56
137
|
protected store: SentinelStore,
|
|
57
|
-
protected
|
|
58
|
-
|
|
59
|
-
'slashInactivityTargetPercentage' | 'slashInactivityPenalty' | 'slashInactivityConsecutiveEpochThreshold'
|
|
60
|
-
>,
|
|
138
|
+
protected reexecutionTracker: CheckpointReexecutionTracker,
|
|
139
|
+
protected config: SentinelRuntimeConfig,
|
|
61
140
|
protected logger = createLogger('node:sentinel'),
|
|
62
141
|
) {
|
|
63
142
|
super();
|
|
64
|
-
this.l2TipsStore = new L2TipsMemoryStore();
|
|
65
143
|
const interval = (epochCache.getL1Constants().ethereumSlotDuration * 1000) / 4;
|
|
66
144
|
this.runningPromise = new RunningPromise(this.work.bind(this), logger, interval);
|
|
67
145
|
}
|
|
68
146
|
|
|
147
|
+
private getSignatureContext(): CoordinationSignatureContext {
|
|
148
|
+
return {
|
|
149
|
+
chainId: this.config.l1ChainId,
|
|
150
|
+
rollupAddress: this.config.rollupAddress,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
69
154
|
public updateConfig(config: Partial<SlasherConfig>) {
|
|
70
155
|
this.config = { ...this.config, ...config };
|
|
71
156
|
}
|
|
@@ -75,79 +160,87 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
75
160
|
this.runningPromise.start();
|
|
76
161
|
}
|
|
77
162
|
|
|
78
|
-
/**
|
|
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
|
+
*/
|
|
79
169
|
protected async init() {
|
|
80
|
-
this.initialSlot = this.
|
|
81
|
-
|
|
82
|
-
this.logger.info(`Starting validator sentinel with initial slot ${this.initialSlot} and block ${startingBlock}`);
|
|
83
|
-
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}`);
|
|
84
172
|
}
|
|
85
173
|
|
|
86
|
-
|
|
87
|
-
|
|
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();
|
|
88
183
|
}
|
|
89
184
|
|
|
90
|
-
public
|
|
91
|
-
|
|
92
|
-
if (event.type === 'chain-checkpointed') {
|
|
93
|
-
this.handleCheckpoint(event);
|
|
94
|
-
} else if (event.type === 'chain-proven') {
|
|
95
|
-
await this.handleChainProven(event);
|
|
96
|
-
}
|
|
185
|
+
public stop() {
|
|
186
|
+
return this.runningPromise.stop();
|
|
97
187
|
}
|
|
98
188
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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;
|
|
102
208
|
}
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
209
|
+
const signatureContext = this.getSignatureContext();
|
|
210
|
+
const proposalPayloadHash = CheckpointProposalHash.fromBuffer(
|
|
211
|
+
ConsensusPayload.fromCheckpoint(checkpoint.checkpoint, signatureContext).getPayloadHash(),
|
|
212
|
+
);
|
|
213
|
+
return {
|
|
107
214
|
checkpointNumber: checkpoint.checkpoint.number,
|
|
108
215
|
archive: checkpoint.checkpoint.archive.root.toString(),
|
|
109
|
-
|
|
216
|
+
proposalPayloadHash,
|
|
217
|
+
attestors: getAttestationInfoFromPublishedCheckpoint(checkpoint, signatureContext)
|
|
110
218
|
.filter(a => a.status === 'recovered-from-signature')
|
|
111
219
|
.map(a => a.address!),
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Prune the archive map to only keep at most N entries
|
|
115
|
-
const historyLength = this.store.getHistoryLength();
|
|
116
|
-
if (this.slotNumberToCheckpoint.size > historyLength) {
|
|
117
|
-
const toDelete = Array.from(this.slotNumberToCheckpoint.keys())
|
|
118
|
-
.sort((a, b) => Number(a - b))
|
|
119
|
-
.slice(0, this.slotNumberToCheckpoint.size - historyLength);
|
|
120
|
-
for (const key of toDelete) {
|
|
121
|
-
this.slotNumberToCheckpoint.delete(key);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
220
|
+
};
|
|
124
221
|
}
|
|
125
222
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// TODO(palla/slash): We should only be computing proven performance if this is
|
|
138
|
-
// a full proof epoch and not a partial one, otherwise we'll end up with skewed stats.
|
|
139
|
-
const epoch = getEpochAtSlot(block.header.getSlot(), this.epochCache.getL1Constants());
|
|
140
|
-
this.logger.debug(`Computing proven performance for epoch ${epoch}`);
|
|
141
|
-
const performance = await this.computeProvenPerformance(epoch);
|
|
142
|
-
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);
|
|
143
232
|
|
|
144
|
-
await this.store.
|
|
145
|
-
await this.
|
|
233
|
+
await this.store.updateEpochPerformance(epoch, performance);
|
|
234
|
+
await this.handleEpochPerformance(epoch, performance);
|
|
146
235
|
}
|
|
147
236
|
|
|
148
|
-
protected async
|
|
237
|
+
protected async computeEpochPerformance(epoch: EpochNumber): Promise<ValidatorsEpochPerformance> {
|
|
149
238
|
const [fromSlot, toSlot] = getSlotRangeForEpoch(epoch, this.epochCache.getL1Constants());
|
|
150
|
-
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
|
+
}
|
|
151
244
|
if (!committee) {
|
|
152
245
|
this.logger.trace(`No committee found for slot ${fromSlot}`);
|
|
153
246
|
return {};
|
|
@@ -187,8 +280,8 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
187
280
|
return true;
|
|
188
281
|
}
|
|
189
282
|
|
|
190
|
-
// Get all historical performance for this validator
|
|
191
|
-
const allPerformance = await this.store.
|
|
283
|
+
// Get all historical per-epoch performance for this validator
|
|
284
|
+
const allPerformance = await this.store.getEpochPerformance(validator);
|
|
192
285
|
|
|
193
286
|
// Sort by epoch descending to get most recent first, keep only epochs strictly before the current one, and get the first N
|
|
194
287
|
const pastEpochs = allPerformance.sort((a, b) => Number(b.epoch - a.epoch)).filter(p => p.epoch < currentEpoch);
|
|
@@ -204,16 +297,12 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
204
297
|
// Check that we have at least requiredConsecutiveEpochs and that all of them are above the inactivity threshold
|
|
205
298
|
return pastEpochs
|
|
206
299
|
.slice(0, requiredConsecutiveEpochs)
|
|
207
|
-
.every(p => p.missed / p.total >= this.config.slashInactivityTargetPercentage);
|
|
300
|
+
.every(p => (p.total === 0 ? false : p.missed / p.total >= this.config.slashInactivityTargetPercentage));
|
|
208
301
|
}
|
|
209
302
|
|
|
210
|
-
protected async
|
|
211
|
-
if (this.config.slashInactivityPenalty === 0n) {
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
|
|
303
|
+
protected async handleEpochPerformance(epoch: EpochNumber, performance: ValidatorsEpochPerformance) {
|
|
215
304
|
const inactiveValidators = getEntries(performance)
|
|
216
|
-
.filter(([_, { missed, total }]) => missed / total >= this.config.slashInactivityTargetPercentage)
|
|
305
|
+
.filter(([_, { missed, total }]) => total > 0 && missed / total >= this.config.slashInactivityTargetPercentage)
|
|
217
306
|
.map(([address]) => address);
|
|
218
307
|
|
|
219
308
|
this.logger.debug(`Found ${inactiveValidators.length} inactive validators in epoch ${epoch}`, {
|
|
@@ -235,9 +324,17 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
235
324
|
}));
|
|
236
325
|
|
|
237
326
|
if (criminals.length > 0) {
|
|
238
|
-
this.logger.
|
|
239
|
-
`Identified ${criminals.length}
|
|
240
|
-
{
|
|
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
|
+
},
|
|
241
338
|
);
|
|
242
339
|
this.emit(WANT_TO_SLASH_EVENT, args);
|
|
243
340
|
}
|
|
@@ -247,26 +344,68 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
247
344
|
* Process data for two L2 slots ago.
|
|
248
345
|
* Note that we do not process historical data, since we rely on p2p data for processing,
|
|
249
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.
|
|
250
351
|
*/
|
|
251
352
|
public async work() {
|
|
252
|
-
const
|
|
353
|
+
const currentSlot = await this.getCurrentSlot();
|
|
253
354
|
try {
|
|
254
|
-
//
|
|
255
|
-
// Note we never `start` the blockstream, so it loops at the same pace as we do.
|
|
256
|
-
await this.blockStream.sync();
|
|
257
|
-
|
|
258
|
-
// 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).
|
|
259
356
|
const targetSlot = await this.isReadyToProcess(currentSlot);
|
|
260
|
-
|
|
261
|
-
// And process it if we are.
|
|
262
357
|
if (targetSlot !== false) {
|
|
263
358
|
await this.processSlot(targetSlot);
|
|
264
359
|
}
|
|
360
|
+
|
|
361
|
+
// End-of-epoch evaluation (lag = sentinelEpochEndBufferSlots beyond the epoch's last slot).
|
|
362
|
+
await this.processEpochEnds(currentSlot);
|
|
265
363
|
} catch (err) {
|
|
266
364
|
this.logger.error(`Failed to process slot ${currentSlot}`, err);
|
|
267
365
|
}
|
|
268
366
|
}
|
|
269
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
|
+
|
|
270
409
|
/**
|
|
271
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.
|
|
272
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.
|
|
@@ -294,13 +433,13 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
294
433
|
return false;
|
|
295
434
|
}
|
|
296
435
|
|
|
297
|
-
const
|
|
298
|
-
if (
|
|
299
|
-
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 });
|
|
300
439
|
return false;
|
|
301
440
|
}
|
|
302
441
|
|
|
303
|
-
const archiverLastBlockHash = await this.
|
|
442
|
+
const archiverLastBlockHash = await this.archiver.getL2Tips().then(tip => tip.proposed.hash);
|
|
304
443
|
const p2pLastBlockHash = await this.p2p.getL2Tips().then(tips => tips.proposed.hash);
|
|
305
444
|
const isP2pSynced = archiverLastBlockHash === p2pLastBlockHash;
|
|
306
445
|
if (!isP2pSynced) {
|
|
@@ -316,7 +455,12 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
316
455
|
* and updates overall stats.
|
|
317
456
|
*/
|
|
318
457
|
protected async processSlot(slot: SlotNumber) {
|
|
319
|
-
const { epoch, seed, committee } = await this.epochCache.getCommittee(slot);
|
|
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
|
+
}
|
|
320
464
|
if (!committee || committee.length === 0) {
|
|
321
465
|
this.logger.trace(`No committee found for slot ${slot} at epoch ${epoch}`);
|
|
322
466
|
this.lastProcessedSlot = slot;
|
|
@@ -330,46 +474,75 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
330
474
|
this.lastProcessedSlot = slot;
|
|
331
475
|
}
|
|
332
476
|
|
|
333
|
-
/**
|
|
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
|
+
*/
|
|
334
494
|
protected async getSlotActivity(slot: SlotNumber, epoch: EpochNumber, proposer: EthAddress, committee: EthAddress[]) {
|
|
335
495
|
this.logger.debug(`Computing stats for slot ${slot} at epoch ${epoch}`, { slot, epoch, proposer, committee });
|
|
336
496
|
|
|
337
|
-
//
|
|
338
|
-
|
|
339
|
-
//
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
// (contains the ones synced from mined blocks, which we may have missed from p2p).
|
|
343
|
-
const block = this.slotNumberToCheckpoint.get(slot);
|
|
344
|
-
const p2pAttested = await this.p2p.getCheckpointAttestationsForSlot(slot, block?.archive);
|
|
345
|
-
// 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);
|
|
346
502
|
const p2pAttestors = p2pAttested.map(a => a.getSender()).filter((s): s is EthAddress => s !== undefined);
|
|
347
503
|
const attestors = new Set(
|
|
348
|
-
[...p2pAttestors.map(a => a.toString()), ...(
|
|
349
|
-
addr => proposer.toString() !== addr,
|
|
504
|
+
[...p2pAttestors.map(a => a.toString()), ...(checkpoint?.attestors.map(a => a.toString()) ?? [])].filter(
|
|
505
|
+
addr => proposer.toString() !== addr,
|
|
350
506
|
),
|
|
351
507
|
);
|
|
352
508
|
|
|
353
|
-
//
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
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 });
|
|
361
533
|
|
|
362
|
-
//
|
|
534
|
+
// Missing-attestor faults only apply when we have positive evidence the proposal was valid.
|
|
535
|
+
const attestorsExpected = status === 'checkpoint-mined' || status === 'checkpoint-valid';
|
|
363
536
|
const missedAttestors = new Set(
|
|
364
|
-
|
|
365
|
-
?
|
|
366
|
-
:
|
|
537
|
+
attestorsExpected
|
|
538
|
+
? committee.filter(v => !attestors.has(v.toString()) && !proposer.equals(v)).map(v => v.toString())
|
|
539
|
+
: [],
|
|
367
540
|
);
|
|
368
541
|
|
|
369
542
|
this.logger.debug(`Retrieved ${attestors.size} attestors out of ${committee.length} for slot ${slot}`, {
|
|
370
|
-
|
|
543
|
+
status,
|
|
371
544
|
proposer: proposer.toString(),
|
|
372
|
-
...
|
|
545
|
+
...checkpoint,
|
|
373
546
|
slot,
|
|
374
547
|
attestors: [...attestors],
|
|
375
548
|
missedAttestors: [...missedAttestors],
|
|
@@ -379,7 +552,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
379
552
|
// Compute the status for each validator in the committee
|
|
380
553
|
const statusFor = (who: `0x${string}`): ValidatorStatusInSlot | undefined => {
|
|
381
554
|
if (who === proposer.toString()) {
|
|
382
|
-
return
|
|
555
|
+
return status;
|
|
383
556
|
} else if (attestors.has(who)) {
|
|
384
557
|
return 'attestation-sent';
|
|
385
558
|
} else if (missedAttestors.has(who)) {
|
|
@@ -407,7 +580,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
407
580
|
? fromEntries(await Promise.all(validators.map(async v => [v.toString(), await this.store.getHistory(v)])))
|
|
408
581
|
: await this.store.getHistories();
|
|
409
582
|
|
|
410
|
-
const slotNow = this.
|
|
583
|
+
const slotNow = await this.getCurrentSlot();
|
|
411
584
|
fromSlot ??= SlotNumber(Math.max((this.lastProcessedSlot ?? slotNow) - this.store.getHistoryLength(), 0));
|
|
412
585
|
toSlot ??= this.lastProcessedSlot ?? slotNow;
|
|
413
586
|
|
|
@@ -435,7 +608,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
435
608
|
return undefined;
|
|
436
609
|
}
|
|
437
610
|
|
|
438
|
-
const slotNow = this.
|
|
611
|
+
const slotNow = await this.getCurrentSlot();
|
|
439
612
|
const effectiveFromSlot =
|
|
440
613
|
fromSlot ?? SlotNumber(Math.max((this.lastProcessedSlot ?? slotNow) - this.store.getHistoryLength(), 0));
|
|
441
614
|
const effectiveToSlot = toSlot ?? this.lastProcessedSlot ?? slotNow;
|
|
@@ -457,7 +630,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
457
630
|
|
|
458
631
|
return {
|
|
459
632
|
validator,
|
|
460
|
-
|
|
633
|
+
allTimeEpochPerformance: await this.store.getEpochPerformance(validatorAddress),
|
|
461
634
|
lastProcessedSlot: this.lastProcessedSlot,
|
|
462
635
|
initialSlot: this.initialSlot,
|
|
463
636
|
slotWindow: this.store.getHistoryLength(),
|
|
@@ -472,14 +645,19 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
472
645
|
): ValidatorStats {
|
|
473
646
|
let history = fromSlot ? allHistory.filter(h => BigInt(h.slot) >= fromSlot) : allHistory;
|
|
474
647
|
history = toSlot ? history.filter(h => BigInt(h.slot) <= toSlot) : history;
|
|
475
|
-
const lastProposal = history.filter(h => h.status === '
|
|
648
|
+
const lastProposal = history.filter(h => h.status === 'checkpoint-valid' || h.status === 'checkpoint-mined').at(-1);
|
|
476
649
|
const lastAttestation = history.filter(h => h.status === 'attestation-sent').at(-1);
|
|
477
650
|
return {
|
|
478
651
|
address: EthAddress.fromString(address),
|
|
479
652
|
lastProposal: this.computeFromSlot(lastProposal?.slot),
|
|
480
653
|
lastAttestation: this.computeFromSlot(lastAttestation?.slot),
|
|
481
654
|
totalSlots: history.length,
|
|
482
|
-
missedProposals: this.computeMissed(history, '
|
|
655
|
+
missedProposals: this.computeMissed(history, 'proposer', [
|
|
656
|
+
'checkpoint-missed',
|
|
657
|
+
'blocks-missed',
|
|
658
|
+
'checkpoint-invalid',
|
|
659
|
+
'checkpoint-unvalidated',
|
|
660
|
+
]),
|
|
483
661
|
missedAttestations: this.computeMissed(history, 'attestation', ['attestation-missed']),
|
|
484
662
|
history,
|
|
485
663
|
};
|
|
@@ -487,10 +665,12 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
487
665
|
|
|
488
666
|
protected computeMissed(
|
|
489
667
|
history: ValidatorStatusHistory,
|
|
490
|
-
|
|
668
|
+
computeOverCategory: ValidatorStatusType | undefined,
|
|
491
669
|
filter: ValidatorStatusInSlot[],
|
|
492
670
|
) {
|
|
493
|
-
const relevantHistory = history.filter(
|
|
671
|
+
const relevantHistory = history.filter(
|
|
672
|
+
h => !computeOverCategory || statusToCategory(h.status) === computeOverCategory,
|
|
673
|
+
);
|
|
494
674
|
const filteredHistory = relevantHistory.filter(h => filter.includes(h.status));
|
|
495
675
|
return {
|
|
496
676
|
currentStreak: countWhile([...relevantHistory].reverse(), h => filter.includes(h.status)),
|