-
Notifications
You must be signed in to change notification settings - Fork 49
rpc/interface: separate RpcHandler
into 3 tower::Service
s
#266
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
Conversation
/// An RPC [`tower::Service`]. | ||
/// | ||
/// This trait solely exists to encapsulate the traits needed | ||
/// to handle RPC requests and respond with responses - **it is | ||
/// not meant to be used directly.** | ||
/// | ||
/// The `Request` and `Response` are generic and | ||
/// are used in the [`tower::Service`] bounds. | ||
/// | ||
/// The error type is always [`RpcError`]. | ||
/// | ||
/// There is a blanket implementation that implements this | ||
/// trait on types that implement `tower::Service` correctly. | ||
/// | ||
/// See [`RpcHandler`](crate::RpcHandler) for more information. | ||
pub trait RpcService<Request, Response>: | ||
Clone | ||
+ Send | ||
+ Sync | ||
+ 'static | ||
+ Service< | ||
Request, | ||
Response = Response, | ||
Error = RpcError, | ||
Future: Future<Output = Result<Response, RpcError>> + Send + Sync + 'static, | ||
> | ||
{ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this exist? It's just an alias because these bounds x3 on RpcHandler
looked messy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think it's a good idea.
FWIW I don't think you need the Sync
bound here, although I also overuse the Sync
bound in other parts of the code, I plan to go through it at some point and check so if this isn't needed then I'll remove it.
/// An RPC [`tower::Service`]. | ||
/// | ||
/// This trait solely exists to encapsulate the traits needed | ||
/// to handle RPC requests and respond with responses - **it is | ||
/// not meant to be used directly.** | ||
/// | ||
/// The `Request` and `Response` are generic and | ||
/// are used in the [`tower::Service`] bounds. | ||
/// | ||
/// The error type is always [`RpcError`]. | ||
/// | ||
/// There is a blanket implementation that implements this | ||
/// trait on types that implement `tower::Service` correctly. | ||
/// | ||
/// See [`RpcHandler`](crate::RpcHandler) for more information. | ||
pub trait RpcService<Request, Response>: | ||
Clone | ||
+ Send | ||
+ Sync | ||
+ 'static | ||
+ Service< | ||
Request, | ||
Response = Response, | ||
Error = RpcError, | ||
Future: Future<Output = Result<Response, RpcError>> + Send + Sync + 'static, | ||
> | ||
{ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think it's a good idea.
FWIW I don't think you need the Sync
bound here, although I also overuse the Sync
bound in other parts of the code, I plan to go through it at some point and check so if this isn't needed then I'll remove it.
What
Rpc{Request,Response}
enums incuprate_rpc_interface
tower::Service
bound oncuprate_rpc_interface::RpcHandler
with 3 ones, one for each RPC enum type i.e.JsonRpcRequest, BinRequest, OtherRequest
Why
The size difference between the smallest and largest enum variant triggers this lint.
Discussed in this meeting: monero-project/meta#1064.
How
The 300 byte figure I left in the meeting is incorrect since this PR also decouples request enums with JSON-RPC types.
It's closer to a 32 byte difference across enums and 96 byte difference within the largest enum itself
OtherRequest
(one variant is 96 bytes, one is 0 bytes). This can be solved by implementingtower::Service
for each request type, but this was decided as too unwieldy, so for now it is implemented on the 3 RPC enum types.