-
Notifications
You must be signed in to change notification settings - Fork 51
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' error
unset RUSTC_WRAPPER
# clear log
echo "" > ./cross-sync.log
function best_block_number() {
local HOST=$1
local 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'
}
function upstream_block_number() { best_block_number "$JSON_RPC"; }
function current_block_number() { best_block_number "http://localhost:8080"; }
function sync_to() {
local TARGET_BN=$1
local DB_PATH=$2
local BRANCH=$3
local 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
while true; do
BN=`current_block_number`
if [ -z "$BN" ]; then
echo "Node doesn't responds" 1>&2
exit -1
fi
if [ "$BN" -ge "$TARGET_BN" ]; then
break
fi
echo "$BRANCH-$DB_PATH $BN/$TARGET_BN" >> ./cross-sync.log
sleep 1
done
sleep $WAIT_MORE
kill -INT $CODECHAIN
wait $CODECHAIN
trap 'exit -1' SIGINT
}
function run(){
local DB_PATH=$1
local SCRATCH=$2
local 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