Skip to content

Commit

Permalink
Merge branch 'release/v1.x' into backport/PR-519
Browse files Browse the repository at this point in the history
  • Loading branch information
GAtom22 committed Feb 28, 2025
2 parents e9ce519 + ab3ee89 commit a6f7beb
Show file tree
Hide file tree
Showing 87 changed files with 5,815 additions and 990 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,32 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### Improvements

- [#558](https://github.com/babylonlabs-io/babylon/pull/558) Change BLS public key format from hex to base64 in bls_key.json.
- [#466](https://github.com/babylonlabs-io/babylon/pull/466) Add e2e test to
- [#519](https://github.com/babylonlabs-io/babylon/pull/519) Add missing data in `InitGenesis` and `ExportGenesis` in `x/incentive` module
block bank send and still create BTC delegations
- [#538](https://github.com/babylonlabs-io/babylon/pull/538) Upgrade to wasmd v0.54.x and wasmvm v2.2.x
- [#527](https://github.com/babylonlabs-io/babylon/pull/527) Create BSL signer on start command with flags.
- [#554](https://github.com/babylonlabs-io/babylon/pull/554) Improve vote extension logs
- [#566](https://github.com/babylonlabs-io/babylon/pull/566) Remove float values in `BeforeValidatorSlashed` hook in `x/epoching` module

### State Machine Breaking

- [#518](https://github.com/babylonlabs-io/babylon/pull/518) Add check BTC reorg blocks higher than `k` deep
- [#530](https://github.com/babylonlabs-io/babylon/pull/530) Add `ConflictingCheckpointReceived` flag in `x/checkpointing` module.
- [#537](https://github.com/babylonlabs-io/babylon/pull/537) Add `CommissionRates` type to `MsgCreateFinalityProvider` and commission validation to `EditFinalityProvider` in `x/btcstaking` module
- [#567](https://github.com/babylonlabs-io/babylon/pull/567) Add check for height overflow in `CommitPubRandList` in `x/finality` module

### Bug fixes

- - [#539](https://github.com/babylonlabs-io/babylon/pull/539) fix: add missing `x/checkpointing` hooks
- [#539](https://github.com/babylonlabs-io/babylon/pull/539) fix: add missing `x/checkpointing` hooks
invocation
- [#579](https://github.com/babylonlabs-io/babylon/pull/579) Slashed FP gets activated in voting power distribution
cache if an old BTC delegation receives inclusion proof
- [#592](https://github.com/babylonlabs-io/babylon/pull/592) finality: avoid refunding finality signatures over forks
- [#525](https://github.com/babylonlabs-io/babylon/pull/525) fix: add back `NewIBCHeaderDecorator` post handler
- [#563](https://github.com/babylonlabs-io/babylon/pull/563) reject coinbase staking transactions
- [#584](https://github.com/babylonlabs-io/babylon/pull/584) fix: Panic can be triggered in handling liveness

## v1.0.0-rc6

Expand Down
4 changes: 2 additions & 2 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewAnteHandler(
feegrantKeeper authante.FeegrantKeeper,
signModeHandler *txsigning.HandlerMap,
ibcKeeper *ibckeeper.Keeper,
wasmConfig *wasmtypes.WasmConfig,
wasmConfig *wasmtypes.NodeConfig,
wasmKeeper *wasmkeeper.Keeper,
circuitKeeper *circuitkeeper.Keeper,
epochingKeeper *epochingkeeper.Keeper,
Expand Down Expand Up @@ -51,7 +51,7 @@ func NewAnteHandler(
TxFeeChecker: CheckTxFeeWithGlobalMinGasPrices,
},
IBCKeeper: ibcKeeper,
WasmConfig: wasmConfig,
NodeConfig: wasmConfig,
TXCounterStoreService: txCounterStoreService,
WasmKeeper: wasmKeeper,
CircuitKeeper: circuitKeeper,
Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func NewBabylonApp(
bApp.SetInterfaceRegistry(interfaceRegistry)
bApp.SetTxEncoder(txConfig.TxEncoder())

wasmConfig, err := wasm.ReadWasmConfig(appOpts)
wasmConfig, err := wasm.ReadNodeConfig(appOpts)
if err != nil {
panic(fmt.Sprintf("error while reading wasm config: %s", err))
}
Expand Down
2 changes: 2 additions & 0 deletions app/include_upgrade_testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
v1 "github.com/babylonlabs-io/babylon/app/upgrades/v1"
"github.com/babylonlabs-io/babylon/app/upgrades/v1/testnet"
v1rc5 "github.com/babylonlabs-io/babylon/app/upgrades/v1rc5/testnet"
v1rc7 "github.com/babylonlabs-io/babylon/app/upgrades/v1rc7/testnet"
)

// init is used to include v1 upgrade testnet data
Expand All @@ -23,5 +24,6 @@ func init() {
AllowedStakingTxHashesStr: testnet.AllowedStakingTxHashesStr,
}, testnet.TestnetParamUpgrade),
v1rc5.CreateUpgrade(),
v1rc7.CreateUpgrade(),
}
}
3 changes: 2 additions & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (ak *AppKeepers) InitKeepers(
skipUpgradeHeights map[int64]bool,
blsSigner checkpointingtypes.BlsSigner,
appOpts servertypes.AppOptions,
wasmConfig wasmtypes.WasmConfig,
wasmConfig wasmtypes.NodeConfig,
wasmOpts []wasmkeeper.Option,
blockedAddress map[string]bool,
) {
Expand Down Expand Up @@ -540,6 +540,7 @@ func (ak *AppKeepers) InitKeepers(
bApp.GRPCQueryRouter(),
homePath,
wasmConfig,
wasmtypes.VMConfig{},
WasmCapabilities(),
appparams.AccGov.String(),
wasmOpts...,
Expand Down
3 changes: 0 additions & 3 deletions app/modules.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app

import (
"github.com/CosmWasm/wasmd/x/wasm/ibctesting"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/cosmos/cosmos-sdk/client"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
Expand All @@ -11,8 +10,6 @@ import (
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
)

var _ ibctesting.ChainApp = &BabylonApp{}

// The following functions are required by ibctesting
// (copied from https://github.com/osmosis-labs/osmosis/blob/main/app/modules.go)

Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v1/data_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestHardCodedBtcStakingParamsAreValid(t *testing.T) {
for _, upgradeData := range UpgradeV1Data {
db := dbm.NewMemDB()
stateStore := store.NewCommitMultiStore(db, log.NewTestLogger(t), storemetrics.NewNoOpMetrics())
k, ctx := testutilk.BTCStakingKeeperWithStore(t, db, stateStore, nil, nil, nil)
k, ctx := testutilk.BTCStakingKeeperWithStore(t, db, stateStore, nil, nil, nil, nil)

params, err := v1.LoadBtcStakingParamsFromData(upgradeData.BtcStakingParamsStr)
require.NoError(t, err)
Expand Down
100 changes: 100 additions & 0 deletions app/upgrades/v1rc7/testnet/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package testnet

import (
"context"
"fmt"

sdkmath "cosmossdk.io/math"
upgradetypes "cosmossdk.io/x/upgrade/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/types/query"

"github.com/babylonlabs-io/babylon/app/keepers"
"github.com/babylonlabs-io/babylon/app/upgrades"
btcstakingkeeper "github.com/babylonlabs-io/babylon/x/btcstaking/keeper"
btcstakingtypes "github.com/babylonlabs-io/babylon/x/btcstaking/types"
)

const (
UpgradeName = "v1rc7"
)

func CreateUpgrade() upgrades.Upgrade {
return upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler(),
}
}

// CreateUpgradeHandler upgrade handler for launch.
func CreateUpgradeHandler() upgrades.UpgradeHandlerCreator {
return func(mm *module.Manager, cfg module.Configurator, keepers *keepers.AppKeepers) upgradetypes.UpgradeHandler {
return func(context context.Context, _plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx := sdk.UnwrapSDKContext(context)

logger := ctx.Logger().With("upgrade", UpgradeName)
migrations, err := mm.RunMigrations(ctx, cfg, fromVM)
if err != nil {
return nil, fmt.Errorf("failed to run migrations: %w", err)
}

logger.Info("migrating finality providers...")
if err := MigrateFinalityProviders(ctx, keepers.BTCStakingKeeper); err != nil {
return nil, fmt.Errorf("failed migrate finality providers: %w", err)
}
logger.Info("finality providers migration done!")

return migrations, nil
}
}
}

// MigrateFinalityProviders populates the new CommissionInfo field
// with default values
func MigrateFinalityProviders(goCtx context.Context, k btcstakingkeeper.Keeper) error {
var (
defaultCommissionMaxRate = sdkmath.LegacyMustNewDecFromStr("0.2")
defaultCommissionMaxChangeRate = sdkmath.LegacyMustNewDecFromStr("0.01")
ctx = sdk.UnwrapSDKContext(goCtx)
pagKey = []byte{}
)
for {
// FinalityProviders query is paginated, so we'll need to use
// the page key to make sure to migrate all of them
res, err := k.FinalityProviders(goCtx, &btcstakingtypes.QueryFinalityProvidersRequest{
Pagination: &query.PageRequest{Key: pagKey},
})
if err != nil {
return err
}

for _, fp := range res.FinalityProviders {
err := k.UpdateFinalityProvider(goCtx, &btcstakingtypes.FinalityProvider{
Addr: fp.Addr,
Description: fp.Description,
Commission: fp.Commission,
BtcPk: fp.BtcPk,
Pop: fp.Pop,
SlashedBabylonHeight: fp.SlashedBabylonHeight,
SlashedBtcHeight: fp.SlashedBtcHeight,
Jailed: fp.Jailed,
HighestVotedHeight: fp.HighestVotedHeight,
CommissionInfo: btcstakingtypes.NewCommissionInfoWithTime(defaultCommissionMaxRate, defaultCommissionMaxChangeRate, ctx.BlockHeader().Time),
})
if err != nil {
return err
}
}

// Break if there are no more pages
if res.Pagination == nil || len(res.Pagination.NextKey) == 0 {
break
}

// Set the next pagination key
pagKey = res.Pagination.NextKey
}

return nil
}
89 changes: 89 additions & 0 deletions app/upgrades/v1rc7/testnet/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package testnet_test

import (
"math/rand"
"sort"
"testing"

sdkmath "cosmossdk.io/math"
"cosmossdk.io/store/prefix"
storetypes "cosmossdk.io/store/types"

appparams "github.com/babylonlabs-io/babylon/app/params"
"github.com/babylonlabs-io/babylon/app/upgrades/v1rc7/testnet"
"github.com/babylonlabs-io/babylon/testutil/datagen"
keepertest "github.com/babylonlabs-io/babylon/testutil/keeper"
btcstakingtypes "github.com/babylonlabs-io/babylon/x/btcstaking/types"
"github.com/cosmos/cosmos-sdk/runtime"

"github.com/test-go/testify/require"
)

func FuzzMigrateFinalityProviders(f *testing.F) {
datagen.AddRandomSeedsToFuzzer(f, 10)
f.Fuzz(func(t *testing.T, seed int64) {
var (
r = rand.New(rand.NewSource(seed))
storeKey = storetypes.NewKVStoreKey(btcstakingtypes.StoreKey)
storeService = runtime.NewKVStoreService(storeKey)
encConf = appparams.DefaultEncodingConfig()
keeper, ctx = keepertest.BTCStakingKeeperWithStoreKey(t, storeKey, nil, nil, nil)
)

// seed the store with finality providers without commission info
storeAdapter := runtime.KVStoreAdapter(storeService.OpenKVStore(ctx))
store := prefix.NewStore(storeAdapter, btcstakingtypes.FinalityProviderKey)
fpCount := rand.Intn(300)
// slice of the expected finality providers after the migration
expFps := make([]btcstakingtypes.FinalityProvider, fpCount)
for i := range expFps {
fp, err := datagen.GenRandomFinalityProvider(r)
require.NoError(t, err)
// make sure commission info is nil when seeding the store
fp.CommissionInfo = nil
// use store directly to store the fps
fpBytes := encConf.Codec.MustMarshal(fp)
store.Set(fp.BtcPk.MustMarshal(), fpBytes)

// Add the expected fp with the commission info defined
expFps[i] = btcstakingtypes.FinalityProvider{
Addr: fp.Addr,
Description: fp.Description,
Commission: fp.Commission,
BtcPk: fp.BtcPk,
Pop: fp.Pop,
SlashedBabylonHeight: fp.SlashedBabylonHeight,
SlashedBtcHeight: fp.SlashedBtcHeight,
Jailed: fp.Jailed,
HighestVotedHeight: fp.HighestVotedHeight,
CommissionInfo: btcstakingtypes.NewCommissionInfoWithTime(
sdkmath.LegacyMustNewDecFromStr("0.2"),
sdkmath.LegacyMustNewDecFromStr("0.01"),
ctx.BlockHeader().Time,
),
}
}

// Run the migration logic
require.NoError(t, testnet.MigrateFinalityProviders(ctx, *keeper))

// get all the stored finality providers
migratedFps := []btcstakingtypes.FinalityProvider{}
iter := store.Iterator(nil, nil)
defer iter.Close()
for ; iter.Valid(); iter.Next() {
var fp btcstakingtypes.FinalityProvider
encConf.Codec.MustUnmarshal(iter.Value(), &fp)
migratedFps = append(migratedFps, fp)
}

// sort the expected and migrated slices
sort.Slice(expFps, func(i, j int) bool {
return expFps[i].Addr < expFps[j].Addr
})
sort.Slice(migratedFps, func(i, j int) bool {
return migratedFps[i].Addr < migratedFps[j].Addr
})
require.Equal(t, expFps, migratedFps)
})
}
Loading

0 comments on commit a6f7beb

Please sign in to comment.