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

Method validateImportedHeaders

tests/block_test_util.go:255–272  ·  view source on GitHub ↗
(cm *core.BlockChain, validBlocks []btBlock)

Source from the content-addressed store, hash-verified

253}
254
255func (t *BlockTest) validateImportedHeaders(cm *core.BlockChain, validBlocks []btBlock) error {
256 // to get constant lookup when verifying block headers by hash (some tests have many blocks)
257 bmap := make(map[common.Hash]btBlock, len(t.json.Blocks))
258 for _, b := range validBlocks {
259 bmap[b.BlockHeader.Hash] = b
260 }
261 // iterate over blocks backwards from HEAD and validate imported
262 // headers vs test file. some tests have reorgs, and we import
263 // block-by-block, so we can only validate imported headers after
264 // all blocks have been processed by BlockChain, as they may not
265 // be part of the longest chain until last block is imported.
266 for b := cm.CurrentBlock(); b != nil && b.NumberU64() != 0; b = cm.GetBlockByHash(b.Header().ParentHash) {
267 if err := validateHeader(bmap[b.Hash()].BlockHeader, b.Header()); err != nil {
268 return fmt.Errorf("Imported block header validation failed: %v", err)
269 }
270 }
271 return nil
272}
273
274func (bb *btBlock) decode() (*types.Block, error) {
275 data, err := hexutil.Decode(bb.Rlp)

Callers 1

RunMethod · 0.95

Calls 6

validateHeaderFunction · 0.85
NumberU64Method · 0.80
HeaderMethod · 0.80
CurrentBlockMethod · 0.65
GetBlockByHashMethod · 0.65
HashMethod · 0.65

Tested by

no test coverage detected