Section MatchIndexSanity.
Context {orig_base_params : BaseParams}.
Context {one_node_params : OneNodeParams orig_base_params}.
Context {raft_params : RaftParams orig_base_params}.
Context {aersi : append_entries_reply_sublog_interface}.
Context {si : sorted_interface}.
Proof using.
unfold raft_net_invariant_init, match_index_sanity.
simpl.
intuition.
Qed.
Proof using.
unfold raft_net_invariant_client_request, match_index_sanity.
simpl.
intros.
repeat find_higher_order_rewrite.
update_destruct_simplify.
- find_copy_apply_lem_hyp handleClientRequest_type.
find_copy_apply_lem_hyp handleClientRequest_matchIndex.
intuition.
+ repeat find_rewrite. auto.
+ repeat find_rewrite.
destruct (name_eq_dec h0 leader).
* subst. rewrite get_set_same_default. auto.
* rewrite get_set_diff_default by auto.
eauto using le_trans.
- auto.
Qed.
Proof using.
unfold matchIndex_preserved.
intros. intuition.
repeat find_rewrite.
auto.
Qed.
Proof using.
unfold raft_net_invariant_timeout, match_index_sanity.
simpl.
intros.
repeat find_higher_order_rewrite.
update_destruct_simplify.
- find_apply_lem_hyp handleTimeout_matchIndex_preserved.
eauto using match_index_sanity_preserved.
- auto.
Qed.
Proof using.
unfold raft_net_invariant_append_entries, match_index_sanity.
simpl.
intros.
repeat find_higher_order_rewrite.
update_destruct_simplify.
- find_apply_lem_hyp handleAppendEntries_matchIndex_preserved.
eauto using match_index_sanity_preserved.
- auto.
Qed.

Lemma handleAppendEntriesReply_matchIndex :
forall h st st' m t es res h',
handleAppendEntriesReply h st h' t es res = (st', m) ->
type st' = Leader ->
type st = Leader /\
(matchIndex st' = matchIndex st \/
res = true /\
currentTerm st = t /\
matchIndex st' =
(assoc_set name_eq_dec (matchIndex st) h'
(Nat.max (assoc_default name_eq_dec (matchIndex st) h' 0)
(maxIndex es)))).