Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: rename total voting power to total bonded sat #207

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased

### State Machine Breaking

* [#207](https://github.com/babylonlabs-io/babylon/pull/207) Rename total voting power
to total bonded sat

## v0.13.0

### API Breaking
Expand Down
14 changes: 7 additions & 7 deletions proto/babylon/btcstaking/v1/incentive.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ option go_package = "github.com/babylonlabs-io/babylon/x/btcstaking/types";
// and their BTC delegations at a height
message VotingPowerDistCache {
option (gogoproto.goproto_getters) = false;
// total_voting_power is the total voting power of all the finality providers
// total_sat is the total amount of bonded BTC stake (in Satoshi) of all the finality providers
// in the cache
uint64 total_voting_power = 1;
uint64 total_bonded_sat = 1;
// finality_providers is a list of finality providers' voting power information
repeated FinalityProviderDistInfo finality_providers = 2;
// num_active_fps is the number of finality providers that have active BTC
Expand All @@ -32,8 +32,8 @@ message FinalityProviderDistInfo {
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec"
];
// total_voting_power is the total voting power of the finality provider
uint64 total_voting_power = 4;
// total_bonded_sat is the total amount of bonded BTC stake (in Satoshi) of the finality provider
uint64 total_bonded_sat = 4;
// btc_dels is a list of BTC delegations' voting power information under this finality provider
repeated BTCDelDistInfo btc_dels = 5;
// is_timestamped indicates whether the finality provider
Expand All @@ -48,7 +48,7 @@ message FinalityProviderDistInfo {
bool is_slashed = 8;
}

// BTCDelDistInfo contains the information related to reward distribution for a BTC delegation
// BTCDelDistInfo contains the information related to voting power distribution for a BTC delegation
message BTCDelDistInfo {
// btc_pk is the Bitcoin secp256k1 PK of this BTC delegation
// the PK follows encoding in BIP-340 spec
Expand All @@ -57,6 +57,6 @@ message BTCDelDistInfo {
string staker_addr = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// staking_tx_hash is the staking tx hash of the BTC delegation
string staking_tx_hash = 3;
// voting_power is the voting power of the BTC delegation
uint64 voting_power = 4;
// total_sat is the amount of BTC stake (in Satoshi) of the BTC delegation
uint64 total_sat = 4;
}
8 changes: 4 additions & 4 deletions testutil/datagen/incentive.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ func GenRandomBTCDelDistInfo(r *rand.Rand) (*bstypes.BTCDelDistInfo, error) {
return nil, err
}
return &bstypes.BTCDelDistInfo{
BtcPk: btcPK,
StakerAddr: GenRandomAccount().Address,
VotingPower: RandomInt(r, 1000) + 1,
BtcPk: btcPK,
StakerAddr: GenRandomAccount().Address,
TotalSat: RandomInt(r, 1000) + 1,
}, nil
}

Expand All @@ -105,7 +105,7 @@ func GenRandomFinalityProviderDistInfo(r *rand.Rand) (*bstypes.FinalityProviderD
return nil, err
}
fpDistInfo.BtcDels = append(fpDistInfo.BtcDels, btcDelDistInfo)
fpDistInfo.TotalVotingPower += btcDelDistInfo.VotingPower
fpDistInfo.TotalBondedSat += btcDelDistInfo.TotalSat
fpDistInfo.IsTimestamped = true
}
return fpDistInfo, nil
Expand Down
6 changes: 3 additions & 3 deletions x/btcstaking/keeper/incentive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ func FuzzRecordVotingPowerDistCache(f *testing.F) {
dc, err := h.BTCStakingKeeper.GetVotingPowerDistCache(h.Ctx, babylonHeight)
require.NoError(t, err)
require.NotNil(t, dc)
require.Equal(t, dc.TotalVotingPower, numFpsWithVotingPower*numBTCDels*stakingValue)
require.Equal(t, dc.TotalBondedSat, numFpsWithVotingPower*numBTCDels*stakingValue)
activeFPs := dc.GetActiveFinalityProviderSet()
for _, fpDistInfo := range activeFPs {
require.Equal(t, fpDistInfo.TotalVotingPower, numBTCDels*stakingValue)
require.Equal(t, fpDistInfo.TotalBondedSat, numBTCDels*stakingValue)
fp, ok := fpsWithVotingPowerMap[fpDistInfo.Addr]
require.True(t, ok)
require.Equal(t, fpDistInfo.Commission, fp.Commission)
require.Len(t, fpDistInfo.BtcDels, int(numBTCDels))
for _, delDistInfo := range fpDistInfo.BtcDels {
require.Equal(t, delDistInfo.VotingPower, stakingValue)
require.Equal(t, delDistInfo.TotalSat, stakingValue)
}
}
})
Expand Down
10 changes: 5 additions & 5 deletions x/btcstaking/keeper/power_dist_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (k Keeper) recordVotingPowerAndCache(ctx context.Context, newDc *types.Voti
// set voting power table for each active finality providers at this height
for i := uint32(0); i < newDc.NumActiveFps; i++ {
fp := newDc.FinalityProviders[i]
k.SetVotingPower(ctx, fp.BtcPk.MustMarshal(), babylonTipHeight, fp.TotalVotingPower)
k.SetVotingPower(ctx, fp.BtcPk.MustMarshal(), babylonTipHeight, fp.TotalBondedSat)
}

// set the voting power distribution cache of the current height
Expand Down Expand Up @@ -132,7 +132,7 @@ func (k Keeper) recordMetrics(dc *types.VotingPowerDistCache) {
// staked Satoshi
stakedSats := btcutil.Amount(0)
for _, fp := range dc.FinalityProviders {
stakedSats += btcutil.Amount(fp.TotalVotingPower)
stakedSats += btcutil.Amount(fp.TotalBondedSat)
}
numStakedBTCs := stakedSats.ToBTC()
types.RecordMetricsKeyStakedBitcoins(float32(numStakedBTCs))
Expand Down Expand Up @@ -218,7 +218,7 @@ func (k Keeper) ProcessAllPowerDistUpdateEvents(
for i := range dc.FinalityProviders {
// create a copy of the finality provider
fp := *dc.FinalityProviders[i]
fp.TotalVotingPower = 0
fp.TotalBondedSat = 0
fp.BtcDels = []*types.BTCDelDistInfo{}

fpBTCPKHex := fp.BtcPk.MarshalHex()
Expand Down Expand Up @@ -263,7 +263,7 @@ func (k Keeper) ProcessAllPowerDistUpdateEvents(
}

// add this finality provider to the new cache if it has voting power
if fp.TotalVotingPower > 0 {
if fp.TotalBondedSat > 0 {
newDc.AddFinalityProviderDistInfo(&fp)
}
}
Expand Down Expand Up @@ -299,7 +299,7 @@ func (k Keeper) ProcessAllPowerDistUpdateEvents(
}

// add this finality provider to the new cache if it has voting power
if fpDistInfo.TotalVotingPower > 0 {
if fpDistInfo.TotalBondedSat > 0 {
newDc.AddFinalityProviderDistInfo(fpDistInfo)
}
}
Expand Down
4 changes: 2 additions & 2 deletions 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) {

// 30 percent not have timestamped randomness, which causes
// zero voting power in the table
fpDistInfo := &types.FinalityProviderDistInfo{BtcPk: fp.BtcPk, TotalVotingPower: stakingValue}
fpDistInfo := &types.FinalityProviderDistInfo{BtcPk: fp.BtcPk, TotalBondedSat: stakingValue}
if r.Intn(10) <= 2 {
finalityKeeper.EXPECT().HasTimestampedPubRand(gomock.Any(), fp.BtcPk, gomock.Any()).Return(false).AnyTimes()
noTimestampedFps[fp.BtcPk.MarshalHex()] = true
Expand All @@ -229,7 +229,7 @@ func FuzzVotingPowerTable_ActiveFinalityProviders(f *testing.F) {
expectedActiveFps := fpsWithMeta[:min(uint32(len(fpsWithMeta)-len(noTimestampedFps)), maxActiveFpsParam)]
expectedActiveFpsMap := map[string]uint64{}
for _, fp := range expectedActiveFps {
expectedActiveFpsMap[fp.BtcPk.MarshalHex()] = fp.TotalVotingPower
expectedActiveFpsMap[fp.BtcPk.MarshalHex()] = fp.TotalBondedSat
}

// record voting power table
Expand Down
4 changes: 2 additions & 2 deletions x/btcstaking/types/btcstaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ func SortFinalityProvidersWithZeroedVotingPower(fps []*FinalityProviderDistInfo)
}

// both voting power the same, compare BTC public keys
if fps[i].TotalVotingPower == fps[j].TotalVotingPower {
if fps[i].TotalBondedSat == fps[j].TotalBondedSat {
return iPkHex < jPkHex
}

return fps[i].TotalVotingPower > fps[j].TotalVotingPower
return fps[i].TotalBondedSat > fps[j].TotalBondedSat
})
}

Expand Down
72 changes: 36 additions & 36 deletions x/btcstaking/types/btcstaking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,55 +20,55 @@ func TestSortFinalityProvidersWithZeroedVotingPower(t *testing.T) {
{
name: "Sort by voting power",
fps: []*types.FinalityProviderDistInfo{
{Addr: "fp1", TotalVotingPower: 100, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x03}},
{Addr: "fp2", TotalVotingPower: 200, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x02}},
{Addr: "fp3", TotalVotingPower: 150, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x01}},
{Addr: "fp1", TotalBondedSat: 100, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x03}},
{Addr: "fp2", TotalBondedSat: 200, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x02}},
{Addr: "fp3", TotalBondedSat: 150, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x01}},
},
expected: []*types.FinalityProviderDistInfo{
{Addr: "fp2", TotalVotingPower: 200, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x02}},
{Addr: "fp3", TotalVotingPower: 150, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x01}},
{Addr: "fp1", TotalVotingPower: 100, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x03}},
{Addr: "fp2", TotalBondedSat: 200, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x02}},
{Addr: "fp3", TotalBondedSat: 150, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x01}},
{Addr: "fp1", TotalBondedSat: 100, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x03}},
},
},
{
name: "Jailed and non-timestamped providers at the end",
fps: []*types.FinalityProviderDistInfo{
{Addr: "fp1", TotalVotingPower: 100, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x04}},
{Addr: "fp2", TotalVotingPower: 200, IsJailed: true, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x02}},
{Addr: "fp3", TotalVotingPower: 150, IsJailed: false, IsTimestamped: false, BtcPk: &bbn.BIP340PubKey{0x03}},
{Addr: "fp4", TotalVotingPower: 50, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x01}},
{Addr: "fp1", TotalBondedSat: 100, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x04}},
{Addr: "fp2", TotalBondedSat: 200, IsJailed: true, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x02}},
{Addr: "fp3", TotalBondedSat: 150, IsJailed: false, IsTimestamped: false, BtcPk: &bbn.BIP340PubKey{0x03}},
{Addr: "fp4", TotalBondedSat: 50, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x01}},
},
expected: []*types.FinalityProviderDistInfo{
{Addr: "fp1", TotalVotingPower: 100, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x04}},
{Addr: "fp4", TotalVotingPower: 50, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x01}},
{Addr: "fp2", TotalVotingPower: 200, IsJailed: true, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x02}},
{Addr: "fp3", TotalVotingPower: 150, IsJailed: false, IsTimestamped: false, BtcPk: &bbn.BIP340PubKey{0x03}},
{Addr: "fp1", TotalBondedSat: 100, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x04}},
{Addr: "fp4", TotalBondedSat: 50, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x01}},
{Addr: "fp2", TotalBondedSat: 200, IsJailed: true, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x02}},
{Addr: "fp3", TotalBondedSat: 150, IsJailed: false, IsTimestamped: false, BtcPk: &bbn.BIP340PubKey{0x03}},
},
},
{
name: "Equal voting power, sort by BTC public key",
fps: []*types.FinalityProviderDistInfo{
{Addr: "fp1", TotalVotingPower: 100, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x03}},
{Addr: "fp2", TotalVotingPower: 100, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x01}},
{Addr: "fp3", TotalVotingPower: 100, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x02}},
{Addr: "fp1", TotalBondedSat: 100, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x03}},
{Addr: "fp2", TotalBondedSat: 100, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x01}},
{Addr: "fp3", TotalBondedSat: 100, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x02}},
},
expected: []*types.FinalityProviderDistInfo{
{Addr: "fp2", TotalVotingPower: 100, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x01}},
{Addr: "fp3", TotalVotingPower: 100, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x02}},
{Addr: "fp1", TotalVotingPower: 100, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x03}},
{Addr: "fp2", TotalBondedSat: 100, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x01}},
{Addr: "fp3", TotalBondedSat: 100, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x02}},
{Addr: "fp1", TotalBondedSat: 100, IsJailed: false, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x03}},
},
},
{
name: "Zeroed voting power, sort by BTC public key",
fps: []*types.FinalityProviderDistInfo{
{Addr: "fp1", TotalVotingPower: 200, IsJailed: true, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x03}},
{Addr: "fp2", TotalVotingPower: 150, IsJailed: false, IsTimestamped: false, BtcPk: &bbn.BIP340PubKey{0x01}},
{Addr: "fp3", TotalVotingPower: 100, IsJailed: true, IsTimestamped: false, BtcPk: &bbn.BIP340PubKey{0x02}},
{Addr: "fp1", TotalBondedSat: 200, IsJailed: true, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x03}},
{Addr: "fp2", TotalBondedSat: 150, IsJailed: false, IsTimestamped: false, BtcPk: &bbn.BIP340PubKey{0x01}},
{Addr: "fp3", TotalBondedSat: 100, IsJailed: true, IsTimestamped: false, BtcPk: &bbn.BIP340PubKey{0x02}},
},
expected: []*types.FinalityProviderDistInfo{
{Addr: "fp2", TotalVotingPower: 150, IsJailed: false, IsTimestamped: false, BtcPk: &bbn.BIP340PubKey{0x01}},
{Addr: "fp3", TotalVotingPower: 100, IsJailed: true, IsTimestamped: false, BtcPk: &bbn.BIP340PubKey{0x02}},
{Addr: "fp1", TotalVotingPower: 200, IsJailed: true, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x03}},
{Addr: "fp2", TotalBondedSat: 150, IsJailed: false, IsTimestamped: false, BtcPk: &bbn.BIP340PubKey{0x01}},
{Addr: "fp3", TotalBondedSat: 100, IsJailed: true, IsTimestamped: false, BtcPk: &bbn.BIP340PubKey{0x02}},
{Addr: "fp1", TotalBondedSat: 200, IsJailed: true, IsTimestamped: true, BtcPk: &bbn.BIP340PubKey{0x03}},
},
},
}
Expand Down Expand Up @@ -107,11 +107,11 @@ func FuzzSortingDeterminism(f *testing.F) {
require.NoError(t, err)

fpsWithMeta := []*types.FinalityProviderDistInfo{
{TotalVotingPower: vp0, IsJailed: false, IsTimestamped: true, Addr: "addr0", BtcPk: pk1},
{TotalVotingPower: vp1, IsJailed: false, IsTimestamped: true, Addr: "addr1", BtcPk: pk2},
{TotalVotingPower: vp2, IsJailed: false, IsTimestamped: true, Addr: "addr2", BtcPk: pk3},
{TotalVotingPower: vp3, IsJailed: false, IsTimestamped: true, Addr: "addr3", BtcPk: pk4},
{TotalVotingPower: vp4, IsJailed: false, IsTimestamped: true, Addr: "addr4", BtcPk: pk5},
{TotalBondedSat: vp0, IsJailed: false, IsTimestamped: true, Addr: "addr0", BtcPk: pk1},
{TotalBondedSat: vp1, IsJailed: false, IsTimestamped: true, Addr: "addr1", BtcPk: pk2},
{TotalBondedSat: vp2, IsJailed: false, IsTimestamped: true, Addr: "addr2", BtcPk: pk3},
{TotalBondedSat: vp3, IsJailed: false, IsTimestamped: true, Addr: "addr3", BtcPk: pk4},
{TotalBondedSat: vp4, IsJailed: false, IsTimestamped: true, Addr: "addr4", BtcPk: pk5},
}
jailedIdx := datagen.RandomInt(r, len(fpsWithMeta))
noTimestampedIdx := datagen.RandomIntOtherThan(r, int(jailedIdx), len(fpsWithMeta))
Expand All @@ -122,11 +122,11 @@ func FuzzSortingDeterminism(f *testing.F) {
fpsWithMeta[noTimestampedIdx].IsTimestamped = false

fpsWithMeta1 := []*types.FinalityProviderDistInfo{
{TotalVotingPower: vp0, IsJailed: false, IsTimestamped: true, Addr: "addr0", BtcPk: pk1},
{TotalVotingPower: vp1, IsJailed: false, IsTimestamped: true, Addr: "addr1", BtcPk: pk2},
{TotalVotingPower: vp2, IsJailed: false, IsTimestamped: true, Addr: "addr2", BtcPk: pk3},
{TotalVotingPower: vp3, IsJailed: false, IsTimestamped: true, Addr: "addr3", BtcPk: pk4},
{TotalVotingPower: vp4, IsJailed: false, IsTimestamped: true, Addr: "addr4", BtcPk: pk5},
{TotalBondedSat: vp0, IsJailed: false, IsTimestamped: true, Addr: "addr0", BtcPk: pk1},
{TotalBondedSat: vp1, IsJailed: false, IsTimestamped: true, Addr: "addr1", BtcPk: pk2},
{TotalBondedSat: vp2, IsJailed: false, IsTimestamped: true, Addr: "addr2", BtcPk: pk3},
{TotalBondedSat: vp3, IsJailed: false, IsTimestamped: true, Addr: "addr3", BtcPk: pk4},
{TotalBondedSat: vp4, IsJailed: false, IsTimestamped: true, Addr: "addr4", BtcPk: pk5},
}

fpsWithMeta1[jailedIdx].IsJailed = true
Expand Down
36 changes: 18 additions & 18 deletions x/btcstaking/types/incentive.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

func NewVotingPowerDistCache() *VotingPowerDistCache {
return &VotingPowerDistCache{
TotalVotingPower: 0,
TotalBondedSat: 0,
FinalityProviders: []*FinalityProviderDistInfo{},
}
}
Expand Down Expand Up @@ -74,7 +74,7 @@ func (dc *VotingPowerDistCache) ApplyActiveFinalityProviders(maxActiveFPs uint32
if numActiveFPs == maxActiveFPs {
break
}
if fp.TotalVotingPower == 0 {
if fp.TotalBondedSat == 0 {
break
}
if !fp.IsTimestamped {
Expand All @@ -86,13 +86,13 @@ func (dc *VotingPowerDistCache) ApplyActiveFinalityProviders(maxActiveFPs uint32
numActiveFPs++
}

totalVotingPower := uint64(0)
TotalBondedSat := uint64(0)

for i := uint32(0); i < numActiveFPs; i++ {
totalVotingPower += dc.FinalityProviders[i].TotalVotingPower
TotalBondedSat += dc.FinalityProviders[i].TotalBondedSat
}

dc.TotalVotingPower = totalVotingPower
dc.TotalBondedSat = TotalBondedSat
dc.NumActiveFps = numActiveFPs
}

Expand Down Expand Up @@ -138,32 +138,32 @@ func (dc *VotingPowerDistCache) GetInactiveFinalityProviderSet() map[string]*Fin
func (dc *VotingPowerDistCache) FilterVotedDistCache(voterBTCPKs map[string]struct{}) *VotingPowerDistCache {
activeFPs := dc.GetActiveFinalityProviderSet()
var filteredFps []*FinalityProviderDistInfo
totalVotingPower := uint64(0)
TotalBondedSat := uint64(0)
for k, v := range activeFPs {
if _, ok := voterBTCPKs[k]; ok {
filteredFps = append(filteredFps, v)
totalVotingPower += v.TotalVotingPower
TotalBondedSat += v.TotalBondedSat
}
}

return &VotingPowerDistCache{
FinalityProviders: filteredFps,
TotalVotingPower: totalVotingPower,
TotalBondedSat: TotalBondedSat,
}
}

// GetFinalityProviderPortion returns the portion of a finality provider's voting power out of the total voting power
func (dc *VotingPowerDistCache) GetFinalityProviderPortion(v *FinalityProviderDistInfo) sdkmath.LegacyDec {
return sdkmath.LegacyNewDec(int64(v.TotalVotingPower)).QuoTruncate(sdkmath.LegacyNewDec(int64(dc.TotalVotingPower)))
return sdkmath.LegacyNewDec(int64(v.TotalBondedSat)).QuoTruncate(sdkmath.LegacyNewDec(int64(dc.TotalBondedSat)))
}

func NewFinalityProviderDistInfo(fp *FinalityProvider) *FinalityProviderDistInfo {
return &FinalityProviderDistInfo{
BtcPk: fp.BtcPk,
Addr: fp.Addr,
Commission: fp.Commission,
TotalVotingPower: 0,
BtcDels: []*BTCDelDistInfo{},
BtcPk: fp.BtcPk,
Addr: fp.Addr,
Commission: fp.Commission,
TotalBondedSat: 0,
BtcDels: []*BTCDelDistInfo{},
}
}

Expand All @@ -176,21 +176,21 @@ func (v *FinalityProviderDistInfo) AddBTCDel(btcDel *BTCDelegation) {
BtcPk: btcDel.BtcPk,
StakerAddr: btcDel.StakerAddr,
StakingTxHash: btcDel.MustGetStakingTxHash().String(),
VotingPower: btcDel.TotalSat,
TotalSat: btcDel.TotalSat,
}
v.BtcDels = append(v.BtcDels, btcDelDistInfo)
v.TotalVotingPower += btcDelDistInfo.VotingPower
v.TotalBondedSat += btcDelDistInfo.TotalSat
}

func (v *FinalityProviderDistInfo) AddBTCDelDistInfo(d *BTCDelDistInfo) {
v.BtcDels = append(v.BtcDels, d)
v.TotalVotingPower += d.VotingPower
v.TotalBondedSat += d.TotalSat
}

// GetBTCDelPortion returns the portion of a BTC delegation's voting power out of
// the finality provider's total voting power
func (v *FinalityProviderDistInfo) GetBTCDelPortion(d *BTCDelDistInfo) sdkmath.LegacyDec {
return sdkmath.LegacyNewDec(int64(d.VotingPower)).QuoTruncate(sdkmath.LegacyNewDec(int64(v.TotalVotingPower)))
return sdkmath.LegacyNewDec(int64(d.TotalSat)).QuoTruncate(sdkmath.LegacyNewDec(int64(v.TotalBondedSat)))
}

func (d *BTCDelDistInfo) GetAddress() sdk.AccAddress {
Expand Down
Loading
Loading