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: x/params is deprecated, need to migrate away from it #735

Merged
merged 5 commits into from
Dec 13, 2022
Merged
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
6 changes: 3 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,14 +498,14 @@ func New(
appCodec,
keys[cronostypes.StoreKey],
keys[cronostypes.MemStoreKey],
app.GetSubspace(cronostypes.ModuleName),
app.BankKeeper,
app.TransferKeeper,
gravityKeeper,
app.EvmKeeper,
app.AccountKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
cronosModule := cronos.NewAppModule(app.CronosKeeper, app.AccountKeeper, app.BankKeeper)
cronosModule := cronos.NewAppModule(app.CronosKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(cronostypes.ModuleName))

// register the proposal types
govRouter := govv1beta1.NewRouter()
Expand Down Expand Up @@ -968,7 +968,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)
paramsKeeper.Subspace(cronostypes.ModuleName).WithKeyTable(cronostypes.ParamKeyTable())

return paramsKeeper
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/crypto-org-chain/cronos
go 1.18

require (
cosmossdk.io/errors v1.0.0-beta.7
cosmossdk.io/math v1.0.0-beta.3
github.com/armon/go-metrics v0.4.1
github.com/cosmos/cosmos-sdk v0.46.3
Expand Down Expand Up @@ -32,7 +33,6 @@ require (
cloud.google.com/go/compute v1.7.0 // indirect
cloud.google.com/go/iam v0.4.0 // indirect
cloud.google.com/go/storage v1.22.1 // indirect
cosmossdk.io/errors v1.0.0-beta.7 // indirect
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
Expand Down
11 changes: 11 additions & 0 deletions integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1430,3 +1430,14 @@ def turn_bridge(self, enable, **kwargs):
**kwargs,
)
)

def query_params(self):
"query cronos params"
return json.loads(
self.raw(
"query",
"cronos",
"params",
home=self.data_dir,
)
)
65 changes: 65 additions & 0 deletions integration_tests/test_gov_update_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import json

from dateutil.parser import isoparse

from .utils import parse_events, wait_for_block_time, wait_for_new_blocks


def test_gov_update_params(cronos, tmp_path):
cli = cronos.cosmos_cli()

proposal = tmp_path / "proposal.json"
# governance module account as signer
signer = "crc10d07y265gmmuvt4z0w9aw880jnsr700jdufnyd"
proposal_src = {
"messages": [
{
"@type": "/cronos.MsgUpdateParams",
"authority": signer,
"params": {
"cronos_admin": "crc12luku6uxehhak02py4rcz65zu0swh7wjsrw0pp",
"enable_auto_deployment": False,
"ibc_cro_denom": "ibc/6411AE2ADA1E73DB59DB151"
"A8988F9B7D5E7E233D8414DB6817F8F1A01600000",
"ibc_timeout": "96400000000000",
},
}
],
"deposit": "1basetcro",
}
proposal.write_text(json.dumps(proposal_src))
rsp = cli.submit_gov_proposal(proposal, from_="community")

assert rsp["code"] == 0, rsp["raw_log"]

# get proposal_id
ev = parse_events(rsp["logs"])["submit_proposal"]
proposal_id = ev["proposal_id"]
print("gov proposal submitted", proposal_id)

# not sure why, but sometimes can't find the proposal immediatelly
wait_for_new_blocks(cli, 1)
proposal = cli.query_proposal(proposal_id)

# each validator vote yes
for i in range(len(cronos.config["validators"])):
rsp = cronos.cosmos_cli(i).gov_vote("validator", proposal_id, "yes")
assert rsp["code"] == 0, rsp["raw_log"]
wait_for_new_blocks(cli, 1)
assert (
int(cli.query_tally(proposal_id)["yes_count"]) == cli.staking_pool()
), "all validators should have voted yes"
print("wait for proposal to be activated")
wait_for_block_time(cli, isoparse(proposal["voting_end_time"]))
wait_for_new_blocks(cli, 1)

print("check params have been updated now")
rsp = cli.query_params()
print("params", rsp)
assert rsp == {
"cronos_admin": "crc12luku6uxehhak02py4rcz65zu0swh7wjsrw0pp",
"enable_auto_deployment": False,
"ibc_cro_denom": "ibc/6411AE2ADA1E73DB59DB151"
"A8988F9B7D5E7E233D8414DB6817F8F1A01600000",
"ibc_timeout": "96400000000000",
}
9 changes: 9 additions & 0 deletions integration_tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,12 @@ def test_cosmovisor_upgrade(custom_cronos: Cronos):

# check eth_call works on older blocks
contract.caller(block_identifier=target_height - 2).balanceOf(ADDRS["validator"])

# check we could fetch the right params after cronos Migrate1To2
assert cli.query_params() == {
"cronos_admin": "crc12luku6uxehhak02py4rcz65zu0swh7wjsrw0pp",
"enable_auto_deployment": True,
"ibc_cro_denom": "ibc/6411AE2ADA1E73DB59DB151"
"A8988F9B7D5E7E233D8414DB6817F8F1A01611F86",
"ibc_timeout": "86400000000000",
}
15 changes: 15 additions & 0 deletions proto/cronos/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "google/protobuf/timestamp.proto";
import "ethermint/evm/v1/tx.proto";
import "cronos/cronos.proto";
// this line is used by starport scaffolding # 1

option go_package = "github.com/crypto-org-chain/cronos/x/cronos/types";
Expand All @@ -24,6 +25,11 @@ service Query {
// ReplayBlock replay the eth messages in the block to recover the results of false-failed txs.
rpc ReplayBlock(ReplayBlockRequest) returns (ReplayBlockResponse) { }

// Params queries all parameters.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/cronos/v1/params";
}

// this line is used by starport scaffolding # 2
}

Expand Down Expand Up @@ -71,4 +77,13 @@ message ReplayBlockResponse {
repeated ethermint.evm.v1.MsgEthereumTxResponse responses = 1;
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
// params defines the parameters of the module.
Params params = 1 [(gogoproto.nullable) = false];
}

// this line is used by starport scaffolding # 3
16 changes: 16 additions & 0 deletions proto/cronos/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cronos;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cronos/cronos.proto";

option go_package = "github.com/crypto-org-chain/cronos/x/cronos/types";

Expand All @@ -26,6 +27,9 @@ service Msg {

// TurnBridge defines a method to disable or enable the gravity bridge
rpc TurnBridge(MsgTurnBridge) returns (MsgTurnBridgeResponse);

// UpdateParams defines a method to update cronos module params
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

// MsgConvertVouchers represents a message to convert ibc voucher coins to
Expand Down Expand Up @@ -77,4 +81,16 @@ message MsgTurnBridge {
// MsgTurnBridgegResponse defines the response type
message MsgTurnBridgeResponse {}

// MsgUpdateParams defines the request type for updating cronos params.
message MsgUpdateParams {
// authority is the address of the governance account.
string authority = 1;

// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false];
}

// MsgUpdateParamsResponse defines the response type.
message MsgUpdateParamsResponse {}

// this line is used by starport scaffolding # proto/tx/message
33 changes: 33 additions & 0 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"
"strings"

rpctypes "github.com/evmos/ethermint/rpc/types"
"github.com/spf13/cobra"
Expand All @@ -26,13 +27,45 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
cmd.AddCommand(
GetContractByDenomCmd(),
GetDenomByContractCmd(),
QueryParamsCmd(),
)

// this line is used by starport scaffolding # 1

return cmd
}

// 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:

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

queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{})
if err != nil {
return err
}

return clientCtx.PrintProto(&res.Params)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetContractByDenomCmd queries the contracts by denom
func GetContractByDenomCmd() *cobra.Command {
cmd := &cobra.Command{
Expand Down
18 changes: 18 additions & 0 deletions x/cronos/exported/exported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package exported

import (
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

type (
ParamSet = paramtypes.ParamSet

// Subspace defines an interface that implements the legacy x/params Subspace
// type.
//
// NOTE: This is used solely for migration of x/params managed parameters.
Subspace interface {
GetParamSet(ctx sdk.Context, ps ParamSet)
}
)
4 changes: 3 additions & 1 deletion x/cronos/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
// InitGenesis initializes the capability module's state from a provided genesis
// state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
k.SetParams(ctx, genState.Params)
if err := k.SetParams(ctx, genState.Params); err != nil {
panic(fmt.Sprintf("Invalid cronos module params: %v\n", genState.Params))
}

for _, m := range genState.ExternalContracts {
// Only allowed to bootstrap external token at genesis
Expand Down
7 changes: 5 additions & 2 deletions x/cronos/keeper/evm_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ package keeper_test

import (
"fmt"
handlers "github.com/crypto-org-chain/cronos/x/cronos/keeper/evmhandlers"
"math/big"

handlers "github.com/crypto-org-chain/cronos/x/cronos/keeper/evmhandlers"

gravitytypes "github.com/peggyjv/gravity-bridge/module/v2/x/gravity/types"

"github.com/crypto-org-chain/cronos/app"
keepertest "github.com/crypto-org-chain/cronos/x/cronos/keeper/mock"
"github.com/crypto-org-chain/cronos/x/cronos/types"

sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
cronosmodulekeeper "github.com/crypto-org-chain/cronos/x/cronos/keeper"
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -198,12 +201,12 @@ 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,
suite.app.EvmKeeper,
suite.app.AccountKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
suite.app.CronosKeeper = cronosKeeper

Expand Down
8 changes: 5 additions & 3 deletions x/cronos/keeper/evmhandlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"math/big"

sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/crypto-org-chain/cronos/app"
cronosmodulekeeper "github.com/crypto-org-chain/cronos/x/cronos/keeper"
evmhandlers "github.com/crypto-org-chain/cronos/x/cronos/keeper/evmhandlers"
Expand Down Expand Up @@ -356,12 +358,12 @@ 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,
suite.app.EvmKeeper,
suite.app.AccountKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
handler := evmhandlers.NewSendToIbcHandler(suite.app.BankKeeper, cronosKeeper)
tc.malleate()
Expand Down Expand Up @@ -478,12 +480,12 @@ 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,
suite.app.EvmKeeper,
suite.app.AccountKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
handler := evmhandlers.NewSendToIbcV2Handler(suite.app.BankKeeper, cronosKeeper)
tc.malleate()
Expand Down Expand Up @@ -575,12 +577,12 @@ 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,
suite.app.EvmKeeper,
suite.app.AccountKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
handler := evmhandlers.NewSendCroToIbcHandler(suite.app.BankKeeper, cronosKeeper)
tc.malleate()
Expand Down
14 changes: 14 additions & 0 deletions x/cronos/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"fmt"
"math/big"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/crypto-org-chain/cronos/x/cronos/types"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -110,3 +113,14 @@ func (k Keeper) ReplayBlock(goCtx context.Context, req *types.ReplayBlockRequest
Responses: rsps,
}, nil
}

// Params returns parameters of cronos module
func (k Keeper) Params(goCtx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
ctx := sdk.UnwrapSDKContext(goCtx)
params := k.GetParams(ctx)

return &types.QueryParamsResponse{Params: params}, nil
}
Loading