Skip to content

Commit

Permalink
Fix idle validator slashing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
p0p3yee committed Oct 24, 2024
1 parent 3cb81a2 commit 7071416
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions x/keyshare/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ func (am AppModule) BeginBlock(cctx context.Context) error {
if foundQc {
am.keeper.SetActiveCommitments(ctx, qc)
}
// When switching the active public key,
// Reset all validators last submitted height,
// So they won't get slashed if they miss the first block of the new active pubkey keyshare.
for _, v := range qk.EncryptedKeyshares {
am.keeper.SetLastSubmittedHeight(ctx, v.Validator, strconv.FormatInt(ctx.BlockHeight(), 10))
}
}
am.keeper.DeleteQueuedPubkey(ctx)
am.pepKeeper.DeleteQueuedPubkey(ctx)
Expand All @@ -256,6 +262,13 @@ func (am AppModule) EndBlock(cctx context.Context) error {
validators := am.keeper.GetAllValidatorSet(ctx)
params := am.keeper.GetParams(ctx)

pubKey, found := am.keeper.GetActivePubkey(ctx)
// If no active public key / no validator in the current public key
// Then no Idling check needed
if !found || len(pubKey.PublicKey) == 0 || len(pubKey.EncryptedKeyshares) == 0 {
return nil
}

for _, eachValidator := range validators {
lastSubmittedHeight := am.keeper.GetLastSubmittedHeight(ctx, eachValidator.Validator)
am.keeper.Logger().Info(fmt.Sprintf("Last submitted: %s: %d", eachValidator.Validator, lastSubmittedHeight))
Expand All @@ -279,10 +292,19 @@ func (am AppModule) EndBlock(cctx context.Context) error {
continue
}

if val, found := am.keeper.GetActivePubkey(ctx); !found || len(val.PublicKey) == 0 {
// Not slashing validator if there is no active public key
inCurrentEpoch := false

for _, k := range pubKey.EncryptedKeyshares {
if k.Validator == eachValidator.Validator {
inCurrentEpoch = true
break
}
}

if !inCurrentEpoch {
am.keeper.Logger().Info(fmt.Sprintf("Validator: %s not in the current epoch, updating last submitted height to current block height.", eachValidator.Validator))
am.keeper.SetLastSubmittedHeight(ctx, eachValidator.Validator, strconv.FormatInt(ctx.BlockHeight(), 10))
continue
return nil
}

am.keeper.SlashingKeeper().Slash(
Expand Down

0 comments on commit 7071416

Please sign in to comment.