Episode 37 - Lifecycle of a Blockchain Transaction
The user or DApp composes a transaction with information like input parameters, cryptographic signature, and some metadata about the blockchain network and a serialized data object is created out of it. All of this happens outside the blockchain using Wallets or DApps.
This serialized transaction data is then sent to one of the blockchain nodes using the RPC API.
Once the transaction is submitted to the node, some initial validation checks are run on it. If it is found valid, it is placed in the transaction queue of the node. At this time, it is also broadcasted to other nodes connected as peers to this node. Other nodes also run validations on the transaction.
The transaction, along with other transactions, is then picked up by one of the nodes (assuming it has reached that node’s transaction queue) to be included in the next block they propose. Which node creates the next block is part of the consensus and block production algorithm. This could be different in different blockchain protocols. One thing that influences the inclusion of transactions in the block is the transaction fee paid by the user. The transactions are generally prioritized according to the fee.
Once one of the nodes proposes a block, it is then propagated to other nodes in the network. All other nodes verify the block by executing all transactions included in it. Once majority of the nodes successfully verify the block, they reach consensus.
Once the network agrees on the new block’s validity, all the nodes update their local state of the blockchain by executing all transaction in the block and committing that state. The next block would be built on top of this new state.
At this time, the effects of the transaction are visible because the state of the blockchain is updated across all nodes.