fix: define and document stop_gap#1351
Conversation
1c5598b to
465908e
Compare
|
Thanks for this work. I'm actually in favor of renaming the variable instead of changing the definition. I think if |
I think that We can discuss on how to handle |
ValuedMammal
left a comment
There was a problem hiding this comment.
I think the code in bdk_electrum suffers from the same stop gap bug. If so, we should try to fix that in this PR also, and probably have a test for it.
In terms of Changelog I consider this a bugfix but I wouldn't call it a breaking change, per se ?
crates/esplora/src/blocking_ext.rs
Outdated
| let last_index = last_index.expect("Must be set since handles wasn't empty."); | ||
| let past_gap_limit = if let Some(i) = last_active_index { | ||
| let gap_limit_reached = if let Some(i) = last_active_index { | ||
| last_index > i.saturating_add(stop_gap as u32) |
There was a problem hiding this comment.
| last_index > i.saturating_add(stop_gap as u32) | |
| last_index >= i.saturating_add(stop_gap as u32) |
Imagine 10 addresses and we send a tx to the 4th address and the 10th address (like in the test). We need to scan 6 times in order to find the tx at the 10th address (5, 6, 7, 8, 9, 10). So here, when i is 3 and the last_index scanned is 9, we have
9 >= 3 + 6
and we break.
This means the second half of the test test_update_tx_graph_gap_limit should read
// A scan with gap limit 5 won't find the second transaction, but a scan with gap limit 6 will.
There was a problem hiding this comment.
Hey, this was marked as resolved, but the code didn't really change. Unresolving.
|
I agree with José here, although I'm fine with both panicking or returning an error if the stop_gap is 0. |
|
I'll argue that Returning an error when |
You're right that it's not difficult to understand, but it's yet another thing to find out and learn about bdk. My intuition is that for a developer that wants to use bdk, there's already a lot to be learned, should we really add yet another concept, even if small?
I would agree if we didn't already return a result, but since we do, it's probably not so bad to add a new error variant. But again, both error and panic are ok for me. |
|
We can discuss Error/Panic on Tue's call |
896e9d9 to
88f36ba
Compare
88f36ba to
0f5a56b
Compare
Gosh, I just realized we return a esplora error, and so we can't create a new error variant easily 😅 |
I have a stash that wraps the errors: /// Custom error type for handling errors related to `esplora_client` operations
/// and additional conditions specific to our application logic, such as invalid parameters.
#[derive(Debug)]
enum EsploraError {
/// Represents errors originating from the `esplora_client` crate.
EsploraClientError(esplora_client::Error),
/// Error to indicate an invalid `stop_gap` value, specifically when `stop_gap` is 0.
InvalidStopGap,
}
impl From<esplora_client::Error> for EsploraError {
fn from(err: esplora_client::Error) -> EsploraError {
EsploraError::EsploraClientError(err)
}
}
impl std::fmt::Display for EsploraError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match *self {
EsploraError::EsploraClientError(ref err) => write!(f, "Esplora client error: {}", err),
EsploraError::InvalidStopGap => write!(f, "Invalid stop_gap: stop_gap cannot be 0"),
}
}
}
impl std::error::Error for EsploraError {}Not beautiful but works 😂 |
|
Can we not create an error variant for this? It's more baggage which callers will have to deal with. |
We cannot extend enums variants from other crates in Rust. |
|
Discussed in 2024-02-27 BDK Lib Meeting:
|
819b8e0 to
648a688
Compare
7d4d4ba to
b9ba9b5
Compare
danielabrozzoni
left a comment
There was a problem hiding this comment.
There are still some issues with your code, that were pointed out by other contributors but weren't resolved.
I don't want to be harsh, and I know it's not easy, but please try to put attention to details. Making sure to incorporate all the feedback that is given is important for speeding up review time.
crates/esplora/src/blocking_ext.rs
Outdated
| let last_index = last_index.expect("Must be set since handles wasn't empty."); | ||
| let past_gap_limit = if let Some(i) = last_active_index { | ||
| let gap_limit_reached = if let Some(i) = last_active_index { | ||
| last_index > i.saturating_add(stop_gap as u32) |
There was a problem hiding this comment.
Hey, this was marked as resolved, but the code didn't really change. Unresolving.
|
@danielabrozzoni sorry about the oversight and thank you for pointing that out! |
danielabrozzoni
left a comment
There was a problem hiding this comment.
Sweet, can you remove the FIXME and NOTE in the tests and squash the two commits together? Then it's ready to merge for me
ValuedMammal
left a comment
There was a problem hiding this comment.
Just to note: the fix for electrum may be as simple as changing a > to >= but right now you kind of have to test manually to convince yourself that's the case
- changes the code implementation to "the maximum number of consecutive unused addresses" in esplora async and blocking extjensions. - treat `stop_gap = 0` as `stop_gap = 1` for all purposes. - renames `past_gap_limit` to `gap_limit_reached` to indicate we want to break once the gap limit is reached and not go further in `full_scan`, as suggested in bitcoindevkit#1227 (comment) - change the tests according to the new implementation. - add notes on what `stop_gap` means and links to convergent definition in other Bitcoin-related software. Closes bitcoindevkit#1227
|
Rebased to |
Description
stop_gap = 0asstop_gap = 1.past_gap_limittogap_limit_reachedto indicate we want to break once the gap limit is reached and not go further infull_scan, as suggested in Clearly define and documentstop_gap#1227 (comment)stop_gapmeans and links to convergent definition in other Bitcoin-related software.Closes #1227.
Notes to the reviewers
We can iterate over the wording and presentation of the
stop_gapdefinitionand details.
Changelog notice
stop_gapdefinition and effects infull_scanto reflect the common definitions in most Bitcoin-related software.
Checklists
All Submissions:
cargo fmtandcargo clippybefore committingNew Features:
Bugfixes: