-
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
feat: make more block types generic #12812
Conversation
@@ -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
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.
well seems like it should then. anywhere in there impl that a transaction is also used? we don't want to be using fully qualified syntax or yet another adapter there for no apparent reason. just use the AT Primitives: NodePrimitives
for now. BlockPrimitives
would make most sense.
@@ -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.
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.
unsure what benefits #12721 would bring here because this type is supposed to wrap the Block
9a090bf
to
94d8acd
Compare
@@ -44,7 +44,7 @@ where | |||
.ok_or(ProviderError::BlockBodyIndicesNotFound(block))?; | |||
|
|||
let mut transactions_cursor = provider.tx_ref().cursor_read::<tables::Transactions< | |||
<<Provider as StaticFileProviderFactory>::Primitives as NodePrimitives>::SignedTx, | |||
<Provider::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.
same here, use TxTy<Provider>
@@ -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.
well seems like it should then. anywhere in there impl that a transaction is also used? we don't want to be using fully qualified syntax or yet another adapter there for no apparent reason. just use the AT Primitives: NodePrimitives
for now. BlockPrimitives
would make most sense.
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.
cool, another big milestone
/// Create new block instance. | ||
fn new(header: Self::Header, body: Self::Body) -> 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.
this and split
makes sense because we expect that block consists of those two things
/// 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.
unsure what benefits #12721 would bring here because this type is supposed to wrap the Block
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