MCPcopy Create free account
hub / github.com/tendermint/tendermint / ValidateBasic

Method ValidateBasic

types/block.go:54–95  ·  view source on GitHub ↗

ValidateBasic performs basic validation that doesn't involve state data. It checks the internal consistency of the block. Further validation is done using state#ValidateBlock.

()

Source from the content-addressed store, hash-verified

52// It checks the internal consistency of the block.
53// Further validation is done using state#ValidateBlock.
54func (b *Block) ValidateBasic() error {
55 if b == nil {
56 return errors.New("nil block")
57 }
58
59 b.mtx.Lock()
60 defer b.mtx.Unlock()
61
62 if err := b.Header.ValidateBasic(); err != nil {
63 return fmt.Errorf("invalid header: %w", err)
64 }
65
66 // Validate the last commit and its hash.
67 if b.LastCommit == nil {
68 return errors.New("nil LastCommit")
69 }
70 if err := b.LastCommit.ValidateBasic(); err != nil {
71 return fmt.Errorf("wrong LastCommit: %v", err)
72 }
73
74 if w, g := b.LastCommit.Hash(), b.LastCommitHash; !bytes.Equal(w, g) {
75 return fmt.Errorf("wrong Header.LastCommitHash. Expected %X, got %X", w, g)
76 }
77
78 // NOTE: b.Data.Txs may be nil, but b.Data.Hash() still works fine.
79 if w, g := b.Data.Hash(), b.DataHash; !bytes.Equal(w, g) {
80 return fmt.Errorf("wrong Header.DataHash. Expected %X, got %X", w, g)
81 }
82
83 // NOTE: b.Evidence.Evidence may be nil, but we're just looping.
84 for i, ev := range b.Evidence.Evidence {
85 if err := ev.ValidateBasic(); err != nil {
86 return fmt.Errorf("invalid evidence (#%d): %v", i, err)
87 }
88 }
89
90 if w, g := b.Evidence.Hash(), b.EvidenceHash; !bytes.Equal(w, g) {
91 return fmt.Errorf("wrong Header.EvidenceHash. Expected %X, got %X", w, g)
92 }
93
94 return nil
95}
96
97// fillHeader fills in any remaining header fields that are a function of the block data
98func (b *Block) fillHeader() {

Callers

nothing calls this directly

Calls 5

LockMethod · 0.65
UnlockMethod · 0.65
ValidateBasicMethod · 0.65
HashMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected