* This file contains the default implementation of a 'Block' which is used as 'block bytes' in a quorum certificate */ BLOCK HEADER CODE BELOW Check() 'sanity checks' the block header
(networkID, chainId uint64)
| 16 | |
| 17 | // Check() 'sanity checks' the block header |
| 18 | func (x *BlockHeader) Check(networkID, chainId uint64) ErrorI { |
| 19 | // rejects empty block header |
| 20 | if x == nil { |
| 21 | return ErrNilBlockHeader() |
| 22 | } |
| 23 | // check proposer address size |
| 24 | if len(x.ProposerAddress) != crypto.AddressSize { |
| 25 | return ErrInvalidBlockProposerAddress() |
| 26 | } |
| 27 | // check BlockHash size |
| 28 | if len(x.Hash) != crypto.HashSize { |
| 29 | return ErrWrongLengthBlockHash() |
| 30 | } |
| 31 | // check StateRoot hash size |
| 32 | if len(x.StateRoot) != crypto.HashSize { |
| 33 | return ErrWrongLengthStateRoot() |
| 34 | } |
| 35 | // check TransactionRoot hash size |
| 36 | if len(x.TransactionRoot) != crypto.HashSize { |
| 37 | return ErrWrongLengthTransactionRoot() |
| 38 | } |
| 39 | // check ValidatorRoot hash size |
| 40 | if len(x.ValidatorRoot) != crypto.HashSize { |
| 41 | return ErrWrongLengthValidatorRoot() |
| 42 | } |
| 43 | // check NextValidatorRoot hash size |
| 44 | if len(x.NextValidatorRoot) != crypto.HashSize { |
| 45 | return ErrWrongLengthNextValidatorRoot() |
| 46 | } |
| 47 | // check LastBlockHash hash size |
| 48 | if len(x.LastBlockHash) != crypto.HashSize { |
| 49 | return ErrWrongLengthLastBlockHash() |
| 50 | } |
| 51 | // if after the first block |
| 52 | if x.Height > 1 { |
| 53 | // check the LastQuorumCertificate |
| 54 | if err := x.LastQuorumCertificate.CheckBasic(); err != nil { |
| 55 | return err |
| 56 | } |
| 57 | // ensure the last quorum certificate has the proper network id |
| 58 | if x.LastQuorumCertificate.Header.NetworkId != networkID { |
| 59 | return ErrWrongNetworkID() |
| 60 | } |
| 61 | // check the last quorum certificate has the proper chain id |
| 62 | if x.LastQuorumCertificate.Header.ChainId != chainId { |
| 63 | return ErrWrongChainId() |
| 64 | } |
| 65 | } |
| 66 | // check network id |
| 67 | if uint64(x.NetworkId) != networkID { |
| 68 | return ErrWrongNetworkID() |
| 69 | } |
| 70 | // check for non-zero BlockTime |
| 71 | if x.Time == 0 { |
| 72 | return ErrNilBlockTime() |
| 73 | } |
| 74 | // check for non-zero NetworkID |
| 75 | if x.NetworkId == 0 { |
nothing calls this directly
no test coverage detected