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 3 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
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