-
Notifications
You must be signed in to change notification settings - Fork 406
(draft) refactor(esplora): clear remaining panic paths #2053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
let last_index = | ||
last_index.ok_or_else(|| Box::new(esplora_client::Error::InvalidResponse))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One suggestion is to leave last_index
as an Option and wrap stop_gap
in Some(..)
when doing the comparison.
But there's a much better way to handle this, which is to introduce an unused_count
variable. Now when processing handles, if txs.is_empty()
we increment the unused count, else update the last active index (and reset the unused count). Finally, break
once the unused count reaches the gap limit. AFAICT there'd be no reason to keep track of the last_index
scanned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took your suggestion and worked it in; didn't want to push it to this branch yet if I had the wrong idea, but here is the commit reez@35538e2 on a branch that builds on this branch.
I felt like I had to keep two small guardrails from the old logic:
processed_any
(still surface the “no handles ran” error)gap_limit = stop_gap.max(1)
(keeps old “stop_gap==0 still means one empty derivation” behavior)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's an error if handles
turns up empty - we need a way to break from the loop once all of the keychain-spks are consumed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe stop_gap = stop_gap.max(parallel_requests)
, since we check at least 1 spk-index for every request in parallel_requests
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super helpful thanks mammal, I made the below changes to that my side branch esplora+mammal
that I can eventually fold back into this esplora
branch if I'm on the right track
I don't think it's an error if handles turns up empty - we need a way to break from the loop once all of the keychain-spks are consumed.
Good call. I made this change 36073d0 based on that
Maybe stop_gap = stop_gap.max(parallel_requests), since we check at least 1 spk-index for every request in parallel_requests.
Good catch, made another change 590edcf based on this
let (index, txs, evicted) = handle.join().expect("thread must not panic")?; | ||
let handle_result = handle | ||
.join() | ||
.map_err(|_| Box::new(esplora_client::Error::InvalidResponse))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because you're dropping the error it won't be very informative to propagate it upward. Instead this module can define its own Error
type to handle errors that aren't covered by esplora_client::Error
.
Description
This PR clears remaining panic paths from bdk_esplora, replacing them with proper error handling.
Attempting to address bitcoindevkit/bdk_wallet#30 for Esplora
Notes to the reviewers
Open to any and all feedback on this.
Other PR's made along these lines:
unwrap()
s andexpect()
s #1981 (electrum)chain_update
errors if no point of connection #1971 (esplora)Changelog notice
bdk_esplora.rs
.Checklists
All Submissions:
New Features:
Bugfixes: