Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: TLA+ specification of consensus protocol #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

andrewgordstewart
Copy link
Contributor

No description provided.

\* Arrays are 1-indexed, while the % operator returns a number between 0 and NumParticipants.
\* This explains the following slightly complicated expression
mover(turnNumber) == 1 + ((turnNumber-1) % NumParticipants)
safeToSend(state) ==
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add some spacing here to it's clear that mover and safeToSend are different chunks of logic (methods?functions? not sure what they're called in TLA+)

msg := NULL;
end macro;

macro voteOrreturnFailure(turnNumber, votesRequired)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
macro voteOrreturnFailure(turnNumber, votesRequired)
macro voteOrReturnFailure(turnNumber, votesRequired)

either returnFailure(state.turnNumber)
or if msg.turnNumber > state.turnNumber then
\* First, update our state based on the incoming message
if msg.votesRequired = 0 then returnSuccess()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be clearer if returnSuccess was renamed to indicate it also "sends" a success message.

ConsensusUpdate.tla Show resolved Hide resolved
ConsensusUpdate.tla Show resolved Hide resolved
mover(turnNumber) == 1 + ((turnNumber-1) % NumParticipants)
safeToSend(state) ==
/\ state.type = Types.WAITING
/\ \/ state.ourIndex = state.turnNumber % NumParticipants

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should mover definition be used here?

ConsensusUpdate.tla Show resolved Hide resolved
\* work this way
either returnFailure(state.turnNumber)
or if msg.turnNumber > state.turnNumber then
\* First, update our state based on the incoming message

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A thought: should we strive to eliminate comments that explain code?

ConsensusUpdate.tla Show resolved Hide resolved
(***************************************************************************)
fair process consensusUpdate \in DOMAIN Participants
variables
state = [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is msg defined at the start of the file as opposed to here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! state is a variable that belongs to a process, while msg is a global variable that all processes have access to.

When translated, TLA+ does this by having state be a function whose domain is the set of labels used to label the processes. In this case, DOMAIN Participants are the labels of the processes, so the variable state referred to in the Pluscal specification corresponds to the variable state[p] in the TLA+ translation, where p is the index of the participant.

I'll add to the TLA+ primer

ReachConsensus:
while Running(state) do
if safeToSend(state) /\ msg = NULL then
either returnFailure(state.turnNumber) \* If the commitment is not valid

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If voteOrReturnFailure is used on line 143 below, is this line needed?


\* Safety properties

TypeOK ==

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "safety" and "liveness" properties can be checked in a "model" of the specification (a particular set of values for the constants). The TypeOK property, for instance, specifies what values the msg and state variables can be. (IE. it's a sort of type safety.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants