MCPcopy Create free account
hub / github.com/CPChain/chain / ValidateBody

Method ValidateBody

core/block_validator.go:50–72  ·  view source on GitHub ↗

ValidateBody validates the header's transaction root. The headers are assumed to be already validated at this point.

(block *types.Block)

Source from the content-addressed store, hash-verified

48// ValidateBody validates the header's transaction root.
49// The headers are assumed to be already validated at this point.
50func (v *BlockValidator) ValidateBody(block *types.Block) error {
51 // check whether the block's known, and if not, that it's linkable
52 if v.bc.HasBlockAndState(block.Hash(), block.NumberU64()) {
53 return ErrKnownBlock
54 }
55
56 if !v.bc.HasBlockAndState(block.ParentHash(), block.NumberU64()-1) {
57 // we do not have the parent block
58 if !v.bc.HasBlock(block.ParentHash(), block.NumberU64()-1) {
59 return consensus.ErrUnknownAncestor
60 }
61 // we have the parent block but its state is pruned
62 return consensus.ErrPrunedAncestor
63 }
64
65 // if a block already exists, but the state is missing. we will also try to insert it.
66 // header validity is known at this point, check the transactions validity
67 header := block.Header()
68 if hash := types.DeriveSha(block.Transactions()); hash != header.TxsRoot {
69 return fmt.Errorf("transaction root hash mismatch: have %x, want %x", hash, header.TxsRoot)
70 }
71 return nil
72}
73
74// ValidateState validates the various changes that happen after a state
75// transition, such as amount of used gas, the receipt roots and the state root

Callers

nothing calls this directly

Calls 7

HasBlockAndStateMethod · 0.80
NumberU64Method · 0.80
ParentHashMethod · 0.80
HeaderMethod · 0.80
TransactionsMethod · 0.80
HashMethod · 0.65
HasBlockMethod · 0.65

Tested by

no test coverage detected