Polykey
Polykey copied to clipboard
Apply `timedCancellable` to `Sigchain` such as the deadline in nodes claim process
Specification
From original node claims issue: https://github.com/MatrixAI/js-polykey/issues/213#issuecomment-914837190
Due to intermediate resources being created for this interaction between 2 agents to sign each node, we will need a deadline for each interaction step.
To simplify, you can have a single deadline for the entire interaction from step 2 onwards.
X -> sends notification to (to start cross signing request)( -> Y STEP 2 BEGINS HERE: X <- calls cross signing grpc request and sends its signed claim (intermediate) <- Y (use bidirectional stream and lock the sigchain on Y and X) X -> responds with double signing the Y signed claim, and also bundles it with its own signed claim (intermediate) -> Y X <- responds with double signing the X signed claim <- Y
Both X and Y would need a deadline starting from step 2.
To implement a deadline, there are 2 ways:
- Using the underlying GRPC deadline functionality - I've seen this parameter get used in unary calls, but I don't know how that applies to streams, it may not relevant to streams.
- Using racing promises. I've already implemented this pattern in the networking domain. See the usage of
timerStart
andtimerStop
insideForwardProxy
and thePromise.race
call inConnectionForward
. The usage is quite complex in the networking domain, but in the case of this node claims process, the entire usage of theTimer
type (insrc/types.ts
) should be executed entirely inside theGRPCClientAgent
of Y andagentService
of X. However it is possible to consider the construction and destruction of the timer object in the imperative shell, and then use it in an optional way inside the nodes domain.If the deadline fails it's an exception in the interaction. Upon this exception you need to throw the relevant error to the other side of the interaction, and then finish up and clean up any intermediate resources. Remember to UNLOCK your domains!
This work should be extended into other relevant gRPC calls too.
Additional context
- there's some good discussion and explanation by Roger of his timeout construct from a call we had a little while ago: https://vimeo.com/manage/videos/599995567 see around 13:00
Tasks
- Look into the pre-existing timeout construct
- Add timeout to both client-side and server-side claims process
- Throw relevant exceptions on timeout (close stream, etc)
Using deadlines right now is tricky due to our async start ops in the client interceptor: https://github.com/MatrixAI/js-polykey/issues/249#issuecomment-991999605.
May not affect agent service for now due to lack of any interceptor.
This should be integrated into the design in #297.
In our new RPC design, we are envisioning the ability for the server to call back the client while handling the client's call. This should replace the duplex stream being used currently to do this. Each call can have a deadline, so then naturally this issue will be resolved if each subcall has a deadline.