-
Notifications
You must be signed in to change notification settings - Fork 9
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
Remove electrum tip query on start #708
Conversation
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.
Makes sense to reuse the block_headers_subscribe_raw()
instead of caching the tip.
There are a couple of println
's that need removing
lib/core/src/chain/liquid.rs
Outdated
println!("Fetching block headers none"); | ||
// https://github.com/bitcoindevkit/rusprintln!("Fetching block headers");t-electrum-client/issues/124 |
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.
println!("Fetching block headers none"); | |
// https://github.com/bitcoindevkit/rusprintln!("Fetching block headers");t-electrum-client/issues/124 | |
// https://github.com/bitcoindevkit/rust-electrum-client/issues/124 |
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.
Done
lib/core/src/chain/liquid.rs
Outdated
let new_tip: Option<u32> = match maybe_popped_header { | ||
Some(popped_header) => Some(popped_header.height.try_into()?), | ||
None => { | ||
// https://github.com/bitcoindevkit/rusprintln!("Fetching block headers");t-electrum-client/issues/124 |
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.
// https://github.com/bitcoindevkit/rusprintln!("Fetching block headers");t-electrum-client/issues/124 | |
// https://github.com/bitcoindevkit/rust-electrum-client/issues/124 |
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.
Oh... how did it got there.
Done
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.
LGTM
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.
LGTM. Only a couple nits
lib/core/src/chain/bitcoin.rs
Outdated
} | ||
|
||
Ok(tip.clone()) | ||
let tip = new_tip.ok_or_else(|| anyhow!("Failed to get tip"))?; |
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.
Nit: the new_tip
name no longer makes sense. Maybe rename to maybe_tip
? We can even get rid of it and return the tip directly within the match
.
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.
Done
lib/core/src/chain/liquid.rs
Outdated
let new_tip: Option<u32> = match maybe_popped_header { | ||
Some(popped_header) => Some(popped_header.height.try_into()?), | ||
None => { | ||
// https://github.com/bitcoindevkit/rust-electrum-client/issues/124 | ||
// It might be that the client has reconnected and subscriptions don't persist | ||
// across connections. Calling `client.ping()` won't help here because the | ||
// successful retry will prevent us knowing about the reconnect. | ||
if let Ok(header) = client.block_headers_subscribe_raw() { | ||
Some(header.height.try_into()?) | ||
} else { | ||
None | ||
} | ||
} | ||
}; | ||
|
||
let tip: u32 = new_tip.ok_or_else(|| anyhow!("Failed to get tip"))?; |
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.
Nit: Same as above. The name new_tip
doesn't fit. We can return within the match
.
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.
Done
ElecturmClient needs to be initialized with the current tip which forced us to query right on start which caused up to several seconds of sdk initialization.
Since we don't really need lwk ElectrumClient to use electrum this PR shifts to use the underline Client directly and saves this startup time and reduced it to less than a millisecond.
Edit: It turns out that also Electurm client initialization has some overhead as it tries to connect. I changed the code to use lazy initialization of electrum which causes the startup flow to complete instantly now.