Skip to content

Commit

Permalink
move voting power reset to one place
Browse files Browse the repository at this point in the history
  • Loading branch information
gitferry committed Aug 20, 2024
1 parent a0b524d commit bfa93e6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 2 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/btc_staking_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
21 changes: 11 additions & 10 deletions x/btcstaking/keeper/power_dist_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bfa93e6

Please sign in to comment.