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

chore(sdk): blanket impl Header for Block types #12660

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

emhane
Copy link
Member

@emhane emhane commented Nov 19, 2024

Ref #12575

Since we currently rely on Block type to deref to Header, this helper trait avoids explicitly having to insert block.header() everywhere with #12454

@emhane emhane added C-debt Refactor of code section that is hard to understand or maintain A-sdk Related to reth's use as a library labels Nov 19, 2024
@emhane emhane changed the title chore(sdk): blanket impl Header for Block types chore(sdk): blanket impl Header for Block types Nov 19, 2024
@emhane emhane requested review from mattsse and klkvr November 19, 2024 13:38
@@ -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 {
Copy link
Collaborator

@klkvr klkvr Nov 19, 2024

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?

Copy link
Member Author

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.

Copy link
Collaborator

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

Copy link
Member Author

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

Copy link
Member Author

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

Copy link
Member Author

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.

@emhane emhane requested a review from klkvr November 19, 2024 16:01
@@ -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 {
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sdk Related to reth's use as a library C-debt Refactor of code section that is hard to understand or maintain
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants