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: implement generalizable rpc middleware #9429

Merged
merged 4 commits into from
Jul 15, 2024

Conversation

smatthewenglish
Copy link
Contributor

@smatthewenglish smatthewenglish commented Jul 10, 2024

towards more flexibility of rpc middleware in the style of Server from jsonrpsee

as part of this feature RpcRequestMetrics was made public, with the idea that it (or whatever other middleware the operator wants to use) be added when the config/server is started

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.

looking good so far, removing the intermediary type definitely helped a lot

Comment on lines 1169 to 1172
where
RpcMiddleware: for<'a> Layer<RpcService, Service: RpcServiceT<'a>> + Clone + Send + 'static,
<RpcMiddleware as Layer<RpcService>>::Service: Send + std::marker::Sync,
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need several implant blocks for this type, and we want to be as unrestrictive as possible, so the setters are easy to call

we only need to enforce these bounds when we start the server

@@ -105,7 +117,7 @@ async fn test_launch_same_port_different_cors() {
EthApiBuild::build,
);
let addr = test_address();
let res = RpcServerConfig::ws(Default::default())
let res = RpcServerConfig::<Identity>::ws(Default::default())
Copy link
Collaborator

Choose a reason for hiding this comment

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

this shouldn't be necessary if we put the init functions in another impl block that doesn't require this generic

@mattsse mattsse added the A-rpc Related to the RPC implementation label Jul 11, 2024
@smatthewenglish smatthewenglish force-pushed the middleware branch 3 times, most recently from 884d8fc to bc09a85 Compare July 11, 2024 15:15
@smatthewenglish smatthewenglish force-pushed the middleware branch 4 times, most recently from 738dae4 to 0be45b9 Compare July 11, 2024 15:47
@smatthewenglish
Copy link
Contributor Author

looking good so far, removing the intermediary type definitely helped a lot

thank you for this feedback! i'm learning a lot about idiomatic rust from you, and i really appreciate that

in this updated code created an impl block to handle initialization and moved the trait bounds from the config type to the start method

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.

great!

the pr does change additional metric setup internals, I don't want to do this in this pr, because this is out of scope.
we can limit this pr to the introduction of the additional middleware value and then try to integrate it in a followup then it's easier.
I'm fine with leaving the additional rpc_middleware unused at first

Comment on lines +1197 to +1198
/// convenience. To set a custom [`IdProvider`], please use [`Self::with_id_provider`].
pub fn with_ws(mut self, config: ServerBuilder<Identity, Identity>) -> Self {
Copy link
Collaborator

Choose a reason for hiding this comment

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

these accept self and return Self, and don't care about the current generic, so these should be moved to the

`impl RpcServerConfig

scope

@@ -1591,7 +1623,7 @@ pub struct TransportRpcModules<Context = ()> {
/// The original config
config: TransportRpcModuleConfig,
/// rpcs module for http
http: Option<RpcModule<Context>>,
pub http: Option<RpcModule<Context>>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wanna keep this private

Comment on lines 1352 to 1398
RpcServiceBuilder::new().layer(
modules
.http
.as_ref()
.or(modules.ws.as_ref())
.map(RpcRequestMetrics::same_port)
.unwrap_or_default(),
),
)
.set_rpc_middleware(self.rpc_middleware)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this now puts the metrics setup on the caller, we don't want this.

can we please keep the rpc_middleware setup as it was before and then integrate the custom middleware in a next step
there's a lot that can go wrong here

Copy link
Collaborator

Choose a reason for hiding this comment

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

this pr should not change the any metrics setup

@smatthewenglish smatthewenglish force-pushed the middleware branch 3 times, most recently from 0ca715c to 47f51b7 Compare July 12, 2024 14:11
@smatthewenglish
Copy link
Contributor Author

great!

the pr does change additional metric setup internals, I don't want to do this in this pr, because this is out of scope. we can limit this pr to the introduction of the additional middleware value and then try to integrate it in a followup then it's easier. I'm fine with leaving the additional rpc_middleware unused at first

sounds good. i've updated the branch accordingly

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.

lgtm!

next we can try merging the existing metrics layer setup with the additional rpc middleware field

@mattsse mattsse added this pull request to the merge queue Jul 15, 2024
Merged via the queue into paradigmxyz:main with commit 5a03959 Jul 15, 2024
32 checks passed
@smatthewenglish
Copy link
Contributor Author

lgtm!

next we can try merging the existing metrics layer setup with the additional rpc middleware field

Thank you for the review. This was my first pr with the prefix "feat" 🙌

That sounds good to me, I'll give it a shot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rpc Related to the RPC implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants