insert injects a new head block into the current block chain. This method assumes that the block is indeed a true head. It will also reset the head header and the head fast sync block to this very same block if they are older or if they are on a different side chain. Note, this function assumes tha
(block *types.Block)
| 618 | // |
| 619 | // Note, this function assumes that the `mu` mutex is held! |
| 620 | func (bc *BlockChain) insert(block *types.Block) { |
| 621 | // If the block is on a side chain or an unknown one, force other heads onto it too |
| 622 | updateHeads := rawdb.ReadCanonicalHash(bc.db, block.NumberU64()) != block.Hash() |
| 623 | |
| 624 | // Add the block to the canonical chain number scheme and mark as the head |
| 625 | rawdb.WriteCanonicalHash(bc.db, block.Hash(), block.NumberU64()) |
| 626 | rawdb.WriteHeadBlockHash(bc.db, block.Hash()) |
| 627 | |
| 628 | bc.currentBlock.Store(block) |
| 629 | |
| 630 | // If the block is better than our head or is on a different chain, force update heads |
| 631 | if updateHeads { |
| 632 | bc.hc.SetCurrentHeader(block.Header()) |
| 633 | rawdb.WriteHeadFastBlockHash(bc.db, block.Hash()) |
| 634 | |
| 635 | bc.currentFastBlock.Store(block) |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | // Genesis retrieves the chain's genesis block. |
| 640 | func (bc *BlockChain) Genesis() *types.Block { |
no test coverage detected