I'm learning about
transaction lifecycle in
substrate docs, I saw the diagram but I don't understand the flow operation of this diagram. Please, let's explain the flow operation of the transaction lifecycle.
The transaction is submitted to a network within a JSON-RPC request and will be processed by an authoring node.
Transactions are first validated using the rules that are defined in the runtime and queued on the local node in a transaction pool. After the initial validity check, the transaction pool periodically checks whether existing transactions in the pool are still valid. If a transaction is found to be invalid or has expired, it is dropped from the pool.
If a transaction is identified as valid, the transaction pool moves the transaction into a transaction queue. The next block author node uses a priority system to order the transactions for the next block. The transactions are ordered from high to low priority until the block reaches the maximum weight or length.
From the transaction queue the executive module orchestrates how transactions are executed to produce a block. Once the block is produced, the block is published to the network.
The Substrate docs official documentation has a summary that I like:
- The local node listens for transactions on the network.
- Each transaction is verified.
- Valid transactions are placed in the transaction pool.
- The transaction pool orders the valid transactions in the appropriate transaction queue and the executive module calls into the runtime to begin the next block.
- Transactions are executed and state changes are stored in local memory.
- The constructed block is published to the network.
This previous StackExchange answer has a very detailed explanation with links into the codebase: Transactions lifecycle
A video on youtube Transaction lifecycle | Substrate Seminar