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

deployment: add scripts to set up full nodes using state sync #25

Merged
merged 1 commit into from
Jan 10, 2023
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
17 changes: 16 additions & 1 deletion deployment/localup/.env
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
## BASIC CONFIG
CHAIN_ID=inscription_9000-121
STAKING_BOND_DENOM=bnb
BASIC_DENOM=gweibnb
STAKING_BOND_AMOUNT=10000000000
SNAPSHOT_INTERVAL=10
SNAPSHOT_KEEP_RECENT=0
KPASS=12345678
GENESIS_ACCOUNT_BALANCE=100000000000
COMMISSION_MAX_CHANGE_RATE=0.01
COMMISSION_MAX_RATE=1.0
COMMISSION_RATE=0.07
NATIVE_COIN_DESC='{"description":"The native staking token of the Inscription.","denom_units":[{"denom":"weibnb","exponent":0,"aliases":["ether"]},{"denom":"gweibnb","exponent":9,"aliases":["gwei"]},{"denom":"bnb","exponent":18 }],"base":"wei","display":"bnb"}'
NATIVE_COIN_DESC='{"description":"The native staking token of the Inscription.","denom_units":[{"denom":"weibnb","exponent":0,"aliases":["ether"]},{"denom":"gweibnb","exponent":9,"aliases":["gwei"]},{"denom":"bnb","exponent":18 }],"base":"wei","display":"bnb"}'

## ENDPOINT
VALIDATOR_ADDRESS_PORT_START=28750
VALIDATOR_P2P_PORT_START=27750
VALIDATOR_GRPC_PORT_START=9090
VALIDATOR_GRPC_WEB_PORT_START=9190
VALIDATOR_RPC_PORT_START=26750
DATASEED_ADDRESS_PORT_START=28850
DATASEED_P2P_PORT_START=27850
DATASEED_GRPC_PORT_START=9890
DATASEED_GRPC_WEB_PORT_START=9990
DATASEED_RPC_PORT_START=26850
39 changes: 15 additions & 24 deletions deployment/localup/localup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,10 @@
basedir=$(cd `dirname $0`; pwd)
workspace=${basedir}
source ${workspace}/.env
source ${workspace}/utils.sh

bin_name=bfsd
bin=${workspace}/../../build/bin/${bin_name}
address_port_start=28750
p2p_port_start=27750
grpc_port_start=9090
grpc_web_port_start=9190
rpc_port_start=26750


function joinByString() {
local separator="$1"
shift
local first="$1"
shift
printf "%s" "$first" "${@/#/$separator}"
}

function init() {
size=$1
Expand Down Expand Up @@ -80,7 +68,7 @@ function generate_genesis() {
--commission-rate=${COMMISSION_RATE} \
--details="validator${i}" \
--website="http://website" \
--node tcp://localhost:$((${p2p_port_start}+${i})) \
--node tcp://localhost:$((${VALIDATOR_P2P_PORT_START}+${i})) \
--node-id "validator${i}" \
--ip 127.0.0.1
cp ${workspace}/.local/validator${i}/config/gentx/gentx-validator${i}.json ${workspace}/.local/gentx/
Expand All @@ -91,7 +79,7 @@ function generate_genesis() {
for ((i=0;i<${size};i++));do
cp ${workspace}/.local/gentx/* ${workspace}/.local/validator${i}/config/gentx/
${bin} collect-gentxs --home ${workspace}/.local/validator${i}
node_ids="$(${bin} tendermint show-node-id --home ${workspace}/.local/validator${i})@127.0.0.1:$((${p2p_port_start}+${i})) ${node_ids}"
node_ids="$(${bin} tendermint show-node-id --home ${workspace}/.local/validator${i})@127.0.0.1:$((${VALIDATOR_P2P_PORT_START}+${i})) ${node_ids}"
done

persistent_peers=$(joinByString ',' ${node_ids})
Expand All @@ -104,6 +92,8 @@ function generate_genesis() {
sed -i -e "s/persistent_peers = \".*\"/persistent_peers = \"${persistent_peers}\"/g" ${workspace}/.local/validator${i}/config/config.toml
sed -i -e "s/addr_book_strict = true/addr_book_strict = false/g" ${workspace}/.local/validator${i}/config/config.toml
sed -i -e "s/allow_duplicate_ip = false/allow_duplicate_ip = true/g" ${workspace}/.local/validator${i}/config/config.toml
sed -i -e "s/snapshot-interval = 0/snapshot-interval = ${SNAPSHOT_INTERVAL}/g" ${workspace}/.local/validator${i}/config/app.toml
sed -i -e "s/snapshot-keep-recent = 2/snapshot-keep-recent = ${SNAPSHOT_KEEP_RECENT}/g" ${workspace}/.local/validator${i}/config/app.toml

done
}
Expand All @@ -113,21 +103,20 @@ function start() {
for ((i=0;i<${size};i++));do
mkdir -p ${workspace}/.local/validator${i}/logs
nohup ${bin} start --home ${workspace}/.local/validator${i} \
--address 0.0.0.0:$((${address_port_start}+${i})) \
--grpc-web.address 0.0.0.0:$((${grpc_web_port_start}+${i})) \
--grpc.address 0.0.0.0:$((${grpc_port_start}+${i})) \
--p2p.laddr tcp://0.0.0.0:$((${p2p_port_start}+${i})) \
--p2p.external-address 127.0.0.1:$((${p2p_port_start}+${i})) \
--rpc.laddr tcp://0.0.0.0:$((${rpc_port_start}+${i})) \
--address 0.0.0.0:$((${VALIDATOR_ADDRESS_PORT_START}+${i})) \
--grpc-web.address 0.0.0.0:$((${VALIDATOR_GRPC_WEB_PORT_START}+${i})) \
--grpc.address 0.0.0.0:$((${VALIDATOR_GRPC_PORT_START}+${i})) \
--p2p.laddr tcp://0.0.0.0:$((${VALIDATOR_P2P_PORT_START}+${i})) \
--p2p.external-address 127.0.0.1:$((${VALIDATOR_P2P_PORT_START}+${i})) \
--rpc.laddr tcp://0.0.0.0:$((${VALIDATOR_RPC_PORT_START}+${i})) \
--log_format json > ${workspace}/.local/validator${i}/logs/node.log &
done
}

function stop() {
killall ${bin_name}
ps -ef | grep ${bin_name} | grep validator | awk '{print $2}' | xargs kill
}


CMD=$1
SIZE=3
if [ ! -z $2 ] && [ "$2" -gt "0" ]; then
Expand Down Expand Up @@ -156,6 +145,8 @@ stop)
echo "===== end ===="
;;
all)
echo "===== stop ===="
stop
echo "===== init ===="
init $SIZE
echo "===== generate genesis ===="
Expand Down
96 changes: 96 additions & 0 deletions deployment/localup/localup_fullnode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/env bash
basedir=$(cd `dirname $0`; pwd)
workspace=${basedir}
source ${workspace}/.env
source ${workspace}/utils.sh

bin_name=bfsd
bin=${workspace}/../../build/bin/${bin_name}

function init_fullnode() {
size=$1
rm -rf ${workspace}/.local/dataseed*

trust_height=$(curl -s http://localhost:${VALIDATOR_RPC_PORT_START}/block | jq -r '.result.block.header.height')
trust_hash=$(curl -s http://localhost:${VALIDATOR_RPC_PORT_START}/block | jq -r '.result.block_id.hash')
tmp=""
n=0
for v in ${workspace}/.local/validator*;do
tmp="$tmp localhost:$((${VALIDATOR_RPC_PORT_START}+${n}))"
((n++))
done
rpc_servers=$(joinByString ',' ${tmp})

for ((i=0;i<${size};i++));do
# init chain
${bin} init dataseed${i} --chain-id ${CHAIN_ID} --staking-bond-denom ${STAKING_BOND_DENOM} --home ${workspace}/.local/dataseed${i}
# remove unused files
rm -rf ${workspace}/.local/dataseed${i}/priv_validator_key.json
# copy configs from validator
cp ${workspace}/.local/validator0/config/genesis.json ${workspace}/.local/dataseed${i}/config/genesis.json
cp ${workspace}/.local/validator0/config/app.toml ${workspace}/.local/dataseed${i}/config/app.toml
cp ${workspace}/.local/validator0/config/client.toml ${workspace}/.local/dataseed${i}/config/client.toml
cp ${workspace}/.local/validator0/config/config.toml ${workspace}/.local/dataseed${i}/config/config.toml

# set state sync info
sed -i 'N;s/\# starting from the height of the snapshot\.\nenable = false/\# starting from the height of the snapshot\.\nenable = true/Mg'sed -i -e 'N;s/\# starting from the height of the snapshot\.\nenable = false/\# starting from the height of the snapshot\.\nenable = true/g' ${workspace}/.local/dataseed${i}/config/config.toml
sed -i -e "s/trust_height = 0/trust_height = ${trust_height}/g" ${workspace}/.local/dataseed${i}/config/config.toml
sed -i -e "s/trust_hash = \"\"/trust_hash = \"${trust_hash}\"/g" ${workspace}/.local/dataseed${i}/config/config.toml
sed -i -e "s/rpc_servers = \"\"/rpc_servers = \"${rpc_servers}\"/g" ${workspace}/.local/dataseed${i}/config/config.toml
done
}

function start_fullnode() {
size=$1
for ((i=0;i<${size};i++));do
mkdir -p ${workspace}/.local/dataseed${i}/logs
nohup ${bin} start --home ${workspace}/.local/dataseed${i} \
--address 0.0.0.0:$((${DATASEED_ADDRESS_PORT_START}+${i})) \
--grpc-web.address 0.0.0.0:$((${DATASEED_GRPC_WEB_PORT_START}+${i})) \
--grpc.address 0.0.0.0:$((${DATASEED_GRPC_PORT_START}+${i})) \
--p2p.laddr tcp://0.0.0.0:$((${DATASEED_P2P_PORT_START}+${i})) \
--p2p.external-address 127.0.0.1:$((${DATASEED_P2P_PORT_START}+${i})) \
--rpc.laddr tcp://0.0.0.0:$((${DATASEED_RPC_PORT_START}+${i})) \
--log_format json > ${workspace}/.local/dataseed${i}/logs/node.log &
done
}

function stop_fullnode() {
ps -ef | grep ${bin_name} | grep dataseed | awk '{print $2}' | xargs kill
}

CMD=$1
SIZE=3
if [ ! -z $2 ] && [ "$2" -gt "0" ]; then
SIZE=$2
fi

case ${CMD} in
init)
echo "===== init ===="
init_fullnode $SIZE
echo "===== end ===="
;;
start)
echo "===== start ===="
start_fullnode $SIZE
echo "===== end ===="
;;
stop)
echo "===== stop ===="
stop_fullnode
echo "===== end ===="
;;
all)
echo "===== stop ===="
stop_fullnode
echo "===== init ===="
init_fullnode $SIZE
echo "===== start ===="
start_fullnode $SIZE
echo "===== end ===="
;;
*)
echo "Usage: localup_fullnode.sh all | init | start | stop"
;;
esac
9 changes: 9 additions & 0 deletions deployment/localup/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

function joinByString() {
local separator="$1"
shift
local first="$1"
shift
printf "%s" "$first" "${@/#/$separator}"
}
18 changes: 18 additions & 0 deletions deployment/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,21 @@ bash ./deployment/localup/localup.sh stop
bash ./deployment/localup/localup.sh stop
bash ./deployment/localup/localup.sh start ${SIZE}
```

## Quickly Setup Fullnode
1. Start
```bash
SIZE=3 # The number of nodes in the cluster.
bash ./deployment/localup/localup_fullnode.sh all ${SIZE}
```

2. Stop
```bash
bash ./deployment/localup/localup_fullnode.sh stop
```

3. Restart the fullnodes without initialization
```bash
bash ./deployment/localup/localup_fullnode.sh stop
bash ./deployment/localup/localup_fullnode.sh start ${SIZE}
```