diff --git a/CHANGELOG.md b/CHANGELOG.md index e407d02bb..b2732464a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,49 +31,16 @@ Ref: https://keepachangelog.com/en/1.0.0/ # Changelog -## [Unreleased](https://github.com/babylonchain/babylon-private/tree/HEAD) - -[Full Changelog](https://github.com/babylonchain/babylon-private/compare/euphrates-0.2.0-rc.0...HEAD) - - -## [euphrates-v0.2.0-rc.0](https://github.com/babylonchain/babylon-private/tree/euphrates-v0.2.0-rc.0) (2024-05-17) - -[Full Changelog](https://github.com/babylonchain/babylon-private/compare/euphrates-0.1.0-rc.1...euphrates-v0.2.0-rc.0) - -## [euphrates-0.1.0-rc.1](https://github.com/babylonchain/babylon-private/tree/euphrates-0.1.0-rc.1) (2024-03-25) - -[Full Changelog](https://github.com/babylonchain/babylon-private/compare/euphrates-0.1.0-rc.0...euphrates-0.1.0-rc.1) - -**Fixed bugs:** - -- Fix: only calculating Babylon FPs for FP set rotation (#223) - -## [euphrates-0.1.0-rc.0](https://github.com/babylonchain/babylon-private/tree/euphrates-0.1.0-rc.0) (2024-03-22) - -[Full Changelog](https://github.com/babylonchain/babylon-private/compare/v0.8.5...euphrates-0.1.0-rc.0) - -**Closed issues:** - -- handler for registering consumer chain finality providers [\#211](https://github.com/babylonchain/babylon-private/issues/211) -- restaking support and tests [\#208](https://github.com/babylonchain/babylon-private/issues/208) -- New module for BTC staking integration [\#204](https://github.com/babylonchain/babylon-private/issues/204) -- Consumer chain finality provider registry [\#203](https://github.com/babylonchain/babylon-private/issues/203) - -## [v0.8.0](https://github.com/babylonchain/babylon/tree/v0.8.0) (2024-02-08) +All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## Unreleased -### Improvements - -- [#391](https://github.com/babylonlabs-io/babylon/pull/391) Fix e2e `TestBTCRewardsDistribution` flunky -check of rewards - -### Bug fixes +### State Machine Breaking -- [#353](https://github.com/babylonlabs-io/babylon/pull/353) Bump to SDK - 0.50.11 +- [#402](https://github.com/babylonlabs-io/babylon/pull/402) **Babylon multi-staking support**. +This PR contains a series of PRs on multi-staking support and BTC stakingintegration. ## v1.0.0-rc3 diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 2b4801a21..209ddce02 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -431,7 +431,7 @@ func (ak *AppKeepers) InitKeepers( homePath, wasmConfig, WasmCapabilities(), - authtypes.NewModuleAddress(govtypes.ModuleName).String(), + appparams.AccGov.String(), wasmOpts..., ) @@ -514,7 +514,7 @@ func (ak *AppKeepers) InitKeepers( ak.BankKeeper, ak.IBCKeeper.ClientKeeper, ak.WasmKeeper, - authtypes.NewModuleAddress(govtypes.ModuleName).String(), + appparams.AccGov.String(), ) // set up BTC staking keeper @@ -569,7 +569,7 @@ func (ak *AppKeepers) InitKeepers( &ak.BTCStakingKeeper, &ak.BTCStkConsumerKeeper, scopedZoneConciergeKeeper, - authtypes.NewModuleAddress(govtypes.ModuleName).String(), + appparams.AccGov.String(), ) // add msgServiceRouter so that the epoching module can forward unwrapped messages to the staking module diff --git a/client/docs/config.json b/client/docs/config.json index 83337a2aa..e1665e73e 100644 --- a/client/docs/config.json +++ b/client/docs/config.json @@ -15,7 +15,7 @@ } }, { - "url": "./tmp-swagger-gen/babylon/btclightclient/v1/query.swagger.json", + "url": "./tmp-swagger-gen/babylon/btclightclient/v1/query.swagger.json", "operationIds": { "rename": { "Params": "BtcLightClientParams" @@ -23,7 +23,7 @@ } }, { - "url": "./tmp-swagger-gen/babylon/epoching/v1/query.swagger.json", + "url": "./tmp-swagger-gen/babylon/epoching/v1/query.swagger.json", "operationIds": { "rename": { "Params": "EpochingParams" @@ -31,12 +31,60 @@ } }, { - "url": "./tmp-swagger-gen/babylon/checkpointing/v1/query.swagger.json", + "url": "./tmp-swagger-gen/babylon/checkpointing/v1/query.swagger.json", "operationIds": { "rename": { "Params": "CheckpointingParams" } } + }, + { + "url": "./tmp-swagger-gen/babylon/btcstaking/v1/query.swagger.json", + "operationIds": { + "rename": { + "Params": "BtcStakingParams" + } + } + }, + { + "url": "./tmp-swagger-gen/babylon/btcstkconsumer/v1/query.swagger.json", + "operationIds": { + "rename": { + "Params": "BtcStkConsumerParams" + } + } + }, + { + "url": "./tmp-swagger-gen/babylon/finality/v1/query.swagger.json", + "operationIds": { + "rename": { + "Params": "FinalityParams" + } + } + }, + { + "url": "./tmp-swagger-gen/babylon/incentive/v1/query.swagger.json", + "operationIds": { + "rename": { + "Params": "IncentiveParams" + } + } + }, + { + "url": "./tmp-swagger-gen/babylon/monitor/v1/query.swagger.json", + "operationIds": { + "rename": { + "Params": "MonitorParams" + } + } + }, + { + "url": "./tmp-swagger-gen/babylon/zoneconcierge/v1/query.swagger.json", + "operationIds": { + "rename": { + "Params": "ZoneConciergeParams" + } + } } ] -} +} \ No newline at end of file diff --git a/contrib/images/Makefile b/contrib/images/Makefile index 2d674d72b..ef41b46f5 100644 --- a/contrib/images/Makefile +++ b/contrib/images/Makefile @@ -29,4 +29,4 @@ cosmos-relayer: cosmos-relayer-rmi cosmos-relayer-rmi: docker rmi babylonlabs-io/cosmos-relayer 2>/dev/null; true -.PHONY: all babylond babylond-before-upgrade cosmos-relayer e2e-init-chain babylond-rmi babylond-rmi-upgrade cosmos-relayer-rmi +.PHONY: all babylond cosmos-relayer e2e-init-chain babylond-rmi cosmos-relayer-rmi diff --git a/proto/babylon/finality/v1/tx.proto b/proto/babylon/finality/v1/tx.proto index 64981377a..a19181a6c 100644 --- a/proto/babylon/finality/v1/tx.proto +++ b/proto/babylon/finality/v1/tx.proto @@ -17,7 +17,6 @@ service Msg { rpc CommitPubRandList(MsgCommitPubRandList) returns (MsgCommitPubRandListResponse); // AddFinalitySig adds a finality signature to a given block rpc AddFinalitySig(MsgAddFinalitySig) returns (MsgAddFinalitySigResponse); - // TODO: msg for evidence of equivocation. this is not specified yet // UpdateParams updates the finality module parameters. rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); // UnjailFinalityProvider defines a method for unjailing a jailed diff --git a/test/e2e/configurer/chain/commands_btcstaking.go b/test/e2e/configurer/chain/commands_btcstaking.go index bd7aede2a..701a9f2e3 100644 --- a/test/e2e/configurer/chain/commands_btcstaking.go +++ b/test/e2e/configurer/chain/commands_btcstaking.go @@ -129,7 +129,7 @@ func (n *NodeConfig) CreateBTCDelegation( // broadcast stuff cmd = append(cmd, "-b=sync", "--yes") } - // cmd = append(cmd, fmt.Sprintf("--chain-id=%s", n.chainId), "-b=sync", "--yes", "--keyring-backend=test", "--log_format=json", "--home=/home/babylon/babylondata") + cmd = append(cmd, fmt.Sprintf("--chain-id=%s", n.chainId), "-b=sync", "--yes") outBuff, _, err := n.containerManager.ExecCmd(n.t, n.Name, append(cmd, overallFlags...), "") diff --git a/test/e2e/containers/containers.go b/test/e2e/containers/containers.go index 631460f16..c1c60c9a0 100644 --- a/test/e2e/containers/containers.go +++ b/test/e2e/containers/containers.go @@ -272,7 +272,10 @@ func (m *Manager) RunNodeResource(chainId string, containerName, valCondifDir st Entrypoint: []string{ "sh", "-c", - "babylond start " + FlagHome + " --log_level trace --trace", + // one can use the following for debugging purposes + // "babylond start " + FlagHome + " --log_level trace --trace", + // TODO: parameterise the log level + "babylond start " + FlagHome, }, ExposedPorts: []string{"26656", "26657", "1317", "9090"}, Mounts: []string{ diff --git a/testutil/btcstaking-helper/keeper.go b/testutil/btcstaking-helper/keeper.go index 367cc3dd0..08270f9af 100644 --- a/testutil/btcstaking-helper/keeper.go +++ b/testutil/btcstaking-helper/keeper.go @@ -37,8 +37,6 @@ var ( timestampedEpoch = uint64(10) ) -// TODO: move this to keeper package rather than keeper_test so that -// it can be inherited to test other modules? type Helper struct { t testing.TB diff --git a/x/btccheckpoint/client/cli/tx.go b/x/btccheckpoint/client/cli/tx.go index d463dd636..6a28ea957 100644 --- a/x/btccheckpoint/client/cli/tx.go +++ b/x/btccheckpoint/client/cli/tx.go @@ -2,13 +2,13 @@ package cli import ( "fmt" + "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" - // "github.com/cosmos/cosmos-sdk/client/flags" "github.com/babylonlabs-io/babylon/x/btccheckpoint/types" ) diff --git a/x/btcstaking/keeper/btc_consumer_delegations.go b/x/btcstaking/keeper/btc_consumer_delegations.go index 107036f54..f6935b777 100644 --- a/x/btcstaking/keeper/btc_consumer_delegations.go +++ b/x/btcstaking/keeper/btc_consumer_delegations.go @@ -12,14 +12,10 @@ import ( "github.com/cosmos/cosmos-sdk/types/query" ) -// IndexBTCConsumerDelegation indexes a BTC delegation into the BTC consumer delegator store +// indexBTCConsumerDelegation indexes a BTC delegation into the BTC consumer delegator store // CONTRACT: this function only takes BTC delegations that have passed verifications // imposed in `x/btcstaking/msg_server.go` -func (k Keeper) IndexBTCConsumerDelegation(ctx sdk.Context, btcDel *bstypes.BTCDelegation) error { - if err := btcDel.ValidateBasic(); err != nil { - return err - } - +func (k Keeper) indexBTCConsumerDelegation(ctx sdk.Context, btcDel *bstypes.BTCDelegation) error { // get staking tx hash stakingTxHash, err := btcDel.GetStakingTxHash() if err != nil { @@ -58,7 +54,6 @@ func (k Keeper) GetBTCConsumerDelegatorDelegationsResponses( ctx sdk.Context, fpBTCPK *bbn.BIP340PubKey, pagination *query.PageRequest, - wValue uint32, btcHeight uint32, covenantQuorum uint32, ) ([]*bstypes.BTCDelegatorDelegationsResponse, *query.PageResponse, error) { diff --git a/x/btcstaking/keeper/btc_delegations.go b/x/btcstaking/keeper/btc_delegations.go index 1657fc3f4..cc638d8ce 100644 --- a/x/btcstaking/keeper/btc_delegations.go +++ b/x/btcstaking/keeper/btc_delegations.go @@ -266,6 +266,7 @@ func (k Keeper) validateRestakedFPs(ctx context.Context, fpBTCPKs []bbn.BIP340Pu } // restakedFPConsumerIDs returns the unique consumer IDs of non-Babylon finality providers +// The returned list is sorted in order to make sure the function is deterministic func (k Keeper) restakedFPConsumerIDs(ctx context.Context, fpBTCPKs []bbn.BIP340PubKey) ([]string, error) { consumerIDMap := make(map[string]struct{}) diff --git a/x/btcstaking/keeper/btc_staking_consumer_events_test.go b/x/btcstaking/keeper/btc_staking_consumer_events_test.go index e3ed0afca..3f80358b7 100644 --- a/x/btcstaking/keeper/btc_staking_consumer_events_test.go +++ b/x/btcstaking/keeper/btc_staking_consumer_events_test.go @@ -18,6 +18,8 @@ func FuzzSetBTCStakingEventStore_NewFp(f *testing.F) { datagen.AddRandomSeedsToFuzzer(f, 10) f.Fuzz(func(t *testing.T, seed int64) { + t.Parallel() + r := rand.New(rand.NewSource(seed)) ctrl := gomock.NewController(t) defer ctrl.Finish() @@ -75,6 +77,8 @@ func FuzzSetBTCStakingEventStore_ActiveDel(f *testing.F) { datagen.AddRandomSeedsToFuzzer(f, 10) f.Fuzz(func(t *testing.T, seed int64) { + t.Parallel() + r := rand.New(rand.NewSource(seed)) ctrl := gomock.NewController(t) defer ctrl.Finish() @@ -169,6 +173,8 @@ func FuzzSetBTCStakingEventStore_UnbondedDel(f *testing.F) { datagen.AddRandomSeedsToFuzzer(f, 10) f.Fuzz(func(t *testing.T, seed int64) { + t.Parallel() + r := rand.New(rand.NewSource(seed)) ctrl := gomock.NewController(t) defer ctrl.Finish() @@ -270,6 +276,8 @@ func FuzzDeleteBTCStakingEventStore(f *testing.F) { datagen.AddRandomSeedsToFuzzer(f, 10) f.Fuzz(func(t *testing.T, seed int64) { + t.Parallel() + r := rand.New(rand.NewSource(seed)) ctrl := gomock.NewController(t) defer ctrl.Finish() diff --git a/x/btcstaking/keeper/finality_providers.go b/x/btcstaking/keeper/finality_providers.go index 6d8cb4657..09b749869 100644 --- a/x/btcstaking/keeper/finality_providers.go +++ b/x/btcstaking/keeper/finality_providers.go @@ -36,7 +36,7 @@ func (k Keeper) AddFinalityProvider(goCtx context.Context, msg *types.MsgCreateF // default consumer ID is Babylon's chain ID consumerID := msg.GetConsumerId() if consumerID == "" { - // canonical chain id + // Babylon chain ID consumerID = ctx.ChainID() } @@ -202,6 +202,8 @@ func (k Keeper) PropagateFPSlashingToConsumers(ctx context.Context, fpBTCPK *bbn consumerID, exists := fpToConsumerMap[fpBTCPKHex] if !exists { // If not in map, check if it's a Babylon FP or get its consumer + // TODO: avoid querying GetFinalityProvider again by passing the result + // https://github.com/babylonlabs-io/babylon/blob/873f1232365573a97032037af4ac99b5e3fcada8/x/btcstaking/keeper/btc_delegators.go#L79 to this function if _, err := k.GetFinalityProvider(ctx, delegationFPBTCPK); err == nil { continue // It's a Babylon FP, skip } else if consumerID, err = k.BscKeeper.GetConsumerOfFinalityProvider(ctx, &delegationFPBTCPK); err == nil { diff --git a/x/btcstaking/keeper/grpc_query.go b/x/btcstaking/keeper/grpc_query.go index 00d21eb0c..4ff647d2a 100644 --- a/x/btcstaking/keeper/grpc_query.go +++ b/x/btcstaking/keeper/grpc_query.go @@ -143,7 +143,6 @@ func (k Keeper) FinalityProviderDelegations(ctx context.Context, req *types.Quer } sdkCtx := sdk.UnwrapSDKContext(ctx) - currentWValue := k.btccKeeper.GetParams(ctx).CheckpointFinalizationTimeout btcHeight := k.btclcKeeper.GetTipInfo(ctx).Height covenantQuorum := k.GetParams(ctx).CovenantQuorum @@ -188,7 +187,7 @@ func (k Keeper) FinalityProviderDelegations(ctx context.Context, req *types.Quer case k.BscKeeper.HasConsumerFinalityProvider(ctx, fpPK): // this is a consumer finality provider - btcDels, pageRes, err = k.GetBTCConsumerDelegatorDelegationsResponses(sdkCtx, fpPK, req.Pagination, currentWValue, btcHeight, covenantQuorum) + btcDels, pageRes, err = k.GetBTCConsumerDelegatorDelegationsResponses(sdkCtx, fpPK, req.Pagination, btcHeight, covenantQuorum) if err != nil { return nil, err } diff --git a/x/btcstaking/keeper/msg_server.go b/x/btcstaking/keeper/msg_server.go index 138f1b91f..66ee20146 100644 --- a/x/btcstaking/keeper/msg_server.go +++ b/x/btcstaking/keeper/msg_server.go @@ -297,7 +297,7 @@ func (ms msgServer) CreateBTCDelegation(goCtx context.Context, req *types.MsgCre // if this BTC delegation is restaked to consumers' FPs, add it to btcstkconsumer indexes // TODO: revisit the relationship between BTC staking module and BTC staking consumer module if restakedToConsumers { - if err := ms.IndexBTCConsumerDelegation(ctx, newBTCDel); err != nil { + if err := ms.indexBTCConsumerDelegation(ctx, newBTCDel); err != nil { panic(fmt.Errorf("failed to add BTC delegation restaked to consumers' finality providers despite it has passed verification: %w", err)) } } diff --git a/x/btcstkconsumer/client/cli/tx.go b/x/btcstkconsumer/client/cli/tx.go index 89114187a..fd2965dd5 100644 --- a/x/btcstkconsumer/client/cli/tx.go +++ b/x/btcstkconsumer/client/cli/tx.go @@ -33,10 +33,11 @@ func GetTxCmd() *cobra.Command { func NewRegisterConsumerCmd() *cobra.Command { cmd := &cobra.Command{ Use: "register-consumer [description]", - Args: cobra.RangeArgs(2, 3), - Short: "Registers a CZ consumer", + Args: cobra.ExactArgs(3), + Short: "Registers a consumer", Long: strings.TrimSpace( - `Registers a CZ consumer.`, + `Registers a consumer with Babylon. The consumer-id must be unique and will be used to identify this consumer. + The name and optional description help identify the purpose of this consumer.`, ), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) @@ -44,7 +45,6 @@ func NewRegisterConsumerCmd() *cobra.Command { return err } - // get description consumerId := args[0] if consumerId == "" { return fmt.Errorf("consumer's id cannot be empty") @@ -53,9 +53,9 @@ func NewRegisterConsumerCmd() *cobra.Command { if name == "" { return fmt.Errorf("consumer's name cannot be empty") } - description := "" - if len(args) == 3 { - description = args[2] + description := args[2] + if description == "" { + return fmt.Errorf("consumer's description cannot be empty") } msg := types.MsgRegisterConsumer{ diff --git a/x/btcstkconsumer/keeper/finality_provider_registry.go b/x/btcstkconsumer/keeper/finality_provider_registry.go index 7cb343f8c..d6e7f975c 100644 --- a/x/btcstkconsumer/keeper/finality_provider_registry.go +++ b/x/btcstkconsumer/keeper/finality_provider_registry.go @@ -5,7 +5,6 @@ import ( "github.com/cosmos/cosmos-sdk/runtime" - errorsmod "cosmossdk.io/errors" "cosmossdk.io/store/prefix" bbn "github.com/babylonlabs-io/babylon/types" @@ -55,57 +54,6 @@ func (k Keeper) GetConsumerOfFinalityProvider(ctx context.Context, fpBTCPK *bbn. return string(chainID), nil } -// IterateFPs iterates over all finality providers for a given chain -func (k Keeper) IterateFPs(ctx context.Context, chainId string, handler func(fp *btcstaking.FinalityProvider) bool) { - // filter out all finality providers with positive voting power - fpIter := k.finalityProviderStore(ctx, chainId).Iterator(nil, nil) - defer fpIter.Close() - for ; fpIter.Valid(); fpIter.Next() { - var fp btcstaking.FinalityProvider - k.cdc.MustUnmarshal(fpIter.Value(), &fp) - - shouldContinue := handler(&fp) - if !shouldContinue { - return - } - } -} - -// HasFPs checks if the FPs list exists for a given chain id -func (k Keeper) HasFPs(ctx context.Context, chainID string) bool { - store := k.finalityProviderStore(ctx, chainID) - iter := store.Iterator(nil, nil) - defer iter.Close() - return iter.Valid() -} - -// GetFPs gets the list of FPs, i.e., the finality provider set for a given chain id -func (k Keeper) GetFPs(ctx context.Context, chainID string) map[string]btcstaking.FinalityProvider { - store := k.finalityProviderStore(ctx, chainID) - iter := store.Iterator(nil, nil) - defer iter.Close() - - // if no finality provider for this chain id, return nil - if !iter.Valid() { - return nil - } - - // get all finality providers for this chain id - fpSet := map[string]btcstaking.FinalityProvider{} - for ; iter.Valid(); iter.Next() { - fpBTCPK, err := bbn.NewBIP340PubKey(iter.Key()) - if err != nil { - // failing to unmarshal finality provider BTC PK in KVStore is a programming error - panic(errorsmod.Wrapf(bbn.ErrUnmarshal, "Failed to unmarshall FP BTC PK %s: %v", iter.Key(), err)) - } - var fp btcstaking.FinalityProvider - k.cdc.MustUnmarshal(iter.Value(), &fp) - fpSet[fpBTCPK.MarshalHex()] = fp - } - - return fpSet -} - // finalityProviderStore returns the KVStore of the finality provider set per chain // prefix: ConsumerFinalityProviderKey || chain id // key: Bitcoin PubKey diff --git a/x/btcstkconsumer/keeper/query.go b/x/btcstkconsumer/keeper/query.go deleted file mode 100644 index 8f1684a08..000000000 --- a/x/btcstkconsumer/keeper/query.go +++ /dev/null @@ -1,7 +0,0 @@ -package keeper - -import ( - "github.com/babylonlabs-io/babylon/x/btcstkconsumer/types" -) - -var _ types.QueryServer = Keeper{} diff --git a/x/btcstkconsumer/types/errors.go b/x/btcstkconsumer/types/errors.go index 256662dde..752b7bf92 100644 --- a/x/btcstkconsumer/types/errors.go +++ b/x/btcstkconsumer/types/errors.go @@ -10,9 +10,8 @@ import ( var ( ErrInvalidSigner = sdkerrors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message") ErrConsumerNotRegistered = sdkerrors.Register(ModuleName, 1101, "consumer not registered") - ErrInvalidConsumerRegister = sdkerrors.Register(ModuleName, 1102, "invalid consumer register") - ErrConsumerAlreadyRegistered = sdkerrors.Register(ModuleName, 1103, "consumer already registered") - ErrInvalidConsumerIDs = sdkerrors.Register(ModuleName, 1104, "consumer ids contain duplicates or empty strings") - ErrInvalidCosmosConsumerRequest = sdkerrors.Register(ModuleName, 1105, "invalid registration request of Cosmos consumer") - ErrInvalidETHL2ConsumerRequest = sdkerrors.Register(ModuleName, 1106, "invalid registration request of ETH L2 consumer") + ErrConsumerAlreadyRegistered = sdkerrors.Register(ModuleName, 1102, "consumer already registered") + ErrInvalidConsumerIDs = sdkerrors.Register(ModuleName, 1103, "consumer ids contain duplicates or empty strings") + ErrInvalidCosmosConsumerRequest = sdkerrors.Register(ModuleName, 1104, "invalid registration request of Cosmos consumer") + ErrInvalidETHL2ConsumerRequest = sdkerrors.Register(ModuleName, 1105, "invalid registration request of ETH L2 consumer") ) diff --git a/x/btcstkconsumer/types/expected_keepers.go b/x/btcstkconsumer/types/expected_keepers.go index 0892050a0..e8e0862b4 100644 --- a/x/btcstkconsumer/types/expected_keepers.go +++ b/x/btcstkconsumer/types/expected_keepers.go @@ -10,13 +10,11 @@ import ( // AccountKeeper defines the expected interface for the Account module. type AccountKeeper interface { - GetAccount(context.Context, sdk.AccAddress) sdk.AccountI // only used for simulation // Methods imported from account should be defined here } // BankKeeper defines the expected interface for the Bank module. type BankKeeper interface { - SpendableCoins(context.Context, sdk.AccAddress) sdk.Coins // Methods imported from bank should be defined here } diff --git a/x/btcstkconsumer/types/genesis.go b/x/btcstkconsumer/types/genesis.go index bdb9f4151..9d633ecd7 100644 --- a/x/btcstkconsumer/types/genesis.go +++ b/x/btcstkconsumer/types/genesis.go @@ -1,8 +1,5 @@ package types -// DefaultIndex is the default global index -const DefaultIndex uint64 = 1 - // DefaultGenesis returns the default genesis state func DefaultGenesis() *GenesisState { return &GenesisState{ diff --git a/x/btcstkconsumer/types/types.go b/x/btcstkconsumer/types/types.go deleted file mode 100644 index ab1254f4c..000000000 --- a/x/btcstkconsumer/types/types.go +++ /dev/null @@ -1 +0,0 @@ -package types diff --git a/x/checkpointing/client/cli/tx.go b/x/checkpointing/client/cli/tx.go index 8de4578b0..c72356930 100644 --- a/x/checkpointing/client/cli/tx.go +++ b/x/checkpointing/client/cli/tx.go @@ -16,9 +16,8 @@ import ( cosmoscli "github.com/cosmos/cosmos-sdk/x/staking/client/cli" "github.com/spf13/cobra" - "github.com/cosmos/cosmos-sdk/client" - // "github.com/cosmos/cosmos-sdk/client/flags" "github.com/babylonlabs-io/babylon/x/checkpointing/types" + "github.com/cosmos/cosmos-sdk/client" ) // GetTxCmd returns the transaction commands for this module diff --git a/x/epoching/keeper/modified_staking.go b/x/epoching/keeper/modified_staking.go index d0b122c11..a59c821aa 100644 --- a/x/epoching/keeper/modified_staking.go +++ b/x/epoching/keeper/modified_staking.go @@ -81,6 +81,7 @@ func (k Keeper) ApplyMatureUnbonding(ctx context.Context, epochNumber uint64) { panic(err) } + // TODO: emit typed event currentSdkCtx.EventManager().EmitEvent( sdk.NewEvent( stakingtypes.EventTypeCompleteUnbonding, @@ -135,6 +136,7 @@ func (k Keeper) ApplyMatureUnbonding(ctx context.Context, epochNumber uint64) { panic(err) } + // TODO: emit typed event currentSdkCtx.EventManager().EmitEvent( sdk.NewEvent( stakingtypes.EventTypeCompleteRedelegation, diff --git a/x/epoching/types/genesis.go b/x/epoching/types/genesis.go index 2b7ca883f..ebbc08ed8 100644 --- a/x/epoching/types/genesis.go +++ b/x/epoching/types/genesis.go @@ -1,8 +1,5 @@ package types -// DefaultIndex is the default capability global index -const DefaultIndex uint64 = 1 - // DefaultGenesis returns the default Capability genesis state func DefaultGenesis() *GenesisState { return &GenesisState{ diff --git a/x/finality/client/cli/tx.go b/x/finality/client/cli/tx.go index 384d87448..04dfffa3c 100644 --- a/x/finality/client/cli/tx.go +++ b/x/finality/client/cli/tx.go @@ -28,6 +28,7 @@ func GetTxCmd() *cobra.Command { cmd.AddCommand( NewCommitPubRandListCmd(), NewAddFinalitySigCmd(), + NewUnjailFinalityProviderCmd(), ) return cmd @@ -165,3 +166,37 @@ func NewAddFinalitySigCmd() *cobra.Command { return cmd } + +func NewUnjailFinalityProviderCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "unjail-finality-provider [fp_btc_pk]", + Args: cobra.ExactArgs(1), + Short: "Unjail a jailed finality provider", + Long: strings.TrimSpace( + `Unjail a jailed finality provider.`, + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + // get finality provider BTC PK + fpBTCPK, err := bbn.NewBIP340PubKeyFromHex(args[0]) + if err != nil { + return err + } + + msg := types.MsgUnjailFinalityProvider{ + Signer: clientCtx.FromAddress.String(), + FpBtcPk: fpBTCPK, + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/finality/keeper/power_dist_change.go b/x/finality/keeper/power_dist_change.go index 75e602163..83ff5d8f7 100644 --- a/x/finality/keeper/power_dist_change.go +++ b/x/finality/keeper/power_dist_change.go @@ -210,6 +210,10 @@ func (k Keeper) ProcessAllPowerDistUpdateEvents( // add the BTC delegation to each restaked finality provider for _, fpBTCPK := range btcDel.FpBtcPkList { fpBTCPKHex := fpBTCPK.MarshalHex() + if !k.BTCStakingKeeper.HasFinalityProvider(ctx, fpBTCPK) { + // This is a consumer FP rather than Babylon FP, skip it + continue + } activedSatsByFpBtcPk[fpBTCPKHex] = append(activedSatsByFpBtcPk[fpBTCPKHex], btcDel.TotalSat) } @@ -338,6 +342,10 @@ func (k Keeper) ProcessAllPowerDistUpdateEvents( for _, fpBTCPKHex := range fpActiveBtcPkHexList { // get the finality provider and initialise its dist info newFP := k.loadFP(ctx, fpByBtcPkHex, fpBTCPKHex) + if newFP == nil { + // This is a consumer FP rather than Babylon FP, skip it + continue + } fpDistInfo := ftypes.NewFinalityProviderDistInfo(newFP) // check for jailing cases @@ -379,6 +387,10 @@ func (k Keeper) processPowerDistUpdateEventUnbond( ) { for _, fpBTCPK := range btcDel.FpBtcPkList { fpBTCPKHex := fpBTCPK.MarshalHex() + if !k.BTCStakingKeeper.HasFinalityProvider(ctx, fpBTCPK) { + // This is a consumer FP rather than Babylon FP, skip it + continue + } unbondedSatsByFpBtcPk[fpBTCPKHex] = append(unbondedSatsByFpBtcPk[fpBTCPKHex], btcDel.TotalSat) } k.processRewardTracker(ctx, cacheFpByBtcPkHex, btcDel, func(fp, del sdk.AccAddress, sats uint64) { @@ -416,9 +428,13 @@ func (k Keeper) votingPowerDistCacheStore(ctx context.Context) prefix.Store { return prefix.NewStore(storeAdapter, ftypes.VotingPowerDistCacheKey) } -// processRewardTracker loads the fps from inside the btc delegation -// with cache and executes the function by passing the fp, delegator address +// processRewardTracker loads Babylon FPs from the given BTC delegation +// and executes the given function over each Babylon FP, delegator address // and satoshi amounts. +// NOTE: +// - The function will only be executed over Babylon FPs but not consumer FPs +// - The function makes uses of the fpByBtcPkHex cache, and the cache only +// contains Babylon FPs but not consumer FPs func (k Keeper) processRewardTracker( ctx context.Context, fpByBtcPkHex map[string]*types.FinalityProvider, @@ -428,6 +444,10 @@ func (k Keeper) processRewardTracker( delAddr := sdk.MustAccAddressFromBech32(btcDel.StakerAddr) for _, fpBTCPK := range btcDel.FpBtcPkList { fp := k.loadFP(ctx, fpByBtcPkHex, fpBTCPK.MarshalHex()) + if fp == nil { + // This is a consumer FP rather than Babylon FP, skip it + continue + } f(fp.Address(), delAddr, btcDel.TotalSat) } } @@ -463,7 +483,9 @@ func (k Keeper) loadFP( } fp, err = k.BTCStakingKeeper.GetFinalityProvider(ctx, *fpBTCPK) if err != nil { - panic(err) // only programming error + // This is a consumer FP, return nil and the caller shall + // skip it + return nil } cacheFpByBtcPkHex[fpBTCPKHex] = fp } diff --git a/x/finality/types/tx.pb.go b/x/finality/types/tx.pb.go index 8726910b7..92757559d 100644 --- a/x/finality/types/tx.pb.go +++ b/x/finality/types/tx.pb.go @@ -766,7 +766,6 @@ type MsgClient interface { CommitPubRandList(ctx context.Context, in *MsgCommitPubRandList, opts ...grpc.CallOption) (*MsgCommitPubRandListResponse, error) // AddFinalitySig adds a finality signature to a given block AddFinalitySig(ctx context.Context, in *MsgAddFinalitySig, opts ...grpc.CallOption) (*MsgAddFinalitySigResponse, error) - // TODO: msg for evidence of equivocation. this is not specified yet // UpdateParams updates the finality module parameters. UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) // UnjailFinalityProvider defines a method for unjailing a jailed @@ -847,7 +846,6 @@ type MsgServer interface { CommitPubRandList(context.Context, *MsgCommitPubRandList) (*MsgCommitPubRandListResponse, error) // AddFinalitySig adds a finality signature to a given block AddFinalitySig(context.Context, *MsgAddFinalitySig) (*MsgAddFinalitySigResponse, error) - // TODO: msg for evidence of equivocation. this is not specified yet // UpdateParams updates the finality module parameters. UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) // UnjailFinalityProvider defines a method for unjailing a jailed diff --git a/x/mint/abci.go b/x/mint/abci.go index dcb7257e1..e4adbbaf8 100644 --- a/x/mint/abci.go +++ b/x/mint/abci.go @@ -82,6 +82,7 @@ func mintBlockProvision(ctx context.Context, k keeper.Keeper) { defer telemetry.ModuleSetGauge(types.ModuleName, float32(toMintCoin.Amount.Int64()), "minted_tokens") } + // TODO: emit typed event sdkCtx.EventManager().EmitEvent( sdk.NewEvent( types.EventTypeMint, diff --git a/x/zoneconcierge/client/cli/tx.go b/x/zoneconcierge/client/cli/tx.go index 23bd93b94..7d69d4419 100644 --- a/x/zoneconcierge/client/cli/tx.go +++ b/x/zoneconcierge/client/cli/tx.go @@ -2,11 +2,11 @@ package cli import ( "fmt" + "github.com/spf13/cobra" - "github.com/cosmos/cosmos-sdk/client" - // "github.com/cosmos/cosmos-sdk/client/flags" "github.com/babylonlabs-io/babylon/x/zoneconcierge/types" + "github.com/cosmos/cosmos-sdk/client" ) // GetTxCmd returns the transaction commands for this module diff --git a/x/zoneconcierge/keeper/grpc_query.go b/x/zoneconcierge/keeper/grpc_query.go index 5b0e7ee62..8df7f9232 100644 --- a/x/zoneconcierge/keeper/grpc_query.go +++ b/x/zoneconcierge/keeper/grpc_query.go @@ -72,6 +72,7 @@ func (k Keeper) ChainsInfo(c context.Context, req *types.QueryChainsInfoRequest) ctx := sdk.UnwrapSDKContext(c) var chainsInfo []*types.ChainInfo + // TODO: paginate this for loop for _, ConsumerId := range req.ConsumerIds { chainInfo, err := k.GetChainInfo(ctx, ConsumerId) if err != nil { @@ -133,6 +134,7 @@ func (k Keeper) EpochChainsInfo(c context.Context, req *types.QueryEpochChainsIn ctx := sdk.UnwrapSDKContext(c) var chainsInfo []*types.ChainInfo + // TODO: paginate this for loop for _, ConsumerId := range req.ConsumerIds { // check if chain ID is valid if !k.HasChainInfo(ctx, ConsumerId) { @@ -239,6 +241,7 @@ func (k Keeper) FinalizedChainsInfo(c context.Context, req *types.QueryFinalized // find the last finalised epoch lastFinalizedEpoch := k.GetLastFinalizedEpoch(ctx) + // TODO: paginate this for loop for _, ConsumerId := range req.ConsumerIds { // check if chain ID is valid if !k.HasChainInfo(ctx, ConsumerId) { diff --git a/x/zoneconcierge/keeper/ibc_header_decorator.go b/x/zoneconcierge/keeper/ibc_header_decorator.go index 930f33e6e..df74ac0d6 100644 --- a/x/zoneconcierge/keeper/ibc_header_decorator.go +++ b/x/zoneconcierge/keeper/ibc_header_decorator.go @@ -22,6 +22,7 @@ func NewIBCHeaderDecorator(k Keeper) *IBCHeaderDecorator { } } +// getHeaderAndClientState extracts the header info and client state from an IBC update client message func (d *IBCHeaderDecorator) getHeaderAndClientState(ctx sdk.Context, m sdk.Msg) (*types.HeaderInfo, *ibctmtypes.ClientState) { // ensure the message is MsgUpdateClient msgUpdateClient, ok := m.(*clienttypes.MsgUpdateClient) @@ -62,6 +63,12 @@ func (d *IBCHeaderDecorator) getHeaderAndClientState(ctx sdk.Context, m sdk.Msg) return headerInfo, cmtClientState } +// PostHandle processes IBC client update messages after they are executed. For each message: +// - Extracts header info and client state if it's a valid IBC client update message +// - Determines if the header is a fork header by checking if client is frozen +// - Handles the header appropriately via HandleHeaderWithValidCommit +// - Unfreezes client if it was frozen due to a fork header +// Only runs during block finalization or tx simulation, and only for successful txs. func (d *IBCHeaderDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simulate, success bool, next sdk.PostHandler) (sdk.Context, error) { // only do this when finalizing a block or simulating the current tx if ctx.ExecMode() != sdk.ExecModeFinalize && !simulate { diff --git a/x/zoneconcierge/module_ibc.go b/x/zoneconcierge/module_ibc.go index c74c92fc8..4225a177c 100644 --- a/x/zoneconcierge/module_ibc.go +++ b/x/zoneconcierge/module_ibc.go @@ -217,16 +217,10 @@ func (im IBCModule) OnAcknowledgementPacket( } } - // // TODO (Babylon): Dispatch and process packet - // switch packet := modulePacketData.Packet.(type) { - // default: - // errMsg := fmt.Sprintf("unrecognized %s packet type: %T", types.ModuleName, packet) - // return errorsmod.Wrap(sdkerrors.ErrUnknownRequest, errMsg) - // } - switch resp := ack.Response.(type) { case *channeltypes.Acknowledgement_Result: im.keeper.Logger(ctx).Info("received an Acknowledgement message", "result", string(resp.Result)) + // TODO: emit typed event ctx.EventManager().EmitEvent( sdk.NewEvent( types.EventTypeAck, @@ -236,6 +230,7 @@ func (im IBCModule) OnAcknowledgementPacket( ) case *channeltypes.Acknowledgement_Error: im.keeper.Logger(ctx).Error("received an Acknowledgement error message", "error", resp.Error) + // TODO: emit typed event ctx.EventManager().EmitEvent( sdk.NewEvent( types.EventTypeAck, @@ -259,13 +254,6 @@ func (im IBCModule) OnTimeoutPacket( return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal packet data: %s", err.Error()) } - // // TODO (Babylon): Dispatch and process packet - // switch packet := modulePacketData.Packet.(type) { - // default: - // errMsg := fmt.Sprintf("unrecognized %s packet type: %T", types.ModuleName, packet) - // return errorsmod.Wrap(sdkerrors.ErrUnknownRequest, errMsg) - // } - // TODO: close channel upon timeout return nil