Expand description
Implementation of the unary RPC protocol as per DiemNet wire protocol v1.
Design:
The unary RPC protocol is implemented here as two independent async completion
queues: InboundRpcs and OutboundRpcs.
The InboundRpcs queue is responsible for handling inbound rpc requests
off-the-wire, forwarding the request to the application layer, waiting for
the application layer’s response, and then enqueuing the rpc response to-be
written over-the-wire.
Likewise, the OutboundRpcs queue is responsible for handling outbound rpc
requests from the application layer, enqueuing the request for writing onto
the wire, waiting for a corresponding rpc response, and then notifying the
requestor of the arrived response message.
Both InboundRpcs and OutboundRpcs are owned and driven by the Peer
actor. This has a few implications. First, it means that each connection has
its own pair of local rpc completion queues; the queues are not shared
across connections. Second, the queues don’t do any IO work. They’re purely
driven by the owning Peer actor, who calls handle_ methods on new
NetworkMessage arrivals and polls for completed rpc requests. The queues
also do not write to the wire directly; instead, they’re given a reference to
the Peer actor’s write queue, which they can enqueue a new outbound
NetworkMessage onto.
Timeouts:
Both inbound and outbound requests have mandatory timeouts. The tasks in the
async completion queues are each wrapped in a timeout future, which causes
the task to complete with an error if the task isn’t fulfilled before the
deadline.
Limits:
We limit the number of pending inbound and outbound RPC tasks to ensure that resource usage is bounded.
Modules
- Rpc protocol errors
Structs
- A wrapper struct for an inbound rpc request and its associated context.
InboundRpcshandles new inbound rpc requests off the wire, notifies thePeerManagerof the new request, and stores the pending response on a queue. If the response eventually completes,InboundRpcrecords some metrics and enqueues the response message onto the outbound write queue.- A wrapper struct for an outbound rpc request and its associated context.
OutboundRpcshandles new outbound rpc requests made from the application layer.