Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gitferry committed Sep 16, 2024
1 parent 3cdf04b commit a871d44
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion x/btcstaking/keeper/voting_power_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func FuzzVotingPowerTable_ActiveFinalityProviders(f *testing.F) {

maxActiveFpsParam := h.BTCStakingKeeper.GetParams(h.Ctx).MaxActiveFinalityProviders
// get a map of expected active finality providers
types.SortFinalityProvidersWithTimestampingAndJailing(fpsWithMeta)
types.SortFinalityProvidersWithZeroedVotingPower(fpsWithMeta)
expectedActiveFps := fpsWithMeta[:min(uint32(len(fpsWithMeta)-len(noTimestampedFps)), maxActiveFpsParam)]
expectedActiveFpsMap := map[string]uint64{}
for _, fp := range expectedActiveFps {
Expand Down
26 changes: 13 additions & 13 deletions x/btcstaking/types/btcstaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,24 @@ func (fp *FinalityProvider) ValidateBasic() error {
return nil
}

// SortFinalityProvidersWithTimestampingAndJailing sorts the finality providers slice,
// from higher to lower voting power
// finality providers that are timestamped come higher than
// those are not
func SortFinalityProvidersWithTimestampingAndJailing(fps []*FinalityProviderDistInfo) {
// SortFinalityProvidersWithZeroedVotingPower sorts the finality providers slice,
// from higher to lower voting power. In the following cases, the voting power
// is treated as zero:
// 1. IsTimestamped is false
// 2. IsJailed is true
func SortFinalityProvidersWithZeroedVotingPower(fps []*FinalityProviderDistInfo) {
sort.SliceStable(fps, func(i, j int) bool {
if fps[i].IsTimestamped && !fps[j].IsTimestamped {
return true
}
if !fps[i].IsTimestamped && fps[j].IsTimestamped {
iShouldBeZeroed := fps[i].IsJailed || !fps[i].IsTimestamped
jShouldBeZeroed := fps[j].IsJailed || !fps[j].IsTimestamped

if iShouldBeZeroed && !jShouldBeZeroed {
return false
}
if !fps[i].IsJailed && fps[j].IsJailed {

if !iShouldBeZeroed && jShouldBeZeroed {
return true
}
if fps[i].IsJailed && !fps[j].IsJailed {
return false
}

return fps[i].TotalVotingPower > fps[j].TotalVotingPower
})
}
Expand Down
2 changes: 1 addition & 1 deletion x/btcstaking/types/incentive.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (dc *VotingPowerDistCache) FindNewActiveFinalityProviders(prevDc *VotingPow
// and records them in cache
func (dc *VotingPowerDistCache) ApplyActiveFinalityProviders(maxActiveFPs uint32) {
// sort finality providers with timestamping considered
SortFinalityProvidersWithTimestampingAndJailing(dc.FinalityProviders)
SortFinalityProvidersWithZeroedVotingPower(dc.FinalityProviders)

numActiveFPs := uint32(0)

Expand Down

0 comments on commit a871d44

Please sign in to comment.