Section LeaderLogsVotesWithLog.
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 {vrmutdi : votesReceived_moreUpToDate_interface}.
Context {rvrmutdi : requestVoteReply_moreUpToDate_interface}.
Proof using.
intros.
break_exists_exists. intuition.
find_apply_hyp_hyp. break_exists_exists. intuition eauto.
Qed.
Proof using.
red. unfold leaderLogs_votesWithLog. intros. simpl in *.
subst. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
- find_rewrite_lem update_elections_data_appendEntries_leaderLogs.
eapply quorum_preserved; [|eauto].
intros.
find_higher_order_rewrite; destruct_update; simpl in *; eauto.
rewrite votesWithLog_same_append_entries. auto.
- eapply quorum_preserved; [|eauto].
intros.
find_higher_order_rewrite; destruct_update; simpl in *; eauto.
rewrite votesWithLog_same_append_entries. auto.
Qed.
Proof using.
red. unfold leaderLogs_votesWithLog. intros. simpl in *.
subst. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
- eapply quorum_preserved; [|eauto].
intros.
find_higher_order_rewrite; destruct_update; simpl in *; eauto.
- eapply quorum_preserved; [|eauto].
intros.
find_higher_order_rewrite; destruct_update; simpl in *; eauto.
Qed.
Proof using.
intros.
unfold update_elections_data_requestVote in *.
repeat break_match; simpl in *; intuition.
Qed.
Proof using.
red. unfold leaderLogs_votesWithLog. intros. simpl in *.
subst. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
- find_rewrite_lem leaderLogs_update_elections_data_requestVote.
eapply quorum_preserved; [|eauto].
intros.
find_higher_order_rewrite; destruct_update; simpl in *;
eauto using update_elections_data_request_vote_votesWithLog_old.
- eapply quorum_preserved; [|eauto].
intros.
find_higher_order_rewrite; destruct_update; simpl in *;
eauto using update_elections_data_request_vote_votesWithLog_old.
Qed.
Proof using.
intros.
exists (dedup name_eq_dec l). intuition; eauto using NoDup_dedup, in_dedup_was_in.
unfold wonElection in *.
do_bool. lia.
Qed.
Proof using rvrmutdi vrmutdi.
red. unfold leaderLogs_votesWithLog. intros. simpl in *.
subst. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto;
[|eapply quorum_preserved; [|eauto];
intros;
find_higher_order_rewrite; destruct_update; simpl in *; eauto;
rewrite update_elections_data_request_vote_reply_votesWithLog;
auto].
find_eapply_lem_hyp leaderLogs_update_elections_data_RVR; eauto.
intuition;
[eapply quorum_preserved; [|eauto];
intros;
find_higher_order_rewrite; destruct_update; simpl in *; eauto;
rewrite update_elections_data_request_vote_reply_votesWithLog;
auto|].
subst.
match goal with
| |- context [handleRequestVoteReply ?h ?st ?h' ?t ?r] =>
remember (handleRequestVoteReply h st h' t r) as new_state
end.
find_eapply_lem_hyp handleRequestVoteReply_spec'.
intuition.
conclude_using
ltac:(repeat find_rewrite; congruence).
concludes.
intuition.
repeat find_rewrite.
find_apply_lem_hyp wonElection_dedup_spec.
break_exists_exists. intuition.
find_apply_hyp_hyp.
simpl in *. intuition.
- subst.
find_eapply_lem_hyp requestVoteReply_moreUpToDate_invariant; eauto.
repeat find_rewrite.
repeat conclude_using eauto.
break_exists_exists. intuition.
find_higher_order_rewrite.
simpl in *.
destruct_update; subst; simpl in *; eauto.
repeat find_rewrite.
rewrite update_elections_data_request_vote_reply_votesWithLog. auto.
- find_eapply_lem_hyp votesReceived_moreUpToDate_invariant; eauto.
break_exists_exists. intuition.
find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
rewrite update_elections_data_request_vote_reply_votesWithLog. auto.
Qed.
Proof using.
intros.
unfold update_elections_data_timeout.
repeat break_match; simpl in *; auto.
Qed.
Proof using.
red. unfold leaderLogs_votesWithLog. intros. simpl in *.
subst. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto;
[|eapply quorum_preserved; [|eauto];
intros;
find_higher_order_rewrite; destruct_update; simpl in *; eauto;
apply update_elections_data_timeout_votesWithLog_old;
auto].
find_rewrite_lem update_elections_data_timeout_leaderLogs.
eapply quorum_preserved; [|eauto];
intros;
find_higher_order_rewrite; destruct_update; simpl in *; eauto;
apply update_elections_data_timeout_votesWithLog_old;
auto.
Qed.
Proof using.
red. unfold leaderLogs_votesWithLog. intros. simpl in *.
subst. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto;
[|eapply quorum_preserved; [|eauto];
intros;
find_higher_order_rewrite; destruct_update; simpl in *; eauto;
rewrite votesWithLog_same_client_request;
auto].
find_rewrite_lem update_elections_data_client_request_leaderLogs.
eapply quorum_preserved; [|eauto];
intros;
find_higher_order_rewrite; destruct_update; simpl in *; eauto;
rewrite votesWithLog_same_client_request;
auto.
Qed.
Proof using.
red. unfold leaderLogs_votesWithLog. intros. simpl in *.
match goal with
| H : nwState ?net ?h = (?gd, ?d) |- _ =>
replace gd with (fst (nwState net h)) in * by (rewrite H; reflexivity);
replace d with (snd (nwState net h)) in * by (rewrite H; reflexivity);
clear H
end.
subst. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto;
solve [eapply quorum_preserved; [|eauto];
intros;
find_higher_order_rewrite; destruct_update; simpl in *; eauto;
auto].
Qed.
Proof using.
red. unfold leaderLogs_votesWithLog. intros. simpl in *.
match goal with
| H : nwState ?net ?h = (?gd, ?d) |- _ =>
replace gd with (fst (nwState net h)) in * by (rewrite H; reflexivity);
replace d with (snd (nwState net h)) in * by (rewrite H; reflexivity);
clear H
end.
subst. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto;
solve [eapply quorum_preserved; [|eauto];
intros;
find_higher_order_rewrite; destruct_update; simpl in *; eauto;
auto].
Qed.

Lemma leaderLogs_votesWithLog_reboot :
refined_raft_net_invariant_reboot leaderLogs_votesWithLog.