Episode 47 - Lifecycle of a Block
A block is a collection of transactions and some metadata. Let’s take a look at how a block is produced. Let’s just assume that according to the algorithm we already have the node (validator or miner) selected to produce the next block.
The first thing that this block producer node would do is to choose which block to build on. Remember blockchain is a chain of blocks. For each new block we need to refer to the hash of the previous block. Hence, the node would first choose or select which block to build on. Recall that all nodes in a blockchain store all the data about the state of the blockchain. So, the node would just pick the hash of the latest block from its local state.
Next, the node would pick the transactions waiting in its transaction queue or mem-pool and create a new block by ordering and packaging them together. This process is call block building. The output would be a block — a data object with metadata and a list of included transactions.
Once the block is built, it is then broadcasted on the peer-to-peer network for other nodes to download and verify it. The details of broadcast and propagation are depend on the specific implementation of networking protocol for different blockchains. Each node in the network then verifies the block by executing all the transactions in it. If they find everything ok, they update their local state based on the transactions in the block. And the block is added to the chain.
This is how a fully decentralized network of nodes updates the state of a distributed ledger.
The next block is the built on top of this block, and the process continues.