@aztec/slasher 0.0.1-commit.85d7d01 → 0.0.1-commit.8655d4a
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 +76 -79
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +29 -29
- package/dest/factory/create_facade.d.ts +3 -3
- package/dest/factory/create_facade.d.ts.map +1 -1
- package/dest/factory/create_facade.js +25 -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 +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 +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/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 +10 -9
- package/dest/slash_offenses_collector.d.ts.map +1 -1
- package/dest/slash_offenses_collector.js +50 -30
- 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} +45 -45
- package/dest/slasher_client_facade.d.ts +6 -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 +35 -29
- package/src/factory/create_facade.ts +32 -4
- package/src/factory/create_implementation.ts +24 -105
- 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/null_slasher_client.ts +2 -6
- package/src/slash_offenses_collector.ts +70 -32
- package/src/{tally_slasher_client.ts → slasher_client.ts} +63 -54
- package/src/slasher_client_facade.ts +6 -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
|
@@ -2,11 +2,11 @@ import { EthAddress } from '@aztec/aztec.js/addresses';
|
|
|
2
2
|
import { maxBigint } from '@aztec/foundation/bigint';
|
|
3
3
|
import { compactArray, partition, times } from '@aztec/foundation/collection';
|
|
4
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
-
import { OffenseType, getEpochsForRound, getSlashConsensusVotesFromOffenses } from '@aztec/stdlib/slashing';
|
|
5
|
+
import { OffenseType, getEpochsForRound, getOffenseTypeName, getSlashConsensusVotesFromOffenses } from '@aztec/stdlib/slashing';
|
|
6
6
|
import { SlashOffensesCollector } from './slash_offenses_collector.js';
|
|
7
7
|
import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
8
8
|
/**
|
|
9
|
-
* The
|
|
9
|
+
* The Slasher client is responsible for managing slashable offenses using
|
|
10
10
|
* the consensus-based slashing model where proposers vote on individual validator offenses.
|
|
11
11
|
*
|
|
12
12
|
* The client subscribes to several slash watchers that emit offenses and tracks them. When the slasher is the
|
|
@@ -30,16 +30,10 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
30
30
|
* - Validators that reach the quorum threshold are slashed. A vote for slashing N units is also considered
|
|
31
31
|
* a vote for slashing N-1, N-2, ..., 1 units. The system slashes for the largest amount that reaches quorum.
|
|
32
32
|
* - The client monitors executable rounds and triggers execution when appropriate.
|
|
33
|
-
|
|
34
|
-
* Differences from Empire model
|
|
35
|
-
* - No fixed slash payloads - votes are for individual validator offenses encoded in bytes
|
|
36
|
-
* - The L1 contract determines which offenses reach quorum rather than nodes agreeing on a payload
|
|
37
|
-
* - Proposers vote directly on which validators to slash and by how much
|
|
38
|
-
* - Uses a slash offset to vote on validators from past rounds (e.g., round N votes on round N-2)
|
|
39
|
-
*/ export class TallySlasherClient {
|
|
33
|
+
*/ export class SlasherClient {
|
|
40
34
|
config;
|
|
41
35
|
settings;
|
|
42
|
-
|
|
36
|
+
slashingProposer;
|
|
43
37
|
slasher;
|
|
44
38
|
rollup;
|
|
45
39
|
epochCache;
|
|
@@ -49,10 +43,10 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
49
43
|
unwatchCallbacks;
|
|
50
44
|
roundMonitor;
|
|
51
45
|
offensesCollector;
|
|
52
|
-
constructor(config, settings,
|
|
46
|
+
constructor(config, settings, slashingProposer, slasher, rollup, watchers, epochCache, dateProvider, offensesStore, log = createLogger('slasher:consensus')){
|
|
53
47
|
this.config = config;
|
|
54
48
|
this.settings = settings;
|
|
55
|
-
this.
|
|
49
|
+
this.slashingProposer = slashingProposer;
|
|
56
50
|
this.slasher = slasher;
|
|
57
51
|
this.rollup = rollup;
|
|
58
52
|
this.epochCache = epochCache;
|
|
@@ -64,26 +58,24 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
64
58
|
this.offensesCollector = new SlashOffensesCollector(config, settings, watchers, offensesStore);
|
|
65
59
|
}
|
|
66
60
|
async start() {
|
|
67
|
-
this.log.debug('Starting
|
|
61
|
+
this.log.debug('Starting slasher client...');
|
|
68
62
|
this.roundMonitor.start();
|
|
69
63
|
await this.offensesCollector.start();
|
|
70
64
|
// Listen for RoundExecuted events
|
|
71
|
-
this.unwatchCallbacks.push(this.
|
|
65
|
+
this.unwatchCallbacks.push(this.slashingProposer.listenToRoundExecuted(({ round, slashCount, l1BlockHash })=>void this.handleRoundExecuted(round, slashCount, l1BlockHash).catch((err)=>this.log.error('Error handling round executed', err))));
|
|
72
66
|
// Check for round changes
|
|
73
67
|
this.unwatchCallbacks.push(this.roundMonitor.listenToNewRound((round)=>this.handleNewRound(round)));
|
|
74
|
-
this.log.info(`Started
|
|
68
|
+
this.log.info(`Started slasher client`);
|
|
75
69
|
return Promise.resolve();
|
|
76
70
|
}
|
|
77
|
-
/**
|
|
78
|
-
|
|
79
|
-
*/ async stop() {
|
|
80
|
-
this.log.debug('Stopping Tally Slasher client...');
|
|
71
|
+
/** Stop the slasher client */ async stop() {
|
|
72
|
+
this.log.debug('Stopping slasher client...');
|
|
81
73
|
for (const unwatchCallback of this.unwatchCallbacks){
|
|
82
74
|
unwatchCallback();
|
|
83
75
|
}
|
|
84
76
|
this.roundMonitor.stop();
|
|
85
77
|
await this.offensesCollector.stop();
|
|
86
|
-
this.log.info('
|
|
78
|
+
this.log.info('Slasher client stopped');
|
|
87
79
|
}
|
|
88
80
|
/** Returns the current config */ getConfig() {
|
|
89
81
|
return this.config;
|
|
@@ -95,10 +87,10 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
95
87
|
};
|
|
96
88
|
}
|
|
97
89
|
/** Triggered on a time basis when we enter a new slashing round. Clears expired offenses. */ async handleNewRound(round) {
|
|
98
|
-
this.log.info(`Starting new
|
|
90
|
+
this.log.info(`Starting new slashing round ${round}`);
|
|
99
91
|
await this.offensesCollector.handleNewRound(round);
|
|
100
92
|
}
|
|
101
|
-
/** Called when we see a RoundExecuted event on the
|
|
93
|
+
/** Called when we see a RoundExecuted event on the SlashingProposer (just for logging). */ async handleRoundExecuted(round, slashCount, l1BlockHash) {
|
|
102
94
|
const slashes = await this.rollup.getSlashEvents(l1BlockHash);
|
|
103
95
|
this.log.info(`Slashing round ${round} has been executed with ${slashCount} slashes`, {
|
|
104
96
|
slashes
|
|
@@ -170,7 +162,7 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
170
162
|
};
|
|
171
163
|
this.log.debug(`Testing if slashing round ${executableRound} is executable`, logData);
|
|
172
164
|
try {
|
|
173
|
-
const roundInfo = await this.
|
|
165
|
+
const roundInfo = await this.slashingProposer.getRound(executableRound);
|
|
174
166
|
logData = {
|
|
175
167
|
...logData,
|
|
176
168
|
roundInfo
|
|
@@ -186,19 +178,19 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
186
178
|
return undefined;
|
|
187
179
|
}
|
|
188
180
|
// Check if round is ready to execute at the given slot
|
|
189
|
-
const isReadyToExecute = await this.
|
|
181
|
+
const isReadyToExecute = await this.slashingProposer.isRoundReadyToExecute(executableRound, slotNumber);
|
|
190
182
|
if (!isReadyToExecute) {
|
|
191
183
|
this.log.warn(`Round ${executableRound} is not ready to execute at slot ${slotNumber} according to contract check`, logData);
|
|
192
184
|
return undefined;
|
|
193
185
|
}
|
|
194
186
|
// Check if the round yields any slashing at all
|
|
195
|
-
const { actions: slashActions, committees } = await this.
|
|
187
|
+
const { actions: slashActions, committees } = await this.slashingProposer.getTally(executableRound);
|
|
196
188
|
if (slashActions.length === 0) {
|
|
197
189
|
this.log.verbose(`Round ${executableRound} does not resolve in any slashing`, logData);
|
|
198
190
|
return undefined;
|
|
199
191
|
}
|
|
200
192
|
// Check if the slash payload is vetoed
|
|
201
|
-
const payload = await this.
|
|
193
|
+
const payload = await this.slashingProposer.getPayload(executableRound);
|
|
202
194
|
const isVetoed = await this.slasher.isPayloadVetoed(payload.address);
|
|
203
195
|
if (isVetoed) {
|
|
204
196
|
this.log.warn(`Round ${executableRound} payload is vetoed (skipping execution)`, {
|
|
@@ -256,7 +248,7 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
256
248
|
slotNumber,
|
|
257
249
|
currentRound,
|
|
258
250
|
slashedRound,
|
|
259
|
-
|
|
251
|
+
offensesFromAlwaysSlash: offensesFromAlwaysSlash.map(getOffenseLogData),
|
|
260
252
|
slashValidatorsAlways: this.config.slashValidatorsAlways
|
|
261
253
|
});
|
|
262
254
|
}
|
|
@@ -265,7 +257,7 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
265
257
|
slotNumber,
|
|
266
258
|
currentRound,
|
|
267
259
|
slashedRound,
|
|
268
|
-
offensesToForgive,
|
|
260
|
+
offensesToForgive: offensesToForgive.map(getOffenseLogData),
|
|
269
261
|
slashValidatorsNever: this.config.slashValidatorsNever
|
|
270
262
|
});
|
|
271
263
|
}
|
|
@@ -277,29 +269,36 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
277
269
|
});
|
|
278
270
|
return undefined;
|
|
279
271
|
}
|
|
280
|
-
|
|
281
|
-
...offense,
|
|
282
|
-
amount: offense.amount.toString()
|
|
283
|
-
}));
|
|
284
|
-
this.log.info(`Voting to slash ${offensesToSlash.length} offenses`, {
|
|
272
|
+
this.log.debug(`Computing slash votes for ${offensesToSlash.length} offenses`, {
|
|
285
273
|
slotNumber,
|
|
286
274
|
currentRound,
|
|
287
275
|
slashedRound,
|
|
288
|
-
offensesToSlash:
|
|
276
|
+
offensesToSlash: offensesToSlash.map(getOffenseLogData)
|
|
289
277
|
});
|
|
290
278
|
const committees = await this.collectCommitteesActiveDuringRound(slashedRound);
|
|
291
279
|
const epochsForCommittees = getEpochsForRound(slashedRound, this.settings);
|
|
292
|
-
const
|
|
280
|
+
const { slashMaxPayloadSize } = this.config;
|
|
281
|
+
const votes = getSlashConsensusVotesFromOffenses(offensesToSlash, committees, epochsForCommittees.map((e)=>BigInt(e)), {
|
|
282
|
+
...this.settings,
|
|
283
|
+
maxSlashedValidators: slashMaxPayloadSize
|
|
284
|
+
}, this.log);
|
|
293
285
|
if (votes.every((v)=>v === 0)) {
|
|
294
286
|
this.log.warn(`Computed votes for offenses are all zero. Skipping vote.`, {
|
|
295
287
|
slotNumber,
|
|
296
288
|
currentRound,
|
|
297
289
|
slashedRound,
|
|
298
|
-
offensesToSlash,
|
|
290
|
+
offensesToSlash: offensesToSlash.map(getOffenseLogData),
|
|
299
291
|
committees
|
|
300
292
|
});
|
|
301
293
|
return undefined;
|
|
302
294
|
}
|
|
295
|
+
this.log.info(`Voting to slash ${offensesToSlash.length} offenses`, {
|
|
296
|
+
slotNumber,
|
|
297
|
+
slashedRound,
|
|
298
|
+
currentRound,
|
|
299
|
+
votes,
|
|
300
|
+
offensesToSlash: offensesToSlash.map(getOffenseLogData)
|
|
301
|
+
});
|
|
303
302
|
this.log.debug(`Computed votes for slashing ${offensesToSlash.length} offenses`, {
|
|
304
303
|
slashedRound,
|
|
305
304
|
currentRound,
|
|
@@ -320,14 +319,8 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
320
319
|
return Promise.all(epochsToSlash.map((epoch)=>this.epochCache.getCommitteeForEpoch(epoch).then((c)=>c.committee ?? emptyCommittee)));
|
|
321
320
|
}
|
|
322
321
|
/**
|
|
323
|
-
* Get slash payloads is NOT SUPPORTED in tally model
|
|
324
|
-
* @throws Error indicating this operation is not supported
|
|
325
|
-
*/ getSlashPayloads() {
|
|
326
|
-
return Promise.reject(new Error('Tally slashing model does not support slash payloads'));
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
322
|
* Gather offenses to be slashed on a given round.
|
|
330
|
-
*
|
|
323
|
+
* Round N slashes validators from round N - slashOffsetInRounds.
|
|
331
324
|
* @param round - The round to get offenses for, defaults to current round
|
|
332
325
|
* @returns Array of pending offenses for the round with offset applied
|
|
333
326
|
*/ async gatherOffensesForRound(round) {
|
|
@@ -337,8 +330,8 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
337
330
|
}
|
|
338
331
|
return await this.offensesStore.getOffensesForRound(targetRound);
|
|
339
332
|
}
|
|
340
|
-
/** Returns all
|
|
341
|
-
return this.offensesStore.
|
|
333
|
+
/** Returns all offenses stored */ getOffenses() {
|
|
334
|
+
return this.offensesStore.getOffenses();
|
|
342
335
|
}
|
|
343
336
|
/**
|
|
344
337
|
* Returns the round to be slashed given the current round by applying the slash offset.
|
|
@@ -352,3 +345,10 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
352
345
|
return round - BigInt(this.settings.slashingOffsetInRounds);
|
|
353
346
|
}
|
|
354
347
|
}
|
|
348
|
+
function getOffenseLogData(offense) {
|
|
349
|
+
return {
|
|
350
|
+
...offense,
|
|
351
|
+
validator: offense.validator.toString(),
|
|
352
|
+
offenseType: getOffenseTypeName(offense.offenseType)
|
|
353
|
+
};
|
|
354
|
+
}
|
|
@@ -2,12 +2,11 @@ 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 { DateProvider } from '@aztec/foundation/timer';
|
|
7
|
-
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
8
6
|
import { AztecLMDBStoreV2 } from '@aztec/kv-store/lmdb-v2';
|
|
9
7
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
10
|
-
import type {
|
|
8
|
+
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
9
|
+
import type { Offense, ProposerSlashAction } from '@aztec/stdlib/slashing';
|
|
11
10
|
import type { SlasherClientInterface } from './slasher_client_interface.js';
|
|
12
11
|
import type { Watcher } from './watcher.js';
|
|
13
12
|
/**
|
|
@@ -19,26 +18,25 @@ export declare class SlasherClientFacade implements SlasherClientInterface {
|
|
|
19
18
|
private config;
|
|
20
19
|
private rollup;
|
|
21
20
|
private l1Client;
|
|
22
|
-
private slashFactoryAddress;
|
|
23
21
|
private watchers;
|
|
24
22
|
private epochCache;
|
|
25
23
|
private dateProvider;
|
|
26
24
|
private kvStore;
|
|
25
|
+
private rollupRegisteredAtL2Slot;
|
|
27
26
|
private logger;
|
|
28
27
|
private client;
|
|
29
28
|
private unwatch;
|
|
30
29
|
constructor(config: SlasherConfig & DataStoreConfig & {
|
|
31
30
|
ethereumSlotDuration: number;
|
|
32
|
-
}, rollup: RollupContract, l1Client: ViemClient,
|
|
31
|
+
}, rollup: RollupContract, l1Client: ViemClient, watchers: Watcher[], epochCache: EpochCache, dateProvider: DateProvider, kvStore: AztecLMDBStoreV2, rollupRegisteredAtL2Slot: SlotNumber, logger?: import("@aztec/foundation/log").Logger);
|
|
33
32
|
start(): Promise<void>;
|
|
34
33
|
stop(): Promise<void>;
|
|
35
34
|
getConfig(): SlasherConfig;
|
|
36
35
|
updateConfig(config: Partial<SlasherConfig>): void;
|
|
37
|
-
getSlashPayloads(): Promise<SlashPayloadRound[]>;
|
|
38
36
|
gatherOffensesForRound(round?: bigint): Promise<Offense[]>;
|
|
39
|
-
|
|
37
|
+
getOffenses(): Promise<Offense[]>;
|
|
40
38
|
getProposerActions(slotNumber: SlotNumber): Promise<ProposerSlashAction[]>;
|
|
41
39
|
private createSlasherClient;
|
|
42
40
|
private handleSlasherChange;
|
|
43
41
|
}
|
|
44
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
42
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2xhc2hlcl9jbGllbnRfZmFjYWRlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvc2xhc2hlcl9jbGllbnRfZmFjYWRlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUNoRCxPQUFPLEVBQUUsY0FBYyxFQUFFLE1BQU0sMkJBQTJCLENBQUM7QUFDM0QsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFDeEQsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0saUNBQWlDLEN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FQUNuQixVQUFVLEVBQUUsVUFBVSxFQUN0QixZQUFZLEVBQUUsWUFBWSxFQUMxQixPQUFPLEVBQUUsZ0JBQWdCLEVBQ3pCLHdCQUF3QixFQUFFLFVBQVUsRUFDcEMsTUFBTSx5Q0FBMEIsRUFDdEM7SUFFUyxLQUFLLElBQUksT0FBTyxDQUFDLElBQUksQ0FBQyxDQVNsQztJQUVZLElBQUksSUFBSSxPQUFPLENBQUMsSUFBSSxDQUFDLENBSWpDO0lBRU0sU0FBUyxJQUFJLGFBQWEsQ0FFaEM7SUFFTSxZQUFZLENBQUMsTUFBTSxFQUFFLE9BQU8sQ0FBQyxhQUFhLENBQUMsR0FBRyxJQUFJLENBSXhEO0lBRU0sc0JBQXNCLENBQUMsS0FBSyxDQUFDLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxPQUFPLEVBQUUsQ0FBQyxDQUVoRTtJQUVNLFdBQVcsSUFBSSxPQUFPLENBQUMsT0FBTyxFQUFFLENBQUMsQ0FFdkM7SUFFTSxrQkFBa0IsQ0FBQyxVQUFVLEVBQUUsVUFBVSxHQUFHLE9BQU8sQ0FBQyxtQkFBbUIsRUFBRSxDQUFDLENBRWhGO0lBRUQsT0FBTyxDQUFDLG1CQUFtQjtZQWNiLG1CQUFtQjtDQU1sQyJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slasher_client_facade.d.ts","sourceRoot":"","sources":["../src/slasher_client_facade.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"slasher_client_facade.d.ts","sourceRoot":"","sources":["../src/slasher_client_facade.ts"],"names":[],"mappings":"AAAA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,yCAA0B,EACtC;IAES,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CASlC;IAEY,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAIjC;IAEM,SAAS,IAAI,aAAa,CAEhC;IAEM,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAIxD;IAEM,sBAAsB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAEhE;IAEM,WAAW,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,CAEvC;IAEM,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAEhF;IAED,OAAO,CAAC,mBAAmB;YAcb,mBAAmB;CAMlC"}
|
|
@@ -8,23 +8,23 @@ import { createSlasherImplementation } from './factory/create_implementation.js'
|
|
|
8
8
|
config;
|
|
9
9
|
rollup;
|
|
10
10
|
l1Client;
|
|
11
|
-
slashFactoryAddress;
|
|
12
11
|
watchers;
|
|
13
12
|
epochCache;
|
|
14
13
|
dateProvider;
|
|
15
14
|
kvStore;
|
|
15
|
+
rollupRegisteredAtL2Slot;
|
|
16
16
|
logger;
|
|
17
17
|
client;
|
|
18
18
|
unwatch;
|
|
19
|
-
constructor(config, rollup, l1Client,
|
|
19
|
+
constructor(config, rollup, l1Client, watchers, epochCache, dateProvider, kvStore, rollupRegisteredAtL2Slot, logger = createLogger('slasher')){
|
|
20
20
|
this.config = config;
|
|
21
21
|
this.rollup = rollup;
|
|
22
22
|
this.l1Client = l1Client;
|
|
23
|
-
this.slashFactoryAddress = slashFactoryAddress;
|
|
24
23
|
this.watchers = watchers;
|
|
25
24
|
this.epochCache = epochCache;
|
|
26
25
|
this.dateProvider = dateProvider;
|
|
27
26
|
this.kvStore = kvStore;
|
|
27
|
+
this.rollupRegisteredAtL2Slot = rollupRegisteredAtL2Slot;
|
|
28
28
|
this.logger = logger;
|
|
29
29
|
}
|
|
30
30
|
async start() {
|
|
@@ -52,20 +52,17 @@ import { createSlasherImplementation } from './factory/create_implementation.js'
|
|
|
52
52
|
this.client?.updateConfig(config);
|
|
53
53
|
this.watchers.forEach((watcher)=>watcher.updateConfig?.(config));
|
|
54
54
|
}
|
|
55
|
-
getSlashPayloads() {
|
|
56
|
-
return this.client?.getSlashPayloads() ?? Promise.reject(new Error('Slasher client not initialized'));
|
|
57
|
-
}
|
|
58
55
|
gatherOffensesForRound(round) {
|
|
59
56
|
return this.client?.gatherOffensesForRound(round) ?? Promise.reject(new Error('Slasher client not initialized'));
|
|
60
57
|
}
|
|
61
|
-
|
|
62
|
-
return this.client?.
|
|
58
|
+
getOffenses() {
|
|
59
|
+
return this.client?.getOffenses() ?? Promise.reject(new Error('Slasher client not initialized'));
|
|
63
60
|
}
|
|
64
61
|
getProposerActions(slotNumber) {
|
|
65
62
|
return this.client?.getProposerActions(slotNumber) ?? Promise.reject(new Error('Slasher client not initialized'));
|
|
66
63
|
}
|
|
67
64
|
createSlasherClient() {
|
|
68
|
-
return createSlasherImplementation(this.config, this.rollup, this.l1Client, this.
|
|
65
|
+
return createSlasherImplementation(this.config, this.rollup, this.l1Client, this.watchers, this.epochCache, this.dateProvider, this.kvStore, this.rollupRegisteredAtL2Slot, this.logger);
|
|
69
66
|
}
|
|
70
67
|
async handleSlasherChange() {
|
|
71
68
|
this.logger.warn('Slasher contract changed, recreating slasher client');
|
|
@@ -1,31 +1,17 @@
|
|
|
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
|
|
4
|
-
/**
|
|
5
|
-
* Common interface for slasher clients used by the Aztec node.
|
|
6
|
-
* Both Empire and Consensus slasher clients implement this interface.
|
|
7
|
-
*/
|
|
3
|
+
import type { Offense, ProposerSlashAction } from '@aztec/stdlib/slashing';
|
|
4
|
+
/** Common interface for slasher clients used by the Aztec node. */
|
|
8
5
|
export interface SlasherClientInterface {
|
|
9
6
|
/** Start the slasher client */
|
|
10
7
|
start(): Promise<void>;
|
|
11
8
|
/** Stop the slasher client */
|
|
12
9
|
stop(): Promise<void>;
|
|
13
|
-
/**
|
|
14
|
-
* Get slash payloads for the Empire model.
|
|
15
|
-
* The Consensus model should throw an error when this is called.
|
|
16
|
-
*/
|
|
17
|
-
getSlashPayloads(): Promise<SlashPayloadRound[]>;
|
|
18
|
-
/**
|
|
19
|
-
* Gather offenses for a given round, defaults to current.
|
|
20
|
-
* Used by both Empire and Consensus models.
|
|
21
|
-
*/
|
|
10
|
+
/** Gather offenses for a given round, defaults to current. */
|
|
22
11
|
gatherOffensesForRound(round?: bigint): Promise<Offense[]>;
|
|
23
|
-
/** Returns all
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Update the configuration.
|
|
27
|
-
* Used by both Empire and Consensus models.
|
|
28
|
-
*/
|
|
12
|
+
/** Returns all offenses */
|
|
13
|
+
getOffenses(): Promise<Offense[]>;
|
|
14
|
+
/** Update the configuration. */
|
|
29
15
|
updateConfig(config: Partial<SlasherConfig>): void;
|
|
30
16
|
/**
|
|
31
17
|
* Get the actions the proposer should take for slashing.
|
|
@@ -36,4 +22,4 @@ export interface SlasherClientInterface {
|
|
|
36
22
|
/** Returns the current config */
|
|
37
23
|
getConfig(): SlasherConfig;
|
|
38
24
|
}
|
|
39
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
25
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2xhc2hlcl9jbGllbnRfaW50ZXJmYWNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvc2xhc2hlcl9jbGllbnRfaW50ZXJmYWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLFVBQVUsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQ2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|
+
{"version":3,"file":"slasher_client_interface.d.ts","sourceRoot":"","sources":["../src/slasher_client_interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE3E,mEAAmE;AACnE,MAAM,WAAW,sBAAsB;IACrC,+BAA+B;IAC/B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB,8BAA8B;IAC9B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtB,8DAA8D;IAC9D,sBAAsB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAE3D,2BAA2B;IAC3B,WAAW,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAElC,gCAAgC;IAChC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC;IAEnD;;;;OAIG;IACH,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAAC;IAE3E,iCAAiC;IACjC,SAAS,IAAI,aAAa,CAAC;CAC5B"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
2
2
|
import { type Offense, type OffenseIdentifier } from '@aztec/stdlib/slashing';
|
|
3
3
|
export declare const SCHEMA_VERSION = 1;
|
|
4
|
+
type ClearOffensesFilter = Pick<Offense, 'offenseType' | 'epochOrSlot'> & {
|
|
5
|
+
validators?: Offense['validator'][];
|
|
6
|
+
};
|
|
4
7
|
export declare class SlasherOffensesStore {
|
|
5
8
|
private kvStore;
|
|
6
9
|
private settings;
|
|
7
10
|
/** Map from offense key to offense data */
|
|
8
11
|
private offenses;
|
|
9
|
-
/**
|
|
10
|
-
private offensesSlashed;
|
|
11
|
-
/** Multimap from round to offense keys (only used for consensus based slashing) */
|
|
12
|
+
/** Multimap from round to offense keys */
|
|
12
13
|
private roundsOffenses;
|
|
13
14
|
private log;
|
|
14
15
|
constructor(kvStore: AztecAsyncKVStore, settings: {
|
|
@@ -16,22 +17,21 @@ export declare class SlasherOffensesStore {
|
|
|
16
17
|
epochDuration: number;
|
|
17
18
|
slashOffenseExpirationRounds?: number;
|
|
18
19
|
});
|
|
19
|
-
/** Returns all offenses
|
|
20
|
-
|
|
20
|
+
/** Returns all offenses */
|
|
21
|
+
getOffenses(): Promise<Offense[]>;
|
|
21
22
|
/** Returns all offenses tracked for the given round */
|
|
22
23
|
getOffensesForRound(round: bigint): Promise<Offense[]>;
|
|
23
|
-
/** Returns whether an offense is pending (ie not marked as slashed) */
|
|
24
|
-
hasPendingOffense(offense: OffenseIdentifier): Promise<boolean>;
|
|
25
24
|
/** Returns whether we have seen this offense */
|
|
26
25
|
hasOffense(offense: OffenseIdentifier): Promise<boolean>;
|
|
27
|
-
/** Adds a new offense
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
|
|
26
|
+
/** Adds a new offense. Returns false if the offense is already pending. */
|
|
27
|
+
addOffense(offense: Offense): Promise<boolean>;
|
|
28
|
+
/** Removes pending offenses matching the given offense type, epoch/slot, and optional validators. */
|
|
29
|
+
clearOffenses(filter: ClearOffensesFilter): Promise<number>;
|
|
31
30
|
/** Prunes all offenses expired from the store */
|
|
32
31
|
clearExpiredOffenses(currentRound: bigint): Promise<number>;
|
|
33
32
|
/** Generate a unique key for an offense */
|
|
34
33
|
private getOffenseKey;
|
|
35
34
|
private getRoundKey;
|
|
36
35
|
}
|
|
37
|
-
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib2ZmZW5zZXNfc3RvcmUuZC50cyIsInNvdXJjZVJvb3QiO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0FBQyxPQUFPLEVBQUUsQ0FBQyxDQVVsRTtJQUVELGdEQUFnRDtJQUNuQyxVQUFVLENBQUMsT0FBTyxFQUFFLGlCQUFpQixHQUFHLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FHcEU7SUFFRCwyRUFBMkU7SUFDOUQsVUFBVSxDQUFDLE9BQU8sRUFBRSxPQUFPLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQWtCMUQ7SUFFRCxxR0FBcUc7SUFDeEYsYUFBYSxDQUFDLE1BQU0sRUFBRSxtQkFBbUIsR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLENBbUN2RTtJQUVELGlEQUFpRDtJQUNwQyxvQkFBb0IsQ0FBQyxZQUFZLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FxQ3ZFO0lBRUQsMkNBQTJDO0lBQzNDLE9BQU8sQ0FBQyxhQUFhO0lBSXJCLE9BQU8sQ0FBQyxXQUFXO0NBR3BCIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"offenses_store.d.ts","sourceRoot":"","sources":["../../src/stores/offenses_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"offenses_store.d.ts","sourceRoot":"","sources":["../../src/stores/offenses_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAqC,MAAM,iBAAiB,CAAC;AAC5F,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,iBAAiB,EAIvB,MAAM,wBAAwB,CAAC;AAEhC,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC,KAAK,mBAAmB,GAAG,IAAI,CAAC,OAAO,EAAE,aAAa,GAAG,aAAa,CAAC,GAAG;IACxE,UAAU,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;CACrC,CAAC;AAEF,qBAAa,oBAAoB;IAU7B,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,QAAQ;IAVlB,2CAA2C;IAC3C,OAAO,CAAC,QAAQ,CAAgC;IAEhD,0CAA0C;IAC1C,OAAO,CAAC,cAAc,CAAqC;IAE3D,OAAO,CAAC,GAAG,CAA0C;IAErD,YACU,OAAO,EAAE,iBAAiB,EAC1B,QAAQ,EAAE;QAChB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,aAAa,EAAE,MAAM,CAAC;QACtB,4BAA4B,CAAC,EAAE,MAAM,CAAC;KACvC,EAIF;IAED,2BAA2B;IACd,WAAW,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,CAM7C;IAED,uDAAuD;IAC1C,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAUlE;IAED,gDAAgD;IACnC,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,CAGpE;IAED,2EAA2E;IAC9D,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAkB1D;IAED,qGAAqG;IACxF,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC,CAmCvE;IAED,iDAAiD;IACpC,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAqCvE;IAED,2CAA2C;IAC3C,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,WAAW;CAGpB"}
|
|
@@ -5,8 +5,7 @@ export class SlasherOffensesStore {
|
|
|
5
5
|
kvStore;
|
|
6
6
|
settings;
|
|
7
7
|
/** Map from offense key to offense data */ offenses;
|
|
8
|
-
/**
|
|
9
|
-
/** Multimap from round to offense keys (only used for consensus based slashing) */ roundsOffenses;
|
|
8
|
+
/** Multimap from round to offense keys */ roundsOffenses;
|
|
10
9
|
log;
|
|
11
10
|
constructor(kvStore, settings){
|
|
12
11
|
this.kvStore = kvStore;
|
|
@@ -14,16 +13,11 @@ export class SlasherOffensesStore {
|
|
|
14
13
|
this.log = createLogger('slasher:store:offenses');
|
|
15
14
|
this.offenses = kvStore.openMap('offenses');
|
|
16
15
|
this.roundsOffenses = kvStore.openMultiMap('rounds-offenses');
|
|
17
|
-
this.offensesSlashed = kvStore.openSet('offenses-slashed');
|
|
18
16
|
}
|
|
19
|
-
/** Returns all offenses
|
|
17
|
+
/** Returns all offenses */ async getOffenses() {
|
|
20
18
|
const offenses = [];
|
|
21
|
-
for await (const [
|
|
22
|
-
|
|
23
|
-
continue; // Skip executed offenses
|
|
24
|
-
}
|
|
25
|
-
const offense = deserializeOffense(buffer);
|
|
26
|
-
offenses.push(offense);
|
|
19
|
+
for await (const [, buffer] of this.offenses.entriesAsync()){
|
|
20
|
+
offenses.push(deserializeOffense(buffer));
|
|
27
21
|
}
|
|
28
22
|
return offenses;
|
|
29
23
|
}
|
|
@@ -38,29 +32,60 @@ export class SlasherOffensesStore {
|
|
|
38
32
|
}
|
|
39
33
|
return offenses;
|
|
40
34
|
}
|
|
41
|
-
/** Returns whether an offense is pending (ie not marked as slashed) */ async hasPendingOffense(offense) {
|
|
42
|
-
const key = this.getOffenseKey(offense);
|
|
43
|
-
return await this.offenses.getAsync(key) !== undefined && !await this.offensesSlashed.hasAsync(key);
|
|
44
|
-
}
|
|
45
35
|
/** Returns whether we have seen this offense */ async hasOffense(offense) {
|
|
46
36
|
const key = this.getOffenseKey(offense);
|
|
47
37
|
return await this.offenses.getAsync(key) !== undefined;
|
|
48
38
|
}
|
|
49
|
-
/** Adds a new offense
|
|
39
|
+
/** Adds a new offense. Returns false if the offense is already pending. */ async addOffense(offense) {
|
|
50
40
|
const key = this.getOffenseKey(offense);
|
|
51
41
|
const round = getRoundForOffense(offense, this.settings);
|
|
52
|
-
await this.kvStore.transactionAsync(async ()=>{
|
|
42
|
+
const added = await this.kvStore.transactionAsync(async ()=>{
|
|
43
|
+
if (await this.offenses.getAsync(key) !== undefined) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
53
46
|
await this.offenses.set(key, serializeOffense(offense));
|
|
54
47
|
await this.roundsOffenses.set(this.getRoundKey(round), key);
|
|
48
|
+
return true;
|
|
55
49
|
});
|
|
56
|
-
|
|
50
|
+
if (added) {
|
|
51
|
+
this.log.trace(`Adding pending offense ${key} for round ${round}`);
|
|
52
|
+
}
|
|
53
|
+
return added;
|
|
57
54
|
}
|
|
58
|
-
/**
|
|
59
|
-
await this.kvStore.transactionAsync(async ()=>{
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
/** Removes pending offenses matching the given offense type, epoch/slot, and optional validators. */ async clearOffenses(filter) {
|
|
56
|
+
return await this.kvStore.transactionAsync(async ()=>{
|
|
57
|
+
const offensesToClear = new Map();
|
|
58
|
+
if (filter.validators && filter.validators.length > 0) {
|
|
59
|
+
for (const validator of filter.validators){
|
|
60
|
+
const identifier = {
|
|
61
|
+
validator,
|
|
62
|
+
offenseType: filter.offenseType,
|
|
63
|
+
epochOrSlot: filter.epochOrSlot
|
|
64
|
+
};
|
|
65
|
+
const key = this.getOffenseKey(identifier);
|
|
66
|
+
const buffer = await this.offenses.getAsync(key);
|
|
67
|
+
if (buffer) {
|
|
68
|
+
offensesToClear.set(key, deserializeOffense(buffer));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
for await (const [key, buffer] of this.offenses.entriesAsync()){
|
|
73
|
+
const offense = deserializeOffense(buffer);
|
|
74
|
+
if (offense.offenseType === filter.offenseType && offense.epochOrSlot === filter.epochOrSlot) {
|
|
75
|
+
offensesToClear.set(key, offense);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (offensesToClear.size === 0) {
|
|
80
|
+
return 0;
|
|
63
81
|
}
|
|
82
|
+
for (const [key, offense] of offensesToClear){
|
|
83
|
+
const round = getRoundForOffense(offense, this.settings);
|
|
84
|
+
await this.offenses.delete(key);
|
|
85
|
+
await this.roundsOffenses.deleteValue(this.getRoundKey(round), key);
|
|
86
|
+
this.log.trace(`Cleared pending offense ${key} for round ${round}`);
|
|
87
|
+
}
|
|
88
|
+
return offensesToClear.size;
|
|
64
89
|
});
|
|
65
90
|
}
|
|
66
91
|
/** Prunes all offenses expired from the store */ async clearExpiredOffenses(currentRound) {
|
|
@@ -72,31 +97,29 @@ export class SlasherOffensesStore {
|
|
|
72
97
|
if (expiredBefore < 0) {
|
|
73
98
|
return 0; // Not enough rounds have passed to expire anything
|
|
74
99
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
await this.kvStore.transactionAsync(async ()=>{
|
|
100
|
+
return await this.kvStore.transactionAsync(async ()=>{
|
|
101
|
+
// Collect expired offenses and rounds
|
|
102
|
+
const expiredRoundKeys = new Set();
|
|
103
|
+
const expiredOffenseKeys = new Set();
|
|
104
|
+
for await (const [roundKey, offenseKey] of this.roundsOffenses.entriesAsync({
|
|
105
|
+
end: this.getRoundKey(expiredBefore)
|
|
106
|
+
})){
|
|
107
|
+
expiredOffenseKeys.add(offenseKey);
|
|
108
|
+
expiredRoundKeys.add(roundKey);
|
|
109
|
+
}
|
|
110
|
+
if (expiredOffenseKeys.size === 0 && expiredRoundKeys.size === 0) {
|
|
111
|
+
return 0; // Nothing to clean up
|
|
112
|
+
}
|
|
89
113
|
for (const key of expiredOffenseKeys){
|
|
90
114
|
this.log.trace(`Deleting offense ${key}`);
|
|
91
115
|
await this.offenses.delete(key);
|
|
92
|
-
await this.offensesSlashed.delete(key);
|
|
93
116
|
}
|
|
94
117
|
for (const roundKey of expiredRoundKeys){
|
|
95
118
|
this.log.trace(`Deleting round info for ${roundKey}`);
|
|
96
119
|
await this.roundsOffenses.delete(roundKey);
|
|
97
120
|
}
|
|
121
|
+
return expiredOffenseKeys.size;
|
|
98
122
|
});
|
|
99
|
-
return expiredOffenseKeys.size;
|
|
100
123
|
}
|
|
101
124
|
/** Generate a unique key for an offense */ getOffenseKey(offense) {
|
|
102
125
|
return `${offense.validator.toString()}:${offense.offenseType}:${offense.epochOrSlot}`;
|