diff --git a/contrib/teamcity/ibd.sh b/contrib/teamcity/ibd.sh --- a/contrib/teamcity/ibd.sh +++ b/contrib/teamcity/ibd.sh @@ -17,6 +17,8 @@ DEBUG_LOG="${DATA_DIR}/debug.log" touch "${DEBUG_LOG}" chmod +x bitcoind +chmod +x bitcoin-cli +BITCOIN_CLI="./bitcoin-cli -datadir=${DATA_DIR}" # Launch bitcoind using this script's parameters ./bitcoind "-datadir=${DATA_DIR}" $* & @@ -40,8 +42,24 @@ ) echo "Initial block download complete." - # TODO Add more checks to see if IBD completed as expected, - # These checks will exit the subshell with a non-zero exit code. + # Check that chainwork after exiting IBD exceeds minimum chainwork. + MIN_CHAINWORK=`cat "${DEBUG_LOG}" | grep nMinimumChainWork | tail -1 | sed 's/.*Setting nMinimumChainWork=\([a-z0-9]\{64\}\).*/\1/g'` + BEST_BLOCK_HASH=`$BITCOIN_CLI getbestblockhash` + CURRENT_CHAINWORK=`$BITCOIN_CLI getblockheader $BEST_BLOCK_HASH | grep "chainwork" | sed 's/.*chainwork": "\([a-z0-9]\{64\}\).*/\1/g'` + if [ "${#MIN_CHAINWORK}" -ne 64 ]; then + echo "Minimum chainwork is malformed. Got: $MIN_CHAINWORK" + exit 1 + fi + if [ "${#CURRENT_CHAINWORK}" -ne 64 ]; then + echo "Current chainwork is malformed. Got: $CURRENT_CHAINWORK" + exit 1 + fi + echo "Minimum Chainwork: $MIN_CHAINWORK" + echo "Current Chainwork: $CURRENT_CHAINWORK" + if (( "0x${CURRENT_CHAINWORK}" < "0x${MIN_CHAINWORK}" )); then + echo "IBD finished too early! Current chainwork is lower than minimum chainwork." + exit 1 + fi ) & IBD_PID=$!