Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 50
Sync test script
foriequal0 edited this page May 16, 2019
·
4 revisions
You can inspect whether the branch contains breaking changes from master using this script. It simply tries to sync from scratch on both branches and tries to continue to sync on the other branch. Although it doesn't automagically detect state root mismatches, you might inspect easily by seeing the progress stalls or spurious logs.
#/bin/bash## USAGE## ./cross-sync.sh master feature/blah ./db-synctest 192.168.100.123:3485 192.168.100.123:8080
BASE=$1
REMOTE=$2
DB_PATH=$3
BOOTSTRAP=$4
JSON_RPC=$5# sccache makes 'error reading compile response from server' errorunset RUSTC_WRAPPER
# clear logecho""> ./cross-sync.log
functionbest_block_number() {
local HOST=$1local RESP=`curl --retry 5 --retry-connrefused --retry-delay 1 \ -s -H 'Content-Type: application/json' \ -d '{"jsonrpc": "2.0", "method": "chain_getBestBlockNumber", "params": [], "id": null}' \$HOST`echo$RESP| sed -n 's/.*"result":\([0-9]*\).*/\1/p'
}
functionupstream_block_number() { best_block_number "$JSON_RPC"; }
functioncurrent_block_number() { best_block_number "http://localhost:8080"; }
functionsync_to() {
local TARGET_BN=$1local DB_PATH=$2local BRANCH=$3local WAIT_MORE=$4
git checkout $BRANCH
cargo build --release
ENABLE_DELEGATIONS=true \
ENABLE_ORDER=true \
RUST_LOG=info,mio=warn,tokio=warn,hyper=warn,rpc=info \
./target/release/codechain -c corgi --jsonrpc-port 8080 --port 3485 \
--no-tx-relay --enable-devel-api --no-miner --no-discovery \
--bootstrap-addresses $BOOTSTRAP \
--db-path "$DB_PATH"&
CODECHAIN=$!trap"kill -INT $CODECHAIN; wait $CODECHAIN; exit" SIGINT
sleep 2
whiletrue;do
BN=`current_block_number`if [ -z"$BN" ];thenecho"Node doesn't responds"1>&2exit -1
fiif [ "$BN"-ge"$TARGET_BN" ];thenbreakfiecho"$BRANCH-$DB_PATH$BN/$TARGET_BN">> ./cross-sync.log
sleep 1
done
sleep $WAIT_MOREkill -INT $CODECHAINwait$CODECHAINtrap'exit -1' SIGINT
}
functionrun(){local DB_PATH=$1local SCRATCH=$2local CONTINUE=$3# Sync from scratch with branch SCRATCH. This will test sync compatibility.
sync_to `upstream_block_number`"$DB_PATH""$SCRATCH" 0
# Continue to sync with branch CONTINUE. This will test it can boot and further sync with existing db.
sync_to `upstream_block_number`"$DB_PATH""$CONTINUE" 60
}
set -ex
run "$DB_PATH-base-remote""$BASE""$REMOTE"
run "$DB_PATH-remote-base""$REMOTE""$BASE"If your JSONRPC is behind the ssh, you can try forwarding
ssh ssh -o 'ControlPath ./jsonrpc.ctrl' -fNTM -L 9000:localhost:8080 $SSH_JSON_RPC
bash cross-sync.sh master feature/blah ./db-synctest 192.168.100.123:3485 localhost:9000
ssh -o 'ControlPath ./jsonrpc.ctrl' -TO exit$SSH_JSON_RPC