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

Method CheckBasic

lib/certificate.go:36–111  ·  view source on GitHub ↗

QUORUM CERTIFICATE CODE BELOW CheckBasic() performs 'sanity' checks on the Quorum Certificate structure

()

Source from the content-addressed store, hash-verified

34
35// CheckBasic() performs 'sanity' checks on the Quorum Certificate structure
36func (x *QuorumCertificate) CheckBasic() ErrorI {
37 // a valid QC must have either the results hash or the proposer key set
38 if x == nil || (x.ResultsHash == nil && x.ProposerKey == nil) {
39 // exit with empty qc error
40 return ErrEmptyQuorumCertificate()
41 }
42 // sanity check the view of the QC
43 if err := x.Header.CheckBasic(); err != nil {
44 // exit with error
45 return err
46 }
47 // is QC with result (AFTER ELECTION)
48 if x.ResultsHash != nil {
49 // check the block hash for the proper size
50 if len(x.BlockHash) != crypto.HashSize {
51 return ErrInvalidBlockHash()
52 }
53 // check the result hash for the proper size
54 if len(x.ResultsHash) != crypto.HashSize {
55 return ErrInvalidResultsHash()
56 }
57 // results may be omitted in certain cases like double sign evidence
58 if x.Results != nil {
59 if err := x.Results.CheckBasic(); err != nil {
60 return err
61 }
62 // validate the ProposalHash = the hash of the proposal sign bytes
63 resultsBytes, err := Marshal(x.Results)
64 if err != nil {
65 return err
66 }
67 // check the results hash
68 if !bytes.Equal(x.ResultsHash, crypto.Hash(resultsBytes)) {
69 return ErrMismatchResultsHash()
70 }
71 }
72 // block may be omitted in certain cases like the 'reward transaction'
73 if x.Block != nil {
74 // create a new block object reference to ensure a non nil result
75 block := new(Block)
76 // populate the block structure with the block bytes in the certificate
77 hash, e := block.BytesToBlockHash(x.Block)
78 // if an error occurred during this conversion
79 if e != nil {
80 // exit with the error
81 return e
82 }
83 // check the block hash
84 if !bytes.Equal(x.BlockHash, hash) {
85 return ErrMismatchQCBlockHash()
86 }
87 // ensure the number of bytes in the block doesn't exceed the global max block size
88 blockSize := len(x.Block)
89 // global max block size enforcement
90 if blockSize > GlobalMaxBlockSize {
91 return ErrExpectedMaxBlockSize()
92 }
93 }

Callers 1

CheckMethod · 0.95

Calls 13

HashFunction · 0.92
ErrInvalidBlockHashFunction · 0.85
ErrInvalidResultsHashFunction · 0.85
ErrMismatchResultsHashFunction · 0.85
ErrMismatchQCBlockHashFunction · 0.85
ErrExpectedMaxBlockSizeFunction · 0.85
ErrInvalidSignerFunction · 0.85
ErrNonNilBlockFunction · 0.85
EqualMethod · 0.80
BytesToBlockHashMethod · 0.80
MarshalFunction · 0.70

Tested by

no test coverage detected