Section AppliedEntriesMonotonicProof.
Context {orig_base_params : BaseParams}.
Context {one_node_params : OneNodeParams orig_base_params}.
Context {raft_params : RaftParams orig_base_params}.
Context {si : sorted_interface}.
Context {lmi : log_matching_interface}.
Context {uii : unique_indices_interface}.
Context {smsi : state_machine_safety_interface}.
Context {misi : max_index_sanity_interface}.
Context {crci : commit_recorded_committed_interface}.
Context {lci : leader_completeness_interface}.
Context {lacimi : lastApplied_commitIndex_match_interface}.
Proof using lmi si.
intros.
find_copy_apply_lem_hyp logs_sorted_invariant.
pose proof log_matching_invariant.
eapply_prop_hyp raft_intermediate_reachable raft_intermediate_reachable.
unfold log_matching, log_matching_hosts, logs_sorted in *.
intuition.
match goal with
| H : forall _ _, _ <= _ <= _ -> _ |- _ =>
specialize (H h i);
conclude H ltac:(intuition; find_apply_lem_hyp maxIndex_is_max; eauto; lia)
end.
break_exists_exists. intuition. apply findAtIndex_intro; eauto using sorted_uniqueIndices.
Qed.
Proof using lmi.
intros.
find_apply_lem_hyp maxIndex_non_empty.
break_exists; intuition; find_rewrite.
find_apply_lem_hyp log_matching_invariant.
unfold log_matching, log_matching_nw in *.
intuition. destruct (pBody p) eqn:?; simpl in *; try congruence.
find_apply_hyp_hyp. intuition. find_inversion.
find_apply_hyp_hyp. lia.
Qed.
Proof using.
intros. unfold deghost in *. simpl.
repeat break_match; subst; simpl.
repeat find_rewrite. reflexivity.
Qed.
Proof using.
intros.
unfold committed in *.
break_exists_exists. intuition.
unfold log_matching, log_matching_hosts in *.
intuition. unfold entries_match in *.
rewrite deghost_snd in *.
match goal with
| H : forall _ _ _ _ _, _  |- In _ (_ (_ _ ?x)) =>
specialize (H h x e e e')
end; intuition eauto.
Qed.
Proof using lmi.
intros.
find_apply_lem_hyp log_matching_invariant.
unfold log_matching, log_matching_hosts in *.
intuition.
unfold contiguous_range_exact_lo.
intuition eauto.
find_apply_hyp_hyp. intuition.
Qed.
Proof using lmi.
intros.
find_apply_lem_hyp log_matching_invariant.
unfold log_matching, log_matching_nw in *.
intuition. destruct (pBody p) eqn:?; simpl in *; try congruence.
find_inversion.
find_apply_hyp_hyp. intuition.
find_apply_hyp_hyp. lia.
Qed.
Proof using lmi.
intros.
find_apply_lem_hyp log_matching_invariant.
unfold log_matching, log_matching_nw in *.
intuition. destruct (pBody p) eqn:?; simpl in *; try congruence.
find_inversion.
find_apply_hyp_hyp. intuition.
Qed.
Proof using.
induction l; simpl in *; intros; intuition eauto.
- apply H0. intuition.
- apply H0. intuition.
Qed.

Lemma handleMessage_applied_entries :
forall net h h' m st' ms,
raft_intermediate_reachable net ->
In {| pBody := m; pDst := h; pSrc := h' |} (nwPackets net) ->
handleMessage h' h m (nwState net h) = (st', ms) ->
applied_entries (nwState net) = applied_entries (update name_eq_dec (nwState net) h st').