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

Method FastSyncCommitHead

core/blockchain.go:449–465  ·  view source on GitHub ↗

FastSyncCommitHead sets the current head block to the one defined by the hash irrelevant what the chain contents were prior.

(hash common.Hash)

Source from the content-addressed store, hash-verified

447// FastSyncCommitHead sets the current head block to the one defined by the hash
448// irrelevant what the chain contents were prior.
449func (bc *BlockChain) FastSyncCommitHead(hash common.Hash) error {
450 // Make sure that both the block as well at its state trie exists
451 block := bc.GetBlockByHash(hash)
452 if block == nil {
453 return fmt.Errorf("non existent block [%x…]", hash[:4])
454 }
455 if _, err := trie.NewSecure(block.StateRoot(), bc.stateCache.TrieDB(), 0); err != nil {
456 return err
457 }
458 // If all checks out, manually set the head block
459 bc.mu.Lock()
460 bc.currentBlock.Store(block)
461 bc.mu.Unlock()
462
463 log.Info("Committed new head block", "number", block.Number(), "hash", hash.Hex())
464 return nil
465}
466
467// GasLimit returns the gas limit of the current HEAD block.
468func (bc *BlockChain) GasLimit() uint64 {

Callers

nothing calls this directly

Calls 7

GetBlockByHashMethod · 0.95
StateRootMethod · 0.80
LockMethod · 0.80
UnlockMethod · 0.80
TrieDBMethod · 0.65
InfoMethod · 0.65
NumberMethod · 0.45

Tested by

no test coverage detected