FastSyncCommitHead sets the current head block to the one defined by the hash irrelevant what the chain contents were prior.
(hash common.Hash)
| 447 | // FastSyncCommitHead sets the current head block to the one defined by the hash |
| 448 | // irrelevant what the chain contents were prior. |
| 449 | func (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. |
| 468 | func (bc *BlockChain) GasLimit() uint64 { |