@aztec/slasher 0.0.1-commit.f5d02921e → 0.0.1-commit.f650c0a5c
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 +28 -52
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +0 -12
- package/dest/factory/create_facade.d.ts +2 -2
- package/dest/factory/create_facade.d.ts.map +1 -1
- package/dest/factory/create_facade.js +1 -1
- package/dest/factory/create_implementation.d.ts +4 -6
- 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 +1 -3
- package/dest/generated/slasher-defaults.d.ts.map +1 -1
- package/dest/generated/slasher-defaults.js +0 -2
- package/dest/index.d.ts +2 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- 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/slash_offenses_collector.d.ts +1 -7
- package/dest/slash_offenses_collector.d.ts.map +1 -1
- package/dest/slash_offenses_collector.js +7 -16
- package/dest/slasher_client.d.ts +112 -0
- package/dest/slasher_client.d.ts.map +1 -0
- package/dest/{tally_slasher_client.js → slasher_client.js} +20 -34
- package/dest/slasher_client_facade.d.ts +4 -7
- package/dest/slasher_client_facade.d.ts.map +1 -1
- package/dest/slasher_client_facade.js +4 -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 +6 -12
- package/dest/stores/offenses_store.d.ts.map +1 -1
- package/dest/stores/offenses_store.js +5 -24
- package/package.json +9 -9
- package/src/config.ts +0 -12
- package/src/factory/create_facade.ts +1 -2
- package/src/factory/create_implementation.ts +11 -117
- package/src/factory/get_settings.ts +8 -8
- package/src/factory/index.ts +1 -1
- package/src/generated/slasher-defaults.ts +0 -2
- package/src/index.ts +1 -2
- package/src/null_slasher_client.ts +2 -6
- package/src/slash_offenses_collector.ts +8 -17
- package/src/{tally_slasher_client.ts → slasher_client.ts} +25 -42
- package/src/slasher_client_facade.ts +3 -10
- package/src/slasher_client_interface.ts +6 -21
- package/src/stores/offenses_store.ts +8 -33
- 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/src/empire_slasher_client.ts +0 -649
- package/src/stores/payloads_store.ts +0 -149
|
@@ -20,7 +20,7 @@ import type { Watcher } from '../watcher.js';
|
|
|
20
20
|
/** Creates a slasher client facade that updates itself whenever the rollup slasher changes */
|
|
21
21
|
export async function createSlasherFacade(
|
|
22
22
|
config: SlasherConfig & DataStoreConfig & { ethereumSlotDuration: number },
|
|
23
|
-
l1Contracts: Pick<L1ReaderConfig['l1Contracts'], 'rollupAddress' | '
|
|
23
|
+
l1Contracts: Pick<L1ReaderConfig['l1Contracts'], 'rollupAddress' | 'registryAddress'>,
|
|
24
24
|
l1Client: ViemClient,
|
|
25
25
|
watchers: Watcher[],
|
|
26
26
|
dateProvider: DateProvider,
|
|
@@ -71,7 +71,6 @@ export async function createSlasherFacade(
|
|
|
71
71
|
updatedConfig,
|
|
72
72
|
rollup,
|
|
73
73
|
l1Client,
|
|
74
|
-
l1Contracts.slashFactoryAddress,
|
|
75
74
|
watchers,
|
|
76
75
|
epochCache,
|
|
77
76
|
dateProvider,
|
|
@@ -1,33 +1,24 @@
|
|
|
1
1
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
-
import {
|
|
3
|
-
EmpireSlashingProposerContract,
|
|
4
|
-
RollupContract,
|
|
5
|
-
TallySlashingProposerContract,
|
|
6
|
-
} from '@aztec/ethereum/contracts';
|
|
2
|
+
import { RollupContract, SlashingProposerContract } from '@aztec/ethereum/contracts';
|
|
7
3
|
import type { ViemClient } from '@aztec/ethereum/types';
|
|
8
4
|
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
9
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
10
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
11
6
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
12
7
|
import { AztecLMDBStoreV2 } from '@aztec/kv-store/lmdb-v2';
|
|
13
8
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
14
9
|
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
15
|
-
import { SlashFactoryContract } from '@aztec/stdlib/l1-contracts';
|
|
16
10
|
|
|
17
|
-
import { EmpireSlasherClient, type EmpireSlasherSettings } from '../empire_slasher_client.js';
|
|
18
11
|
import { NullSlasherClient } from '../null_slasher_client.js';
|
|
12
|
+
import { SlasherClient } from '../slasher_client.js';
|
|
19
13
|
import { SlasherOffensesStore } from '../stores/offenses_store.js';
|
|
20
|
-
import { SlasherPayloadsStore } from '../stores/payloads_store.js';
|
|
21
|
-
import { TallySlasherClient } from '../tally_slasher_client.js';
|
|
22
14
|
import type { Watcher } from '../watcher.js';
|
|
23
|
-
import {
|
|
15
|
+
import { getSlasherSettings } from './get_settings.js';
|
|
24
16
|
|
|
25
|
-
/** Creates a slasher client implementation
|
|
17
|
+
/** Creates a slasher client implementation based on the slasher proposer type in the rollup */
|
|
26
18
|
export async function createSlasherImplementation(
|
|
27
19
|
config: SlasherConfig & DataStoreConfig & { ethereumSlotDuration: number },
|
|
28
20
|
rollup: RollupContract,
|
|
29
21
|
l1Client: ViemClient,
|
|
30
|
-
slashFactoryAddress: EthAddress | undefined,
|
|
31
22
|
watchers: Watcher[],
|
|
32
23
|
epochCache: EpochCache,
|
|
33
24
|
dateProvider: DateProvider,
|
|
@@ -38,30 +29,14 @@ export async function createSlasherImplementation(
|
|
|
38
29
|
const proposer = await rollup.getSlashingProposer();
|
|
39
30
|
if (!proposer) {
|
|
40
31
|
return new NullSlasherClient(config);
|
|
41
|
-
} else if (proposer.type === 'tally') {
|
|
42
|
-
return createTallySlasher(
|
|
43
|
-
config,
|
|
44
|
-
rollup,
|
|
45
|
-
proposer,
|
|
46
|
-
watchers,
|
|
47
|
-
dateProvider,
|
|
48
|
-
epochCache,
|
|
49
|
-
kvStore,
|
|
50
|
-
rollupRegisteredAtL2Slot,
|
|
51
|
-
logger,
|
|
52
|
-
);
|
|
53
32
|
} else {
|
|
54
|
-
|
|
55
|
-
throw new Error('Cannot initialize an empire-based SlasherClient without a SlashFactory address');
|
|
56
|
-
}
|
|
57
|
-
const slashFactory = new SlashFactoryContract(l1Client, slashFactoryAddress.toString());
|
|
58
|
-
return createEmpireSlasher(
|
|
33
|
+
return createSlasher(
|
|
59
34
|
config,
|
|
60
35
|
rollup,
|
|
61
36
|
proposer,
|
|
62
|
-
slashFactory,
|
|
63
37
|
watchers,
|
|
64
38
|
dateProvider,
|
|
39
|
+
epochCache,
|
|
65
40
|
kvStore,
|
|
66
41
|
rollupRegisteredAtL2Slot,
|
|
67
42
|
logger,
|
|
@@ -69,99 +44,18 @@ export async function createSlasherImplementation(
|
|
|
69
44
|
}
|
|
70
45
|
}
|
|
71
46
|
|
|
72
|
-
async function
|
|
73
|
-
config: SlasherConfig & DataStoreConfig & { ethereumSlotDuration: number },
|
|
74
|
-
rollup: RollupContract,
|
|
75
|
-
slashingProposer: EmpireSlashingProposerContract,
|
|
76
|
-
slashFactoryContract: SlashFactoryContract,
|
|
77
|
-
watchers: Watcher[],
|
|
78
|
-
dateProvider: DateProvider,
|
|
79
|
-
kvStore: AztecLMDBStoreV2,
|
|
80
|
-
rollupRegisteredAtL2Slot: SlotNumber,
|
|
81
|
-
logger = createLogger('slasher'),
|
|
82
|
-
): Promise<EmpireSlasherClient> {
|
|
83
|
-
if (slashingProposer.type !== 'empire') {
|
|
84
|
-
throw new Error('Slashing proposer contract is not of type Empire');
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const [
|
|
88
|
-
slashingExecutionDelayInRounds,
|
|
89
|
-
slashingPayloadLifetimeInRounds,
|
|
90
|
-
slashingRoundSize,
|
|
91
|
-
slashingQuorumSize,
|
|
92
|
-
epochDuration,
|
|
93
|
-
proofSubmissionEpochs,
|
|
94
|
-
l1GenesisTime,
|
|
95
|
-
slotDuration,
|
|
96
|
-
l1StartBlock,
|
|
97
|
-
slasher,
|
|
98
|
-
] = await Promise.all([
|
|
99
|
-
slashingProposer.getExecutionDelayInRounds(),
|
|
100
|
-
slashingProposer.getLifetimeInRounds(),
|
|
101
|
-
slashingProposer.getRoundSize(),
|
|
102
|
-
slashingProposer.getQuorumSize(),
|
|
103
|
-
rollup.getEpochDuration(),
|
|
104
|
-
rollup.getProofSubmissionEpochs(),
|
|
105
|
-
rollup.getL1GenesisTime(),
|
|
106
|
-
rollup.getSlotDuration(),
|
|
107
|
-
rollup.getL1StartBlock(),
|
|
108
|
-
rollup.getSlasherContract(),
|
|
109
|
-
]);
|
|
110
|
-
|
|
111
|
-
const settings: EmpireSlasherSettings = {
|
|
112
|
-
slashingExecutionDelayInRounds: Number(slashingExecutionDelayInRounds),
|
|
113
|
-
slashingPayloadLifetimeInRounds: Number(slashingPayloadLifetimeInRounds),
|
|
114
|
-
slashingRoundSize: Number(slashingRoundSize),
|
|
115
|
-
slashingQuorumSize: Number(slashingQuorumSize),
|
|
116
|
-
epochDuration: Number(epochDuration),
|
|
117
|
-
proofSubmissionEpochs: Number(proofSubmissionEpochs),
|
|
118
|
-
l1GenesisTime: l1GenesisTime,
|
|
119
|
-
slotDuration: Number(slotDuration),
|
|
120
|
-
l1StartBlock,
|
|
121
|
-
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
122
|
-
slashingAmounts: undefined,
|
|
123
|
-
rollupRegisteredAtL2Slot,
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const payloadsStore = new SlasherPayloadsStore(kvStore, {
|
|
127
|
-
slashingPayloadLifetimeInRounds: settings.slashingPayloadLifetimeInRounds,
|
|
128
|
-
});
|
|
129
|
-
const offensesStore = new SlasherOffensesStore(kvStore, {
|
|
130
|
-
...settings,
|
|
131
|
-
slashOffenseExpirationRounds: config.slashOffenseExpirationRounds,
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
return new EmpireSlasherClient(
|
|
135
|
-
config,
|
|
136
|
-
settings,
|
|
137
|
-
slashFactoryContract,
|
|
138
|
-
slashingProposer,
|
|
139
|
-
slasher!,
|
|
140
|
-
rollup,
|
|
141
|
-
watchers,
|
|
142
|
-
dateProvider,
|
|
143
|
-
offensesStore,
|
|
144
|
-
payloadsStore,
|
|
145
|
-
logger,
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
async function createTallySlasher(
|
|
47
|
+
async function createSlasher(
|
|
150
48
|
config: SlasherConfig & DataStoreConfig,
|
|
151
49
|
rollup: RollupContract,
|
|
152
|
-
slashingProposer:
|
|
50
|
+
slashingProposer: SlashingProposerContract,
|
|
153
51
|
watchers: Watcher[],
|
|
154
52
|
dateProvider: DateProvider,
|
|
155
53
|
epochCache: EpochCache,
|
|
156
54
|
kvStore: AztecLMDBStoreV2,
|
|
157
55
|
rollupRegisteredAtL2Slot: SlotNumber,
|
|
158
56
|
logger = createLogger('slasher'),
|
|
159
|
-
): Promise<
|
|
160
|
-
|
|
161
|
-
throw new Error('Slashing proposer contract is not of type tally');
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const settings = { ...(await getTallySlasherSettings(rollup, slashingProposer)), rollupRegisteredAtL2Slot };
|
|
57
|
+
): Promise<SlasherClient> {
|
|
58
|
+
const settings = { ...(await getSlasherSettings(rollup, slashingProposer)), rollupRegisteredAtL2Slot };
|
|
165
59
|
const slasher = await rollup.getSlasherContract();
|
|
166
60
|
|
|
167
61
|
const offensesStore = new SlasherOffensesStore(kvStore, {
|
|
@@ -169,7 +63,7 @@ async function createTallySlasher(
|
|
|
169
63
|
slashOffenseExpirationRounds: config.slashOffenseExpirationRounds,
|
|
170
64
|
});
|
|
171
65
|
|
|
172
|
-
return new
|
|
66
|
+
return new SlasherClient(
|
|
173
67
|
config,
|
|
174
68
|
settings,
|
|
175
69
|
slashingProposer,
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type { RollupContract,
|
|
1
|
+
import type { RollupContract, SlashingProposerContract } from '@aztec/ethereum/contracts';
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { SlasherSettings } from '../slasher_client.js';
|
|
4
4
|
|
|
5
|
-
export async function
|
|
5
|
+
export async function getSlasherSettings(
|
|
6
6
|
rollup: RollupContract,
|
|
7
|
-
slashingProposer?:
|
|
8
|
-
): Promise<Omit<
|
|
7
|
+
slashingProposer?: SlashingProposerContract,
|
|
8
|
+
): Promise<Omit<SlasherSettings, 'rollupRegisteredAtL2Slot'>> {
|
|
9
9
|
if (!slashingProposer) {
|
|
10
10
|
const rollupSlashingProposer = await rollup.getSlashingProposer();
|
|
11
|
-
if (!rollupSlashingProposer
|
|
12
|
-
throw new Error('Rollup slashing proposer
|
|
11
|
+
if (!rollupSlashingProposer) {
|
|
12
|
+
throw new Error('Rollup slashing proposer not found');
|
|
13
13
|
}
|
|
14
14
|
slashingProposer = rollupSlashingProposer;
|
|
15
15
|
}
|
|
@@ -40,7 +40,7 @@ export async function getTallySlasherSettings(
|
|
|
40
40
|
rollup.getTargetCommitteeSize(),
|
|
41
41
|
]);
|
|
42
42
|
|
|
43
|
-
const settings: Omit<
|
|
43
|
+
const settings: Omit<SlasherSettings, 'rollupRegisteredAtL2Slot'> = {
|
|
44
44
|
slashingExecutionDelayInRounds: Number(slashingExecutionDelayInRounds),
|
|
45
45
|
slashingRoundSize: Number(slashingRoundSize),
|
|
46
46
|
slashingRoundSizeInEpochs: Number(slashingRoundSizeInEpochs),
|
package/src/factory/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { createSlasherFacade as createSlasher } from './create_facade.js';
|
|
2
|
-
export {
|
|
2
|
+
export { getSlasherSettings } from './get_settings.js';
|
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
/** Default slasher configuration values from network-defaults.yml */
|
|
5
5
|
export const slasherDefaultEnv = {
|
|
6
|
-
SLASH_MIN_PENALTY_PERCENTAGE: 0.5,
|
|
7
|
-
SLASH_MAX_PENALTY_PERCENTAGE: 2,
|
|
8
6
|
SLASH_OFFENSE_EXPIRATION_ROUNDS: 4,
|
|
9
7
|
SLASH_MAX_PAYLOAD_SIZE: 80,
|
|
10
8
|
SLASH_EXECUTE_ROUNDS_LOOK_BACK: 4,
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export * from './config.js';
|
|
2
2
|
export * from './watchers/epoch_prune_watcher.js';
|
|
3
3
|
export * from './watchers/attestations_block_watcher.js';
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './tally_slasher_client.js';
|
|
4
|
+
export * from './slasher_client.js';
|
|
6
5
|
export * from './slash_offenses_collector.js';
|
|
7
6
|
export * from './slasher_client_interface.js';
|
|
8
7
|
export * from './factory/index.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import type { Offense, ProposerSlashAction
|
|
2
|
+
import type { Offense, ProposerSlashAction } from '@aztec/stdlib/slashing';
|
|
3
3
|
|
|
4
4
|
import type { SlasherConfig } from './config.js';
|
|
5
5
|
import type { SlasherClientInterface } from './slasher_client_interface.js';
|
|
@@ -15,15 +15,11 @@ export class NullSlasherClient implements SlasherClientInterface {
|
|
|
15
15
|
return Promise.resolve();
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
public getSlashPayloads(): Promise<SlashPayloadRound[]> {
|
|
19
|
-
return Promise.resolve([]);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
18
|
public gatherOffensesForRound(_round?: bigint): Promise<Offense[]> {
|
|
23
19
|
return Promise.resolve([]);
|
|
24
20
|
}
|
|
25
21
|
|
|
26
|
-
public
|
|
22
|
+
public getOffenses(): Promise<Offense[]> {
|
|
27
23
|
return Promise.resolve([]);
|
|
28
24
|
}
|
|
29
25
|
|
|
@@ -3,7 +3,7 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
3
3
|
import type { Prettify } from '@aztec/foundation/types';
|
|
4
4
|
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
5
5
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
6
|
-
import { type Offense,
|
|
6
|
+
import { type Offense, getSlotForOffense } from '@aztec/stdlib/slashing';
|
|
7
7
|
|
|
8
8
|
import type { SlasherOffensesStore } from './stores/offenses_store.js';
|
|
9
9
|
import { WANT_TO_SLASH_EVENT, type WantToSlashArgs, type Watcher } from './watcher.js';
|
|
@@ -66,20 +66,20 @@ export class SlashOffensesCollector {
|
|
|
66
66
|
*/
|
|
67
67
|
public async handleWantToSlash(args: WantToSlashArgs[]) {
|
|
68
68
|
for (const arg of args) {
|
|
69
|
-
const
|
|
69
|
+
const offense: Offense = {
|
|
70
70
|
validator: arg.validator,
|
|
71
71
|
amount: arg.amount,
|
|
72
72
|
offenseType: arg.offenseType,
|
|
73
73
|
epochOrSlot: arg.epochOrSlot,
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
-
if (this.shouldSkipOffense(
|
|
77
|
-
this.log.verbose('Skipping offense during grace period',
|
|
76
|
+
if (this.shouldSkipOffense(offense)) {
|
|
77
|
+
this.log.verbose('Skipping offense during grace period', offense);
|
|
78
78
|
continue;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
if (await this.offensesStore.hasOffense(
|
|
82
|
-
this.log.debug('Skipping repeated offense',
|
|
81
|
+
if (await this.offensesStore.hasOffense(offense)) {
|
|
82
|
+
this.log.debug('Skipping repeated offense', offense);
|
|
83
83
|
continue;
|
|
84
84
|
}
|
|
85
85
|
|
|
@@ -90,8 +90,8 @@ export class SlashOffensesCollector {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
this.log.info(`Adding pending offense for validator ${arg.validator}`,
|
|
94
|
-
await this.offensesStore.
|
|
93
|
+
this.log.info(`Adding pending offense for validator ${arg.validator}`, offense);
|
|
94
|
+
await this.offensesStore.addOffense(offense);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
|
|
@@ -106,15 +106,6 @@ export class SlashOffensesCollector {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
/**
|
|
110
|
-
* Marks offenses as slashed (no longer pending)
|
|
111
|
-
* @param offenses - The offenses to mark as slashed
|
|
112
|
-
*/
|
|
113
|
-
public markAsSlashed(offenses: OffenseIdentifier[]) {
|
|
114
|
-
this.log.verbose(`Marking offenses as slashed`, { offenses });
|
|
115
|
-
return this.offensesStore.markAsSlashed(offenses);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
109
|
/** Returns whether to skip an offense if it happened during the grace period after the network upgrade */
|
|
119
110
|
private shouldSkipOffense(offense: Offense): boolean {
|
|
120
111
|
const offenseSlot = getSlotForOffense(offense, this.settings);
|
|
@@ -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,7 +13,6 @@ import {
|
|
|
13
13
|
OffenseType,
|
|
14
14
|
type ProposerSlashAction,
|
|
15
15
|
type ProposerSlashActionProvider,
|
|
16
|
-
type SlashPayloadRound,
|
|
17
16
|
getEpochsForRound,
|
|
18
17
|
getSlashConsensusVotesFromOffenses,
|
|
19
18
|
} from '@aztec/stdlib/slashing';
|
|
@@ -30,8 +29,8 @@ import type { SlasherClientInterface } from './slasher_client_interface.js';
|
|
|
30
29
|
import type { SlasherOffensesStore } from './stores/offenses_store.js';
|
|
31
30
|
import type { Watcher } from './watcher.js';
|
|
32
31
|
|
|
33
|
-
/** Settings used in the
|
|
34
|
-
export type
|
|
32
|
+
/** Settings used in the slasher client, loaded from the L1 contracts during initialization */
|
|
33
|
+
export type SlasherSettings = Prettify<
|
|
35
34
|
SlashRoundMonitorSettings &
|
|
36
35
|
SlashOffensesCollectorSettings & {
|
|
37
36
|
slashingLifetimeInRounds: number;
|
|
@@ -45,14 +44,14 @@ export type TallySlasherSettings = Prettify<
|
|
|
45
44
|
}
|
|
46
45
|
>;
|
|
47
46
|
|
|
48
|
-
export type
|
|
47
|
+
export type SlasherClientConfig = SlashOffensesCollectorConfig &
|
|
49
48
|
Pick<
|
|
50
49
|
SlasherConfig,
|
|
51
50
|
'slashValidatorsAlways' | 'slashValidatorsNever' | 'slashExecuteRoundsLookBack' | 'slashMaxPayloadSize'
|
|
52
51
|
>;
|
|
53
52
|
|
|
54
53
|
/**
|
|
55
|
-
* The
|
|
54
|
+
* The Slasher client is responsible for managing slashable offenses using
|
|
56
55
|
* the consensus-based slashing model where proposers vote on individual validator offenses.
|
|
57
56
|
*
|
|
58
57
|
* The client subscribes to several slash watchers that emit offenses and tracks them. When the slasher is the
|
|
@@ -76,22 +75,16 @@ export type TallySlasherClientConfig = SlashOffensesCollectorConfig &
|
|
|
76
75
|
* - Validators that reach the quorum threshold are slashed. A vote for slashing N units is also considered
|
|
77
76
|
* a vote for slashing N-1, N-2, ..., 1 units. The system slashes for the largest amount that reaches quorum.
|
|
78
77
|
* - The client monitors executable rounds and triggers execution when appropriate.
|
|
79
|
-
*
|
|
80
|
-
* Differences from Empire model
|
|
81
|
-
* - No fixed slash payloads - votes are for individual validator offenses encoded in bytes
|
|
82
|
-
* - The L1 contract determines which offenses reach quorum rather than nodes agreeing on a payload
|
|
83
|
-
* - Proposers vote directly on which validators to slash and by how much
|
|
84
|
-
* - Uses a slash offset to vote on validators from past rounds (e.g., round N votes on round N-2)
|
|
85
78
|
*/
|
|
86
|
-
export class
|
|
79
|
+
export class SlasherClient implements ProposerSlashActionProvider, SlasherClientInterface {
|
|
87
80
|
protected unwatchCallbacks: (() => void)[] = [];
|
|
88
81
|
protected roundMonitor: SlashRoundMonitor;
|
|
89
82
|
protected offensesCollector: SlashOffensesCollector;
|
|
90
83
|
|
|
91
84
|
constructor(
|
|
92
|
-
private config:
|
|
93
|
-
private settings:
|
|
94
|
-
private
|
|
85
|
+
private config: SlasherClientConfig,
|
|
86
|
+
private settings: SlasherSettings,
|
|
87
|
+
private slashingProposer: SlashingProposerContract,
|
|
95
88
|
private slasher: SlasherContract,
|
|
96
89
|
private rollup: RollupContract,
|
|
97
90
|
watchers: Watcher[],
|
|
@@ -105,14 +98,14 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
105
98
|
}
|
|
106
99
|
|
|
107
100
|
public async start() {
|
|
108
|
-
this.log.debug('Starting
|
|
101
|
+
this.log.debug('Starting slasher client...');
|
|
109
102
|
|
|
110
103
|
this.roundMonitor.start();
|
|
111
104
|
await this.offensesCollector.start();
|
|
112
105
|
|
|
113
106
|
// Listen for RoundExecuted events
|
|
114
107
|
this.unwatchCallbacks.push(
|
|
115
|
-
this.
|
|
108
|
+
this.slashingProposer.listenToRoundExecuted(
|
|
116
109
|
({ round, slashCount, l1BlockHash }) =>
|
|
117
110
|
void this.handleRoundExecuted(round, slashCount, l1BlockHash).catch(err =>
|
|
118
111
|
this.log.error('Error handling round executed', err),
|
|
@@ -123,15 +116,13 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
123
116
|
// Check for round changes
|
|
124
117
|
this.unwatchCallbacks.push(this.roundMonitor.listenToNewRound(round => this.handleNewRound(round)));
|
|
125
118
|
|
|
126
|
-
this.log.info(`Started
|
|
119
|
+
this.log.info(`Started slasher client`);
|
|
127
120
|
return Promise.resolve();
|
|
128
121
|
}
|
|
129
122
|
|
|
130
|
-
/**
|
|
131
|
-
* Stop the tally slasher client
|
|
132
|
-
*/
|
|
123
|
+
/** Stop the slasher client */
|
|
133
124
|
public async stop() {
|
|
134
|
-
this.log.debug('Stopping
|
|
125
|
+
this.log.debug('Stopping slasher client...');
|
|
135
126
|
|
|
136
127
|
for (const unwatchCallback of this.unwatchCallbacks) {
|
|
137
128
|
unwatchCallback();
|
|
@@ -140,7 +131,7 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
140
131
|
this.roundMonitor.stop();
|
|
141
132
|
await this.offensesCollector.stop();
|
|
142
133
|
|
|
143
|
-
this.log.info('
|
|
134
|
+
this.log.info('Slasher client stopped');
|
|
144
135
|
}
|
|
145
136
|
|
|
146
137
|
/** Returns the current config */
|
|
@@ -155,11 +146,11 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
155
146
|
|
|
156
147
|
/** Triggered on a time basis when we enter a new slashing round. Clears expired offenses. */
|
|
157
148
|
protected async handleNewRound(round: bigint) {
|
|
158
|
-
this.log.info(`Starting new
|
|
149
|
+
this.log.info(`Starting new slashing round ${round}`);
|
|
159
150
|
await this.offensesCollector.handleNewRound(round);
|
|
160
151
|
}
|
|
161
152
|
|
|
162
|
-
/** Called when we see a RoundExecuted event on the
|
|
153
|
+
/** Called when we see a RoundExecuted event on the SlashingProposer (just for logging). */
|
|
163
154
|
protected async handleRoundExecuted(round: bigint, slashCount: bigint, l1BlockHash: Hex) {
|
|
164
155
|
const slashes = await this.rollup.getSlashEvents(l1BlockHash);
|
|
165
156
|
this.log.info(`Slashing round ${round} has been executed with ${slashCount} slashes`, { slashes });
|
|
@@ -240,7 +231,7 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
240
231
|
this.log.debug(`Testing if slashing round ${executableRound} is executable`, logData);
|
|
241
232
|
|
|
242
233
|
try {
|
|
243
|
-
const roundInfo = await this.
|
|
234
|
+
const roundInfo = await this.slashingProposer.getRound(executableRound);
|
|
244
235
|
logData = { ...logData, roundInfo };
|
|
245
236
|
if (roundInfo.isExecuted) {
|
|
246
237
|
this.log.verbose(`Round ${executableRound} has already been executed`, logData);
|
|
@@ -254,7 +245,7 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
254
245
|
}
|
|
255
246
|
|
|
256
247
|
// Check if round is ready to execute at the given slot
|
|
257
|
-
const isReadyToExecute = await this.
|
|
248
|
+
const isReadyToExecute = await this.slashingProposer.isRoundReadyToExecute(executableRound, slotNumber);
|
|
258
249
|
if (!isReadyToExecute) {
|
|
259
250
|
this.log.warn(
|
|
260
251
|
`Round ${executableRound} is not ready to execute at slot ${slotNumber} according to contract check`,
|
|
@@ -264,14 +255,14 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
264
255
|
}
|
|
265
256
|
|
|
266
257
|
// Check if the round yields any slashing at all
|
|
267
|
-
const { actions: slashActions, committees } = await this.
|
|
258
|
+
const { actions: slashActions, committees } = await this.slashingProposer.getTally(executableRound);
|
|
268
259
|
if (slashActions.length === 0) {
|
|
269
260
|
this.log.verbose(`Round ${executableRound} does not resolve in any slashing`, logData);
|
|
270
261
|
return undefined;
|
|
271
262
|
}
|
|
272
263
|
|
|
273
264
|
// Check if the slash payload is vetoed
|
|
274
|
-
const payload = await this.
|
|
265
|
+
const payload = await this.slashingProposer.getPayload(executableRound);
|
|
275
266
|
const isVetoed = await this.slasher.isPayloadVetoed(payload.address);
|
|
276
267
|
if (isVetoed) {
|
|
277
268
|
this.log.warn(`Round ${executableRound} payload is vetoed (skipping execution)`, {
|
|
@@ -405,17 +396,9 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
405
396
|
);
|
|
406
397
|
}
|
|
407
398
|
|
|
408
|
-
/**
|
|
409
|
-
* Get slash payloads is NOT SUPPORTED in tally model
|
|
410
|
-
* @throws Error indicating this operation is not supported
|
|
411
|
-
*/
|
|
412
|
-
public getSlashPayloads(): Promise<SlashPayloadRound[]> {
|
|
413
|
-
return Promise.reject(new Error('Tally slashing model does not support slash payloads'));
|
|
414
|
-
}
|
|
415
|
-
|
|
416
399
|
/**
|
|
417
400
|
* Gather offenses to be slashed on a given round.
|
|
418
|
-
*
|
|
401
|
+
* Round N slashes validators from round N - slashOffsetInRounds.
|
|
419
402
|
* @param round - The round to get offenses for, defaults to current round
|
|
420
403
|
* @returns Array of pending offenses for the round with offset applied
|
|
421
404
|
*/
|
|
@@ -428,9 +411,9 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
428
411
|
return await this.offensesStore.getOffensesForRound(targetRound);
|
|
429
412
|
}
|
|
430
413
|
|
|
431
|
-
/** Returns all
|
|
432
|
-
public
|
|
433
|
-
return this.offensesStore.
|
|
414
|
+
/** Returns all offenses stored */
|
|
415
|
+
public getOffenses(): Promise<Offense[]> {
|
|
416
|
+
return this.offensesStore.getOffenses();
|
|
434
417
|
}
|
|
435
418
|
|
|
436
419
|
/**
|
|
@@ -2,13 +2,12 @@ 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';
|
|
6
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
7
6
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
8
7
|
import { AztecLMDBStoreV2 } from '@aztec/kv-store/lmdb-v2';
|
|
9
8
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
10
9
|
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
11
|
-
import type { Offense, ProposerSlashAction
|
|
10
|
+
import type { Offense, ProposerSlashAction } from '@aztec/stdlib/slashing';
|
|
12
11
|
|
|
13
12
|
import { createSlasherImplementation } from './factory/create_implementation.js';
|
|
14
13
|
import type { SlasherClientInterface } from './slasher_client_interface.js';
|
|
@@ -27,7 +26,6 @@ export class SlasherClientFacade implements SlasherClientInterface {
|
|
|
27
26
|
private config: SlasherConfig & DataStoreConfig & { ethereumSlotDuration: number },
|
|
28
27
|
private rollup: RollupContract,
|
|
29
28
|
private l1Client: ViemClient,
|
|
30
|
-
private slashFactoryAddress: EthAddress | undefined,
|
|
31
29
|
private watchers: Watcher[],
|
|
32
30
|
private epochCache: EpochCache,
|
|
33
31
|
private dateProvider: DateProvider,
|
|
@@ -63,16 +61,12 @@ export class SlasherClientFacade implements SlasherClientInterface {
|
|
|
63
61
|
this.watchers.forEach(watcher => watcher.updateConfig?.(config));
|
|
64
62
|
}
|
|
65
63
|
|
|
66
|
-
public getSlashPayloads(): Promise<SlashPayloadRound[]> {
|
|
67
|
-
return this.client?.getSlashPayloads() ?? Promise.reject(new Error('Slasher client not initialized'));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
64
|
public gatherOffensesForRound(round?: bigint): Promise<Offense[]> {
|
|
71
65
|
return this.client?.gatherOffensesForRound(round) ?? Promise.reject(new Error('Slasher client not initialized'));
|
|
72
66
|
}
|
|
73
67
|
|
|
74
|
-
public
|
|
75
|
-
return this.client?.
|
|
68
|
+
public getOffenses(): Promise<Offense[]> {
|
|
69
|
+
return this.client?.getOffenses() ?? Promise.reject(new Error('Slasher client not initialized'));
|
|
76
70
|
}
|
|
77
71
|
|
|
78
72
|
public getProposerActions(slotNumber: SlotNumber): Promise<ProposerSlashAction[]> {
|
|
@@ -84,7 +78,6 @@ export class SlasherClientFacade implements SlasherClientInterface {
|
|
|
84
78
|
this.config,
|
|
85
79
|
this.rollup,
|
|
86
80
|
this.l1Client,
|
|
87
|
-
this.slashFactoryAddress,
|
|
88
81
|
this.watchers,
|
|
89
82
|
this.epochCache,
|
|
90
83
|
this.dateProvider,
|
|
@@ -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
|
/**
|