-
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
feat: make more block types generic #12812
base: main
Are you sure you want to change the base?
Conversation
@@ -144,7 +145,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> { | |||
for block in blocks.into_iter().rev() { | |||
let block_number = block.number; | |||
let sealed_block = block | |||
.try_seal_with_senders() | |||
.try_seal_with_senders::<<N::Primitives as NodePrimitives>::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.
.try_seal_with_senders::<<N::Primitives as NodePrimitives>::Block>() | |
.try_seal_with_senders::<BlockTy<N>>() |
add another type alias here for BlockTy
reth/crates/node/types/src/lib.rs
Lines 236 to 243 in 6695d07
/// Helper adapter type for accessing [`NodePrimitives::BlockHeader`] on [`NodeTypes`]. | |
pub type HeaderTy<N> = <<N as NodeTypes>::Primitives as NodePrimitives>::BlockHeader; | |
/// Helper adapter type for accessing [`NodePrimitives::BlockBody`] on [`NodeTypes`]. | |
pub type BodyTy<N> = <<N as NodeTypes>::Primitives as NodePrimitives>::BlockBody; | |
/// Helper adapter type for accessing [`NodePrimitives::SignedTx`] on [`NodeTypes`]. | |
pub type TxTy<N> = <<N as NodeTypes>::Primitives as NodePrimitives>::SignedTx; |
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.
updated in a587d19
crates/primitives/src/traits.rs
Outdated
/// Extension trait for [`reth_primitives_traits::Block`] implementations | ||
/// allowing for conversions into common block parts containers such as [`SealedBlock`], | ||
/// [`BlockWithSenders`], etc. | ||
pub trait BlockSealExt: 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.
this name is better as either BlockSeal
or BlockExt
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.
renamed to BlockExt
in d54846d
@@ -33,7 +33,7 @@ pub fn setup_without_evm<Provider>( | |||
where | |||
Provider: StaticFileProviderFactory | |||
+ StageCheckpointWriter | |||
+ BlockWriter<Body: reth_node_api::BlockBody>, | |||
+ BlockWriter<Block: reth_node_api::Block<Header = reth_primitives::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.
+ BlockWriter<Block: reth_node_api::Block<Header = reth_primitives::Header>>, | |
+ BlockWriter<BlockHeader = reth_primitives::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.
BlockWriter
doesn't have this AT
@@ -64,7 +64,8 @@ fn append_first_block<Provider>( | |||
total_difficulty: U256, | |||
) -> Result<(), eyre::Error> | |||
where | |||
Provider: BlockWriter<Body: reth_node_api::BlockBody> + StaticFileProviderFactory, | |||
Provider: BlockWriter<Block: reth_node_api::Block<Header = reth_primitives::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.
Provider: BlockWriter<Block: reth_node_api::Block<Header = reth_primitives::Header>> | |
Provider: BlockWriter<BlockHeader = reth_primitives::Header> |
crates/primitives/src/block.rs
Outdated
@@ -204,72 +152,83 @@ impl<'a> arbitrary::Arbitrary<'a> for Block { | |||
|
|||
/// Sealed block with senders recovered from transactions. | |||
#[derive(Debug, Clone, PartialEq, Eq, Default, Deref, DerefMut)] | |||
pub struct BlockWithSenders { | |||
pub struct BlockWithSenders<B: reth_primitives_traits::Block = 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.
pub struct BlockWithSenders<B: reth_primitives_traits::Block = Block> { | |
pub struct BlockWithSenders<B = Block> { |
it's always better to not constraint the generic in the type definition with a trait bound that implements a bunch of behaviour (ie trait methods), makes the code more flexible in testing
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.
updated in f7c301d
/// List of senders that match the transactions in the block | ||
pub senders: Vec<Address>, | ||
} | ||
|
||
impl BlockWithSenders { | ||
impl<B: reth_primitives_traits::Block> BlockWithSenders<B> { |
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.
9a090bf
to
94d8acd
Compare
Preparation for abstraction of block readers
Changes in this PR:
Block
struct are moved to a new extension traitBlockSealExt
which is implemented for everyBlock
trait implementations, allowing them to be called once we abstract the block typeBlockWriter
AT is changed fromBody
toBlock
BlockWithSenders
andSealedBlockWithSenders
are made generic over a singleB: Block
generic.SealedBlock
is still generic over both. This is a bit tricky to simplify because some of the networking components which construct blocks only know separate header and body types when constructingSealedBlock
, and converting those 2 generics to a single one would need an additional generic for those types. One of such components isBodiesDownloader
which usesBodiesRequestFuture
:reth/crates/net/downloaders/src/bodies/request.rs
Line 40 in f61a764
This issue doesn't apply to other components because they usually receive full blocks