Skip to content

Commit

Permalink
point to fix_chain_id
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Oct 21, 2023
1 parent ed641eb commit 667be5c
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 53 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
30 changes: 0 additions & 30 deletions cmd/cronosd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
6 changes: 3 additions & 3 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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="
Expand Down
13 changes: 11 additions & 2 deletions integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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

Expand Down
8 changes: 7 additions & 1 deletion integration_tests/ibc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 39 additions & 11 deletions integration_tests/test_client_id.py
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 667be5c

Please sign in to comment.