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

feat: make more block types generic #12812

Merged
merged 7 commits into from
Nov 25, 2024
Merged

feat: make more block types generic #12812

merged 7 commits into from
Nov 25, 2024

Conversation

klkvr
Copy link
Collaborator

@klkvr klkvr commented Nov 23, 2024

Preparation for abstraction of block readers

Changes in this PR:

  • Methods from Block struct are moved to a new extension trait BlockSealExt which is implemented for every Block trait implementations, allowing them to be called once we abstract the block type
  • BlockWriter AT is changed from Body to Block
  • BlockWithSenders and SealedBlockWithSenders are made generic over a single B: 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 constructing SealedBlock, and converting those 2 generics to a single one would need an additional generic for those types. One of such components is BodiesDownloader which uses BodiesRequestFuture:
    pub(crate) struct BodiesRequestFuture<B: BodiesClient> {

This issue doesn't apply to other components because they usually receive full blocks

bin/reth/src/commands/debug_cmd/merkle.rs Outdated Show resolved Hide resolved
crates/primitives/src/traits.rs Outdated Show resolved Hide resolved
@@ -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>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
+ BlockWriter<Block: reth_node_api::Block<Header = reth_primitives::Header>>,
+ BlockWriter<BlockHeader = reth_primitives::Header>,

Copy link
Collaborator Author

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

Copy link
Member

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>>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Provider: BlockWriter<Block: reth_node_api::Block<Header = reth_primitives::Header>>
Provider: BlockWriter<BlockHeader = reth_primitives::Header>

@@ -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> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Collaborator Author

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> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BlockPrimitives would have been ideal here, then you have the transaction type accessible without fully qualified syntax and without making yet another adapter type
#12721 @mattsse

Copy link
Collaborator

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

@klkvr klkvr force-pushed the klkvr/generic-blocks branch from 9a090bf to 94d8acd Compare November 25, 2024 00:01
@klkvr klkvr mentioned this pull request Nov 25, 2024
emhane
emhane previously requested changes Nov 25, 2024
@@ -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,
Copy link
Member

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>>,
Copy link
Member

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.

Copy link
Collaborator

@mattsse mattsse left a 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

Comment on lines +49 to 51
/// Create new block instance.
fn new(header: Self::Header, body: Self::Body) -> Self;

Copy link
Collaborator

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> {
Copy link
Collaborator

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

@mattsse mattsse added C-enhancement New feature or request A-sdk Related to reth's use as a library labels Nov 25, 2024
@mattsse mattsse dismissed emhane’s stale review November 25, 2024 10:50

marking as completed

@mattsse mattsse added this pull request to the merge queue Nov 25, 2024
Merged via the queue into main with commit dcaa06a Nov 25, 2024
41 checks passed
@mattsse mattsse deleted the klkvr/generic-blocks branch November 25, 2024 11:13
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-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants