Skip to content

Commit 1d8c9ba

Browse files
Arshia-r-mzoedberg
andcommitted
fix: improve bitcoind startup wait logic
Co-authored-by: Zoe Faltibà <7492268+zoedberg@users.noreply.github.com>
1 parent 753b18f commit 1d8c9ba

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

regtest.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ _is_port_bound() {
3636
}
3737

3838
_wait_for_bitcoind() {
39-
# wait for bitcoind to be up
39+
# wait until bitcoind RPC is actually ready
4040
start_time=$(date +%s)
41-
until $COMPOSE logs bitcoind |grep -q 'Bound to'; do
41+
until $BITCOIN_CLI getblockchaininfo >/dev/null 2>&1; do
4242
current_time=$(date +%s)
4343
if [ $((current_time - start_time)) -gt $TIMEOUT ]; then
44-
echo "Timeout waiting for bitcoind to start"
44+
echo "Timeout waiting for bitcoind RPC to become ready"
4545
$COMPOSE logs bitcoind
4646
exit 1
4747
fi
@@ -74,11 +74,13 @@ _start_services() {
7474
_die "port $port is already bound, services can't be started"
7575
fi
7676
done
77-
$COMPOSE up -d
77+
# start bitcoind first to avoid depending services failing due to RPC unavailability
78+
$COMPOSE up -d bitcoind
7879
echo && echo "preparing bitcoind wallet"
7980
_wait_for_bitcoind
8081
$BITCOIN_CLI createwallet miner >/dev/null
8182
$BITCOIN_CLI -rpcwallet=miner -generate $INITIAL_BLOCKS >/dev/null
83+
$COMPOSE up -d
8284
echo "waiting for electrs to have completed startup"
8385
_wait_for_electrs
8486
}

0 commit comments

Comments
 (0)