Updated on December 7, 2020
Lifecycle of a transaction in Raft
On any node (minter, follower, or learner)
- The transaction is submitted using an RPC call to GoQuorum.
- Using the P2P protocol, the transaction is announced to all peers. Raft clusters use static nodes so every transaction is sent to all peers in the cluster.
On the minter
- When the transaction reaches the minter, the transaction is included in the next block (see
mintNewBlock) via the transaction pool.
- Block creation triggers a
NewMinedBlockEvent. The Raft protocol manager receives the new block event via subscription to
raft/handler.go) puts the new block to the
serveLocalProposalsis waiting at the other end of the channel.
serveLocalProposalsRLP-encodes blocks and proposes the blocks to Raft. Once the block flows through Raft, this block most likely becomes the new head of the blockchain (on all nodes).
On every node
Raft reaches consensus and appends the log entry containing the block to the Raft log. At the Raft layer, the leader sends an
AppendEntriesto all followers, and all followers acknowledge receipt of the message. Once the leader has received a quorum of acknowledgements, the leader notifies each node that the new entry has been committed permanently to the log.
Having crossed the network through Raft, the block reaches the
eventLoopprocesses Raft log entries. The block arrives from the leader through
pm.transport, an instance of
The block is handled by
applyNewChainHeadchecks whether the block extends the chain (that is, whether the block parent is the current head of the chain). If the block does not extend the chain, the block is ignored as a no-op. If the block does extend the chain, the block is validated and written as the new head of the chain by
ChainHeadEventis posted to notify listeners that a new block has been accepted.
- Removes the relevant transaction from the transaction pool.
- Removes the relevant transaction from the proposed transactions on this speculative chain.
minter.go) to schedule the minting of a new block if more transactions are pending.
The transaction is now available on all nodes in the cluster with finality. Raft guarantees a single ordering of log entries. Everything that is committed is guaranteed to remain so there is no forking of a blockchain built on Raft.