@aztec/slasher 0.0.1-commit.993d52e → 0.0.1-commit.9a89641
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/README.md +83 -79
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +28 -28
- package/dest/factory/create_facade.d.ts +7 -4
- package/dest/factory/create_facade.d.ts.map +1 -1
- package/dest/factory/create_facade.js +5 -2
- package/dest/factory/create_implementation.d.ts +6 -7
- package/dest/factory/create_implementation.d.ts.map +1 -1
- package/dest/factory/create_implementation.js +7 -59
- package/dest/factory/get_settings.d.ts +4 -4
- package/dest/factory/get_settings.d.ts.map +1 -1
- package/dest/factory/get_settings.js +3 -3
- package/dest/factory/index.d.ts +2 -2
- package/dest/factory/index.d.ts.map +1 -1
- package/dest/factory/index.js +1 -1
- package/dest/generated/slasher-defaults.d.ts +5 -5
- package/dest/generated/slasher-defaults.js +5 -5
- package/dest/index.d.ts +6 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +5 -3
- package/dest/metrics.d.ts +23 -0
- package/dest/metrics.d.ts.map +1 -0
- package/dest/metrics.js +38 -0
- package/dest/null_slasher_client.d.ts +3 -4
- package/dest/null_slasher_client.d.ts.map +1 -1
- package/dest/null_slasher_client.js +1 -4
- package/dest/own_validator_slash_monitor.d.ts +66 -0
- package/dest/own_validator_slash_monitor.d.ts.map +1 -0
- package/dest/own_validator_slash_monitor.js +163 -0
- package/dest/slash_offenses_collector.d.ts +6 -8
- package/dest/slash_offenses_collector.d.ts.map +1 -1
- package/dest/slash_offenses_collector.js +48 -28
- package/dest/slasher_client.d.ts +118 -0
- package/dest/slasher_client.d.ts.map +1 -0
- package/dest/{tally_slasher_client.js → slasher_client.js} +64 -41
- package/dest/slasher_client_facade.d.ts +7 -8
- package/dest/slasher_client_facade.d.ts.map +1 -1
- package/dest/slasher_client_facade.js +6 -9
- package/dest/slasher_client_interface.d.ts +7 -21
- package/dest/slasher_client_interface.d.ts.map +1 -1
- package/dest/slasher_client_interface.js +1 -4
- package/dest/stores/offenses_store.d.ts +12 -12
- package/dest/stores/offenses_store.d.ts.map +1 -1
- package/dest/stores/offenses_store.js +61 -38
- package/dest/watcher.d.ts +8 -1
- package/dest/watcher.d.ts.map +1 -1
- package/dest/watcher.js +1 -0
- package/dest/watchers/attestations_block_watcher.d.ts +26 -13
- package/dest/watchers/attestations_block_watcher.d.ts.map +1 -1
- package/dest/watchers/attestations_block_watcher.js +76 -61
- package/dest/watchers/attested_invalid_proposal_watcher.d.ts +42 -0
- package/dest/watchers/attested_invalid_proposal_watcher.d.ts.map +1 -0
- package/dest/watchers/attested_invalid_proposal_watcher.js +117 -0
- package/dest/watchers/broadcasted_invalid_checkpoint_proposal_watcher.d.ts +38 -0
- package/dest/watchers/broadcasted_invalid_checkpoint_proposal_watcher.d.ts.map +1 -0
- package/dest/watchers/broadcasted_invalid_checkpoint_proposal_watcher.js +138 -0
- package/dest/watchers/checkpoint_equivocation_watcher.d.ts +30 -0
- package/dest/watchers/checkpoint_equivocation_watcher.d.ts.map +1 -0
- package/dest/watchers/checkpoint_equivocation_watcher.js +69 -0
- package/dest/watchers/data_withholding_watcher.d.ts +63 -0
- package/dest/watchers/data_withholding_watcher.d.ts.map +1 -0
- package/dest/watchers/data_withholding_watcher.js +193 -0
- package/package.json +10 -10
- package/src/config.ts +33 -28
- package/src/factory/create_facade.ts +7 -4
- package/src/factory/create_implementation.ts +17 -118
- package/src/factory/get_settings.ts +8 -8
- package/src/factory/index.ts +1 -1
- package/src/generated/slasher-defaults.ts +5 -5
- package/src/index.ts +5 -3
- package/src/metrics.ts +59 -0
- package/src/null_slasher_client.ts +2 -6
- package/src/own_validator_slash_monitor.ts +184 -0
- package/src/slash_offenses_collector.ts +62 -29
- package/src/{tally_slasher_client.ts → slasher_client.ts} +85 -50
- package/src/slasher_client_facade.ts +7 -11
- package/src/slasher_client_interface.ts +6 -21
- package/src/stores/offenses_store.ts +73 -47
- package/src/watcher.ts +8 -0
- package/src/watchers/attestations_block_watcher.ts +88 -82
- package/src/watchers/attested_invalid_proposal_watcher.ts +168 -0
- package/src/watchers/broadcasted_invalid_checkpoint_proposal_watcher.ts +192 -0
- package/src/watchers/checkpoint_equivocation_watcher.ts +96 -0
- package/src/watchers/data_withholding_watcher.ts +225 -0
- package/dest/empire_slasher_client.d.ts +0 -190
- package/dest/empire_slasher_client.d.ts.map +0 -1
- package/dest/empire_slasher_client.js +0 -564
- package/dest/stores/payloads_store.d.ts +0 -29
- package/dest/stores/payloads_store.d.ts.map +0 -1
- package/dest/stores/payloads_store.js +0 -128
- package/dest/tally_slasher_client.d.ts +0 -125
- package/dest/tally_slasher_client.d.ts.map +0 -1
- package/dest/watchers/epoch_prune_watcher.d.ts +0 -39
- package/dest/watchers/epoch_prune_watcher.d.ts.map +0 -1
- package/dest/watchers/epoch_prune_watcher.js +0 -176
- package/src/empire_slasher_client.ts +0 -649
- package/src/stores/payloads_store.ts +0 -149
- package/src/watchers/epoch_prune_watcher.ts +0 -253
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EthAddress } from '@aztec/aztec.js/addresses';
|
|
2
2
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
3
|
-
import { RollupContract, SlasherContract,
|
|
3
|
+
import { RollupContract, SlasherContract, SlashingProposerContract } from '@aztec/ethereum/contracts';
|
|
4
4
|
import { maxBigint } from '@aztec/foundation/bigint';
|
|
5
5
|
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
6
6
|
import { compactArray, partition, times } from '@aztec/foundation/collection';
|
|
@@ -13,13 +13,16 @@ import {
|
|
|
13
13
|
OffenseType,
|
|
14
14
|
type ProposerSlashAction,
|
|
15
15
|
type ProposerSlashActionProvider,
|
|
16
|
-
type SlashPayloadRound,
|
|
17
16
|
getEpochsForRound,
|
|
17
|
+
getOffenseTypeName,
|
|
18
18
|
getSlashConsensusVotesFromOffenses,
|
|
19
19
|
} from '@aztec/stdlib/slashing';
|
|
20
|
+
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
20
21
|
|
|
21
22
|
import type { Hex } from 'viem';
|
|
22
23
|
|
|
24
|
+
import { SlasherMetrics } from './metrics.js';
|
|
25
|
+
import { OwnValidatorSlashMonitor } from './own_validator_slash_monitor.js';
|
|
23
26
|
import {
|
|
24
27
|
SlashOffensesCollector,
|
|
25
28
|
type SlashOffensesCollectorConfig,
|
|
@@ -30,8 +33,8 @@ import type { SlasherClientInterface } from './slasher_client_interface.js';
|
|
|
30
33
|
import type { SlasherOffensesStore } from './stores/offenses_store.js';
|
|
31
34
|
import type { Watcher } from './watcher.js';
|
|
32
35
|
|
|
33
|
-
/** Settings used in the
|
|
34
|
-
export type
|
|
36
|
+
/** Settings used in the slasher client, loaded from the L1 contracts during initialization */
|
|
37
|
+
export type SlasherSettings = Prettify<
|
|
35
38
|
SlashRoundMonitorSettings &
|
|
36
39
|
SlashOffensesCollectorSettings & {
|
|
37
40
|
slashingLifetimeInRounds: number;
|
|
@@ -45,11 +48,22 @@ export type TallySlasherSettings = Prettify<
|
|
|
45
48
|
}
|
|
46
49
|
>;
|
|
47
50
|
|
|
48
|
-
export type
|
|
49
|
-
Pick<
|
|
51
|
+
export type SlasherClientConfig = SlashOffensesCollectorConfig &
|
|
52
|
+
Pick<
|
|
53
|
+
SlasherConfig,
|
|
54
|
+
'slashValidatorsAlways' | 'slashValidatorsNever' | 'slashExecuteRoundsLookBack' | 'slashMaxPayloadSize'
|
|
55
|
+
>;
|
|
56
|
+
|
|
57
|
+
type AlwaysSlashOffense = {
|
|
58
|
+
validator: EthAddress;
|
|
59
|
+
amount: bigint;
|
|
60
|
+
offenseType: OffenseType.UNKNOWN;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
type SlashVoteOffense = Offense | AlwaysSlashOffense;
|
|
50
64
|
|
|
51
65
|
/**
|
|
52
|
-
* The
|
|
66
|
+
* The Slasher client is responsible for managing slashable offenses using
|
|
53
67
|
* the consensus-based slashing model where proposers vote on individual validator offenses.
|
|
54
68
|
*
|
|
55
69
|
* The client subscribes to several slash watchers that emit offenses and tracks them. When the slasher is the
|
|
@@ -73,43 +87,41 @@ export type TallySlasherClientConfig = SlashOffensesCollectorConfig &
|
|
|
73
87
|
* - Validators that reach the quorum threshold are slashed. A vote for slashing N units is also considered
|
|
74
88
|
* a vote for slashing N-1, N-2, ..., 1 units. The system slashes for the largest amount that reaches quorum.
|
|
75
89
|
* - The client monitors executable rounds and triggers execution when appropriate.
|
|
76
|
-
*
|
|
77
|
-
* Differences from Empire model
|
|
78
|
-
* - No fixed slash payloads - votes are for individual validator offenses encoded in bytes
|
|
79
|
-
* - The L1 contract determines which offenses reach quorum rather than nodes agreeing on a payload
|
|
80
|
-
* - Proposers vote directly on which validators to slash and by how much
|
|
81
|
-
* - Uses a slash offset to vote on validators from past rounds (e.g., round N votes on round N-2)
|
|
82
90
|
*/
|
|
83
|
-
export class
|
|
91
|
+
export class SlasherClient implements ProposerSlashActionProvider, SlasherClientInterface {
|
|
84
92
|
protected unwatchCallbacks: (() => void)[] = [];
|
|
85
93
|
protected roundMonitor: SlashRoundMonitor;
|
|
86
94
|
protected offensesCollector: SlashOffensesCollector;
|
|
95
|
+
protected readonly ownValidatorMonitor: OwnValidatorSlashMonitor;
|
|
87
96
|
|
|
88
97
|
constructor(
|
|
89
|
-
private config:
|
|
90
|
-
private settings:
|
|
91
|
-
private
|
|
98
|
+
private config: SlasherClientConfig,
|
|
99
|
+
private settings: SlasherSettings,
|
|
100
|
+
private slashingProposer: SlashingProposerContract,
|
|
92
101
|
private slasher: SlasherContract,
|
|
93
102
|
private rollup: RollupContract,
|
|
94
103
|
watchers: Watcher[],
|
|
95
104
|
private epochCache: EpochCache,
|
|
96
105
|
private dateProvider: DateProvider,
|
|
97
106
|
private offensesStore: SlasherOffensesStore,
|
|
107
|
+
private readonly ownValidators: EthAddress[] = [],
|
|
98
108
|
private log = createLogger('slasher:consensus'),
|
|
109
|
+
private readonly metrics = new SlasherMetrics(getTelemetryClient()),
|
|
99
110
|
) {
|
|
100
111
|
this.roundMonitor = new SlashRoundMonitor(settings, dateProvider);
|
|
101
112
|
this.offensesCollector = new SlashOffensesCollector(config, settings, watchers, offensesStore);
|
|
113
|
+
this.ownValidatorMonitor = new OwnValidatorSlashMonitor(slashingProposer, settings, ownValidators, this.metrics);
|
|
102
114
|
}
|
|
103
115
|
|
|
104
116
|
public async start() {
|
|
105
|
-
this.log.debug('Starting
|
|
117
|
+
this.log.debug('Starting slasher client...');
|
|
106
118
|
|
|
107
119
|
this.roundMonitor.start();
|
|
108
120
|
await this.offensesCollector.start();
|
|
109
121
|
|
|
110
122
|
// Listen for RoundExecuted events
|
|
111
123
|
this.unwatchCallbacks.push(
|
|
112
|
-
this.
|
|
124
|
+
this.slashingProposer.listenToRoundExecuted(
|
|
113
125
|
({ round, slashCount, l1BlockHash }) =>
|
|
114
126
|
void this.handleRoundExecuted(round, slashCount, l1BlockHash).catch(err =>
|
|
115
127
|
this.log.error('Error handling round executed', err),
|
|
@@ -120,24 +132,34 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
120
132
|
// Check for round changes
|
|
121
133
|
this.unwatchCallbacks.push(this.roundMonitor.listenToNewRound(round => this.handleNewRound(round)));
|
|
122
134
|
|
|
123
|
-
|
|
135
|
+
// Warn early when a slashing vote names one of our own validators. Skipped entirely when running none, so
|
|
136
|
+
// those nodes pay no extra L1 subscription.
|
|
137
|
+
if (this.ownValidators.length > 0) {
|
|
138
|
+
this.ownValidatorMonitor.start(this.roundMonitor.getCurrentRound().round);
|
|
139
|
+
this.unwatchCallbacks.push(
|
|
140
|
+
this.slashingProposer.listenToVoteCast(
|
|
141
|
+
({ round, voteIndex }) => void this.ownValidatorMonitor.handleVoteCast(round, voteIndex),
|
|
142
|
+
),
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
this.log.info(`Started slasher client`);
|
|
124
147
|
return Promise.resolve();
|
|
125
148
|
}
|
|
126
149
|
|
|
127
|
-
/**
|
|
128
|
-
* Stop the tally slasher client
|
|
129
|
-
*/
|
|
150
|
+
/** Stop the slasher client */
|
|
130
151
|
public async stop() {
|
|
131
|
-
this.log.debug('Stopping
|
|
152
|
+
this.log.debug('Stopping slasher client...');
|
|
132
153
|
|
|
133
154
|
for (const unwatchCallback of this.unwatchCallbacks) {
|
|
134
155
|
unwatchCallback();
|
|
135
156
|
}
|
|
136
157
|
|
|
137
158
|
this.roundMonitor.stop();
|
|
159
|
+
await this.ownValidatorMonitor.stop();
|
|
138
160
|
await this.offensesCollector.stop();
|
|
139
161
|
|
|
140
|
-
this.log.info('
|
|
162
|
+
this.log.info('Slasher client stopped');
|
|
141
163
|
}
|
|
142
164
|
|
|
143
165
|
/** Returns the current config */
|
|
@@ -152,14 +174,17 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
152
174
|
|
|
153
175
|
/** Triggered on a time basis when we enter a new slashing round. Clears expired offenses. */
|
|
154
176
|
protected async handleNewRound(round: bigint) {
|
|
155
|
-
this.log.info(`Starting new
|
|
177
|
+
this.log.info(`Starting new slashing round ${round}`);
|
|
178
|
+
this.ownValidatorMonitor.handleNewRound(round);
|
|
156
179
|
await this.offensesCollector.handleNewRound(round);
|
|
157
180
|
}
|
|
158
181
|
|
|
159
|
-
/** Called when we see a RoundExecuted event on the
|
|
182
|
+
/** Called when we see a RoundExecuted event on the SlashingProposer (just for logging and metrics). */
|
|
160
183
|
protected async handleRoundExecuted(round: bigint, slashCount: bigint, l1BlockHash: Hex) {
|
|
184
|
+
this.metrics.recordRoundExecuted();
|
|
161
185
|
const slashes = await this.rollup.getSlashEvents(l1BlockHash);
|
|
162
186
|
this.log.info(`Slashing round ${round} has been executed with ${slashCount} slashes`, { slashes });
|
|
187
|
+
this.ownValidatorMonitor.handleSlashes(round, slashes, l1BlockHash);
|
|
163
188
|
}
|
|
164
189
|
|
|
165
190
|
/**
|
|
@@ -237,7 +262,7 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
237
262
|
this.log.debug(`Testing if slashing round ${executableRound} is executable`, logData);
|
|
238
263
|
|
|
239
264
|
try {
|
|
240
|
-
const roundInfo = await this.
|
|
265
|
+
const roundInfo = await this.slashingProposer.getRound(executableRound);
|
|
241
266
|
logData = { ...logData, roundInfo };
|
|
242
267
|
if (roundInfo.isExecuted) {
|
|
243
268
|
this.log.verbose(`Round ${executableRound} has already been executed`, logData);
|
|
@@ -251,7 +276,7 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
251
276
|
}
|
|
252
277
|
|
|
253
278
|
// Check if round is ready to execute at the given slot
|
|
254
|
-
const isReadyToExecute = await this.
|
|
279
|
+
const isReadyToExecute = await this.slashingProposer.isRoundReadyToExecute(executableRound, slotNumber);
|
|
255
280
|
if (!isReadyToExecute) {
|
|
256
281
|
this.log.warn(
|
|
257
282
|
`Round ${executableRound} is not ready to execute at slot ${slotNumber} according to contract check`,
|
|
@@ -261,14 +286,14 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
261
286
|
}
|
|
262
287
|
|
|
263
288
|
// Check if the round yields any slashing at all
|
|
264
|
-
const { actions: slashActions, committees } = await this.
|
|
289
|
+
const { actions: slashActions, committees } = await this.slashingProposer.getTally(executableRound);
|
|
265
290
|
if (slashActions.length === 0) {
|
|
266
291
|
this.log.verbose(`Round ${executableRound} does not resolve in any slashing`, logData);
|
|
267
292
|
return undefined;
|
|
268
293
|
}
|
|
269
294
|
|
|
270
295
|
// Check if the slash payload is vetoed
|
|
271
|
-
const payload = await this.
|
|
296
|
+
const payload = await this.slashingProposer.getPayload(executableRound);
|
|
272
297
|
const isVetoed = await this.slasher.isPayloadVetoed(payload.address);
|
|
273
298
|
if (isVetoed) {
|
|
274
299
|
this.log.warn(`Round ${executableRound} payload is vetoed (skipping execution)`, {
|
|
@@ -315,7 +340,7 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
315
340
|
// Compute offenses to slash, by loading the offenses for this round, adding synthetic offenses
|
|
316
341
|
// for validators that should always be slashed, and removing the ones that should never be slashed.
|
|
317
342
|
const offensesForRound = await this.gatherOffensesForRound(currentRound);
|
|
318
|
-
const offensesFromAlwaysSlash = (this.config.slashValidatorsAlways ?? []).map(validator => ({
|
|
343
|
+
const offensesFromAlwaysSlash: AlwaysSlashOffense[] = (this.config.slashValidatorsAlways ?? []).map(validator => ({
|
|
319
344
|
validator,
|
|
320
345
|
amount: this.settings.slashingAmounts[2],
|
|
321
346
|
offenseType: OffenseType.UNKNOWN,
|
|
@@ -329,7 +354,7 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
329
354
|
slotNumber,
|
|
330
355
|
currentRound,
|
|
331
356
|
slashedRound,
|
|
332
|
-
|
|
357
|
+
offensesFromAlwaysSlash: offensesFromAlwaysSlash.map(getOffenseLogData),
|
|
333
358
|
slashValidatorsAlways: this.config.slashValidatorsAlways,
|
|
334
359
|
});
|
|
335
360
|
}
|
|
@@ -339,7 +364,7 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
339
364
|
slotNumber,
|
|
340
365
|
currentRound,
|
|
341
366
|
slashedRound,
|
|
342
|
-
offensesToForgive,
|
|
367
|
+
offensesToForgive: offensesToForgive.map(getOffenseLogData),
|
|
343
368
|
slashValidatorsNever: this.config.slashValidatorsNever,
|
|
344
369
|
});
|
|
345
370
|
}
|
|
@@ -349,32 +374,42 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
349
374
|
return undefined;
|
|
350
375
|
}
|
|
351
376
|
|
|
352
|
-
this.log.
|
|
377
|
+
this.log.debug(`Computing slash votes for ${offensesToSlash.length} offenses`, {
|
|
353
378
|
slotNumber,
|
|
354
379
|
currentRound,
|
|
355
380
|
slashedRound,
|
|
356
|
-
offensesToSlash,
|
|
381
|
+
offensesToSlash: offensesToSlash.map(getOffenseLogData),
|
|
357
382
|
});
|
|
358
383
|
|
|
359
384
|
const committees = await this.collectCommitteesActiveDuringRound(slashedRound);
|
|
360
385
|
const epochsForCommittees = getEpochsForRound(slashedRound, this.settings);
|
|
386
|
+
const { slashMaxPayloadSize } = this.config;
|
|
361
387
|
const votes = getSlashConsensusVotesFromOffenses(
|
|
362
388
|
offensesToSlash,
|
|
363
389
|
committees,
|
|
364
390
|
epochsForCommittees.map(e => BigInt(e)),
|
|
365
|
-
this.settings,
|
|
391
|
+
{ ...this.settings, maxSlashedValidators: slashMaxPayloadSize },
|
|
392
|
+
this.log,
|
|
366
393
|
);
|
|
367
394
|
if (votes.every(v => v === 0)) {
|
|
368
395
|
this.log.warn(`Computed votes for offenses are all zero. Skipping vote.`, {
|
|
369
396
|
slotNumber,
|
|
370
397
|
currentRound,
|
|
371
398
|
slashedRound,
|
|
372
|
-
offensesToSlash,
|
|
399
|
+
offensesToSlash: offensesToSlash.map(getOffenseLogData),
|
|
373
400
|
committees,
|
|
374
401
|
});
|
|
375
402
|
return undefined;
|
|
376
403
|
}
|
|
377
404
|
|
|
405
|
+
this.log.info(`Voting to slash ${offensesToSlash.length} offenses`, {
|
|
406
|
+
slotNumber,
|
|
407
|
+
slashedRound,
|
|
408
|
+
currentRound,
|
|
409
|
+
votes,
|
|
410
|
+
offensesToSlash: offensesToSlash.map(getOffenseLogData),
|
|
411
|
+
});
|
|
412
|
+
|
|
378
413
|
this.log.debug(`Computed votes for slashing ${offensesToSlash.length} offenses`, {
|
|
379
414
|
slashedRound,
|
|
380
415
|
currentRound,
|
|
@@ -400,17 +435,9 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
400
435
|
);
|
|
401
436
|
}
|
|
402
437
|
|
|
403
|
-
/**
|
|
404
|
-
* Get slash payloads is NOT SUPPORTED in tally model
|
|
405
|
-
* @throws Error indicating this operation is not supported
|
|
406
|
-
*/
|
|
407
|
-
public getSlashPayloads(): Promise<SlashPayloadRound[]> {
|
|
408
|
-
return Promise.reject(new Error('Tally slashing model does not support slash payloads'));
|
|
409
|
-
}
|
|
410
|
-
|
|
411
438
|
/**
|
|
412
439
|
* Gather offenses to be slashed on a given round.
|
|
413
|
-
*
|
|
440
|
+
* Round N slashes validators from round N - slashOffsetInRounds.
|
|
414
441
|
* @param round - The round to get offenses for, defaults to current round
|
|
415
442
|
* @returns Array of pending offenses for the round with offset applied
|
|
416
443
|
*/
|
|
@@ -423,9 +450,9 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
423
450
|
return await this.offensesStore.getOffensesForRound(targetRound);
|
|
424
451
|
}
|
|
425
452
|
|
|
426
|
-
/** Returns all
|
|
427
|
-
public
|
|
428
|
-
return this.offensesStore.
|
|
453
|
+
/** Returns all offenses stored */
|
|
454
|
+
public getOffenses(): Promise<Offense[]> {
|
|
455
|
+
return this.offensesStore.getOffenses();
|
|
429
456
|
}
|
|
430
457
|
|
|
431
458
|
/**
|
|
@@ -441,3 +468,11 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
441
468
|
return round - BigInt(this.settings.slashingOffsetInRounds);
|
|
442
469
|
}
|
|
443
470
|
}
|
|
471
|
+
|
|
472
|
+
function getOffenseLogData(offense: SlashVoteOffense) {
|
|
473
|
+
return {
|
|
474
|
+
...offense,
|
|
475
|
+
validator: offense.validator.toString(),
|
|
476
|
+
offenseType: getOffenseTypeName(offense.offenseType),
|
|
477
|
+
};
|
|
478
|
+
}
|
|
@@ -2,13 +2,13 @@ import { EpochCache } from '@aztec/epoch-cache';
|
|
|
2
2
|
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
3
3
|
import type { ViemClient } from '@aztec/ethereum/types';
|
|
4
4
|
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
5
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
6
|
import { createLogger } from '@aztec/foundation/log';
|
|
7
7
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
8
|
-
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
9
8
|
import { AztecLMDBStoreV2 } from '@aztec/kv-store/lmdb-v2';
|
|
10
9
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
11
|
-
import type {
|
|
10
|
+
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
11
|
+
import type { Offense, ProposerSlashAction } from '@aztec/stdlib/slashing';
|
|
12
12
|
|
|
13
13
|
import { createSlasherImplementation } from './factory/create_implementation.js';
|
|
14
14
|
import type { SlasherClientInterface } from './slasher_client_interface.js';
|
|
@@ -27,12 +27,12 @@ export class SlasherClientFacade implements SlasherClientInterface {
|
|
|
27
27
|
private config: SlasherConfig & DataStoreConfig & { ethereumSlotDuration: number },
|
|
28
28
|
private rollup: RollupContract,
|
|
29
29
|
private l1Client: ViemClient,
|
|
30
|
-
private slashFactoryAddress: EthAddress | undefined,
|
|
31
30
|
private watchers: Watcher[],
|
|
32
31
|
private epochCache: EpochCache,
|
|
33
32
|
private dateProvider: DateProvider,
|
|
34
33
|
private kvStore: AztecLMDBStoreV2,
|
|
35
34
|
private rollupRegisteredAtL2Slot: SlotNumber,
|
|
35
|
+
private ownValidators: EthAddress[] = [],
|
|
36
36
|
private logger = createLogger('slasher'),
|
|
37
37
|
) {}
|
|
38
38
|
|
|
@@ -63,16 +63,12 @@ export class SlasherClientFacade implements SlasherClientInterface {
|
|
|
63
63
|
this.watchers.forEach(watcher => watcher.updateConfig?.(config));
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
public getSlashPayloads(): Promise<SlashPayloadRound[]> {
|
|
67
|
-
return this.client?.getSlashPayloads() ?? Promise.reject(new Error('Slasher client not initialized'));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
66
|
public gatherOffensesForRound(round?: bigint): Promise<Offense[]> {
|
|
71
67
|
return this.client?.gatherOffensesForRound(round) ?? Promise.reject(new Error('Slasher client not initialized'));
|
|
72
68
|
}
|
|
73
69
|
|
|
74
|
-
public
|
|
75
|
-
return this.client?.
|
|
70
|
+
public getOffenses(): Promise<Offense[]> {
|
|
71
|
+
return this.client?.getOffenses() ?? Promise.reject(new Error('Slasher client not initialized'));
|
|
76
72
|
}
|
|
77
73
|
|
|
78
74
|
public getProposerActions(slotNumber: SlotNumber): Promise<ProposerSlashAction[]> {
|
|
@@ -84,12 +80,12 @@ export class SlasherClientFacade implements SlasherClientInterface {
|
|
|
84
80
|
this.config,
|
|
85
81
|
this.rollup,
|
|
86
82
|
this.l1Client,
|
|
87
|
-
this.slashFactoryAddress,
|
|
88
83
|
this.watchers,
|
|
89
84
|
this.epochCache,
|
|
90
85
|
this.dateProvider,
|
|
91
86
|
this.kvStore,
|
|
92
87
|
this.rollupRegisteredAtL2Slot,
|
|
88
|
+
this.ownValidators,
|
|
93
89
|
this.logger,
|
|
94
90
|
);
|
|
95
91
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
3
|
-
import type { Offense, ProposerSlashAction
|
|
3
|
+
import type { Offense, ProposerSlashAction } from '@aztec/stdlib/slashing';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Common interface for slasher clients used by the Aztec node.
|
|
7
|
-
* Both Empire and Consensus slasher clients implement this interface.
|
|
8
|
-
*/
|
|
5
|
+
/** Common interface for slasher clients used by the Aztec node. */
|
|
9
6
|
export interface SlasherClientInterface {
|
|
10
7
|
/** Start the slasher client */
|
|
11
8
|
start(): Promise<void>;
|
|
@@ -13,25 +10,13 @@ export interface SlasherClientInterface {
|
|
|
13
10
|
/** Stop the slasher client */
|
|
14
11
|
stop(): Promise<void>;
|
|
15
12
|
|
|
16
|
-
/**
|
|
17
|
-
* Get slash payloads for the Empire model.
|
|
18
|
-
* The Consensus model should throw an error when this is called.
|
|
19
|
-
*/
|
|
20
|
-
getSlashPayloads(): Promise<SlashPayloadRound[]>;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Gather offenses for a given round, defaults to current.
|
|
24
|
-
* Used by both Empire and Consensus models.
|
|
25
|
-
*/
|
|
13
|
+
/** Gather offenses for a given round, defaults to current. */
|
|
26
14
|
gatherOffensesForRound(round?: bigint): Promise<Offense[]>;
|
|
27
15
|
|
|
28
|
-
/** Returns all
|
|
29
|
-
|
|
16
|
+
/** Returns all offenses */
|
|
17
|
+
getOffenses(): Promise<Offense[]>;
|
|
30
18
|
|
|
31
|
-
/**
|
|
32
|
-
* Update the configuration.
|
|
33
|
-
* Used by both Empire and Consensus models.
|
|
34
|
-
*/
|
|
19
|
+
/** Update the configuration. */
|
|
35
20
|
updateConfig(config: Partial<SlasherConfig>): void;
|
|
36
21
|
|
|
37
22
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/aztec.js/log';
|
|
2
|
-
import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap
|
|
2
|
+
import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap } from '@aztec/kv-store';
|
|
3
3
|
import {
|
|
4
4
|
type Offense,
|
|
5
5
|
type OffenseIdentifier,
|
|
@@ -10,14 +10,15 @@ import {
|
|
|
10
10
|
|
|
11
11
|
export const SCHEMA_VERSION = 1;
|
|
12
12
|
|
|
13
|
+
type ClearOffensesFilter = Pick<Offense, 'offenseType' | 'epochOrSlot'> & {
|
|
14
|
+
validators?: Offense['validator'][];
|
|
15
|
+
};
|
|
16
|
+
|
|
13
17
|
export class SlasherOffensesStore {
|
|
14
18
|
/** Map from offense key to offense data */
|
|
15
19
|
private offenses: AztecAsyncMap<string, Buffer>;
|
|
16
20
|
|
|
17
|
-
/**
|
|
18
|
-
private offensesSlashed: AztecAsyncSet<string>;
|
|
19
|
-
|
|
20
|
-
/** Multimap from round to offense keys (only used for consensus based slashing) */
|
|
21
|
+
/** Multimap from round to offense keys */
|
|
21
22
|
private roundsOffenses: AztecAsyncMultiMap<string, string>;
|
|
22
23
|
|
|
23
24
|
private log = createLogger('slasher:store:offenses');
|
|
@@ -32,18 +33,13 @@ export class SlasherOffensesStore {
|
|
|
32
33
|
) {
|
|
33
34
|
this.offenses = kvStore.openMap('offenses');
|
|
34
35
|
this.roundsOffenses = kvStore.openMultiMap('rounds-offenses');
|
|
35
|
-
this.offensesSlashed = kvStore.openSet('offenses-slashed');
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
/** Returns all offenses
|
|
39
|
-
public async
|
|
38
|
+
/** Returns all offenses */
|
|
39
|
+
public async getOffenses(): Promise<Offense[]> {
|
|
40
40
|
const offenses: Offense[] = [];
|
|
41
|
-
for await (const [
|
|
42
|
-
|
|
43
|
-
continue; // Skip executed offenses
|
|
44
|
-
}
|
|
45
|
-
const offense = deserializeOffense(buffer);
|
|
46
|
-
offenses.push(offense);
|
|
41
|
+
for await (const [, buffer] of this.offenses.entriesAsync()) {
|
|
42
|
+
offenses.push(deserializeOffense(buffer));
|
|
47
43
|
}
|
|
48
44
|
return offenses;
|
|
49
45
|
}
|
|
@@ -61,36 +57,68 @@ export class SlasherOffensesStore {
|
|
|
61
57
|
return offenses;
|
|
62
58
|
}
|
|
63
59
|
|
|
64
|
-
/** Returns whether an offense is pending (ie not marked as slashed) */
|
|
65
|
-
public async hasPendingOffense(offense: OffenseIdentifier): Promise<boolean> {
|
|
66
|
-
const key = this.getOffenseKey(offense);
|
|
67
|
-
return (await this.offenses.getAsync(key)) !== undefined && !(await this.offensesSlashed.hasAsync(key));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
60
|
/** Returns whether we have seen this offense */
|
|
71
61
|
public async hasOffense(offense: OffenseIdentifier): Promise<boolean> {
|
|
72
62
|
const key = this.getOffenseKey(offense);
|
|
73
63
|
return (await this.offenses.getAsync(key)) !== undefined;
|
|
74
64
|
}
|
|
75
65
|
|
|
76
|
-
/** Adds a new offense
|
|
77
|
-
public async
|
|
66
|
+
/** Adds a new offense. Returns false if the offense is already pending. */
|
|
67
|
+
public async addOffense(offense: Offense): Promise<boolean> {
|
|
78
68
|
const key = this.getOffenseKey(offense);
|
|
79
69
|
const round = getRoundForOffense(offense, this.settings);
|
|
80
|
-
await this.kvStore.transactionAsync(async () => {
|
|
70
|
+
const added = await this.kvStore.transactionAsync(async () => {
|
|
71
|
+
if ((await this.offenses.getAsync(key)) !== undefined) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
|
|
81
75
|
await this.offenses.set(key, serializeOffense(offense));
|
|
82
76
|
await this.roundsOffenses.set(this.getRoundKey(round), key);
|
|
77
|
+
return true;
|
|
83
78
|
});
|
|
84
|
-
|
|
79
|
+
|
|
80
|
+
if (added) {
|
|
81
|
+
this.log.trace(`Adding pending offense ${key} for round ${round}`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return added;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
/**
|
|
88
|
-
public async
|
|
89
|
-
await this.kvStore.transactionAsync(async () => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
/** Removes pending offenses matching the given offense type, epoch/slot, and optional validators. */
|
|
88
|
+
public async clearOffenses(filter: ClearOffensesFilter): Promise<number> {
|
|
89
|
+
return await this.kvStore.transactionAsync(async () => {
|
|
90
|
+
const offensesToClear = new Map<string, Offense>();
|
|
91
|
+
|
|
92
|
+
if (filter.validators && filter.validators.length > 0) {
|
|
93
|
+
for (const validator of filter.validators) {
|
|
94
|
+
const identifier = { validator, offenseType: filter.offenseType, epochOrSlot: filter.epochOrSlot };
|
|
95
|
+
const key = this.getOffenseKey(identifier);
|
|
96
|
+
const buffer = await this.offenses.getAsync(key);
|
|
97
|
+
if (buffer) {
|
|
98
|
+
offensesToClear.set(key, deserializeOffense(buffer));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
for await (const [key, buffer] of this.offenses.entriesAsync()) {
|
|
103
|
+
const offense = deserializeOffense(buffer);
|
|
104
|
+
if (offense.offenseType === filter.offenseType && offense.epochOrSlot === filter.epochOrSlot) {
|
|
105
|
+
offensesToClear.set(key, offense);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
93
108
|
}
|
|
109
|
+
|
|
110
|
+
if (offensesToClear.size === 0) {
|
|
111
|
+
return 0;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
for (const [key, offense] of offensesToClear) {
|
|
115
|
+
const round = getRoundForOffense(offense, this.settings);
|
|
116
|
+
await this.offenses.delete(key);
|
|
117
|
+
await this.roundsOffenses.deleteValue(this.getRoundKey(round), key);
|
|
118
|
+
this.log.trace(`Cleared pending offense ${key} for round ${round}`);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return offensesToClear.size;
|
|
94
122
|
});
|
|
95
123
|
}
|
|
96
124
|
|
|
@@ -106,34 +134,32 @@ export class SlasherOffensesStore {
|
|
|
106
134
|
return 0; // Not enough rounds have passed to expire anything
|
|
107
135
|
}
|
|
108
136
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
137
|
+
return await this.kvStore.transactionAsync(async () => {
|
|
138
|
+
// Collect expired offenses and rounds
|
|
139
|
+
const expiredRoundKeys = new Set<string>();
|
|
140
|
+
const expiredOffenseKeys = new Set<string>();
|
|
141
|
+
for await (const [roundKey, offenseKey] of this.roundsOffenses.entriesAsync({
|
|
142
|
+
end: this.getRoundKey(expiredBefore),
|
|
143
|
+
})) {
|
|
144
|
+
expiredOffenseKeys.add(offenseKey);
|
|
145
|
+
expiredRoundKeys.add(roundKey);
|
|
146
|
+
}
|
|
118
147
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
148
|
+
if (expiredOffenseKeys.size === 0 && expiredRoundKeys.size === 0) {
|
|
149
|
+
return 0; // Nothing to clean up
|
|
150
|
+
}
|
|
122
151
|
|
|
123
|
-
// Remove expired stuff in a transaction
|
|
124
|
-
await this.kvStore.transactionAsync(async () => {
|
|
125
152
|
for (const key of expiredOffenseKeys) {
|
|
126
153
|
this.log.trace(`Deleting offense ${key}`);
|
|
127
154
|
await this.offenses.delete(key);
|
|
128
|
-
await this.offensesSlashed.delete(key);
|
|
129
155
|
}
|
|
130
156
|
for (const roundKey of expiredRoundKeys) {
|
|
131
157
|
this.log.trace(`Deleting round info for ${roundKey}`);
|
|
132
158
|
await this.roundsOffenses.delete(roundKey);
|
|
133
159
|
}
|
|
134
|
-
});
|
|
135
160
|
|
|
136
|
-
|
|
161
|
+
return expiredOffenseKeys.size;
|
|
162
|
+
});
|
|
137
163
|
}
|
|
138
164
|
|
|
139
165
|
/** Generate a unique key for an offense */
|
package/src/watcher.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { OffenseType } from '@aztec/stdlib/slashing';
|
|
|
5
5
|
import type { SlasherConfig } from './config.js';
|
|
6
6
|
|
|
7
7
|
export const WANT_TO_SLASH_EVENT = 'want-to-slash' as const;
|
|
8
|
+
export const WANT_TO_CLEAR_SLASH_EVENT = 'want-to-clear-slash' as const;
|
|
8
9
|
|
|
9
10
|
export interface WantToSlashArgs {
|
|
10
11
|
validator: EthAddress;
|
|
@@ -13,9 +14,16 @@ export interface WantToSlashArgs {
|
|
|
13
14
|
epochOrSlot: bigint; // Epoch number for epoch-based offenses, slot number for slot-based
|
|
14
15
|
}
|
|
15
16
|
|
|
17
|
+
export interface WantToClearSlashArgs {
|
|
18
|
+
offenseType: OffenseType;
|
|
19
|
+
epochOrSlot: bigint; // Epoch number for epoch-based offenses, slot number for slot-based
|
|
20
|
+
validators?: EthAddress[];
|
|
21
|
+
}
|
|
22
|
+
|
|
16
23
|
// Event map for specific, known events of a watcher
|
|
17
24
|
export interface WatcherEventMap {
|
|
18
25
|
[WANT_TO_SLASH_EVENT]: (args: WantToSlashArgs[]) => void;
|
|
26
|
+
[WANT_TO_CLEAR_SLASH_EVENT]: (args: WantToClearSlashArgs[]) => void;
|
|
19
27
|
}
|
|
20
28
|
|
|
21
29
|
export type WatcherEmitter = TypedEventEmitter<WatcherEventMap>;
|