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

feat: cosmos sdk v0.50 draft #1833

Draft
wants to merge 1 commit 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
12 changes: 6 additions & 6 deletions app/ante.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package app

import (
corestoretypes "cosmossdk.io/core/store"
sdkerrors "cosmossdk.io/errors"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/errors"
sdkante "github.com/cosmos/cosmos-sdk/x/auth/ante"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"

"github.com/NibiruChain/nibiru/app/ante"
devgasante "github.com/NibiruChain/nibiru/x/devgas/v1/ante"
Expand All @@ -22,8 +22,8 @@ type AnteHandlerOptions struct {
DevGasKeeper *devgaskeeper.Keeper
DevGasBankKeeper devgasante.BankKeeper

TxCounterStoreKey types.StoreKey
WasmConfig *wasmtypes.WasmConfig
TXCounterStoreService corestoretypes.KVStoreService
WasmConfig *wasmtypes.WasmConfig
}

// NewAnteHandler returns and AnteHandler that checks and increments sequence
Expand Down Expand Up @@ -55,7 +55,7 @@ func NewAnteHandler(options AnteHandlerOptions) (sdk.AnteHandler, error) {
anteDecorators := []sdk.AnteDecorator{
sdkante.NewSetUpContextDecorator(),
wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit),
wasmkeeper.NewCountTXDecorator(options.TxCounterStoreKey),
wasmkeeper.NewCountTXDecorator(options.TXCounterStoreService),
sdkante.NewExtensionOptionsDecorator(nil),
sdkante.NewValidateBasicDecorator(),
sdkante.NewTxTimeoutHeightDecorator(),
Expand Down
3 changes: 2 additions & 1 deletion app/ante/commission.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package ante

import (
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

func MAX_COMMISSION() sdk.Dec { return sdk.MustNewDecFromStr("0.25") }
func MAX_COMMISSION() sdkmath.LegacyDec { return sdkmath.LegacyMustNewDecFromStr("0.25") }

var _ sdk.AnteDecorator = (*AnteDecoratorStakingCommission)(nil)

Expand Down
4 changes: 2 additions & 2 deletions app/ante/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package ante

import (
sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkmath "cosmossdk.io/math"
)

var errorCodeIdx uint32 = 1
Expand All @@ -18,7 +18,7 @@ var (
ErrMaxValidatorCommission = registerError("validator commission rate is above max")
)

func NewErrMaxValidatorCommission(gotCommission sdk.Dec) error {
func NewErrMaxValidatorCommission(gotCommission sdkmath.LegacyDec) error {
return ErrMaxValidatorCommission.Wrapf(
"got (%s), max rate is (%s)", gotCommission, MAX_COMMISSION())
}
18 changes: 8 additions & 10 deletions app/ante/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,38 @@ package ante
import (
"fmt"

storetypes "github.com/cosmos/cosmos-sdk/store/types"

"github.com/cosmos/cosmos-sdk/types"
storetypes "cosmossdk.io/store/types"
)

type fixedGasMeter struct {
consumed types.Gas
consumed storetypes.Gas
}

// NewFixedGasMeter returns a reference to a new fixedGasMeter.
func NewFixedGasMeter(fixedGas types.Gas) types.GasMeter {
func NewFixedGasMeter(fixedGas storetypes.Gas) storetypes.GasMeter {
return &fixedGasMeter{
consumed: fixedGas,
}
}

func (g *fixedGasMeter) GasConsumed() types.Gas {
func (g *fixedGasMeter) GasConsumed() storetypes.Gas {
return g.consumed
}

func (g *fixedGasMeter) GasConsumedToLimit() types.Gas {
func (g *fixedGasMeter) GasConsumedToLimit() storetypes.Gas {
return g.consumed
}

func (g *fixedGasMeter) Limit() types.Gas {
func (g *fixedGasMeter) Limit() storetypes.Gas {
return g.consumed
}

func (g *fixedGasMeter) GasRemaining() storetypes.Gas {
return g.consumed
}

func (g *fixedGasMeter) ConsumeGas(types.Gas, string) {}
func (g *fixedGasMeter) RefundGas(types.Gas, string) {}
func (g *fixedGasMeter) ConsumeGas(storetypes.Gas, string) {}
func (g *fixedGasMeter) RefundGas(storetypes.Gas, string) {}

func (g *fixedGasMeter) IsPastLimit() bool {
return false
Expand Down
2 changes: 1 addition & 1 deletion app/ante/testutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/cosmos/cosmos-sdk/x/auth/ante"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
Expand Down
57 changes: 31 additions & 26 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
"encoding/json"
"fmt"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
"io"
"net/http"
"os"
Expand All @@ -13,35 +14,34 @@ import (

"github.com/NibiruChain/nibiru/app/wasmext"

dbm "github.com/cometbft/cometbft-db"
"cosmossdk.io/log"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
tmos "github.com/cometbft/cometbft/libs/os"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
//_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"
"github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
"github.com/cosmos/cosmos-sdk/x/crisis"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
"github.com/cosmos/ibc-go/v7/testing/types"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
"github.com/cosmos/ibc-go/v8/testing/types"
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus"
"github.com/rakyll/statik/fs"
Expand Down Expand Up @@ -138,7 +138,8 @@ func NewNibiruApp(
txConfig := encodingConfig.TxConfig

bApp := baseapp.NewBaseApp(
appName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
appName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...,
)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
bApp.SetInterfaceRegistry(interfaceRegistry)
Expand Down Expand Up @@ -192,11 +193,11 @@ func NewNibiruApp(
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
SigGasConsumer: authante.DefaultSigVerificationGasConsumer,
},
IBCKeeper: app.ibcKeeper,
TxCounterStoreKey: keys[wasmtypes.StoreKey],
WasmConfig: &wasmConfig,
DevGasKeeper: &app.DevGasKeeper,
DevGasBankKeeper: app.BankKeeper,
IBCKeeper: app.ibcKeeper,
TXCounterStoreService: runtime.NewKVStoreService(keys[wasmtypes.StoreKey]),
WasmConfig: &wasmConfig,
DevGasKeeper: &app.DevGasKeeper,
DevGasBankKeeper: app.BankKeeper,
})
if err != nil {
panic(fmt.Errorf("failed to create sdk.AnteHandler: %s", err))
Expand Down Expand Up @@ -245,32 +246,36 @@ func NewNibiruApp(
func (app *NibiruApp) Name() string { return app.BaseApp.Name() }

// BeginBlocker application updates every begin block
func (app *NibiruApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
return app.ModuleManager.BeginBlock(ctx, req)
func (app *NibiruApp) BeginBlocker(ctx sdk.Context) (sdk.BeginBlock, error) {
return app.ModuleManager.BeginBlock(ctx)
}

// EndBlocker application updates every end block
func (app *NibiruApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
return app.ModuleManager.EndBlock(ctx, req)
func (app *NibiruApp) EndBlocker(ctx sdk.Context) (sdk.EndBlock, error) {
return app.ModuleManager.EndBlock(ctx)
}

// InitChainer application update at chain initialization
func (app *NibiruApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
func (app *NibiruApp) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) {
var genesisState GenesisState
if err := json.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}
app.upgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap())
return app.ModuleManager.InitGenesis(ctx, app.appCodec, genesisState)
err := app.upgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap())
if err != nil {
panic(err)
}
response, err := app.ModuleManager.InitGenesis(ctx, app.appCodec, genesisState)
return response, err
}

// LoadHeight loads a particular height
func (app *NibiruApp) LoadHeight(height int64) error {
return app.LoadVersion(height)
}

func (app *NibiruApp) RegisterNodeService(clientCtx client.Context) {
node.RegisterNodeService(clientCtx, app.GRPCQueryRouter())
func (app *NibiruApp) RegisterNodeService(clientCtx client.Context, cfg config.Config) {
node.RegisterNodeService(clientCtx, app.GRPCQueryRouter(), cfg)
}

// ModuleAccountAddrs returns all the app's module account addresses.
Expand Down Expand Up @@ -348,7 +353,7 @@ func (app *NibiruApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.API
// Register new tx routes from grpc-gateway.
authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
// Register new tendermint queries routes from grpc-gateway.
tmservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
cmtservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// Register legacy and grpc-gateway routes for all modules.
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
Expand All @@ -368,7 +373,7 @@ func (app *NibiruApp) RegisterTxService(clientCtx client.Context) {

// RegisterTendermintService implements the Application.RegisterTendermintService method.
func (app *NibiruApp) RegisterTendermintService(clientCtx client.Context) {
tmservice.RegisterTendermintService(
cmtservice.RegisterTendermintService(
clientCtx,
app.BaseApp.GRPCQueryRouter(),
app.interfaceRegistry,
Expand Down
40 changes: 26 additions & 14 deletions app/export.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package app

import (
storetypes "cosmossdk.io/store/types"
"encoding/json"
"log"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
Expand All @@ -19,7 +18,7 @@ func (app *NibiruApp) ExportAppStateAndValidators(
forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string,
) (servertypes.ExportedApp, error) {
// as if they could withdraw from the start of the next block
ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
ctx := app.NewContext(true)

// We export at last height + 1, because that's the height at which
// Tendermint will start InitChain.
Expand All @@ -29,7 +28,10 @@ func (app *NibiruApp) ExportAppStateAndValidators(
app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs)
}

genState := app.ModuleManager.ExportGenesisForModules(ctx, app.appCodec, modulesToExport)
genState, err := app.ModuleManager.ExportGenesisForModules(ctx, app.appCodec, modulesToExport)
if err != nil {
return servertypes.ExportedApp{}, err
}
appState, err := json.MarshalIndent(genState, "", " ")
if err != nil {
return servertypes.ExportedApp{}, err
Expand Down Expand Up @@ -73,12 +75,13 @@ func (app *NibiruApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs

// withdraw all validator commission
app.stakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
operator, _ := sdk.ValAddressFromBech32(val.GetOperator())
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, operator)
return false
})

// withdraw all delegator rewards
dels := app.stakingKeeper.GetAllDelegations(ctx)
dels, _ := app.stakingKeeper.GetAllDelegations(ctx)
for _, delegation := range dels {
valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress)
if err != nil {
Expand All @@ -105,12 +108,21 @@ func (app *NibiruApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs
// reinitialize all validators
app.stakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
// donate any unwithdrawn outstanding reward fraction tokens to the community pool
scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator())
feePool := app.DistrKeeper.GetFeePool(ctx)
valAddr, err := sdk.ValAddressFromBech32(val.GetOperator())
if err != nil {
panic(err)
}

scraps, _ := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, valAddr)
feePool, err := app.DistrKeeper.FeePool.Get(ctx)
if err != nil {
panic(err)
}

feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
app.DistrKeeper.SetFeePool(ctx, feePool)
app.DistrKeeper.FeePool.Set(ctx, feePool)

err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
err = app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, valAddr)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -163,14 +175,14 @@ func (app *NibiruApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs
// Iterate through validators by power descending, reset bond heights, and
// update bond intra-tx counters.
store := ctx.KVStore(app.keys[stakingtypes.StoreKey])
iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
iter := storetypes.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
counter := int16(0)

for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key()))
validator, found := app.stakingKeeper.GetValidator(ctx, addr)
if !found {
panic("expected validator, not found")
validator, err := app.stakingKeeper.GetValidator(ctx, addr)
if err != nil {
panic(err)
}

validator.UnbondingHeight = 0
Expand Down
4 changes: 2 additions & 2 deletions app/ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
"github.com/stretchr/testify/suite"

"github.com/NibiruChain/nibiru/app"
Expand Down
Loading