-
Notifications
You must be signed in to change notification settings - Fork 127
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
Upgrade cosmos-sdk in irishub to v0.50.10 #2975
Changes from 3 commits
9c68542
6c4f04c
48d939b
81b8deb
54b724b
bf3dda8
4fa6679
3d9c89b
6b8788a
3cebb54
0268714
532bf8f
02ddedd
f0566f0
fe459a7
e785d18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,11 @@ package ante | |
import ( | ||
"strings" | ||
|
||
sdkerrors "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
errortypes "github.com/cosmos/cosmos-sdk/types/errors" | ||
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" | ||
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" | ||
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" | ||
|
||
coinswaptypes "mods.irisnet.org/modules/coinswap/types" | ||
servicetypes "mods.irisnet.org/modules/service/types" | ||
|
@@ -38,23 +39,23 @@ func (vtd ValidateTokenDecorator) AnteHandle( | |
switch msg := msg.(type) { | ||
case *ibctransfertypes.MsgTransfer: | ||
if containSwapCoin(msg.Token) { | ||
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "can't transfer coinswap liquidity tokens through the IBC module") | ||
return ctx, sdkerrors.Wrap(errortypes.ErrInvalidRequest, "can't transfer coinswap liquidity tokens through the IBC module") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Update error handling pattern The current error wrapping pattern uses -return ctx, sdkerrors.Wrap(errortypes.ErrInvalidRequest, "can't transfer coinswap liquidity tokens through the IBC module")
+return ctx, sdkerrors.ErrInvalidRequest.Wrap("can't transfer coinswap liquidity tokens through the IBC module") Apply similar changes to all error handling instances in this file. Also applies to: 46-46, 50-50, 54-54, 58-58, 84-84 |
||
} | ||
case *tokentypesv1.MsgBurnToken: | ||
if _, err := vtd.tk.GetToken(ctx, msg.Coin.Denom); err != nil { | ||
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "burnt failed, only native tokens can be burnt") | ||
return ctx, sdkerrors.Wrap(errortypes.ErrInvalidRequest, "burnt failed, only native tokens can be burnt") | ||
} | ||
case *tokentypesv1beta1.MsgBurnToken: | ||
if _, err := vtd.tk.GetToken(ctx, msg.Symbol); err != nil { | ||
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "burnt failed, only native tokens can be burnt") | ||
return ctx, sdkerrors.Wrap(errortypes.ErrInvalidRequest, "burnt failed, only native tokens can be burnt") | ||
} | ||
case *govv1.MsgSubmitProposal: | ||
if containSwapCoin(msg.InitialDeposit...) { | ||
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "can't deposit coinswap liquidity token for proposal") | ||
return ctx, sdkerrors.Wrap(errortypes.ErrInvalidRequest, "can't deposit coinswap liquidity token for proposal") | ||
} | ||
case *govv1.MsgDeposit: | ||
if containSwapCoin(msg.Amount...) { | ||
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "can't deposit coinswap liquidity token for proposal") | ||
return ctx, sdkerrors.Wrap(errortypes.ErrInvalidRequest, "can't deposit coinswap liquidity token for proposal") | ||
} | ||
} | ||
} | ||
|
@@ -80,7 +81,7 @@ func (vsd ValidateServiceDecorator) AnteHandle( | |
switch msg := msg.(type) { | ||
case *servicetypes.MsgCallService: | ||
if msg.Repeated { | ||
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "currently does not support to create repeatable service invocation") | ||
return ctx, sdkerrors.Wrap(errortypes.ErrInvalidRequest, "currently does not support to create repeatable service invocation") | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ func (rmd RejectMessagesDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula | |
case *vestingtypes.MsgCreateVestingAccount, | ||
*vestingtypes.MsgCreatePermanentLockedAccount, | ||
*vestingtypes.MsgCreatePeriodicVestingAccount: | ||
return ctx, errortypes.Wrap( | ||
return ctx, errorsmod.Wrap( | ||
errortypes.ErrInvalidType, | ||
"currently doesn't support creating vesting account") | ||
Comment on lines
+31
to
33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Migration to errorsmod.Wrap is incomplete across the codebase The verification reveals inconsistent error handling patterns:
The codebase should consistently use 🔗 Analysis chainLGTM! Error handling update aligns with Cosmos SDK v0.50.x The change from Let's verify the consistency of error handling across the codebase: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Check for any remaining old error handling patterns
rg "errortypes\.Wrap" --type go
Length of output: 33 Script: #!/bin/bash
# Let's check for both old and new error handling patterns to ensure consistency
echo "Checking for errortypes imports..."
rg "\"github.com/cosmos/cosmos-sdk/types/errors\"" --type go
echo -e "\nChecking for errorsmod imports..."
rg "\"cosmossdk.io/errors\"" --type go
echo -e "\nChecking for error wrapping patterns..."
rg "\.Wrap\(" --type go -A 1
Length of output: 4734 |
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
|
||
tmproto "github.com/cometbft/cometbft/proto/tendermint/types" | ||
|
||
storetypes "cosmossdk.io/store/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" | ||
|
@@ -25,7 +26,7 @@ func (app *IrisApp) ExportAppStateAndValidators( | |
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.NewContextLegacy(true, tmproto.Header{Height: app.LastBlockHeight()}) | ||
|
||
// We export at last height + 1, because that's the height at which | ||
// Tendermint will start InitChain. | ||
|
@@ -38,7 +39,10 @@ func (app *IrisApp) ExportAppStateAndValidators( | |
service.PrepForZeroHeightGenesis(ctx, app.ServiceKeeper) | ||
} | ||
|
||
genState := app.mm.ExportGenesisForModules(ctx, app.appCodec, modulesToExport) | ||
genState, err := app.mm.ExportGenesisForModules(ctx, app.appCodec, modulesToExport) | ||
if err != nil { | ||
return servertypes.ExportedApp{}, err | ||
} | ||
appState, err := json.MarshalIndent(genState, "", " ") | ||
if err != nil { | ||
return servertypes.ExportedApp{}, err | ||
|
@@ -84,13 +88,16 @@ func (app *IrisApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [ | |
app.StakingKeeper.IterateValidators( | ||
ctx, | ||
func(_ int64, val stakingtypes.ValidatorI) (stop bool) { | ||
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator()) | ||
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, sdk.ValAddress(val.GetOperator())) | ||
return false | ||
}, | ||
) | ||
wangjiulian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// withdraw all delegator rewards | ||
dels := app.StakingKeeper.GetAllDelegations(ctx) | ||
dels, err := app.StakingKeeper.GetAllDelegations(ctx) | ||
if err != nil { | ||
panic(err) | ||
} | ||
for _, delegation := range dels { | ||
valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress) | ||
if err != nil { | ||
|
@@ -119,12 +126,21 @@ func (app *IrisApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [ | |
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) | ||
scraps, err := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, sdk.ValAddress(val.GetOperator())) | ||
if err != nil { | ||
panic(err) | ||
} | ||
feePool, err := app.DistrKeeper.FeePool.Get(ctx) | ||
if err != nil { | ||
panic(nil) | ||
} | ||
|
||
wangjiulian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...) | ||
app.DistrKeeper.SetFeePool(ctx, feePool) | ||
if err := app.DistrKeeper.FeePool.Set(ctx, feePool); err != nil { | ||
panic(err) | ||
} | ||
|
||
if err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator()); err != nil { | ||
if err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, sdk.ValAddress(val.GetOperator())); err != nil { | ||
panic(err) | ||
} | ||
return false | ||
|
@@ -182,22 +198,24 @@ func (app *IrisApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [ | |
// Iterate through validators by power descending, reset bond heights, and | ||
// update bond intra-tx counters. | ||
store := ctx.KVStore(app.GetKey(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 | ||
if applyAllowedAddrs && !allowedAddrsMap[addr.String()] { | ||
validator.Jailed = true | ||
} | ||
|
||
app.StakingKeeper.SetValidator(ctx, validator) | ||
if err := app.StakingKeeper.SetValidator(ctx, validator); err != nil { | ||
panic(err) | ||
} | ||
counter++ | ||
} | ||
|
||
|
@@ -206,7 +224,7 @@ func (app *IrisApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [ | |
return | ||
} | ||
|
||
_, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx) | ||
_, err = app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
wangjiulian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
@@ -232,6 +250,6 @@ func (app *IrisApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [ | |
// ExportGenesis returns the KVStoreKey for the provided store key. | ||
// | ||
// NOTE: This is solely to be used for testing purposes. | ||
func (app *IrisApp) ExportGenesis(ctx sdk.Context) map[string]json.RawMessage { | ||
func (app *IrisApp) ExportGenesis(ctx sdk.Context) (map[string]json.RawMessage, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle error returned by The |
||
return app.mm.ExportGenesis(ctx, app.AppCodec()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consolidate error handling imports
The file currently imports both
sdkerrors
anderrortypes
which can lead to confusion. In Cosmos SDK v0.50.x, the recommended approach is to usecosmossdk.io/errors
exclusively.Then update all error usages to use
sdkerrors.ErrXXX
instead oferrortypes.ErrXXX
.Also applies to: 8-8