Episode 36 - Anatomy of a Blockchain Node
Blockchains are peer to peer network of nodes. These nodes connect with each other and come to consensus on the state of the blockchain. All these nodes are basically computers running the blockchain node software. Let’s look at all the components of a blockchain node that come together to make it all possible.
Storage: This is the most basic component of the blockchain node. This is where the state of the blockchain is stored. In general, this is simply a database optimized for blockchain use-cases. All the Merkle tree logic and related functions are implemented in the storage component of the blockchain node.
Networking: Using the networking component, the nodes connect with each other and pass messages. Without the networking component, there would be no network, and there would be no consensus. This component is mainly comprised of two sub-components — discovery and message passing. Using discovery, the nodes find and connect with their close peers, and using messaging they pass information required for sharing state and voting on consensus.
Consensus: The consensus engine is responsible for getting agreement on the state of the blockchain among all the nodes. All the logic about PoW, PoS, etc. is implemented in the consensus algorithm. In general, the consensus algorithm is responsible for finding which node would produce the next block of whose block would be accepted, and getting the votes from all peers on the validity of the block.
Transaction Queue: When a user submits a transaction to a blockchain node, and before this transaction is included in a block, it is temporarily stored in the transaction queue on the node for initial validation checks. The nodes also share these transactions with other nodes, so that any node could propose them in the next block as per the rules. Transaction queue is also knows as the mem-pool.
Node API: The node API is the user facing API that is used by users and applications to interact with the blockchain nodes. When the users submit a transaction, they use this API. The API is also used for several other purposes like reading the state, etc. Without an API, the users and apps won’t be able to interact with the blockchain.
State Transition Function (STF): The STF of a blockchain is the most important component and it represents the core business logic of the blockchain. In the STF, all the rules about processing of transactions and their execution are implemented. The state of the blockchain is updated based on these rules written in the STF. For example, in the Bitcoin blockchain, the STF implements the logic about transfer of bitcoins from one account to other(s) when the users submit transactions.