Definition ack_in_flight_to_primary (l : list packet) : nat :=
length (filterMap
(fun p => if msg_eq_dec (pBody p) ack
then if name_eq_dec (pDst p) primary
then Some tt else None
else None)
l).

Lemma NetHandler_trace_preserved :
forall p d u o d' l,
NetHandler (pDst p) (pBody p) d = (u, o, d', l) ->
inc_in_flight_to_backup [p] +
ack_in_flight_to_primary [p] =
trace_outputs [((pDst p), inr o)] +
inc_in_flight_to_backup (send_packets (pDst p) l) +
ack_in_flight_to_primary (send_packets (pDst p) l).