Description
Recent work on p2p
(#1108 + #1067) has uncovered a set of implicit (and important) invariants that our existing actors assume. We should take the time (for our own sanity) to properly document said invariants (and or refine them):
- Throughout the codebase, we call
unwrap()
inMailbox
(monorepo/p2p/src/authenticated/actors/tracker/ingress.rs
Lines 111 to 188 in c46312f
- A recent change in
p2p
([p2p] Update P2P discovery PR #921), made message ordering totracker
(from peers) critical for correctness (i.e. not panicking). We should form a strict opinion on whether other actors should ensure they always send messages that arrive at the destination in the right order (also implicitly enforcing the recipient to process incoming messages in a single loop) or make a best effort (dropping messages that don't make sense for the current actor state/returning an error). An example of this pattern is proposal handling in consensus:monorepo/consensus/src/threshold_simplex/actors/voter/actor.rs
Lines 1874 to 1879 in c46312f
- It is possible that someone using actors could deadlock if two actors are messaging back and forth to each other (both hit a bounded channel max and can no longer add). We try to prevent this in
p2p
with rate limiting and channel prevents (using a biased select where we pull control messages that could cause a deadlock before data messages):monorepo/p2p/src/authenticated/actors/peer/actor.rs
Lines 145 to 171 in f6a179e
I've historically found it "sane" to reason about these actors as independent entities that can handle invalid inputs behind well-defined interfaces (as a way to build large/complex crates without locks + better take advantage of parallelism). However, leaking the internal state machine of some actor to all other actors seems like the worst of all worlds (and very difficult to maintain). Getting on top of this seems prudent.