-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
use result for TransactionCompact::fill
.
#12170
use result for TransactionCompact::fill
.
#12170
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.
looking good
hey @emhane, I tried to fix the suggestions but a lot places needs error conversions, which might require a little context, so I've used |
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.
nice progress!
* Add an associated type for `TransactionCompact` and use it for `fill` return type.
c90a97b
to
52e731d
Compare
@emhane your previous commit helped me understand the issue correctly. You're a Rockstar! 🌟 |
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.
still a bit to go!
let signed_tx = tx.clone().into_signed(); | ||
let hash = tx.hash; | ||
|
||
let mut inner = EthTxBuilder.fill(tx, tx_info); | ||
let mut inner = | ||
EthTxBuilder.fill(tx, tx_info).expect("EthTxBuilder.fill should be infallible"); |
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.
only this call to fill can be expected to be infallible. all the other expect statements need to be removed.
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.
just one comment
@@ -20,11 +21,13 @@ where | |||
{ | |||
type Transaction = <Ethereum as Network>::TransactionResponse; | |||
|
|||
type TransactionError = EthApiError; |
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 can be the Infallible
type right?
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.
it can, and was initially set to infallible by @lakshya-sky . however it became complicated converting the error to an EthApiError
and OpEthApiError
in order to propagate it, it required explicit trait bounds for the conversion all over the place and got very messy
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.
hmmm, I see, I'm assuming it wasn't as easy as unwrapping when this was called at a higher level?
crates/rpc/rpc-eth-api/src/core.rs
Outdated
.map(|tx| tx.into_transaction(self.tx_resp_builder())) | ||
.transpose() | ||
.map_err(|err| internal_rpc_err(format!("failed to convert transaction: {}", 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.
.map(|tx| tx.into_transaction(self.tx_resp_builder())) | |
.transpose() | |
.map_err(|err| internal_rpc_err(format!("failed to convert transaction: {}", err)))?) | |
.map(|tx| tx.into_transaction(self.tx_resp_builder())) | |
.transpose()? |
doesn't this work?
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 couldn't get this to work. no matter what I try its not able to convert the error types.
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'll try again later to see if I can fix that.
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.
hm ok, perhaps you must explicitly add the trait bound on the trait impl in that case, smthg like
impl<T>
EthApiServer<
RpcTransaction<T::NetworkTypes>,
RpcBlock<T::NetworkTypes>,
RpcReceipt<T::NetworkTypes>,
> for T
where
T: FullEthApi,
jsonrpsee_types::error::ErrorObject<'static>: From<T::Error>,
jsonrpsee_types::error::ErrorObject<'static>: From<<T::TransactionCompat as TransactionCompat>::TransactionError>,
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.
nice progress, getting close to done
crates/rpc/rpc/src/eth/filter.rs
Outdated
)) | ||
pending_txs.push( | ||
from_recovered(tx.transaction.to_recovered_transaction(), &self.tx_resp_builder) | ||
.expect("fill should be infallible"), |
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 expect still needs to go
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've removed the expect and tried logging the error so that it doesn't become nightmare to propagate the error.(I tried propagating it first but requires changing a lot of types).
crates/rpc/rpc/src/eth/pubsub.rs
Outdated
tx.transaction.to_recovered_transaction(), | ||
&tx_resp_builder, | ||
) | ||
.expect("fill should be infallible"), |
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 expect still needs to go
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.
Here also I've tried to log the error, otherwise it requires TransactionCompat::Error : Serialize + Send
, which is something I don't know how to do.
@@ -88,7 +88,8 @@ pub fn from_block_full<T: TransactionCompat>( | |||
|
|||
from_recovered_with_block_context::<T>(signed_tx_ec_recovered, tx_info, tx_resp_builder) | |||
}) | |||
.collect::<Vec<_>>(); | |||
.collect::<Result<Vec<_>, T::TransactionError>>() | |||
.expect("fill should be infallible"); |
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 expect still needs to go
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.
For this one what do you think is the best idea? I was thinking to add TransactionCompatError
inside alloy_rpc_eth::BlockError
and maping the error to BlockError
. Which would require making a pr to alloy.
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.
yes indeed it does require a pr to alloy, you're right. suggest making a pr to alloy adding error variant BlockError::Custom(Box<dyn Error>)
or BlockError::Custom(String)
- would you please open the pr?
not to block this pr until next alloy release, let's log the error here, and would you please open an issue to propagate the error here instead when the alloy change is available.
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.
actually makes most sense to change the signature of from_block_full
to return TransactionCompat::Error
, and add trait bound From<BlockError>
to the associated type
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.
great job!
@@ -88,7 +88,8 @@ pub fn from_block_full<T: TransactionCompat>( | |||
|
|||
from_recovered_with_block_context::<T>(signed_tx_ec_recovered, tx_info, tx_resp_builder) | |||
}) | |||
.collect::<Vec<_>>(); | |||
.collect::<Result<Vec<_>, T::TransactionError>>() | |||
.expect("fill should be infallible"); |
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.
yes indeed it does require a pr to alloy, you're right. suggest making a pr to alloy adding error variant BlockError::Custom(Box<dyn Error>)
or BlockError::Custom(String)
- would you please open the pr?
not to block this pr until next alloy release, let's log the error here, and would you please open an issue to propagate the error here instead when the alloy change is available.
crates/rpc/rpc/src/eth/filter.rs
Outdated
match from_recovered(tx.transaction.to_recovered_transaction(), &self.tx_resp_builder) { | ||
Ok(tx) => pending_txs.push(tx), | ||
Err(err) => { | ||
error!(target: "rpc", %err, "Failed to fill txn with block context"); |
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.
error!(target: "rpc", %err, "Failed to fill txn with block context"); | |
error!(target: "rpc::filter", %err, "Failed to fill txn with block context"); |
nitpick, makes the target more helpful
nonetheless, this error should be propagated, but can be handled separately, could you please open an issue
crates/rpc/rpc/src/eth/pubsub.rs
Outdated
let stream = pubsub | ||
.full_pending_transaction_stream() | ||
.filter_map(|tx| { | ||
let tx_value = match from_recovered( | ||
tx.transaction.to_recovered_transaction(), | ||
&tx_resp_builder, | ||
){ | ||
Ok(tx) => Some(EthSubscriptionResult::FullTransaction(Box::new(tx))), | ||
Err(err) => { | ||
tracing::error!(target = "rpc", %err, "Failed to fill transaction with block context"); | ||
None | ||
} | ||
}; | ||
std::future::ready(tx_value) |
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.
same here, this error should be propagated, or, sent as a message i.e. add new variant SubscriptionMessageInner::Error(Box<dyn Error>)
. please open an issue.
@emhane you fixed this succinctly! Cheers! |
TransactionCompact
and use it forfill
return type.Closes #12020