Repository navigation
Description
With regards to concurrent calls to ABCI methods, the current specification states that
In principle, each of the four ABCI++ connections operates concurrently with one another. This means applications need to ensure access to state is thread safe. Both the default in-process ABCI client and the default Go ABCI server use a global lock to guard the handling of events across all connections, so they are not concurrent at all. This means whether your app is compiled in-process with Tendermint using the NewLocalClient, or run out-of-process using the SocketServer, ABCI messages from all connections are received in sequence, 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.
In the recalled 0.36 branch, changes had been made to allow for more concurrency
In principle, each of the four ABCI++ connections operates concurrently with one another. This means applications need to ensure access to state is thread safe. Up to v0.35.x, both the default in-process ABCI client and the default Go ABCI server used a global lock to guard the handling of events across all connections, so they were not concurrent at all. This meant whether your app was compiled in-process with Tendermint using the NewLocalClient, or run out-of-process using the SocketServer, ABCI messages from all connections were received in sequence, one at a time. This is no longer the case starting from v0.36.0: the global locks have been removed and it is up to the Application to synchronize access to its state when handling ABCI++ methods on all connections. Nevertheless, as all ABCI calls are now synchronous, ABCI messages using the same connection are still received in sequence.
Also
Before invoking Commit, Tendermint locks the mempool and flushes the mempool connection. This ensures that no new messages will be received on the mempool connection during this processing step, providing an opportunity to safely update all four connection states to the latest committed state at the same time.
and
After the Commit call returns, while still holding the mempool lock, CheckTx is run again on all transactions that remain in the node's local mempool after filtering those included in the block. Parameter Type in RequestCheckTx indicates whether an incoming transaction is new (CheckTxType_New), or a recheck (CheckTxType_Recheck).
Finally, after re-checking transactions in the mempool, Tendermint will unlock the mempool connection. New transactions are once again able to be processed through CheckTx.
Meaning that connections are not completely independent.
The goal of this issue is to clearly document what is the concurrency model of ABCI and, possibly, simplify it so applications can improve concurrency in handling ABCI requests.
DoD:
A formal model of the concurrency model of ABCI >1, that is, what ABCI methods may and cannot be called concurrently. The model allows for multi-threaded handling of calls over multiple connections.
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsDone
Activity
spec: migrate v0.7.1. into v0.34 (#9262)
adizere commentedon May 20, 2023
I think we should start with a smaller scope. We have a specific problem to solve, identified in #815: namely, we want queries to run on a different lock than consensus (if possible). This can cause nodes to fall-out-sync and seem unable to recover. Put differently, the problem we want to solve here: consensus doesn't starve waiting for a lock that a query routine might be holding.
sergio-mena commentedon May 22, 2023
@adizere take a look at tendermint/tendermint#9830, which addresses tendermint/tendermint#7073. This introduces a new client type with a more relaxed concurrency model, similar to the one offered by the socket client, whereby each time you create a new client, it contains a different mutex. So the SDK could create a client for consensus, another client for mempool (i.e.,
CheckTx), another for queries, etc. This will be shipped as part ofv0.38.x.I think this might be useful to #815, although the SDK would need to switch to using
NewUnsyncLocalClientCreator. While this seems a simple change to do on their side, it has massive implications to the SDK... the whole codebase will need to be thoroughly tested for race conditions with the new (more relaxed) concurrency model.adizere commentedon May 22, 2023
Hi @tac0turtle, wanted to put this on your radar, in case there will be interest soon in the SDK to move to using the unsynchronized client cosmos/cosmos-sdk#13788.
tac0turtle commentedon May 22, 2023
Hey thanks for the ping, we dont be working on these sort of changes in the sdk till after this current release and when we begin runtime modules. This issue will be helpful when we start that work.
I dont fully understand this, i thought abci is multiplexed but the current design is the mutex is global.
I have been thinking about ABCI quite a bit and i think it needs to be refactored from the ground up. The current abci was designed in a world where not many people knew how to develop complex state machines, hence consensus controlling the application. We are in a new world where the application is trying to do much more complex things but ABCI is super limiting in what can be done and prevents many complex state machines from existing. Lots of the calls im part of are about how to circumnavigate ABCI in order to achieve x and y. It could be worth talking about if the current design will be the final design and then a completely new design is thought of. A few of us have been doing this approach and designing what we want out of an interface between consensus and the state machine.
lcwik commentedon May 22, 2023
I really liked the approach in tendermint/tendermint#9660 since it allowed pushing the lock all the way into the application. This allowed the application a lot of flexibility to gain big performance gains through some simple things like moving the request/response marshalling and basic message validation outside the mutex.
sergio-mena commentedon May 23, 2023
That's true for the local client. In the socket client (or remote client), you get a different mutex for every "connection" you create with
NewABCIClientmethod of theClientCreatorobtained viaNewRemoteClientCreatoradizere commentedon Jul 11, 2023
I think SDK v0.47 and v0.50 uses the
NewLocalClientCreatorwhich uses the global mutex. There are two alternatives to that:NewUnsyncLocalClientCreator@tac0turtle for a mid-term solution, would the SDK be open to adopting the
NewUnsyncLocalClientCreator? Or is there a preference for having a fully unsynchronized client, as per @lcwik comment above? If the latter, should we prioritize it for v0.39?Also copying @ValarDragon, any preference? For context, this is as a follow-up to our discussion here.
[-]Clarify and formally specify the ABCI concurrency model[/-][+]Introduce relaxed ABCI concurrency models[/+]thanethomson commentedon Jul 18, 2023
For anyone interested, I've submitted #1141 as a demonstration of a slightly more generalized approach to offering different concurrency models when interacting with local clients. Feedback there would be highly appreciated!
adizere commentedon Nov 8, 2023
Fixed in #1141
Merge pull request cometbft#89 from osmosis-labs/mergify/bp/osmo-v25/…
Olshansk commentedon Aug 5, 2025
@adizere @thanethomson I found this PR as a result of this thread in slack in #cosmos-tech.
Will try to keep things short but lmk if I should provide more details...
Our goal is: Prevent heavy EndBlockers from blocking incoming RPC requests.
How we want to achieve it: Use mainline CosmosSDK + mainline CometBFT out of the box with a basic FullNode functionality.
Tradeoffs we're willing to make: Returning data from the latest committed state even if we're processing another block. There are more in the slack thread.
Current thinking: Putting out a PR to change how runTx works in the CosmosSDK.
Question: Can the solution implemented in #1141 somehow be used for this?
cc @red-0ne for visibility.