From d1730fd4be091aef2b6dbbba009e2ec0870c465a Mon Sep 17 00:00:00 2001 From: aleem1314 Date: Fri, 7 Oct 2022 22:26:17 +0530 Subject: [PATCH 1/3] fix validatorset issue --- app/app.go | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/app/app.go b/app/app.go index f175ac0bdc..cbe41c1fae 100644 --- a/app/app.go +++ b/app/app.go @@ -646,6 +646,12 @@ func (app *RegenApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci. validatorsVoteInfo[sdk.ConsAddress(voteInfo.Validator.Address).String()] = voteInfo } + // memoize tendermint valset pubkeys + validatorsPubkeysMap := make(map[string]crypto.PubKey, len(validatorsPubkeys.Pubkeys)) // map of consensus address to pubkey + for _, pubkey := range validatorsPubkeys.Pubkeys { + validatorsPubkeysMap[sdk.ConsAddress(pubkey.Address()).String()] = pubkey + } + for _, validator := range validators { tmProtoPk, err := validator.TmConsPublicKey() if err != nil { @@ -680,21 +686,26 @@ func (app *RegenApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci. inStakingValidatorSet[valCons.String()] = true } } else { - updates = append(updates, abci.ValidatorUpdate{ - PubKey: tmProtoPk, - Power: validator.ConsensusPower(sdk.DefaultPowerReduction), - }) + if validator.ConsensusPower(sdk.DefaultPowerReduction) == 0 { + if _, ok := validatorsPubkeysMap[valCons.String()]; ok { + updates = append(updates, abci.ValidatorUpdate{ + PubKey: tmProtoPk, + Power: validator.ConsensusPower(sdk.DefaultPowerReduction), + }) + + inStakingValidatorSet[valCons.String()] = true + } + } else { + updates = append(updates, abci.ValidatorUpdate{ + PubKey: tmProtoPk, + Power: validator.ConsensusPower(sdk.DefaultPowerReduction), + }) + inStakingValidatorSet[valCons.String()] = true + } - inStakingValidatorSet[valCons.String()] = true } } - // memoize tendermint valset pubkeys - validatorsPubkeysMap := make(map[string]crypto.PubKey, len(validatorsPubkeys.Pubkeys)) // map of consensus address to pubkey - for _, pubkey := range validatorsPubkeys.Pubkeys { - validatorsPubkeysMap[sdk.ConsAddress(pubkey.Address()).String()] = pubkey - } - for _, voteInfo := range app.votesInfo { consAddr := sdk.ConsAddress(voteInfo.Validator.Address).String() if !inStakingValidatorSet[consAddr] { From abf421fda1781327486b93f5657fbbf12941b964 Mon Sep 17 00:00:00 2001 From: aleem1314 Date: Fri, 7 Oct 2022 22:38:45 +0530 Subject: [PATCH 2/3] chore: add doc --- app/app.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/app.go b/app/app.go index cbe41c1fae..ed5f9a1e46 100644 --- a/app/app.go +++ b/app/app.go @@ -686,11 +686,13 @@ func (app *RegenApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci. inStakingValidatorSet[valCons.String()] = true } } else { + // ignore validator with zero consensus power and not part + // of tendermint valset. if validator.ConsensusPower(sdk.DefaultPowerReduction) == 0 { if _, ok := validatorsPubkeysMap[valCons.String()]; ok { updates = append(updates, abci.ValidatorUpdate{ PubKey: tmProtoPk, - Power: validator.ConsensusPower(sdk.DefaultPowerReduction), + Power: 0, }) inStakingValidatorSet[valCons.String()] = true From 7911bd58019afddf3553b8a2f0b8cb24599744fc Mon Sep 17 00:00:00 2001 From: aleem1314 Date: Fri, 7 Oct 2022 23:30:35 +0530 Subject: [PATCH 3/3] chore: review changes --- app/app.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/app.go b/app/app.go index ed5f9a1e46..7ac495e11a 100644 --- a/app/app.go +++ b/app/app.go @@ -646,12 +646,6 @@ func (app *RegenApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci. validatorsVoteInfo[sdk.ConsAddress(voteInfo.Validator.Address).String()] = voteInfo } - // memoize tendermint valset pubkeys - validatorsPubkeysMap := make(map[string]crypto.PubKey, len(validatorsPubkeys.Pubkeys)) // map of consensus address to pubkey - for _, pubkey := range validatorsPubkeys.Pubkeys { - validatorsPubkeysMap[sdk.ConsAddress(pubkey.Address()).String()] = pubkey - } - for _, validator := range validators { tmProtoPk, err := validator.TmConsPublicKey() if err != nil { @@ -689,7 +683,7 @@ func (app *RegenApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci. // ignore validator with zero consensus power and not part // of tendermint valset. if validator.ConsensusPower(sdk.DefaultPowerReduction) == 0 { - if _, ok := validatorsPubkeysMap[valCons.String()]; ok { + if _, ok := validatorsVoteInfo[valCons.String()]; ok { updates = append(updates, abci.ValidatorUpdate{ PubKey: tmProtoPk, Power: 0, @@ -708,6 +702,12 @@ func (app *RegenApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci. } } + // memoize tendermint valset pubkeys + validatorsPubkeysMap := make(map[string]crypto.PubKey, len(validatorsPubkeys.Pubkeys)) // map of consensus address to pubkey + for _, pubkey := range validatorsPubkeys.Pubkeys { + validatorsPubkeysMap[sdk.ConsAddress(pubkey.Address()).String()] = pubkey + } + for _, voteInfo := range app.votesInfo { consAddr := sdk.ConsAddress(voteInfo.Validator.Address).String() if !inStakingValidatorSet[consAddr] {