The behavior of stop_gap when set to 0 is somewhat underspecified. The documentation states that "A stop gap of 0 will be treated as a stop gap of 1", however it has been pointed out that scanning scripts will stop after the first parallel-requests number of requests to esplora regardless of whether the SPK is found to have transaction history, i.e. not what you'd expect if using a stop gap of 1. Possible solutions are to:
1) Remove the doc comment and leave the behavior the same
2) Change the code to internally set stop_gap to the maximum of 1 and the given value
3) If stop gap is 0, then set it to the number of parallel requests
I also think readability here could be improved by changing the variable gap_limit_reached to unused_count as originally suggested by @evanlinjin and then stopping when the count of unused scripts is greater or equal to the stop gap.
https://github.com/bitcoindevkit/bdk/blob/647d2855941d0c46412efa797db4ae157fb544d5/crates/esplora/src/async_ext.rs#L327-L335
The behavior of
stop_gapwhen set to 0 is somewhat underspecified. The documentation states that "A stop gap of 0 will be treated as a stop gap of 1", however it has been pointed out that scanning scripts will stop after the first parallel-requests number of requests to esplora regardless of whether the SPK is found to have transaction history, i.e. not what you'd expect if using a stop gap of 1. Possible solutions are to:1) Remove the doc comment and leave the behavior the same2) Change the code to internally set
stop_gapto the maximum of 1 and the given value3) If stop gap is 0, then set it to the number of parallel requests
I also think readability here could be improved by changing the variable
gap_limit_reachedtounused_countas originally suggested by @evanlinjin and then stopping when the count of unused scripts is greater or equal to the stop gap.https://github.com/bitcoindevkit/bdk/blob/647d2855941d0c46412efa797db4ae157fb544d5/crates/esplora/src/async_ext.rs#L327-L335