Skip to content

WIP: TLA+ specification of consensus protocol#1

Open
andrewgordstewart wants to merge 5 commits intomasterfrom
consensus-update
Open

WIP: TLA+ specification of consensus protocol#1
andrewgordstewart wants to merge 5 commits intomasterfrom
consensus-update

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.

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?

\* 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?

(***************************************************************************)
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