Links

Produce a new block

Step 1: Prepare
A validator node prepares the block header of next block.
路 Load snapshot from cache or database,
路 If (height % epoch)==0, should fetch ValidatorSet from ValidatorSet contract.
路 Every epoch block, will store validators set message in extraData field of block header to facilitate the implement of light client.
路 The coinbase is the address of the validator
Step2: FinalizeAndAssemble
路 If the validator is not the in-turn validator, will call liveness slash contract to slash the expected validator and generate a slashing transaction.
路 If there is gas-fee in the block, will distribute 1/16 to system reward contract, the rest go to validator contract.
Step3: Seal
The final step before a validator broadcast the new block.
路 Sign all things in block header and append the signature to extraData.
路 If it is out of turn for validators to sign blocks, an honest validator it will wait for a random reasonable time.
How to Validate/Replay a block
Step1: VerifyHeader
Verify the block header when receiving a new block.
路 Verify the signature of the coinbase is in extraData of the blockheader
路 Compare the block time of the blockHeader and the expected block time that the signer suppose to use, will deny a blockerHeader that is smaller than expected. It helps to prevent a selfish validator from rushing to seal a block.
路 The coinbase should be the signer and the difficulty should be expected value.
Step2: Finalize
路 If it is an epoch block, a validator node will fetch validatorSet from ValidatorSet and compare it with extra_data.
路 If the block is not generate by inturn validatorvalidaror, will call slash contract. if there is gas-fee in the block, will distribute 1/16 to system reward contract, the rest go to validator contract.
路 The transaction generated by the consensus engine must be the same as the tx in block.
Signature
The signature of the coinbase is in extraData of the blockheader, the structure of extraData is: epoch block. 32 bytes of extraVanity + N*{20 bytes of validator address} + 65 bytes of signature. none epoch block. 32 bytes of extraVanity + 65 bytes of signature. The signed content is the Keccak256 of RLP encoded of the block header.