Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: ibc v9 #2050

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
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
27 changes: 13 additions & 14 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,56 +18,55 @@ linters:
- exportloopref
- goconst
- gocritic
- gci
- gofumpt
- gosec
- gosimple
- govet
- ineffassign
- maintidx
- misspell
- nakedret
- nolintlint
- staticcheck
- revive
- stylecheck
- typecheck
# - thelper # too many positives with table tests that have custom setup(*testing.T)
- unconvert
- unused

issues:
exclude-rules:
- text: 'Use of weak random number generator'
- text: "Use of weak random number generator"
linters:
- gosec
- text: 'ST1003:'
- text: "ST1003:"
linters:
- stylecheck
# FIXME: Disabled until golangci-lint updates stylecheck with this fix:
# https://github.com/dominikh/go-tools/issues/389
- text: 'ST1016:'
- text: "ST1016:"
linters:
- stylecheck
- path: 'migrations'
text: 'SA1019:'
- path: "migrations"
text: "SA1019:"
linters:
- staticcheck
- text: 'SA1019: codec.NewAminoCodec is deprecated' # TODO remove once migration path is set out
- text: "SA1019: codec.NewAminoCodec is deprecated" # TODO remove once migration path is set out
linters:
- staticcheck
- text: 'SA1019: legacybech32.MustMarshalPubKey' # TODO remove once ready to remove from the sdk
- text: "SA1019: legacybech32.MustMarshalPubKey" # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: 'SA1019: legacybech32.MarshalPubKey' # TODO remove once ready to remove from the sdk
- text: "SA1019: legacybech32.MarshalPubKey" # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: 'SA1019: legacybech32.UnmarshalPubKey' # TODO remove once ready to remove from the sdk
- text: "SA1019: legacybech32.UnmarshalPubKey" # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: 'SA1019: params.SendEnabled is deprecated' # TODO remove once ready to remove from the sdk
- text: "SA1019: params.SendEnabled is deprecated" # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: 'leading space'
- text: "leading space"
linters:
- nolintlint
max-issues-per-linter: 10000
Expand Down Expand Up @@ -140,7 +139,7 @@ linters-settings:
require-explanation: false
require-specific: false
gosimple:
checks: ['all']
checks: ["all"]
gocritic:
disabled-checks:
- regexpMust
Expand Down
4 changes: 2 additions & 2 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package app
import (
"errors"

ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante"
"github.com/cosmos/ibc-go/v8/modules/core/keeper"
ibcante "github.com/cosmos/ibc-go/v9/modules/core/ante"
"github.com/cosmos/ibc-go/v9/modules/core/keeper"

corestoretypes "cosmossdk.io/core/store"
circuitante "cosmossdk.io/x/circuit/ante"
Expand Down
64 changes: 29 additions & 35 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,26 @@ import (
"github.com/cosmos/ibc-go/modules/capability"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts"
icacontroller "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller"
icacontrollerkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
icahost "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host"
icahostkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
ibcfee "github.com/cosmos/ibc-go/v8/modules/apps/29-fee"
ibcfeekeeper "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/keeper"
ibcfeetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types"
"github.com/cosmos/ibc-go/v8/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v8/modules/core"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
ica "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts"
icacontroller "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller"
icacontrollerkeeper "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/types"
icahost "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/host"
icahostkeeper "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/types"
ibcfee "github.com/cosmos/ibc-go/v9/modules/apps/29-fee"
ibcfeekeeper "github.com/cosmos/ibc-go/v9/modules/apps/29-fee/keeper"
ibcfeetypes "github.com/cosmos/ibc-go/v9/modules/apps/29-fee/types"
"github.com/cosmos/ibc-go/v9/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v9/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v9/modules/core"
ibcclienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
ibcconnectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types"
porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v9/modules/core/keeper"
"github.com/spf13/cast"

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
Expand Down Expand Up @@ -515,7 +514,6 @@ func NewWasmApp(
appCodec,
keys[ibcexported.StoreKey],
app.GetSubspace(ibcexported.ModuleName),
app.StakingKeeper,
app.UpgradeKeeper,
scopedIBCKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Expand Down Expand Up @@ -599,16 +597,15 @@ func NewWasmApp(
appCodec,
keys[icahosttypes.StoreKey],
app.GetSubspace(icahosttypes.SubModuleName),
app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.PortKeeper,
app.AccountKeeper,
scopedICAHostKeeper,
app.MsgServiceRouter(),
app.IBCFeeKeeper, // ICS4Wrapper
app.IBCKeeper.ChannelKeeper, // ChannelKeeper
app.IBCKeeper.PortKeeper, // PortKeeper
app.AccountKeeper, // AccountKeeper
scopedICAHostKeeper, // ScopedKeeper
app.MsgServiceRouter(), // MessageRouter
app.GRPCQueryRouter(), // QueryRouter
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
// set grpc router for ica host
app.ICAHostKeeper.WithQueryRouter(app.GRPCQueryRouter())

app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -663,10 +660,7 @@ func NewWasmApp(
var icaControllerStack porttypes.IBCModule
// integration point for custom authentication modules
// see https://medium.com/the-interchain-foundation/ibc-go-v6-changes-to-interchain-accounts-and-how-it-impacts-your-chain-806c185300d7
var noAuthzModule porttypes.IBCModule
icaControllerStack = icacontroller.NewIBCMiddleware(noAuthzModule, app.ICAControllerKeeper)
// app.ICAAuthModule = icaControllerStack.(ibcmock.IBCModule)
icaControllerStack = icacontroller.NewIBCMiddleware(icaControllerStack, app.ICAControllerKeeper)
icaControllerStack = icacontroller.NewIBCMiddleware(app.ICAControllerKeeper)
Fixed Show fixed Hide fixed
icaControllerStack = ibccallbacks.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper, wasmStackIBCHandler, wasm.DefaultMaxIBCCallbackGas)
icaICS4Wrapper := icaControllerStack.(porttypes.ICS4Wrapper)
icaControllerStack = ibcfee.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper)
Expand Down Expand Up @@ -735,7 +729,7 @@ func NewWasmApp(
transfer.NewAppModule(app.TransferKeeper),
ibcfee.NewAppModule(app.IBCFeeKeeper),
ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper),
ibctm.AppModule{},
// ibctm.NewAppModule(app.IBCKeeper.ClientKeeper), // this seems to be some kind of core issue
// sdk
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), // always be last to make sure that it checks for all invariants and not only part of them
)
Expand Down
108 changes: 56 additions & 52 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,8 @@ func (app *WasmApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedA
}, err
}

// prepare for fresh start at zero height
// NOTE zero height genesis is a temporary feature which will be deprecated
//
// in favor of export at a block height
func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
applyAllowedAddrs := false

// check if there is a allowed address list
if len(jailAllowedAddrs) > 0 {
applyAllowedAddrs = true
}

func (app *WasmApp) handleAllowedAddrs(jailAllowedAddrs []string) (map[string]bool, bool) {
applyAllowedAddrs := len(jailAllowedAddrs) > 0
allowedAddrsMap := make(map[string]bool)

for _, addr := range jailAllowedAddrs {
Expand All @@ -71,11 +61,10 @@ func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
allowedAddrsMap[addr] = true
}

/* Just to be safe, assert the invariants on current state. */
app.CrisisKeeper.AssertInvariants(ctx)

/* Handle fee distribution state. */
return allowedAddrsMap, applyAllowedAddrs
}

func (app *WasmApp) handleFeeDistribution(ctx sdk.Context) []stakingtypes.Delegation {
// withdraw all validator commission
err := app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
valBz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator())
Expand Down Expand Up @@ -108,22 +97,20 @@ func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
}
}

// clear validator slash events
// clear validator slash events and historical rewards
app.DistrKeeper.DeleteAllValidatorSlashEvents(ctx)

// clear validator historical rewards
app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx)

// set context height to zero
height := ctx.BlockHeight()
ctx = ctx.WithBlockHeight(0)
return dels
}

// reinitialize all validators
err = app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
func (app *WasmApp) reinitializeValidators(ctx sdk.Context) error {
return app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
valBz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator())
if err != nil {
panic(err)
}

// donate any unwithdrawn outstanding reward fraction tokens to the community pool
scraps, err := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, valBz)
if err != nil {
Expand All @@ -143,11 +130,9 @@ func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
}
return false
})
if err != nil {
panic(err)
}
}

// reinitialize all delegations
func (app *WasmApp) reinitializeDelegations(ctx sdk.Context, dels []stakingtypes.Delegation) {
for _, del := range dels {
valAddr, err := sdk.ValAddressFromBech32(del.ValidatorAddress)
if err != nil {
Expand All @@ -156,27 +141,22 @@ func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
delAddr := sdk.MustAccAddressFromBech32(del.DelegatorAddress)

if err := app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr); err != nil {
// never called as BeforeDelegationCreated always returns nil
panic(fmt.Errorf("error while incrementing period: %w", err))
}

if err := app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr); err != nil {
// never called as AfterDelegationModified always returns nil
panic(fmt.Errorf("error while creating a new delegation period record: %w", err))
}
}
}

// reset context height
ctx = ctx.WithBlockHeight(height)

/* Handle staking state. */

// iterate through redelegations, reset creation height
err = app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) {
func (app *WasmApp) handleStakingState(ctx sdk.Context, applyAllowedAddrs bool, allowedAddrsMap map[string]bool) {
// Reset redelegations
err := app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) {
for i := range red.Entries {
red.Entries[i].CreationHeight = 0
}
err = app.StakingKeeper.SetRedelegation(ctx, red)
err := app.StakingKeeper.SetRedelegation(ctx, red)
if err != nil {
panic(err)
}
Expand All @@ -186,12 +166,12 @@ func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
panic(err)
}

// iterate through unbonding delegations, reset creation height
// Reset unbonding delegations
err = app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) {
for i := range ubd.Entries {
ubd.Entries[i].CreationHeight = 0
}
err = app.StakingKeeper.SetUnbondingDelegation(ctx, ubd)
err := app.StakingKeeper.SetUnbondingDelegation(ctx, ubd)
if err != nil {
panic(err)
}
Expand All @@ -201,10 +181,14 @@ func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
panic(err)
}

// Iterate through validators by power descending, reset bond heights, and
// update bond intra-tx counters.
// Update validators
store := ctx.KVStore(app.GetKey(stakingtypes.StoreKey))
iter := storetypes.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
defer func() {
if err := iter.Close(); err != nil {
app.Logger().Error("error while closing the key-value store reverse prefix iterator: ", err)
}
}()

for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key()))
Expand All @@ -224,20 +208,15 @@ func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
}
}

if err := iter.Close(); err != nil {
app.Logger().Error("error while closing the key-value store reverse prefix iterator: ", err)
return
}

_, err = app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
if err != nil {
log.Fatal(err)
app.Logger().Error("error while applying validator set updates", "error", err)
return
}
}

/* Handle slashing state. */

// reset start height on signing infos
err = app.SlashingKeeper.IterateValidatorSigningInfos(
func (app *WasmApp) handleSlashingState(ctx sdk.Context) {
err := app.SlashingKeeper.IterateValidatorSigningInfos(
ctx,
func(addr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) {
info.StartHeight = 0
Expand All @@ -251,3 +230,28 @@ func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
panic(err)
}
}

func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
allowedAddrsMap, applyAllowedAddrs := app.handleAllowedAddrs(jailAllowedAddrs)

// Assert the invariants on current state
app.CrisisKeeper.AssertInvariants(ctx)

// Handle fee distribution state
height := ctx.BlockHeight()
ctx = ctx.WithBlockHeight(0)
dels := app.handleFeeDistribution(ctx)

// Reinitialize validators and delegations
if err := app.reinitializeValidators(ctx); err != nil {
panic(err)
}
app.reinitializeDelegations(ctx, dels)

// Reset context height
ctx = ctx.WithBlockHeight(height)

// Handle staking and slashing states
app.handleStakingState(ctx, applyAllowedAddrs, allowedAddrsMap)
app.handleSlashingState(ctx)
}
2 changes: 1 addition & 1 deletion app/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app

import (
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
ibckeeper "github.com/cosmos/ibc-go/v9/modules/core/keeper"

"github.com/cosmos/cosmos-sdk/baseapp"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
Expand Down
Loading
Loading