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

finality: refactor voting power table and APIs #222

Merged
merged 19 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### State Machine Breaking

* [#217](https://github.com/babylonlabs-io/babylon/pull/216) move voting power table to finality module
* [#207](https://github.com/babylonlabs-io/babylon/pull/207) Rename total voting power
to total bonded sat
* [#215](https://github.com/babylonlabs-io/babylon/pull/215) Implement ADR-29
Expand Down
8 changes: 0 additions & 8 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,6 @@ func (ak *AppKeepers) InitKeepers(
runtime.NewKVStoreService(keys[btcstakingtypes.StoreKey]),
&btclightclientKeeper,
&btcCheckpointKeeper,
// setting the finality keeper as nil for now
// need to set it after finality keeper is initiated
nil,
&ak.IncentiveKeeper,
btcNetParams,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Expand All @@ -513,11 +510,6 @@ func (ak *AppKeepers) InitKeepers(
ak.CheckpointingKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
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
evidenceKeeper := evidencekeeper.NewKeeper(
Expand Down
3 changes: 1 addition & 2 deletions app/upgrades/v1/mainnet/btcstaking_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ const BtcStakingParamStr = `
"slashing_rate": "0.100000000000000000",
"min_unbonding_time_blocks": 0,
"unbonding_fee_sat": "1000",
"min_commission_rate": "0.03",
"max_active_finality_providers": 100
"min_commission_rate": "0.03"
}`
1 change: 1 addition & 0 deletions app/upgrades/v1/mainnet/finality_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mainnet
// TODO Some default parameters. Consider how to switch those depending on network:
// mainnet, testnet, devnet etc.
const FinalityParamStr = `{
"max_active_finality_providers": 100,
"signed_blocks_window": 100,
"finality_sig_timeout": 3,
"min_signed_per_window": "0.1",
Expand Down
1 change: 0 additions & 1 deletion app/upgrades/v1/testnet/btcstaking_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ const BtcStakingParamStr = `
"min_unbonding_time_blocks": 0,
"unbonding_fee_sat": "1000",
"min_commission_rate": "0.03",
"max_active_finality_providers": 100,
"delegation_creation_base_gas_fee": 1000
}`
1 change: 1 addition & 0 deletions app/upgrades/v1/testnet/finality_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package testnet
// TODO Some default parameters. Consider how to switch those depending on network:
// mainnet, testnet, devnet etc.
const FinalityParamStr = `{
"max_active_finality_providers": 100,
"signed_blocks_window": 100,
"finality_sig_timeout": 3,
"min_signed_per_window": "0.1",
Expand Down
45 changes: 0 additions & 45 deletions client/query/btcstaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,48 +121,3 @@ func (c *QueryClient) BTCDelegation(stakingTxHashHex string) (*btcstakingtypes.Q

return resp, err
}

// ActiveFinalityProvidersAtHeight queries the BTCStaking module for all finality providers
// with non-zero voting power at a given height
func (c *QueryClient) ActiveFinalityProvidersAtHeight(height uint64, pagination *sdkquerytypes.PageRequest) (*btcstakingtypes.QueryActiveFinalityProvidersAtHeightResponse, error) {
var resp *btcstakingtypes.QueryActiveFinalityProvidersAtHeightResponse
err := c.QueryBTCStaking(func(ctx context.Context, queryClient btcstakingtypes.QueryClient) error {
var err error
req := &btcstakingtypes.QueryActiveFinalityProvidersAtHeightRequest{
Height: height,
Pagination: pagination,
}
resp, err = queryClient.ActiveFinalityProvidersAtHeight(ctx, req)
return err
})

return resp, err
}

// FinalityProviderPowerAtHeight queries the BTCStaking module for the power of a finality provider at a given height
func (c *QueryClient) FinalityProviderPowerAtHeight(fpBtcPkHex string, height uint64) (*btcstakingtypes.QueryFinalityProviderPowerAtHeightResponse, error) {
var resp *btcstakingtypes.QueryFinalityProviderPowerAtHeightResponse
err := c.QueryBTCStaking(func(ctx context.Context, queryClient btcstakingtypes.QueryClient) error {
var err error
req := &btcstakingtypes.QueryFinalityProviderPowerAtHeightRequest{
FpBtcPkHex: fpBtcPkHex,
Height: height,
}
resp, err = queryClient.FinalityProviderPowerAtHeight(ctx, req)
return err
})

return resp, err
}

func (c *QueryClient) ActivatedHeight() (*btcstakingtypes.QueryActivatedHeightResponse, error) {
var resp *btcstakingtypes.QueryActivatedHeightResponse
err := c.QueryBTCStaking(func(ctx context.Context, queryClient btcstakingtypes.QueryClient) error {
var err error
req := &btcstakingtypes.QueryActivatedHeightRequest{}
resp, err = queryClient.ActivatedHeight(ctx, req)
return err
})

return resp, err
}
45 changes: 45 additions & 0 deletions client/query/finality.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,51 @@ func (c *QueryClient) QueryFinality(f func(ctx context.Context, queryClient fina
return f(ctx, queryClient)
}

// ActiveFinalityProvidersAtHeight queries the BTCStaking module for all finality providers
// with non-zero voting power at a given height
func (c *QueryClient) ActiveFinalityProvidersAtHeight(height uint64, pagination *sdkquerytypes.PageRequest) (*finalitytypes.QueryActiveFinalityProvidersAtHeightResponse, error) {
var resp *finalitytypes.QueryActiveFinalityProvidersAtHeightResponse
err := c.QueryFinality(func(ctx context.Context, queryClient finalitytypes.QueryClient) error {
var err error
req := &finalitytypes.QueryActiveFinalityProvidersAtHeightRequest{
Height: height,
Pagination: pagination,
}
resp, err = queryClient.ActiveFinalityProvidersAtHeight(ctx, req)
return err
})

return resp, err
}

// FinalityProviderPowerAtHeight queries the BTCStaking module for the power of a finality provider at a given height
func (c *QueryClient) FinalityProviderPowerAtHeight(fpBtcPkHex string, height uint64) (*finalitytypes.QueryFinalityProviderPowerAtHeightResponse, error) {
var resp *finalitytypes.QueryFinalityProviderPowerAtHeightResponse
err := c.QueryFinality(func(ctx context.Context, queryClient finalitytypes.QueryClient) error {
var err error
req := &finalitytypes.QueryFinalityProviderPowerAtHeightRequest{
FpBtcPkHex: fpBtcPkHex,
Height: height,
}
resp, err = queryClient.FinalityProviderPowerAtHeight(ctx, req)
return err
})

return resp, err
}

func (c *QueryClient) ActivatedHeight() (*finalitytypes.QueryActivatedHeightResponse, error) {
var resp *finalitytypes.QueryActivatedHeightResponse
err := c.QueryFinality(func(ctx context.Context, queryClient finalitytypes.QueryClient) error {
var err error
req := &finalitytypes.QueryActivatedHeightRequest{}
resp, err = queryClient.ActivatedHeight(ctx, req)
return err
})

return resp, err
}

// FinalityParams queries the finality module parameters
func (c *QueryClient) FinalityParams() (*finalitytypes.Params, error) {
var resp *finalitytypes.QueryParamsResponse
Expand Down
2 changes: 1 addition & 1 deletion cmd/babylond/cmd/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ func TestnetGenesisParams(
genParams.BtcstakingParams.MinSlashingTxFeeSat = minSlashingFee
genParams.BtcstakingParams.MinCommissionRate = minCommissionRate
genParams.BtcstakingParams.SlashingRate = slashingRate
genParams.BtcstakingParams.MaxActiveFinalityProviders = maxActiveFinalityProviders
genParams.BtcstakingParams.MinUnbondingTimeBlocks = uint32(minUnbondingTime)
genParams.BtcstakingParams.UnbondingFeeSat = unbondingFeeSat
if err := genParams.BtcstakingParams.Validate(); err != nil {
Expand All @@ -434,6 +433,7 @@ func TestnetGenesisParams(
genParams.BlockGasLimit = blockGasLimit
genParams.VoteExtensionsEnableHeight = voteExtensionEnableHeight

genParams.FinalityParams.MaxActiveFinalityProviders = maxActiveFinalityProviders
genParams.FinalityParams.SignedBlocksWindow = signedBlocksWindow
genParams.FinalityParams.MinSignedPerWindow = minSignedPerWindow
genParams.FinalityParams.FinalitySigTimeout = finalitySigTimeout
Expand Down
25 changes: 0 additions & 25 deletions proto/babylon/btcstaking/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package babylon.btcstaking.v1;
import "gogoproto/gogo.proto";
import "babylon/btcstaking/v1/params.proto";
import "babylon/btcstaking/v1/btcstaking.proto";
import "babylon/btcstaking/v1/incentive.proto";
import "babylon/btcstaking/v1/events.proto";

option go_package = "github.com/babylonlabs-io/babylon/x/btcstaking/types";
Expand All @@ -17,36 +16,12 @@ message GenesisState {
repeated FinalityProvider finality_providers = 2;
// btc_delegations all the btc delegations in the state.
repeated BTCDelegation btc_delegations = 3;
// voting_powers the voting power of every finality provider at every block height.
repeated VotingPowerFP voting_powers = 4;
// block_height_chains the block height of babylon and bitcoin.
repeated BlockHeightBbnToBtc block_height_chains = 5;
// btc_delegators contains all the btc delegators with the associated finality provider.
repeated BTCDelegator btc_delegators = 6;
// all the events and its indexes.
repeated EventIndex events = 7;
// vp_dst_cache is the table of all providers voting power with the total at one specific block.
// TODO: remove this after not storing in the keeper store it anymore.
repeated VotingPowerDistCacheBlkHeight vp_dst_cache = 8;
}

// VotingPowerFP contains the information about the voting power
// of an finality provider in a specific block height.
message VotingPowerFP {
// block_height is the height of the block the voting power was stored.
uint64 block_height = 1;
// fp_btc_pk the finality provider btc public key.
bytes fp_btc_pk = 2 [ (gogoproto.customtype) = "github.com/babylonlabs-io/babylon/types.BIP340PubKey" ];
// voting_power is the power of the finality provider at this specific block height.
uint64 voting_power = 3;
}

// VotingPowerDistCacheBlkHeight the total voting power of the finality providers at one specific block height
message VotingPowerDistCacheBlkHeight {
// block_height is the height of the block the voting power distribution cached was stored.
uint64 block_height = 1;
// vp_distribution the finality providers distribution cache at that height.
VotingPowerDistCache vp_distribution = 2;
}

// BlockHeightBbnToBtc stores the btc <-> bbn block.
Expand Down
62 changes: 0 additions & 62 deletions proto/babylon/btcstaking/v1/incentive.proto

This file was deleted.

4 changes: 1 addition & 3 deletions proto/babylon/btcstaking/v1/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ message Params {
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
// max_active_finality_providers is the maximum number of active finality providers in the BTC staking protocol
uint32 max_active_finality_providers = 13;
// base gas fee for delegation creation
uint64 delegation_creation_base_gas_fee = 14;
uint64 delegation_creation_base_gas_fee = 13;
}

// StoredParams attach information about the version of stored parameters
Expand Down
Loading