Consensus

Understand how transactions are propagated to the network and why blockchain nodes need to agree on the transactions to be added to the chain.

So far, what we know about blockchains is that:

  • A blockchain network has one logical common ledger.

  • A blockchain network is made up of several independent nodes.

  • Each node has a copy of the ledger.

When new transactions are submitted to the network, a new block must be appended to the chain so that the global state of the ledger changes. But, if all nodes are independent of each other, who decides what transactions to include in a block? How is the uniqueness of the ledger preserved?

Metaphorically, we can picture this as a group of people deciding which restaurant to go to for dinner. If they agree on a common choice, the problem does not exist. They have reached a consensus. But we know well that this is a utopian scenario. Most of the time, the group must find a way to reach an agreement: they have to realize a consensus mechanism.

A consensus mechanism is a set of rules and protocols (with incentives or penalties) that all nodes must adhere to continuously agree on the current version of a blockchain’s state.

Transaction propagation

To understand how blockchain nodes resolve disputes, first we need to know the journey a transaction takes from its creation to its inclusion in a block. The steps might differ from one blockchain to another, but typically they are:

  1. Construction: A user constructs the transaction with the appropriate software.

  2. Propagation: The transaction is sent to a node in the network, which in turn propagates it to its neighboring nodes (peers), and so on, like it happens in a P2P network.

  3. Formal validation: Some verification is done before a transaction is admitted to the mempool (a storage system where valid and pending transactions wait for finalization in a block).

  4. Mempool insertion: If valid, the transaction is marked as pending and added to the node’s mempool.

  5. Block selection: Each node selects from its mempool a set of transactions and forms a candidate block.

  6. Block validation: The node sequentially executes all the transactions into the candidate block and ensures they do not break the rules of the blockchain network.

Get hands-on with 1200+ tech skills courses.