@aztec/slasher 0.0.1-commit.96bb3f7 → 0.0.1-commit.993d240
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -76
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +53 -41
- 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 +26 -3
- 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 +21 -0
- package/dest/generated/slasher-defaults.d.ts.map +1 -0
- package/dest/generated/slasher-defaults.js +21 -0
- 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} +50 -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 +64 -39
- 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 +28 -14
- package/dest/watchers/attestations_block_watcher.d.ts.map +1 -1
- package/dest/watchers/attestations_block_watcher.js +80 -64
- 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 +15 -13
- package/src/config.ts +61 -41
- package/src/factory/create_facade.ts +33 -5
- 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 +23 -0
- 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} +68 -54
- package/src/slasher_client_facade.ts +6 -11
- package/src/slasher_client_interface.ts +6 -21
- package/src/stores/offenses_store.ts +76 -48
- package/src/watcher.ts +8 -0
- package/src/watchers/attestations_block_watcher.ts +95 -84
- 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 -572
- 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 -125
- 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 -37
- package/dest/watchers/epoch_prune_watcher.d.ts.map +0 -1
- package/dest/watchers/epoch_prune_watcher.js +0 -137
- package/src/empire_slasher_client.ts +0 -657
- package/src/stores/payloads_store.ts +0 -146
- package/src/watchers/epoch_prune_watcher.ts +0 -194
|
@@ -2,12 +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 {
|
|
6
|
-
import { OffenseType, getEpochsForRound, getSlashConsensusVotesFromOffenses } from '@aztec/stdlib/slashing';
|
|
5
|
+
import { OffenseType, getEpochsForRound, getOffenseTypeName, getSlashConsensusVotesFromOffenses } from '@aztec/stdlib/slashing';
|
|
7
6
|
import { SlashOffensesCollector } from './slash_offenses_collector.js';
|
|
8
7
|
import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
9
8
|
/**
|
|
10
|
-
* The
|
|
9
|
+
* The Slasher client is responsible for managing slashable offenses using
|
|
11
10
|
* the consensus-based slashing model where proposers vote on individual validator offenses.
|
|
12
11
|
*
|
|
13
12
|
* The client subscribes to several slash watchers that emit offenses and tracks them. When the slasher is the
|
|
@@ -31,16 +30,10 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
31
30
|
* - Validators that reach the quorum threshold are slashed. A vote for slashing N units is also considered
|
|
32
31
|
* a vote for slashing N-1, N-2, ..., 1 units. The system slashes for the largest amount that reaches quorum.
|
|
33
32
|
* - The client monitors executable rounds and triggers execution when appropriate.
|
|
34
|
-
|
|
35
|
-
* Differences from Empire model
|
|
36
|
-
* - No fixed slash payloads - votes are for individual validator offenses encoded in bytes
|
|
37
|
-
* - The L1 contract determines which offenses reach quorum rather than nodes agreeing on a payload
|
|
38
|
-
* - Proposers vote directly on which validators to slash and by how much
|
|
39
|
-
* - Uses a slash offset to vote on validators from past rounds (e.g., round N votes on round N-2)
|
|
40
|
-
*/ export class TallySlasherClient {
|
|
33
|
+
*/ export class SlasherClient {
|
|
41
34
|
config;
|
|
42
35
|
settings;
|
|
43
|
-
|
|
36
|
+
slashingProposer;
|
|
44
37
|
slasher;
|
|
45
38
|
rollup;
|
|
46
39
|
epochCache;
|
|
@@ -50,10 +43,10 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
50
43
|
unwatchCallbacks;
|
|
51
44
|
roundMonitor;
|
|
52
45
|
offensesCollector;
|
|
53
|
-
constructor(config, settings,
|
|
46
|
+
constructor(config, settings, slashingProposer, slasher, rollup, watchers, epochCache, dateProvider, offensesStore, log = createLogger('slasher:consensus')){
|
|
54
47
|
this.config = config;
|
|
55
48
|
this.settings = settings;
|
|
56
|
-
this.
|
|
49
|
+
this.slashingProposer = slashingProposer;
|
|
57
50
|
this.slasher = slasher;
|
|
58
51
|
this.rollup = rollup;
|
|
59
52
|
this.epochCache = epochCache;
|
|
@@ -65,28 +58,24 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
65
58
|
this.offensesCollector = new SlashOffensesCollector(config, settings, watchers, offensesStore);
|
|
66
59
|
}
|
|
67
60
|
async start() {
|
|
68
|
-
this.log.debug('Starting
|
|
61
|
+
this.log.debug('Starting slasher client...');
|
|
69
62
|
this.roundMonitor.start();
|
|
70
63
|
await this.offensesCollector.start();
|
|
71
64
|
// Listen for RoundExecuted events
|
|
72
|
-
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))));
|
|
73
66
|
// Check for round changes
|
|
74
67
|
this.unwatchCallbacks.push(this.roundMonitor.listenToNewRound((round)=>this.handleNewRound(round)));
|
|
75
|
-
this.log.info(`Started
|
|
68
|
+
this.log.info(`Started slasher client`);
|
|
76
69
|
return Promise.resolve();
|
|
77
70
|
}
|
|
78
|
-
/**
|
|
79
|
-
|
|
80
|
-
*/ async stop() {
|
|
81
|
-
this.log.debug('Stopping Tally Slasher client...');
|
|
71
|
+
/** Stop the slasher client */ async stop() {
|
|
72
|
+
this.log.debug('Stopping slasher client...');
|
|
82
73
|
for (const unwatchCallback of this.unwatchCallbacks){
|
|
83
74
|
unwatchCallback();
|
|
84
75
|
}
|
|
85
76
|
this.roundMonitor.stop();
|
|
86
77
|
await this.offensesCollector.stop();
|
|
87
|
-
|
|
88
|
-
await sleep(2000);
|
|
89
|
-
this.log.info('Tally Slasher client stopped');
|
|
78
|
+
this.log.info('Slasher client stopped');
|
|
90
79
|
}
|
|
91
80
|
/** Returns the current config */ getConfig() {
|
|
92
81
|
return this.config;
|
|
@@ -98,10 +87,10 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
98
87
|
};
|
|
99
88
|
}
|
|
100
89
|
/** Triggered on a time basis when we enter a new slashing round. Clears expired offenses. */ async handleNewRound(round) {
|
|
101
|
-
this.log.info(`Starting new
|
|
90
|
+
this.log.info(`Starting new slashing round ${round}`);
|
|
102
91
|
await this.offensesCollector.handleNewRound(round);
|
|
103
92
|
}
|
|
104
|
-
/** 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) {
|
|
105
94
|
const slashes = await this.rollup.getSlashEvents(l1BlockHash);
|
|
106
95
|
this.log.info(`Slashing round ${round} has been executed with ${slashCount} slashes`, {
|
|
107
96
|
slashes
|
|
@@ -173,7 +162,7 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
173
162
|
};
|
|
174
163
|
this.log.debug(`Testing if slashing round ${executableRound} is executable`, logData);
|
|
175
164
|
try {
|
|
176
|
-
const roundInfo = await this.
|
|
165
|
+
const roundInfo = await this.slashingProposer.getRound(executableRound);
|
|
177
166
|
logData = {
|
|
178
167
|
...logData,
|
|
179
168
|
roundInfo
|
|
@@ -189,19 +178,19 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
189
178
|
return undefined;
|
|
190
179
|
}
|
|
191
180
|
// Check if round is ready to execute at the given slot
|
|
192
|
-
const isReadyToExecute = await this.
|
|
181
|
+
const isReadyToExecute = await this.slashingProposer.isRoundReadyToExecute(executableRound, slotNumber);
|
|
193
182
|
if (!isReadyToExecute) {
|
|
194
183
|
this.log.warn(`Round ${executableRound} is not ready to execute at slot ${slotNumber} according to contract check`, logData);
|
|
195
184
|
return undefined;
|
|
196
185
|
}
|
|
197
186
|
// Check if the round yields any slashing at all
|
|
198
|
-
const { actions: slashActions, committees } = await this.
|
|
187
|
+
const { actions: slashActions, committees } = await this.slashingProposer.getTally(executableRound);
|
|
199
188
|
if (slashActions.length === 0) {
|
|
200
189
|
this.log.verbose(`Round ${executableRound} does not resolve in any slashing`, logData);
|
|
201
190
|
return undefined;
|
|
202
191
|
}
|
|
203
192
|
// Check if the slash payload is vetoed
|
|
204
|
-
const payload = await this.
|
|
193
|
+
const payload = await this.slashingProposer.getPayload(executableRound);
|
|
205
194
|
const isVetoed = await this.slasher.isPayloadVetoed(payload.address);
|
|
206
195
|
if (isVetoed) {
|
|
207
196
|
this.log.warn(`Round ${executableRound} payload is vetoed (skipping execution)`, {
|
|
@@ -210,8 +199,12 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
210
199
|
});
|
|
211
200
|
return undefined;
|
|
212
201
|
}
|
|
202
|
+
const slashActionsWithAmounts = slashActions.map((action)=>({
|
|
203
|
+
validator: action.validator.toString(),
|
|
204
|
+
slashAmount: action.slashAmount.toString()
|
|
205
|
+
}));
|
|
213
206
|
this.log.info(`Round ${executableRound} is ready to execute with ${slashActions.length} slashes`, {
|
|
214
|
-
slashActions,
|
|
207
|
+
slashActions: slashActionsWithAmounts,
|
|
215
208
|
payloadAddress: payload.address.toString(),
|
|
216
209
|
...logData
|
|
217
210
|
});
|
|
@@ -255,7 +248,7 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
255
248
|
slotNumber,
|
|
256
249
|
currentRound,
|
|
257
250
|
slashedRound,
|
|
258
|
-
|
|
251
|
+
offensesFromAlwaysSlash: offensesFromAlwaysSlash.map(getOffenseLogData),
|
|
259
252
|
slashValidatorsAlways: this.config.slashValidatorsAlways
|
|
260
253
|
});
|
|
261
254
|
}
|
|
@@ -264,7 +257,7 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
264
257
|
slotNumber,
|
|
265
258
|
currentRound,
|
|
266
259
|
slashedRound,
|
|
267
|
-
offensesToForgive,
|
|
260
|
+
offensesToForgive: offensesToForgive.map(getOffenseLogData),
|
|
268
261
|
slashValidatorsNever: this.config.slashValidatorsNever
|
|
269
262
|
});
|
|
270
263
|
}
|
|
@@ -276,25 +269,36 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
276
269
|
});
|
|
277
270
|
return undefined;
|
|
278
271
|
}
|
|
279
|
-
this.log.
|
|
272
|
+
this.log.debug(`Computing slash votes for ${offensesToSlash.length} offenses`, {
|
|
280
273
|
slotNumber,
|
|
281
274
|
currentRound,
|
|
282
275
|
slashedRound,
|
|
283
|
-
offensesToSlash
|
|
276
|
+
offensesToSlash: offensesToSlash.map(getOffenseLogData)
|
|
284
277
|
});
|
|
285
278
|
const committees = await this.collectCommitteesActiveDuringRound(slashedRound);
|
|
286
279
|
const epochsForCommittees = getEpochsForRound(slashedRound, this.settings);
|
|
287
|
-
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);
|
|
288
285
|
if (votes.every((v)=>v === 0)) {
|
|
289
286
|
this.log.warn(`Computed votes for offenses are all zero. Skipping vote.`, {
|
|
290
287
|
slotNumber,
|
|
291
288
|
currentRound,
|
|
292
289
|
slashedRound,
|
|
293
|
-
offensesToSlash,
|
|
290
|
+
offensesToSlash: offensesToSlash.map(getOffenseLogData),
|
|
294
291
|
committees
|
|
295
292
|
});
|
|
296
293
|
return undefined;
|
|
297
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
|
+
});
|
|
298
302
|
this.log.debug(`Computed votes for slashing ${offensesToSlash.length} offenses`, {
|
|
299
303
|
slashedRound,
|
|
300
304
|
currentRound,
|
|
@@ -315,14 +319,8 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
315
319
|
return Promise.all(epochsToSlash.map((epoch)=>this.epochCache.getCommitteeForEpoch(epoch).then((c)=>c.committee ?? emptyCommittee)));
|
|
316
320
|
}
|
|
317
321
|
/**
|
|
318
|
-
* Get slash payloads is NOT SUPPORTED in tally model
|
|
319
|
-
* @throws Error indicating this operation is not supported
|
|
320
|
-
*/ getSlashPayloads() {
|
|
321
|
-
return Promise.reject(new Error('Tally slashing model does not support slash payloads'));
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
322
|
* Gather offenses to be slashed on a given round.
|
|
325
|
-
*
|
|
323
|
+
* Round N slashes validators from round N - slashOffsetInRounds.
|
|
326
324
|
* @param round - The round to get offenses for, defaults to current round
|
|
327
325
|
* @returns Array of pending offenses for the round with offset applied
|
|
328
326
|
*/ async gatherOffensesForRound(round) {
|
|
@@ -332,8 +330,8 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
332
330
|
}
|
|
333
331
|
return await this.offensesStore.getOffensesForRound(targetRound);
|
|
334
332
|
}
|
|
335
|
-
/** Returns all
|
|
336
|
-
return this.offensesStore.
|
|
333
|
+
/** Returns all offenses stored */ getOffenses() {
|
|
334
|
+
return this.offensesStore.getOffenses();
|
|
337
335
|
}
|
|
338
336
|
/**
|
|
339
337
|
* Returns the round to be slashed given the current round by applying the slash offset.
|
|
@@ -347,3 +345,10 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
|
|
|
347
345
|
return round - BigInt(this.settings.slashingOffsetInRounds);
|
|
348
346
|
}
|
|
349
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2xhc2hlcl9jbGllbnRfZmFjYWRlLmQudHMiLCJzb3VyY2VS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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,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;AAElE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAG3E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;GAIG;AACH,qBAAa,mBAAoB,YAAW,sBAAsB;IAK9D,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,wBAAwB;IAChC,OAAO,CAAC,MAAM;IAZhB,OAAO,CAAC,MAAM,CAAqC;IACnD,OAAO,CAAC,OAAO,CAA2B;IAE1C,YACU,MAAM,EAAE,aAAa,GAAG,eAAe,GAAG;QAAE,oBAAoB,EAAE,MAAM,CAAA;KAAE,EAC1E,MAAM,EAAE,cAAc,EACtB,QAAQ,EAAE,UAAU,EACpB,QAAQ,EAAE,OAAO,EAAE,EACnB,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,gBAAgB,EACzB,wBAAwB,EAAE,UAAU,EACpC,MAAM,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():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tQkFBbUIsRUFBRSxDQUFDLENBQUM7SUFFM0UsaUNBQWlDO0lBQ2pDLFNBQVMsSUFBSSxhQUFhLENBQUM7Q0FDNUIifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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,
|
|
1
|
+
{"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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib2ZmZW5zZXNfc3RvcmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zdG9yZXMvb2ZmZW5zZXNfc3RvcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQXFDLE1BQU0saUJBQWlCLENBQUM7QUFDNUYsT0FBTyxFQUNMLEtBQUssT0FBTyxFQUNaLEtBQUssaUJBQWlCLEVBSXZCLE1BQU0sd0JBQXdCLENBQUM7QUFFaEMsZUFBTyxNQUFNLGNBQWMsSUFBSSxDQUFDO0FBRWhDLEtBQUssbUJBQW1CLEdBQUcsSUFBSSxDQUFDLE9BQU8sRUFBRSxhQUFhLEdBQUcsYUFBYSxDQUFDLEdBQUc7SUFDeEUsVUFBVSxDQUFDLEVBQUUsT0FBTyxDQUFDLFdBQVcsQ0FBQyxFQUFFLENBQUM7Q0FDckMsQ0FBQztBQUVGLHFCQUFhLG9CQUFvQjtJQVU3QixPQUFPLENBQUMsT0FBTztJQUNmLE9BQU8sQ0FBQyxRQUFRO0lBVmxCLDJDQUEyQztJQUMzQyxPQUFPLENBQUMsUUFBUSxDQUFnQztJQUVoRCwwQ0FBMEM7SUFDMUMsT0FBTyxDQUFDLGNBQWMsQ0FBcUM7SUFFM0QsT0FBTyxDQUFDLEdBQUcsQ0FBMEM7SUFFckQsWUFDVSxPQUFPLEVBQUUsaUJBQWlCLEVBQzFCLFFBQVEsRUFBRTtRQUNoQixpQkFBaUIsRUFBRSxNQUFNLENBQUM7UUFDMUIsYUFBYSxFQUFFLE1BQU0sQ0FBQztRQUN0Qiw0QkFBNEIsQ0FBQyxFQUFFLE1BQU0sQ0FBQztLQUN2QyxFQUlGO0lBRUQsMkJBQTJCO0lBQ2QsV0FBVyxJQUFJLE9BQU8sQ0FBQyxPQUFPLEVBQUUsQ0FBQyxDQU03QztJQUVELHVEQUF1RDtJQUMxQyxtQkFBbUIsQ0FBQyxLQUFLLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxPQUFPLEVBQUUsQ0FBQyxDQVVsRTtJQUVELGdEQUFnRDtJQUNuQyxVQUFVLENBQUMsT0FBTyxFQUFFLGlCQUFpQixHQUFHLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FHcEU7SUFFRCwyRUFBMkU7SUFDOUQsVUFBVSxDQUFDLE9BQU8sRUFBRSxPQUFPLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQWtCMUQ7SUFFRCxxR0FBcUc7SUFDeEYsYUFBYSxDQUFDLE1BQU0sRUFBRSxtQkFBbUIsR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLENBbUN2RTtJQUVELGlEQUFpRDtJQUNwQyxvQkFBb0IsQ0FBQyxZQUFZLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FxQ3ZFO0lBRUQsMkNBQTJDO0lBQzNDLE9BQU8sQ0FBQyxhQUFhO0lBSXJCLE9BQU8sQ0FBQyxXQUFXO0NBR3BCIn0=
|
|
@@ -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/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C,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,27 +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
|
-
await this.offenses.set(key, serializeOffense(offense));
|
|
52
41
|
const round = getRoundForOffense(offense, this.settings);
|
|
53
|
-
await this.
|
|
54
|
-
|
|
42
|
+
const added = await this.kvStore.transactionAsync(async ()=>{
|
|
43
|
+
if (await this.offenses.getAsync(key) !== undefined) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
await this.offenses.set(key, serializeOffense(offense));
|
|
47
|
+
await this.roundsOffenses.set(this.getRoundKey(round), key);
|
|
48
|
+
return true;
|
|
49
|
+
});
|
|
50
|
+
if (added) {
|
|
51
|
+
this.log.trace(`Adding pending offense ${key} for round ${round}`);
|
|
52
|
+
}
|
|
53
|
+
return added;
|
|
55
54
|
}
|
|
56
|
-
/**
|
|
57
|
-
await this.kvStore.transactionAsync(async ()=>{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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;
|
|
61
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;
|
|
62
89
|
});
|
|
63
90
|
}
|
|
64
91
|
/** Prunes all offenses expired from the store */ async clearExpiredOffenses(currentRound) {
|
|
@@ -70,31 +97,29 @@ export class SlasherOffensesStore {
|
|
|
70
97
|
if (expiredBefore < 0) {
|
|
71
98
|
return 0; // Not enough rounds have passed to expire anything
|
|
72
99
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
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
|
+
}
|
|
87
113
|
for (const key of expiredOffenseKeys){
|
|
88
114
|
this.log.trace(`Deleting offense ${key}`);
|
|
89
115
|
await this.offenses.delete(key);
|
|
90
|
-
await this.offensesSlashed.delete(key);
|
|
91
116
|
}
|
|
92
117
|
for (const roundKey of expiredRoundKeys){
|
|
93
118
|
this.log.trace(`Deleting round info for ${roundKey}`);
|
|
94
119
|
await this.roundsOffenses.delete(roundKey);
|
|
95
120
|
}
|
|
121
|
+
return expiredOffenseKeys.size;
|
|
96
122
|
});
|
|
97
|
-
return expiredOffenseKeys.size;
|
|
98
123
|
}
|
|
99
124
|
/** Generate a unique key for an offense */ getOffenseKey(offense) {
|
|
100
125
|
return `${offense.validator.toString()}:${offense.offenseType}:${offense.epochOrSlot}`;
|