diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-05-15 01:38:10 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-05-15 01:38:10 +0800 |
commit | 3ac34ee3c4a3a7b875fc672a958075455d0181bc (patch) | |
tree | 81da5a4445565a084a4c0f51d30c0588e50cb42b | |
parent | 69c78ddbb4a99858780668988831ae000198ef22 (diff) | |
parent | b19bf3ec7817b8288389be559ef437b31e678c16 (diff) | |
download | go-tangerine-3ac34ee3c4a3a7b875fc672a958075455d0181bc.tar go-tangerine-3ac34ee3c4a3a7b875fc672a958075455d0181bc.tar.gz go-tangerine-3ac34ee3c4a3a7b875fc672a958075455d0181bc.tar.bz2 go-tangerine-3ac34ee3c4a3a7b875fc672a958075455d0181bc.tar.lz go-tangerine-3ac34ee3c4a3a7b875fc672a958075455d0181bc.tar.xz go-tangerine-3ac34ee3c4a3a7b875fc672a958075455d0181bc.tar.zst go-tangerine-3ac34ee3c4a3a7b875fc672a958075455d0181bc.zip |
Merge pull request #975 from obscuren/develop
core: changed log message for forks. closes #952
-rw-r--r-- | core/chain_manager.go | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/core/chain_manager.go b/core/chain_manager.go index 0480f692b..9f6d7f823 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -573,13 +573,6 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) { if block.Td.Cmp(self.td) > 0 { // Check for chain forks. If H(block.num - 1) != block.parent, we're on a fork and need to do some merging if previous := self.getBlockByNumber(block.NumberU64() - 1); previous.Hash() != block.ParentHash() { - chash := cblock.Hash() - hash := block.Hash() - - if glog.V(logger.Info) { - 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) - } - // during split we merge two different chains and create the new canonical chain self.merge(previous, block) @@ -636,17 +629,21 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) { // diff takes two blocks, an old chain and a new chain and will reconstruct the blocks and inserts them // to be part of the new canonical chain. func (self *ChainManager) diff(oldBlock, newBlock *types.Block) types.Blocks { - glog.V(logger.Debug).Infof("Applying diff to %x & %x\n", oldBlock.Hash().Bytes()[:4], newBlock.Hash().Bytes()[:4]) - - var newChain types.Blocks + var ( + newChain types.Blocks + commonBlock *types.Block + oldStart = oldBlock + newStart = newBlock + ) // first find common number for newBlock = newBlock; newBlock.NumberU64() != oldBlock.NumberU64(); newBlock = self.GetBlock(newBlock.ParentHash()) { newChain = append(newChain, newBlock) } - glog.V(logger.Debug).Infoln("Found common number", newBlock.Number()) + numSplit := newBlock.Number() for { if oldBlock.Hash() == newBlock.Hash() { + commonBlock = oldBlock break } newChain = append(newChain, newBlock) @@ -654,6 +651,11 @@ func (self *ChainManager) diff(oldBlock, newBlock *types.Block) types.Blocks { oldBlock, newBlock = self.GetBlock(oldBlock.ParentHash()), self.GetBlock(newBlock.ParentHash()) } + if glog.V(logger.Info) { + commonHash := commonBlock.Hash() + glog.Infof("Fork detected @ %x. Reorganising chain from #%v %x to %x", commonHash[:4], numSplit, oldStart.Hash().Bytes()[:4], newStart.Hash().Bytes()[:4]) + } + return newChain } |