Section AllEntriesVotesWithLog.
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 {aeli : allEntries_log_interface}.
Context {vwltsi : votesWithLog_term_sanity_interface}.
Context {vvwlci : votes_votesWithLog_correspond_interface}.
Context {vci : votes_correct_interface}.
Proof using.
intros. unfold update_elections_data_appendEntries in *.
repeat break_match; auto. simpl in *.
do_in_app. intuition. do_in_map. find_inversion.
right.
unfold handleAppendEntries in *.
repeat break_match; find_inversion; simpl in *; do_bool; auto.
Qed.
Proof using vwltsi.
red. unfold allEntries_votesWithLog. intros. simpl in *.
repeat find_higher_order_rewrite.
destruct_update; simpl in *.
- find_eapply_lem_hyp votesWithLog_update_elections_data_append_entries; eauto.
find_copy_apply_lem_hyp votesWithLog_term_sanity_invariant; eauto.
find_eapply_lem_hyp update_elections_data_appendEntries_allEntries'; eauto.
intuition; do 2 (unfold raft_data, ghost_data in *; simpl in *); try lia.
eapply_prop_hyp votesWithLog votesWithLog; eauto. intuition.
right. break_exists_exists. intuition.
find_higher_order_rewrite. destruct_update; simpl in *; auto.
rewrite update_elections_data_appendEntries_leaderLogs. auto.
- eapply_prop_hyp votesWithLog votesWithLog; eauto. intuition.
right. break_exists_exists. intuition.
find_higher_order_rewrite. destruct_update; simpl in *; auto.
rewrite update_elections_data_appendEntries_leaderLogs. auto.
Qed.
Proof using.
red. unfold allEntries_votesWithLog. intros. simpl in *.
repeat find_higher_order_rewrite.
destruct_update; simpl in *;
eapply_prop_hyp votesWithLog votesWithLog; eauto; intuition;
right; break_exists_exists; intuition;
find_higher_order_rewrite; destruct_update; simpl in *; auto.
Qed.
Definition currentTerm_votedFor_votesWithLog net :=
forall h t n,
(currentTerm (snd (nwState net h)) = t /\
votedFor (snd (nwState net h)) = Some n) ->
exists l,
In (t, n, l) (votesWithLog (fst (nwState net h))).
Proof using vci vvwlci.
unfold currentTerm_votedFor_votesWithLog. intros.
eapply votes_votesWithLog_correspond_invariant; eauto.
break_and.
eapply votes_correct_invariant; eauto.
Qed.

Lemma handleRequestVote_currentTerm_leaderId' :
forall h st t c li lt st' m,
handleRequestVote h st t c li lt = (st', m) ->
votedFor st' <> votedFor st ->
currentTerm st < currentTerm st' \/
leaderId st = None.