diff --git a/e2e/chains/bsc/Makefile b/e2e/chains/bsc/Makefile index a3085f6a..92565ea8 100644 --- a/e2e/chains/bsc/Makefile +++ b/e2e/chains/bsc/Makefile @@ -10,6 +10,7 @@ bootstrap: .PHONY:network network: + docker compose -f docker-compose.simple.yml up -d autoheal docker compose -f docker-compose.simple.yml up -d bsc-rpc bsc-validator1-1 bsc-validator1-2 bsc-validator1-3 bsc-validator1-4 bsc-validator1-5 docker compose -f docker-compose.simple.yml up -d bsc-rpc2 bsc-validator2-1 bsc-validator2-2 bsc-validator2-3 diff --git a/e2e/chains/bsc/docker-compose.simple.yml b/e2e/chains/bsc/docker-compose.simple.yml index 649dd689..84e8a9ff 100644 --- a/e2e/chains/bsc/docker-compose.simple.yml +++ b/e2e/chains/bsc/docker-compose.simple.yml @@ -71,6 +71,10 @@ services: - ./scripts:/scripts - ./config:/config command: ash /scripts/bsc-rpc.sh + healthcheck: + test: ["CMD", "ash", "/scripts/healthcheck.sh"] + interval: "5s" + start_period: "10s" bsc-rpc2: # This is the bootstrap node image: bsc-geth:docker-local @@ -86,6 +90,10 @@ services: - ./scripts:/scripts - ./config:/config command: ash /scripts/bsc-rpc.sh + healthcheck: + test: ["CMD", "ash", "/scripts/healthcheck.sh"] + interval: "5s" + start_period: "10s" bsc-validator1-1: image: bsc-geth:docker-local @@ -217,6 +225,14 @@ services: - ./scripts:/scripts command: ash /scripts/bsc-validator.sh + autoheal: + restart: always + image: willfarrell/autoheal + environment: + - AUTOHEAL_CONTAINER_LABEL=all + volumes: + - /var/run/docker.sock:/var/run/docker.sock + networks: bsc: ipam: @@ -227,4 +243,4 @@ networks: ipam: driver: default config: - - subnet: 99.98.0.0/16 \ No newline at end of file + - subnet: 99.98.0.0/16 diff --git a/e2e/chains/bsc/scripts/bootstrap.sh b/e2e/chains/bsc/scripts/bootstrap.sh index 33c86f80..c1e6d985 100755 --- a/e2e/chains/bsc/scripts/bootstrap.sh +++ b/e2e/chains/bsc/scripts/bootstrap.sh @@ -21,12 +21,12 @@ function init_validator() { # set validator address mkdir -p ${workspace}/storage/${node_id}/keystore cp ${workspace}/validators/keystore/${node_id} ${workspace}/storage/${node_id}/keystore/${node_id} - validatorAddr=0x$(cat ${workspace}/storage/${node_id}/keystore/${node_id} | jq .address | sed 's/"//g') + validatorAddr=0x$(jq -r .address ${workspace}/storage/${node_id}/keystore/${node_id}) echo ${validatorAddr} >${workspace}/storage/${node_id}/address # create new BLS vote address expect ${workspace}/scripts/create_bls_key.sh ${workspace}/storage/${node_id} - voteAddr=0x$(cat ${workspace}/storage/${node_id}/bls/keystore/*json| jq .pubkey | sed 's/"//g') + voteAddr=0x$(jq -r .pubkey ${workspace}/storage/${node_id}/bls/keystore/*json) echo $voteAddr echo "${validatorAddr},${validatorAddr},${validatorAddr},0x0000000010000000,${voteAddr}" >>scripts/validators.conf diff --git a/e2e/chains/bsc/scripts/bsc-rpc.sh b/e2e/chains/bsc/scripts/bsc-rpc.sh index f70eba47..656b3fc1 100755 --- a/e2e/chains/bsc/scripts/bsc-rpc.sh +++ b/e2e/chains/bsc/scripts/bsc-rpc.sh @@ -13,6 +13,7 @@ while [ "$i" -lt ${account_cnt} ]; do done ETHSTATS="" -geth --config ${DATA_DIR}/config.toml --datadir ${DATA_DIR} --netrestrict ${CLUSTER_CIDR} \ +# Use exec to handle signals +exec geth --config ${DATA_DIR}/config.toml --datadir ${DATA_DIR} --netrestrict ${CLUSTER_CIDR} \ --state.scheme=hash --db.engine=leveldb --verbosity ${VERBOSE} --nousb ${ETHSTATS} \ --unlock ${unlock_sequences} --password /dev/null --ipcpath /gethipc --override.fixedturnlength 2 diff --git a/e2e/chains/bsc/scripts/bsc-validator.sh b/e2e/chains/bsc/scripts/bsc-validator.sh index 2d2228cf..3ae3e6a3 100755 --- a/e2e/chains/bsc/scripts/bsc-validator.sh +++ b/e2e/chains/bsc/scripts/bsc-validator.sh @@ -10,7 +10,8 @@ HOST_IP=$(hostname -i) echo "validator id: ${HOST_IP}" ETHSTATS="" -geth --config ${DATA_DIR}/config.toml --datadir ${DATA_DIR} --netrestrict ${CLUSTER_CIDR} \ +# Use exec to handle signals +exec geth --config ${DATA_DIR}/config.toml --datadir ${DATA_DIR} --netrestrict ${CLUSTER_CIDR} \ --verbosity ${VERBOSE} --nousb ${ETHSTATS} --state.scheme=hash --db.engine=leveldb \ --bootnodes enode://${BOOTSTRAP_PUB_KEY}@${BOOTSTRAP_IP}:${BOOTSTRAP_TCP_PORT} \ --mine --miner.etherbase=${VALIDATOR_ADDR} -unlock ${VALIDATOR_ADDR} --password /dev/null --blspassword /scripts/wallet_password.txt \ diff --git a/e2e/chains/bsc/scripts/healthcheck.sh b/e2e/chains/bsc/scripts/healthcheck.sh new file mode 100755 index 00000000..9b9c1ba9 --- /dev/null +++ b/e2e/chains/bsc/scripts/healthcheck.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -e + +timestamp=$(geth attach --exec 'parseInt(eth.getBlockByNumber("latest").timestamp)' /gethipc) +[ $(($(date '+%s') - $timestamp)) -lt 5 ]