diff --git a/x/keyshare/module/module.go b/x/keyshare/module/module.go index 916ced6d..121019d8 100644 --- a/x/keyshare/module/module.go +++ b/x/keyshare/module/module.go @@ -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) @@ -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)) @@ -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(