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(consensus): Generic Block Type #1319

Merged
merged 9 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions crates/consensus/src/block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//! Genesic Block Type

use crate::Header;
use alloc::vec::Vec;
use alloy_eips::eip4895::Withdrawal;
use alloy_eips::eip2718::{Encodable2718, Decodable2718};
use alloy_rlp::{Decodable, Encodable, RlpDecodable, RlpEncodable};

/// Ethereum full block.
///
/// Withdrawals can be optionally included at the end of the RLP encoded message.
///
/// Taken from [reth-primitives](https://github.com/paradigmxyz/reth)
Comment on lines +8 to +12
Copy link
Member

Choose a reason for hiding this comment

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

#[derive(Debug, Clone, PartialEq, Eq, Default, RlpEncodable, RlpDecodable)]
#[rlp(trailing)]
pub struct Block<T: Encodable + Decodable + Encodable2718 + Decodable2718> {
Copy link
Member

Choose a reason for hiding this comment

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

same

Copy link
Member

Choose a reason for hiding this comment

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

this should only use Encodable + Decodable

and it is expected that this is equivalent to

fn network_encode(&self, out: &mut dyn BufMut) {

see:

impl Encodable for TxEnvelope {
fn encode(&self, out: &mut dyn alloy_rlp::BufMut) {
self.network_encode(out)
}

because this type is the p2p type

/// Block header.
pub header: Header,
/// Block body.
#[rlp(flatten)]
Copy link
Member

Choose a reason for hiding this comment

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

I don't think #[rlp(flatten)] works? this should probably be manual impl instead

pub body: BlockBody<T>,
}

/// A block body.
#[derive(Debug, Clone, PartialEq, Eq, Default, RlpEncodable, RlpDecodable)]
#[rlp(trailing)]
pub struct BlockBody<T: Encodable + Decodable + Encodable2718 + Decodable2718> {
Copy link
Member

Choose a reason for hiding this comment

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

let's not require anything here

Copy link
Contributor Author

@refcell refcell Sep 23, 2024

Choose a reason for hiding this comment

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

I think we need Encodable + Decodable for the RlpEncodable, RlpDecodable auto-derive above right?

Copy link
Member

Choose a reason for hiding this comment

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

I see

Copy link
Member

Choose a reason for hiding this comment

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

hmm, I don't think it's needed? those derives will add bounds for respective impl blocks

/// Transactions in this block.
pub transactions: Vec<T>,
/// Ommers/uncles header.
pub ommers: Vec<Header>,
/// Block withdrawals.
pub withdrawals: Option<Vec<Withdrawal>>,
// TODO: add request with rlp encoding support
refcell marked this conversation as resolved.
Show resolved Hide resolved
}
3 changes: 3 additions & 0 deletions crates/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ extern crate alloc;
mod account;
pub use account::Account;

mod block;
pub use block::{Block, BlockBody};

pub mod constants;

mod encodable_signature;
Expand Down
Loading