Section AllEntriesLogMatching.
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 {aelsi : allEntries_leader_sublog_interface}.
Context {lsi : leader_sublog_interface}.
Context {rlmli : refined_log_matching_lemmas_interface}.
Definition allEntries_log_matching_nw net :=
forall (e e' : entry) (h : name) (p : packet)
t leaderId prevLogIndex prevLogTerm entries leaderCommit,
In p (nwPackets net) ->
pBody p = AppendEntries t leaderId prevLogIndex prevLogTerm entries leaderCommit ->
In e entries ->
In e' (map snd (allEntries (fst (nwState net h)))) ->
eTerm e = eTerm e' -> eIndex e = eIndex e' -> e = e'.
Definition allEntries_log_matching_inductive net :=
allEntries_log_matching net /\ allEntries_log_matching_nw net.
Ltac start :=
red; unfold allEntries_log_matching_inductive; simpl; intros.
Ltac start_update :=
start; intuition; [unfold allEntries_log_matching in *|unfold allEntries_log_matching_nw in *];
intros; repeat find_higher_order_rewrite; repeat (update_destruct; rewrite_update); subst; simpl; eauto.
Proof using.
start. split.
- unfold allEntries_log_matching. intros. simpl in *. intuition.
- unfold allEntries_log_matching_nw. intros. simpl in *. intuition.
Qed.
Definition leader_sublog (net : network) :=
forall leader e h,
type (snd (nwState net leader)) = Leader ->
In e (log (snd (nwState net h))) ->
eTerm e = currentTerm (snd (nwState net leader)) ->
In e (log (snd (nwState net leader))).
Proof using lsi rri.
pose proof lift_prop _ leader_sublog_invariant_invariant.
unfold leader_sublog, leader_sublog_invariant, leader_sublog_host_invariant in *.
intuition.
unfold raft_refined_base_params in *.
repeat rewrite <- deghost_spec in *.
repeat match goal with
| [ H : _ |- _ ] => rewrite <- deghost_spec in H
end.
find_apply_hyp_hyp. intuition.
eauto.
Qed.
Proof using lsi rri.
intros.
pose proof (lift_prop _ leader_sublog_invariant_invariant _ ltac:(eauto)) as Hinv.
unfold leader_sublog_invariant, leader_sublog_nw_invariant in *.
destruct Hinv as [Hhost Hnw].
find_apply_lem_hyp ghost_packet.
eapply_prop_hyp In In; eauto; try find_rewrite_lem deghost_spec; try rewrite deghost_spec; eauto.
Qed.
Proof using rlmli.
intros.
intro_refined_invariant entries_sorted_invariant.
find_apply_lem_hyp maxIndex_is_max; auto.
find_rewrite.
lia.
Qed.
Ltac fix_data :=
do 2 (unfold raft_data in *; simpl in *).
Ltac contradict_maxIndex :=
exfalso; find_apply_lem_hyp maxIndex_is_max;
try (fix_data; lia);
eapply entries_sorted_invariant; eauto.
Proof using rlmli lsi aelsi rri.
start_update.
- subst.
find_copy_apply_lem_hyp update_elections_data_client_request_log_allEntries.
intuition; simpl in *; repeat find_rewrite; eauto.
break_exists; intuition; repeat find_rewrite; simpl in *; intuition; subst; simpl in *; eauto.
+ contradict_maxIndex.
+ enough (In e' (log (snd (nwState net h0)))) by
contradict_maxIndex.
eapply allEntries_leader_sublog_invariant; repeat find_rewrite; eauto.
- find_apply_lem_hyp update_elections_data_client_request_log_allEntries.
intuition; simpl in *; repeat find_rewrite; eauto.
break_exists. intuition; repeat find_rewrite; simpl in *; intuition; eauto.
subst.
enough (In e (log (snd (nwState net h')))) by
contradict_maxIndex.
eapply lifted_leader_sublog_invariant; repeat find_rewrite; eauto.
- find_apply_lem_hyp update_elections_data_client_request_log_allEntries.
intuition; simpl in *; repeat find_rewrite; eauto.
break_exists. intuition; repeat find_rewrite; simpl in *; intuition; eauto.
subst.
enough (In e' (log (snd (nwState net h0)))) by
contradict_maxIndex.
eapply allEntries_leader_sublog_invariant; repeat find_rewrite; eauto.
- find_apply_hyp_hyp.
intuition;
[|exfalso; do_in_map; subst; simpl in *;
find_eapply_lem_hyp handleClientRequest_no_append_entries; eauto;
intuition; repeat find_rewrite; find_false; repeat eexists; eauto].
find_apply_lem_hyp update_elections_data_client_request_log_allEntries.
intuition; simpl in *; repeat find_rewrite; eauto.
break_exists. intuition; repeat find_rewrite; simpl in *; intuition; eauto.
subst.
enough (In e (log (snd (nwState net h0)))) by
contradict_maxIndex.
eapply lifted_leader_sublog_nw_invariant; repeat find_rewrite; eauto.
- find_apply_hyp_hyp.
intuition;
[|exfalso; do_in_map; subst; simpl in *;
find_eapply_lem_hyp handleClientRequest_no_append_entries; eauto;
intuition; repeat find_rewrite; find_false; repeat eexists; eauto].
eauto.
Qed.
Proof using.
unfold allEntries_log_matching. intros.
find_higher_order_rewrite.
do 2 (update_destruct; rewrite_update); simpl in *;
repeat find_rewrite; eauto.
Qed.
Ltac unchanged :=
red; intros; eapply allEntries_log_matching_unchanged; subst; eauto.
Proof using.
start_update; simpl in *; try find_erewrite_lem handleTimeout_log_same; eauto;
try find_erewrite_lem update_elections_data_timeout_allEntries; eauto;
find_apply_hyp_hyp; intuition; eauto;
exfalso; do_in_map; subst; simpl in *;
find_eapply_lem_hyp handleTimeout_not_is_append_entries; eauto;
intuition; repeat find_rewrite; find_false; repeat eexists; eauto.
Qed.
Proof using rlmli.
intros.
unfold haveNewEntries in *. do_bool. intuition;
[unfold not_empty in *; break_match; subst; simpl in *; intuition; congruence|].
break_match; try congruence.
do_bool. find_apply_lem_hyp findAtIndex_elim. intuition.
assert (es <> nil) by (destruct es; subst; simpl in *; intuition; congruence).
find_eapply_lem_hyp maxIndex_non_empty.
break_exists. intuition.
find_copy_eapply_lem_hyp entries_sorted_nw_invariant; eauto.
match goal with
| H : In e es |- _ => copy_eapply maxIndex_is_max H; eauto
end.
repeat find_rewrite.
find_eapply_lem_hyp entries_match_nw_host_invariant; eauto.
Qed.
Proof using rlmli.
intros.
enough (In e' entries) by
(eapply uniqueIndices_elim_eq; eauto; apply sorted_uniqueIndices; eapply entries_sorted_nw_invariant; [| | eauto]; eauto).
eapply entries_match_nw_1_invariant.
5: { eauto. } 9: { eauto. }
4: { eauto. } all:eauto.
intuition. repeat find_reverse_rewrite.
eapply entries_contiguous_nw_invariant; eauto.
Qed.
Proof using rlmli.
start_update; simpl in *.
- match goal with
| H : context [handleAppendEntries] |- _ =>
eapply update_elections_data_appendEntries_log_allEntries with (h' := n) in H
end ; intuition; repeat find_rewrite; simpl in *; intuition; subst; eauto;
try (find_rewrite_lem map_app; find_rewrite_lem map_map; simpl in *; find_rewrite_lem map_id;
do_in_app; intuition; eauto).
+ enough (In e' (log (snd (nwState net (pDst p))))) by
(eapply uniqueIndices_elim_eq; eauto; apply sorted_uniqueIndices; eapply entries_sorted_invariant; eauto).
eapply entries_match_nw_host_invariant; eauto.
+ eapply uniqueIndices_elim_eq; eauto; apply sorted_uniqueIndices; eapply entries_sorted_nw_invariant; eauto.
+ do_in_app. intuition.
* eapply uniqueIndices_elim_eq; eauto; apply sorted_uniqueIndices;
eapply entries_sorted_nw_invariant; eauto.
* find_apply_lem_hyp removeAfterIndex_in.
enough (In e' (log (snd (nwState net (pDst p))))) by
(eapply uniqueIndices_elim_eq; eauto; apply sorted_uniqueIndices; eapply entries_sorted_invariant; eauto).
eapply entries_match_nw_host_invariant; eauto.
+ do_in_app; intuition; eauto using removeAfterIndex_in.
- match goal with
| H : context [handleAppendEntries] |- _ =>
eapply update_elections_data_appendEntries_log_allEntries with (h' := n) in H
end ; intuition; repeat find_rewrite; simpl in *; intuition; subst; eauto;
try (find_rewrite_lem map_app; find_rewrite_lem map_map; simpl in *; find_rewrite_lem map_id;
do_in_app; intuition; eauto).
+ enough (In e' (log (snd (nwState net h)))) by
(eapply uniqueIndices_elim_eq; eauto; apply sorted_uniqueIndices; eapply entries_sorted_invariant; eauto).
eapply entries_match_nw_host_invariant; eauto.
+ enough (In e' (log (snd (nwState net h)))) by
(eapply uniqueIndices_elim_eq; eauto; apply sorted_uniqueIndices; eapply entries_sorted_invariant; eauto).
eapply entries_match_nw_host_invariant; eauto.
+ enough (In e' (log (snd (nwState net h)))) by
(eapply uniqueIndices_elim_eq; eauto; apply sorted_uniqueIndices; eapply entries_sorted_invariant; eauto).
eapply entries_match_nw_host_invariant; eauto.
- find_apply_lem_hyp handleAppendEntries_log.
intuition; repeat find_rewrite; simpl in *; eauto.
do_in_app. intuition; eauto using removeAfterIndex_in.
- find_apply_hyp_hyp.
intuition;
[|exfalso; do_in_map; subst; simpl in *;
find_eapply_lem_hyp handleAppendEntries_not_append_entries; eauto;
intuition; repeat find_rewrite; find_false; repeat eexists; eauto].
assert (In p0 (xs ++ p :: ys)) by in_crush.
match goal with
| H : context [handleAppendEntries] |- _ =>
eapply update_elections_data_appendEntries_log_allEntries with (h' := n) in H
end.
intuition; repeat find_rewrite; simpl in *; subst; intuition; eauto.
+ find_rewrite_lem map_app.
find_rewrite_lem map_map.
simpl in *.
find_rewrite_lem map_id.
apply in_app_or in H11.
intuition; eauto.
eauto using packets_entries_eq.
+ find_rewrite_lem map_app.
find_rewrite_lem map_map.
simpl in *.
find_rewrite_lem map_id.
apply in_app_or in H11.
intuition; eauto.
eauto using packets_entries_eq.
+ find_rewrite_lem map_app.
find_rewrite_lem map_map.
simpl in *.
find_rewrite_lem map_id.
apply in_app_or in H11.
intuition; eauto.
eauto using packets_entries_eq.
- find_apply_hyp_hyp.
intuition;
[|exfalso; do_in_map; subst; simpl in *;
eapply handleAppendEntries_not_append_entries; eauto;
intuition; repeat find_rewrite; repeat eexists; eauto].
eauto.
Qed.
Proof using.
start_update; simpl in *;
try find_erewrite_lem handleAppendEntriesReply_log; eauto;
find_apply_hyp_hyp; intuition; eauto;
exfalso; do_in_map; subst; simpl in *;
find_eapply_lem_hyp handleAppendEntriesReply_packets; eauto;
subst; simpl in *; intuition.
Qed.

Lemma allEntries_log_matching_request_vote :
refined_raft_net_invariant_request_vote allEntries_log_matching_inductive.