Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1#!/usr/bin/env bash3__sleep_amount() {4if [ -n "$constant_sleep" ]; then5sleep_time=$constant_sleep6else7sleep_time=`awk "BEGIN {t = $min_sleep * $(( (1<<($attempts -1)) )); print (t > $max_sleep ? $max_sleep : t)}"`8fi9}11__log_out() {12echo "$1" 1>&213}15# Parameters: max_tries min_sleep max_sleep constant_sleep fail_script EXECUTION_COMMAND16retry()17{18local max_tries="$1"; shift19local min_sleep="$1"; shift20local max_sleep="$1"; shift21local constant_sleep="$1"; shift22local fail_script="$1"; shift23if [ -n "$VERBOSE" ]; then24__log_out "Retry Parameters: max_tries=$max_tries min_sleep=$min_sleep max_sleep=$max_sleep constant_sleep=$constant_sleep"25if [ -n "$fail_script" ]; then __log_out "Fail script: $fail_script"; fi26__log_out ""27__log_out "Execution Command: $*"28__log_out ""29fi31local attempts=032local return_code=135while [[ $return_code -ne 0 && $attempts -le $max_tries ]]; do36if [ $attempts -gt 0 ]; then37__sleep_amount38__log_out "Before retry #$attempts: sleeping $sleep_time seconds"39sleep $sleep_time40fi42P="$1"43for param in "${@:2}"; do P="$P '$param'"; done44export RETRY_ATTEMPT=$attempts45bash -c "$P"46return_code=$?47#__log_out "Process returned $return_code on attempt $attempts"48if [ $return_code -eq 127 ]; then49# command not found50exit $return_code51elif [ $return_code -ne 0 ]; then52attempts=$[$attempts +1]53fi54done56if [ $attempts -gt $max_tries ]; then57if [ -n "$fail_script" ]; then58__log_out "Retries exhausted, running fail script"59eval $fail_script60else61__log_out "Retries exhausted"62fi63fi65exit $return_code66}68max_tries=1069min_sleep=0.370max_sleep=60.071constant_sleep=72fail_script=74retry "$max_tries" "$min_sleep" "$max_sleep" "$constant_sleep" "$fail_script" "$@"
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.