This repository has been archived by the owner on Feb 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
abci: note on concurrency #258
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,26 @@ Since Tendermint maintains four concurrent ABCI connections, it is typical | |
for an application to maintain a distinct state for each, and for the states to | ||
be synchronized during `Commit`. | ||
|
||
### Concurrency | ||
|
||
In principle, each of the four ABCI connections operate concurrently with one | ||
another. This means applications need to ensure access to state is | ||
thread safe. In practice, both the | ||
[default in-process ABCI client](https://github.com/tendermint/tendermint/blob/v0.34.4/abci/client/local_client.go#L18) | ||
and the | ||
[default Go ABCI | ||
server](https://github.com/tendermint/tendermint/blob/v0.34.4/abci/server/socket_server.go#L32) | ||
use global locks across all connections, so they are not | ||
concurrent at all. This means if your app is written in Go, and compiled in-process with Tendermint | ||
using the default `NewLocalClient`, or run out-of-process using the default `SocketServer`, | ||
ABCI messages from all connections will be linearizable (received one at a | ||
time). | ||
|
||
The existence of this global mutex means Go application developers can get | ||
thread safety for application state by routing *all* reads and writes through the ABCI | ||
system. Thus it may be *unsafe* to expose application state directly to an RPC | ||
interface, and unless explicit measures are taken, all queries should be routed through the ABCI Query method. | ||
|
||
### BeginBlock | ||
|
||
The BeginBlock request can be used to run some code at the beginning of | ||
|
@@ -37,7 +57,7 @@ pick up from when it restarts. See information on the Handshake, below. | |
Application state should only be persisted to disk during `Commit`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As in contrast to what? |
||
|
||
Before `Commit` is called, Tendermint locks and flushes the mempool so that no new messages will | ||
be received on the mempool connection. This provides an opportunity to safely update all three | ||
be received on the mempool connection. This provides an opportunity to safely update all four connection | ||
states to the latest committed state at once. | ||
|
||
When `Commit` completes, it unlocks the mempool. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this tendermint state or application. Would be good to differentiate. These two separate states get conflated often