mirror of https://github.com/poanetwork/quorum.git
4.0 KiB
4.0 KiB
How a block gets added to the chain in quorum
A code walkthrough showing the making of a new block and how nodes receive and vote for it.
Pre-requisites for all nodes:
The BlockVoting service has been started with a block maker strategy in place
On the block maker
- BlockMaker reaches its deadline waiting for a new block from others and fires an event to trigger the creation of a new one itself
- The event is picked up by the BlockVoting loop
- A new block is constructed, inserted into the chain
- A ChainHeadEvent is published on BlockChain.chainEvents
- A NewMinedBlockEvent is published
- The NewMinedBlockEvent will eventually cause the ProtocolManager to broadcast the new block
- Finally, the ChainHeadEvent will cause the node to reset its pending state and vote for its own block
On other nodes
- Node receives a message notifying about new block
- Enqueues it for import
- The fetcher detects a new import has been queued
- And imports it by calling ProtocolManager.insertChain()
- Which in turn calls BlockChain.InsertChain(), which checks that the block was created by a block maker (via BlockValidator.ValidateBlock() -> ValidateHeader() -> ValidateExtraData()), and call BlockValidator.ValidateState() to check that its parent is the current head
- It will then send a ChainHeadEvent on BlockChain.chainEvents
- Which is processed in BlockVoting.run(), causing the Node's pending state to be reset and the node to vote for the new block