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

Conversation

refcell
Copy link
Contributor

@refcell refcell commented Sep 20, 2024

Description

Introduces a Block type for the alloy-consensus crate. See #1290

/// 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

/// Taken from [reth-primitives](https://github.com/paradigmxyz/reth)
#[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

crates/consensus/src/block.rs Outdated Show resolved Hide resolved
Copy link
Member

@emhane emhane left a comment

Choose a reason for hiding this comment

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

wondering if the en-/decoding of requests is a bit out of scope?

crates/consensus/src/request.rs Outdated Show resolved Hide resolved
Copy link
Member

@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.

suggestions

/// Taken from [reth-primitives](https://github.com/paradigmxyz/reth)
#[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.

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

Comment on lines +11 to +15
/// 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)
Copy link
Member

Choose a reason for hiding this comment

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

@refcell
Copy link
Contributor Author

refcell commented Sep 23, 2024

Think I've added what you're asking for but LMK if I'm missing something :)

/// 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

@mattsse mattsse merged commit cf9a98f into alloy-rs:main Sep 24, 2024
26 checks passed
lwedge99 pushed a commit to sentioxyz/alloy that referenced this pull request Oct 8, 2024
* feat: consensus block type

* fix: block type

* fix: block type

* alloc vec

* bind to 2718 as well

* fix: add requests

* fix: remove 2718 encodables, docs

* manual rlp

---------

Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants