Section LeaderLogsSublog.
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 {lsi : leader_sublog_interface}.
Context {lltsi : leaderLogs_term_sanity_interface}.
Context {eewci : every_entry_was_created_interface}.
Context {llcei : leaderLogs_candidate_entries_interface}.
Context {cci : cronies_correct_interface}.
Context {vci : votes_correct_interface}.
Proof using.
unfold refined_raft_net_invariant_init, leaderLogs_sublog.
simpl. intuition.
Qed.
Ltac start :=
repeat match goal with
| [ H : _ |- _ ] =>
rewrite update_fun_comm with (f := fst) in H
| [ H : _ |- _ ] =>
rewrite update_fun_comm with (f := snd) in H
| [ H : _ |- _ ] =>
rewrite update_fun_comm with (f := leaderLogs) in H
end;
rewrite update_fun_comm with (f := snd);
simpl in *;
match goal with
| [ H : context [ type ] |- _ ] =>
rewrite update_fun_comm in H;
rewrite update_nop_ext' in H by auto
end;
match goal with
| [ H : context [ currentTerm ] |- _ ] =>
rewrite update_fun_comm in H;
rewrite update_nop_ext' in H by auto
end.
Proof using.
unfold refined_raft_net_invariant_client_request, leaderLogs_sublog.
intuition.
simpl in *.
repeat find_higher_order_rewrite.
find_copy_apply_lem_hyp handleClientRequest_type. intuition.
start.
find_rewrite_lem update_elections_data_client_request_leaderLogs.
find_erewrite_lem update_nop_ext' .
update_destruct_max_simplify.
- destruct (log d) using (handleClientRequest_log_ind ltac:(eauto)).
+ eauto.
+ simpl. right. eauto.
- eauto.
Qed.
Proof using.
unfold refined_raft_net_invariant_timeout, leaderLogs_sublog.
simpl. intuition.
repeat find_higher_order_rewrite.
find_copy_apply_lem_hyp handleTimeout_type.
intuition.
- start.
find_rewrite_lem update_elections_data_timeout_leaderLogs.
find_erewrite_lem update_nop_ext' .
update_destruct_max_simplify; eauto.
erewrite handleTimeout_log_same by eauto; eauto.
- repeat update_destruct_max_simplify; try congruence.
+ find_rewrite_lem update_elections_data_timeout_leaderLogs.
eauto.
+ eauto.
Qed.
Proof using.
unfold handleAppendEntries.
intros.
repeat break_match; repeat find_inversion; simpl in *; auto; discriminate.
Qed.
Proof using.
unfold refined_raft_net_invariant_append_entries, leaderLogs_sublog.
simpl. intuition.
repeat find_higher_order_rewrite.
find_copy_apply_lem_hyp handleAppendEntries_type.
intuition.
- start.
find_rewrite_lem update_elections_data_appendEntries_leaderLogs.
find_erewrite_lem update_nop_ext'.
update_destruct_max_simplify; eauto.
erewrite handleAppendEntries_leader by (eauto; congruence).
eauto.
- repeat update_destruct_max_simplify; try congruence.
+ find_rewrite_lem update_elections_data_appendEntries_leaderLogs.
eauto.
+ eauto.
Qed.
Proof using.
unfold refined_raft_net_invariant_append_entries_reply, leaderLogs_sublog.
simpl. intuition.
repeat find_higher_order_rewrite.
find_copy_apply_lem_hyp handleAppendEntriesReply_type.
intuition.
- start.
find_erewrite_lem update_nop_ext'.
update_destruct_max_simplify; eauto.
erewrite handleAppendEntriesReply_same_log by eauto.
eauto.
- repeat update_destruct_max_simplify; try congruence; eauto.
Qed.
Proof using.
unfold refined_raft_net_invariant_request_vote, leaderLogs_sublog.
simpl. intuition.
repeat find_higher_order_rewrite.
find_copy_apply_lem_hyp handleRequestVote_type.
intuition.
- start.
find_rewrite_lem leaderLogs_update_elections_data_requestVote.
find_erewrite_lem update_nop_ext'.
update_destruct_max_simplify; eauto.
erewrite handleRequestVote_same_log by eauto.
eauto.
- repeat update_destruct_max_simplify; try congruence.
+ find_rewrite_lem leaderLogs_update_elections_data_requestVote.
eauto.
+ eauto.
Qed.
Proof using lsi rri.
intros.
pose proof (lift_prop _ leader_sublog_invariant_invariant).
find_apply_hyp_hyp.
match goal with H : forall _ , _ |- _ => clear H end.
unfold leader_sublog_invariant, leader_sublog_host_invariant in *.
break_and.
do 3 find_insterU.
repeat find_rewrite_lem deghost_spec.
eauto.
Qed.
Proof using.
intros.
unfold handleRequestVoteReply, advanceCurrentTerm in *.
repeat break_match; try find_inversion; subst; simpl in *; intuition;
do_bool; intuition; try right; congruence.
Qed.
Proof using lltsi.
intros.
find_copy_eapply_lem_hyp leaderLogs_term_sanity_invariant; eauto.
find_eapply_lem_hyp leaderLogs_currentTerm_invariant; eauto.
lia.
Qed.
Arguments dedup : simpl never.

Lemma leaderLogs_candidate_entries_rvr :
forall net,
leaderLogs_candidateEntries net ->
votes_correct net ->
cronies_correct net ->
forall p h t ll e,
In (t, ll) (leaderLogs (fst (nwState net h))) ->
In e ll ->
In p (nwPackets net) ->
pBody p = RequestVoteReply (eTerm e) true ->
currentTerm (snd (nwState net (pDst p))) = eTerm e ->
wonElection (dedup name_eq_dec (pSrc p :: votesReceived (snd (nwState net (pDst p))))) = true ->
type (snd (nwState net (pDst p))) <> Candidate.