-
Jay Guo authored
This CR rewrites BlockCreator so that it doesn't return nil block. BEFORE: blockcreator holds a channel of created blocks, which is buffered with size of createdBlocksBuffersize (default 20). It also stores the hash and number of latest block. When requested to create new block, blockcreator does so by assembling a block based on that hash and number, enque the block to buffered channel. If channel is full, a nil is returned. When commit a block, it drains the channel. If there's nothing in the channel, it implies the blockcreator is manipulated by raft follower, therefore blockreator simply updates hash and number. NOW: what we need is actually as simple as: a blockcreator holds the hash and number of latest block. When it is requested to create a block, it just uses that hash and number to assemble one. And ONLY raft leader holds a blockcreator. Followers blindly commit whatever comes from consensus. When a follower is elected as new leader, it simply looks up the ledger, find hash and number of latest block, and creates a new blockcreator. Change-Id: I226ee34d666fbb1e8d034dc22ea6800df993f7a4 Signed-off-by:
Jay Guo <guojiannan1101@gmail.com>