Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### State breaking

- [#1965](https://github.com/babylonlabs-io/babylon/pull/1965) chore: bump CosmWasm/wasmd v0.60.5
- [#2024](https://github.com/babylonlabs-io/babylon/pull/2024) chore(deps): bump
cosmos-sdk to v0.53.8, ship it as an empty v4.4 upgrade

## v4.3.1

Expand Down
2 changes: 2 additions & 0 deletions app/include_upgrade_mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
v41 "github.com/babylonlabs-io/babylon/v4/app/upgrades/v4_1"
v42 "github.com/babylonlabs-io/babylon/v4/app/upgrades/v4_2"
v43 "github.com/babylonlabs-io/babylon/v4/app/upgrades/v4_3"
v44 "github.com/babylonlabs-io/babylon/v4/app/upgrades/v4_4"
)

var WhitelistedChannelsID = map[string]struct{}{
Expand All @@ -27,6 +28,7 @@ var WhitelistedChannelsID = map[string]struct{}{
// init is used to include v2.2 upgrade for mainnet data
func init() {
Upgrades = []upgrades.Upgrade{
v44.Upgrade,
v43.Upgrade,
v42.Upgrade,
v41.Upgrade,
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 @@ -16,13 +16,15 @@ import (
v41 "github.com/babylonlabs-io/babylon/v4/app/upgrades/v4_1"
v42 "github.com/babylonlabs-io/babylon/v4/app/upgrades/v4_2"
v43 "github.com/babylonlabs-io/babylon/v4/app/upgrades/v4_3"
v44 "github.com/babylonlabs-io/babylon/v4/app/upgrades/v4_4"
v4rc3 "github.com/babylonlabs-io/babylon/v4/app/upgrades/v4rc3/testnet"
)

// init is used to include v1 upgrade testnet data
// it is also used for e2e testing
func init() {
Upgrades = []upgrades.Upgrade{
v44.Upgrade,
v43.Upgrade,
v42.Upgrade,
v41.Upgrade,
Expand Down
37 changes: 37 additions & 0 deletions app/upgrades/v4_4/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package v4_4

import (
"context"

store "cosmossdk.io/store/types"
upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/types/module"

"github.com/babylonlabs-io/babylon/v4/app/keepers"
"github.com/babylonlabs-io/babylon/v4/app/upgrades"
)

const UpgradeName = "v4.4"

// Upgrade carries no state migration. It exists to coordinate the binary swap
// for the cosmos-sdk v0.53.8 security release, which is state breaking: the SDK
// changes are unconditional binary behaviour, so every validator must switch at
// the same height or the network forks on the first affected transaction.
//
// No SDK module changed its ConsensusVersion between v0.53.4 (the version
// mainnet runs) and v0.53.8, so RunMigrations has nothing to migrate and no
// store keys are added or deleted.
var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{},
Deleted: []string{},
},
}

func CreateUpgradeHandler(mm *module.Manager, configurator module.Configurator, _ *keepers.AppKeepers) upgradetypes.UpgradeHandler {
return func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return mm.RunMigrations(ctx, configurator, fromVM)
}
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module github.com/babylonlabs-io/babylon/v4
require (
github.com/CosmWasm/wasmd v0.60.5
github.com/btcsuite/btcd v0.24.2
github.com/cometbft/cometbft v0.38.22
github.com/cometbft/cometbft v0.38.23
github.com/cometbft/cometbft-db v0.15.0
github.com/cosmos/cosmos-sdk v0.53.5
github.com/cosmos/cosmos-sdk v0.53.8
github.com/cosmos/ibc-go/modules/light-clients/08-wasm/v10 v10.3.0
github.com/gorilla/mux v1.8.1
github.com/grpc-ecosystem/grpc-gateway v1.16.0
Expand Down Expand Up @@ -120,7 +120,7 @@ require (
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/iavl v1.2.4 // indirect
github.com/cosmos/ledger-cosmos-go v0.16.0 // indirect
github.com/cosmos/ledger-cosmos-go v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/desertbit/timer v1.0.1 // indirect
github.com/dgraph-io/ristretto v0.2.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,8 @@ github.com/cockroachdb/redact v1.1.6/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZ
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo=
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/cometbft/cometbft v0.38.22 h1:T9BLO8f4DOhvQ5ic9ULq+4WjOlgxeKtFt2lR0IL5Qos=
github.com/cometbft/cometbft v0.38.22/go.mod h1:jtH//cs5e2U5dNiaYIPMBwWXZsedXJfIie77gVhuRaA=
github.com/cometbft/cometbft v0.38.23 h1:jtCe5Do4EcHVf/FCyZMvkBm+AmsRGGyvswImXYAabdM=
github.com/cometbft/cometbft v0.38.23/go.mod h1:jtH//cs5e2U5dNiaYIPMBwWXZsedXJfIie77gVhuRaA=
github.com/cometbft/cometbft-db v0.15.0 h1:VLtsRt8udD4jHCyjvrsTBpgz83qne5hnL245AcPJVRk=
github.com/cometbft/cometbft-db v0.15.0/go.mod h1:EBrFs1GDRiTqrWXYi4v90Awf/gcdD5ExzdPbg4X8+mk=
github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg=
Expand All @@ -856,8 +856,8 @@ github.com/cosmos/cosmos-db v1.1.3 h1:7QNT77+vkefostcKkhrzDK9uoIEryzFrU9eoMeaQOP
github.com/cosmos/cosmos-db v1.1.3/go.mod h1:kN+wGsnwUJZYn8Sy5Q2O0vCYA99MJllkKASbs6Unb9U=
github.com/cosmos/cosmos-proto v1.0.0-beta.5 h1:eNcayDLpip+zVLRLYafhzLvQlSmyab+RC5W7ZfmxJLA=
github.com/cosmos/cosmos-proto v1.0.0-beta.5/go.mod h1:hQGLpiIUloJBMdQMMWb/4wRApmI9hjHH05nefC0Ojec=
github.com/cosmos/cosmos-sdk v0.53.5 h1:JPue+SFn2gyDzTV9TYb8mGpuIH3kGt7WbGadulkpTcU=
github.com/cosmos/cosmos-sdk v0.53.5/go.mod h1:AQJx0jpon70WAD4oOs/y+SlST4u7VIwEPR6F8S7JMdo=
github.com/cosmos/cosmos-sdk v0.53.8 h1:rKQIgqifo3Izv/JQLpPIjReOJ7jK+Qh8Rt8GIttDADw=
github.com/cosmos/cosmos-sdk v0.53.8/go.mod h1:b/De6uhCfooGEy4kE5G4C0A+MxK9aPr0nZNMyR+PmY0=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=
Expand All @@ -883,8 +883,8 @@ github.com/cosmos/ics23/go v0.11.0 h1:jk5skjT0TqX5e5QJbEnwXIS2yI2vnmLOgpQPeM5Rtn
github.com/cosmos/ics23/go v0.11.0/go.mod h1:A8OjxPE67hHST4Icw94hOxxFEJMBG031xIGF/JHNIY0=
github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo=
github.com/cosmos/keyring v1.2.0/go.mod h1:fc+wB5KTk9wQ9sDx0kFXB3A0MaeGHM9AwRStKOQ5vOA=
github.com/cosmos/ledger-cosmos-go v0.16.0 h1:YKlWPG9NnGZIEUb2bEfZ6zhON1CHlNTg0QKRRGcNEd0=
github.com/cosmos/ledger-cosmos-go v0.16.0/go.mod h1:WrM2xEa8koYoH2DgeIuZXNarF7FGuZl3mrIOnp3Dp0o=
github.com/cosmos/ledger-cosmos-go v1.0.0 h1:jNKW89nPf0vR0EkjHG8Zz16h6p3zqwYEOxlHArwgYtw=
github.com/cosmos/ledger-cosmos-go v1.0.0/go.mod h1:mGaw2wDOf+Z6SfRJsMGxU9DIrBa4du0MAiPlpPhLAOE=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/creachadair/atomicfile v0.3.7 h1:wdg8+Isz07NDMi2yZQAoI1EKB9SxuDhvo5MUii/ZqlM=
Expand Down
13 changes: 13 additions & 0 deletions test/e2ev2/tmanager/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/babylonlabs-io/babylon/v4/testutil/datagen"
blc "github.com/babylonlabs-io/babylon/v4/x/btclightclient/types"
epochingtypes "github.com/babylonlabs-io/babylon/v4/x/epoching/types"

"encoding/json"

Expand Down Expand Up @@ -526,6 +527,18 @@ func (n *Node) WaitForNextBlocks(numberOfBlocks uint64) {
}, fmt.Sprintf("Timed out waiting for block %d. Current height is: %d", latest, blockToWait))
}

func (n *Node) WaitForEpochEnd() *epochingtypes.QueryCurrentEpochResponse {
currEpoch := n.QueryCurrentEpoch()
currEpochNum := currEpoch.CurrentEpoch

n.WaitForCondition(func() bool {
currEpoch = n.QueryCurrentEpoch()
newEpochNum := currEpoch.CurrentEpoch
return newEpochNum > currEpochNum
}, fmt.Sprintf("Timed out waiting for epoch %d. Current epoch is: %d", currEpochNum+1, currEpochNum))
return currEpoch
}

func (n *Node) WaitUntilBlkHeight(blkHeight uint32) {
var (
latestBlockHeight uint64
Expand Down
46 changes: 46 additions & 0 deletions test/e2ev2/tmanager/node_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import (
bbn "github.com/babylonlabs-io/babylon/v4/types"
btclighttypes "github.com/babylonlabs-io/babylon/v4/x/btclightclient/types"
btcstktypes "github.com/babylonlabs-io/babylon/v4/x/btcstaking/types"
epochingtypes "github.com/babylonlabs-io/babylon/v4/x/epoching/types"
ictvtypes "github.com/babylonlabs-io/babylon/v4/x/incentive/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdktx "github.com/cosmos/cosmos-sdk/types/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
stktypes "github.com/cosmos/cosmos-sdk/x/staking/types"
channeltypes "github.com/cosmos/ibc-go/v10/modules/core/04-channel/types"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
Expand Down Expand Up @@ -93,6 +95,50 @@ func (n *Node) UpgradeQuery(f func(upgradetypes.QueryClient)) {
})
}

func (n *Node) StakingQuery(f func(stktypes.QueryClient)) {
n.GrpcConn(func(conn *grpc.ClientConn) {
stkClient := stktypes.NewQueryClient(conn)
f(stkClient)
})
}

func (n *Node) EpochingQuery(f func(epochingtypes.QueryClient)) {
n.GrpcConn(func(conn *grpc.ClientConn) {
epochingClient := epochingtypes.NewQueryClient(conn)
f(epochingClient)
})
}

func (n *Node) QueryDelegation(delAddr sdk.AccAddress, valAddr sdk.ValAddress) stktypes.DelegationResponse {
var (
resp *stktypes.QueryDelegationResponse
err error
)

n.StakingQuery(func(qc stktypes.QueryClient) {
resp, err = qc.Delegation(context.Background(), &stktypes.QueryDelegationRequest{
DelegatorAddr: delAddr.String(),
ValidatorAddr: valAddr.String(),
})
require.NoError(n.T(), err)
})

return *resp.DelegationResponse
}

func (n *Node) QueryCurrentEpoch() *epochingtypes.QueryCurrentEpochResponse {
var (
resp *epochingtypes.QueryCurrentEpochResponse
err error
)

n.EpochingQuery(func(qc epochingtypes.QueryClient) {
resp, err = qc.CurrentEpoch(context.Background(), &epochingtypes.QueryCurrentEpochRequest{})
require.NoError(n.T(), err)
})
return resp
}

// QueryProposals returns all governance proposals on the chain.
func (n *Node) QueryProposals() *govtypes.QueryProposalsResponse {
var (
Expand Down
16 changes: 16 additions & 0 deletions test/e2ev2/tmanager/node_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,29 @@ import (
tokenfactorytypes "github.com/strangelove-ventures/tokenfactory/x/tokenfactory/types"
"github.com/stretchr/testify/require"

appparams "github.com/babylonlabs-io/babylon/v4/app/params"
"github.com/babylonlabs-io/babylon/v4/btcstaking"
"github.com/babylonlabs-io/babylon/v4/testutil/datagen"
tkeeper "github.com/babylonlabs-io/babylon/v4/testutil/keeper"
bbn "github.com/babylonlabs-io/babylon/v4/types"
bstypes "github.com/babylonlabs-io/babylon/v4/x/btcstaking/types"
epochingtypes "github.com/babylonlabs-io/babylon/v4/x/epoching/types"
stktypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

// WrappedDelegate submits an epoched delegation from walletName to valAddr.
func (n *Node) WrappedDelegate(walletName string, valAddr sdk.ValAddress, amt math.Int) {
wallet := n.Wallet(walletName)
require.NotNil(n.T(), wallet, "Wallet %s not found", walletName)

amtDelegate := sdk.NewCoin(appparams.DefaultBondDenom, amt)
msg := epochingtypes.NewMsgWrappedDelegate(stktypes.NewMsgDelegate(wallet.Address.String(), valAddr.String(), amtDelegate))

_, tx := wallet.SubmitMsgs(msg)
require.NotNil(n.T(), tx, "Delegate tx should not be nil")
n.T().Logf("delegation created %+v", msg)
}

// SendIBCTransfer creates and submits an IBC transfer transaction
func (n *Node) SendIBCTransfer(wallet *WalletSender, recipient string, token sdk.Coin, channelID string, memo string) string {
n.T().Logf("Sending %s from %s (BSN) to %s (BBN) via channel %s", token.String(), wallet.Address.String(), recipient, channelID)
Expand Down
124 changes: 124 additions & 0 deletions test/e2ev2/upgrades_v4_4_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package e2e2

import (
"testing"

"github.com/stretchr/testify/require"

sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1"

upgradetypes "cosmossdk.io/x/upgrade/types"
appparams "github.com/babylonlabs-io/babylon/v4/app/params"
v44 "github.com/babylonlabs-io/babylon/v4/app/upgrades/v4_4"
"github.com/babylonlabs-io/babylon/v4/test/e2ev2/tmanager"
)

// TestUpgradeV44 exercises the v4.4 upgrade, which carries no state migration.
// Its only job is to coordinate the binary swap for the cosmos-sdk v0.53.8
// security release, so what this test has to prove is that the chain survives
// that swap and that the transaction paths the SDK bump touches still work
// afterwards.
//
// The pre-upgrade image runs cosmos-sdk v0.53.4 -- the version mainnet runs --
// and the locally built image runs v0.53.8, so the swap crosses the exact SDK
// delta production will cross.
func TestUpgradeV44(t *testing.T) {
t.Parallel()

tm := tmanager.NewTmWithUpgrade(t, 0, "")
chainVal := tm.ChainValidator()
n := tm.Chains[tmanager.CHAIN_ID_BABYLON].Nodes[0]

tm.Start()
chainVal.WaitUntilBlkHeight(3)

del := n.CreateWallet("del")
del.VerifySentTx = true

initAmt := sdk.NewCoin(appparams.DefaultBondDenom, sdkmath.NewInt(100_000000))
n.SendCoins(del.Address.String(), sdk.NewCoins(initAmt))
n.WaitForNextBlock()
n.UpdateWalletAccSeqNumber(del.KeyName)

// Build staking and distribution state that has to survive the swap.
delAmt := sdkmath.NewInt(10_000000)
n.WrappedDelegate(del.KeyName, chainVal.Wallet.ValidatorAddress, delAmt)
n.WaitForEpochEnd()

delBefore := n.QueryDelegation(del.Address, chainVal.Wallet.ValidatorAddress)
require.Equal(t, delAmt, delBefore.Balance.Amount)
balBefore := n.QueryAllBalances(del.Address.String())

// Height 0 lets the harness place the plan at current height + 20. v4.4 has
// no epoch-boundary constraint, unlike the migrating upgrades.
govMsg, preUpgradeFunc := createGovPropAndPreUpgradeFunc(
t, chainVal.Wallet.WalletSender, v44.UpgradeName, 0,
)

tm.Upgrade(govMsg, preUpgradeFunc)

// The chain is still producing blocks on the new binary.
heightAtUpgrade, err := n.LatestBlockNumber()
require.NoError(t, err)
n.WaitForNextBlocks(2)
heightLater, err := n.LatestBlockNumber()
require.NoError(t, err)
require.Greater(t, heightLater, heightAtUpgrade)

// v4.4 migrates nothing, so pre-upgrade state must be untouched.
delAfter := n.QueryDelegation(del.Address, chainVal.Wallet.ValidatorAddress)
require.Equal(t, delBefore.Balance, delAfter.Balance)
require.Equal(t, balBefore, n.QueryAllBalances(del.Address.String()))

n.UpdateWalletAccSeqNumber(n.DefaultWallet().KeyName)
n.UpdateWalletAccSeqNumber(del.KeyName)

// A bank send exercises the ante chain, where most of the audited v0.53.8
// changes live (SetPubKeyDecorator, signature verification, tx decoding).
recipient := n.CreateWallet("recipient")
sendAmt := sdk.NewCoin(appparams.DefaultBondDenom, sdkmath.NewInt(1_000000))
n.SendCoins(recipient.Address.String(), sdk.NewCoins(sendAmt))
n.WaitForNextBlock()
require.Equal(t, sdk.NewCoins(sendAmt), n.QueryAllBalances(recipient.Address.String()))

// A second delegation exercises the epoching -> x/staking -> x/distribution
// path that v0.53.8 changed (getBeginInfo, strict historical rewards reads).
n.WrappedDelegate(del.KeyName, chainVal.Wallet.ValidatorAddress, delAmt)
n.WaitForEpochEnd()

delFinal := n.QueryDelegation(del.Address, chainVal.Wallet.ValidatorAddress)
require.Equal(t, delAmt.MulRaw(2), delFinal.Balance.Amount)
}

// createGovPropAndPreUpgradeFunc builds a MsgSoftwareUpgrade gov proposal for
// the named plan, plus a no-op pre-upgrade hook. v4.4 needs no chain state set
// up before the swap, unlike the migrating upgrades.
func createGovPropAndPreUpgradeFunc(t *testing.T, valWallet *tmanager.WalletSender, upgradeName string, upgradeHeight int64) (*govtypes.MsgSubmitProposal, tmanager.PreUpgradeFunc) {
upgradeMsg := &upgradetypes.MsgSoftwareUpgrade{
Authority: "bbn10d07y265gmmuvt4z0w9aw880jnsr700jduz5f2",
Plan: upgradetypes.Plan{
Name: upgradeName,
Height: upgradeHeight,
Info: "Upgrade to " + upgradeName,
},
}

anyMsg, err := types.NewAnyWithValue(upgradeMsg)
require.NoError(t, err)

govMsg := &govtypes.MsgSubmitProposal{
Messages: []*types.Any{anyMsg},
InitialDeposit: []sdk.Coin{sdk.NewCoin(appparams.DefaultBondDenom, sdkmath.NewInt(1_000_000))},
Proposer: valWallet.Address.String(),
Metadata: "",
Title: upgradeName,
Summary: "upgrade",
Expedited: false,
}

preUpgradeFunc := func(nodes []*tmanager.Node) {}
return govMsg, preUpgradeFunc
}
Loading