Skip to content

Commit

Permalink
add deploy scripts for sp
Browse files Browse the repository at this point in the history
  • Loading branch information
jingjunLi committed Feb 15, 2023
1 parent f57771c commit afeb60c
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 10 deletions.
3 changes: 3 additions & 0 deletions deployment/localup/.env
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ MIN_DEPOSIT_AMOUNT=100
SRC_CHAIN_ID=18
DEST_CHAIN_ID=714

## Proposal
PROPOSAL_ID_START=1

## ENDPOINT
VALIDATOR_ADDRESS_PORT_START=28750
VALIDATOR_P2P_PORT_START=27750
Expand Down
150 changes: 140 additions & 10 deletions deployment/localup/localup.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ source ${workspace}/utils.sh
bin_name=gnfd
bin=${workspace}/../../build/bin/${bin_name}

function build() {
make proto-gen && make build
}

function init() {
size=$1
rm -rf ${workspace}/.local
Expand Down Expand Up @@ -116,11 +120,11 @@ function generate_genesis() {
sed -i -e "s/\"stake\"/\"${BASIC_DENOM}\"/g" ${workspace}/.local/validator${i}/config/genesis.json
sed -i -e "s/\"denom_metadata\": \[\]/\"denom_metadata\": \[${NATIVE_COIN_DESC}\]/g" ${workspace}/.local/validator${i}/config/genesis.json
sed -i -e "s/persistent_peers = \".*\"/persistent_peers = \"${persistent_peers}\"/g" ${workspace}/.local/validator${i}/config/config.toml
sed -i -e "s/src-chain-id = 1/src-chain-id = ${SRC_CHAIN_ID}/g" ${workspace}/.local/validator${i}/config/app.toml
sed -i -e "s/dest-chain-id = 2/dest-chain-id = ${DEST_CHAIN_ID}/g" ${workspace}/.local/validator${i}/config/app.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/src-chain-id = 1/src-chain-id = ${SRC_CHAIN_ID}/g" ${workspace}/.local/validator${i}/config/app.toml
sed -i -e "s/dest-chain-id = 2/dest-chain-id = ${DEST_CHAIN_ID}/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
sed -i -e "s/\"reserve_time\": \"15552000\"/\"reserve_time\": \"600\"/g" ${workspace}/.local/validator${i}/config/genesis.json
sed -i -e "s/\"forced_settle_time\": \"86400\"/\"forced_settle_time\": \"100\"/g" ${workspace}/.local/validator${i}/config/genesis.json
Expand Down Expand Up @@ -150,11 +154,124 @@ function stop() {
ps -ef | grep ${bin_name} | grep validator | awk '{print $2}' | xargs kill
}

function validator_deploy() {
validator_size=$1
sp_size=1
if [ $# -eq 2 ]; then
sp_size=$2
fi
echo "===== init ===="
init "$validator_size" "$sp_size"
echo "===== generate genesis ===="
generate_genesis "$validator_size" "$sp_size"
echo "===== start ===="
start "$validator_size"
echo "===== end ===="
}

function sp_deploy_start() {
sp_size=1
if [ $# -eq 1 ]; then
sp_size=$1
fi

sleep 5

# Get the key list (genesis account generated by localup.sh )
for ((i = 0; i < ${sp_size}; i++)); do
${bin} keys list --keyring-backend test --home ${workspace}/.local/sp${i}
done

# Authorize the Gov Module Account to debit the Funding account of SP
for ((i = 0; i < ${sp_size}; i++)); do
# get sp address
sp_addrs=("$(${bin} keys show sp${i} -a --keyring-backend test --home ${workspace}/.local/sp${i})")
echo " ===="
echo ${sp_addrs}
sleep 6
${bin} tx sp grant 0x7b5Fe22B5446f7C62Ea27B8BD71CeF94e03f3dF2 \
--spend-limit 1000000bnb \
--SPAddress "${sp_addrs}" \
--from sp${i}_fund \
--home "${workspace}/.local/sp${i}" \
--keyring-backend test \
--node http://localhost:26750 \
--trace \
--log_level trace \
--yes
done

# submit proposal for each sp
for ((i = 0; i < ${sp_size}; i++)); do
cp ${workspace}/create_sp.json ${workspace}/create_sp${i}.json
#create sp and sp fund account
sp_addrs=("$(${bin} keys show sp${i} -a --keyring-backend test --home ${workspace}/.local/sp${i})")
spfund_addrs=("$(${bin} keys show sp${i}_fund -a --keyring-backend test --home ${workspace}/.local/sp${i})")

sed -i -e "s/\"moniker\": \".*\"/\"moniker\":\"sp${i}\"/g" ${workspace}/create_sp${i}.json
sed -i -e "s/\"sp_address\":\".*\"/\"sp_address\":\"${sp_addrs}\"/g" ${workspace}/create_sp${i}.json
sed -i -e "s/\"funding_address\":\".*\"/\"funding_address\":\"${spfund_addrs}\"/g" ${workspace}/create_sp${i}.json
sed -i -e "s/\"endpoint\": \".*\"/\"endpoint\":\"sp${i}.greenfield.io\"/g" ${workspace}/create_sp${i}.json

sleep 6
# submit-proposal
${bin} tx gov submit-proposal ${workspace}/create_sp${i}.json \
--from sp${i} \
--keyring-backend test \
--home ${workspace}/.local/sp${i} \
--node http://localhost:26750 \
--yes

sleep 6
# deposit the proposal
${bin} tx gov deposit $((${PROPOSAL_ID_START} + ${i})) 10000bnb \
--from sp${i} \
--keyring-backend test \
--home ${workspace}/.local/sp${i} \
--node http://localhost:26750 \
--yes

sleep 6
${bin} tx gov vote $((${PROPOSAL_ID_START} + ${i})) yes \
--from validator0 \
--keyring-backend test \
--home ${workspace}/.local/validator0 \
--node http://localhost:26750 \
--yes
sleep 1
done
}

function sp_deploy_check() {
sp_size=1
if [ $# -eq 1 ]; then
sp_size=$1
fi

n=0
while [ $n -le 360 ]; do
approval_cnt=("$(${bin} query sp storage-providers --node http://localhost:26750 | grep approval_address | wc -l)")
((n++))
sleep 1
if [ $approval_cnt -eq $sp_size ]; then
echo "sp deploy done"
return
fi
echo "sp deploy check finish $n times"

done
echo "sp deploy may failed please check"
}

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

case ${CMD} in
init)
Expand All @@ -177,18 +294,31 @@ stop)
stop
echo "===== end ===="
;;
build)
echo "===== build ===="
build
echo "===== end ===="
;;
deploy_sp)
echo "===== deploy_sp ===="
stop
validator_deploy $SIZE $SP_SIZE
sp_deploy_start $SP_SIZE
sp_deploy_check $SP_SIZE
echo "===== end ===="
;;
sp_deploy_check)
echo "===== sp_deploy_check ===="
sp_deploy_check $SP_SIZE
echo "===== end ===="
;;

all)
echo "===== stop ===="
stop
echo "===== init ===="
init $SIZE
echo "===== generate genesis ===="
generate_genesis $SIZE
echo "===== start ===="
start $SIZE
echo "===== end ===="
validator_deploy $SIZE $SP_SIZE
;;
*)
echo "Usage: localup.sh all | init | generate | start | stop"
echo "Usage: localup.sh all | init | generate | start | stop | build | deploy_sp | sp_deploy_check"
;;
esac

0 comments on commit afeb60c

Please sign in to comment.