MCPcopy
hub / github.com/canopy-network/canopy / Check

Method Check

lib/block.go:18–97  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

16
17// Check() 'sanity checks' the block header
18func (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 {

Callers

nothing calls this directly

Calls 15

HashFunction · 0.92
ErrNilBlockHeaderFunction · 0.85
ErrWrongLengthBlockHashFunction · 0.85
ErrWrongLengthStateRootFunction · 0.85
ErrWrongNetworkIDFunction · 0.85
ErrWrongChainIdFunction · 0.85
ErrNilBlockTimeFunction · 0.85

Tested by

no test coverage detected