-
Notifications
You must be signed in to change notification settings - Fork 4
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
Sergerad/batch provider impl #49
base: main
Are you sure you want to change the base?
Conversation
crates/protocol/src/batch/traits.rs
Outdated
|
||
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))] | ||
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)] | ||
impl<N, T, P> BatchValidationProvider<N, T> for P | ||
where | ||
N: Network, | ||
T: Transport + Clone, | ||
P: Provider<T, N>, | ||
{ | ||
type Error = TransportError; | ||
|
||
async fn l2_block_info_by_number(&mut self, number: u64) -> Result<L2BlockInfo, Self::Error> { | ||
// TODO: Actual request + logic | ||
self.client().request("eth_getBlockByNumber", (number,)).await | ||
} | ||
|
||
async fn block_by_number(&mut self, number: u64) -> Result<OpBlock, Self::Error> { | ||
// TODO: Actual request + logic | ||
self.client().request("eth_getBlockByNumber", (number, true)).await | ||
} | ||
} |
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 reason why the BatchValidationProvider
trait is defined here is to abstract away the provider logic from the protocol crate. That allows for any downstream consumers of the maili-protocol
crate to define their own way of providing this data fetching. For example, BatchValidationProvider
is implemented for the provider that is used when validating batches. Let me know if this makes sense!
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.
Thanks @refcell that makes a lot of sense. I see now the issue description was clear about implementing the trait for ReqwestProvider
. Have pushed a small change to that effect impl BatchValidationProvider for alloy_provider::ReqwestProvider {
.
Will proceed with the rest of the implementation later today.
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.
Got it thanks for clarifying. I'm supportive of these changes, but can we move this implementation into a reqwest.rs
file, and hide the module behind a reqwest
feature flag?
e.g. in lib.rs
we could do the following.
...
#[cfg(feature = "reqwest")]
pub mod reqwest;
...
crates/protocol/src/batch/traits.rs
Outdated
let block = block.unwrap(); // TODO: handle error | ||
|
||
// Convert the transactions. | ||
// TODO: how/what do we actually need to do here? |
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.
@refcell Could you please advise the canonical approach to getting the OpBlock
type from the results returned from alloy::Provider
fns like get_block_by_number()
(used above). Main issue here is converting from the vec of transactions returned by the provider into OpTxEnvelope
enum. Couldn't find any relevant from
impls.
Or if there is an alternative means to performing the requests here. I looked at how Kona uses ReqwestProvider
and found that it did provider.client().request("debug_* ...
style requests for headers etc. Unsure if that is a relevant approach here.
TY!
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 crate isn't longer depending on op-allloy. merged main into your branch to reflect these changes. either it's enough to use the local maili_consensus::DepsoitTxEnvelope
trait. otherwise if you have to deal with other transaction types specifically, this pr is blocked by alloy-rs/alloy#1910.
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.
Thanks @emhane for that. I have pushed up a Reqwest impl for the BatchValidationProvider trait. I am guessing that this impl should be able to return more than just deposit txns which would mean it depends on your PR you linked there as you say.
If the intention is to only support deposit txns, then I still don't know how to convert between the eth rpc tx types and a tx type that the user of the Reqwest impl would expect.
I have left TODOs on the relevant lines. There are also TODOs for 2 fields I lack in order to construct the L2BlockInfo, LMK if you have any insight on that too.
TY!
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.
getting there!
crates/protocol/src/reqwest.rs
Outdated
let l1_origin = (block.header.number, block.header.hash); // TODO: We don't have valid values | ||
// for this or access to genesis for | ||
// L2BlockInfo::from_block_and_genesis(). | ||
let seq_num = 0u64; // TODO: We don't have this value either. |
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.
@refcell appreciate your input here
crates/protocol/src/reqwest.rs
Outdated
errors::ReqwestBatchValidationProviderError, BatchValidationProvider, BlockInfo, L2BlockInfo, | ||
}; | ||
|
||
struct ReqwestBatchValidationProvider<T, P = alloy_provider::ReqwestProvider> { |
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.
struct ReqwestBatchValidationProvider<T, P = alloy_provider::ReqwestProvider> { | |
struct ReqwestBatchValidationProvider<T, N: Network<TxEnvelope = T>, P = alloy_provider::ReqwestProvider<N>> { |
alloy_network::Network
crates/protocol/src/reqwest.rs
Outdated
errors::ReqwestBatchValidationProviderError, BatchValidationProvider, BlockInfo, L2BlockInfo, | ||
}; | ||
|
||
struct ReqwestBatchValidationProvider<T, P = alloy_provider::ReqwestProvider> { |
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.
make this type public please also. you never known completely how other devs want to use your library and shouldn't limit them to explore new things by keeping types private. open-source philosophy :)
e00e1a5
to
4b0dab0
Compare
@emhane @refcell just summarizing latest state of the PR
Thanks! |
would it be enough with adding the trait bound |
581c4eb
to
8bc5bb7
Compare
8bc5bb7
to
e7d11ac
Compare
@emhane @refcell I have rebased from the latest changes (this commit having changed the trait). Which has simplified the impl I think. But I'm wondering if there is a canonical conversion between these two types that you could point me to (I need to return
Ignore the vec in that message - in an ideal world would do I have checked the Thanks! |
sorry there has been a lot of rebuilding here lately, perhaps makes sense to let this pr sleep for a week or so then check in again |
Motivation
Closes #18
Solution
WIP
PR Checklist