Skip to content

Commit

Permalink
rename to btc_staker
Browse files Browse the repository at this point in the history
  • Loading branch information
GAtom22 committed Feb 28, 2025
1 parent a86ddd4 commit 3206cfe
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 86 deletions.
8 changes: 4 additions & 4 deletions docs/register-bitcoin-stake.md
Original file line number Diff line number Diff line change
Expand Up @@ -690,18 +690,18 @@ Rewards can be withdrawn by submitting a `MsgWithdrawReward` message:
// MsgWithdrawReward defines a message for withdrawing reward of a stakeholder.
message MsgWithdrawReward {
option (cosmos.msg.v1.signer) = "address";
// {finality_provider, btc_delegation}
string type = 1;
// address is the address of the stakeholder in bech32 string
// signer of this msg has to be this address
string address = 2;
// Type of stakeholder (FINALITY_PROVIDER or BTC_STAKER)
StakeholderType type = 3;
}
```

The message defines the following fields:
* `type`: Specifies the stakeholder type for reward withdrawal. Allowed values:
* `finality_provider`
* `btc_delegation`
* `FINALITY_PROVIDER = 0`
* `BTC_STAKER = 1`
* `address`: The bech32 address of the stakeholder
(must match the signer of the message).

Expand Down
4 changes: 2 additions & 2 deletions proto/babylon/incentive/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ enum StakeholderType {
option (gogoproto.goproto_enum_prefix) = false;
// Finality provider stakeholder type
FINALITY_PROVIDER = 0;
// BTC delegation stakeholder type
BTC_DELEGATION = 1;
// BTC staker stakeholder type
BTC_STAKER = 1;
}
2 changes: 1 addition & 1 deletion proto/babylon/incentive/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ message MsgWithdrawReward {
// address is the address of the stakeholder in bech32 string
// signer of this msg has to be this address
string address = 2;
// Type of stakeholder (FINALITY_PROVIDER or BTC_DELEGATION)
// Type of stakeholder (FINALITY_PROVIDER or BTC_STAKER)
StakeholderType type = 3;
}

Expand Down
8 changes: 4 additions & 4 deletions test/e2e/btc_rewards_distribution_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,11 +709,11 @@ func (s *BtcRewardsDistribution) QueryRewardGauges(n *chain.NodeConfig) (
s.True(ok)
s.True(fp2RewardGauge.Coins.IsAllPositive())

btcDel1RewardGauge, ok := btcDel1RewardGauges[itypes.BTC_DELEGATION.String()]
btcDel1RewardGauge, ok := btcDel1RewardGauges[itypes.BTC_STAKER.String()]
s.True(ok)
s.True(btcDel1RewardGauge.Coins.IsAllPositive())

btcDel2RewardGauge, ok := btcDel2RewardGauges[itypes.BTC_DELEGATION.String()]
btcDel2RewardGauge, ok := btcDel2RewardGauges[itypes.BTC_STAKER.String()]
s.True(ok)
s.True(btcDel2RewardGauge.Coins.IsAllPositive())

Expand Down Expand Up @@ -743,7 +743,7 @@ func CheckWithdrawReward(
delBalanceBeforeWithdraw, err := n.QueryBalances(delAddr)
require.NoError(t, err)

txHash := n.WithdrawReward(itypes.BTC_DELEGATION.String(), delWallet)
txHash := n.WithdrawReward(itypes.BTC_STAKER.String(), delWallet)

n.WaitForNextBlock()

Expand All @@ -757,7 +757,7 @@ func CheckWithdrawReward(

// note that the rewards might not be precise as more or less blocks were produced and given out rewards
// while the query balance / withdraw / query gauge was running
delRewardGauge, ok := delRwdGauge[itypes.BTC_DELEGATION.String()]
delRewardGauge, ok := delRwdGauge[itypes.BTC_STAKER.String()]
require.True(t, ok)
require.True(t, delRewardGauge.Coins.IsAllPositive())

Expand Down
4 changes: 2 additions & 2 deletions test/e2e/btc_staking_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func (s *BTCStakingTestSuite) Test3CommitPublicRandomnessAndSubmitFinalitySignat
// ensure BTC delegation has received rewards after the block is finalised
btcDelRewardGauges, err := nonValidatorNode.QueryRewardGauge(delBabylonAddr)
s.NoError(err)
btcDelRewardGauge, ok := btcDelRewardGauges[itypes.BTC_DELEGATION.String()]
btcDelRewardGauge, ok := btcDelRewardGauges[itypes.BTC_STAKER.String()]
s.True(ok)
s.True(btcDelRewardGauge.Coins.IsAllPositive())
s.T().Logf("the finality provider received rewards for providing finality")
Expand All @@ -338,7 +338,7 @@ func (s *BTCStakingTestSuite) Test4WithdrawReward() {
s.NoError(err)

n.WithdrawRewardCheckingBalances(itypes.FINALITY_PROVIDER.String(), s.cacheFP.Addr)
n.WithdrawRewardCheckingBalances(itypes.BTC_DELEGATION.String(), s.cacheFP.Addr)
n.WithdrawRewardCheckingBalances(itypes.BTC_STAKER.String(), s.cacheFP.Addr)
}

// Test5SubmitStakerUnbonding is an end-to-end test for user unbonding
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/btc_staking_pre_approval_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func (s *BTCStakingPreApprovalTestSuite) Test4CommitPublicRandomnessAndSubmitFin
// ensure BTC delegation has received rewards after the block is finalised
btcDelRewardGauges, err := nonValidatorNode.QueryRewardGauge(delBabylonAddr)
s.NoError(err)
btcDelRewardGauge, ok := btcDelRewardGauges[itypes.BTC_DELEGATION.String()]
btcDelRewardGauge, ok := btcDelRewardGauges[itypes.BTC_STAKER.String()]
s.True(ok)
s.True(btcDelRewardGauge.Coins.IsAllPositive())
s.Require().Len(btcDelRewardGauge.Coins, 1)
Expand All @@ -417,7 +417,7 @@ func (s *BTCStakingPreApprovalTestSuite) Test4WithdrawReward() {
s.NoError(err)

n.WithdrawRewardCheckingBalances(itypes.FINALITY_PROVIDER.String(), s.cacheFP.Addr)
n.WithdrawRewardCheckingBalances(itypes.BTC_DELEGATION.String(), s.cacheFP.Addr)
n.WithdrawRewardCheckingBalances(itypes.BTC_STAKER.String(), s.cacheFP.Addr)
}

// Test5SubmitStakerUnbonding is an end-to-end test for user unbonding
Expand Down
6 changes: 3 additions & 3 deletions x/finality/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func FuzzCommitPubRandList(f *testing.F) {
require.NoError(t, err)

// Case 6: commit a pubrand list that overflows when adding startHeight + numPubRand
overflowStartHeight := math.MaxUint64 - datagen.RandomInt(r, 5)
overflowStartHeight := math.MaxUint64 - datagen.RandomInt(r, 5)
_, msg, err = datagen.GenRandomMsgCommitPubRandList(r, btcSK, overflowStartHeight, numPubRand)
require.NoError(t, err)
_, err = ms.CommitPubRandList(ctx, msg)
Expand Down Expand Up @@ -700,13 +700,13 @@ func TestBtcDelegationRewards(t *testing.T) {
Address: fp1Del1.Address().String(),
})
h.NoError(err)
h.Equal(fp1Del1Rwd.RewardGauges[ictvtypes.BTC_DELEGATION.String()].Coins.String(), rwdFp1Del1.String())
h.Equal(fp1Del1Rwd.RewardGauges[ictvtypes.BTC_STAKER.String()].Coins.String(), rwdFp1Del1.String())

fp1Del2Rwd, err := h.IncentivesKeeper.RewardGauges(h.Ctx, &ictvtypes.QueryRewardGaugesRequest{
Address: fp1Del2.Address().String(),
})
h.NoError(err)
h.Equal(fp1Del2Rwd.RewardGauges[ictvtypes.BTC_DELEGATION.String()].Coins.String(), rwdFp1Del2.String())
h.Equal(fp1Del2Rwd.RewardGauges[ictvtypes.BTC_STAKER.String()].Coins.String(), rwdFp1Del2.String())
}

func TestBtcDelegationRewardsEarlyUnbondingAndExpire(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion x/incentive/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func GetTxCmd() *cobra.Command {
func NewWithdrawRewardCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "withdraw-reward [type]",
Short: "withdraw reward of the stakeholder behind the transaction submitter in a given type (one of {finality_provider, btc_delegation})",
Short: "withdraw reward of the stakeholder behind the transaction submitter in a given type (one of {finality_provider, btc_staker})",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
Expand Down
4 changes: 2 additions & 2 deletions x/incentive/keeper/btc_staking_gauge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func FuzzRewardBTCStaking(f *testing.F) {
for addrStr, reward := range btcDelRewardMap {
addr, err := sdk.AccAddressFromBech32(addrStr)
require.NoError(t, err)
rg := k.GetRewardGauge(ctx, types.BTC_DELEGATION, addr)
rg := k.GetRewardGauge(ctx, types.BTC_STAKER, addr)
require.NotNil(t, rg)

// A little bit of rewards could be lost in the process due to precision points
Expand Down Expand Up @@ -174,7 +174,7 @@ func FuzzRewardBTCStaking(f *testing.F) {
// Check their delegators received no rewards
for delAddrStr := range btcTotalSatByDelAddressByFpAddress[fpAddr.String()] {
delAddr := sdk.MustAccAddressFromBech32(delAddrStr)
rg := k.GetRewardGauge(ctx, types.BTC_DELEGATION, delAddr)
rg := k.GetRewardGauge(ctx, types.BTC_STAKER, delAddr)
require.Nil(t, rg)
}
}
Expand Down
2 changes: 1 addition & 1 deletion x/incentive/keeper/reward_gauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func (k Keeper) sendAllBtcDelegationTypeToRewardsGauge(ctx context.Context, sType types.StakeholderType, del sdk.AccAddress) error {
if sType != types.BTC_DELEGATION {
if sType != types.BTC_STAKER {
return nil
}
return k.sendAllBtcRewardsToGauge(ctx, del)
Expand Down
2 changes: 1 addition & 1 deletion x/incentive/keeper/reward_gauge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestSetGetRewardGauge(t *testing.T) {

// Retrieve values using the new enum type
rg1 := k.GetRewardGauge(ctx, types.FINALITY_PROVIDER, addr1)
rg2 := k.GetRewardGauge(ctx, types.BTC_DELEGATION, addr2)
rg2 := k.GetRewardGauge(ctx, types.BTC_STAKER, addr2)

// Validate that both are equal
require.Equal(t, g1, rg1)
Expand Down
2 changes: 1 addition & 1 deletion x/incentive/keeper/reward_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (k Keeper) CalculateBTCDelegationRewardsAndSendToGauge(ctx context.Context,
return nil
}

k.accumulateRewardGauge(ctx, types.BTC_DELEGATION, del, rewards)
k.accumulateRewardGauge(ctx, types.BTC_STAKER, del, rewards)
return nil
}

Expand Down
24 changes: 12 additions & 12 deletions x/incentive/keeper/reward_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ func FuzzCheckFpSlashed(f *testing.F) {
require.NoError(t, err)

del1Fp1Rwds := coins.CalculatePercentageOfCoins(rwdFp1, del1Fp1Percentage)
del1RwdGauge := k.GetRewardGauge(ctx, types.BTC_DELEGATION, del1)
del1RwdGauge := k.GetRewardGauge(ctx, types.BTC_STAKER, del1)
coins.RequireCoinsDiffInPointOnePercentMargin(t, del1Fp1Rwds, del1RwdGauge.Coins)

del2Fp1Rwds := coins.CalculatePercentageOfCoins(rwdFp1, del2Fp1Percentage)
del2RwdGauge := k.GetRewardGauge(ctx, types.BTC_DELEGATION, del2)
del2RwdGauge := k.GetRewardGauge(ctx, types.BTC_STAKER, del2)
coins.RequireCoinsDiffInPointOnePercentMargin(t, del2Fp1Rwds, del2RwdGauge.Coins)

// verifies that everything was deleted for fp1
Expand Down Expand Up @@ -103,13 +103,13 @@ func FuzzCheckFpSlashed(f *testing.F) {

fp2RwdForEachDel := coins.CalculatePercentageOfCoins(rwdFp2, eachDelFp2Percentage)

lastDel1RwdGauge := k.GetRewardGauge(ctx, types.BTC_DELEGATION, del1)
lastDel1RwdGauge := k.GetRewardGauge(ctx, types.BTC_STAKER, del1)
coins.RequireCoinsDiffInPointOnePercentMargin(t, del1Fp1Rwds.Add(fp2RwdForEachDel...), lastDel1RwdGauge.Coins)

err = k.sendAllBtcRewardsToGauge(ctx, del2)
require.NoError(t, err)

lastDel2RwdGauge := k.GetRewardGauge(ctx, types.BTC_DELEGATION, del2)
lastDel2RwdGauge := k.GetRewardGauge(ctx, types.BTC_STAKER, del2)
coins.RequireCoinsDiffInPointOnePercentMargin(t, del2Fp1Rwds.Add(fp2RwdForEachDel...), lastDel2RwdGauge.Coins)
})
}
Expand Down Expand Up @@ -159,7 +159,7 @@ func FuzzCheckSendAllBtcRewardsToGauge(f *testing.F) {
del1Fp1Rwds := coins.CalculatePercentageOfCoins(rwdFp1, del1Fp1Percentage)
fp2RwdForEachDel := coins.CalculatePercentageOfCoins(rwdFp2, eachDelFp2Percentage)
expectedRwdDel1 := del1Fp1Rwds.Add(fp2RwdForEachDel...)
del1RwdGauge := k.GetRewardGauge(ctx, types.BTC_DELEGATION, del1)
del1RwdGauge := k.GetRewardGauge(ctx, types.BTC_STAKER, del1)
coins.RequireCoinsDiffInPointOnePercentMargin(t, expectedRwdDel1, del1RwdGauge.Coins)

// calculates rewards for the del2
Expand All @@ -168,14 +168,14 @@ func FuzzCheckSendAllBtcRewardsToGauge(f *testing.F) {

del2Fp1Rwds := coins.CalculatePercentageOfCoins(rwdFp1, del2Fp1Percentage)
expectedRwdDel2 := del2Fp1Rwds.Add(fp2RwdForEachDel...)
del2RwdGauge := k.GetRewardGauge(ctx, types.BTC_DELEGATION, del2)
del2RwdGauge := k.GetRewardGauge(ctx, types.BTC_STAKER, del2)
coins.RequireCoinsDiffInPointOnePercentMargin(t, expectedRwdDel2, del2RwdGauge.Coins)

// check if send all the rewards again something changes, it shouldn't
err = k.sendAllBtcRewardsToGauge(ctx, del1)
require.NoError(t, err)

newDel1RwdGauge := k.GetRewardGauge(ctx, types.BTC_DELEGATION, del1)
newDel1RwdGauge := k.GetRewardGauge(ctx, types.BTC_STAKER, del1)
require.Equal(t, newDel1RwdGauge.Coins.String(), del1RwdGauge.Coins.String())

// sends new rewards for fp2 which is 50/50
Expand All @@ -187,7 +187,7 @@ func FuzzCheckSendAllBtcRewardsToGauge(f *testing.F) {
require.NoError(t, err)

lastFp2RwdForEachDel := coins.CalculatePercentageOfCoins(rwdFp2, eachDelFp2Percentage)
lastDel1RwdGauge := k.GetRewardGauge(ctx, types.BTC_DELEGATION, del1)
lastDel1RwdGauge := k.GetRewardGauge(ctx, types.BTC_STAKER, del1)
lastExpectedRwdDel1 := del1Fp1Rwds.Add(fp2RwdForEachDel...).Add(lastFp2RwdForEachDel...)
coins.RequireCoinsDiffInPointOnePercentMargin(t, lastExpectedRwdDel1, lastDel1RwdGauge.Coins)
require.Equal(t, lastFp2RwdForEachDel.String(), lastDel1RwdGauge.Coins.Sub(newDel1RwdGauge.Coins...).String())
Expand Down Expand Up @@ -217,7 +217,7 @@ func FuzzCheckBtcDelegationModifiedWithPreInitDel(f *testing.F) {
err = k.BtcDelegationActivated(ctx, fp, del, datagen.RandomInt(r, 1000)+10)
require.NoError(t, err)

delRwdGauge := k.GetRewardGauge(ctx, types.BTC_DELEGATION, del)
delRwdGauge := k.GetRewardGauge(ctx, types.BTC_STAKER, del)
require.Nil(t, delRwdGauge)

coinsToDel := datagen.GenRandomCoins(r)
Expand All @@ -228,7 +228,7 @@ func FuzzCheckBtcDelegationModifiedWithPreInitDel(f *testing.F) {
require.NoError(t, err)
require.Equal(t, count, 2)

delRwdGauge = k.GetRewardGauge(ctx, types.BTC_DELEGATION, del)
delRwdGauge = k.GetRewardGauge(ctx, types.BTC_STAKER, del)
coins.RequireCoinsDiffInPointOnePercentMargin(t, delRwdGauge.Coins, coinsToDel)
// note: the difference here in one micro coin value is expected due to the loss of precision in the BTC reward tracking mechanism
// that needs to keep track of how much rewards 1 satoshi is entitled to receive.
Expand Down Expand Up @@ -264,12 +264,12 @@ func FuzzCheckCalculateBTCDelegationRewardsAndSendToGauge(f *testing.F) {
expectedRwd = expectedRwd.QuoInt(types.DecimalAccumulatedRewards)

rwdGauge := datagen.GenRandomRewardGauge(r)
k.SetRewardGauge(ctx, types.BTC_DELEGATION, del, rwdGauge)
k.SetRewardGauge(ctx, types.BTC_STAKER, del, rwdGauge)

err = k.CalculateBTCDelegationRewardsAndSendToGauge(ctx, fp, del, endPeriod)
require.NoError(t, err)

delRwdGauge := k.GetRewardGauge(ctx, types.BTC_DELEGATION, del)
delRwdGauge := k.GetRewardGauge(ctx, types.BTC_STAKER, del)
require.Equal(t, rwdGauge.Coins.Add(expectedRwd...).String(), delRwdGauge.Coins.String())
})
}
Expand Down
Loading

0 comments on commit 3206cfe

Please sign in to comment.