Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a2c7ee9
start of a top-level English spec for the p2p layer
josef-widder Nov 17, 2022
eeacdae
start of intro paragraphs
josef-widder Nov 17, 2022
8158a88
intro done?
josef-widder Nov 17, 2022
2397f81
rename
josef-widder Nov 21, 2022
8ec77d4
to be shared
josef-widder Nov 21, 2022
0461d43
some requirements discussion
josef-widder Nov 22, 2022
6c04c1d
things learned from the SRDS 2021 paper.
josef-widder Nov 24, 2022
128b617
minor changes
josef-widder Nov 24, 2022
a0d0856
Update spec/p2p/p2p-top-level.md
josef-widder Nov 25, 2022
7ef04ee
incorporated comments from the PR discussion
josef-widder Nov 25, 2022
46c857c
Update spec/p2p/p2p-top-level.md
josef-widder Nov 25, 2022
84b521a
added (unstructured) nodes after office hour with Bucky
josef-widder Nov 29, 2022
0fbeaaf
Merge branch 'josef/i9573-josef-p2p' of github.com:tendermint/tenderm…
josef-widder Nov 29, 2022
e3fd2cf
consensus reactor
josef-widder Dec 5, 2022
2d85387
requirements
josef-widder Dec 5, 2022
3bc10d1
req
josef-widder Dec 5, 2022
22c99c2
spec/p2p: mempool requirements, intro to mempool
Jan 16, 2023
10e6489
spec/p2p: mempool internal interactions
Jan 18, 2023
73b2fe2
spec/p2p: mempool first formalization attempt
Jan 18, 2023
ee1d351
first draft of mempool section
josef-widder Jan 19, 2023
d24f2a8
discussion on evidence reactor
josef-widder Jan 19, 2023
5178701
evidence consensus parameters
josef-widder Jan 19, 2023
6923593
addressed two simple comments by Daniel on the Draft PR. More complic…
josef-widder Jan 24, 2023
f0454df
Apply suggestions from code review
Jan 26, 2023
713c66e
Update spec/p2p/p2p-top-level.md
josef-widder Jan 26, 2023
a61f85f
minor changes following PR discussion (without changes to add pending…
josef-widder Jan 26, 2023
268ff6d
Update spec/p2p/p2p-mempool-reqs.md
josef-widder Jan 26, 2023
61e8a9a
rename to CometBFT
josef-widder Jan 27, 2023
e710f4d
pending discussion
josef-widder Jan 27, 2023
3be36d0
requirements with tags
josef-widder Jan 27, 2023
3f3e8f7
sync protocols
josef-widder Jan 30, 2023
d19f085
fixed TODOs in the beginning
josef-widder Jan 31, 2023
73a4ddb
moved reactor discussion out of p2p spec
josef-widder Jan 31, 2023
0e4e76a
clean up expectations. put at right spot for now
josef-widder Jan 31, 2023
b0fc580
final before new PR
josef-widder Jan 31, 2023
f2f73d2
pass over reactor survey
josef-widder Feb 2, 2023
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
142 changes: 142 additions & 0 deletions spec/p2p/p2p-mempool-reqs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
** This (unfinished) document was used to collect a common understanding of the mempool. We will need to see how/whether this should be incorporated in the specification at some moment **

# Mempool
Comment thread
josef-widder marked this conversation as resolved.
Resolved

The mempool is a distributed pool of pending transactions.
A pending transaction is a valid transaction that has been submitted by a
client of the blockchain but has not yet been committed to the blockchain.
The mempool is thus fed with client transactions,
that a priori can be submitted to any node in the network.
And it is consumed by the consensus protocol, more specifically by validator nodes,

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.

Consensus shouldn't have to know about transactions, requiring only that the mempool return a potential block payload. The fact that consensus knows transactions should be a detail of our implementation.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm not sure if I agree. Transactions are values for consensus. Blockchain consensus protocol do batching, a block is a batch of values.

@lasarojc lasarojc Jan 26, 2023 •

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.

I understand but I don't see the value in that as the application itself can do the batching, as the SDK does, specially with ABCI 1 and the application's ability to redo the whole block. But I guess a better point is that the mempool shouldn't have to know about who is consuming its transactions, only that they may be reaped and become invalid due to the transactions being executed or the app state changing.

which retrieve from the mempool transactions to be included in proposed blocks.

More concretely, every node participating in the mempool protocol maintains a
local copy of the mempool, namely a list of pending transactions.
Nodes that expose an interface to receive transactions from clients
append the submitted transactions to their local copy of the mempool.
These nodes are the entry point of the mempool protocol,
and by extension of the consensus protocol.
Nodes that play the role of validators in the consensus protocol,
in their turn, retrieve from their local copy of the mempool
pending transactions to be included in proposed blocks.
Validator nodes are therefore the recipients of the transactions stored and
transported by the mempool protocol.

The goal of the mempool protocol is then to convey transactions
from the nodes that act as entry points of the network
to the nodes whose role is to order transactions.

## Interactions

### RPC server

Clients submit transactions through the RPC endpoints offered by certain
(public) nodes, which add the submitted transactions to the mempool.

### ABCI application

The mempool should only store and convey valid transactions.
It is up to the ABCI application to define whether a transaction is valid.

Transactions received by a node are sent to the application to be validated,
through the CheckTx method from the mempool ABCI connection.
This applies for both transactions received from a client and transactions
received from a peer in the mempool protocol.
Transactions that are validated by the application are appended to the local
copy of the mempool.
Transactions considered invalid by the application are droped, therefore are
not added to the local copy of the mempool.

The validity of a transaction may depend on the state of the application.
In particular, some transactions that were valid considering a given state of
the application can become invalid when the state of the application is updated.
Comment thread
josef-widder marked this conversation as resolved.
Resolved
The state of the application is updated when a commited block of transactions
is delivered to the application for being executed.
Thus, whenever a new block is committed, the list of pending transactions
stored in the mempool is updated to exclude the executed transactions and
sent to the application to be validated against the
new state of the application.
Transactions that have become invalid with the new state of application are
then removed from the mempool.

Comment thread
lasarojc marked this conversation as resolved.
Resolved
### Consensus: validators

The consensus protocol consumes pending transactions stored in the mempool to
build blocks to be proposed.
More precisely, the consensus protocol requests to the mempool a list of
pending transactions that respects certain limits, in terms of the number of
transactions returned, their total size in bytes, and their required gas.
The mempool then returns the longest prefix of its local list of pending
transactions that respects the limits established by the consensus protocol.
This means that the order with which the transactions are stored in the mempool
is preserved when transactions are provided to the consensus protocol.

> Notice that the transactions provided to the consensus protocol are not
> removed from the mempool, as they are still pending transactions albeit being
> included in a proposed block.

As proposing blocks is a prerogative of nodes acting as validators,
only validator nodes interact with the mempool in this way.

### Consensus: all nodes

The consensus protocol is responsible for committing blocks of transactions to
the blockchain.
Once a block is committed to the blockchain, all transactions included in the
block should be removed from the mempool, as they are no any longer pending.
The consensus protocol thus, as part of the procedure to commit a block,
informs the mempool the list of transactions included in the committed block.
The mempool then removes from its local list of pending transactions the
transactions that were included in the committed block, and therefore are no
longer pending.
This procedure precedes the re-validation of transactions against the new state
of the application, which is part of this same procedure to commit a block.

> **Note**
> Notice that a node can commit blocks to the blockchain through different
Comment thread
cason marked this conversation as resolved.
Resolved
> procedures, such as via the block sync protocol.
> The above operation should be part of these other procedures, and should be
> performed whenever a node commits a new block to the blockchain.

## Formalization Attempt

Let `committed(tx, h)` return true iff the transaction `tx` is committed by
height `h` of the blockchain.
This means that `tx` was included in a block `B_k` of transactions with height `k <= h`.

> Notice that `committed(tx, h) => committed(tx, h')` for all `h' > h`.

Lets `valid(tx, h)` to return true iff the transaction `tx` is valid at height
`h` of the blockchain.

> The height of the blockchain reflects the state of the application.
> Some transactions can be valid at a given state (height), but no longer valid
> in another state (height).

We need to assume for the `valid` predicate a property similar to the one we
have for the `committed` predicate.
That is, that from a given height the state of the transaction is not changed
anymore.
While this is trivial for the `committed` predicate, we need to assume that
behavior for the `valid` predicate.

So, we need to assume that there is a height `h*` from which a transaction `tx`
becomes invalid, and this state does not change for higher heights.
That is, we assume that there is a height `h*` so that for all `h >= h* =>
valid(tx, h) == FALSE`.

This property is realistic as applications are expected to implement some form
of replay protection.
This means that once a transaction `tx` is committed, the application should
reject processing the same transaction `tx` again.
This is achieved by rejecting `tx` as invalid from the moment that `tx` is
committed and executed by the application.
So, a replay protection procedure can be define as:
`committed(tx, h) => h' > h \and !valid(tx, h')`

Given these definitions, the main property of the mempool is the following:

- If a transaction `tx` is added to the local mempool of a correct node, then
eventually we have a height `h*` for which either:
- `committed(tx, h*)` is true
- or `!valid(tx, h*)` and `h > h* => !valid(tx, h)`
Loading