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

Method GetBodyRLP

core/blockchain.go:667–683  ·  view source on GitHub ↗

GetBodyRLP retrieves a block body in RLP encoding from the database by hash, caching it if found.

(hash common.Hash)

Source from the content-addressed store, hash-verified

665// GetBodyRLP retrieves a block body in RLP encoding from the database by hash,
666// caching it if found.
667func (bc *BlockChain) GetBodyRLP(hash common.Hash) rlp.RawValue {
668 // Short circuit if the body's already in the cache, retrieve otherwise
669 if cached, ok := bc.bodyRLPCache.Get(hash); ok {
670 return cached.(rlp.RawValue)
671 }
672 number := bc.hc.GetBlockNumber(hash)
673 if number == nil {
674 return nil
675 }
676 body := rawdb.ReadBodyRLP(bc.db, hash, *number)
677 if len(body) == 0 {
678 return nil
679 }
680 // Cache the found body for next time and return
681 bc.bodyRLPCache.Add(hash, body)
682 return body
683}
684
685// HasBlock checks if a block is fully present in the database or not.
686func (bc *BlockChain) HasBlock(hash common.Hash, number uint64) bool {

Callers 1

handleSyncMsgMethod · 0.80

Calls 3

GetMethod · 0.65
AddMethod · 0.65
GetBlockNumberMethod · 0.45

Tested by

no test coverage detected