-
Notifications
You must be signed in to change notification settings - Fork 49
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
fix(wallet_esplora): Gracefully handle 429s errors #59
fix(wallet_esplora): Gracefully handle 429s errors #59
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.
Aproach NACK
Thank you for taking a shot at this.
Why 500ms? What if the server expects us to wait for 600ms? I would prefer if we checked the Retry-After
header. If that does not exist, then have an exponential back-off delay as a fallback.
Do we need the async recursion? Is there a way to do it with a loop?
I also think introducing tokio
as an async dependency is a big ask. Would it be trivial to implement a simple Future
using Instant
?
Thanks for the feedback. It is helpful. I will try to modify the approach. 👍🏻 |
Not really trivial and using I would avoid sleeping and just lower the number of batch requests in the next round by the number of 429s you get. PS are we testing this crate on WASM? If not PR fixing that before this one would be good. |
Err(ureq::Error::Status(code, resp)) => { | ||
if is_status_too_many_requests(code) { | ||
eprintln!("Too many requests, sleeping for 500 ms"); | ||
sleep(Duration::from_millis(500)); |
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.
this will cause a panic in wasm, might need to pass in a function that sleeps. for wasm sleep needs to be async too
I will try another approach in the EDIT: |
Closes bitcoindevkit/bdk#1120
Details
BlockingClient
:scripthash_txs
for 429 Status codes.If detected, hard-coded sleep for 500ms using
std::thread::sleep
(so it is also thread-safe).AsyncClient
(little more convoluted thanBlockingClient
):I had to bring
tokio
andasync-recursion
into thedependencies
.Inside the
scripthash_txs
we are checking for 429 Status codes.If detected, hard-coded sleep for 500ms using
tokio::time::sleep
.Since this is an "async recursion" the macro
async_recursion
handles that gracefully without having to deal with:If we annotate the offending recursive function with
#[async_recursion]
,it automatically convert an async function to one returning a boxed
Future
.