Section SortedProof.
Context {orig_base_params : BaseParams}.
Context {one_node_params : OneNodeParams orig_base_params}.
Context {raft_params : RaftParams orig_base_params}.
Context {tsi : term_sanity_interface}.
Proof using.
unfold raft_net_invariant_init, logs_sorted,
logs_sorted_host, logs_sorted_nw, packets_gt_prevIndex, packets_ge_prevTerm in *.
intuition; simpl in *; intuition.
Qed.
Proof using.
intros. find_apply_lem_hyp handleClientRequest_log. intuition.
Qed.
Proof using.
unfold logs_sorted_nw in *. intros.
simpl in *. find_apply_hyp_hyp. intuition eauto.
Qed.
Proof using.
unfold packets_gt_prevIndex in *. intros.
simpl in *. find_apply_hyp_hyp. intuition eauto.
Qed.
Proof using.
unfold packets_ge_prevTerm in *. intros.
simpl in *. find_apply_hyp_hyp. intuition eauto.
Qed.
Proof using tsi.
unfold logs_sorted_host.
intros.
find_apply_lem_hyp handleClientRequest_log. intuition.
+ repeat find_rewrite. eauto.
+ find_apply_lem_hyp no_entries_past_current_term_invariant.
break_exists; intuition; repeat find_rewrite.
simpl. intuition eauto.
* find_eapply_lem_hyp maxIndex_is_max; eauto.
lia.
* unfold no_entries_past_current_term, no_entries_past_current_term_host in *.
intuition. simpl in *. find_apply_hyp_hyp. lia.
Qed.
Proof using tsi.
unfold raft_net_invariant_client_request. unfold logs_sorted. intuition.
- unfold logs_sorted_host in *. simpl in *. intros.
find_higher_order_rewrite. break_match; eauto.
subst.
eauto using handleClientRequest_logs_sorted.
- find_apply_lem_hyp handleClientRequest_packets. subst. simpl in *.
eauto using logs_sorted_nw_packets_unchanged.
- find_apply_lem_hyp handleClientRequest_packets. subst. simpl in *.
eauto using packets_gt_prevIndex_packets_unchanged.
- find_apply_lem_hyp handleClientRequest_packets. subst. simpl in *.
eauto using packets_ge_prevTerm_packets_unchanged.
Qed.

Theorem handleTimeout_log :
forall h st out st' ps,
handleTimeout h st = (out, st', ps) ->
log st' = log st.