Proof using aelsi lsli llsli rlmli rri.
red. unfold prefix_within_term_inductive. intuition.
- unfold allEntries_leaderLogs_prefix_within_term. intros.
simpl in *. subst. repeat find_higher_order_rewrite.
repeat destruct_update; simpl in *; eauto;
try find_rewrite_lem update_elections_data_client_request_leaderLogs; eauto.
+ unfold prefix_within_term. intros.
find_apply_lem_hyp update_elections_data_clientRequest_allEntries_new. intuition.
* eapply_prop allEntries_leaderLogs_prefix_within_term; eauto.
* exfalso.
repeat find_rewrite.
find_eapply_lem_hyp leaderLogs_sublog_invariant; eauto.
repeat conclude_using eauto.
find_eapply_lem_hyp maxIndex_is_max; [|eapply entries_sorted_invariant; eauto].
unfold ghost_data in *. simpl in *. omega.
+ unfold prefix_within_term. intros.
find_apply_lem_hyp update_elections_data_clientRequest_allEntries_new. intuition.
* eapply_prop allEntries_leaderLogs_prefix_within_term; eauto.
* exfalso.
repeat find_rewrite.
find_eapply_lem_hyp leaderLogs_sublog_invariant; eauto.
repeat conclude_using eauto.
find_eapply_lem_hyp maxIndex_is_max; [|eapply entries_sorted_invariant; eauto].
unfold ghost_data in *. simpl in *. omega.
- unfold log_leaderLogs_prefix_within_term. intros.
simpl in *. subst. repeat find_higher_order_rewrite.
repeat destruct_update; simpl in *; eauto;
try find_rewrite_lem update_elections_data_client_request_leaderLogs; eauto.
+ unfold prefix_within_term. intros.
find_eapply_lem_hyp handleClientRequest_log'; eauto. intuition.
* eapply_prop log_leaderLogs_prefix_within_term; eauto.
* exfalso.
repeat find_rewrite.
find_eapply_lem_hyp leaderLogs_sublog_invariant; eauto.
repeat conclude_using eauto.
find_eapply_lem_hyp maxIndex_is_max; [|eapply entries_sorted_invariant; eauto].
unfold ghost_data in *. simpl in *. omega.
+ unfold prefix_within_term. intros.
find_eapply_lem_hyp handleClientRequest_log'; eauto. intuition.
* eapply_prop log_leaderLogs_prefix_within_term; eauto.
* exfalso.
repeat find_rewrite.
find_eapply_lem_hyp leaderLogs_sublog_invariant; eauto.
repeat conclude_using eauto.
find_eapply_lem_hyp maxIndex_is_max; [|eapply entries_sorted_invariant; eauto].
unfold ghost_data in *. simpl in *. omega.
- unfold allEntries_log_prefix_within_term. intros.
simpl in *. subst. repeat find_higher_order_rewrite.
repeat destruct_update; simpl in *; eauto.
+ unfold prefix_within_term. intros.
match goal with
| H : In _ (map _ _) |- _ => unfold update_elections_data_client_request in H
end.
repeat break_let.
find_inversion.
find_apply_lem_hyp handleClientRequest_log. intuition; repeat find_rewrite.
* break_if; do_bool; try omega.
eapply_prop allEntries_log_prefix_within_term; eauto.
* { break_exists; intuition.
repeat find_rewrite. simpl in *. break_if; do_bool; try omega.
do_in_map; simpl in *; intuition; subst; simpl in *; auto.
- right. eapply allEntries_leader_sublog_invariant; repeat find_rewrite; eauto.
apply in_map_iff; eauto.
- right. eapply_prop allEntries_log_prefix_within_term; eauto.
apply in_map_iff; eauto.
}
+ unfold prefix_within_term. intros.
match goal with
| H : In _ (map _ _) |- _ => unfold update_elections_data_client_request in H
end.
repeat break_let.
find_inversion.
find_apply_lem_hyp handleClientRequest_log. intuition; repeat find_rewrite.
* break_if; do_bool; try omega.
eapply_prop allEntries_log_prefix_within_term; eauto.
* { break_exists; intuition.
repeat find_rewrite. simpl in *. break_if; do_bool; try omega.
do_in_map; simpl in *; intuition; subst; simpl in *; auto.
- find_eapply_lem_hyp lift_leader_sublog; repeat find_rewrite; eauto.
find_eapply_lem_hyp maxIndex_is_max; [|eapply entries_sorted_invariant; eauto].
unfold ghost_data in *. simpl in *. omega.
- eapply_prop allEntries_log_prefix_within_term; eauto.
apply in_map_iff; eauto.
}
+ unfold prefix_within_term. intros.
find_apply_lem_hyp handleClientRequest_log. intuition; repeat find_rewrite.
* eapply_prop allEntries_log_prefix_within_term; eauto.
* { break_exists; intuition. repeat find_rewrite. simpl in *. intuition.
- subst. right.
eapply allEntries_leader_sublog_invariant; repeat find_rewrite; eauto.
- right. eapply_prop allEntries_log_prefix_within_term; eauto.
}
- (* leadersublog_nw *)
unfold allEntries_append_entries_prefix_within_term_nw. intros.
simpl in *. subst.
find_apply_hyp_hyp.
intuition; [| do_in_map; subst; simpl in *;
find_eapply_lem_hyp handleClientRequest_no_append_entries; eauto;
intuition;
find_false; repeat eexists; eauto].
repeat find_higher_order_rewrite.
repeat destruct_update; simpl in *; eauto.
+ find_apply_lem_hyp update_elections_data_clientRequest_allEntries_new.
intuition.
* eapply_prop_hyp allEntries_append_entries_prefix_within_term_nw pBody; eauto.
repeat conclude_using eauto. repeat find_rewrite. auto.
* exfalso. find_rewrite.
find_eapply_lem_hyp lift_leader_sublog_nw; eauto.
find_eapply_lem_hyp maxIndex_is_max; [|eapply entries_sorted_invariant; eauto].
unfold ghost_data in *. simpl in *. omega.
+ eapply_prop_hyp allEntries_append_entries_prefix_within_term_nw pBody; eauto.
repeat conclude_using eauto. repeat find_rewrite. auto.
- (* trivial *)
unfold append_entries_leaderLogs_prefix_within_term in *. intros.
simpl in *. subst.
find_apply_hyp_hyp.
intuition; [| do_in_map; subst; simpl in *;
find_eapply_lem_hyp handleClientRequest_no_append_entries; eauto;
intuition;
find_false; repeat eexists; eauto].
repeat find_higher_order_rewrite.
repeat destruct_update; simpl in *; eauto.
find_rewrite_lem update_elections_data_client_request_leaderLogs. eauto.
- unfold append_entries_log_prefix_within_term, prefix_within_term in *.
intros. simpl in *. subst.
find_apply_hyp_hyp.
intuition; [| do_in_map; subst; simpl in *;
find_eapply_lem_hyp handleClientRequest_no_append_entries; eauto;
intuition;
find_false; repeat eexists; eauto].
repeat find_higher_order_rewrite.
repeat destruct_update; simpl in *; eauto.
find_apply_lem_hyp handleClientRequest_log. intuition; repeat find_rewrite; eauto.
break_exists; intuition. repeat find_rewrite. simpl in *; eauto.
intuition; eauto. subst.
right.
eapply lift_leader_sublog_nw; repeat find_rewrite; eauto.
Qed.

(* Specifications: *)
Lemma doLeader_spec :
forall st h os st' ms m t n pli plt es ci,
doLeader st h = (os, st', ms) ->
In m ms ->
snd m = AppendEntries t n pli plt es ci ->
t = currentTerm st /\
log st' = log st /\
type st = Leader /\
((pli = 0 /\ plt = 0 /\ es = findGtIndex (log st) 0) \/
((exists e, findAtIndex (log st) pli = Some e /\
eTerm e = plt) /\
es = findGtIndex (log st) pli) \/
exists h', pred (getNextIndex st h') <> 0 /\ findAtIndex (log st) (pred (getNextIndex st h')) = None).