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: NodeTypesWithDB #10683

Merged
merged 7 commits into from
Sep 4, 2024
Merged

feat: NodeTypesWithDB #10683

merged 7 commits into from
Sep 4, 2024

Conversation

klkvr
Copy link
Collaborator

@klkvr klkvr commented Sep 3, 2024

This PR extracts DB AT from FullNodeTypes into separate trait NodeTypesWithDB. This trait is moved to new crate reth-node-types along with NodePrimitives, NodeTypes and NodeTypesWithEngine This is needed to allow reth-provider depend on NodeTypesWithDB

FullProvider is now generic over NodeTypesWithDB and FullNodeTypes is changed to the following form:

pub trait FullNodeTypes: Send + Sync + Unpin + 'static {
/// Node's types with the database.
type Types: NodeTypesWithDB;
/// The provider type used to interact with the node.
type Provider: FullProvider<Self::Types>;
}

As it no more depends on NodeTypes I had to change the way we access some of the ATs (Node::Engine -> <Node::Types as NodeTypesWithEngine>::Engine)

This should allow usage of NodeTypesWithDB in provider traits

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.

why not use syntax?

trait FullNodeTypes: NodeTypes<Engine: EngineTypes, DB: FullDatabase> { .. }

@klkvr
Copy link
Collaborator Author

klkvr commented Sep 4, 2024

why not use syntax?

trait FullNodeTypes: NodeTypes<Engine: EngineTypes, DB: FullDatabase> { .. }

this would leave us with something like

trait FullNodeTypes: NodeTypes<Engine: EngineTypes, DB: FullDatabase> { 
    type Provider = FullProvider<Self>;
}

and such structure would make it harder to deal with generics on providers, eg expressing this bound becomes not trivial if BlockchainProvider has NodeTypes generic:

T: FullNodeTypes<Provider = BlockchainProvider<Types::DB>, Types = Types>,

@emhane
Copy link
Member

emhane commented Sep 4, 2024

why not use syntax?

trait FullNodeTypes: NodeTypes<Engine: EngineTypes, DB: FullDatabase> { .. }

this would leave us with something like

trait FullNodeTypes: NodeTypes<Engine: EngineTypes, DB: FullDatabase> { 
    type Provider = FullProvider<Self>;
}

and such structure would make it harder to deal with generics on providers, eg expressing this bound becomes not trivial if BlockchainProvider has NodeTypes generic:

T: FullNodeTypes<Provider = BlockchainProvider<Types::DB>, Types = Types>,

ok I see, then why have these traits got associated types? and not just super traits? instead of NodeTypesWithDB just

trait FullDB: DatabaseMetrics + Database + NodeTypes {}

@klkvr
Copy link
Collaborator Author

klkvr commented Sep 4, 2024

ok I see, then why have these traits got associated types? and not just super traits? instead of NodeTypesWithDB just

trait FullDB: DatabaseMetrics + Database + NodeTypes {}

hmm, what's the benefit of such trait? doesn't feel right that we'd impl NodeTypes on DB instead of layering it on top of other types as another AT

@emhane
Copy link
Member

emhane commented Sep 4, 2024

ok I see, then why have these traits got associated types? and not just super traits? instead of NodeTypesWithDB just

trait FullDB: DatabaseMetrics + Database + NodeTypes {}

hmm, what's the benefit of such trait? doesn't feel right that we'd impl NodeTypes on DB instead of layering it on top of other types as another AT

doesn't feel right to have a trait with one associated type. what are the reasons for this?

it's a shame that we loose the nice aggregation of stateless components that we used to have in NodeTypes. think we may be getting an abstraction layer too much if we unite them again in a new aggregation trait. would have been simpler with removing the primitives associated type.

trait NodeTypes: PrimitiveTypes {
    type Engine: EngineTypes;
    type ChainSpec: ChainsSpec;
}

nonetheless, we can see where this ends up, and if we need to deal with debt later. it is beneficial that we are agiley moving forward.

@klkvr
Copy link
Collaborator Author

klkvr commented Sep 4, 2024

doesn't feel right to have a trait with one associated type. what are the reasons for this?

we've added NodeTypesWithEngine to close #9555, and the motivation for NodeTypesWithDB is that NodeTypes are coming from the user and need to be configured separately (this is primary motivation for the FullNodeTypesAdapter):

pub fn with_types<T>(self) -> NodeBuilderWithTypes<RethFullAdapter<DB, T>>
where
T: NodeTypesWithEngine<ChainSpec = ChainSpec>,
{

it's a shame that we loose the nice aggregation of stateless components that we used to have in NodeTypes. think we may be getting an abstraction layer too much if we unite them again in a new aggregation trait. would have been simpler with removing the primitives associated type.

agreed that we might end up with too many layers. helper traits aggregating types should help, we could also consider restructuring NodeBuilder a bit to not depend on its interface, especially given it already uses adapters

@mattsse
Copy link
Collaborator

mattsse commented Sep 4, 2024

we could also consider restructuring NodeBuilder a bit to not depend on its interface, especially given it already uses adapters

fully supportive of this

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.

cool,

this will be slightly messy for a bit and some parts will change often but we need incremental progress here

/// node.
///
/// Its types are configured by node internally and are not intended to be user configurable.
pub trait NodeTypesWithDB: NodeTypesWithEngine {
Copy link
Collaborator

Choose a reason for hiding this comment

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

for nodebuilder I think we should perhaps try to stack trait types, like T: NodeTypesWithDB + EngineTypes and consider getting rid of

enginetypes: NodeTypes

but for now this seems appropriate

@mattsse mattsse added this pull request to the merge queue Sep 4, 2024
Merged via the queue into main with commit a1d9ece Sep 4, 2024
36 checks passed
@mattsse mattsse deleted the klkvr/node-types branch September 4, 2024 18:08
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