-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat(backend): add support for arbitrary provider requests with AnyRequest #32
feat(backend): add support for arbitrary provider requests with AnyRequest #32
Conversation
add in-memory provider test
4601be7
to
1647268
Compare
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,
this doesn't hurt,
I think what we could do is adding support for caching arbitrary endpoint data, so that the bytecode responses get cached
pub fn do_any_request<T, F>(&mut self, fut: F) -> DatabaseResult<T> | ||
where | ||
F: Future<Output = Result<T, eyre::Report>> + Send + 'static, | ||
T: fmt::Debug + Send + 'static, | ||
{ | ||
self.blocking_mode.run(|| { | ||
let (sender, rx) = oneshot_channel::<Result<T, eyre::Report>>(); | ||
let req = BackendRequest::AnyRequest(Box::new(AnyRequestFuture { | ||
sender, | ||
future: Box::pin(fut), | ||
})); | ||
self.backend.unbounded_send(req)?; | ||
rx.recv()?.map_err(|err| DatabaseError::AnyRequest(Arc::new(err))) | ||
}) | ||
} |
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.
the way this is implemented kinda acts as tokio::Handle::block_on
but it sends the request to the async backend, I think this could be quite useful, especially if we extend this with caching functionality, because rn this does not persist cache the responses.
we can add this feature separately though
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.
Will follow-up accordingly.
trait WrappedAnyRequest: Unpin + Send + fmt::Debug { | ||
fn poll_inner(&mut self, cx: &mut Context<'_>) -> Poll<()>; | ||
} |
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 see, this is basically a helper, alternatively we could use BoxFuture, but this would require a manual debug impl on the request enum, so this seems fine
Motivation
SharedBackend
to support diverse use casesfoundry-fork-db
. For example,foundry-zksync
is currently using a fork of this repo for its own needs, specifically implementsZkSyncMiddleware
to facilitate bytecode retrieval viazks_getBytecodeByHash
. These changes will eliminate the necessity of that fork while also serving other parties needs outside offoundry-zksync
.Solution
src/backend.rs
: Added theAnyRequestFuture
struct and implemented theWrappedAnyRequest
trait to handle arbitrary requests.src/backend.rs
: Updated theProviderRequest
andBackendRequest
enums to include theAnyRequest
variant.src/backend.rs
: Modified theSharedBackend
struct to include thedo_any_request
method for executing arbitrary requests.src/error.rs
: Added theAnyRequest
variant to theDatabaseError
enum for error handling.shared_backend_any_request
for verifying the arbitrary request handling feature. This test spins up an in-memory HTTP server to simulate requests.PR Checklist