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

primitives: use alloy Header struct #10691

Merged
merged 16 commits into from
Sep 23, 2024
Merged

Conversation

@tcoratger
Copy link
Contributor Author

I think that we should revise the types in alloy to transform all u128 to u64 to limit the conversions and be fully aligned between alloy and reth. Maybe we could do that in a follow up PR in alloy if there are no limitations about this on alloy side?

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.

the casts are indeed excessive and we should change them in alloy, because only u64 are useful here

wdyt @klkvr

Comment on lines 119 to 122
self.headers.get(&self.max_block()?).map(|h| {
let sealed = h.clone().seal_slow();
SealedHeader::new(sealed.inner().clone(), sealed.seal())
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

why does this have to be changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because in alloy seal_slow returns a generic Sealed<T> type which is different from the SealedHeader that we have in reth. So that to be compatible with reth at the moment we have to reconstruct a reth SealedHeader from the alloy Sealed<Header> type.

But I'm thinking about a follow up PR to replace our reth SealedHeader by the alloy Sealed<Header> primitive wdyt?

Copy link
Collaborator

@mattsse mattsse Sep 7, 2024

Choose a reason for hiding this comment

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

this now has an additional clone, this is not great and looks just weird.
we don't need the seal function here if we only need the hash

Copy link
Collaborator

Choose a reason for hiding this comment

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

this can also be solved with a SealedHeader:: seal(Header) function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe to reduce overhead, what would you say to replace also in this PR SealedHeader by alloy Sealed type?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
self.headers.get(&self.max_block()?).map(|h| {
let sealed = h.clone().seal_slow();
SealedHeader::new(sealed.inner().clone(), sealed.seal())
})
self.headers.get(&self.max_block()?).map(|h| {
let sealed = h.clone().seal_slow();
let (header, seal) = sealed.into_parts();
SealedHeader::new(header, seal);
})

I think we can just do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just fixed this but I think that in a follow up we can simply rm SealedHeader from reth and use Sealed instead, it will simplify everything no?

crates/net/downloaders/src/headers/reverse_headers.rs Outdated Show resolved Hide resolved
@tcoratger
Copy link
Contributor Author

the casts are indeed excessive and we should change them in alloy, because only u64 are useful here

wdyt @klkvr

@mattsse Yeah related alloy-rs/alloy#1241 cc @greged93

@klkvr
Copy link
Collaborator

klkvr commented Sep 7, 2024

the casts are indeed excessive and we should change them in alloy, because only u64 are useful here

agreed, we should definitely unify all of this, there's no point in u128 as revm uses u64 anyway, wondering if there's a spec for gas value type?

@tcoratger
Copy link
Contributor Author

the casts are indeed excessive and we should change them in alloy, because only u64 are useful here

agreed, we should definitely unify all of this, there's no point in u128 as revm uses u64 anyway, wondering if there's a spec for gas value type?

@klkvr If you validate alloy-rs/alloy#1241 (please can you comment there to be sure this is accepted), me or @greged93 can start working on this :)

@tcoratger tcoratger marked this pull request as ready for review September 10, 2024 16:13
@tcoratger
Copy link
Contributor Author

@klkvr @mattsse In my opinion:

  • We have way too many conversions here (it's not avoidable in the current state). In my opinion we should first merge this PR to get through this big part and then directly after follow up on [Feature] Make some gas fields u64 for Header alloy-rs/alloy#1241 to have a clear consensus on the types u64 vs u128.
  • Then we should also do a follow up to remove SealedHeader from the repo and use the alloy type Sealed<Header> in order to remove the unnecessary lines of code to convert a Sealed<Header> to SealedHeader each time (but if we do it in this PR it will be way too long).

@emhane
Copy link
Member

emhane commented Sep 20, 2024

need help fixing merge conflicts @tcoratger ? all for removing redundancy, think it will be brilliant

@tcoratger
Copy link
Contributor Author

need help fixing merge conflicts @tcoratger ? all for removing redundancy, think it will be brilliant

@emhane No worries, I think I can handle it. Can you provide just an overview review to confirm that everything (the approach, the conversion handling...) is good so that directly after solving conflicts we can merge and avoid further conflicts?

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.

lgtm

@tcoratger
Copy link
Contributor Author

@emhane @mattsse Should be good now, can we merge asap? so that we don't have to handle additional conflicts because a lot of files are involved so that this is very easy to generate new conflicts :)

Comment on lines +602 to +604
let sealed = header.seal_slow();
let (header, seal) = sealed.into_parts();
sealed_header = SealedHeader::new(header, seal);
Copy link
Member

Choose a reason for hiding this comment

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

pls open issue if one doesn't exist to remove SealedHeader in favour of alloy Sealed as you suggested, to avoid these conversions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done #11123

@emhane emhane added this pull request to the merge queue Sep 23, 2024
Merged via the queue into paradigmxyz:main with commit ed1de89 Sep 23, 2024
36 checks passed
0xForerunner pushed a commit to 0xForerunner/reth that referenced this pull request Sep 25, 2024
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.

Replace reth-primitives header type with alloy::consensus
4 participants