diff --git a/app/app.go b/app/app.go index 589f0a900d..5be90ab911 100644 --- a/app/app.go +++ b/app/app.go @@ -498,6 +498,7 @@ func New( appCodec, keys[cronostypes.StoreKey], keys[cronostypes.MemStoreKey], + app.GetSubspace(cronostypes.ModuleName), app.BankKeeper, app.TransferKeeper, gravityKeeper, @@ -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 } diff --git a/integration_tests/cosmoscli.py b/integration_tests/cosmoscli.py index b9246b2645..f364d4e83a 100644 --- a/integration_tests/cosmoscli.py +++ b/integration_tests/cosmoscli.py @@ -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, ) ) diff --git a/integration_tests/test_upgrade.py b/integration_tests/test_upgrade.py index 2c3c862649..e6dfcb5f41 100644 --- a/integration_tests/test_upgrade.py +++ b/integration_tests/test_upgrade.py @@ -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", + } + diff --git a/x/cronos/client/cli/query.go b/x/cronos/client/cli/query.go index 8efec106a1..28facfc8e9 100644 --- a/x/cronos/client/cli/query.go +++ b/x/cronos/client/cli/query.go @@ -2,6 +2,7 @@ package cli import ( "fmt" + "strconv" "strings" rpctypes "github.com/evmos/ethermint/rpc/types" @@ -38,12 +39,13 @@ 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: -$ query cronos params +$ query cronos params [height] `), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientQueryContext(cmd) @@ -51,8 +53,15 @@ $ query cronos params 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 } diff --git a/x/cronos/exported/exported.go b/x/cronos/exported/exported.go index 000114e619..2d8532c46e 100644 --- a/x/cronos/exported/exported.go +++ b/x/cronos/exported/exported.go @@ -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 } ) diff --git a/x/cronos/keeper/evm_hooks_test.go b/x/cronos/keeper/evm_hooks_test.go index 908a26aff3..b7d7a8b5bf 100644 --- a/x/cronos/keeper/evm_hooks_test.go +++ b/x/cronos/keeper/evm_hooks_test.go @@ -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, diff --git a/x/cronos/keeper/evmhandlers_test.go b/x/cronos/keeper/evmhandlers_test.go index 03092eda1c..cb13b49f62 100644 --- a/x/cronos/keeper/evmhandlers_test.go +++ b/x/cronos/keeper/evmhandlers_test.go @@ -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, @@ -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, @@ -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, diff --git a/x/cronos/keeper/ibc_test.go b/x/cronos/keeper/ibc_test.go index ec7ab125bc..47f0b80a93 100644 --- a/x/cronos/keeper/ibc_test.go +++ b/x/cronos/keeper/ibc_test.go @@ -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, diff --git a/x/cronos/keeper/keeper.go b/x/cronos/keeper/keeper.go index 167fd4530a..c65905c9e7 100644 --- a/x/cronos/keeper/keeper.go +++ b/x/cronos/keeper/keeper.go @@ -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" @@ -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 @@ -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, @@ -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, diff --git a/x/cronos/keeper/keeper_test.go b/x/cronos/keeper/keeper_test.go index 17455f377e..d89e218a45 100644 --- a/x/cronos/keeper/keeper_test.go +++ b/x/cronos/keeper/keeper_test.go @@ -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, @@ -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, diff --git a/x/cronos/keeper/params.go b/x/cronos/keeper/params.go index 4c54c934b1..606c17c954 100644 --- a/x/cronos/keeper/params.go +++ b/x/cronos/keeper/params.go @@ -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, ¶ms) return params } k.cdc.MustUnmarshal(bz, ¶ms) diff --git a/x/cronos/keeper/params_test.go b/x/cronos/keeper/params_test.go index a7cacf94e0..e8a8455171 100644 --- a/x/cronos/keeper/params_test.go +++ b/x/cronos/keeper/params_test.go @@ -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, diff --git a/x/cronos/migrations/v2/migrate_test.go b/x/cronos/migrations/v2/migrate_test.go index d20ae38557..b2e479c39d 100644 --- a/x/cronos/migrations/v2/migrate_test.go +++ b/x/cronos/migrations/v2/migrate_test.go @@ -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" @@ -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"))