-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Closed
+196
−9
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9788e5b
Blanket impl Header for Block types
emhane a45b891
Merge branch 'main' into emhane/block-header
emhane 9d0cd2c
Fix lint
emhane 077aeb6
Fix lint
emhane f21f5f4
Add no_std support for reth-optimism-primitives
emhane a11c59c
Fix deps
emhane cdebd41
Use Header without symbol in reth_primitives_traits::block_prelude
emhane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
use core::fmt; | ||
|
||
use alloy_primitives::Sealable; | ||
use alloy_primitives::{Address, BlockNumber, Bloom, Bytes, Sealable, B256, B64, U256}; | ||
use reth_codecs::Compact; | ||
|
||
use crate::{InMemorySize, MaybeSerde}; | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. introducing a new trait just for this feels like weird to me |
||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn parent_hash(&self) -> B256; | ||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn ommers_hash(&self) -> B256; | ||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn beneficiary(&self) -> Address; | ||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn state_root(&self) -> B256; | ||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn transactions_root(&self) -> B256; | ||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn receipts_root(&self) -> B256; | ||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn withdrawals_root(&self) -> Option<B256>; | ||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn logs_bloom(&self) -> Bloom; | ||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn difficulty(&self) -> U256; | ||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn number(&self) -> BlockNumber; | ||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn gas_limit(&self) -> u64; | ||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn gas_used(&self) -> u64; | ||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn timestamp(&self) -> u64; | ||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn mix_hash(&self) -> Option<B256>; | ||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn nonce(&self) -> Option<B64>; | ||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn base_fee_per_gas(&self) -> Option<u64>; | ||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn blob_gas_used(&self) -> Option<u64>; | ||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn excess_blob_gas(&self) -> Option<u64>; | ||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn parent_beacon_block_root(&self) -> Option<B256>; | ||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn requests_hash(&self) -> Option<B256>; | ||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn extra_data(&self) -> &Bytes; | ||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn next_block_excess_blob_gas(&self) -> Option<u64>; | ||
/// See [`alloy_consensus::BlockHeader`]. | ||
fn next_block_blob_fee(&self) -> Option<u128>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 implementationsalthough doing
block.header().number()
is not that bad imoThere 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.