Skip to content

Commit

Permalink
Merge branch 'main' into feat/bls-keystore-improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
gitferry committed Feb 4, 2025
2 parents 3df2c9f + d2f1b88 commit 74a6e39
Show file tree
Hide file tree
Showing 61 changed files with 3,380 additions and 1,186 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### Improvements

- [#434](https://github.com/babylonlabs-io/babylon/pull/434) Removal of delegator address, change init cmd and add migration cmd
- [#396](https://github.com/babylonlabs-io/babylon/pull/396) BLS Key Separation and ERC2335 Implementation
- [#421](https://github.com/babylonlabs-io/babylon/pull/421) Add checks to public
randomness commit at `TestBTCRewardsDistribution`.
- [#391](https://github.com/babylonlabs-io/babylon/pull/391) Fix e2e `TestBTCRewardsDistribution` flunky
check of rewards
- [#458](https://github.com/babylonlabs-io/babylon/pull/458) Set `CosmosProvider` functions as public
- [#467](https://github.com/babylonlabs-io/babylon/pull/467) BLS keystore improvement

### State Machine Breaking

- [#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 staking integration.
- [#457](https://github.com/babylonlabs-io/babylon/pull/457) Remove staking msg server and update gentx to generate
`MsgWrappedCreateValidator`

### Bug fixes

Expand Down
1 change: 0 additions & 1 deletion app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func NewAnteHandler(

anteHandler := sdk.ChainAnteDecorators(
NewWrappedAnteHandler(authAnteHandler),
epochingkeeper.NewDropValidatorMsgDecorator(epochingKeeper),
NewBtcValidationDecorator(btcConfig, btccKeeper),
)

Expand Down
4 changes: 4 additions & 0 deletions app/ante/fee_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func CheckTxFeeWithGlobalMinGasPrices(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, in
// provided in a transaction.
// NOTE: This implementation should not be used for txs with multiple coins.
func getTxPriority(fee sdk.Coins, gas int64) int64 {
if gas == 0 {
return 0
}

var priority int64
for _, c := range fee {
p := c.Amount.Mul(sdkmath.NewInt(priorityScalingFactor)).QuoRaw(gas)
Expand Down
6 changes: 6 additions & 0 deletions app/ante/get_tx_priority_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ func TestGetTxPriority(t *testing.T) {
gas: 1_000_000,
expectedPri: 1000,
},
{
name: "0 gas, should return 0 priority",
fee: sdk.NewCoins(sdk.NewInt64Coin(denom, 1_000)),
gas: 0,
expectedPri: 0,
},
}

for _, tc := range cases {
Expand Down
49 changes: 44 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/gogoproto/proto"
"github.com/cosmos/ibc-go/modules/capability"
Expand Down Expand Up @@ -329,7 +330,7 @@ func NewBabylonApp(
app.BasicModuleManager = module.NewBasicManagerFromManager(
app.ModuleManager,
map[string]module.AppModuleBasic{
genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
genutiltypes.ModuleName: genutil.NewAppModuleBasic(checkpointingtypes.GenTxMessageValidatorWrappedCreateValidator),
govtypes.ModuleName: gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
Expand Down Expand Up @@ -454,10 +455,7 @@ func NewBabylonApp(

app.ModuleManager.RegisterInvariants(app.CrisisKeeper)
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
if err := app.ModuleManager.RegisterServices(app.configurator); err != nil {
panic(err)
}

app.RegisterServicesWithoutStaking()
autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.ModuleManager.Modules))

reflectionSvc, err := runtimeservices.NewReflectionService()
Expand Down Expand Up @@ -588,6 +586,47 @@ func NewBabylonApp(
return app
}

// RegisterServicesWithoutStaking calls the module manager
// registration services without the staking module.
func (app *BabylonApp) RegisterServicesWithoutStaking() {
// removes the staking module from the register services
stkModTemp := app.ModuleManager.Modules[stakingtypes.ModuleName]
delete(app.ModuleManager.Modules, stakingtypes.ModuleName)

if err := app.ModuleManager.RegisterServices(app.configurator); err != nil {
panic(err)
}

app.RegisterStakingQueryAndMigrations()

// adds the staking module back it back
app.ModuleManager.Modules[stakingtypes.ModuleName] = stkModTemp
}

// RegisterStakingQueryAndMigrations registrates in the configurator
// the x/staking query server and its migrations
func (app *BabylonApp) RegisterStakingQueryAndMigrations() {
cfg, stkK := app.configurator, app.StakingKeeper
stkq := stakingkeeper.NewQuerier(stkK)

stakingtypes.RegisterQueryServer(cfg.QueryServer(), stkq)

ls := app.GetSubspace(stakingtypes.ModuleName)
m := stakingkeeper.NewMigrator(stkK, ls)
if err := cfg.RegisterMigration(stakingtypes.ModuleName, 1, m.Migrate1to2); err != nil {
panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", stakingtypes.ModuleName, err))
}
if err := cfg.RegisterMigration(stakingtypes.ModuleName, 2, m.Migrate2to3); err != nil {
panic(fmt.Sprintf("failed to migrate x/%s from version 2 to 3: %v", stakingtypes.ModuleName, err))
}
if err := cfg.RegisterMigration(stakingtypes.ModuleName, 3, m.Migrate3to4); err != nil {
panic(fmt.Sprintf("failed to migrate x/%s from version 3 to 4: %v", stakingtypes.ModuleName, err))
}
if err := cfg.RegisterMigration(stakingtypes.ModuleName, 4, m.Migrate4to5); err != nil {
panic(fmt.Sprintf("failed to migrate x/%s from version 4 to 5: %v", stakingtypes.ModuleName, err))
}
}

// GetBaseApp returns the BaseApp of BabylonApp
// required by ibctesting
func (app *BabylonApp) GetBaseApp() *baseapp.BaseApp {
Expand Down
36 changes: 33 additions & 3 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ import (
dbm "github.com/cosmos/cosmos-db"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
stktypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/require"

"github.com/babylonlabs-io/babylon/testutil/signer"
testsigner "github.com/babylonlabs-io/babylon/testutil/signer"
checkpointingtypes "github.com/babylonlabs-io/babylon/x/checkpointing/types"
)

func TestBabylonBlockedAddrs(t *testing.T) {
db := dbm.NewMemDB()

tbs, err := signer.SetupTestBlsSigner()
tbs, err := testsigner.SetupTestBlsSigner()
require.NoError(t, err)
blsSigner := checkpointingtypes.BlsSigner(tbs)

Expand Down Expand Up @@ -79,7 +80,7 @@ func TestGetMaccPerms(t *testing.T) {
func TestUpgradeStateOnGenesis(t *testing.T) {
db := dbm.NewMemDB()

tbs, err := signer.SetupTestBlsSigner()
tbs, err := testsigner.SetupTestBlsSigner()
require.NoError(t, err)
blsSigner := checkpointingtypes.BlsSigner(tbs)

Expand All @@ -103,3 +104,32 @@ func TestUpgradeStateOnGenesis(t *testing.T) {
}
}
}

func TestStakingRouterDisabled(t *testing.T) {
db := dbm.NewMemDB()
tbs, _ := testsigner.SetupTestBlsSigner()
logger := log.NewTestLogger(t)

app := NewBabylonAppWithCustomOptions(t, false, tbs, SetupOptions{
Logger: logger,
DB: db,
InvCheckPeriod: 0,
SkipUpgradeHeights: map[int64]bool{},
AppOpts: TmpAppOptions(),
})

msgs := []sdk.Msg{
&stktypes.MsgCreateValidator{},
&stktypes.MsgBeginRedelegate{},
&stktypes.MsgCancelUnbondingDelegation{},
&stktypes.MsgDelegate{},
&stktypes.MsgEditValidator{},
&stktypes.MsgUndelegate{},
&stktypes.MsgUpdateParams{},
}

for _, msg := range msgs {
msgHandler := app.MsgServiceRouter().HandlerByTypeURL(sdk.MsgTypeURL(msg))
require.Nil(t, msgHandler)
}
}
5 changes: 2 additions & 3 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ func (ak *AppKeepers) InitKeepers(
runtime.NewKVStoreService(keys[epochingtypes.StoreKey]),
bankKeeper,
stakingKeeper,
stakingkeeper.NewMsgServerImpl(stakingKeeper),
appparams.AccGov.String(),
)

Expand Down Expand Up @@ -410,7 +411,7 @@ func (ak *AppKeepers) InitKeepers(
appparams.AccGov.String(),
)

wasmOpts = append(owasm.RegisterCustomPlugins(&ak.EpochingKeeper, &ak.CheckpointingKeeper, &ak.BTCLightClientKeeper, &ak.ZoneConciergeKeeper), wasmOpts...)
wasmOpts = append(owasm.RegisterCustomPlugins(&epochingKeeper, &ak.CheckpointingKeeper, &ak.BTCLightClientKeeper, &ak.ZoneConciergeKeeper), wasmOpts...)
wasmOpts = append(owasm.RegisterGrpcQueries(*bApp.GRPCQueryRouter(), appCodec), wasmOpts...)

ak.WasmKeeper = wasmkeeper.NewKeeper(
Expand Down Expand Up @@ -571,8 +572,6 @@ func (ak *AppKeepers) InitKeepers(
appparams.AccGov.String(),
)

// add msgServiceRouter so that the epoching module can forward unwrapped messages to the staking module
epochingKeeper.SetMsgServiceRouter(bApp.MsgServiceRouter())
// make ZoneConcierge and Monitor to subscribe to the epoching's hooks
epochingKeeper.SetHooks(
epochingtypes.NewMultiEpochingHooks(zcKeeper.Hooks(), monitorKeeper.Hooks()),
Expand Down
2 changes: 1 addition & 1 deletion app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func genesisStateWithValSet(t *testing.T,
Description: stakingtypes.Description{},
UnbondingHeight: int64(0),
UnbondingTime: time.Unix(0, 0).UTC(),
Commission: stakingtypes.NewCommission(math.LegacyZeroDec(), math.LegacyZeroDec(), math.LegacyZeroDec()),
Commission: stakingtypes.NewCommission(math.LegacyZeroDec(), math.LegacyNewDec(100), math.LegacyNewDec(2)),
MinSelfDelegation: math.ZeroInt(),
}

Expand Down
3 changes: 1 addition & 2 deletions client/client/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import (
"fmt"
"sync"

"github.com/babylonlabs-io/babylon/client/babylonclient"

signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1"
"cosmossdk.io/errors"
txsigning "cosmossdk.io/x/tx/signing"
"github.com/avast/retry-go/v4"
"github.com/babylonlabs-io/babylon/client/babylonclient"
btcctypes "github.com/babylonlabs-io/babylon/x/btccheckpoint/types"
btclctypes "github.com/babylonlabs-io/babylon/x/btclightclient/types"
abci "github.com/cometbft/cometbft/abci/types"
Expand Down
9 changes: 3 additions & 6 deletions cmd/babylond/cmd/create_bls_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ func CreateBlsKeyCmd() *cobra.Command {
Long: strings.TrimSpace(`create-bls will create a pair of BLS keys that are used to
send BLS signatures for checkpointing.
BLS keys are stored along with other validator keys in priv_validator_key.json,
which should exist before running the command (via babylond init or babylond testnet).
Example:
$ babylond create-bls-key --home ./
`,
Expand All @@ -28,7 +25,7 @@ $ babylond create-bls-key --home ./
RunE: func(cmd *cobra.Command, args []string) error {
homeDir, _ := cmd.Flags().GetString(flags.FlagHome)
password, _ := cmd.Flags().GetString(flagBlsPassword)
createBlsKeyAndSave(homeDir, password)
CreateBlsKeyAndSave(homeDir, password)
return nil
},
}
Expand All @@ -38,8 +35,8 @@ $ babylond create-bls-key --home ./
return cmd
}

// createBlsKeyAndSave creates a pair of BLS keys and saves them to files
func createBlsKeyAndSave(homeDir, password string) {
// CreateBlsKeyAndSave creates a pair of BLS keys and saves them to files
func CreateBlsKeyAndSave(homeDir, password string) {
if password == "" {
password = appsigner.NewBlsPassword()
}
Expand Down
108 changes: 0 additions & 108 deletions cmd/babylond/cmd/genhelpers/bls_add.go

This file was deleted.

Loading

0 comments on commit 74a6e39

Please sign in to comment.