Section AppendEntriesRequestLeaderLogs.
Context {orig_base_params : BaseParams}.
Context {one_node_params : OneNodeParams orig_base_params}.
Context {raft_params : RaftParams orig_base_params}.
Context {lhllsi : leaders_have_leaderLogs_strong_interface}.
Context {rri : raft_refinement_interface}.
Context {si : sorted_interface}.
Context {lmi : log_matching_interface}.
Context {nisi : nextIndex_safety_interface}.
Proof using si rri.
intros.
eapply lift_prop; eauto using logs_sorted_invariant.
Qed.
Proof using si rri.
intros.
find_apply_lem_hyp lift_sorted.
unfold logs_sorted, logs_sorted_host in *.
intuition.
unfold deghost in *. simpl in *. break_match; eauto.
Qed.
Proof using lmi rri.
intros.
eapply lift_prop; eauto using log_matching_invariant.
Qed.
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.
Ltac start :=
red; unfold append_entries_leaderLogs; intros;
subst; simpl in *; find_higher_order_rewrite;
update_destruct; subst; rewrite_update; eauto; simpl in *.
Ltac prove_in :=
match goal with
| [ _ : nwPackets ?net = _,
_ : In (?p : packet) _ |- _] =>
assert (In p (nwPackets net)) by (repeat find_rewrite; do_in_app; intuition)
| [ _ : nwPackets ?net = _,
_ : pBody ?p = _ |- _] =>
assert (In p (nwPackets net)) by (repeat find_rewrite; intuition)
end.
Proof using.
red. unfold append_entries_leaderLogs. intros.
subst. simpl in *.
find_apply_hyp_hyp. intuition eauto.
- prove_in. eapply_prop_hyp In In; break_exists. intuition; eauto.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto;
rewrite update_elections_data_appendEntries_leaderLogs; eauto;
subst; auto.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto;
rewrite update_elections_data_appendEntries_leaderLogs; eauto;
subst; auto.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto;
rewrite update_elections_data_appendEntries_leaderLogs; eauto;
subst; auto.
+ eauto.
- subst. simpl in *.
unfold handleAppendEntries in *.
repeat break_match; find_inversion; congruence.
Qed.
Proof using.
red. unfold append_entries_leaderLogs. intros.
subst. simpl in *.
find_apply_hyp_hyp. intuition eauto.
- prove_in. eapply_prop_hyp In In; break_exists. intuition; eauto.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto;
subst; auto.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto;
subst; auto.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto;
subst; auto.
+ eauto.
- do_in_map. subst. simpl in *.
unfold handleAppendEntriesReply in *.
repeat break_match; find_inversion; simpl in *; intuition.
Qed.
Proof using.
red. unfold append_entries_leaderLogs. intros.
subst. simpl in *.
find_apply_hyp_hyp. intuition eauto.
- prove_in. eapply_prop_hyp In In; break_exists. intuition; eauto.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto;
rewrite update_elections_data_requestVote_leaderLogs; eauto;
subst; auto.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto;
rewrite update_elections_data_requestVote_leaderLogs; eauto;
subst; auto.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto;
rewrite update_elections_data_requestVote_leaderLogs; eauto;
subst; auto.
+ eauto.
- subst. simpl in *.
unfold handleRequestVote in *.
repeat break_match; find_inversion; congruence.
Qed.
Proof using.
red. unfold append_entries_leaderLogs. intros.
subst. simpl in *.
find_apply_hyp_hyp. intuition eauto.
- prove_in. eapply_prop_hyp In In; break_exists. intuition; eauto.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto.
subst; auto using update_elections_data_requestVoteReply_leaderLogs.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto.
subst; auto using update_elections_data_requestVoteReply_leaderLogs.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto.
subst; auto using update_elections_data_requestVoteReply_leaderLogs.
+ eauto.
Qed.
Proof using.
red. unfold append_entries_leaderLogs. intros.
subst. simpl in *.
find_apply_hyp_hyp. intuition eauto.
- eapply_prop_hyp In In; break_exists. intuition; eauto.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto.
subst. rewrite update_elections_data_client_request_leaderLogs.
eauto.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto.
subst. rewrite update_elections_data_client_request_leaderLogs.
eauto.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto.
subst. rewrite update_elections_data_client_request_leaderLogs.
eauto.
+ eauto.
- subst. simpl in *.
unfold handleClientRequest in *.
repeat break_match; find_inversion; do_in_map; simpl in *; intuition.
Qed.
Proof using.
red. unfold append_entries_leaderLogs. intros.
subst. simpl in *.
find_apply_hyp_hyp. intuition eauto.
- eapply_prop_hyp In In; break_exists. intuition; eauto.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto.
subst. rewrite update_elections_data_timeout_leaderLogs.
eauto.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto.
subst. rewrite update_elections_data_timeout_leaderLogs.
eauto.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto.
subst. rewrite update_elections_data_timeout_leaderLogs.
eauto.
+ eauto.
- subst. simpl in *.
unfold handleTimeout, tryToBecomeLeader in *.
repeat break_match; find_inversion; do_in_map; simpl in *; intuition;
subst; simpl in *; do_in_map; subst; simpl in *; congruence.
Qed.
Proof using.
red. unfold append_entries_leaderLogs. intros.
subst. simpl in *.
find_apply_hyp_hyp. intuition eauto.
- eapply_prop_hyp In In; break_exists. intuition; eauto.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto.
subst. replace gd with (fst (nwState net x)); eauto; repeat find_rewrite; reflexivity.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto.
subst. replace gd with (fst (nwState net x)); eauto; repeat find_rewrite; reflexivity.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto.
subst. replace gd with (fst (nwState net x)); eauto; repeat find_rewrite; reflexivity.
+ eauto.
- unfold doGenericServer in *;
repeat break_match; find_inversion; do_in_map; simpl in *; intuition;
subst; simpl in *; do_in_map; subst; simpl in *; congruence.
Qed.

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).