From 667be5c9b8ac4dd22695282f22e583389169754f Mon Sep 17 00:00:00 2001 From: mmsqe Date: Sat, 21 Oct 2023 09:28:15 +0800 Subject: [PATCH] point to fix_chain_id --- CHANGELOG.md | 4 +-- cmd/cronosd/cmd/root.go | 30 ----------------- go.mod | 4 +-- go.sum | 4 +-- gomod2nix.toml | 6 ++-- integration_tests/cosmoscli.py | 13 ++++++-- integration_tests/ibc_utils.py | 8 ++++- integration_tests/test_client_id.py | 50 ++++++++++++++++++++++------- 8 files changed, 66 insertions(+), 53 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f104d55c9e..93a2b48a18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,9 @@ ## [Unreleased] -### Improvements +### Bug Fixes -- [#1216](https://github.com/crypto-org-chain/cronos/pull/1216) Enforce chainID config in client.toml. +- [#1216](https://github.com/crypto-org-chain/cronos/pull/1216) Read chainID config from client.toml with gensis fallback. *October 17, 2023* diff --git a/cmd/cronosd/cmd/root.go b/cmd/cronosd/cmd/root.go index f1e6c2cc5a..394a0f6bad 100644 --- a/cmd/cronosd/cmd/root.go +++ b/cmd/cronosd/cmd/root.go @@ -4,12 +4,10 @@ import ( "errors" "io" "os" - "path/filepath" "cosmossdk.io/simapp/params" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/types/module" - "github.com/spf13/viper" dbm "github.com/cometbft/cometbft-db" tmcfg "github.com/cometbft/cometbft/config" @@ -243,39 +241,11 @@ type appCreator struct { // newApp is an AppCreator func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application { home := cast.ToString(appOpts.Get(flags.FlagHome)) - snapshotDir := filepath.Join(home, "data", "snapshots") - if err := os.MkdirAll(snapshotDir, os.ModePerm); err != nil { - panic(err) - } - skipUpgradeHeights := make(map[int64]bool) for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) { skipUpgradeHeights[int64(h)] = true } - - // Setup chainId - chainID := cast.ToString(appOpts.Get(flags.FlagChainID)) - if len(chainID) == 0 { - v := viper.New() - v.AddConfigPath(filepath.Join(home, "config")) - v.SetConfigName("client") - v.SetConfigType("toml") - if err := v.ReadInConfig(); err != nil { - panic(err) - } - conf := new(config.ClientConfig) - if err := v.Unmarshal(conf); err != nil { - panic(err) - } - chainID = conf.ChainID - } - if len(chainID) == 0 { - panic("chainID not set") - } baseappOptions := server.DefaultBaseappOptions(appOpts) - baseappOptions = append(baseappOptions, func(app *baseapp.BaseApp) { - baseapp.SetChainID(chainID) - }) return app.New( logger, db, traceStore, true, SkipGravity, skipUpgradeHeights, home, diff --git a/go.mod b/go.mod index 1fbf653127..845231193f 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,6 @@ require ( github.com/spf13/cast v1.5.1 github.com/spf13/cobra v1.7.0 github.com/spf13/pflag v1.0.5 - github.com/spf13/viper v1.16.0 github.com/stretchr/testify v1.8.4 golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb google.golang.org/genproto/googleapis/api v0.0.0-20230629202037-9506855d4529 @@ -181,6 +180,7 @@ require ( github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect github.com/spf13/afero v1.9.5 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect + github.com/spf13/viper v1.16.0 // indirect github.com/status-im/keycard-go v0.0.0-20200402102358-957c09536969 // indirect github.com/subosito/gotenv v1.4.2 // indirect github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect @@ -234,7 +234,7 @@ replace ( // TODO: remove it: https://github.com/cosmos/cosmos-sdk/issues/13134 github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2 github.com/ethereum/go-ethereum => github.com/evmos/go-ethereum v1.10.26-evmos-rc1 - github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20230925072753-4062d0cc2a32 + github.com/evmos/ethermint => github.com/mmsqe/ethermint v0.6.1-0.20231021012219-5151dffd4e96 // Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities. // TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0 diff --git a/go.sum b/go.sum index 03b46f7274..7413395ed9 100644 --- a/go.sum +++ b/go.sum @@ -484,8 +484,6 @@ github.com/crypto-org-chain/cometbft-db v0.0.0-20231011055109-57922ac52a63 h1:R1 github.com/crypto-org-chain/cometbft-db v0.0.0-20231011055109-57922ac52a63/go.mod h1:rocwIfnS+kA060x64gkSIRvWB9StSppIkJuo5MWzL24= github.com/crypto-org-chain/cosmos-sdk v0.46.0-beta2.0.20231013072415-eec017435467 h1:m0/aHPIJAzi2MSP3TXzzbLTFf+koRFQiaYmerRZUtK4= github.com/crypto-org-chain/cosmos-sdk v0.46.0-beta2.0.20231013072415-eec017435467/go.mod h1:G384omH7cXgm90xXR7xpHvsKG7vdBaDuz4To6GpTHUU= -github.com/crypto-org-chain/ethermint v0.6.1-0.20230925072753-4062d0cc2a32 h1:A++epzNCr3EY57dnU6UTSDwbCiPD6MjvUKHKSd/PoI8= -github.com/crypto-org-chain/ethermint v0.6.1-0.20230925072753-4062d0cc2a32/go.mod h1:wnJQyK4n0vShhL+YIAUd7XCzUhgZ9fgG6yJ14n7qefo= github.com/crypto-org-chain/gravity-bridge/module/v2 v2.0.1-0.20230825054824-75403cd90c6e h1:rSTc35OBjjCBx47rHPWBCIHNGPbMnEj8f7fNcK2TjVI= github.com/crypto-org-chain/gravity-bridge/module/v2 v2.0.1-0.20230825054824-75403cd90c6e/go.mod h1:HBaDqlFjlaXJwVQtA7jHejyaA7xwjXI2o6pU/ccP3tE= github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= @@ -1140,6 +1138,8 @@ github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/mmsqe/ethermint v0.6.1-0.20231021012219-5151dffd4e96 h1:dR+fJHp9zgJYfMs8qW+OS4abAopjB2USv12T8M8/I5M= +github.com/mmsqe/ethermint v0.6.1-0.20231021012219-5151dffd4e96/go.mod h1:rbAKU2rftDobCIoCiol3SO+bTqw2cERu9TEki7PvfK0= github.com/moby/sys/mountinfo v0.5.0/go.mod h1:3bMD3Rg+zkqx8MRYPi7Pyb0Ie97QEBmdxbhnCLlSvSU= github.com/moby/term v0.0.0-20201216013528-df9cb8a40635/go.mod h1:FBS0z0QWA44HXygs7VXDUOGoN/1TV3RuWkLO04am3wc= github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6/go.mod h1:E2VnQOmVuvZB6UYnnDB0qG5Nq/1tD9acaOpo6xmt0Kw= diff --git a/gomod2nix.toml b/gomod2nix.toml index 4d7250a3d7..969aa5cc32 100644 --- a/gomod2nix.toml +++ b/gomod2nix.toml @@ -216,9 +216,9 @@ schema = 3 hash = "sha256-GgcReGsIIuBE2TabDYqDO9sBGogdVr9RSh4arQzdPnE=" replaced = "github.com/evmos/go-ethereum" [mod."github.com/evmos/ethermint"] - version = "v0.6.1-0.20230925072753-4062d0cc2a32" - hash = "sha256-8zwdHROHnAVfly2PIaNAfiXfb2fWsTqePaZ58EJtjH4=" - replaced = "github.com/crypto-org-chain/ethermint" + version = "v0.6.1-0.20231021012219-5151dffd4e96" + hash = "sha256-/2Zv9RZ8mTCdXAnNUc+9ubtt+zsS8dJRIT9TDwUoh9U=" + replaced = "github.com/mmsqe/ethermint" [mod."github.com/felixge/httpsnoop"] version = "v1.0.2" hash = "sha256-hj6FZQ1fDAV+1wGIViAt8XaAkWZ1I5vJzgjIJa7XRBA=" diff --git a/integration_tests/cosmoscli.py b/integration_tests/cosmoscli.py index 88dcc9e274..b7e356de9f 100644 --- a/integration_tests/cosmoscli.py +++ b/integration_tests/cosmoscli.py @@ -316,7 +316,16 @@ def staking_pool(self, bonded=True): )["bonded_tokens" if bonded else "not_bonded_tokens"] ) - def transfer(self, from_, to, coins, generate_only=False, fees=None, **kwargs): + def transfer( + self, + from_, + to, + coins, + generate_only=False, + fees=None, + event_query_tx_for=True, + **kwargs, + ): kwargs.setdefault("gas_prices", DEFAULT_GAS_PRICE) rsp = json.loads( self.raw( @@ -333,7 +342,7 @@ def transfer(self, from_, to, coins, generate_only=False, fees=None, **kwargs): **kwargs, ) ) - if rsp["code"] == 0: + if rsp["code"] == 0 and event_query_tx_for: rsp = self.event_query_tx_for(rsp["txhash"]) return rsp diff --git a/integration_tests/ibc_utils.py b/integration_tests/ibc_utils.py index a00b3c2986..a62b84653a 100644 --- a/integration_tests/ibc_utils.py +++ b/integration_tests/ibc_utils.py @@ -620,7 +620,13 @@ def funds_ica(cli, adr): assert cli.balance(adr) == 0 # send some funds to interchain account - rsp = cli.transfer("signer2", adr, "1cro", gas_prices="1000000basecro") + rsp = cli.transfer( + "signer2", + adr, + "1cro", + gas_prices="1000000basecro", + event_query_tx_for=False, + ) assert rsp["code"] == 0, rsp["raw_log"] wait_for_new_blocks(cli, 1) amt = 100000000 diff --git a/integration_tests/test_client_id.py b/integration_tests/test_client_id.py index 1fd113a956..f90b4bc459 100644 --- a/integration_tests/test_client_id.py +++ b/integration_tests/test_client_id.py @@ -1,30 +1,58 @@ +import json +from pathlib import Path + import pytest import tomlkit from pystarport import ports +from .network import setup_custom_cronos from .utils import wait_for_port -def test_config_client_id(cronos): +@pytest.fixture(scope="module") +def custom_cronos(tmp_path_factory): + path = tmp_path_factory.mktemp("cronos") + yield from setup_custom_cronos( + path, + 26800, + Path(__file__).parent / "configs/default.jsonnet", + ) + + +def test_config_client_id(custom_cronos): n0 = "cronos_777-1-node0" - cronos.supervisorctl("stop", n0) - cli = cronos.cosmos_cli(0) - home = cli.data_dir - file = "config/client.toml" + p0 = custom_cronos.base_port(0) + w3 = custom_cronos.w3 + custom_cronos.supervisorctl("stop", n0) + cli = custom_cronos.cosmos_cli(0) + dir = cli.data_dir / "config" def edit_client_cfg(chain_id): - node0 = tomlkit.parse((home / file).read_text()) + client_cfg = dir / "client.toml" + node0 = tomlkit.parse(client_cfg.read_text()) node0["chain-id"] = chain_id - (home / file).write_text(tomlkit.dumps(node0)) + client_cfg.write_text(tomlkit.dumps(node0)) + + def edit_gensis_cfg(chain_id): + genesis_cfg = dir / "genesis.json" + genesis = json.loads(genesis_cfg.read_text()) + genesis["chain_id"] = chain_id + genesis_cfg.write_text(json.dumps(genesis)) + # empty fallback chain_id from genesis edit_client_cfg("") - with pytest.raises(Exception): - cronos.supervisorctl("start", n0) + edit_gensis_cfg("cronos_778-1") + custom_cronos.supervisorctl("start", n0) + wait_for_port(ports.evmrpc_port(p0)) + assert w3.eth.chain_id == 778 + custom_cronos.supervisorctl("stop", n0) edit_client_cfg("cronos_777-1") - cronos.supervisorctl("start", n0) - wait_for_port(ports.rpc_port(cronos.base_port(0))) + custom_cronos.supervisorctl("start", n0) + wait_for_port(ports.evmrpc_port(p0)) + assert w3.eth.chain_id == 777 + wait_for_port(ports.rpc_port(p0)) # transfer without chain-id flag should work rsp = cli.transfer("signer1", cli.address("validator"), "1basetcro") assert rsp["code"] == 0, rsp["raw_log"]