Skip to content

Introduce relaxed ABCI concurrency models #88

Closed

Description

@lasarojc

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.

Activity

  1. added
    spec
    on Jan 27, 2023
  2. adizere commented on May 20, 2023

    @adizere
    Contributor

    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.

    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.

  3. sergio-mena commented on May 22, 2023

    @sergio-mena
    Collaborator

    @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 of v0.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.

  4. adizere commented on May 22, 2023

    @adizere
    Contributor

    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.

  5. tac0turtle commented on May 22, 2023

    @tac0turtle
    Contributor

    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.

    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 of v0.38.x.

    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.

  6. lcwik commented on May 22, 2023

    @lcwik

    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.

  7. sergio-mena commented on May 23, 2023

    @sergio-mena
    Collaborator

    but the current design is the mutex is global.

    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 NewABCIClient method of the ClientCreator obtained via NewRemoteClientCreator

  8. adizere commented on Jul 11, 2023

    @adizere
    Contributor

    I dont fully understand this, i thought abci is multiplexed but the current design is the mutex is global.

    I think SDK v0.47 and v0.50 uses the NewLocalClientCreator which uses the global mutex. There are two alternatives to that:

    1. The NewUnsyncLocalClientCreator
      • This is already available in v0.38. The semantics of this client are the same as for the remote (socket) client.
    2. The fully unsynchronized client (abci: Add unsynchronized local client tendermint/tendermint#9660)
      • Allows more flexibility by putting all the responsibility for synchronization on the application.
      • This is not yet released in any version of Comet, we can make it available in v0.39, and optionally port to v0.38 if there is need.

    after this current release and when we begin runtime modules. This issue will be helpful when we start that work.
    I have been thinking about ABCI quite a bit and i think it needs to be refactored from the ground up.

    @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.

  9. changed the title [-]Clarify and formally specify the ABCI concurrency model[/-] [+]Introduce relaxed ABCI concurrency models[/+] on Jul 11, 2023
  10. added
    abci
    on Jul 18, 2023
  11. thanethomson commented on Jul 18, 2023

    @thanethomson
    Contributor

    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!

  12. adizere commented on Nov 8, 2023

    @adizere
    Contributor

    Fixed in #1141

  13. added a commit that references this issue on Jun 25, 2024
  14. Olshansk commented on Aug 5, 2025

    @Olshansk

    @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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    abcispec

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions