Skip to content

Commit a84de1a

Browse files
Retries on esplora connection
1 parent c282d8e commit a84de1a

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

.github/workflows/python.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,18 @@ jobs:
2626

2727
- name: Wait for services to be fully initialized
2828
run: |
29-
echo "Waiting for services to be ready..."
30-
timeout 90 bash -c 'until docker compose ps | grep -q "bitcoin.*healthy" && docker compose ps | grep -q "electrs.*healthy"; do sleep 5; done'
31-
echo "All services are healthy"
29+
echo "Waiting for Bitcoin to be ready..."
30+
timeout 60 bash -c 'until docker exec ldk-node-bitcoin-1 bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass getblockchaininfo > /dev/null 2>&1; do echo "Waiting for Bitcoin..."; sleep 3; done'
31+
echo "Bitcoin is ready"
32+
33+
echo "Waiting for Esplora to be ready..."
34+
# Try to get Esplora's status with retries and a timeout
35+
timeout 90 bash -c 'until curl -s http://127.0.0.1:3002/blocks/tip/hash > /dev/null 2>&1; do echo "Waiting for Esplora..."; sleep 3; done'
36+
echo "Esplora is ready"
37+
38+
# This is critical - give Esplora extra time to fully index after it starts accepting connections
39+
echo "Giving Esplora extra time to finish indexing..."
40+
sleep 10
3241
3342
- name: Install testing prerequisites
3443
run: |

bindings/python/src/ldk_node/test_ldk_node.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,25 @@ def mine_and_wait(esplora_endpoint, blocks):
5151
def wait_for_block(esplora_endpoint, block_hash):
5252
url = esplora_endpoint + "/block/" + block_hash + "/status"
5353
esplora_picked_up_block = False
54-
while not esplora_picked_up_block:
55-
res = requests.get(url)
54+
max_retries = 30
55+
retry_count = 0
56+
57+
while not esplora_picked_up_block and retry_count < max_retries:
5658
try:
57-
json = res.json()
58-
esplora_picked_up_block = json['in_best_chain']
59-
except:
60-
pass
61-
time.sleep(1)
59+
res = requests.get(url, timeout=10)
60+
try:
61+
json = res.json()
62+
esplora_picked_up_block = json['in_best_chain']
63+
except:
64+
pass
65+
except Exception as e:
66+
print(f"Request error: {e}, retrying ({retry_count+1}/{max_retries})...")
67+
68+
retry_count += 1
69+
time.sleep(0.5)
70+
71+
if not esplora_picked_up_block:
72+
raise TimeoutError(f"Block {block_hash} not found after {max_retries} attempts")
6273

6374
def wait_for_tx(esplora_endpoint, txid):
6475
url = esplora_endpoint + "/tx/" + txid

0 commit comments

Comments
 (0)