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 tominedBlockSub
. TheminedBroadcastLoop
(inraft/handler.go
) puts the new block to theProtocolManager.blockProposalC
channel. serveLocalProposals
is waiting at the other end of the channel.serveLocalProposals
RLP-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
AppendEntries
to 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
eventLoop
.eventLoop
processes Raft log entries. The block arrives from the leader throughpm.transport
, an instance ofrafthttp.Transport
. -
The block is handled by
applyNewChainHead
.applyNewChainHead
checks 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 byInsertChain
. -
A
ChainHeadEvent
is posted to notify listeners that a new block has been accepted.ChainHeadEvent
:- Removes the relevant transaction from the transaction pool.
- Removes the relevant transaction from the proposed transactions on this speculative chain.
- Triggers
requestMinting
in (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.