-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
refactor: Adds type downcasting helpers for InvalidPoolTransactionError
#14046
refactor: Adds type downcasting helpers for InvalidPoolTransactionError
#14046
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.
yes, we want to generalise the impl body too
impl<T: PoolTransaction, E> TransactionValidationOutcome<T, E> { .. }
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.
hmm,
this error already supports arbitrary errors via
reth/crates/transaction-pool/src/error.rs
Lines 223 to 225 in d3cec5a
/// Any other error that occurred while inserting/validating that is transaction specific | |
#[error(transparent)] | |
Other(Box<dyn PoolTransactionError>), |
skeptical that it's worth integrating an error type
which I think would need to be added to
reth/crates/transaction-pool/src/pool/mod.rs
Line 132 in d3cec5a
pub struct PoolInner<V, T, S> |
rollups want to match on their error variants @mattsse . eventually all components that are customisable at sdk level should have an error associated type for good devx. |
what's a use case for this? |
do smthg based on the error variant |
can we add a helper that typechecking the dyn PollError instead, don't think a dedicated type for this is super useful |
sure rollups can work with down casting. though semantically it's nicer for the rollups to wrap l1 errors in a variant, so they can extend it. another place I'm having the same problem rn is |
I added this for now. |
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.
can we instead make this
reth/crates/transaction-pool/src/error.rs
Line 14 in 440e669
pub trait PoolTransactionError: core::error::Error + Send + Sync { |
`: Any``
and add
#[inline]
fn as_any(&self) -> &dyn std::any::Any;
to the trait?
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
actually @PanGan21 we probably don't need the additional Any fn if we require that this trait is 'static and add these helper functions to reth/crates/transaction-pool/src/error.rs Line 189 in 04c1d71
|
It seems that adding this:
would give and error about downcast method not found in |
ah yeah this is an issue with dyn trait and casting because the trait is actually there's let's start by adding |
CodSpeed Performance ReportMerging #14046 will not alter performanceComparing Summary
|
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.
smol naming nit, otherwise lgtm
crates/transaction-pool/src/error.rs
Outdated
|
||
/// Returns a reference to the [`InvalidPoolTransactionError::Other`] value if this type is a | ||
/// [`InvalidPoolTransactionError::Other`] of that type. Returns None otherwise. | ||
pub fn downcast_other<T: core::error::Error + 'static>(&self) -> Option<&T> { |
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.
pub fn downcast_other<T: core::error::Error + 'static>(&self) -> Option<&T> { | |
pub fn downcast_other_ref<T: core::error::Error + 'static>(&self) -> Option<&T> { |
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.
messed up naming on the other pr
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.
Done, trying to fix one last issue in is_other
, probably related to casting which i discovered from the unit tests
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.
Hi @mattsse . It seems that downcasting doesn't work as expected due to rust casting rules. Essentially as you said dyn PoolTransactionError
is recognized as core::error::Error + Send + Sync + 'static
from err.is::<T>
.
Any suggestion that this can be improved?
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.
what we can do is add an fn as_err(&self) &dyn Error
to the trait function itself and impl is just self, this way the type is responsible for the cast
can also be Any
instead of Error
like
fn as_err(&self) -> &dyn Error {
self
}
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 seems Any
did the trick, thanks!
TransactionValidationOutcome
generic over error typeInvalidPoolTransactionError
Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
Closes: #14037
Adds type downcasting helpers for
InvalidPoolTransactionError
.