Repository navigation
Prevent slow chain polls from starving fee updates - #1146
benthecarman wants to merge 3 commits into
Conversation
|
I've assigned @tnull as a reviewer! |
|
Field data point from a mainnet deployment, in case it helps prioritise review. Setup: ldk-node at Symptom: after switching this node from Esplora to bitcoind RPC, Why the poll exceeds the 2 s tick here: sampling With this PR cherry-picked onto Happy to test a revised version on this node if useful. |
tnull
left a comment
There was a problem hiding this comment.
This needs a rebase by now.
| } | ||
|
|
||
| let current_best_block_hash = channel_manager.current_best_block().block_hash; | ||
| if last_best_block_hash != Some(current_best_block_hash) { |
There was a problem hiding this comment.
Are we sure we want this? Core added mempool-based fee estimation with 32.0 / bitcoin/bitcoin#34075, so only updating after each block would lose that inter-block resolution, no?
There was a problem hiding this comment.
We now also refresh if 30s have passed since the last successful update, so we pick up Core's mempool-based estimates between blocks without doing ~10 RPCs every 2s poll tick.
The bitcoind polling loop used a biased select over two separate two-second intervals, with the chain polling tick prioritized over the fee rate update tick. If each chain poll took longer than the polling interval, the chain tick was already ready every time we returned to the select, so the fee rate update branch was never taken and fee estimates could go stale indefinitely. Since both intervals fire at the same rate anyway, we now drop the separate fee rate interval and update fee rate estimates right after each chain poll whenever the best block changed. Every step still races against the stop signal, so shutdown remains prompt. This was found by Project Loupe. This change was made with the help of Claude Code.
418dc30 to
7a2e99e
Compare
tnull
left a comment
There was a problem hiding this comment.
Not entirely against the approach, but wouldn't the more trivial fix be to move the _ = fee_rate_update_interval.tick() => { arm up to the second position?
| // polling interval to starve the fee rate updates. | ||
| let fee_rate_refresh_interval = Duration::from_secs(FEE_RATE_REFRESH_INTERVAL_SECS); | ||
| let mut last_best_block_hash = None; | ||
| let mut last_fee_rate_update: Option<Instant> = None; |
There was a problem hiding this comment.
Hmm, kind of a regression that on startup we immediately re-retrieve the fee rate even though we just did (hence the .reset() above). Can we try to skip the initial update again?
The bitcoind polling loop used a biased select over two separate two-second intervals, with the chain polling tick prioritized over the fee rate update tick. If each chain poll took longer than the polling interval, the chain tick was already ready every time we returned to the select, so the fee rate update branch was never taken and fee estimates could go stale indefinitely.
Since both intervals fire at the same rate anyway, we now drop the separate fee rate interval and update fee rate estimates right after each chain poll whenever the best block changed. Every step still races against the stop signal, so shutdown remains prompt.
This was found by Project Loupe.