From f50a42952737666d32cbdd09e743c7b4ca9b287d Mon Sep 17 00:00:00 2001 From: Solovyov1796 Date: Tue, 30 Jul 2024 10:30:56 +0800 Subject: [PATCH] merge testnet script --- .gitignore | 3 +++ README.md | 24 +++++++++--------------- go.mod | 1 + go.sum | 10 ++++++---- localtestnet.sh | 5 ++++- networks/devnet/deploy.sh | 13 ++++++++++--- networks/devnet/init-genesis.sh | 19 ++++++++++++------- networks/devnet/install.sh | 1 + networks/testnet/deploy.sh | 8 +++++++- networks/testnet/init-genesis.sh | 18 +++++++++++------- networks/testnet/install.sh | 1 + 11 files changed, 65 insertions(+), 38 deletions(-) diff --git a/.gitignore b/.gitignore index e855238c..db289286 100644 --- a/.gitignore +++ b/.gitignore @@ -41,6 +41,9 @@ build/bin build/darwin build/linux +# Ignore deploy outputs +networks/testnet + # Go workspace files go.work go.work.sum diff --git a/README.md b/README.md index 2cb5dc90..50c7b940 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,20 @@ + + +# 0G Chain
-[![version](https://img.shields.io/github/tag/kava-labs/kava.svg)](https://github.com/kava-labs/kava/releases/latest) -[![CircleCI](https://circleci.com/gh/Kava-Labs/kava/tree/master.svg?style=shield)](https://circleci.com/gh/Kava-Labs/kava/tree/master) -[![Go Report Card](https://goreportcard.com/badge/github.com/kava-labs/kava)](https://goreportcard.com/report/github.com/kava-labs/kava) -[![API Reference](https://godoc.org/github.com/Kava-Labs/kava?status.svg)](https://godoc.org/github.com/Kava-Labs/kava) -[![GitHub](https://img.shields.io/github/license/kava-labs/kava.svg)](https://github.com/Kava-Labs/kava/blob/master/LICENSE.md) -[![Twitter Follow](https://img.shields.io/twitter/follow/KAVA_CHAIN.svg?label=Follow&style=social)](https://twitter.com/KAVA_CHAIN) -[![Discord Chat](https://img.shields.io/discord/704389840614981673.svg)](https://discord.com/invite/kQzh3Uv) +### [Telegram](https://t.me/web3_0glabs) | [Discord](https://discord.com/invite/0glabs)
-
- -### [Telegram](https://t.me/kavalabs) | [Medium](https://medium.com/@kava_labs) | [Discord](https://discord.gg/JJYnuCx) - -
- -Reference implementation of Kava, a blockchain for cross-chain DeFi. Built using the [cosmos-sdk](https://github.com/cosmos/cosmos-sdk). +Reference implementation of 0G Chain, the first modular AI chain. Built using the [cosmos-sdk](https://github.com/cosmos/cosmos-sdk). + \ No newline at end of file diff --git a/go.mod b/go.mod index fc2f0f87..bc582870 100644 --- a/go.mod +++ b/go.mod @@ -235,6 +235,7 @@ require ( google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect gopkg.in/ini.v1 v1.67.0 // indirect + gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect gopkg.in/yaml.v3 v3.0.1 // indirect nhooyr.io/websocket v1.8.6 // indirect diff --git a/go.sum b/go.sum index 0d1038c5..18e87f59 100644 --- a/go.sum +++ b/go.sum @@ -221,10 +221,10 @@ git.sr.ht/~sircmpwn/getopt v0.0.0-20191230200459-23622cc906b3/go.mod h1:wMEGFFFN git.sr.ht/~sircmpwn/go-bare v0.0.0-20210406120253-ab86bc2846d9/go.mod h1:BVJwbDfVjCjoFiKrhkei6NdGcZYpkDkdyCdg1ukytRA= github.com/0glabs/cometbft v0.34.27-0glabs.0 h1:jErty8aVtp2RiU/59QTEhUCi3xCoc67NHHsmIqd7Xz4= github.com/0glabs/cometbft v0.34.27-0glabs.0/go.mod h1:BcCbhKv7ieM0KEddnYXvQZR+pZykTKReJJYf7YC7qhw= -github.com/0glabs/cosmos-sdk v0.46.11-0glabs.5 h1:/7zqU8Az6n3UpKnypKQ92Yw8AgrE1v1AfatrL8elajs= -github.com/0glabs/cosmos-sdk v0.46.11-0glabs.5/go.mod h1:jwgWoeAWxqMF5pZUZ4N+G4rD3q6oOLulq3/dGCFLEX4= -github.com/0glabs/ethermint v0.21.0-0g.v2.0.2 h1:mFVOMra9lmeNk+CgL0UsBxqiXHx5JWVeiURJFgQmHzY= -github.com/0glabs/ethermint v0.21.0-0g.v2.0.2/go.mod h1:KPLRino6lVDPV/cZCbQf7dZdR1nsVgptr0Htf6ZxZe8= +github.com/0glabs/cosmos-sdk v0.46.11-0glabs.8 h1:zYkr1AaeyxIxrGyt/B/Xc4l/xWsdk71yo1CniPmrvuo= +github.com/0glabs/cosmos-sdk v0.46.11-0glabs.8/go.mod h1:4uTpR8WwpNKawdsPj5uyUS8DvKilc2OyFKe4RBm4oso= +github.com/0glabs/ethermint v0.21.0-0g.v2.0.4 h1:UFQflLvLk7uvJcKLvpKY6U3n5WU3Osphrf9VUSPgfBY= +github.com/0glabs/ethermint v0.21.0-0g.v2.0.4/go.mod h1:o5lh9adPdMNNAweyDYleu3FRAJyRIy1drdMcSpo1qy8= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4= github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM= @@ -2042,6 +2042,8 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= +gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= diff --git a/localtestnet.sh b/localtestnet.sh index a5137590..2c1040f0 100755 --- a/localtestnet.sh +++ b/localtestnet.sh @@ -66,9 +66,12 @@ userKeyName="user" printf "$userMnemonic\n" | $BINARY keys add $userKeyName --eth --recover $BINARY add-genesis-account $userKeyName 1000000000000000000000ua0gi +VESTING_ACCOUNT_START_TIME=$(date -u +%s) +VESTING_ACCOUNT_END_TIME=$((VESTING_ACCOUNT_START_TIME + 30 * 60)) + vestingKeyName="vesting" printf "$vestingMnemonic\n" | $BINARY keys add $vestingKeyName --eth --recover -$BINARY add-genesis-account $vestingKeyName 1000000000000000000000ua0gi --vesting-amount 1000000000000000000000ua0gi --vesting-start-time 1717200000 --vesting-end-time 1719791999 +$BINARY add-genesis-account $vestingKeyName 1000000000000000000000ua0gi --vesting-amount 1000000000000000000000ua0gi --vesting-start-time $VESTING_ACCOUNT_START_TIME --vesting-end-time $VESTING_ACCOUNT_END_TIME storageContractAcc="0g1vsjpjgw8p5f4x0nwp8ernl9lkszewcqqss7r5d" $BINARY add-genesis-account $storageContractAcc 1000000000000000000000ua0gi diff --git a/networks/devnet/deploy.sh b/networks/devnet/deploy.sh index fce079e1..13507374 100755 --- a/networks/devnet/deploy.sh +++ b/networks/devnet/deploy.sh @@ -7,6 +7,7 @@ function help() { echo " -k Keyring password to create key (for Linux only)" echo " -n Network (default: devnet)" echo " -c Chain ID (default: \"zgtendermint_16600-1\")" + echo " -v schedule end time (unix epoch) for vesting accounts" echo "" } @@ -22,7 +23,9 @@ shift PEM_FLAG="" KEYRING_PASSWORD="" NETWORK="devnet" +TAG_OR_BRANCH="dev" INIT_GENESIS_ENV="" +VESTING_ACCOUNT_END_TIME=0 while [[ $# -gt 0 ]]; do case $1 in @@ -43,6 +46,10 @@ while [[ $# -gt 0 ]]; do INIT_GENESIS_ENV="$INIT_GENESIS_ENV export CHAIN_ID=$2;" shift; shift ;; + -v) + INIT_GENESIS_ENV="$INIT_GENESIS_ENV export VESTING_ACCOUNT_END_TIME=$2;" + shift; shift + ;; *) help echo "Unknown flag passed: \"$1\"" @@ -56,11 +63,11 @@ NUM_NODES=${#IPS[@]} # Install dependent libraries and binary for ((i=0; i<$NUM_NODES; i++)) do - ssh $PEM_FLAG ubuntu@${IPS[$i]} "rm -rf 0g-chain; git clone https://github.com/0glabs/0g-chain.git; cd 0g-chain; git checkout patch_testnet_1; ./networks/devnet/install.sh" + ssh $PEM_FLAG ubuntu@${IPS[$i]} "rm -rf 0g-chain; git clone https://github.com/0glabs/0g-chain.git; cd 0g-chain; git checkout $TAG_OR_BRANCH; ./networks/$NETWORK/install.sh" done # Create genesis config on node0 -ssh $PEM_FLAG ubuntu@${IPS[0]} "cd 0g-chain/networks/devnet; $INIT_GENESIS_ENV ./init-genesis.sh $IP_LIST $KEYRING_PASSWORD; tar czf ~/$NETWORK.tar.gz $NETWORK; rm -rf $NETWORK" +ssh $PEM_FLAG ubuntu@${IPS[0]} "cd 0g-chain/networks/$NETWORK; $INIT_GENESIS_ENV ./init-genesis.sh $IP_LIST $KEYRING_PASSWORD; tar czf ~/$NETWORK.tar.gz $NETWORK; rm -rf $NETWORK" scp $PEM_FLAG ubuntu@${IPS[0]}:$NETWORK.tar.gz . ssh $PEM_FLAG ubuntu@${IPS[0]} "rm $NETWORK.tar.gz" @@ -71,7 +78,7 @@ cd $NETWORK for ((i=0; i<$NUM_NODES; i++)) do tar czf node$i.tar.gz node$i scp $PEM_FLAG node$i.tar.gz ubuntu@${IPS[$i]}:~ - ssh $PEM_FLAG ubuntu@${IPS[$i]} "rm -rf 0gchaind-prod; tar xzf node$i.tar.gz; rm node$i.tar.gz; mv node$i 0gchaind-prod" + ssh $PEM_FLAG ubuntu@${IPS[$i]} "rm -rf 0gchaind-$NETWORK; tar xzf node$i.tar.gz; rm node$i.tar.gz; mv node$i 0gchaind-$NETWORK" rm node$i.tar.gz done diff --git a/networks/devnet/init-genesis.sh b/networks/devnet/init-genesis.sh index 66016681..760acbe3 100755 --- a/networks/devnet/init-genesis.sh +++ b/networks/devnet/init-genesis.sh @@ -33,9 +33,12 @@ set -e IFS=","; declare -a IPS=($1); unset IFS NUM_NODES=${#IPS[@]} -VLIDATOR_BALANCE=15000000000000000000ua0gi -FAUCET_BALANCE=40000000000000000000ua0gi -STAKING=10000000000000000000ua0gi +VALIDATOR_BALANCE=25000000000000ua0gi +FAUCET_BALANCE=500000000000000ua0gi +STAKING=5000000000000ua0gi +VESTING_BALANCE=400000000000000ua0gi + +VESTING_ACCOUNT_START_TIME=$(date -u +%s) # Init configs for ((i=0; i<$NUM_NODES; i++)) do @@ -77,6 +80,7 @@ for ((i=0; i<$NUM_NODES; i++)) do cat "$GENESIS" | jq '.app_state["slashing"]["params"]["signed_blocks_window"]="1000"' >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" cat "$GENESIS" | jq '.app_state["consensus_params"]["block"]["time_iota_ms"]="3000"' >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" + cat "$GENESIS" | jq '.app_state.gov.voting_params.voting_period = "300s"' >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" # Change app.toml APP_TOML="$HOMEDIR"/config/app.toml @@ -85,7 +89,7 @@ for ((i=0; i<$NUM_NODES; i++)) do sed -i '/\[json-rpc\]/,/^\[/ s/address = "127.0.0.1:8545"/address = "0.0.0.0:8545"/' "$APP_TOML" # Set evm tracer to json - sed -in-place='' 's/tracer = ""/tracer = "json"/g' "$APP_TOML" + # sed -in-place='' 's/tracer = ""/tracer = "json"/g' "$APP_TOML" # Enable full error trace to be returned on tx failure sed -in-place='' '/iavl-cache-size/a\ @@ -146,12 +150,13 @@ fi for ((i=0; i<$NUM_NODES; i++)) do for ((j=0; j<$NUM_NODES; j++)) do if [[ "$OS_NAME" = "GNU/Linux" ]]; then - yes $PASSWORD | 0gchaind add-genesis-account "0gchain_validator_$j" $VLIDATOR_BALANCE --home "$ROOT_DIR/node$i" + yes $PASSWORD | 0gchaind add-genesis-account "0gchain_validator_$j" $VALIDATOR_BALANCE --home "$ROOT_DIR/node$i" else - 0gchaind add-genesis-account "0gchain_validator_$j" $VLIDATOR_BALANCE --home "$ROOT_DIR/node$i" + 0gchaind add-genesis-account "0gchain_validator_$j" $VALIDATOR_BALANCE --home "$ROOT_DIR/node$i" fi done - 0gchaind add-genesis-account 0g17n8707c20e8gge2tk2gestetjcs4536p4fhqcs $FAUCET_BALANCE --home "$ROOT_DIR/node$i" + 0gchaind add-genesis-account 0g1zyvrkyr8pmczkguxztxpp3qcd0uhkt0tfxjupt $FAUCET_BALANCE --home "$ROOT_DIR/node$i" + 0gchaind add-genesis-account 0g1jwuhghh6qrln4tthhqrdt3qrmjn9zm05xns46u $VESTING_BALANCE --vesting-amount $VESTING_BALANCE --vesting-start-time $VESTING_ACCOUNT_START_TIME --vesting-end-time $VESTING_ACCOUNT_END_TIME --home "$ROOT_DIR/node$i" done # Prepare genesis txs diff --git a/networks/devnet/install.sh b/networks/devnet/install.sh index 52f288c3..2211e8b5 100755 --- a/networks/devnet/install.sh +++ b/networks/devnet/install.sh @@ -13,6 +13,7 @@ if [[ $? -ne 0 ]]; then # Make under root dir SCRIPT_DIR=`dirname "${BASH_SOURCE[0]}"` cd $SCRIPT_DIR/../.. + rm -rf $(go env GOPATH)/bin/0gchaind make install # Add gopath to path diff --git a/networks/testnet/deploy.sh b/networks/testnet/deploy.sh index a2723591..33745a39 100755 --- a/networks/testnet/deploy.sh +++ b/networks/testnet/deploy.sh @@ -7,6 +7,7 @@ function help() { echo " -k Keyring password to create key (for Linux only)" echo " -n Network (default: testnet)" echo " -c Chain ID (default: \"zgtendermint_16600-1\")" + echo " -v schedule end time (unix epoch) for vesting accounts" echo "" } @@ -23,6 +24,7 @@ PEM_FLAG="" KEYRING_PASSWORD="" NETWORK="testnet" INIT_GENESIS_ENV="" +VESTING_ACCOUNT_END_TIME=0 while [[ $# -gt 0 ]]; do case $1 in @@ -43,6 +45,10 @@ while [[ $# -gt 0 ]]; do INIT_GENESIS_ENV="$INIT_GENESIS_ENV export CHAIN_ID=$2;" shift; shift ;; + -v) + INIT_GENESIS_ENV="$INIT_GENESIS_ENV export VESTING_ACCOUNT_END_TIME=$2;" + shift; shift + ;; *) help echo "Unknown flag passed: \"$1\"" @@ -56,7 +62,7 @@ NUM_NODES=${#IPS[@]} # Install dependent libraries and binary for ((i=0; i<$NUM_NODES; i++)) do - ssh $PEM_FLAG ubuntu@${IPS[$i]} "rm -rf 0g-chain; git clone https://github.com/0glabs/0g-chain.git; cd 0g-chain; git checkout v0.1.0; ./networks/testnet/install.sh" + ssh $PEM_FLAG ubuntu@${IPS[$i]} "rm -rf 0g-chain; git clone https://github.com/0glabs/0g-chain.git; cd 0g-chain; git checkout v0.2.3; ./networks/testnet/install.sh" done # Create genesis config on node0 diff --git a/networks/testnet/init-genesis.sh b/networks/testnet/init-genesis.sh index 67a624e7..6c72fa77 100755 --- a/networks/testnet/init-genesis.sh +++ b/networks/testnet/init-genesis.sh @@ -33,9 +33,12 @@ set -e IFS=","; declare -a IPS=($1); unset IFS NUM_NODES=${#IPS[@]} -VLIDATOR_BALANCE=15000000000000000000ua0gi -FAUCET_BALANCE=40000000000000000000ua0gi -STAKING=10000000000000000000ua0gi +VALIDATOR_BALANCE=25000000000000ua0gi +FAUCET_BALANCE=500000000000000ua0gi +STAKING=5000000000000ua0gi +VESTING_BALANCE=400000000000000ua0gi + +VESTING_ACCOUNT_START_TIME=$(date -u +%s) # Init configs for ((i=0; i<$NUM_NODES; i++)) do @@ -85,7 +88,7 @@ for ((i=0; i<$NUM_NODES; i++)) do sed -i '/\[json-rpc\]/,/^\[/ s/address = "127.0.0.1:8545"/address = "0.0.0.0:8545"/' "$APP_TOML" # Set evm tracer to json - sed -in-place='' 's/tracer = ""/tracer = "json"/g' "$APP_TOML" + # sed -in-place='' 's/tracer = ""/tracer = "json"/g' "$APP_TOML" # Enable full error trace to be returned on tx failure sed -in-place='' '/iavl-cache-size/a\ @@ -146,12 +149,13 @@ fi for ((i=0; i<$NUM_NODES; i++)) do for ((j=0; j<$NUM_NODES; j++)) do if [[ "$OS_NAME" = "GNU/Linux" ]]; then - yes $PASSWORD | 0gchaind add-genesis-account "0gchain_validator_$j" $VLIDATOR_BALANCE --home "$ROOT_DIR/node$i" + yes $PASSWORD | 0gchaind add-genesis-account "0gchain_validator_$j" $VALIDATOR_BALANCE --home "$ROOT_DIR/node$i" else - 0gchaind add-genesis-account "0gchain_validator_$j" $VLIDATOR_BALANCE --home "$ROOT_DIR/node$i" + 0gchaind add-genesis-account "0gchain_validator_$j" $VALIDATOR_BALANCE --home "$ROOT_DIR/node$i" fi done - 0gchaind add-genesis-account 0g17n8707c20e8gge2tk2gestetjcs4536p4fhqcs $FAUCET_BALANCE --home "$ROOT_DIR/node$i" + 0gchaind add-genesis-account 0g1e4t48fq42tqxpapvpnuc9n9k998eex9rnyqzwm $FAUCET_BALANCE --home "$ROOT_DIR/node$i" + 0gchaind add-genesis-account 0g16yvxafe63uzuxu6xpvpxdz9agdvnh0zn8vnuj6 $VESTING_BALANCE --vesting-amount $VESTING_BALANCE --vesting-start-time $VESTING_ACCOUNT_START_TIME --vesting-end-time $VESTING_ACCOUNT_END_TIME --home "$ROOT_DIR/node$i" done # Prepare genesis txs diff --git a/networks/testnet/install.sh b/networks/testnet/install.sh index 52f288c3..2211e8b5 100755 --- a/networks/testnet/install.sh +++ b/networks/testnet/install.sh @@ -13,6 +13,7 @@ if [[ $? -ne 0 ]]; then # Make under root dir SCRIPT_DIR=`dirname "${BASH_SOURCE[0]}"` cd $SCRIPT_DIR/../.. + rm -rf $(go env GOPATH)/bin/0gchaind make install # Add gopath to path