feat: generic api failover client + bitcoin client proof-of-concept with it #549
+717
−82
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Adds a generic fallback/retry type to be used with API clients. Provides the first integration with the
BitcoinCoreClient
and theBlockObserver
to ensure that everything plays nicely together and to show its usage.The goal here is to ensure that we have some measure of resiliency in our external API calls without needing to duplicate that kind of code everywhere (i.e. Bitcoin, Stacks, Emily & Blocklist clients).
I was a little bit back-and-forth on whether or not to put the API clients on the context, but in the end decided to so that they can be created at application startup and the fallback client's state (i.e. current "live" endpoint) shared with the rest of the app. The context now has two methods for newing up:
init()
is more implicit but requires more trait bounds, wherenew()
can be used in tests to provide concrete impls where needed (i.e. theTestHarness
inblock_observer.rs
).The fallback client's logic is pretty naive as it is right now, but we can expand upon this later to add exponential backoffs per endpoint, simpler load-balancing across endpoints (round-robin or lowest-latency, for example), etc. if we want.
Closes:
BitcoinCoreClient
#486Works towards:
BlockObserver
in the main entrypoint #548Changes
ApiFallbackClient
type which can be used to failover to a new endpoint while also supporting retries (default is 3 retries or the number of clients, whichever is higher). Probably not the best name tbh since it's not necessarily specific to API's, but that's what we use it for right now 🤷sbtc
library errors a little so that we get rid of thedyn Error
and problems withSend
.load_latest_deposit_requests()
in theBlockObserver
which otherwise had problems with type signatures (betweensigner
andsbtc
crates) and wouldn't use the failover functionality otherwise.BlockObserver
.Testing Information
Nothing specific, all existing tests pass and there are new tests testing the
ApiFallbackClient
s failover and retry functionality.Checklist: