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

Adding an abstract consensus spec #6438

Merged
merged 24 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/tlaplus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ jobs:
sudo apt install -y default-jre
python3 ./tla/install_deps.py

- name: MCabs.cfg
run: |
set -x
cd tla/
./tlc.sh -workers auto consensus/MCabs.tla -dumpTrace tla MCabs.trace.tla -dumpTrace json MCabs.json

- name: MCccfraft.cfg
run: |
set -x
Expand Down
17 changes: 17 additions & 0 deletions tla/consensus/MCabs.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
SPECIFICATION AbsSpec

CONSTANTS
NodeOne = n1
NodeTwo = n2
NodeThree = n3
Servers <- MCServers
Terms <- MCTerms
MaxLogLength <- MCMaxLogLength

INVARIANTS
NoConflicts
TypeOK

PROPERTIES
AppendOnlyProp

11 changes: 11 additions & 0 deletions tla/consensus/MCabs.tla
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---- MODULE MCabs ----

EXTENDS abs

CONSTANTS NodeOne, NodeTwo, NodeThree

MCServers == {NodeOne, NodeTwo, NodeThree}
MCTerms == 2..4
MCMaxLogLength == 7

====
1 change: 1 addition & 0 deletions tla/consensus/MCccfraft.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ PROPERTIES
MembershipStateTransitionsProp
PendingBecomesFollowerProp
NeverCommitEntryPrevTermsProp
RefinementToAbsProp

INVARIANTS
LogInv
Expand Down
16 changes: 16 additions & 0 deletions tla/consensus/MCccfraft.tla
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,20 @@ DebugNotTooManySigsInv ==
\A i \in Servers:
FoldSeq(LAMBDA e, count: IF e.contentType = TypeSignature THEN count + 1 ELSE count, 0, log[i]) < 8

----
\* Refinement

\* The inital log is up to 4 entries long + one log entry per request/reconfiguration + one signature per request/reconfiguration or new view (no consecutive sigs except across views)
MaxLogLength ==
4 + ((RequestLimit + Len(Configurations)) * 2) + MaxTermLimit

MappingToAbs ==
INSTANCE abs WITH
Servers <- Servers,
Terms <- StartTerm..MaxTermLimit,
MaxLogLength <- MaxLogLength,
CLogs <- [i \in Servers |-> [j \in 1..commitIndex[i] |-> log[i][j].term]]

RefinementToAbsProp == MappingToAbs!AbsSpec

===================================
59 changes: 59 additions & 0 deletions tla/consensus/abs.tla
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---- MODULE abs ----
\* Abstract specification for a distributed consensus algorithm.
\* Assumes that any node can atomically inspect the state of all other nodes.

EXTENDS Sequences, SequencesExt, Naturals, FiniteSets, FiniteSetsExt

CONSTANT Servers, Terms, MaxLogLength

\* Commit logs from each node
\* Each log is append-only and the logs will never diverge.
VARIABLE CLogs
heidihoward marked this conversation as resolved.
Show resolved Hide resolved

TypeOK ==
/\ CLogs \in [Servers ->
UNION {[1..l -> Terms] : l \in 0..MaxLogLength}]

StartTerm == Min(Terms)

InitialLogs == {
<<>>,
<<StartTerm, StartTerm>>,
<<StartTerm, StartTerm, StartTerm, StartTerm>>}

Init ==
CLogs \in [Servers -> InitialLogs]

\* A node i can copy a ledger suffix from another node j.
Copy(i) ==
\E j \in Servers :
/\ Len(CLogs[j]) > Len(CLogs[i])
/\ \E l \in 1..(Len(CLogs[j]) - Len(CLogs[i])) :
CLogs' = [CLogs EXCEPT ![i] = @ \o SubSeq(CLogs[j], Len(@) + 1, Len(@) + l)]

\* The node with the longest log can extend its log.
Extend(i) ==
/\ \A j \in Servers : Len(CLogs[j]) \leq Len(CLogs[i])
/\ \E l \in 0..(MaxLogLength - Len(CLogs[i])) :
achamayou marked this conversation as resolved.
Show resolved Hide resolved
\E s \in [1..l -> Terms] :
CLogs' = [CLogs EXCEPT ![i] = @ \o s]

\* The only possible actions are to append log entries.
\* By construction there cannot be any conflicting log entries
\* Log entries are copied if the node's log is not the longest.
Next ==
\E i \in Servers :
\/ Copy(i)
\/ Extend(i)

AbsSpec == Init /\ [][Next]_CLogs

AppendOnlyProp ==
[][\A i \in Servers : IsPrefix(CLogs[i], CLogs'[i])]_CLogs

NoConflicts ==
\A i, j \in Servers :
\/ IsPrefix(CLogs[i], CLogs[j])
\/ IsPrefix(CLogs[j], CLogs[i])

====