Skip to content
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

Merged

Conversation

lakshya-sky
Copy link
Contributor

  • Add an associated type for TransactionCompact and use it for fill return type.

Closes #12020

Copy link
Member

@emhane emhane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good

crates/optimism/rpc/src/eth/transaction.rs Outdated Show resolved Hide resolved
crates/rpc/rpc-types-compat/src/transaction/mod.rs Outdated Show resolved Hide resolved
crates/optimism/rpc/src/eth/transaction.rs Outdated Show resolved Hide resolved
crates/optimism/rpc/src/eth/transaction.rs Outdated Show resolved Hide resolved
crates/optimism/rpc/src/eth/transaction.rs Outdated Show resolved Hide resolved
crates/rpc/rpc-types-compat/src/transaction/mod.rs Outdated Show resolved Hide resolved
crates/rpc/rpc-types-compat/src/transaction/mod.rs Outdated Show resolved Hide resolved
crates/rpc/rpc-types-compat/src/transaction/mod.rs Outdated Show resolved Hide resolved
crates/rpc/rpc-types-compat/src/transaction/mod.rs Outdated Show resolved Hide resolved
@lakshya-sky
Copy link
Contributor Author

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 expect at those places. If you could let me know which error variant is best? Thank you!

Copy link
Member

@emhane emhane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice progress!

crates/rpc/rpc-eth-api/src/core.rs Outdated Show resolved Hide resolved
* Add an associated type for `TransactionCompact` and use it for `fill`
  return type.
@lakshya-sky lakshya-sky force-pushed the result-for-transaction-compact-fill branch from c90a97b to 52e731d Compare November 4, 2024 16:24
@lakshya-sky
Copy link
Contributor Author

lakshya-sky commented Nov 5, 2024

@emhane your previous commit helped me understand the issue correctly. You're a Rockstar! 🌟

Copy link
Member

@emhane emhane left a 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");
Copy link
Member

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.

Rjected
Rjected previously requested changes Nov 6, 2024
Copy link
Member

@Rjected Rjected left a 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;
Copy link
Member

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?

Copy link
Member

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

Copy link
Member

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?

Comment on lines 505 to 507
.map(|tx| tx.into_transaction(self.tx_resp_builder()))
.transpose()
.map_err(|err| internal_rpc_err(format!("failed to convert transaction: {}", err)))?)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Member

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>,

Copy link
Member

@emhane emhane left a 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/optimism/rpc/src/eth/transaction.rs Outdated Show resolved Hide resolved
))
pending_txs.push(
from_recovered(tx.transaction.to_recovered_transaction(), &self.tx_resp_builder)
.expect("fill should be infallible"),
Copy link
Member

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

Copy link
Contributor Author

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).

tx.transaction.to_recovered_transaction(),
&tx_resp_builder,
)
.expect("fill should be infallible"),
Copy link
Member

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

Copy link
Contributor Author

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.

crates/rpc/rpc/src/txpool.rs Outdated Show resolved Hide resolved
crates/rpc/rpc-types-compat/src/transaction/mod.rs Outdated Show resolved Hide resolved
@@ -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");
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

@emhane emhane Nov 10, 2024

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

crates/optimism/rpc/src/eth/transaction.rs Outdated Show resolved Hide resolved
crates/optimism/rpc/src/error.rs Outdated Show resolved Hide resolved
Copy link
Member

@emhane emhane left a 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");
Copy link
Member

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.

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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Comment on lines 149 to 162
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)
Copy link
Member

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 emhane added this pull request to the merge queue Nov 12, 2024
Merged via the queue into paradigmxyz:main with commit bad7a4f Nov 12, 2024
41 checks passed
@lakshya-sky
Copy link
Contributor Author

@emhane you fixed this succinctly! Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Return result from TransactionCompat::fill
3 participants