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

Derive rlp en-/decoding for Sealed<T> #754

Closed
wants to merge 2 commits into from
Closed

Conversation

emhane
Copy link
Member

@emhane emhane commented Oct 4, 2024

Motivation

RLP encoding of Sealed<T>. Ref paradigmxyz/reth#11123.

Solution

Enables feature derive for alloy-rlp dep, to derive en-/decoding of Sealed<T>.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@emhane emhane added the debt Refactor of code section that is hard to understand or maintain label Oct 4, 2024
@@ -5,6 +5,7 @@ use crate::B256;
/// We do not implement any specific hashing algorithm here. Instead types
/// implement the [`Sealable`] trait to provide define their own hash.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "rlp", derive(alloy_rlp::RlpEncodable, alloy_rlp::RlpDecodable))]
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 this is useful because the hash is usually never included in any rlp payload if it can be computed from the sealed element

Copy link
Member Author

Choose a reason for hiding this comment

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

valid, pls open an issue in reth then to remove it from SealedBlock and SealedHeader

Copy link
Member

Choose a reason for hiding this comment

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

actually, I can see this being useful for decodeable where T: Sealable

@emhane emhane requested a review from mattsse October 4, 2024 17:02
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.

this is still problematic

we should treat this impl as a delegation:

https://github.com/paradigmxyz/reth/blob/093b1a16dfca2def7b1bf76cb12e554bbe7d967b/crates/primitives-traits/src/header/sealed.rs#L77-L100

if the seal is keccask(rlp) this would also allow us to specialize the decode impl but for this type we can't expect this to always be the case

@emhane
Copy link
Member Author

emhane commented Oct 5, 2024

this is still problematic

we should treat this impl as a delegation:

https://github.com/paradigmxyz/reth/blob/093b1a16dfca2def7b1bf76cb12e554bbe7d967b/crates/primitives-traits/src/header/sealed.rs#L77-L100

if the seal is keccask(rlp) this would also allow us to specialize the decode impl but for this type we can't expect this to always be the case

I see, the hash isn't rlp encoded in the buffer also, it's computed. to unblock this, we need to define a trait Seal, and an extension trait Keccak256Seal: Seal and update the sealed type to Sealed<T, S> + manual impl of rlp traits for Sealed<T, S: Keccak256Seal. proceed? I prefer this to cursing use of Sealed<T> to a wrapper type for rlp encoding impl, since most evm rollups will use the keccak256 seal.

@emhane emhane requested a review from mattsse October 5, 2024 17:43
@mattsse
Copy link
Member

mattsse commented Oct 5, 2024

hmm, after thinking about this a bit, I actually leaning towards not using the struct Sealed in reth because this comes with a few limitations, like we can't implement foreign traits on Sealed and always need to push them in here if we need them.

from reth pov, I wonder if something like trait Sealed would be more useful

@emhane
Copy link
Member Author

emhane commented Oct 5, 2024

hmm, after thinking about this a bit, I actually leaning towards not using the struct Sealed in reth because this comes with a few limitations, like we can't implement foreign traits on Sealed and always need to push them in here if we need them.

from reth pov, I wonder if something like trait Sealed would be more useful

imo it's good to have as an inner type nonetheless, with the "ethereum autotraits" being implemented, like rlp. rather skip rlp impl than not linking alloy and reth via this type.

@emhane emhane closed this Oct 7, 2024
@emhane emhane deleted the emhane/rlp-sealed branch October 7, 2024 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
debt Refactor of code section that is hard to understand or maintain
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants