Section PrevLogCandidateEntriesTerm.
Context {orig_base_params : BaseParams}.
Context {one_node_params : OneNodeParams orig_base_params}.
Context {raft_params : RaftParams orig_base_params}.
Context {rri : raft_refinement_interface}.
Context {cei : candidate_entries_interface}.
Context {cti : cronies_term_interface}.
Context {cci : cronies_correct_interface}.
Proof using.
unfold refined_raft_net_invariant_init, prevLog_candidateEntriesTerm.
simpl. intuition.
Qed.
Proof using.
unfold candidateEntriesTerm.
intros. break_exists_exists.
repeat find_higher_order_rewrite. intuition.
Qed.
Proof using.
unfold candidateEntriesTerm.
intros. break_exists_exists.
repeat find_higher_order_rewrite.
intuition.
Qed.
Proof using.
unfold refined_raft_net_invariant_client_request, prevLog_candidateEntriesTerm.
simpl. intros.
find_apply_hyp_hyp. break_or_hyp.
- eapply candidateEntriesTerm_ext; eauto.
eapply candidateEntriesTerm_same; eauto; intros;
update_destruct_simplify; auto.
+ now erewrite update_elections_data_client_request_cronies by eauto.
+ find_apply_lem_hyp handleClientRequest_type. intuition.
+ find_apply_lem_hyp handleClientRequest_type. intuition.
- find_apply_lem_hyp in_map_iff. break_exists. break_and. subst. simpl in *.
exfalso. eapply handleClientRequest_no_append_entries; eauto.
find_rewrite. eauto 10.
Qed.
Proof using.
unfold update_elections_data_timeout.
intros.
repeat break_match; repeat find_inversion; simpl; auto.
break_match; auto.
Qed.
Proof using cti.
unfold candidateEntriesTerm.
intros.
break_exists_exists. break_and.
match goal with
| [ H : handleTimeout _ _ = _ |- _ ] =>
pose proof H;
eapply update_elections_data_timeout_cronies with (t := t) in H
end. break_or_hyp.
- update_destruct_simplify; auto.
find_copy_apply_lem_hyp handleTimeout_type_strong.
intuition; repeat find_rewrite; auto.
find_apply_lem_hyp wonElection_exists_voter.
break_exists.
find_apply_lem_hyp in_dedup_was_in.
find_copy_apply_lem_hyp cronies_term_invariant; auto.
simpl in *.
lia.
- update_destruct_simplify; auto.
find_copy_apply_lem_hyp handleTimeout_type_strong.
find_apply_lem_hyp wonElection_exists_voter.
break_exists.
find_apply_lem_hyp in_dedup_was_in.
find_copy_apply_lem_hyp cronies_term_invariant; auto.
intuition; subst; repeat find_rewrite; auto;
simpl in *; lia.
Qed.
Proof using cti.
unfold refined_raft_net_invariant_timeout, prevLog_candidateEntriesTerm.
simpl. intros.
find_apply_hyp_hyp. break_or_hyp.
- eapply candidateEntriesTerm_ext; eauto.
eapply handleClientRequest_preserves_candidateEntriesTerm; eauto.
- find_apply_lem_hyp in_map_iff. break_exists. break_and.
subst. simpl in *.
exfalso. eapply handleTimeout_not_is_append_entries; eauto.
find_rewrite. eauto 10.
Qed.

Lemma handleAppendEntries_preserves_candidateEntriesTerm :
forall net h t n pli plt es ci d m t',
handleAppendEntries h (snd (nwState net h)) t n pli plt es ci = (d, m) ->
refined_raft_intermediate_reachable net ->
candidateEntriesTerm t' (nwState net) ->
candidateEntriesTerm t' (update name_eq_dec (nwState net) h
(update_elections_data_appendEntries
h
(nwState net h) t n pli plt es ci, d)).