Proof using uii si.
unfold raft_net_invariant_append_entries.
intros.
find_copy_apply_lem_hyp UniqueIndices_invariant.
find_copy_apply_lem_hyp logs_sorted_invariant.
unfold logs_sorted, UniqueIndices in *. intuition.
find_eapply_lem_hyp handleAppendEntries_spec. intuition.
- eapply log_matching_state_same_packet_subset; eauto.
+ intros. find_higher_order_rewrite. simpl. break_if; subst; intuition.
+ in_crush. find_apply_hyp_hyp. intuition; find_rewrite; in_crush.
- (* beginning of time special case *)
unfold log_matching in *. intuition.
+ (* hosts *)
unfold log_matching_hosts. simpl in *. subst.
{ intuition.
- repeat find_higher_order_rewrite. simpl.
repeat break_if; subst; simpl in *; auto using entries_match_refl;
eauto using entries_match_sym,
handleAppendEntries_log_matching_beginning_of_time_entries_match.
find_apply_hyp_goal.
- repeat find_higher_order_rewrite. simpl in *.
break_if.
+ unfold log_matching_nw in *. repeat subst.
prove_in.
use_nw_invariant.
+ unfold log_matching_hosts in *. intuition.
- repeat find_higher_order_rewrite. simpl in *. break_if.
+ unfold log_matching_nw in *. repeat find_rewrite.
prove_in.
use_nw_invariant.
+ unfold log_matching_hosts in *. intuition eauto.
}
+(* nw *)
unfold log_matching_nw in *.
{ intuition; prep_packets.
- break_if.
+ use_log_matching_nw_nw.
match goal with
| [ H : forall _, _ < _ <= _ -> In _ _ -> In _ ?es |- In _ ?es ] =>
eapply H; eauto; split
end.
match goal with
| [ H : forall _, In _ ?es -> _ < eIndex _,
_ : In ?e ?es
|- 0 < eIndex ?e ] =>
eapply le_lt_trans; [omega|eapply H; eauto]
end.
congruence.
+ use_nw_invariant; try solve [in_crush].
use_log_matching_nw_host. intuition.
- break_if.
+ subst.
match goal with
| [ H : forall _ _ _ _ _ _ _, In _ _ -> _,
Hp : pBody _ = _
|- context [In _ ?es] ] =>
match type of Hp with
| context [ es ] =>
fail 1
| _ => copy_apply H Hp; eauto
end
end.
use_log_matching_nw_nw'.
intuition.
match goal with
| H : forall _, 0 < _ <= _ -> _ |- context [eIndex _ = ?x] =>
specialize (H x); forward H
end.
* split; [destruct prevLogIndex; [congruence|omega]|].
apply lt_le_weak. eapply lt_le_trans.
eauto.
repeat find_rewrite.
eapply maxIndex_is_max; intuition eauto.
* concludes. break_exists.
intuition. eauto.
+ use_nw_invariant.
use_log_matching_nw_host. intuition.
- use_nw_invariant.
- use_nw_invariant.
- match goal with
| H : pBody _ = AppendEntries _ _ _ _ (log _) _ |- _ =>
clear H
end.
use_log_matching_nw_nw.
- match goal with
| H : pBody _ = AppendEntries _ _ _ _ (log _) _ |- _ =>
clear H
end.
use_log_matching_nw_nw.
- match goal with
| H : pBody _ = AppendEntries _ _ _ _ (log _) _ |- _ =>
clear H
end.
use_log_matching_nw_nw.
}
- (* middle of time, successful AppendEntries *)
simpl in *.
unfold log_matching in *. intuition.
+ { (* hosts *)
unfold log_matching_hosts. intuition.
- simpl in *. repeat find_higher_order_rewrite.
repeat break_if; subst; eauto using entries_match_refl.
+ find_rewrite. break_exists; intuition.
eapply handleAppendEntries_log_matching_middle_of_time_entries_match; eauto.
+ find_rewrite. break_exists; intuition. apply entries_match_sym.
eapply handleAppendEntries_log_matching_middle_of_time_entries_match; eauto.
+ unfold log_matching_hosts in *. intuition.
- simpl in *. repeat find_higher_order_rewrite.
break_if; subst.
+ apply contiguous_range_exact_lo_weaken_exists with (lo := 0); [|omega].
break_exists. intuition. do_elim.
repeat find_rewrite. eapply removeIncorrect_new_contiguous; eauto.
* intros.
unfold log_matching_nw in *.
prove_in.
use_nw_invariant.
use_log_matching_nw_host. intuition.
eapply uniqueIndices_elim_eq; eauto.
* unfold contiguous_range_exact_lo.
unfold log_matching_hosts in *.
intuition eauto. find_apply_hyp_hyp. intuition.
* unfold contiguous_range_exact_lo.
unfold log_matching_nw in *.
prove_in.
use_nw_invariant.
+ unfold log_matching_hosts in *. intuition.
- simpl in *. repeat find_higher_order_rewrite.
break_if; subst.
+ repeat find_rewrite. do_in_app. intuition.
* unfold log_matching_nw in *.
prove_in.
use_nw_invariant.
find_apply_hyp_hyp. intuition.
* find_apply_lem_hyp removeAfterIndex_in.
unfold log_matching_hosts in *. intuition eauto.
+ unfold log_matching_hosts in *. intuition eauto.
}
+ (* nw *)
{
unfold log_matching_nw.
intuition; prep_packets.
- break_if; subst.
+ repeat find_rewrite. in_crush_start.
* (* e2 new *)
{ match goal with
| |- In ?e (_ ++ removeAfterIndex _ ?i) =>
destruct (le_lt_dec (eIndex e) i)
end.
- unfold log_matching_nw in *.
repeat find_rewrite.
match goal with
| [ Hp : pBody ?p = AppendEntries _ _ _ _ ?es _,
Hp' : pBody ?p' = AppendEntries _ _ _ _ ?entries _,
H : forall _ _ _ _ _ _ _, In _ _ -> _
|- context [ ?es ++ _ ] ]=>
copy_apply H Hp'; [|in_crush];
copy_apply H Hp; [|in_crush]; clear H; intuition;
match goal with
| [ H : forall _ _ _ _ _ _ _, In _ _ -> _,
H' : forall _ _ _ _ _ _ _, In _ _ -> _,
_ : eIndex ?e = eIndex ?e'
|- _] =>
match type of H with
| context [ ?es ] =>
match type of H' with
| context [ ?entries ] =>
eapply H with (e1:=e)(e2:=e') in Hp; eauto;
eapply H' with (e1:=e')(e2:=e) in Hp'; eauto;
intuition; clear H; clear H'
end
end
end
end.
repeat do_elim.
match goal with
| [ H : forall _, prevLogIndex < _ <= _ -> _
|- context [removeAfterIndex _ ?pli ] ] =>
specialize (H pli); forward H
end.
+ split; [solve [eauto using lt_le_trans]|].
eapply lt_le_weak. eapply lt_le_trans; eauto.
repeat find_reverse_rewrite.
eapply maxIndex_is_max; eauto.
+ concludes.
break_exists; intuition.
apply in_or_app. right.
{ eapply removeAfterIndex_le_In.
- omega.
- do_elim. subst.
match goal with
| [ H : forall _ _ _, In _ ?entries -> _,
_ : eIndex ?e3 <= eIndex _,
_ : In ?e3 ?entries,
_ : In ?e (log _),
_ : eIndex ?x = eIndex ?e
|- _ ] =>
eapply H with (e1:=x)(e2:=e); auto; congruence
end.
}
- apply in_or_app. left.
unfold log_matching_nw in *.
use_log_matching_nw_nw.
}
* (* e2 old *)
apply in_or_app. right.
unfold log_matching_nw in *.
use_nw_invariant.
find_copy_apply_lem_hyp removeAfterIndex_In_le.
find_apply_lem_hyp removeAfterIndex_in.
apply removeAfterIndex_le_In; [omega|].
use_log_matching_nw_host.
intuition. eapply_prop logs_sorted_host.
+ unfold log_matching_nw in *.
use_nw_invariant.
use_log_matching_nw_host.
intuition.
- simpl in *.
{ break_if.
- subst. repeat find_rewrite.
match goal with
| [ _ : eIndex _ = eIndex ?e',
H : In ?e' (_ ++ _) |- _ ] =>
apply in_app_or in H; intuition
end.
+ (* e2 new *)
unfold log_matching_nw in *.
repeat find_rewrite.
match goal with
| [ Hp : pBody ?p = AppendEntries _ _ _ _ ?es _,
Hp' : pBody ?p' = AppendEntries _ _ _ _ ?entries _,
H : forall _ _ _ _ _ _ _, In _ _ -> _
|- context [ ?es ++ _ ] ]=>
copy_apply H Hp'; [|in_crush];
copy_apply H Hp; [|in_crush]; clear H; intuition;
match goal with
| [ H : forall _ _ _ _ _ _ _, In _ _ -> _,
H' : forall _ _ _ _ _ _ _, In _ _ -> _,
_ : eIndex ?e = eIndex ?e'
|- _] =>
match type of H with
| context [ ?es ] =>
match type of H' with
| context [ ?entries ] =>
eapply H with (e1:=e)(e2:=e') in Hp; eauto;
eapply H' with (e1:=e')(e2:=e) in Hp'; eauto;
intuition; clear H; clear H'
end
end
end
end.
destruct (lt_eq_lt_dec prevLogIndex pli); intuition.
* match goal with
| [ H : forall _, prevLogIndex < _ <= _ -> _
|- _ ] =>
specialize (H pli);
conclude H ltac:(
split; intuition;
eapply lt_le_weak;
eapply lt_le_trans; eauto;
repeat find_reverse_rewrite;
apply maxIndex_is_max; eauto)
end.
break_exists; intuition.
do_elim. subst.
match goal with
| [ H : forall _,
In _ entries -> _ |- _ ] =>
specialize (H x); repeat concludes
end.
subst.
use_log_matching_nw_host.
intuition. break_exists.
repeat find_rewrite.
exists x1. intuition.
apply in_or_app. right.
apply removeAfterIndex_le_In; intuition.
* subst. break_exists. intuition. do_elim.
eexists; intuition eauto.
apply in_or_app. right.
apply removeAfterIndex_le_In; intuition.
* match goal with
| [ H : forall _, pli < _ <= _ -> _ |- _ ] =>
specialize (H prevLogIndex);
conclude H
ltac:(
split; auto;
eapply lt_le_weak;
eapply lt_le_trans; [eauto |
repeat find_rewrite;
eapply maxIndex_is_max;
eauto])
end.
break_exists. exists x. intuition.
+ (* e2 old *)
unfold log_matching_nw in *.
repeat find_rewrite.
use_nw_invariant.
find_copy_apply_lem_hyp removeAfterIndex_in.
find_apply_lem_hyp removeAfterIndex_In_le; intuition.
use_log_matching_nw_host.
intuition. break_exists. intuition.
subst.
exists x. intuition.
apply in_or_app. right.
apply removeAfterIndex_le_In; eauto.
apply lt_le_weak.
eapply lt_le_trans; eauto.
repeat find_rewrite.
eauto.
- unfold log_matching_nw in *.
repeat find_rewrite.
use_nw_invariant.
use_log_matching_nw_host. intuition.
}
- simpl in *.
unfold log_matching_nw in *.
repeat find_rewrite.
use_nw_invariant.
- simpl in *.
unfold log_matching_nw in *.
repeat find_rewrite.
use_nw_invariant.
- simpl in *.
unfold log_matching_nw in *.
repeat find_rewrite.
use_log_matching_nw_nw.
- simpl in *.
unfold log_matching_nw in *.
repeat find_rewrite.
use_log_matching_nw_nw.
- simpl in *.
unfold log_matching_nw in *.
repeat find_rewrite.
use_log_matching_nw_nw.
}
Qed.

(* Specifications: *)
Theorem log_matching_invariant:
forall net,
raft_intermediate_reachable net ->
log_matching net.