Changeset View
Changeset View
Standalone View
Standalone View
contrib/teamcity/ibd.sh
Show All 10 Lines | |||||
MYPID=$$ | MYPID=$$ | ||||
# Setup | # Setup | ||||
mkdir -p ibd | mkdir -p ibd | ||||
DEBUG_LOG="ibd/debug.log" | DEBUG_LOG="ibd/debug.log" | ||||
touch "${DEBUG_LOG}" | touch "${DEBUG_LOG}" | ||||
chmod +x bitcoind | chmod +x bitcoind | ||||
chmod +x bitcoin-cli | |||||
# Launch bitcoind using this script's parameters | # Launch bitcoind using this script's parameters | ||||
./bitcoind -datadir=ibd $* & | ./bitcoind -datadir=ibd $* & | ||||
BITCOIND_PID=$! | BITCOIND_PID=$! | ||||
cleanup() { | cleanup() { | ||||
# Cleanup background processes spawned by this script. | # Cleanup background processes spawned by this script. | ||||
pkill -P ${MYPID} tail || true | pkill -P ${MYPID} tail || true | ||||
} | } | ||||
trap "cleanup" EXIT | trap "cleanup" EXIT | ||||
# Show some progress | # Show some progress | ||||
tail -f "${DEBUG_LOG}" | grep 'UpdateTip' | awk 'NR % 10000 == 0' & | tail -f "${DEBUG_LOG}" | grep 'UpdateTip' | awk 'NR % 10000 == 0' & | ||||
# Wait for IBD to finish and kill the daemon | # Wait for IBD to finish and kill the daemon | ||||
( | ( | ||||
( | ( | ||||
# Ignore the broken pipe when tail tries to write pipe closed by grep | # Ignore the broken pipe when tail tries to write pipe closed by grep | ||||
set +o pipefail | set +o pipefail | ||||
tail -f "${DEBUG_LOG}" | grep -m 1 'progress=1.000000' | tail -f "${DEBUG_LOG}" | grep -m 1 'progress=1.000000' | ||||
) | ) | ||||
echo "Initial block download complete." | echo "Initial block download complete." | ||||
# TODO Add more checks to see if IBD completed as expected, | # Check that chainwork after exiting IBD exceeds minimum chainwork. | ||||
# These checks will exit the subshell with a non-zero exit code. | 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 | |||||
if [ "0x${CURRENT_CHAINWORK}" -lt "0x${MIN_CHAINWORK}" ]; then | |||||
echo "IBD finished too early! Current chainwork (${CURRENT_CHAINWORK}) is lower than minimum chainwork (${MIN_CHAINWORK})." | |||||
exit 1 | |||||
fi | |||||
) & | ) & | ||||
IBD_PID=$! | IBD_PID=$! | ||||
# When the IBD subshell finishes, kill bitcoind | # When the IBD subshell finishes, kill bitcoind | ||||
( | ( | ||||
while [ -e /proc/${IBD_PID} ]; do sleep 0.1; done | while [ -e /proc/${IBD_PID} ]; do sleep 0.1; done | ||||
echo "Cleaning up bitcoin daemon (PID: ${BITCOIND_PID})." | echo "Cleaning up bitcoin daemon (PID: ${BITCOIND_PID})." | ||||
Show All 22 Lines |