From 13395636820a3a68b07a33fe8a4a4461e034a318 Mon Sep 17 00:00:00 2001 From: Runchao Han Date: Thu, 17 Oct 2024 16:14:27 +1100 Subject: [PATCH 1/2] init --- proto/babylon/btcstaking/v1/incentive.proto | 14 +- testutil/datagen/incentive.go | 8 +- x/btcstaking/keeper/incentive_test.go | 6 +- x/btcstaking/keeper/power_dist_change.go | 10 +- .../keeper/voting_power_table_test.go | 4 +- x/btcstaking/types/btcstaking.go | 4 +- x/btcstaking/types/btcstaking_test.go | 72 ++++----- x/btcstaking/types/incentive.go | 36 ++--- x/btcstaking/types/incentive.pb.go | 142 +++++++++--------- x/btcstaking/types/incentive_test.go | 94 ++++++------ 10 files changed, 195 insertions(+), 195 deletions(-) diff --git a/proto/babylon/btcstaking/v1/incentive.proto b/proto/babylon/btcstaking/v1/incentive.proto index 795f724d0..3671d874c 100644 --- a/proto/babylon/btcstaking/v1/incentive.proto +++ b/proto/babylon/btcstaking/v1/incentive.proto @@ -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 @@ -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 @@ -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 @@ -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; } diff --git a/testutil/datagen/incentive.go b/testutil/datagen/incentive.go index d379e82ba..15e17bc81 100644 --- a/testutil/datagen/incentive.go +++ b/testutil/datagen/incentive.go @@ -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 } @@ -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 diff --git a/x/btcstaking/keeper/incentive_test.go b/x/btcstaking/keeper/incentive_test.go index bd77243b2..3614fe3ff 100644 --- a/x/btcstaking/keeper/incentive_test.go +++ b/x/btcstaking/keeper/incentive_test.go @@ -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) } } }) diff --git a/x/btcstaking/keeper/power_dist_change.go b/x/btcstaking/keeper/power_dist_change.go index 1852c2f0c..6a0097ad5 100644 --- a/x/btcstaking/keeper/power_dist_change.go +++ b/x/btcstaking/keeper/power_dist_change.go @@ -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 @@ -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)) @@ -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() @@ -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) } } @@ -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) } } diff --git a/x/btcstaking/keeper/voting_power_table_test.go b/x/btcstaking/keeper/voting_power_table_test.go index 2883c6c3b..b356b35f7 100644 --- a/x/btcstaking/keeper/voting_power_table_test.go +++ b/x/btcstaking/keeper/voting_power_table_test.go @@ -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 @@ -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 diff --git a/x/btcstaking/types/btcstaking.go b/x/btcstaking/types/btcstaking.go index 9279adc3f..2453c5f2a 100644 --- a/x/btcstaking/types/btcstaking.go +++ b/x/btcstaking/types/btcstaking.go @@ -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 }) } diff --git a/x/btcstaking/types/btcstaking_test.go b/x/btcstaking/types/btcstaking_test.go index e42e75693..2daf00c18 100644 --- a/x/btcstaking/types/btcstaking_test.go +++ b/x/btcstaking/types/btcstaking_test.go @@ -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}}, }, }, } @@ -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)) @@ -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 diff --git a/x/btcstaking/types/incentive.go b/x/btcstaking/types/incentive.go index 9d3e0d124..caf658512 100644 --- a/x/btcstaking/types/incentive.go +++ b/x/btcstaking/types/incentive.go @@ -7,7 +7,7 @@ import ( func NewVotingPowerDistCache() *VotingPowerDistCache { return &VotingPowerDistCache{ - TotalVotingPower: 0, + TotalBondedSat: 0, FinalityProviders: []*FinalityProviderDistInfo{}, } } @@ -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 { @@ -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 } @@ -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{}, } } @@ -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 { diff --git a/x/btcstaking/types/incentive.pb.go b/x/btcstaking/types/incentive.pb.go index 79633f964..557cd62c0 100644 --- a/x/btcstaking/types/incentive.pb.go +++ b/x/btcstaking/types/incentive.pb.go @@ -29,9 +29,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // VotingPowerDistCache is the cache for voting power distribution of finality providers // and their BTC delegations at a height type VotingPowerDistCache struct { - // 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 - TotalVotingPower uint64 `protobuf:"varint,1,opt,name=total_voting_power,json=totalVotingPower,proto3" json:"total_voting_power,omitempty"` + TotalBondedSat uint64 `protobuf:"varint,1,opt,name=total_bonded_sat,json=totalBondedSat,proto3" json:"total_bonded_sat,omitempty"` // finality_providers is a list of finality providers' voting power information FinalityProviders []*FinalityProviderDistInfo `protobuf:"bytes,2,rep,name=finality_providers,json=finalityProviders,proto3" json:"finality_providers,omitempty"` // num_active_fps is the number of finality providers that have active BTC @@ -81,8 +81,8 @@ type FinalityProviderDistInfo struct { Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` // commission defines the commission rate of finality provider Commission *cosmossdk_io_math.LegacyDec `protobuf:"bytes,3,opt,name=commission,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"commission,omitempty"` - // total_voting_power is the total voting power of the finality provider - TotalVotingPower uint64 `protobuf:"varint,4,opt,name=total_voting_power,json=totalVotingPower,proto3" json:"total_voting_power,omitempty"` + // total_bonded_sat is the total amount of bonded BTC stake (in Satoshi) of the finality provider + TotalBondedSat uint64 `protobuf:"varint,4,opt,name=total_bonded_sat,json=totalBondedSat,proto3" json:"total_bonded_sat,omitempty"` // btc_dels is a list of BTC delegations' voting power information under this finality provider BtcDels []*BTCDelDistInfo `protobuf:"bytes,5,rep,name=btc_dels,json=btcDels,proto3" json:"btc_dels,omitempty"` // is_timestamped indicates whether the finality provider @@ -137,9 +137,9 @@ func (m *FinalityProviderDistInfo) GetAddr() string { return "" } -func (m *FinalityProviderDistInfo) GetTotalVotingPower() uint64 { +func (m *FinalityProviderDistInfo) GetTotalBondedSat() uint64 { if m != nil { - return m.TotalVotingPower + return m.TotalBondedSat } return 0 } @@ -172,7 +172,7 @@ func (m *FinalityProviderDistInfo) GetIsSlashed() bool { return false } -// 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 type BTCDelDistInfo struct { // btc_pk is the Bitcoin secp256k1 PK of this BTC delegation // the PK follows encoding in BIP-340 spec @@ -181,8 +181,8 @@ type BTCDelDistInfo struct { StakerAddr string `protobuf:"bytes,2,opt,name=staker_addr,json=stakerAddr,proto3" json:"staker_addr,omitempty"` // staking_tx_hash is the staking tx hash of the BTC delegation StakingTxHash string `protobuf:"bytes,3,opt,name=staking_tx_hash,json=stakingTxHash,proto3" json:"staking_tx_hash,omitempty"` - // voting_power is the voting power of the BTC delegation - VotingPower uint64 `protobuf:"varint,4,opt,name=voting_power,json=votingPower,proto3" json:"voting_power,omitempty"` + // total_sat is the amount of BTC stake (in Satoshi) of the BTC delegation + TotalSat uint64 `protobuf:"varint,4,opt,name=total_sat,json=totalSat,proto3" json:"total_sat,omitempty"` } func (m *BTCDelDistInfo) Reset() { *m = BTCDelDistInfo{} } @@ -232,9 +232,9 @@ func (m *BTCDelDistInfo) GetStakingTxHash() string { return "" } -func (m *BTCDelDistInfo) GetVotingPower() uint64 { +func (m *BTCDelDistInfo) GetTotalSat() uint64 { if m != nil { - return m.VotingPower + return m.TotalSat } return 0 } @@ -250,45 +250,45 @@ func init() { } var fileDescriptor_ac354c3bd6d7a66b = []byte{ - // 602 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xcd, 0x6e, 0xd3, 0x4c, - 0x14, 0x8d, 0xdb, 0xb4, 0x4d, 0xa6, 0x3f, 0xdf, 0xc7, 0xa8, 0x48, 0xa6, 0x15, 0x69, 0xa8, 0x28, - 0xca, 0xa2, 0xb1, 0x29, 0xed, 0x02, 0x58, 0xd1, 0x34, 0xaa, 0x28, 0xbf, 0x91, 0x5b, 0xb1, 0x60, - 0xc1, 0x68, 0x3c, 0x9e, 0xd8, 0x43, 0x6c, 0x8f, 0xe5, 0x3b, 0x09, 0xcd, 0x1b, 0xb0, 0xe4, 0x11, - 0x78, 0x88, 0xee, 0x78, 0x01, 0x96, 0x55, 0x57, 0xa8, 0x8b, 0x0a, 0xb5, 0x0b, 0x5e, 0x03, 0x79, - 0x6c, 0x68, 0x40, 0x8d, 0xd4, 0x05, 0xbb, 0xdc, 0x73, 0xce, 0xbd, 0x77, 0xce, 0x3d, 0x8a, 0xd1, - 0x9a, 0x4b, 0xdd, 0x61, 0x28, 0x63, 0xdb, 0x55, 0x0c, 0x14, 0xed, 0x89, 0xd8, 0xb7, 0x07, 0x1b, - 0xb6, 0x88, 0x19, 0x8f, 0x95, 0x18, 0x70, 0x2b, 0x49, 0xa5, 0x92, 0xf8, 0x66, 0x21, 0xb3, 0x2e, - 0x65, 0xd6, 0x60, 0x63, 0x69, 0xd1, 0x97, 0xbe, 0xd4, 0x0a, 0x3b, 0xfb, 0x95, 0x8b, 0x97, 0x6e, - 0x31,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5, 0x3a, 0x3d, 0xbc, 0x8e, 0xca, 0xd4, 0xf3, 0x52, - 0x73, 0xa2, 0x6e, 0x34, 0xaa, 0x2d, 0xf3, 0xe4, 0xa8, 0xb9, 0x58, 0x1c, 0x78, 0xdb, 0xf3, 0x52, - 0x0e, 0xb0, 0xaf, 0x52, 0x11, 0xfb, 0x8e, 0x56, 0xe1, 0x97, 0x08, 0x31, 0x19, 0x45, 0x02, 0x40, - 0xc8, 0x58, 0x7b, 0xa8, 0xb6, 0x9a, 0xa7, 0x67, 0x2b, 0xcb, 0x79, 0x0f, 0x78, 0x3d, 0x4b, 0x48, - 0x3b, 0xa2, 0x2a, 0xb0, 0x5e, 0x70, 0x9f, 0xb2, 0x61, 0x9b, 0xb3, 0x93, 0xa3, 0x26, 0x2a, 0x46, - 0xb6, 0x39, 0x73, 0x46, 0x06, 0x8c, 0x09, 0xa9, 0x3c, 0x26, 0xa4, 0x27, 0xa8, 0x92, 0x79, 0xf7, - 0x78, 0x08, 0xe6, 0x94, 0x8e, 0x66, 0x6d, 0x4c, 0x34, 0xad, 0x83, 0x9d, 0x36, 0x0f, 0x7f, 0x07, - 0x32, 0xe3, 0x2a, 0xd6, 0xe6, 0x21, 0xe0, 0x35, 0xb4, 0x20, 0x80, 0x28, 0x11, 0x71, 0x50, 0x34, - 0x4a, 0xb8, 0x67, 0x4e, 0xd7, 0x8d, 0x46, 0xc5, 0x99, 0x17, 0x70, 0x70, 0x09, 0xe2, 0x65, 0x54, - 0x15, 0x40, 0xde, 0x53, 0x11, 0x72, 0xcf, 0x9c, 0xd1, 0x8a, 0x8a, 0x80, 0x67, 0xba, 0xc6, 0xb7, - 0x11, 0x12, 0x40, 0x20, 0xa4, 0x10, 0x70, 0xcf, 0xac, 0x68, 0xb6, 0x2a, 0x60, 0x3f, 0x07, 0x56, - 0x7f, 0x18, 0x68, 0xe1, 0xcf, 0xf5, 0xff, 0x3e, 0xb3, 0x47, 0x68, 0x36, 0x33, 0xcb, 0x53, 0x72, - 0xad, 0xe8, 0x50, 0x2e, 0xce, 0x40, 0x7c, 0x0f, 0xfd, 0x57, 0xdc, 0x89, 0xa8, 0x43, 0x12, 0x50, - 0x08, 0xf2, 0x14, 0x9d, 0xf9, 0x02, 0x3e, 0x38, 0x7c, 0x4a, 0x21, 0xc0, 0x77, 0xd0, 0xdc, 0x15, - 0x99, 0xcc, 0x0e, 0x2e, 0xe3, 0x68, 0xbd, 0xfa, 0x7a, 0x5e, 0x33, 0x8e, 0xcf, 0x6b, 0xc6, 0xf7, - 0xf3, 0x9a, 0xf1, 0xe9, 0xa2, 0x56, 0x3a, 0xbe, 0xa8, 0x95, 0xbe, 0x5d, 0xd4, 0x4a, 0x6f, 0xaf, - 0x61, 0xee, 0x70, 0xf4, 0xfb, 0xa0, 0x9d, 0xba, 0xd3, 0xfa, 0x1f, 0xbd, 0xf9, 0x33, 0x00, 0x00, - 0xff, 0xff, 0xcd, 0xe5, 0x80, 0xc2, 0x42, 0x04, 0x00, 0x00, + // 606 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x94, 0x4f, 0x4f, 0x13, 0x41, + 0x18, 0xc6, 0xbb, 0x50, 0xa0, 0x1d, 0xa0, 0xea, 0x06, 0x93, 0x15, 0x62, 0x69, 0x88, 0x98, 0x1e, + 0xec, 0xae, 0x08, 0x07, 0xf5, 0x24, 0x4b, 0x43, 0xc4, 0xbf, 0xcd, 0x96, 0x78, 0xf0, 0xe0, 0x66, + 0x76, 0x66, 0xba, 0x3b, 0x76, 0x77, 0xa6, 0xd9, 0x77, 0x5a, 0xe9, 0x37, 0xf0, 0xe8, 0x47, 0xf0, + 0x43, 0x90, 0xf8, 0x15, 0x3c, 0x78, 0x20, 0x9c, 0x0c, 0x07, 0xa2, 0xf0, 0x45, 0xcc, 0xce, 0xae, + 0x82, 0x06, 0x12, 0x0e, 0xde, 0x3a, 0xcf, 0xfb, 0xcc, 0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xb5, 0xa6, 0x1b, 0x46, 0xb3, 0xe2, 0xcd, 0x73, 0xd8, 0x3d, 0x13, + 0xcd, 0x25, 0x54, 0xe5, 0xe0, 0xbf, 0xc7, 0x3c, 0x66, 0xd4, 0x9a, 0xd1, 0x8e, 0x0a, 0x87, 0x67, + 0xfa, 0x6c, 0xde, 0x46, 0x88, 0x83, 0x0f, 0x31, 0x86, 0x88, 0x51, 0xab, 0xa2, 0xab, 0x55, 0x0e, + 0xdd, 0x5c, 0x58, 0xf9, 0x69, 0xa0, 0xda, 0xdf, 0xe3, 0xff, 0x3f, 0xaf, 0x47, 0x68, 0x36, 0x0b, + 0xcb, 0x52, 0xff, 0x4a, 0xd8, 0x50, 0x6e, 0xce, 0x44, 0xf3, 0x2e, 0xba, 0x56, 0xec, 0xc9, 0x57, + 0x7b, 0x7e, 0x84, 0x21, 0xca, 0x09, 0x7a, 0xf3, 0x85, 0xbc, 0xbb, 0xf7, 0x14, 0x43, 0x94, 0xad, + 0x20, 0xa7, 0x72, 0x86, 0xa3, 0xa2, 0x85, 0x2e, 0x56, 0xee, 0xab, 0xaf, 0x27, 0x75, 0xe3, 0xe0, + 0xa4, 0x6e, 0xfc, 0x38, 0xa9, 0x1b, 0x9f, 0x4e, 0xeb, 0xa5, 0x83, 0xd3, 0x7a, 0xe9, 0xfb, 0x69, + 0xbd, 0xf4, 0xf6, 0x0a, 0xb1, 0xf6, 0xce, 0x7f, 0x11, 0x74, 0xc6, 0x60, 0x5a, 0xff, 0x87, 0xd7, + 0x7f, 0x05, 0x00, 0x00, 0xff, 0xff, 0x4b, 0xc9, 0x06, 0x18, 0x34, 0x04, 0x00, 0x00, } func (m *VotingPowerDistCache) Marshal() (dAtA []byte, err error) { @@ -330,8 +330,8 @@ func (m *VotingPowerDistCache) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0x12 } } - if m.TotalVotingPower != 0 { - i = encodeVarintIncentive(dAtA, i, uint64(m.TotalVotingPower)) + if m.TotalBondedSat != 0 { + i = encodeVarintIncentive(dAtA, i, uint64(m.TotalBondedSat)) i-- dAtA[i] = 0x8 } @@ -402,8 +402,8 @@ func (m *FinalityProviderDistInfo) MarshalToSizedBuffer(dAtA []byte) (int, error dAtA[i] = 0x2a } } - if m.TotalVotingPower != 0 { - i = encodeVarintIncentive(dAtA, i, uint64(m.TotalVotingPower)) + if m.TotalBondedSat != 0 { + i = encodeVarintIncentive(dAtA, i, uint64(m.TotalBondedSat)) i-- dAtA[i] = 0x20 } @@ -461,8 +461,8 @@ func (m *BTCDelDistInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.VotingPower != 0 { - i = encodeVarintIncentive(dAtA, i, uint64(m.VotingPower)) + if m.TotalSat != 0 { + i = encodeVarintIncentive(dAtA, i, uint64(m.TotalSat)) i-- dAtA[i] = 0x20 } @@ -512,8 +512,8 @@ func (m *VotingPowerDistCache) Size() (n int) { } var l int _ = l - if m.TotalVotingPower != 0 { - n += 1 + sovIncentive(uint64(m.TotalVotingPower)) + if m.TotalBondedSat != 0 { + n += 1 + sovIncentive(uint64(m.TotalBondedSat)) } if len(m.FinalityProviders) > 0 { for _, e := range m.FinalityProviders { @@ -545,8 +545,8 @@ func (m *FinalityProviderDistInfo) Size() (n int) { l = m.Commission.Size() n += 1 + l + sovIncentive(uint64(l)) } - if m.TotalVotingPower != 0 { - n += 1 + sovIncentive(uint64(m.TotalVotingPower)) + if m.TotalBondedSat != 0 { + n += 1 + sovIncentive(uint64(m.TotalBondedSat)) } if len(m.BtcDels) > 0 { for _, e := range m.BtcDels { @@ -584,8 +584,8 @@ func (m *BTCDelDistInfo) Size() (n int) { if l > 0 { n += 1 + l + sovIncentive(uint64(l)) } - if m.VotingPower != 0 { - n += 1 + sovIncentive(uint64(m.VotingPower)) + if m.TotalSat != 0 { + n += 1 + sovIncentive(uint64(m.TotalSat)) } return n } @@ -627,9 +627,9 @@ func (m *VotingPowerDistCache) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TotalVotingPower", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field TotalBondedSat", wireType) } - m.TotalVotingPower = 0 + m.TotalBondedSat = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowIncentive @@ -639,7 +639,7 @@ func (m *VotingPowerDistCache) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.TotalVotingPower |= uint64(b&0x7F) << shift + m.TotalBondedSat |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -852,9 +852,9 @@ func (m *FinalityProviderDistInfo) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 4: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TotalVotingPower", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field TotalBondedSat", wireType) } - m.TotalVotingPower = 0 + m.TotalBondedSat = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowIncentive @@ -864,7 +864,7 @@ func (m *FinalityProviderDistInfo) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.TotalVotingPower |= uint64(b&0x7F) << shift + m.TotalBondedSat |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1114,9 +1114,9 @@ func (m *BTCDelDistInfo) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 4: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field VotingPower", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field TotalSat", wireType) } - m.VotingPower = 0 + m.TotalSat = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowIncentive @@ -1126,7 +1126,7 @@ func (m *BTCDelDistInfo) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.VotingPower |= uint64(b&0x7F) << shift + m.TotalSat |= uint64(b&0x7F) << shift if b < 0x80 { break } diff --git a/x/btcstaking/types/incentive_test.go b/x/btcstaking/types/incentive_test.go index dd3851b22..d70995b62 100644 --- a/x/btcstaking/types/incentive_test.go +++ b/x/btcstaking/types/incentive_test.go @@ -35,14 +35,14 @@ func TestVotingPowerDistCache(t *testing.T) { prevDistCache: NewVotingPowerDistCache(), fps: []*FinalityProviderDistInfo{ { - BtcPk: fpPubKey1, - TotalVotingPower: 1000, - IsTimestamped: false, + BtcPk: fpPubKey1, + TotalBondedSat: 1000, + IsTimestamped: false, }, { - BtcPk: fpPubKey2, - TotalVotingPower: 2000, - IsTimestamped: false, + BtcPk: fpPubKey2, + TotalBondedSat: 2000, + IsTimestamped: false, }, }, }, @@ -55,14 +55,14 @@ func TestVotingPowerDistCache(t *testing.T) { prevDistCache: NewVotingPowerDistCache(), fps: []*FinalityProviderDistInfo{ { - BtcPk: fpPubKey1, - TotalVotingPower: 1000, - IsTimestamped: true, + BtcPk: fpPubKey1, + TotalBondedSat: 1000, + IsTimestamped: true, }, { - BtcPk: fpPubKey2, - TotalVotingPower: 2000, - IsTimestamped: true, + BtcPk: fpPubKey2, + TotalBondedSat: 2000, + IsTimestamped: true, }, }, }, @@ -75,14 +75,14 @@ func TestVotingPowerDistCache(t *testing.T) { prevDistCache: NewVotingPowerDistCache(), fps: []*FinalityProviderDistInfo{ { - BtcPk: fpPubKey1, - TotalVotingPower: 1000, - IsTimestamped: true, + BtcPk: fpPubKey1, + TotalBondedSat: 1000, + IsTimestamped: true, }, { - BtcPk: fpPubKey2, - TotalVotingPower: 2000, - IsTimestamped: false, + BtcPk: fpPubKey2, + TotalBondedSat: 2000, + IsTimestamped: false, }, }, }, @@ -95,14 +95,14 @@ func TestVotingPowerDistCache(t *testing.T) { prevDistCache: NewVotingPowerDistCache(), fps: []*FinalityProviderDistInfo{ { - BtcPk: fpPubKey1, - TotalVotingPower: 1000, - IsTimestamped: true, + BtcPk: fpPubKey1, + TotalBondedSat: 1000, + IsTimestamped: true, }, { - BtcPk: fpPubKey2, - TotalVotingPower: 2000, - IsTimestamped: true, + BtcPk: fpPubKey2, + TotalBondedSat: 2000, + IsTimestamped: true, }, }, }, @@ -115,15 +115,15 @@ func TestVotingPowerDistCache(t *testing.T) { prevDistCache: NewVotingPowerDistCache(), fps: []*FinalityProviderDistInfo{ { - BtcPk: fpPubKey1, - TotalVotingPower: 1000, - IsTimestamped: true, + BtcPk: fpPubKey1, + TotalBondedSat: 1000, + IsTimestamped: true, }, { - BtcPk: fpPubKey2, - TotalVotingPower: 2000, - IsTimestamped: true, - IsJailed: true, + BtcPk: fpPubKey2, + TotalBondedSat: 2000, + IsTimestamped: true, + IsJailed: true, }, }, }, @@ -136,15 +136,15 @@ func TestVotingPowerDistCache(t *testing.T) { prevDistCache: NewVotingPowerDistCache(), fps: []*FinalityProviderDistInfo{ { - BtcPk: fpPubKey1, - TotalVotingPower: 1000, - IsTimestamped: true, + BtcPk: fpPubKey1, + TotalBondedSat: 1000, + IsTimestamped: true, }, { - BtcPk: fpPubKey2, - TotalVotingPower: 0, // a jailed fp cannot accept delegation - IsTimestamped: true, - IsSlashed: true, + BtcPk: fpPubKey2, + TotalBondedSat: 0, // a jailed fp cannot accept delegation + IsTimestamped: true, + IsSlashed: true, }, }, }, @@ -157,17 +157,17 @@ func TestVotingPowerDistCache(t *testing.T) { prevDistCache: NewVotingPowerDistCacheWithFinalityProviders( []*FinalityProviderDistInfo{ { - BtcPk: fpPubKey1, - TotalVotingPower: 1000, - IsTimestamped: true, - IsJailed: true, + BtcPk: fpPubKey1, + TotalBondedSat: 1000, + IsTimestamped: true, + IsJailed: true, }}), fps: []*FinalityProviderDistInfo{ { - BtcPk: fpPubKey1, - TotalVotingPower: 1000, - IsTimestamped: true, - IsJailed: false, + BtcPk: fpPubKey1, + TotalBondedSat: 1000, + IsTimestamped: true, + IsJailed: false, }, }, }, @@ -176,7 +176,7 @@ func TestVotingPowerDistCache(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { dc := NewVotingPowerDistCacheWithFinalityProviders(tc.fps) dc.ApplyActiveFinalityProviders(tc.maxActiveFPs) - require.Equal(t, tc.totalVotingPower, dc.TotalVotingPower) + require.Equal(t, tc.totalVotingPower, dc.TotalBondedSat) require.Equal(t, tc.numActiveFps, dc.NumActiveFps) newActiveFps := dc.FindNewActiveFinalityProviders(tc.prevDistCache) From 47d8d6058bc8f663194bac6a3fb3064fab6dfdef Mon Sep 17 00:00:00 2001 From: Runchao Han Date: Thu, 17 Oct 2024 16:17:02 +1100 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f53bd689..de1a71940 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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