@aztec/slasher 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5a9928
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 +85 -78
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +35 -29
- 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 +29 -3
- package/dest/factory/create_implementation.d.ts +7 -7
- package/dest/factory/create_implementation.d.ts.map +1 -1
- package/dest/factory/create_implementation.js +8 -56
- 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 +8 -7
- package/dest/generated/slasher-defaults.d.ts.map +1 -1
- package/dest/generated/slasher-defaults.js +7 -6
- 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 +172 -0
- package/dest/slash_offenses_collector.d.ts +10 -9
- package/dest/slash_offenses_collector.d.ts.map +1 -1
- package/dest/slash_offenses_collector.js +50 -34
- 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} +65 -45
- package/dest/slasher_client_facade.d.ts +8 -8
- package/dest/slasher_client_facade.d.ts.map +1 -1
- package/dest/slasher_client_facade.js +8 -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 +69 -0
- package/dest/watchers/data_withholding_watcher.d.ts.map +1 -0
- package/dest/watchers/data_withholding_watcher.js +223 -0
- package/package.json +10 -10
- package/src/config.ts +42 -29
- package/src/factory/create_facade.ts +37 -5
- package/src/factory/create_implementation.ts +29 -105
- package/src/factory/get_settings.ts +8 -8
- package/src/factory/index.ts +1 -1
- package/src/generated/slasher-defaults.ts +7 -6
- 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 +195 -0
- package/src/slash_offenses_collector.ts +70 -36
- package/src/{tally_slasher_client.ts → slasher_client.ts} +84 -54
- package/src/slasher_client_facade.ts +9 -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 +257 -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 -175
- package/src/empire_slasher_client.ts +0 -649
- package/src/stores/payloads_store.ts +0 -149
- package/src/watchers/epoch_prune_watcher.ts +0 -251
|
@@ -1,15 +1,27 @@
|
|
|
1
|
+
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { SerialQueue } from '@aztec/foundation/queue';
|
|
2
4
|
import type { Prettify } from '@aztec/foundation/types';
|
|
3
5
|
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
4
6
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
5
|
-
import { type Offense,
|
|
7
|
+
import { type Offense, getOffenseTypeName, getSlotForOffense } from '@aztec/stdlib/slashing';
|
|
6
8
|
|
|
7
9
|
import type { SlasherOffensesStore } from './stores/offenses_store.js';
|
|
8
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
WANT_TO_CLEAR_SLASH_EVENT,
|
|
12
|
+
WANT_TO_SLASH_EVENT,
|
|
13
|
+
type WantToClearSlashArgs,
|
|
14
|
+
type WantToSlashArgs,
|
|
15
|
+
type Watcher,
|
|
16
|
+
} from './watcher.js';
|
|
9
17
|
|
|
10
18
|
export type SlashOffensesCollectorConfig = Prettify<Pick<SlasherConfig, 'slashGracePeriodL2Slots'>>;
|
|
11
19
|
export type SlashOffensesCollectorSettings = Prettify<
|
|
12
|
-
Pick<L1RollupConstants, 'epochDuration'> & {
|
|
20
|
+
Pick<L1RollupConstants, 'epochDuration'> & {
|
|
21
|
+
slashingAmounts: [bigint, bigint, bigint] | undefined;
|
|
22
|
+
/** L2 slot at which the rollup was registered as canonical in the Registry. Used to anchor the slash grace period. */
|
|
23
|
+
rollupRegisteredAtL2Slot: SlotNumber;
|
|
24
|
+
}
|
|
13
25
|
>;
|
|
14
26
|
|
|
15
27
|
/**
|
|
@@ -19,6 +31,7 @@ export type SlashOffensesCollectorSettings = Prettify<
|
|
|
19
31
|
*/
|
|
20
32
|
export class SlashOffensesCollector {
|
|
21
33
|
private readonly unwatchCallbacks: (() => void)[] = [];
|
|
34
|
+
private readonly storeMutationQueue = new SerialQueue();
|
|
22
35
|
|
|
23
36
|
constructor(
|
|
24
37
|
private readonly config: SlashOffensesCollectorConfig,
|
|
@@ -30,28 +43,35 @@ export class SlashOffensesCollector {
|
|
|
30
43
|
|
|
31
44
|
public start() {
|
|
32
45
|
this.log.debug('Starting SlashOffensesCollector...');
|
|
46
|
+
this.storeMutationQueue.start();
|
|
33
47
|
|
|
34
|
-
// Subscribe to
|
|
48
|
+
// Subscribe to watcher slashing events.
|
|
35
49
|
for (const watcher of this.watchers) {
|
|
36
50
|
const wantToSlashCallback = (args: WantToSlashArgs[]) =>
|
|
37
|
-
|
|
51
|
+
this.enqueueStoreMutation('wantToSlash', () => this.handleWantToSlash(args));
|
|
38
52
|
watcher.on(WANT_TO_SLASH_EVENT, wantToSlashCallback);
|
|
39
53
|
this.unwatchCallbacks.push(() => watcher.removeListener(WANT_TO_SLASH_EVENT, wantToSlashCallback));
|
|
54
|
+
|
|
55
|
+
const wantToClearSlashCallback = (args: WantToClearSlashArgs[]) =>
|
|
56
|
+
this.enqueueStoreMutation('wantToClearSlash', () => this.handleWantToClearSlash(args));
|
|
57
|
+
watcher.on(WANT_TO_CLEAR_SLASH_EVENT, wantToClearSlashCallback);
|
|
58
|
+
this.unwatchCallbacks.push(() => watcher.removeListener(WANT_TO_CLEAR_SLASH_EVENT, wantToClearSlashCallback));
|
|
40
59
|
}
|
|
41
60
|
|
|
42
61
|
this.log.info('Started SlashOffensesCollector');
|
|
43
62
|
return Promise.resolve();
|
|
44
63
|
}
|
|
45
64
|
|
|
46
|
-
public stop() {
|
|
65
|
+
public async stop() {
|
|
47
66
|
this.log.debug('Stopping SlashOffensesCollector...');
|
|
48
67
|
|
|
49
68
|
for (const unwatchCallback of this.unwatchCallbacks) {
|
|
50
69
|
unwatchCallback();
|
|
51
70
|
}
|
|
52
71
|
|
|
72
|
+
await this.storeMutationQueue.end();
|
|
73
|
+
|
|
53
74
|
this.log.info('SlashOffensesCollector stopped');
|
|
54
|
-
return Promise.resolve();
|
|
55
75
|
}
|
|
56
76
|
|
|
57
77
|
/**
|
|
@@ -61,36 +81,47 @@ export class SlashOffensesCollector {
|
|
|
61
81
|
*/
|
|
62
82
|
public async handleWantToSlash(args: WantToSlashArgs[]) {
|
|
63
83
|
for (const arg of args) {
|
|
64
|
-
const
|
|
84
|
+
const offense: Offense = {
|
|
65
85
|
validator: arg.validator,
|
|
66
86
|
amount: arg.amount,
|
|
67
87
|
offenseType: arg.offenseType,
|
|
68
88
|
epochOrSlot: arg.epochOrSlot,
|
|
69
89
|
};
|
|
70
90
|
|
|
71
|
-
if (this.shouldSkipOffense(
|
|
72
|
-
this.log.verbose('Skipping offense during grace period',
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (await this.offensesStore.hasOffense(pendingOffense)) {
|
|
77
|
-
this.log.debug('Skipping repeated offense', pendingOffense);
|
|
91
|
+
if (this.shouldSkipOffense(offense)) {
|
|
92
|
+
this.log.verbose('Skipping offense during grace period', this.getOffenseLogData(offense));
|
|
78
93
|
continue;
|
|
79
94
|
}
|
|
80
95
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (
|
|
84
|
-
this.
|
|
96
|
+
const added = await this.offensesStore.addOffense(offense);
|
|
97
|
+
if (added) {
|
|
98
|
+
if (this.settings.slashingAmounts) {
|
|
99
|
+
const minSlash = this.settings.slashingAmounts[0];
|
|
100
|
+
if (arg.amount < minSlash) {
|
|
101
|
+
this.log.warn(
|
|
102
|
+
`Offense amount ${arg.amount} is below minimum slashing amount ${minSlash}`,
|
|
103
|
+
this.getOffenseLogData(offense),
|
|
104
|
+
);
|
|
105
|
+
}
|
|
85
106
|
}
|
|
107
|
+
|
|
108
|
+
this.log.info(`Adding pending offense for validator ${arg.validator}`, this.getOffenseLogData(offense));
|
|
109
|
+
} else {
|
|
110
|
+
this.log.debug('Skipping repeated offense', this.getOffenseLogData(offense));
|
|
86
111
|
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
87
114
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
115
|
+
public async handleWantToClearSlash(args: WantToClearSlashArgs[]) {
|
|
116
|
+
for (const arg of args) {
|
|
117
|
+
const cleared = await this.offensesStore.clearOffenses(arg);
|
|
118
|
+
if (cleared > 0) {
|
|
119
|
+
this.log.info(`Cleared ${cleared} pending offenses`, {
|
|
120
|
+
offenseType: getOffenseTypeName(arg.offenseType),
|
|
121
|
+
epochOrSlot: arg.epochOrSlot,
|
|
122
|
+
validators: arg.validators?.map(validator => validator.toString()),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
94
125
|
}
|
|
95
126
|
}
|
|
96
127
|
|
|
@@ -105,18 +136,21 @@ export class SlashOffensesCollector {
|
|
|
105
136
|
}
|
|
106
137
|
}
|
|
107
138
|
|
|
108
|
-
/**
|
|
109
|
-
* Marks offenses as slashed (no longer pending)
|
|
110
|
-
* @param offenses - The offenses to mark as slashed
|
|
111
|
-
*/
|
|
112
|
-
public markAsSlashed(offenses: OffenseIdentifier[]) {
|
|
113
|
-
this.log.verbose(`Marking offenses as slashed`, { offenses });
|
|
114
|
-
return this.offensesStore.markAsSlashed(offenses);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/** Returns whether to skip an offense if it happened during the grace period at the beginning of the chain */
|
|
139
|
+
/** Returns whether to skip an offense if it happened during the grace period after the network upgrade */
|
|
118
140
|
private shouldSkipOffense(offense: Offense): boolean {
|
|
119
141
|
const offenseSlot = getSlotForOffense(offense, this.settings);
|
|
120
|
-
return offenseSlot < this.config.slashGracePeriodL2Slots;
|
|
142
|
+
return offenseSlot < this.settings.rollupRegisteredAtL2Slot + this.config.slashGracePeriodL2Slots;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private getOffenseLogData(offense: Offense) {
|
|
146
|
+
return {
|
|
147
|
+
...offense,
|
|
148
|
+
validator: offense.validator.toString(),
|
|
149
|
+
offenseType: getOffenseTypeName(offense.offenseType),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private enqueueStoreMutation(label: string, callback: () => Promise<void>) {
|
|
154
|
+
void this.storeMutationQueue.put(callback).catch(err => this.log.error(`Error handling ${label}`, err));
|
|
121
155
|
}
|
|
122
156
|
}
|
|
@@ -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,33 @@ 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. Subscribed only after the monitor's baseline read completes, so a
|
|
137
|
+
// vote cast in between is caught up by a later drain instead of being mistaken for a pre-startup vote.
|
|
138
|
+
if (this.ownValidators.length > 0) {
|
|
139
|
+
await this.ownValidatorMonitor.start(this.roundMonitor.getCurrentRound().round);
|
|
140
|
+
this.unwatchCallbacks.push(
|
|
141
|
+
this.slashingProposer.listenToVoteCast(({ round }) => void this.ownValidatorMonitor.handleVoteCast(round)),
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
this.log.info(`Started slasher client`);
|
|
124
146
|
return Promise.resolve();
|
|
125
147
|
}
|
|
126
148
|
|
|
127
|
-
/**
|
|
128
|
-
* Stop the tally slasher client
|
|
129
|
-
*/
|
|
149
|
+
/** Stop the slasher client */
|
|
130
150
|
public async stop() {
|
|
131
|
-
this.log.debug('Stopping
|
|
151
|
+
this.log.debug('Stopping slasher client...');
|
|
132
152
|
|
|
133
153
|
for (const unwatchCallback of this.unwatchCallbacks) {
|
|
134
154
|
unwatchCallback();
|
|
135
155
|
}
|
|
136
156
|
|
|
137
157
|
this.roundMonitor.stop();
|
|
158
|
+
await this.ownValidatorMonitor.stop();
|
|
138
159
|
await this.offensesCollector.stop();
|
|
139
160
|
|
|
140
|
-
this.log.info('
|
|
161
|
+
this.log.info('Slasher client stopped');
|
|
141
162
|
}
|
|
142
163
|
|
|
143
164
|
/** Returns the current config */
|
|
@@ -152,14 +173,17 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
152
173
|
|
|
153
174
|
/** Triggered on a time basis when we enter a new slashing round. Clears expired offenses. */
|
|
154
175
|
protected async handleNewRound(round: bigint) {
|
|
155
|
-
this.log.info(`Starting new
|
|
176
|
+
this.log.info(`Starting new slashing round ${round}`);
|
|
177
|
+
this.ownValidatorMonitor.handleNewRound(round);
|
|
156
178
|
await this.offensesCollector.handleNewRound(round);
|
|
157
179
|
}
|
|
158
180
|
|
|
159
|
-
/** Called when we see a RoundExecuted event on the
|
|
181
|
+
/** Called when we see a RoundExecuted event on the SlashingProposer (just for logging and metrics). */
|
|
160
182
|
protected async handleRoundExecuted(round: bigint, slashCount: bigint, l1BlockHash: Hex) {
|
|
183
|
+
this.metrics.recordRoundExecuted();
|
|
161
184
|
const slashes = await this.rollup.getSlashEvents(l1BlockHash);
|
|
162
185
|
this.log.info(`Slashing round ${round} has been executed with ${slashCount} slashes`, { slashes });
|
|
186
|
+
this.ownValidatorMonitor.handleSlashes(round, slashes, l1BlockHash);
|
|
163
187
|
}
|
|
164
188
|
|
|
165
189
|
/**
|
|
@@ -237,7 +261,7 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
237
261
|
this.log.debug(`Testing if slashing round ${executableRound} is executable`, logData);
|
|
238
262
|
|
|
239
263
|
try {
|
|
240
|
-
const roundInfo = await this.
|
|
264
|
+
const roundInfo = await this.slashingProposer.getRound(executableRound);
|
|
241
265
|
logData = { ...logData, roundInfo };
|
|
242
266
|
if (roundInfo.isExecuted) {
|
|
243
267
|
this.log.verbose(`Round ${executableRound} has already been executed`, logData);
|
|
@@ -251,7 +275,7 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
251
275
|
}
|
|
252
276
|
|
|
253
277
|
// Check if round is ready to execute at the given slot
|
|
254
|
-
const isReadyToExecute = await this.
|
|
278
|
+
const isReadyToExecute = await this.slashingProposer.isRoundReadyToExecute(executableRound, slotNumber);
|
|
255
279
|
if (!isReadyToExecute) {
|
|
256
280
|
this.log.warn(
|
|
257
281
|
`Round ${executableRound} is not ready to execute at slot ${slotNumber} according to contract check`,
|
|
@@ -261,14 +285,14 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
261
285
|
}
|
|
262
286
|
|
|
263
287
|
// Check if the round yields any slashing at all
|
|
264
|
-
const { actions: slashActions, committees } = await this.
|
|
288
|
+
const { actions: slashActions, committees } = await this.slashingProposer.getTally(executableRound);
|
|
265
289
|
if (slashActions.length === 0) {
|
|
266
290
|
this.log.verbose(`Round ${executableRound} does not resolve in any slashing`, logData);
|
|
267
291
|
return undefined;
|
|
268
292
|
}
|
|
269
293
|
|
|
270
294
|
// Check if the slash payload is vetoed
|
|
271
|
-
const payload = await this.
|
|
295
|
+
const payload = await this.slashingProposer.getPayload(executableRound);
|
|
272
296
|
const isVetoed = await this.slasher.isPayloadVetoed(payload.address);
|
|
273
297
|
if (isVetoed) {
|
|
274
298
|
this.log.warn(`Round ${executableRound} payload is vetoed (skipping execution)`, {
|
|
@@ -315,7 +339,7 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
315
339
|
// Compute offenses to slash, by loading the offenses for this round, adding synthetic offenses
|
|
316
340
|
// for validators that should always be slashed, and removing the ones that should never be slashed.
|
|
317
341
|
const offensesForRound = await this.gatherOffensesForRound(currentRound);
|
|
318
|
-
const offensesFromAlwaysSlash = (this.config.slashValidatorsAlways ?? []).map(validator => ({
|
|
342
|
+
const offensesFromAlwaysSlash: AlwaysSlashOffense[] = (this.config.slashValidatorsAlways ?? []).map(validator => ({
|
|
319
343
|
validator,
|
|
320
344
|
amount: this.settings.slashingAmounts[2],
|
|
321
345
|
offenseType: OffenseType.UNKNOWN,
|
|
@@ -329,7 +353,7 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
329
353
|
slotNumber,
|
|
330
354
|
currentRound,
|
|
331
355
|
slashedRound,
|
|
332
|
-
|
|
356
|
+
offensesFromAlwaysSlash: offensesFromAlwaysSlash.map(getOffenseLogData),
|
|
333
357
|
slashValidatorsAlways: this.config.slashValidatorsAlways,
|
|
334
358
|
});
|
|
335
359
|
}
|
|
@@ -339,7 +363,7 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
339
363
|
slotNumber,
|
|
340
364
|
currentRound,
|
|
341
365
|
slashedRound,
|
|
342
|
-
offensesToForgive,
|
|
366
|
+
offensesToForgive: offensesToForgive.map(getOffenseLogData),
|
|
343
367
|
slashValidatorsNever: this.config.slashValidatorsNever,
|
|
344
368
|
});
|
|
345
369
|
}
|
|
@@ -349,36 +373,42 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
349
373
|
return undefined;
|
|
350
374
|
}
|
|
351
375
|
|
|
352
|
-
|
|
353
|
-
...offense,
|
|
354
|
-
amount: offense.amount.toString(),
|
|
355
|
-
}));
|
|
356
|
-
this.log.info(`Voting to slash ${offensesToSlash.length} offenses`, {
|
|
376
|
+
this.log.debug(`Computing slash votes for ${offensesToSlash.length} offenses`, {
|
|
357
377
|
slotNumber,
|
|
358
378
|
currentRound,
|
|
359
379
|
slashedRound,
|
|
360
|
-
offensesToSlash:
|
|
380
|
+
offensesToSlash: offensesToSlash.map(getOffenseLogData),
|
|
361
381
|
});
|
|
362
382
|
|
|
363
383
|
const committees = await this.collectCommitteesActiveDuringRound(slashedRound);
|
|
364
384
|
const epochsForCommittees = getEpochsForRound(slashedRound, this.settings);
|
|
385
|
+
const { slashMaxPayloadSize } = this.config;
|
|
365
386
|
const votes = getSlashConsensusVotesFromOffenses(
|
|
366
387
|
offensesToSlash,
|
|
367
388
|
committees,
|
|
368
389
|
epochsForCommittees.map(e => BigInt(e)),
|
|
369
|
-
this.settings,
|
|
390
|
+
{ ...this.settings, maxSlashedValidators: slashMaxPayloadSize },
|
|
391
|
+
this.log,
|
|
370
392
|
);
|
|
371
393
|
if (votes.every(v => v === 0)) {
|
|
372
394
|
this.log.warn(`Computed votes for offenses are all zero. Skipping vote.`, {
|
|
373
395
|
slotNumber,
|
|
374
396
|
currentRound,
|
|
375
397
|
slashedRound,
|
|
376
|
-
offensesToSlash,
|
|
398
|
+
offensesToSlash: offensesToSlash.map(getOffenseLogData),
|
|
377
399
|
committees,
|
|
378
400
|
});
|
|
379
401
|
return undefined;
|
|
380
402
|
}
|
|
381
403
|
|
|
404
|
+
this.log.info(`Voting to slash ${offensesToSlash.length} offenses`, {
|
|
405
|
+
slotNumber,
|
|
406
|
+
slashedRound,
|
|
407
|
+
currentRound,
|
|
408
|
+
votes,
|
|
409
|
+
offensesToSlash: offensesToSlash.map(getOffenseLogData),
|
|
410
|
+
});
|
|
411
|
+
|
|
382
412
|
this.log.debug(`Computed votes for slashing ${offensesToSlash.length} offenses`, {
|
|
383
413
|
slashedRound,
|
|
384
414
|
currentRound,
|
|
@@ -404,17 +434,9 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
404
434
|
);
|
|
405
435
|
}
|
|
406
436
|
|
|
407
|
-
/**
|
|
408
|
-
* Get slash payloads is NOT SUPPORTED in tally model
|
|
409
|
-
* @throws Error indicating this operation is not supported
|
|
410
|
-
*/
|
|
411
|
-
public getSlashPayloads(): Promise<SlashPayloadRound[]> {
|
|
412
|
-
return Promise.reject(new Error('Tally slashing model does not support slash payloads'));
|
|
413
|
-
}
|
|
414
|
-
|
|
415
437
|
/**
|
|
416
438
|
* Gather offenses to be slashed on a given round.
|
|
417
|
-
*
|
|
439
|
+
* Round N slashes validators from round N - slashOffsetInRounds.
|
|
418
440
|
* @param round - The round to get offenses for, defaults to current round
|
|
419
441
|
* @returns Array of pending offenses for the round with offset applied
|
|
420
442
|
*/
|
|
@@ -427,9 +449,9 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
427
449
|
return await this.offensesStore.getOffensesForRound(targetRound);
|
|
428
450
|
}
|
|
429
451
|
|
|
430
|
-
/** Returns all
|
|
431
|
-
public
|
|
432
|
-
return this.offensesStore.
|
|
452
|
+
/** Returns all offenses stored */
|
|
453
|
+
public getOffenses(): Promise<Offense[]> {
|
|
454
|
+
return this.offensesStore.getOffenses();
|
|
433
455
|
}
|
|
434
456
|
|
|
435
457
|
/**
|
|
@@ -445,3 +467,11 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
445
467
|
return round - BigInt(this.settings.slashingOffsetInRounds);
|
|
446
468
|
}
|
|
447
469
|
}
|
|
470
|
+
|
|
471
|
+
function getOffenseLogData(offense: SlashVoteOffense) {
|
|
472
|
+
return {
|
|
473
|
+
...offense,
|
|
474
|
+
validator: offense.validator.toString(),
|
|
475
|
+
offenseType: getOffenseTypeName(offense.offenseType),
|
|
476
|
+
};
|
|
477
|
+
}
|
|
@@ -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,11 +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,
|
|
34
|
+
private rollupRegisteredAtL2Slot: SlotNumber,
|
|
35
|
+
private ownValidators: EthAddress[] = [],
|
|
35
36
|
private logger = createLogger('slasher'),
|
|
36
37
|
) {}
|
|
37
38
|
|
|
@@ -62,16 +63,12 @@ export class SlasherClientFacade implements SlasherClientInterface {
|
|
|
62
63
|
this.watchers.forEach(watcher => watcher.updateConfig?.(config));
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
public getSlashPayloads(): Promise<SlashPayloadRound[]> {
|
|
66
|
-
return this.client?.getSlashPayloads() ?? Promise.reject(new Error('Slasher client not initialized'));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
66
|
public gatherOffensesForRound(round?: bigint): Promise<Offense[]> {
|
|
70
67
|
return this.client?.gatherOffensesForRound(round) ?? Promise.reject(new Error('Slasher client not initialized'));
|
|
71
68
|
}
|
|
72
69
|
|
|
73
|
-
public
|
|
74
|
-
return this.client?.
|
|
70
|
+
public getOffenses(): Promise<Offense[]> {
|
|
71
|
+
return this.client?.getOffenses() ?? Promise.reject(new Error('Slasher client not initialized'));
|
|
75
72
|
}
|
|
76
73
|
|
|
77
74
|
public getProposerActions(slotNumber: SlotNumber): Promise<ProposerSlashAction[]> {
|
|
@@ -83,11 +80,12 @@ export class SlasherClientFacade implements SlasherClientInterface {
|
|
|
83
80
|
this.config,
|
|
84
81
|
this.rollup,
|
|
85
82
|
this.l1Client,
|
|
86
|
-
this.slashFactoryAddress,
|
|
87
83
|
this.watchers,
|
|
88
84
|
this.epochCache,
|
|
89
85
|
this.dateProvider,
|
|
90
86
|
this.kvStore,
|
|
87
|
+
this.rollupRegisteredAtL2Slot,
|
|
88
|
+
this.ownValidators,
|
|
91
89
|
this.logger,
|
|
92
90
|
);
|
|
93
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
|
/**
|