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

chore(sdk): replace generics for builders, with generics for their output #11217

Closed
wants to merge 1 commit into from

Conversation

emhane
Copy link
Member

@emhane emhane commented Sep 25, 2024

Closes #9543, alternative to #11204

POC: bijective relation builder-output<>builder, allows for output to provide its builder

The builders' output types that are used through out the program, whereas the builders are only used once and don't leave the node builder scope. It's more lightweight, if we access the builder via the output, output -> builder. rather than currently on main

<N::ComponentsBuilder as NodeComponentsBuilder<RethFullAdapter<DB, N>>>::Components

we should access

N::Components

Builders can definitely rather be used as trait objects than (long complex) generics for the reason that their build function is only called once, and only relevant where it's called. The builder generics aren't really helpful to read, but propagate nonetheless and quickly get overwhelmingly complex - unless we use the BuilderProvider pattern. We don't really care about what the builder type is, we just care about that
(i) we can use it when we need to, and that
(ii) it builds the output type we wish to use through the rest of the program - we are more concerned about the output type.
Atm it feels like it's hard to find the actual output types in the node builder code, they are nested somewhere in associated types of the builders. The builder types are most of what we see reading that code, but we want to see the output types most. The builder types are just a means to an end, the components = reth's substance.

Generics are cumbersome, and should be reserved for types that are used often by the program. For example the consensus type or task spawner type in reth have no need to be dynamically dispatched, because they never change, i.e. we don't have a list of different types of consensus types in some struct field, and they are loaded often by the program, e.g. the spawn trait method on type that impl TaskSpawner is called many times during the program.

@emhane emhane added S-feedback-wanted This issue/PR is looking for feedback A-sdk Related to reth's use as a library labels Sep 25, 2024
@emhane emhane marked this pull request as draft September 25, 2024 15:41
@@ -102,7 +102,7 @@ pub trait BuilderProvider<N: FullNodeComponents>: Send {
fn builder() -> Box<dyn for<'a> Fn(Self::Ctx<'a>) -> Self + Send>;
}

impl<N: FullNodeComponents> BuilderProvider<N> for () {
impl<N> BuilderProvider<N> for () {
type Ctx<'a> = ();

fn builder() -> Box<dyn for<'a> Fn(Self::Ctx<'a>) -> Self + Send> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

the motivation of the referenced pr was to make this stateful so we can move have something like an rpc builder, e.g. op rpc setup needs external input (sequencer URL)
having the NodeAddons stateful would be first step towards that.

Copy link
Member Author

Choose a reason for hiding this comment

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

the one doesn't exclude the other, the node add ons can be passed to the BuilderProvider::Ctx

@github-actions github-actions bot added the S-stale This issue/PR is stale and will close with no further activity label Oct 31, 2024
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.

we've since moved this differently and introduced NodeAddOns

@mattsse mattsse closed this Nov 2, 2024
@emhane emhane deleted the emhane/builder-provider branch November 20, 2024 23:01
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 S-feedback-wanted This issue/PR is looking for feedback S-stale This issue/PR is stale and will close with no further activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Revise NodeComponentsBuilder trait
2 participants