Skip to content

Make Node Types: Clone #14351

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

Closed

Conversation

Cyber-Mitch
Copy link
Contributor

@Cyber-Mitch Cyber-Mitch commented Feb 9, 2025

Make NodeTypes: Clone

Description

The NodeTypes trait and its implementations are used extensively in the codebase, particularly when restricting trait bounds or using associated types. Since NodeTypes is intended to be stateless and only defines types, it should implement the Clone trait to make it easier to derive Clone for types that use NodeTypes.

Issue

The NodeTypes trait and its implementations did not implement the Clone trait.

Solutions Snippet

  1. Add Clone to the NodeTypes trait definition:

    pub trait NodeTypes: Clone + Send + Sync + Unpin + 'static {
        // ...
    }

@mattsse closes #14345

@Cyber-Mitch Cyber-Mitch changed the title Make Node Types; Clone Make Node Types: Clone Feb 9, 2025
@mattsse
Copy link
Collaborator

mattsse commented Feb 10, 2025

still some failing tests

@Cyber-Mitch
Copy link
Contributor Author

Cyber-Mitch commented Feb 10, 2025

still some failing tests

Yes i noticed. I was able to finally get make pr to work and i got some errors in files where the clone has to be also implemented, so i made few modifications to it be deriving clone. especially in the commiments.rs file. Every thing is done now, I just ran the command make pr command again. And there's a particular test taking long. This one benches/state_root_task.rs so when that is done i will commit and push the recent changes just give me a little time. @mattsse

@emhane emhane added the A-sdk Related to reth's use as a library label Feb 10, 2025
@Cyber-Mitch
Copy link
Contributor Author

Cyber-Mitch commented Feb 10, 2025

The make pr command is till running this benches/state_root_task.rs I don't know why it's taking time @mattsse but i just commited and push the changes i made due to the previous errors, i ran cargo nextest run and build and passed all test and was nolonger throwing errors, but the issue here is make pr command is still running. but i think you can run the test from your end again it should pass this time

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.

a few more nits

@@ -79,7 +79,7 @@ impl<Types, DB> Clone for NodeTypesWithDBAdapter<Types, DB> {

impl<Types, DB> NodeTypes for NodeTypesWithDBAdapter<Types, DB>
where
Types: NodeTypes,
Types: NodeTypes + Clone,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think these are now redundant NodeTypes + Clone because NodeTypes already implies Clone

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh okay

Comment on lines 211 to 215
P: NodePrimitives + Send + Sync + Unpin + 'static + Clone,
E: EngineTypes + Send + Sync + Unpin + Clone,
C: EthChainSpec<Header = P::BlockHeader> + 'static + Clone,
SC: StateCommitment + Clone,
S: Default + Send + Sync + Unpin + Debug + 'static + Clone,
Copy link
Collaborator

Choose a reason for hiding this comment

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

most of those are already clone so we likely don't need all of these changes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh okay. I'm on it right away

Copy link
Contributor Author

@Cyber-Mitch Cyber-Mitch Feb 10, 2025

Choose a reason for hiding this comment

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

most of those are already clone so we likely don't need all of these changes

Hey @mattsse i checked they aren't really redundant. If i remove the clone it throws an error like this the trait bound `C: Clone` is not satisfied. That was why i added them there initially.

Example
line 149 to 160 throws an error. The AnyNodeTypes<P, C, SC, S> Throws an error

impl<P, C, SC, S> NodeTypes for AnyNodeTypes<P, C, SC, S>
where
    P: NodePrimitives + Send + Sync + Unpin + 'static,
    C: EthChainSpec<Header = P::BlockHeader> + 'static,
    SC: StateCommitment,
    S: Default + Send + Sync + Unpin + Debug + 'static,
{
    type Primitives = P;
    type ChainSpec = C;
    type StateCommitment = SC;
    type Storage = S;
}

Error

the trait bound `C: Clone` is not satisfied
the trait `Clone` is not implemented for `C`, which is required by `AnyNodeTypes<P, C, SC, S>: Clone`rustc[Click for full compiler diagnostic](rust-analyzer-diagnostics-view:/diagnostic%20message%20[0]?0#file:///home/reentrancy/reth/crates/node/types/src/lib.rs)
lib.rs(108, 10): required for `AnyNodeTypes<P, C, SC, S>` to implement `Clone`
lib.rs(28, 22): required by a bound in `NodeTypes`
lib.rs(152, 55): consider further restricting this bound: ` + std::clone::Clone`
the trait bound `SC: Clone` is not satisfied
the trait `Clone` is not implemented for `SC`, which is required by `AnyNodeTypes<P, C, SC, S>: Clone`rustc[Click for full compiler diagnostic](rust-analyzer-diagnostics-view:/diagnostic%20message%20[4]?4#file:///home/reentrancy/reth/crates/node/types/src/lib.rs)
lib.rs(108, 10): required for `AnyNodeTypes<P, C, SC, S>` to implement `Clone`

@Cyber-Mitch
Copy link
Contributor Author

Hey @mattsse i made a new commit, was able to remove some though, if i removed the rest it will throw errors. Check it out.

@kustrun
Copy link
Contributor

kustrun commented Feb 18, 2025

Hey @Cyber-Mitch,

I believe the Clone trait can be encapsulated even further. Would love to hear your thoughts—feel free to check out my PR: https://github.com/kustrun/reth/pull/1/files#diff-ad159e48f13cb6b654f3866465707834a49427e87e6409cc8ee9b532b89ca988

@Cyber-Mitch
Copy link
Contributor Author

Hey @Cyber-Mitch,

I believe the Clone trait can be encapsulated even further. Would love to hear your thoughts—feel free to check out my PR: https://github.com/kustrun/reth/pull/1/files#diff-ad159e48f13cb6b654f3866465707834a49427e87e6409cc8ee9b532b89ca988

okay. This is good @kustrun But, did you run test to see if all test cases pass though?

@kustrun
Copy link
Contributor

kustrun commented Mar 12, 2025

Yes, the tests are passing (was having some troubles running them locally): #14997

@kustrun
Copy link
Contributor

kustrun commented Mar 26, 2025

@emhane This one is the duplicate of merged #14997.

@emhane emhane closed this Mar 26, 2025
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make NodeTypes: Clone
4 participants