Section LeaderLogsPreserved.
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 {llli : logs_leaderLogs_interface}.
Context {lltsi : leaderLogs_term_sanity_interface}.
Context {llcei : leaderLogs_candidate_entries_interface}.
Context {ollpti : one_leaderLog_per_term_interface}.
Context {vci : votes_correct_interface}.
Context {cci : cronies_correct_interface}.
Proof using.
unfold update_elections_data_client_request in *.
intros. repeat break_match; repeat find_inversion; auto.
Qed.
Proof using.
unfold update_elections_data_timeout.
intros.
repeat break_match; simpl in *; auto.
Qed.
Proof using.
intros.
unfold update_elections_data_appendEntries.
repeat break_match; subst; simpl in *; auto.
Qed.
Proof using.
unfold update_elections_data_requestVote.
intros.
repeat break_match; auto.
Qed.
Proof using.
unfold update_elections_data_requestVoteReply.
intros.
repeat break_match; auto.
simpl in *. intuition.
Qed.
Proof using.
unfold update_elections_data_requestVoteReply.
intros.
repeat break_match; auto.
simpl in *. intuition.
find_inversion. right.
unfold handleRequestVoteReply in *.
repeat break_match; simpl in *; intuition; try congruence;
break_if; try congruence; do_bool; eauto using le_antisym.
Qed.
Proof using cci vci ollpti llcei lltsi llli.
red. unfold leaderLogs_preserved. intros. simpl in *.
repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto;
repeat find_apply_lem_hyp update_elections_data_requestVoteReply_leaderLogs';
intuition; subst; eauto.
- exfalso.
match goal with
| H : In _ ?ll, _ : In (_, ?ll) _ |- _ =>
eapply leaderLogs_term_sanity_invariant in H
end; eauto.
find_eapply_lem_hyp leaderLogs_currentTerm_invariant; eauto.
repeat find_rewrite.
repeat (unfold raft_data in *; simpl in *).
lia.
- find_apply_lem_hyp logs_leaderLogs_invariant; auto.
break_exists. intuition.
find_eapply_lem_hyp one_leaderLog_per_term_log_invariant; eauto;
conclude_using eauto. subst.
find_eapply_lem_hyp app_in_2; eauto using removeAfterIndex_in.
- find_apply_lem_hyp logs_leaderLogs_invariant; auto.
break_exists. intuition.
find_eapply_lem_hyp one_leaderLog_per_term_log_invariant; eauto;
conclude_using eauto. subst.
find_eapply_lem_hyp app_in_2; eauto using removeAfterIndex_in.
- match goal with
| H : In _ ?ll, _ : In (_, ?ll) _ |- _ =>
eapply leaderLogs_candidate_entries_invariant in H
end; eauto.
find_eapply_lem_hyp wonElection_candidateEntries_rvr;
repeat find_rewrite; eauto using votes_correct_invariant, cronies_correct_invariant.
intuition.
Qed.
Proof using.
red. unfold leaderLogs_preserved. intros. simpl in *.
repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto;
repeat find_rewrite_lem update_elections_data_appendEntries_leaderLogs;
intuition; subst; eauto.
Qed.
Proof using.
red. unfold leaderLogs_preserved. intros. simpl in *.
repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto;
repeat find_rewrite_lem update_elections_data_appendEntriesReply_leaderLogs;
intuition; subst; eauto.
Qed.
Proof using.
red. unfold leaderLogs_preserved. intros. simpl in *.
repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto;
repeat find_rewrite_lem update_elections_data_requestVote_leaderLogs;
intuition; subst; eauto.
Qed.
Proof using.
red. unfold leaderLogs_preserved. intros. simpl in *.
repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto;
repeat find_rewrite_lem update_elections_data_client_request_leaderLogs;
intuition; subst; eauto.
Qed.
Proof using.
red. unfold leaderLogs_preserved. intros. simpl in *.
repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto;
repeat find_rewrite_lem update_elections_data_timeout_leaderLogs;
intuition; subst; eauto.
Qed.
Proof using.
red. unfold leaderLogs_preserved. intros. simpl in *. intuition.
Qed.
Proof using.
red. unfold leaderLogs_preserved. 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.
repeat find_higher_order_rewrite. subst.
destruct_update; simpl in *; eauto.
Qed.
Proof using.
red. unfold leaderLogs_preserved. intros. simpl in *.
repeat find_reverse_higher_order_rewrite. eauto.
Qed.
Proof using.
red. unfold leaderLogs_preserved. 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.
repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
Qed.

Lemma leaderLogs_preserved_do_leader :
refined_raft_net_invariant_do_leader leaderLogs_preserved.