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.