Section PrefixWithinTerm.
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 {llli : logs_leaderLogs_interface}.
Context {rlmli : refined_log_matching_lemmas_interface}.
Context {ollpti : one_leaderLog_per_term_interface}.
Context {llsi : leaderLogs_sorted_interface}.
Context {llsli : leaderLogs_sublog_interface}.
Context {lsli : leader_sublog_interface}.
Context {nisi : nextIndex_safety_interface}.
Context {llci : leaderLogs_contiguous_interface}.
Context {aelmi : allEntries_log_matching_interface}.
Context {aertsi : append_entries_request_term_sanity_interface}.
Context {aelsi : allEntries_leader_sublog_interface}.
Definition lift_leader_sublog :
forall net leader e h,
refined_raft_intermediate_reachable net ->
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 lsli rri.
intros. pose proof lift_prop leader_sublog_host_invariant.
conclude_using ltac:(apply leader_sublog_invariant_invariant).
find_apply_hyp_hyp.
match goal with
| H : leader_sublog_host_invariant _ |- _ =>
specialize (H leader e h)
end.
repeat find_rewrite_lem deghost_spec. intuition.
Qed.
Proof using.
unfold deghost.
simpl.
intros.
eexists; intuition eauto.
apply in_map_iff. eexists; eauto.
Qed.
Definition lift_leader_sublog_nw :
forall net leader p t leaderId prevLogIndex prevLogTerm entries leaderCommit e,
refined_raft_intermediate_reachable net ->
type (snd (nwState net leader)) = Leader ->
In p (nwPackets net) ->
pBody p = AppendEntries t leaderId prevLogIndex prevLogTerm
entries leaderCommit ->
In e entries ->
eTerm e = currentTerm (snd (nwState net leader)) ->
In e (log (snd (nwState net leader))).
Proof using lsli rri.
intros.
pose proof lift_prop leader_sublog_nw_invariant.
conclude_using ltac:(apply leader_sublog_invariant_invariant).
find_apply_hyp_hyp.
find_apply_lem_hyp exists_deghosted_packet.
match goal with
| H : exists _, _ |- _ => destruct H as [q]
end. break_and.
match goal with
| H : leader_sublog_nw_invariant _ |- _ =>
specialize (H leader q t leaderId prevLogIndex prevLogTerm entries leaderCommit e)
end.
repeat find_rewrite_lem deghost_spec. subst. simpl in *.
intuition.
Qed.
Definition append_entries_append_entries_prefix_within_term_nw net :=
forall p t n pli plt es ci p' t' n' pli' plt' es' ci' e e',
In p (nwPackets net) ->
pBody p = AppendEntries t n pli plt es ci ->
In p' (nwPackets net) ->
pBody p' = AppendEntries t' n' pli' plt' es' ci' ->
eTerm e = eTerm e' ->
eIndex e <= eIndex e' ->
In e es ->
In e' es' ->
(In e es' \/ (eIndex e = pli' /\ eTerm e = plt') \/ (eIndex e < pli' /\ eTerm e <= plt')).
Proof using ollpti rlmli llli.
red. red. intros.
match goal with
| H : In ?e _,
H' : In ?e' _ |- _ =>
copy_eapply logs_leaderLogs_invariant H; eauto;
copy_eapply logs_leaderLogs_invariant H'; eauto
end.
break_exists; intuition.
repeat find_rewrite.
find_eapply_lem_hyp one_leaderLog_per_term_log_invariant; eauto.
conclude_using eauto. subst.
assert (exists e'', eIndex e'' = eIndex e /\ In e'' (log (snd (nwState net h')))) by
(eapply entries_contiguous_invariant; eauto; intuition;
[eapply entries_gt_0_invariant; eauto|];
eapply le_trans; eauto;
eapply maxIndex_is_max; eauto;
apply entries_sorted_invariant; auto).
break_exists. intuition.
match goal with
| _ : removeAfterIndex ?l ?i = _ _,
_ : In ?x ?l,
_ : eIndex ?x = _ |- _ =>
assert (In x (removeAfterIndex l i)) by (apply removeAfterIndex_le_In; eauto; lia)
end.
repeat find_rewrite. do_in_app. intuition.
- find_apply_hyp_hyp.
eapply entries_match_invariant; eauto; repeat find_rewrite; auto.
- cut (e = x0); intros; subst; intuition.
eapply uniqueIndices_elim_eq; eauto.
+ apply sorted_uniqueIndices.
apply entries_sorted_invariant.
auto.
+ match goal with
| H : context [ removeAfterIndex ?l ?index ] |- In _ ?l =>
apply removeAfterIndex_in with (i := index)
end.
repeat find_rewrite. apply in_app_iff; intuition.
Qed.
Definition locked_or x y :=
x \/ y.

Theorem append_entries_append_entries_prefix_within_term_invariant :
forall net,
refined_raft_intermediate_reachable net ->
append_entries_append_entries_prefix_within_term_nw net.