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

Problem: rpc can't query old parameter format after migration #807

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ func New(
appCodec,
keys[cronostypes.StoreKey],
keys[cronostypes.MemStoreKey],
app.GetSubspace(cronostypes.ModuleName),
app.BankKeeper,
app.TransferKeeper,
gravityKeeper,
Expand Down Expand Up @@ -968,7 +969,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(gravitytypes.ModuleName)
}
// this line is used by starport scaffolding # stargate/app/paramSubspace
paramsKeeper.Subspace(cronostypes.ModuleName).WithKeyTable(cronostypes.ParamKeyTable())
paramsKeeper.Subspace(cronostypes.ModuleName)

return paramsKeeper
}
Expand Down
3 changes: 2 additions & 1 deletion integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1431,13 +1431,14 @@ def turn_bridge(self, enable, **kwargs):
)
)

def query_params(self):
def query_params(self, height: int):
"query cronos params"
return json.loads(
self.raw(
"query",
"cronos",
"params",
height,
home=self.data_dir,
)
)
11 changes: 10 additions & 1 deletion integration_tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,19 @@ def test_cosmovisor_upgrade(custom_cronos: Cronos):
contract.caller(block_identifier=target_height - 2).balanceOf(ADDRS["validator"])

# check we could fetch the right params after cronos Migrate1To2
assert cli.query_params() == {
assert cli.query_params(0) == {
"cronos_admin": "crc12luku6uxehhak02py4rcz65zu0swh7wjsrw0pp",
"enable_auto_deployment": True,
"ibc_cro_denom": "ibc/6411AE2ADA1E73DB59DB151"
"A8988F9B7D5E7E233D8414DB6817F8F1A01611F86",
"ibc_timeout": "86400000000000",
}

assert cli.query_params(target_height-5) == {
"cronos_admin": "crc12luku6uxehhak02py4rcz65zu0swh7wjsrw0pp",
"enable_auto_deployment": True,
"ibc_cro_denom": "ibc/6411AE2ADA1E73DB59DB151"
"A8988F9B7D5E7E233D8414DB6817F8F1A01611F86",
"ibc_timeout": "86400000000000",
}

Comment on lines +169 to +184
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
assert cli.query_params(0) == {
"cronos_admin": "crc12luku6uxehhak02py4rcz65zu0swh7wjsrw0pp",
"enable_auto_deployment": True,
"ibc_cro_denom": "ibc/6411AE2ADA1E73DB59DB151"
"A8988F9B7D5E7E233D8414DB6817F8F1A01611F86",
"ibc_timeout": "86400000000000",
}
assert cli.query_params(target_height-5) == {
"cronos_admin": "crc12luku6uxehhak02py4rcz65zu0swh7wjsrw0pp",
"enable_auto_deployment": True,
"ibc_cro_denom": "ibc/6411AE2ADA1E73DB59DB151"
"A8988F9B7D5E7E233D8414DB6817F8F1A01611F86",
"ibc_timeout": "86400000000000",
}
expected_param = {
"cronos_admin": "crc12luku6uxehhak02py4rcz65zu0swh7wjsrw0pp",
"enable_auto_deployment": True,
"ibc_cro_denom": "ibc/6411AE2ADA1E73DB59DB151"
"A8988F9B7D5E7E233D8414DB6817F8F1A01611F86",
"ibc_timeout": "86400000000000",
}
assert cli.query_params(0) == expected_param
assert cli.query_params(target_height-5) == expected_param

21 changes: 15 additions & 6 deletions x/cronos/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"fmt"
"strconv"
"strings"

rpctypes "github.com/evmos/ethermint/rpc/types"
Expand Down Expand Up @@ -38,21 +39,29 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
// QueryParamsCmd returns the command handler for evidence parameter querying.
func QueryParamsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "Query the current cronos parameters",
Args: cobra.NoArgs,
Long: strings.TrimSpace(`Query the current cronos parameters:
Use: "params [height]",
Short: "Query the cronos parameters associated with a specific blockheight",
Args: cobra.ExactArgs(1),
Long: strings.TrimSpace(`Query the cronos parameters associated with a specific blockheight, 0 or negative
means the latest blockheight:

$ <appd> query cronos params
$ <appd> query cronos params [height]
`),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

height, err := strconv.ParseInt(args[0], 10, 64)
if err != nil {
return err
}
if height <= 0 {
height = clientCtx.Height
}
queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{})
res, err := queryClient.Params(rpctypes.ContextWithHeight(height), &types.QueryParamsRequest{})
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions x/cronos/exported/exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ type (
// NOTE: This is used solely for migration of x/params managed parameters.
Subspace interface {
GetParamSet(ctx sdk.Context, ps ParamSet)
HasKeyTable() bool
WithKeyTable(paramtypes.KeyTable) paramtypes.Subspace
}
)
1 change: 1 addition & 0 deletions x/cronos/keeper/evm_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() {
app.MakeEncodingConfig().Codec,
suite.app.GetKey(types.StoreKey),
suite.app.GetKey(types.MemStoreKey),
suite.app.GetSubspace(types.ModuleName),
suite.app.BankKeeper,
keepertest.IbcKeeperMock{},
suite.app.GravityKeeper,
Expand Down
3 changes: 3 additions & 0 deletions x/cronos/keeper/evmhandlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ func (suite *KeeperTestSuite) TestSendToIbcHandler() {
app.MakeEncodingConfig().Codec,
suite.app.GetKey(types.StoreKey),
suite.app.GetKey(types.MemStoreKey),
suite.app.GetSubspace(types.ModuleName),
suite.app.BankKeeper,
keepertest.IbcKeeperMock{},
suite.app.GravityKeeper,
Expand Down Expand Up @@ -479,6 +480,7 @@ func (suite *KeeperTestSuite) TestSendToIbcV2Handler() {
app.MakeEncodingConfig().Codec,
suite.app.GetKey(types.StoreKey),
suite.app.GetKey(types.MemStoreKey),
suite.app.GetSubspace(types.ModuleName),
suite.app.BankKeeper,
keepertest.IbcKeeperMock{},
suite.app.GravityKeeper,
Expand Down Expand Up @@ -576,6 +578,7 @@ func (suite *KeeperTestSuite) TestSendCroToIbcHandler() {
app.MakeEncodingConfig().Codec,
suite.app.GetKey(types.StoreKey),
suite.app.GetKey(types.MemStoreKey),
suite.app.GetSubspace(types.ModuleName),
suite.app.BankKeeper,
keepertest.IbcKeeperMock{},
suite.app.GravityKeeper,
Expand Down
1 change: 1 addition & 0 deletions x/cronos/keeper/ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ func (suite *KeeperTestSuite) TestIbcTransferCoins() {
app.MakeEncodingConfig().Codec,
suite.app.GetKey(types.StoreKey),
suite.app.GetKey(types.MemStoreKey),
suite.app.GetSubspace(types.ModuleName),
suite.app.BankKeeper,
keepertest.IbcKeeperMock{},
suite.app.GravityKeeper,
Expand Down
12 changes: 12 additions & 0 deletions x/cronos/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/crypto-org-chain/cronos/x/cronos/exported"

"github.com/tendermint/tendermint/libs/log"

Expand All @@ -25,6 +26,9 @@ type (
storeKey storetypes.StoreKey
memKey storetypes.StoreKey

// paramsSpace is needed incase we need to get params in old blocks context
paramSpace exported.Subspace

// update balance and accounting operations with coins
bankKeeper types.BankKeeper
// ibc transfer operations
Expand All @@ -48,6 +52,7 @@ func NewKeeper(
cdc codec.Codec,
storeKey,
memKey storetypes.StoreKey,
paramSpace exported.Subspace,
bankKeeper types.BankKeeper,
transferKeeper types.TransferKeeper,
gravityKeeper types.GravityKeeper,
Expand All @@ -60,10 +65,17 @@ func NewKeeper(
panic(err)
}

// set KeyTable if it has not already been set.
// we need paramsSpace incase we need to get params in old blocks context.
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
}

return &Keeper{
cdc: cdc,
storeKey: storeKey,
memKey: memKey,
paramSpace: paramSpace,
bankKeeper: bankKeeper,
transferKeeper: transferKeeper,
gravityKeeper: gravityKeeper,
Expand Down
2 changes: 2 additions & 0 deletions x/cronos/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ func (suite *KeeperTestSuite) TestOnRecvVouchers() {
app.MakeEncodingConfig().Codec,
suite.app.GetKey(types.StoreKey),
suite.app.GetKey(types.MemStoreKey),
suite.app.GetSubspace(types.ModuleName),
suite.app.BankKeeper,
keepertest.IbcKeeperMock{},
suite.app.GravityKeeper,
Expand Down Expand Up @@ -416,6 +417,7 @@ func (suite *KeeperTestSuite) TestRegisterOrUpdateTokenMapping() {
app.MakeEncodingConfig().Codec,
suite.app.GetKey(types.StoreKey),
suite.app.GetKey(types.MemStoreKey),
suite.app.GetSubspace(types.ModuleName),
suite.app.BankKeeper,
keepertest.IbcKeeperMock{},
suite.app.GravityKeeper,
Expand Down
1 change: 1 addition & 0 deletions x/cronos/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamsKey)
if bz == nil {
k.paramSpace.GetParamSet(ctx, &params)
return params
}
k.cdc.MustUnmarshal(bz, &params)
Expand Down
1 change: 1 addition & 0 deletions x/cronos/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (suite *KeeperTestSuite) TestGetSourceChannelID() {
app.MakeEncodingConfig().Codec,
suite.app.GetKey(types.StoreKey),
suite.app.GetKey(types.MemStoreKey),
suite.app.GetSubspace(types.ModuleName),
suite.app.BankKeeper,
keepertest.IbcKeeperMock{},
suite.app.GravityKeeper,
Expand Down
9 changes: 9 additions & 0 deletions x/cronos/migrations/v2/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/crypto-org-chain/cronos/x/cronos/exported"
v2 "github.com/crypto-org-chain/cronos/x/cronos/migrations/v2"
"github.com/crypto-org-chain/cronos/x/cronos/types"
Expand All @@ -24,6 +25,14 @@ func (ms mockSubspace) GetParamSet(ctx sdk.Context, ps exported.ParamSet) {
*ps.(*types.Params) = ms.ps
}

func (ms mockSubspace) HasKeyTable() bool {
return false
}

func (ms mockSubspace) WithKeyTable(paramtypes.KeyTable) paramtypes.Subspace {
return paramtypes.Subspace{}
}

func TestMigrate(t *testing.T) {
storeKey := sdk.NewKVStoreKey(types.ModuleName)
ctx := testutil.DefaultContext(storeKey, sdk.NewTransientStoreKey("test"))
Expand Down