Skip to content

Commit

Permalink
Strengthen various *TypeInvs by defining every function's domain. (#6544
Browse files Browse the repository at this point in the history
)

Signed-off-by: Markus Alexander Kuppe <[email protected]>
Co-authored-by: Amaury Chamayou <[email protected]>
  • Loading branch information
lemmy and achamayou authored Oct 9, 2024
1 parent d61931a commit d7cf62f
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions tla/consensus/ccfraft.tla
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ ConfigurationsTypeInv ==
VARIABLE hasJoined

HasJoinedTypeInv ==
\A i \in Servers :
hasJoined[i] \in BOOLEAN
hasJoined \in [ Servers -> BOOLEAN ]

\* retirementCompleted keeps track of nodes that have been retired completed,
\* i.e., their reconfiguration transaction has been committed, and all the configs to which
Expand All @@ -211,8 +210,7 @@ HasJoinedTypeInv ==
VARIABLE retirementCompleted

RetirementCompletedTypeInv ==
\A i \in Servers :
retirementCompleted[i] \subseteq Servers
retirementCompleted \in [ Servers -> SUBSET Servers ]

reconfigurationVars == <<
configurations,
Expand All @@ -229,26 +227,26 @@ ReconfigurationVarsTypeInv ==
VARIABLE currentTerm

CurrentTermTypeInv ==
\A i \in Servers : currentTerm[i] \in Nat
currentTerm \in [ Servers -> Nat ]

\* The leadership state.
VARIABLE leadershipState

LeadershipStateTypeInv ==
\A i \in Servers : leadershipState[i] \in LeadershipStates
leadershipState \in [ Servers -> LeadershipStates ]

\* The membership state.
VARIABLE membershipState

MembershipStateTypeInv ==
\A i \in Servers : membershipState[i] \in MembershipStates
membershipState \in [ Servers -> MembershipStates ]

\* The candidate the server voted for in its current term, or
\* Nil if it hasn't voted for any.
VARIABLE votedFor

VotedForTypeInv ==
\A i \in Servers : votedFor[i] \in {Nil} \cup Servers
votedFor \in [ Servers -> {Nil} \cup Servers ]

\* isNewFollower is a flag used by followers to limit the
\* number of times they rollback to once per term
Expand All @@ -263,7 +261,7 @@ VotedForTypeInv ==
VARIABLE isNewFollower

IsNewFollowerTypeInv ==
\A i \in Servers : isNewFollower[i] \in BOOLEAN
isNewFollower \in [ Servers -> BOOLEAN ]

serverVars == <<currentTerm, leadershipState, membershipState, votedFor, isNewFollower>>

Expand All @@ -286,7 +284,7 @@ LogTypeInv ==
VARIABLE commitIndex

CommitIndexTypeInv ==
\A i \in Servers : commitIndex[i] \in Nat
commitIndex \in [ Servers -> Nat ]

logVars == <<log, commitIndex>>

Expand All @@ -303,8 +301,7 @@ LogVarsTypeInv ==
VARIABLE votesGranted

VotesGrantedTypeInv ==
\A i \in Servers :
votesGranted[i] \subseteq Servers
votesGranted \in [ Servers -> SUBSET Servers ]

candidateVars == <<votesGranted>>

Expand All @@ -323,16 +320,14 @@ CandidateVarsTypeInv ==
VARIABLE sentIndex

SentIndexTypeInv ==
\A i, j \in Servers : i /= j =>
/\ sentIndex[i][j] \in Nat
sentIndex \in [ Servers -> [ Servers -> Nat ] ]

\* The latest entry that each follower has acknowledged is the same as the
\* leader's. This is used to calculate commitIndex on the leader.
VARIABLE matchIndex

MatchIndexTypeInv ==
\A i, j \in Servers : i /= j =>
matchIndex[i][j] \in Nat
matchIndex \in [ Servers -> [ Servers -> Nat ] ]

leaderVars == <<sentIndex, matchIndex>>

Expand Down

0 comments on commit d7cf62f

Please sign in to comment.