Section MatchIndexAllEntries.
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 {naetli : no_append_entries_to_leader_interface}.
Context {naetsi : no_append_entries_to_self_interface}.
Context {taifoli : terms_and_indices_from_one_log_interface}.
Context {rlmli : refined_log_matching_lemmas_interface}.
Context {laei : log_all_entries_interface}.
Context {aelli : append_entries_leaderLogs_interface}.
Context {lsi : leader_sublog_interface}.
Context {lhllsi : leaders_have_leaderLogs_strong_interface}.
Context {ollpti : one_leaderLog_per_term_interface}.
Context {mili : match_index_leader_interface}.
Context {matchisi : match_index_sanity_interface}.
Context {aersi : append_entries_reply_sublog_interface}.
Context {cei : candidate_entries_interface}.
Context {vci : votes_correct_interface}.
Context {cci : cronies_correct_interface}.
Definition match_index_all_entries_nw (net : network) : Prop :=
forall p t es e,
In p (nwPackets net) ->
pBody p = AppendEntriesReply t es true ->
currentTerm (snd (nwState net (pDst p))) = t ->
In e (log (snd (nwState net (pDst p)))) ->
eTerm e = t ->
eIndex e <= maxIndex es ->
type (snd (nwState net (pDst p))) = Leader ->
In (t, e) (allEntries (fst (nwState net (pSrc p)))).
Definition match_index_all_entries_inv (net : network) : Prop :=
match_index_all_entries net /\ match_index_all_entries_nw net.
Proof using.
unfold refined_raft_net_invariant_init,
match_index_all_entries_inv,
match_index_all_entries_nw,
match_index_all_entries.
simpl. intros.
intuition.
Qed.
Proof using.
intros. unfold handleClientRequest in *.
break_match; find_inversion; subst; intuition.
simpl in *. eauto 10.
Qed.
Proof using mili rri.
intros.
pose proof lift_prop _ match_index_leader_invariant _ ltac:(eauto) leader.
find_rewrite_lem deghost_spec. concludes. auto.
Qed.
Proof using matchisi rri.
intros.
pose proof lift_prop _ match_index_sanity_invariant _ ltac:(eauto) leader h.
find_rewrite_lem deghost_spec. concludes. auto.
Qed.
Proof using aersi rri.
intros.
pose proof lift_prop _ append_entries_reply_sublog_invariant _ ltac:(eauto).
unfold append_entries_reply_sublog in *.
find_apply_lem_hyp ghost_packet.
eapply_prop_hyp In In; eauto; try rewrite deghost_spec; eauto.
find_rewrite_lem deghost_spec. auto.
Qed.
Proof using aersi matchisi mili rlmli rri.
unfold refined_raft_net_invariant_client_request, match_index_all_entries_inv.
simpl. intros. break_and. split.
- unfold match_index_all_entries in *. simpl in *. intros.
repeat find_higher_order_rewrite. update_destruct_simplify_hyp.
+ find_copy_apply_lem_hyp handleClientRequest_type.
find_copy_apply_lem_hyp handleClientRequest_matchIndex_log. intuition.
* repeat find_rewrite.
{ update_destruct_simplify_hyp.
- apply update_elections_data_clientRequest_allEntries_old'.
find_apply_hyp_hyp. repeat find_rewrite. auto.
- find_apply_hyp_hyp. repeat find_rewrite. auto.
}
* break_exists. break_and. repeat find_rewrite.
{ update_destruct_simplify_hyp.
- unfold update_elections_data_client_request. find_rewrite.
break_if.
+ repeat find_rewrite. simpl. break_or_hyp.
* auto.
* right.
find_copy_apply_lem_hyp maxIndex_is_max; [|solve[apply entries_sorted_invariant; auto]].
rewrite <- lifted_match_index_leader in * by auto.
eapply_prop_hyp In In; eauto. repeat find_rewrite. auto.
+ do_bool. find_rewrite. simpl length in *. lia.
- find_erewrite_lem get_set_diff_default.
pose proof lifted_match_index_sanity _ leader h0 ltac:(eauto) ltac:(auto).
break_or_hyp.
+ simpl in *. lia.
+ find_apply_hyp_hyp. repeat find_rewrite. auto.
}
+ find_apply_hyp_hyp. update_destruct_simplify_hyp.
* apply update_elections_data_clientRequest_allEntries_old'.
repeat find_rewrite. auto.
* repeat find_rewrite. auto.
- unfold match_index_all_entries_nw in *.
simpl. intros.
find_apply_hyp_hyp. break_or_hyp.
+ repeat find_higher_order_rewrite. update_destruct_simplify_hyp.
* find_copy_apply_lem_hyp handleClientRequest_type. break_and. repeat find_rewrite.
find_copy_apply_lem_hyp handleClientRequest_log.
{ intuition.
- repeat find_rewrite.
eapply_prop_hyp In In; eauto.
update_destruct_simplify_hyp.
+ apply update_elections_data_clientRequest_allEntries_old'.
repeat find_rewrite. auto.
+ repeat find_rewrite. auto.
- break_exists. break_and. repeat find_rewrite.
assert (es <> nil).
{
apply maxIndex_gt_0_nonempty.
eapply lt_le_trans; [|eauto].
simpl in *. break_or_hyp.
- repeat find_rewrite. lia.
- eapply entries_gt_0_invariant; eauto.
}
pose proof maxIndex_non_empty es. concludes.
break_exists_name max_e. intuition.
find_eapply_lem_hyp lifted_append_entries_reply_sublog; repeat find_rewrite; eauto.
simpl In in *. break_or_hyp.
+ find_apply_lem_hyp maxIndex_is_max; [|solve[apply entries_sorted_invariant; auto]].
lia.
+ eapply_prop_hyp In In; eauto; [|solve[repeat find_rewrite; auto]].
update_destruct_simplify_hyp.
* apply update_elections_data_clientRequest_allEntries_old'.
repeat find_rewrite. auto.
* repeat find_rewrite. auto.
}
* eapply_prop_hyp In In; eauto.
{ update_destruct_simplify_hyp.
- apply update_elections_data_clientRequest_allEntries_old'.
repeat find_rewrite. auto.
- repeat find_rewrite. auto.
}
+ find_apply_lem_hyp handleClientRequest_packets. subst. simpl in *. intuition.
Qed.
Proof using.
unfold handleTimeout, tryToBecomeLeader.
intros.
repeat break_match; repeat find_inversion; simpl in *; auto.
Qed.
Proof using.
intros.
update_destruct_simplify_hyp.
- unfold update_elections_data_timeout. repeat break_match; auto.
- auto.
Qed.
Proof using.
unfold handleTimeout, tryToBecomeLeader.
intros.
repeat break_match; repeat find_inversion.
- do_in_map. subst. eauto 10.
- do_in_map. subst. eauto 10.
- simpl in *. intuition.
Qed.
Proof using.
unfold refined_raft_net_invariant_timeout, match_index_all_entries_inv.
simpl. intros. break_and. split.
- unfold match_index_all_entries in *. simpl. intros.
repeat find_higher_order_rewrite.
apply allEntries_update_timeout.
update_destruct_simplify_hyp.
+ find_erewrite_lem handleTimeout_log_same.
find_copy_apply_lem_hyp handleTimeout_type. intuition; try congruence.
find_erewrite_lem handleTimeout_matchIndex.
repeat find_rewrite.
eapply_prop_hyp In In; eauto. congruence.
+ eapply_prop_hyp In In; eauto. congruence.
- unfold match_index_all_entries_nw in *.
simpl. intros.
find_apply_hyp_hyp. break_or_hyp.
+ repeat find_higher_order_rewrite.
apply allEntries_update_timeout.
update_destruct_simplify_hyp.
* find_erewrite_lem handleTimeout_log_same.
find_copy_apply_lem_hyp handleTimeout_type.
intuition; try congruence.
eapply_prop_hyp In In; eauto; try congruence.
* eapply_prop_hyp In In; eauto; congruence.
+ do_in_map. find_eapply_lem_hyp handleTimeout_sends_RV; eauto.
break_exists. subst. simpl in *. discriminate.
Qed.
Proof using.
unfold handleAppendEntries.
intros.
repeat break_match; repeat find_inversion; auto; try discriminate.
Qed.
Proof using.
unfold handleAppendEntries.
intros.
repeat break_match; repeat find_inversion; auto; try discriminate.
Qed.
Proof using naetli rri.
intros.
pose proof (lift_prop _ no_append_entries_to_leader_invariant _ ltac:(eauto)).
unfold no_append_entries_to_leader in *.
find_apply_lem_hyp ghost_packet.
match goal with
| [ H : forall _ _ _ , _, H' : In _ _ |- _ ] => eapply H in H'; eauto
end;
rewrite deghost_spec;
rewrite pDst_deghost_packet; auto.
Qed.

Lemma lifted_no_AE_to_self :
forall net p t n pli plt es ci,
refined_raft_intermediate_reachable net ->
In p (nwPackets net) ->
pBody p = AppendEntries t n pli plt es ci ->
pDst p = pSrc p ->
False.