Skip to content
This repository was archived by the owner on Feb 23, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
156 changes: 156 additions & 0 deletions spec/abci++/v0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# Tendermint v0 Markdown pseudocode

This translates the latex code for Tendermint consensus from the Tendermint paper into markdown.

### Initialization

```go
h_p ← 0
round_p ← 0
step_p is one of {propose, prevote, precommit}
decision_p ← Vector()
lockedRound_p ← -1
lockedValue_p ← nil
Comment thread
ValarDragon marked this conversation as resolved.
Resolved
validValue_p ← nil
validRound_p ← -1
```

### StartRound(round)

```go
function startRound(round) {
round_p ← round
step_p ← propose
if proposer(h_p, round_p) = p {
if validValue_p != nil {
proposal ← validValue_p
} else {
proposal ← getValue()
}
broadcast ⟨PROPOSAL, h_p, round_p, proposal, validRound_p⟩
} else {
schedule OnTimeoutPropose(h_p,round_p) to be executed after timeoutPropose(round_p)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We are lacking logic for OnTimeoutPropose.

}
}
```

### ReceiveProposal

In the case where the local node is not locked on any round, the following is ran:

@milosevic milosevic Sep 16, 2021 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This rule is for the case when fresh proposal has been received (validRound in Proposal message is -1). Note that at line 42 lockedValue = v. Difference between this rule and the rule at line 54 is that in this case no proof of locking is needed (quorum of PREVOTE messages) as validRound = -1.


```go
upon ⟨PROPOSAL, h_p, round_p, v, −1) from proposer(h_p, round_p) while step_p = propose do {
if valid(v) ∧ (lockedRound_p = −1 ∨ lockedValue_p = v) {
broadcast ⟨PREVOTE, h_p, round_p, id(v)⟩
} else {
broadcast ⟨PREVOTE, h_p, round_p, nil⟩
}
step_p ← prevote
}
```

In the case where the node is locked on a round, the following is ran:

@milosevic milosevic Sep 16, 2021 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In this case, the same as above, local node can have locked some value or not, but the importance is on the fact that proposed value need to be supported by the quorum of PREVOTE messages as validRound >= 0.


```go
upon ⟨PROPOSAL, h_p, round_p, v, vr⟩ from proposer(h_p, round_p)
AND 2f + 1 ⟨PREVOTE, h_p, vr, id(v)⟩
while step_p = propose ∧ (vr ≥ 0 ∧ vr < round_p) do {
if valid(v) ∧ (lockedRound_p ≤ vr ∨ lockedValue_p = v) {
broadcast ⟨PREVOTE, h_p, round_p, id(v)⟩
} else {
broadcast ⟨PREVOTE, h_p, round_p, nil⟩
}
step_p ← prevote
}
```

### Prevote timeout

Upon receiving 2f + 1 prevotes, setup a timeout.

```go
upon 2f + 1 ⟨PREVOTE, h_p, vr, *⟩ with step_p = prevote for the first time, do {
schedule OnTimeoutPrevote(h_p, round_p) to be executed after timeoutPrevote(round_p)
}
```

with OnTimeoutPrevote defined as:

```go
function OnTimeoutPrevote(height, round) {
if (height = h_p && round = round_p && step_p = prevote) {
broadcast ⟨PRECOMMIT, h_p, round_p, nil⟩
step_p ← precommit
}
}
```

### Receiving enough prevotes to precommit

The following code is ran upon receiving 2f + 1 prevotes for the same block

```go
upon ⟨PROPOSAL, h_p, round_p, v, *⟩
from proposer(h_p, round_p)
AND 2f + 1 ⟨PREVOTE, h_p, round_p, id(v)⟩
while valid(v) ∧ step_p >= prevote for the first time do {
if (step_p = prevote) {
lockedValue_p ← v
lockedRound_p ← round_p
broadcast ⟨PRECOMMIT, h_p, round_p, id(v)⟩
step_p ← precommit
}
validValue_p ← v
validRound_p ← round_p
}
```

And upon receiving 2f + 1 prevotes for nil:

```go
upon 2f + 1 ⟨PREVOTE, h_p, round_p, nil⟩
while step_p = prevote do {
broadcast ⟨PRECOMMIT, h_p, round_p, nil⟩
step_p ← precommit
}
```

### Precommit timeout

Upon receiving 2f + 1 precommits, setup a timeout.

```go
upon 2f + 1 ⟨PRECOMMIT, h_p, vr, *⟩ for the first time, do {
schedule OnTimeoutPrecommit(h_p, round_p) to be executed after timeoutPrecommit(round_p)
}
```

with OnTimeoutPrecommit defined as:

```go
function OnTimeoutPrecommit(height, round) {
if (height = h_p && round = round_p) {
StartRound(round_p + 1)
}
}
```

### Upon Receiving 2f + 1 precommits

The following code is ran upon receiving 2f + 1 precommits for the same block

```go
upon ⟨PROPOSAL, h_p, r, v, *⟩
from proposer(h_p, r)
AND 2f + 1 ⟨ PRECOMMIT, h_p, r, id(v)⟩
while decision_p[h_p] = nil do {
if (valid(v)) {
decision_p[h_p] ← v
h_p ← h_p + 1
reset lockedRound_p, lockedValue_p,validRound_p and validValue_p to initial values
StartRound(0)
}
}
```

If we don't see 2f + 1 precommits for the same block, we wait until we get 2f + 1 precommits, and the timeout occurs.
162 changes: 162 additions & 0 deletions spec/abci++/v1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Tendermint v1 Markdown pseudocode

This adds hooks for the existing ABCI to the prior pseudocode

### Initialization

```go
h_p ← 0
round_p ← 0
step_p is one of {propose, prevote, precommit}
decision_p ← Vector()
lockedValue_p ← nil
validValue_p ← nil
validRound_p ← -1
```

### StartRound(round)

```go
function startRound(round) {
round_p ← round
step_p ← propose
if proposer(h_p, round_p) = p {
if validValue_p != nil {
proposal ← validValue_p
} else {
txdata ← mempool.GetBlock()
// getBlockProposal fills in header
proposal ← getBlockProposal(txdata)
}
broadcast ⟨PROPOSAL, h_p, round_p, proposal, validRound_p⟩
} else {
schedule OnTimeoutPropose(h_p,round_p) to be executed after timeoutPropose(round_p)
}
}
```

### ReceiveProposal

In the case where the local node is not locked on any round, the following is ran:

```go
upon ⟨PROPOSAL, h_p, round_p, v, −1) from proposer(h_p, round_p) while step_p = propose do {
if valid(v) ∧ (lockedRound_p = −1 ∨ lockedValue_p = v) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should clarify the semantic of valid(v) function, i.e., is it done purely at the Tendermint level (basically block header verification), or we assume it requires also application level checks.

broadcast ⟨PREVOTE, h_p, round_p, id(v)⟩
} else {
broadcast ⟨PREVOTE, h_p, round_p, nil⟩
}
step_p ← prevote
}
```

In the case where the node is locked on a round, the following is ran:

```go
upon ⟨PROPOSAL, h_p, round_p, v, vr⟩
from proposer(h_p, round_p)
AND 2f + 1 ⟨PREVOTE, h_p, vr, id(v)⟩
while step_p = propose ∧ (vr ≥ 0 ∧ vr < round_p) do {
if valid(v) ∧ (lockedRound_p ≤ vr ∨ lockedValue_p = v) {
broadcast ⟨PREVOTE, h_p, round_p, id(v)⟩
} else {
broadcast ⟨PREVOTE, h_p, round_p, nil⟩
}
step_p ← prevote
}
```

### Prevote timeout

Upon receiving 2f + 1 prevotes, setup a timeout.

```go
upon 2f + 1 ⟨PREVOTE, h_p, vr, -1⟩
with step_p = prevote for the first time, do {
schedule OnTimeoutPrevote(h_p, round_p) to be executed after timeoutPrevote(round_p)
}
```

with OnTimeoutPrevote defined as:

```go
function OnTimeoutPrevote(height, round) {
if (height = h_p && round = round_p && step_p = prevote) {
broadcast ⟨PRECOMMIT, h_p, round_p, nil⟩
step_p ← precommit
}
}
```

### Receiving enough prevotes to precommit

The following code is ran upon receiving 2f + 1 prevotes for the same block

```go
upon ⟨PROPOSAL, h_p, round_p, v, *⟩
from proposer(h_p, round_p)
AND 2f + 1 ⟨PREVOTE, h_p, vr, id(v)⟩
while valid(v) ∧ step_p >= prevote for the first time do {
if (step_p = prevote) {
lockedValue_p ← v
lockedRound_p ← round_p
broadcast ⟨PRECOMMIT, h_p, round_p, id(v)⟩
step_p ← precommit
}
validValue_p ← v
validRound_p ← round_p
}
```

And upon receiving 2f + 1 prevotes for nil:

```go
upon 2f + 1 ⟨PREVOTE, h_p, round_p, nil⟩
while step_p = prevote do {
broadcast ⟨PRECOMMIT, h_p, round_p, nil⟩
step_p ← precommit
}
```

### Precommit timeout

Upon receiving 2f + 1 precommits, setup a timeout.

```go
upon 2f + 1 ⟨PRECOMMIT, h_p, vr, *⟩ for the first time, do {
schedule OnTimeoutPrecommit(h_p, round_p) to be executed after timeoutPrecommit(round_p)
}
```

with OnTimeoutPrecommit defined as:

```go
function OnTimeoutPrecommit(height, round) {
if (height = h_p && round = round_p) {
StartRound(round_p + 1)
}
}
```

### Upon Receiving 2f + 1 precommits

The following code is ran upon receiving 2f + 1 precommits for the same block

```go
upon ⟨PROPOSAL, h_p, r, v, *⟩
from proposer(h_p, r)
AND 2f + 1 ⟨ PRECOMMIT, h_p, r, id(v)⟩
while decision_p[h_p] = nil do {
if (valid(v)) {
decision_p[h_p] ← v
h_p ← h_p + 1
reset lockedRound_p, lockedValue_p,validRound_p and validValue_p to initial values
ABCI.BeginBlock(v.header)
ABCI.DeliverTxs(v.data)
ABCI.EndBlock()
StartRound(0)
}
}
```

If we don't see 2f + 1 precommits for the same block, we wait until we get 2f + 1 precommits, and the timeout occurs.
Loading