@@ -573,13 +573,6 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
573573 if block .Td .Cmp (self .td ) > 0 {
574574 // Check for chain forks. If H(block.num - 1) != block.parent, we're on a fork and need to do some merging
575575 if previous := self .getBlockByNumber (block .NumberU64 () - 1 ); previous .Hash () != block .ParentHash () {
576- chash := cblock .Hash ()
577- hash := block .Hash ()
578-
579- if glog .V (logger .Info ) {
580- glog .Infof ("Split detected. New head #%v (%x) TD=%v, was #%v (%x) TD=%v\n " , block .Header ().Number , hash [:4 ], block .Td , cblock .Header ().Number , chash [:4 ], self .td )
581- }
582-
583576 // during split we merge two different chains and create the new canonical chain
584577 self .merge (previous , block )
585578
@@ -636,24 +629,33 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
636629// diff takes two blocks, an old chain and a new chain and will reconstruct the blocks and inserts them
637630// to be part of the new canonical chain.
638631func (self * ChainManager ) diff (oldBlock , newBlock * types.Block ) types.Blocks {
639- glog .V (logger .Debug ).Infof ("Applying diff to %x & %x\n " , oldBlock .Hash ().Bytes ()[:4 ], newBlock .Hash ().Bytes ()[:4 ])
640-
641- var newChain types.Blocks
632+ var (
633+ newChain types.Blocks
634+ commonBlock * types.Block
635+ oldStart = oldBlock
636+ newStart = newBlock
637+ )
642638 // first find common number
643639 for newBlock = newBlock ; newBlock .NumberU64 () != oldBlock .NumberU64 (); newBlock = self .GetBlock (newBlock .ParentHash ()) {
644640 newChain = append (newChain , newBlock )
645641 }
646642
647- glog . V ( logger . Debug ). Infoln ( "Found common number" , newBlock .Number () )
643+ numSplit := newBlock .Number ()
648644 for {
649645 if oldBlock .Hash () == newBlock .Hash () {
646+ commonBlock = oldBlock
650647 break
651648 }
652649 newChain = append (newChain , newBlock )
653650
654651 oldBlock , newBlock = self .GetBlock (oldBlock .ParentHash ()), self .GetBlock (newBlock .ParentHash ())
655652 }
656653
654+ if glog .V (logger .Info ) {
655+ commonHash := commonBlock .Hash ()
656+ glog .Infof ("Fork detected @ %x. Reorganising chain from #%v %x to %x" , commonHash [:4 ], numSplit , oldStart .Hash ().Bytes ()[:4 ], newStart .Hash ().Bytes ()[:4 ])
657+ }
658+
657659 return newChain
658660}
659661
0 commit comments