-
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
chore(sdk): blanket impl Header
for Block
types
#12660
base: main
Are you sure you want to change the base?
Conversation
Header
for Block typesHeader
for Block
types
@@ -49,3 +49,53 @@ impl<T> BlockHeader for T where | |||
+ MaybeSerde | |||
{ | |||
} | |||
|
|||
/// Helper trait to implement [`BlockHeader`] functionality for all [`Block`](crate::Block) types. | |||
pub trait Header { |
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.
isn't this identical to alloy_consensus::Header
?
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. not possible to impl foreign trait for generic T: Block
.
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.
if this really simplifies things a lot I'd prefer those as Block
trait methods with default implementations
although doing block.header().number()
is not that bad imo
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.
if you default impl these, you lose the ability to inline them afaik. would inline all getters, ref alloy-rs/alloy#1642
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.
but sure, can have identical trait methods on Block
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 whole point though is for rollups to have to avoid implementing lots of boilerplate code.
there is a reason we avoided calling .header()
everywhere in the original code I believe.
77326fb
to
cdebd41
Compare
@@ -49,3 +49,53 @@ impl<T> BlockHeader for T where | |||
+ MaybeSerde | |||
{ | |||
} | |||
|
|||
/// Helper trait to implement [`BlockHeader`] functionality for all [`Block`](crate::Block) types. | |||
pub trait Header { |
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.
introducing a new trait just for this feels like weird to me
Ref #12575
Since we currently rely on
Block
type to deref toHeader
, this helper trait avoids explicitly having to insertblock.header()
everywhere with #12454