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
30 changes: 25 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/group"
groupmodule "github.com/cosmos/cosmos-sdk/x/group/module"
"github.com/cosmos/cosmos-sdk/x/protocolpool"
"github.com/cosmos/gaia/v25/x/liquid"
"github.com/cosmos/gogoproto/proto"
icacontroller "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/controller"
ibccallbacks "github.com/cosmos/ibc-go/v10/modules/apps/callbacks"
Expand Down Expand Up @@ -121,6 +122,8 @@ import (
"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"
liquidkeeper "github.com/cosmos/gaia/v25/x/liquid/keeper"
liquidtypes "github.com/cosmos/gaia/v25/x/liquid/types"
ica "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts"
icacontrollerkeeper "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/controller/types"
Expand Down Expand Up @@ -254,6 +257,7 @@ type App struct {
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
DistrKeeper distrkeeper.Keeper
LiquidKeeper *liquidkeeper.Keeper
GovKeeper govkeeper.Keeper
UpgradeKeeper *upgradekeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
Expand Down Expand Up @@ -283,7 +287,7 @@ type App struct {
sm *module.SimulationManager
}

// New returns a reference to an initialized App.
// New returns a reference to an initialized Gaia.
// NewSimApp returns a reference to an initialized SimApp.
func New(
logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
Expand Down Expand Up @@ -345,6 +349,7 @@ func New(
icacontrollertypes.StoreKey,
paramstypes.StoreKey,
CapabilityStoreKey,
liquidtypes.StoreKey,
)
tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey)
memkeys := storetypes.NewMemoryStoreKeys(CapabilityMemStoreKey)
Expand Down Expand Up @@ -476,6 +481,16 @@ func New(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

app.LiquidKeeper = liquidkeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[liquidtypes.StoreKey]),
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
app.DistrKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

app.FeeGrantKeeper = feegrantkeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[feegrant.StoreKey]),
Expand All @@ -488,6 +503,7 @@ func New(
stakingtypes.NewMultiStakingHooks(
app.DistrKeeper.Hooks(),
app.SlashingKeeper.Hooks(),
app.LiquidKeeper.Hooks(),
),
)

Expand Down Expand Up @@ -567,7 +583,7 @@ func New(

app.GovKeeper = *govKeeper.SetHooks(
govtypes.NewMultiGovHooks(
// register the governance hooks
// register the governance hooks
),
)

Expand Down Expand Up @@ -597,7 +613,7 @@ func New(

app.EpochsKeeper.SetHooks(
epochstypes.NewMultiEpochHooks(
// insert epoch hooks receivers here
// insert epoch hooks receivers here
),
)

Expand Down Expand Up @@ -747,6 +763,7 @@ func New(
transfer.NewAppModule(app.TransferKeeper),
ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper),
ibctm.NewAppModule(tmLightClientModule),
liquid.NewAppModule(appCodec, app.LiquidKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
)

// BasicModuleManager defines the module BasicManager is in charge of setting up basic,
Expand Down Expand Up @@ -787,6 +804,7 @@ func New(
ibctransfertypes.ModuleName,
ibcexported.ModuleName,
icatypes.ModuleName,
liquidtypes.ModuleName,
wasmtypes.ModuleName,
)

Expand Down Expand Up @@ -839,6 +857,7 @@ func New(
icatypes.ModuleName,
// wasm after ibc transfer
wasmtypes.ModuleName,
liquidtypes.ModuleName,
}

exportModuleOrder := []string{
Expand Down Expand Up @@ -867,6 +886,7 @@ func New(
icatypes.ModuleName,
// wasm after ibc transfer
wasmtypes.ModuleName,
liquidtypes.ModuleName,
}

app.mm.SetOrderInitGenesis(genesisModuleOrder...)
Expand Down Expand Up @@ -1046,15 +1066,15 @@ func (app *App) LegacyAmino() *codec.LegacyAmino {
return app.legacyAmino
}

// AppCodec returns app codec.
// AppCodec returns Gaia's app codec.
//
// NOTE: This is solely to be used for testing purposes as it may be desirable
// for modules to register their own custom testing types.
func (app *App) AppCodec() codec.Codec {
return app.appCodec
}

// InterfaceRegistry returns InterfaceRegistry
// InterfaceRegistry returns Gaia's InterfaceRegistry
func (app *App) InterfaceRegistry() types.InterfaceRegistry {
return app.interfaceRegistry
}
Expand Down
32 changes: 32 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"time"

"cosmossdk.io/math"
storetypes "cosmossdk.io/store/types"
circuittypes "cosmossdk.io/x/circuit/types"
"cosmossdk.io/x/nft"
Expand All @@ -24,6 +25,8 @@ import (
//minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
protocolpooltypes "github.com/cosmos/cosmos-sdk/x/protocolpool/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
liquidtypes "github.com/cosmos/gaia/v25/x/liquid/types"
icacontrollertypes "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/types"
ibctransfertypes "github.com/cosmos/ibc-go/v10/modules/apps/transfer/types"
Expand All @@ -45,6 +48,7 @@ var v053StoreUpgrades = storetypes.StoreUpgrades{
group.StoreKey,
icacontrollertypes.StoreKey,
nft.StoreKey,
liquidtypes.StoreKey,
},
Renamed: []storetypes.StoreRename{
// {OldKey: "oldkey", NewKey: "newkey"},
Expand Down Expand Up @@ -100,11 +104,39 @@ func (app *App) RegisterUpgradeHandlers(cfg module.Configurator) {
return nil, err
}

/*
// Pre-seed legacy x/params for mint
if ss, ok := app.ParamsKeeper.GetSubspace(minttypes.ModuleName); ok {
if !ss.Has(sdkCtx, minttypes.KeyInflationRateChange) {
p := minttypes.DefaultParams()
p.MintDenom = "afet"
// TODO: if your chain had custom values, set them here:
ss.SetParamSet(sdkCtx, &p)
}
}
*/

err = migrateConsensusParamsFromParamsStore(app, sdkCtx)
if err != nil {
return nil, err
}

// Bootstrap liquid staking
err = app.StakingKeeper.IterateValidators(ctx, func(_ int64, v stakingtypes.ValidatorI) (stop bool) {
lv := liquidtypes.LiquidValidator{
OperatorAddress: v.GetOperator(),
LiquidShares: math.LegacyZeroDec(),
}
err := app.LiquidKeeper.SetLiquidValidator(ctx, lv)
if err != nil {
return false
}
return false
})
Comment on lines +132 to +135
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Variable shadowing with := inside the IterateValidators callback causes errors from SetLiquidValidator to be silently ignored during the upgrade migration.
Severity: HIGH

Suggested Fix

To ensure errors are handled, either panic on error within the callback by using panic(err), which matches patterns elsewhere in the codebase, or capture the error in a closure variable declared outside the callback. This captured error can then be checked after the iteration completes.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: app/upgrades.go#L132-L135

Potential issue: In the v0.53 upgrade handler, a new `err` variable is declared within
the `IterateValidators` callback using `:=`, shadowing the outer `err` variable.
Consequently, any error returned from `app.LiquidKeeper.SetLiquidValidator` is assigned
to this inner variable and then discarded, as the callback does not propagate errors.
This causes the error to be silently swallowed. If `SetLiquidValidator` fails for any
validator during the one-time migration, that validator will lack a `LiquidValidator`
record, leading to incomplete data for the liquid staking module and potential runtime
issues post-upgrade.

Did we get this right? 👍 / 👎 to inform future reviews.

if err != nil {
return nil, err
}

// If you must pin any module "from" versions, adjust fromVM here.
return app.mm.RunMigrations(ctx, cfg, fromVM)
},
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/CosmWasm/wasmd v0.61.2
github.com/CosmWasm/wasmvm/v3 v3.0.0 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect
github.com/cosmos/gaia/v25 v25.1.1
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gogoproto v1.7.0
github.com/cosmos/iavl v1.2.6 // indirect
Expand Down
16 changes: 10 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,8 @@ github.com/cometbft/cometbft v0.38.19 h1:vNdtCkvhuwUlrcLPAyigV7lQpmmo+tAq8CsB8gZ
github.com/cometbft/cometbft v0.38.19/go.mod h1:UCu8dlHqvkAsmAFmWDRWNZJPlu6ya2fTWZlDrWsivwo=
github.com/cometbft/cometbft-db v1.0.4 h1:cezb8yx/ZWcF124wqUtAFjAuDksS1y1yXedvtprUFxs=
github.com/cometbft/cometbft-db v1.0.4/go.mod h1:M+BtHAGU2XLrpUxo3Nn1nOCcnVCiLM9yx5OuT0u5SCA=
github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg=
github.com/containerd/continuity v0.3.0/go.mod h1:wJEAIwKOm/pBZuBd0JmeTvnLquTB1Ag8espWhkykbPM=
github.com/containerd/continuity v0.4.5 h1:ZRoN1sXq9u7V6QoHMcVWGhOwDFqZ4B9i5H6un1Wh0x4=
github.com/containerd/continuity v0.4.5/go.mod h1:/lNJvtJKUQStBzpVQ1+rasXO1LAWtUQssk28EZvJ3nE=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
Expand All @@ -832,6 +832,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/gaia/v25 v25.1.1 h1:PVfU1tY/ImLv387SxS7aLUejWhKpCXxy92FYwxHFGsc=
github.com/cosmos/gaia/v25 v25.1.1/go.mod h1:nk61Mb7EUU9hnfblUyYEwO/W5IajYOQQrArz8r0iQAY=
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 Down Expand Up @@ -1337,6 +1339,8 @@ github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS4
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/moby/sys/user v0.3.0 h1:9ni5DlcW5an3SvRSx4MouotOygvzaXbaSrc/wGDFWPo=
github.com/moby/sys/user v0.3.0/go.mod h1:bG+tYYYJgaMtRKgEmuueC0hJEAZWwtIbZTB+85uoHjs=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
Expand Down Expand Up @@ -1382,10 +1386,10 @@ github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeD
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0-rc5 h1:Ygwkfw9bpDvs+c9E34SdgGOj41dX/cbdlwvlWt0pnFI=
github.com/opencontainers/image-spec v1.1.0-rc5/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8=
github.com/opencontainers/runc v1.1.12 h1:BOIssBaW1La0/qbNZHXOOa71dZfZEQOzW7dqQf3phss=
github.com/opencontainers/runc v1.1.12/go.mod h1:S+lQwSfncpBha7XTy/5lBwWgm5+y5Ma/O44Ekby9FK8=
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
github.com/opencontainers/runc v1.2.3 h1:fxE7amCzfZflJO2lHXf4y/y8M1BoAqp+FVmG19oYB80=
github.com/opencontainers/runc v1.2.3/go.mod h1:nSxcWUydXrsBZVYNSkTjoQ/N6rcyTtn+1SD5D4+kRIM=
github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis=
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
Expand Down
Loading