Proof using.
unfold refined_raft_net_invariant_append_entries_reply, match_index_all_entries_inv.
simpl. intros. split.
- { unfold match_index_all_entries in *. simpl. intros. break_and.
repeat find_higher_order_rewrite.
rewrite update_nop_fst.
update_destruct_simplify_hyp.
- find_copy_apply_lem_hyp handleAppendEntriesReply_spec.
intuition.
+ match goal with
| [ H : forall _ _ _, type _ = _ -> _ |- _ ] => specialize (H e (pDst p) h)
end.
repeat find_rewrite. repeat concludes.
find_erewrite_lem handleAppendEntriesReply_log.
auto.
+ congruence.
+ repeat find_rewrite.
match goal with
| [ H : context [ assoc_default _ (assoc_set _ _ ?x _) ?y _ ]  |- _ ] =>
destruct (name_eq_dec x y)
end.
* subst. rewrite get_set_same_default in *.
find_apply_lem_hyp app_cons_in.
find_erewrite_lem handleAppendEntriesReply_log.
{ find_apply_lem_hyp PeanoNat.Nat.max_le. break_or_hyp.
- match goal with
| [ H : forall _ _ _, type _ = _ -> _ |- _ ] => specialize (H e (pDst p) (pSrc p))
end. repeat find_rewrite. auto.
- unfold match_index_all_entries_nw in *.
match goal with
| [ H : pBody _ = _, H' : _  |- _ ] => eapply H' with (e := e) in H; auto
end.
}
* rewrite get_set_diff_default in * by auto.
match goal with
| [ H : forall _ _ _, type _ = _ -> _ |- _ ] => specialize (H e (pDst p) h)
end.
repeat find_rewrite. repeat concludes.
find_erewrite_lem handleAppendEntriesReply_log.
auto.
- find_apply_hyp_hyp. congruence.
}
- break_and. unfold match_index_all_entries_nw in *. simpl. intros.
repeat find_higher_order_rewrite. rewrite update_nop_fst.
find_apply_hyp_hyp.
break_or_hyp.
+ update_destruct_simplify_hyp.
* find_erewrite_lem handleAppendEntriesReply_log.
find_copy_apply_lem_hyp handleAppendEntriesReply_spec.
{ repeat break_or_hyp; break_and.
- repeat find_rewrite. eauto using in_middle_insert.
- congruence.
- repeat find_rewrite. eauto using in_middle_insert.
}
* eauto using in_middle_insert.
+ do_in_map. find_apply_lem_hyp handleAppendEntriesReply_packets. subst.
simpl in *. intuition.
Qed.

(* Specifications: *)
Lemma handleRequestVote_sends_RVR :
forall st h h' t lli llt st' m,
handleRequestVote h st t h' lli llt = (st', m) ->
exists t b, m = RequestVoteReply t b.