Skip to content

Use the long-poll client for the startup ping and initial GBT (slow/large templates) - #75

Open
mblowes wants to merge 2 commits into
LayerTwo-Labs:mainfrom
mbdrivechains:up-longpoll-pr
Open

Use the long-poll client for the startup ping and initial GBT (slow/large templates)#75
mblowes wants to merge 2 commits into
LayerTwo-Labs:mainfrom
mbdrivechains:up-longpoll-pr

Conversation

@mblowes

@mblowes mblowes commented Sep 7, 2026

Copy link
Copy Markdown

Problem

On a block-template backend whose getblocktemplate is slow to respond, simplepool can exit at startup and flap in a relaunch loop.

The general-purpose curl client has a 10 s timeout. Two startup calls use it:

  1. The ping. When no RPC credentials are set, bitcoind_ping() skips getblockchaininfo (some backends don't implement it) and falls back to a full getblocktemplate. The CUSF bip300301_enforcer is exactly such a backend.
  2. The initial template, one step later.

A live template is now multi-megabyte and, once the mempool fills, takes longer than 10 s to return — measured 10.5–13.5 s against alphanet through the enforcer. So the pool exits 3 (bitcoind ping failed: curl: Timeout was reached) or exits 5 (initial GBT failed: …), and a supervisor relaunch loop just flaps until a template happens to come back fast.

Fix

Route those two startup calls through the long-poll client (btc_lp, ~90 s timeout) — the same client the tip watcher already uses for every template. No behaviour change for fast backends; it only removes the 10 s ceiling on the two startup fetches. 16-line change to src/main.c, plus a missing bitcoind_client_free(&btc_lp) on the ping error path.

Found running against the enforcer's GBT server; the enforcer is where the slow, large templates come from.

@rsantacroce

Copy link
Copy Markdown
Collaborator

Hi @mblowes thank you for your collaboration. Can you check why some tests are failing ?

mblowes and others added 2 commits September 9, 2026 05:27
On a backend without getblockchaininfo (the CUSF enforcer) bitcoind_ping()
falls back to a full getblocktemplate. The general-purpose client has a
10s timeout and a live alphanet template is now ~4.4 MB and takes
10.5–13.5s to come back, so the pool exits 3 at startup with
"bitcoind ping failed: curl: Timeout was reached" and a relaunch loop
flaps until a template happens to arrive fast (seen on d68f8da on
2026-08-31 23:55 and on this branch on 2026-09-03 12:31 on freebanktest).

The tip watcher already fetches every template through the 90s
long-poll client; the ping now uses the same one. Also free btc_lp on
the ping's failure path.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BufjPUcrUtoG7E4tf61j3n
(cherry picked from commit 67cd9f2)
Same flap as the previous commit, one step later: after the ping passes,
the first getblocktemplate went through the 10s client and exited 5
("initial GBT failed: curl: Timeout was reached") on a 14s live
template. Fetch it with the 90s long-poll client the tip watcher uses.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BufjPUcrUtoG7E4tf61j3n
(cherry picked from commit 6f4a226)
@mblowes

mblowes commented Sep 8, 2026

Copy link
Copy Markdown
Author

Thanks @rsantacroce. Those two checks were failing because the branch was based on an older main; I've rebased onto current main. The change is unrelated to the integration/payout paths — it only routes the startup ping and initial getblocktemplate through the existing long-poll client. Build and unit tests pass locally, CI should be green now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants