Skip to content

Conversation

hinto-janai
Copy link
Contributor

@hinto-janai hinto-janai commented Sep 3, 2024

What

  • Removes the Rpc{Request,Response} enums in cuprate_rpc_interface
  • Replaces the single tower::Service bound on cuprate_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 implementing tower::Service for each request type, but this was decided as too unwieldy, so for now it is implemented on the 3 RPC enum types.

@github-actions github-actions bot added A-docs Area: Related to documentation. A-rpc Area: Related to RPC. labels Sep 3, 2024
@hinto-janai hinto-janai mentioned this pull request Sep 3, 2024
12 tasks
Comment on lines +11 to +38
/// 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,
>
{
}
Copy link
Contributor Author

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.

Copy link
Member

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.

@hinto-janai hinto-janai marked this pull request as ready for review September 3, 2024 21:32
@hinto-janai hinto-janai requested a review from Boog900 September 3, 2024 21:32
Comment on lines +11 to +38
/// 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,
>
{
}
Copy link
Member

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.

@Boog900 Boog900 merged commit 4653ac5 into Cuprate:main Sep 5, 2024
6 checks passed
@hinto-janai hinto-janai deleted the rpc-interface branch September 5, 2024 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Related to documentation. A-rpc Area: Related to RPC.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants