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

Method writeHeader

core/blockchain.go:1859–1868  ·  view source on GitHub ↗

writeHeader writes a header into the local chain, given that its parent is already known. If the total difficulty of the newly inserted header becomes greater than the current known TD, the canonical chain is re-routed. Note: This method is not concurrent-safe with inserting blocks simultaneously i

(header *types.Header)

Source from the content-addressed store, hash-verified

1857// in two scenarios: pure-header mode of operation (light clients), or properly
1858// separated header/block phases (non-archive clients).
1859func (bc *BlockChain) writeHeader(header *types.Header) error {
1860 bc.wg.Add(1)
1861 defer bc.wg.Done()
1862
1863 bc.mu.Lock()
1864 defer bc.mu.Unlock()
1865
1866 _, err := bc.hc.WriteHeader(header)
1867 return err
1868}
1869
1870// CurrentHeader retrieves the current head header of the canonical chain. The
1871// header is retrieved from the HeaderChain's internal cache.

Callers

nothing calls this directly

Calls 4

LockMethod · 0.80
UnlockMethod · 0.80
WriteHeaderMethod · 0.80
AddMethod · 0.65

Tested by

no test coverage detected