diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index f6c7f3d1e..4984a7ad2 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -542,6 +542,8 @@ func (ak *AppKeepers) InitKeepers( ) ak.BTCStakingKeeper = *ak.BTCStakingKeeper.SetHooks(btcstakingtypes.NewMultiBtcStakingHooks(ak.FinalityKeeper.Hooks())) ak.FinalityKeeper = *ak.FinalityKeeper.SetHooks(finalitytypes.NewMultiFinalityHooks(ak.BTCStakingKeeper.Hooks())) + // TODO this introduces circular dependency between the finality module and + // the btcstaking modules, need refactoring ak.BTCStakingKeeper.FinalityKeeper = ak.FinalityKeeper // create evidence keeper with router diff --git a/test/e2e/btc_staking_e2e_test.go b/test/e2e/btc_staking_e2e_test.go index 4b6676ac5..d8b733515 100644 --- a/test/e2e/btc_staking_e2e_test.go +++ b/test/e2e/btc_staking_e2e_test.go @@ -355,7 +355,7 @@ func (s *BTCStakingTestSuite) Test3CommitPublicRandomnessAndSubmitFinalitySignat s.Eventually(func() bool { finalizedBlocks = nonValidatorNode.QueryListBlocks(ftypes.QueriedBlockStatus_FINALIZED) return len(finalizedBlocks) > 0 - }, time.Minute, time.Second*5) + }, time.Minute, time.Second) s.Equal(activatedHeight, finalizedBlocks[0].Height) s.Equal(appHash.Bytes(), finalizedBlocks[0].AppHash) diff --git a/x/btcstaking/keeper/power_dist_change.go b/x/btcstaking/keeper/power_dist_change.go index 3641504bc..bfc2afc06 100644 --- a/x/btcstaking/keeper/power_dist_change.go +++ b/x/btcstaking/keeper/power_dist_change.go @@ -197,11 +197,6 @@ func (k Keeper) ProcessAllPowerDistUpdateEvents( // add this finality provider to the new cache if it has voting power if fp.TotalVotingPower > 0 { - // voting power is not assigned if it does not have timestamped - // public randomness for this height - if !k.FinalityKeeper.HasTimestampedPubRand(ctx, fp.BtcPk, height) { - fp.TotalVotingPower = 0 - } newDc.AddFinalityProviderDistInfo(&fp) } } @@ -238,15 +233,21 @@ func (k Keeper) ProcessAllPowerDistUpdateEvents( // add this finality provider to the new cache if it has voting power if fpDistInfo.TotalVotingPower > 0 { - // voting power is not assigned if it does not have timestamped - // public randomness for this height - if !k.FinalityKeeper.HasTimestampedPubRand(ctx, fpBTCPK, height) { - fpDistInfo.TotalVotingPower = 0 - } newDc.AddFinalityProviderDistInfo(fpDistInfo) } } + // set voting power to 0 if the fp does not have timestamped pub rand + for _, fp := range newDc.FinalityProviders { + if fp.TotalVotingPower > 0 && + // TODO calling HasTimestampedPubRand potentially iterates + // all the pub rand committed by the fp, which might slow down + // the process, need optimization + !k.FinalityKeeper.HasTimestampedPubRand(ctx, fp.BtcPk, height) { + fp.TotalVotingPower = 0 + } + } + // filter out the top N finality providers and their total voting power, and // record them in the new cache newDc.ApplyActiveFinalityProviders(maxActiveFps)