pseudoyu

pseudoyu

Blockchain | Programming | Photography | Boyi
github
twitter
telegram
mastodon
bilibili
jike

Cosmos Blockchain Architecture and Tendermint Consensus Mechanism

Introduction#

cosmos_introduction_and_explaination_photo

In my work, I mainly participate in the design and implementation of cross-chain projects. Because some of the company's solutions are based on the Cosmos blockchain, I have made some modifications to the underlying chain development based on the Cosmos SDK during the project that lasted for more than a year. I have gained some understanding of its technical implementation. However, due to the tight development schedule, I have not been able to have a systematic understanding of the architecture design of Cosmos and the Tendermint consensus mechanism.

After the project was completed, I finally had some free time to read "Blockchain Architecture and Implementation: A Detailed Explanation of Cosmos". This article is my own understanding and summary of Cosmos and Tendermint.

Development of Blockchain Technology#

Before discussing the specific Cosmos blockchain, let's review the development of blockchain and the mainstream blockchain technologies in the industry.

Technological Limitations#

Blockchain has been developing for more than a decade, starting from Bitcoin, then the popular EOS, and later Ethereum becoming the mainstream. Each has its own characteristics but also has its limitations.

  • The Bitcoin or Ethereum-based approach requires relatively high technical expertise to implement P2P networks, cryptography, consensus algorithms, etc.
  • The underlying chains based on the PoW (Proof of Work) mechanism consume more and more computational power (electricity), which is not resource-friendly or environmentally friendly.
  • As the number and scale of on-chain applications increase, the performance bottleneck of the chain becomes more apparent.
  • With the increasing complexity of business scenarios and growing demands, the consensus algorithms of the chain also need to adapt to specific scenarios.
  • The underlying architectures of different chains differ greatly, and different chains are isolated from each other, making it difficult to achieve cross-chain communication, which is a challenging problem for cross-chain technology solutions.

Technological Developments#

To address the above problems, the industry has proposed various technical solutions.

  • Due to the resource consumption of PoW, many chains have adopted the PoS (Proof of Stake) mechanism, such as EOS's DPoS and Ethereum's recent PoS upgrade, which have become more mature.
  • To overcome the limitations of underlying chains, the development has gradually shifted from building separate chains for individual applications, similar to Bitcoin, to building ÐApps using smart contracts.
  • To address performance limitations, Bitcoin Cash has increased block capacity, EOS has increased TPS (transactions per second) capacity (claiming millions of TPS), and Ethereum has implemented sharding to process on-chain transactions in parallel.
  • In terms of cross-chain technology, hash locking (hash time-locked contracts) has been applied in Bitcoin and Algorand projects, and there are also solutions such as notaries and relay chains.

Cosmos Blockchain Framework#

Overview#

Cosmos is an open-source blockchain framework developed by Tendermint. Its goal is to solve various problems encountered in the development of blockchain technology and provide a high-performance, highly scalable, and easy-to-develop blockchain framework. The open-source repository can be found here:

Cosmos can be seen as a multi-chain network that aims to achieve the vision of an "Internet of Blockchains." Tendermint and Cosmos SDK are the technical means and implementation paths for this vision.

To address resource consumption and transaction issues, Cosmos uses a combination of BFT (Byzantine Fault Tolerance) and PoS (Proof of Stake). To reduce the threshold for building blockchains and developing blockchain-based applications, Cosmos adopts a more general project construction approach, making chain development based on Cosmos more modular and engineering-oriented. It mainly consists of three parts: Tendermint Core, IBC, and Cosmos SDK.

Cosmos SDK Components#

Although it is called an "SDK," which may cause some misunderstandings that it is just a library/component for interacting with chains, Cosmos SDK can be considered a complete architecture. Developers can use it to quickly build their own blockchains. It is an important component of the Cosmos ecosystem. The open-source repository can be found here:

The Cosmos SDK mainly implements some common modules in blockchains, such as account systems, transactions, on-chain governance, etc. Developers can easily build new functional modules based on it.

The main modules include:

  • Account and transaction-related modules
    • auth: System account management
    • bank: On-chain asset transfer
  • Auxiliary modules
    • genutil: Genesis block
    • supply: Total asset management
    • crisis: Invariant management for all modules
    • params: Parameter management for all modules
  • On-chain governance module
    • gov: On-chain governance mechanism
    • upgrade: Chain upgrade
  • PoS module
    • staking: On-chain asset staking
    • slashing: Punishment for malicious validators
    • evidence: Punishment for active misbehavior by validators
    • mint: On-chain asset minting
    • distribution: Block reward management
  • IBC protocol module
    • ibc/core: Cross-chain communication functionality

As you can see, the design of the Cosmos SDK framework is based on the Object-Capability Model security concept. It is highly modular, and each module has its own storage space and only exposes necessary interfaces to the outside.

Cosmos SDK has a specific role called Keeper, which is responsible for maintaining and updating the state. Through this management method, the specific implementation details of the modules are hidden from each other, and they only interact with each other through the keeper. Each module is only updated by the keeper, effectively ensuring the consistency of the on-chain state.

Tendermint Components#

Tendermint is the core component of Cosmos. It is a high-performance underlying consensus engine for blockchains. From an architectural perspective, it mainly consists of three parts: peer-to-peer network communication layer, consensus protocol layer, and upper-layer application layer. The consensus protocol layer is the key part.

During consensus, Tendermint does not care about the specific transaction details but treats transactions as bytes packed into blocks. It achieves consensus among nodes through mechanisms between nodes. It requires the state update of the upper-layer application to be a deterministic process. Starting from the same initial state, the transaction order is consistent across the entire network (i.e., all normal nodes process a sequence of messages in the same order), and the state of the upper-layer application should also remain consistent across the network. The blockchain includes digital fingerprints of the upper-layer application for verification.

Tendermint consensus can support sub-second block generation in blockchain networks with hundreds of nodes. It provides the feature of block finality, which means that once a block is confirmed, all previous blocks cannot be modified, ensuring the security of the blockchain network.

After block submission, the Tendermint consensus protocol layer interacts with the upper-layer application through ABCI (Application Blockchain Interface), which abstracts the interaction between the application layer and the consensus layer. It completes transaction processing and returns results. The block execution process is divided into multiple steps, and the upper-layer application has autonomy to define business logic through specific interfaces for development and implementation (e.g., implementing validator filtering logic or reusing Tendermint Core's consensus protocol and peer-to-peer network communication to meet chain business requirements).

For specific details and mechanisms of the Tendermint consensus algorithm, you can refer to the following paper:

Its unique mechanisms bring significant advantages to the consensus process in blockchain.

First, Tendermint is derived from the PBFT (Practical Byzantine Fault Tolerance) SMR (State Machine Replication) algorithm but simplifies its mechanism. Its consensus is mainly based on blocks rather than user requests, and it unifies the regular PBFT process with the view-change process in terms of mechanisms, making it easier to understand and implement.

Tendermint provides a solid infrastructure and a good user experience. It is one of the earliest underlying technologies that can support sub-second block generation in blockchain networks with hundreds of nodes. It also ensures that all previous blocks cannot be modified through block finality, ensuring the security of the blockchain network.

Nodes communicate with each other through the Gossip protocol, which does not require full connectivity between nodes but uses the gossip peer-to-peer network for communication. This effectively reduces communication costs between nodes and improves network fault tolerance.

The specific implementation details and mechanisms of the Tendermint algorithm will be explained in detail in future articles.

IBC Protocol Component#

The IBC protocol is a special module in the Cosmos SDK. It mainly provides Cosmos with cross-chain capabilities. Its main principle is to prove its own on-chain events to other chains using cryptographic techniques. It can be understood as cross-chain parties being lightweight nodes (light clients) for each other, and the communication/transactions between the two chains are implemented through relayers.

There are many details in this part, and it is more related to cross-chain technology. A separate article will be dedicated to explaining it in detail.

Conclusion#

This article is the first in a series about Cosmos and the Tendermint consensus. It mainly introduces the development of blockchain technology, the core components of the Cosmos blockchain framework, such as Tendermint and Cosmos SDK, and provides an overview of the principles and mechanisms of the Tendermint consensus protocol. Due to the length limitation, the focus is on conceptual explanations and process summaries, without specific technical implementation details or code explanations. These will be supplemented in future articles on the Tendermint consensus algorithm/mechanism and Cosmos SDK code implementation.

References#

  1. "Blockchain Architecture and Implementation: A Detailed Explanation of Cosmos - Wen Long/Jia Yin"

  2. Cosmos: The Internet of Blockchains

  3. Whitepaper - Resources - Cosmos Network

  4. Distributed Systems and Blockchain Consensus Mechanism · Pseudoyu

  5. Introduction to Cosmos - Tendermint

  6. Introduction to Cosmos - Cosmos SDK

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.