From b1f4372f5e7f4b27442cfd72e47b7d9ee97d7d9e Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Wed, 12 Jun 2024 11:53:22 +0700 Subject: [PATCH 1/4] feat: add script --- cmd/picad/cmd/root.go | 1 + scripts/run-node-two-validator.sh | 114 ++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100755 scripts/run-node-two-validator.sh diff --git a/cmd/picad/cmd/root.go b/cmd/picad/cmd/root.go index 1eff90f9..c1a2378a 100644 --- a/cmd/picad/cmd/root.go +++ b/cmd/picad/cmd/root.go @@ -85,6 +85,7 @@ func NewRootCmd() (*cobra.Command, app.EncodingConfig) { cmd.SetOut(cmd.OutOrStdout()) cmd.SetErr(cmd.ErrOrStderr()) + initClientCtx = initClientCtx.WithCmdContext(cmd.Context()) initClientCtx, err := client.ReadPersistentCommandFlags(initClientCtx, cmd.Flags()) if err != nil { return err diff --git a/scripts/run-node-two-validator.sh b/scripts/run-node-two-validator.sh new file mode 100755 index 00000000..79a09e1b --- /dev/null +++ b/scripts/run-node-two-validator.sh @@ -0,0 +1,114 @@ +#!/bin/bash + +KEY="mykey" +KEY1="mykey1" +CHAINID="centauri-dev" +MONIKER="localtestnet" +KEYALGO="secp256k1" +KEYRING="test" +LOGLEVEL="info" +BINARY=$1 +# to trace evm +#TRACE="--trace" +TRACE="" + +echo "runnode" + +HOME_DIR=mytestnet +DENOM=ppica + +# remove existing daemon +rm -rf $HOME_DIR + + +if [ ! -x "$(command -v $BINARY)" ]; then + echo "Error: Binary $BINARY is not executable or not found." + exit 1 +fi + + +if [ "$CONTINUE" == "true" ]; then + echo "\n ->> continuing from previous state" + $BINARY start --home $HOME_DIR --log_level debug + exit 0 +fi + + +$BINARY config keyring-backend $KEYRING +$BINARY config chain-id $CHAINID + + +# if $KEY exists it should be deleted +echo "decorate bright ozone fork gallery riot bus exhaust worth way bone indoor calm squirrel merry zero scheme cotton until shop any excess stage laundry" | $BINARY keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO --recover --home $HOME_DIR +echo "bottom loan skill merry east cradle onion journey palm apology verb edit desert impose absurd oil bubble sweet glove shallow size build burst effort" | $BINARY keys add $KEY1 --keyring-backend $KEYRING --algo $KEYALGO --recover --home $HOME_DIR + +$BINARY init $CHAINID --chain-id $CHAINID --default-denom "ppica" --home $HOME_DIR >/dev/null 2>&1 + +update_test_genesis () { + # update_test_genesis '.consensus_params["block"]["max_gas"]="100000000"' + cat $HOME_DIR/config/genesis.json | jq "$1" > $HOME_DIR/config/tmp_genesis.json && cp $HOME_DIR/config/tmp_genesis.json $HOME_DIR/config/genesis.json +} + +# Allocate genesis accounts (cosmos formatted addresses) +$BINARY add-genesis-account $KEY 100000000000000000000000000ppica --keyring-backend $KEYRING --home $HOME_DIR +$BINARY add-genesis-account $KEY1 100000000000000000000000000ppica --keyring-backend $KEYRING --home $HOME_DIR + +# Sign genesis transaction +$BINARY gentx $KEY 10030009994127689ppica --keyring-backend $KEYRING --chain-id $CHAINID --home $HOME_DIR --moniker val1 +mv $HOME_DIR/config/priv_validator_key.json $HOME_DIR/config/priv_validator_key0.json +$BINARY gentx $KEY1 100000ppica --keyring-backend $KEYRING --chain-id $CHAINID --home $HOME_DIR --output-document $HOME_DIR/config/gentx/1.json +mv $HOME_DIR/config/priv_validator_key.json $HOME_DIR/config/priv_validator_key1.json +update_test_genesis '.app_state["gov"]["params"]["voting_period"]="20s"' +update_test_genesis '.app_state["gov"]["params"]["expedited_voting_period"]="10s"' +update_test_genesis '.app_state["stakingmiddleware"]["params"]["blocks_per_epoch"]="5"' +update_test_genesis '.app_state["mint"]["params"]["mint_denom"]="'$DENOM'"' +update_test_genesis '.app_state["gov"]["params"]["min_deposit"]=[{"denom":"'$DENOM'","amount": "1"}]' +update_test_genesis '.app_state["crisis"]["constant_fee"]={"denom":"'$DENOM'","amount":"1000"}' + +# Collect genesis tx +$BINARY collect-gentxs --home $HOME_DIR + +# Run this to ensure everything worked and that the genesis file is setup correctly +$BINARY validate-genesis --home $HOME_DIR + +if [[ $1 == "pending" ]]; then + echo "pending mode is on, please wait for the first block committed." +fi + +# update request max size so that we can upload the light client +# '' -e is a must have params on mac, if use linux please delete before run +sed -i'' -e 's/max_body_bytes = /max_body_bytes = 1/g' $HOME_DIR/config/config.toml +sed -i'' -e 's/max_tx_bytes = 1048576/max_tx_bytes = 10000000/g' $HOME_DIR/config/config.toml + +# Initialize directories for two validators +$BINARY init $CHAINID --chain-id $CHAINID --default-denom "ppica" --home $HOME_DIR/validator1 >/dev/null 2>&1 +$BINARY init $CHAINID --chain-id $CHAINID --default-denom "ppica" --home $HOME_DIR/validator2 >/dev/null 2>&1 + + +# Copy the genesis file to each validator's directory +cp $HOME_DIR/config/genesis.json $HOME_DIR/validator1/config/genesis.json +cp $HOME_DIR/config/genesis.json $HOME_DIR/validator2/config/genesis.json +mv $HOME_DIR/config/priv_validator_key0.json $HOME_DIR/validator1/config/priv_validator_key.json +mv $HOME_DIR/config/priv_validator_key1.json $HOME_DIR/validator2/config/priv_validator_key.json + +P2PPORT_2=26658 +RPCPORT_2=26659 +RESTPORT_2=1316 +ROSETTA_2=8081 +WEB_PORT_2=9091 + +sed -i -e 's#"tcp://0.0.0.0:26656"#"tcp://localhost:'"$P2PPORT_2"'"#g' $HOME_DIR/validator2/config/config.toml +sed -i -e 's#"tcp://127.0.0.1:26657"#"tcp://localhost:'"$RPCPORT_2"'"#g' $HOME_DIR/validator2/config/config.toml +sed -i -e 's#"tcp://localhost:26657"#"tcp://localhost:'"$RPCPORT_2"'"#g' $HOME_DIR/validator2/config/client.toml +sed -i -e 's#"tcp://localhost:1317"#"tcp://localhost:'"$RESTPORT_2"'"#g' $HOME_DIR/validator2/config/app.toml +sed -i -e 's#"localhost:9090"#"localhost:'"$WEB_PORT_2"'"#g' $HOME_DIR/validator2/config/app.toml +sed -i -e 's#"127.0.0.1:9090"#"localhost:'"$WEB_PORT_2"'"#g' $HOME_DIR/validator2/config/app.toml +sed -i -e 's#pprof_laddr = "localhost:6060"#pprof_laddr = "localhost:7070"#g' $HOME_DIR/validator2/config/config.toml +sed -i -e 's#":8080"#":'"$ROSETTA_2"'"#g' $HOME_DIR/validator2/config/app.toml + + +Start each validator with different ports +screen -L -dmS node1 $BINARY start --rpc.unsafe --rpc.laddr tcp://0.0.0.0:26657 --p2p.laddr tcp://0.0.0.0:26656 --home=$HOME_DIR/validator1 --log_level info --trace +NodeID=$($BINARY comet show-node-id --home=$HOME_DIR/validator1) +echo "Node ID: $NodeID" +bin/picad start --home=$HOME_DIR/validator2 --p2p.persistent_peers=$NodeID@127.0.0.1:26656 \ No newline at end of file From 5a62bd9f3d13caeb106be12d588ec85c4a5a2934 Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Wed, 12 Jun 2024 12:18:39 +0700 Subject: [PATCH 2/4] feat: add script --- cmd/picad/cmd/root.go | 3 +++ scripts/run-node-two-validator.sh | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/picad/cmd/root.go b/cmd/picad/cmd/root.go index c1a2378a..e2078a7e 100644 --- a/cmd/picad/cmd/root.go +++ b/cmd/picad/cmd/root.go @@ -2,6 +2,7 @@ package cmd import ( "errors" + "fmt" "io" "os" @@ -96,6 +97,8 @@ func NewRootCmd() (*cobra.Command, app.EncodingConfig) { return err } + fmt.Println("hoank123", initClientCtx.Offline) + // This needs to go after ReadFromClientConfig, as that function // sets the RPC client needed for SIGN_MODE_TEXTUAL. This sign mode // is only available if the client is online. diff --git a/scripts/run-node-two-validator.sh b/scripts/run-node-two-validator.sh index 79a09e1b..6aebcdbc 100755 --- a/scripts/run-node-two-validator.sh +++ b/scripts/run-node-two-validator.sh @@ -56,7 +56,7 @@ $BINARY add-genesis-account $KEY1 100000000000000000000000000ppica --keyring-bac # Sign genesis transaction $BINARY gentx $KEY 10030009994127689ppica --keyring-backend $KEYRING --chain-id $CHAINID --home $HOME_DIR --moniker val1 mv $HOME_DIR/config/priv_validator_key.json $HOME_DIR/config/priv_validator_key0.json -$BINARY gentx $KEY1 100000ppica --keyring-backend $KEYRING --chain-id $CHAINID --home $HOME_DIR --output-document $HOME_DIR/config/gentx/1.json +$BINARY gentx $KEY1 1003000999412768ppica --keyring-backend $KEYRING --chain-id $CHAINID --home $HOME_DIR --output-document $HOME_DIR/config/gentx/1.json mv $HOME_DIR/config/priv_validator_key.json $HOME_DIR/config/priv_validator_key1.json update_test_genesis '.app_state["gov"]["params"]["voting_period"]="20s"' update_test_genesis '.app_state["gov"]["params"]["expedited_voting_period"]="10s"' @@ -64,6 +64,7 @@ update_test_genesis '.app_state["stakingmiddleware"]["params"]["blocks_per_epoch update_test_genesis '.app_state["mint"]["params"]["mint_denom"]="'$DENOM'"' update_test_genesis '.app_state["gov"]["params"]["min_deposit"]=[{"denom":"'$DENOM'","amount": "1"}]' update_test_genesis '.app_state["crisis"]["constant_fee"]={"denom":"'$DENOM'","amount":"1000"}' +update_test_genesis '.app_state["slashing"]["params"]["signed_blocks_window"]="6"' # Collect genesis tx $BINARY collect-gentxs --home $HOME_DIR From 40d7b6e0be3848b6948a153da6a4f71625cc1fe4 Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Wed, 12 Jun 2024 16:44:14 +0700 Subject: [PATCH 3/4] feat: enable sign mode textual --- app/app.go | 18 +++++++++++++++++- cmd/picad/cmd/root.go | 16 +++++++--------- scripts/run-node-two-validator.sh | 4 +++- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/app/app.go b/app/app.go index f9e084cb..391747a8 100644 --- a/app/app.go +++ b/app/app.go @@ -2,6 +2,8 @@ package app import ( "fmt" + sigtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" + txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config" "io" "os" "path/filepath" @@ -330,6 +332,21 @@ func NewComposableApp( appOpts, ) + // optional: enable sign mode textual by overwriting the default tx config (after setting the bank keeper) + enabledSignModes := append(authtx.DefaultSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL) + txConfigOpts := authtx.ConfigOptions{ + EnabledSignModes: enabledSignModes, + TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper), + } + txConfig, err = authtx.NewTxConfigWithOptions( + appCodec, + txConfigOpts, + ) + if err != nil { + panic(err) + } + app.txConfig = txConfig + // custompfm.NewIBCMiddleware() // transferModule := transfer.NewAppModule(app.TransferKeeper) transferModule := customibctransfer.NewAppModule(appCodec, app.TransferKeeper, app.BankKeeper) @@ -446,7 +463,6 @@ func NewComposableApp( authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, - slashingtypes.ModuleName, vestingtypes.ModuleName, ibcexported.ModuleName, genutiltypes.ModuleName, diff --git a/cmd/picad/cmd/root.go b/cmd/picad/cmd/root.go index e2078a7e..2f2be086 100644 --- a/cmd/picad/cmd/root.go +++ b/cmd/picad/cmd/root.go @@ -2,10 +2,10 @@ package cmd import ( "errors" - "fmt" "io" "os" + cmtcfg "github.com/cometbft/cometbft/config" "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/tx" @@ -35,7 +35,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/crisis" "github.com/cosmos/cosmos-sdk/x/genutil" - tmcfg "github.com/cometbft/cometbft/config" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" @@ -97,8 +96,6 @@ func NewRootCmd() (*cobra.Command, app.EncodingConfig) { return err } - fmt.Println("hoank123", initClientCtx.Offline) - // This needs to go after ReadFromClientConfig, as that function // sets the RPC client needed for SIGN_MODE_TEXTUAL. This sign mode // is only available if the client is online. @@ -122,10 +119,9 @@ func NewRootCmd() (*cobra.Command, app.EncodingConfig) { return err } customAppTemplate, customAppConfig := initAppConfig() + customCMTConfig := initCometBFTConfig() - customTMConfig := initTendermintConfig() - - return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customTMConfig) + return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customCMTConfig) }, } @@ -143,8 +139,10 @@ func NewRootCmd() (*cobra.Command, app.EncodingConfig) { return rootCmd, encodingConfig } -func initTendermintConfig() *tmcfg.Config { - cfg := tmcfg.DefaultConfig() +// initCometBFTConfig helps to override default CometBFT Config values. +// return cmtcfg.DefaultConfig if no custom configuration is required for the application. +func initCometBFTConfig() *cmtcfg.Config { + cfg := cmtcfg.DefaultConfig() // these values put a higher strain on node memory // cfg.P2P.MaxNumInboundPeers = 100 diff --git a/scripts/run-node-two-validator.sh b/scripts/run-node-two-validator.sh index 6aebcdbc..5e5afaf8 100755 --- a/scripts/run-node-two-validator.sh +++ b/scripts/run-node-two-validator.sh @@ -64,7 +64,9 @@ update_test_genesis '.app_state["stakingmiddleware"]["params"]["blocks_per_epoch update_test_genesis '.app_state["mint"]["params"]["mint_denom"]="'$DENOM'"' update_test_genesis '.app_state["gov"]["params"]["min_deposit"]=[{"denom":"'$DENOM'","amount": "1"}]' update_test_genesis '.app_state["crisis"]["constant_fee"]={"denom":"'$DENOM'","amount":"1000"}' -update_test_genesis '.app_state["slashing"]["params"]["signed_blocks_window"]="6"' +update_test_genesis '.app_state["slashing"]["params"]["signed_blocks_window"]="4"' +update_test_genesis '.app_state["slashing"]["params"]["downtime_jail_duration"]="5s"' + # Collect genesis tx $BINARY collect-gentxs --home $HOME_DIR From ebc1657fe415c8636b9aa489f2adf39aed5d89d0 Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Wed, 12 Jun 2024 16:47:03 +0700 Subject: [PATCH 4/4] fix lint --- app/app.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/app.go b/app/app.go index 391747a8..a99fe948 100644 --- a/app/app.go +++ b/app/app.go @@ -2,12 +2,13 @@ package app import ( "fmt" - sigtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" - txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config" "io" "os" "path/filepath" + sigtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" + txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config" + "cosmossdk.io/client/v2/autocli" "cosmossdk.io/core/appmodule" @@ -333,9 +334,8 @@ func NewComposableApp( ) // optional: enable sign mode textual by overwriting the default tx config (after setting the bank keeper) - enabledSignModes := append(authtx.DefaultSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL) txConfigOpts := authtx.ConfigOptions{ - EnabledSignModes: enabledSignModes, + EnabledSignModes: append(authtx.DefaultSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL), TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper), } txConfig, err = authtx.NewTxConfigWithOptions(