Repository navigation
fix(esplora): stop full_scan at stop_gap with parallel requests - #2472
debojyoti10CC wants to merge 3 commits into
Conversation
Check the stop gap per script result instead of once per batch, so results past the gap in the same batch are not processed and the update no longer depends on parallel_requests. Gap bookkeeping moves into a small helper with unit tests. Fixes bitcoindevkit#2471
7142fd9 to
b7a3a56
Compare
|
Bumping this in case it got buried. It is still ready for review, and I am happy to make any changes you would like. Thanks! |
Jean-Regis-M
left a comment
There was a problem hiding this comment.
Concept ACK. This makes Esplora behave like Electrum: populate_with_spks in bdk_electrum_client.rs already returns as soon as unused_spk_count >= stop_gap, partway through a batch, so with this change both backends stop at the same script no matter how the requests are batched.
Since you mentioned you couldn't build locally, I tried it on Linux (rustc 1.100). It currently doesn't compile once the blocking or async feature is on:
$ cargo test -p bdk_esplora --lib --all-features
error[E0425]: cannot find function `track_spk_activity` in this scope
error[E0425]: cannot find function `track_spk_activity` in this scope
error: could not compile `bdk_esplora` (lib test) due to 2 previous errors
blocking_ext.rs and async_ext.rs only import use crate::{insert_anchor_or_seen_at_from_status, insert_prevouts};, so the new helper also needs adding there:
use crate::{insert_anchor_or_seen_at_from_status, insert_prevouts, track_spk_activity};cargo clippy -p bdk_esplora --no-default-features passes only because both modules are compiled out, which also explains why the #[allow(dead_code)] hid it. cargo fmt --all -- --check passes.
Two more things, not blocking:
same_result_regardless_of_batchingruns the helper on one sequential list, so it doesn't exercise batching. An electrsd test would cover the real path: same setup astest_update_tx_graph_stop_gap(tx on index 3), withfull_scan(request, 3, p)asserting no txs and nolast_active_indicesforpin[1, 2, 5]. On master,p = 2andp = 5should find the tx; with this PR none should.- After the
break, blocking and async now handle errors differently. Inblocking_ext.rs, the remainingJoinHandles are dropped unjoined, so an error from a request past the gap is ignored. Inasync_ext.rs,try_collecthas already awaited every request in the batch, so the same error still fails the whole scan. Probably fine either way, but it may be worth a sentence in the commit message, or joining the leftover handles so both behave the same.
|
Follow-up with an end-to-end check against electrsd (bitcoind + electrs), using the setup I suggested above: tx on index 3, master (c5e87cc): This PR, with the missing So the bug is real and the fix works once it compiles. With the import added,
Feel free to turn the electrsd check into a test in |
The helper was not in scope in blocking_ext.rs or async_ext.rs, so `--features blocking,async` failed to compile. Import it in both modules, drop the dead_code allow that hid the error, and move the gap_tests module to the end of lib.rs to satisfy clippy::items_after_test_module. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
|
Thanks for the detailed review and for running the electrsd check, @Jean-Regis-M. That was the bug I needed to confirm.nnPushed 63766c9:n- |
Jean-Regis-M
left a comment
There was a problem hiding this comment.
Since you couldn't build locally, I ran 63766c9 on Linux (WSL, Rust 1.100):
cargo test -p bdk_esplora --all-features: lib 9/9 (incl. the 4gap_tests),blocking_ext7/7,async_ext7/7, doc 1/1. The electrsd tests (test_stop_gap_past_last_revealed,test_update_tx_graph_stop_gapand their async versions) pass, so--features blocking,asyncnow compiles and the import fix is complete.cargo clippy -p bdk_esplora --all-features --all-targets -- -D warnings: the only findings areuseless_borrows_in_formattingon theformat!("http://{}", &env.electrsd.esplora_url...)lines in the existing test setup (src/*_ext.rstest modules andtests/*.rs). This PR doesn't touch those lines, and they're new lints in 1.100, so they aren't expected on the pinned 1.96 toolchain. Nothing is flagged in the changed code, anditems_after_test_moduleis gone.
tACK 63766c9 on the gap logic. It now behaves the same for parallel_requests 1, 2 and 5 in the electrsd setup from my earlier comment.
|
Thanks @Jean-Regis-M for running the electrsd tests and the Linux build, and for the tACK. That check caught the compile error and confirmed the stop-gap behavior matches Electrum for batches 1, 2 and 5. |
In the blocking client, handles after the stop-gap break were dropped unjoined, so errors from requests past the gap were ignored, while the async client awaits the whole batch and fails on them. Join every request first so both clients behave the same. Add electrsd tests checking that full_scan stops at stop_gap for parallel_requests 1, 2 and 5 (blocking and async).
|
Following up on the two non-blocking points, @Jean-Regis-M. Pushed 4a00615:
As before, I can't compile locally, so CI (or another run on your side, if you have time) will be the check. |
|
Ran 4a00615 on Linux (Rust 1.100), since you can't build locally:
Joining the whole batch before applying the gap in the blocking client also makes the error behaviour match |
Description
With
parallel_requests > 1, the Esplorafull_scan(blocking and async) only checked the stop gap after processing a whole batch of script results. If the gap was reached partway through a batch, a later script with a transaction reset the unused counter and its transactions went into the update, so the result depended onparallel_requests.The fix factors the gap bookkeeping into a small helper,
track_spk_activity, incrates/esplora/src/lib.rs. Both loops now call it per result and stop processing the batch as soon asstop_gapconsecutive unused scripts have been seen. Withparallel_requests = 1the behaviour is unchanged.Notes to the reviewers
I added unit tests for the helper (same-batch active script past the gap is ignored, revealed indices don't count as unused, activity within the gap resets the counter). They don't need electrsd. I did not add an electrsd integration test.
I could not build or run anything locally: Windows Application Control blocked the cargo build scripts here, so the tests,
cargo fmtcheck and clippy have not been run. Please rely on CI for those. The commit is also unsigned for now, since I haven't set up GPG signing.Used Claude Code to help write the fix and tests; I reviewed and tested the changes.
Changelog notice
Fixed: Esplora
full_scanno longer processes scripts beyondstop_gapwhenparallel_requests > 1.Checklists
All Submissions:
Bugfixes:
Fixes #2471