if err := utxoView.DetachBlock(detachBlock, txStatus); err != nil {
return err
}
+ log.WithFields(log.Fields{"height": detachBlock.Height, "hash": detachBlock.ID.String()}).Debug("Detach from mainchain")
}
for _, a := range attachBlocks {
if err := utxoView.ApplyBlock(attachBlock, txStatus); err != nil {
return err
}
+ log.WithFields(log.Fields{"height": attachBlock.Height, "hash": attachBlock.ID.String()}).Debug("Attach from mainchain")
}
return c.setState(block, utxoView)
if err := c.store.SaveBlock(block, blockEnts.TransactionStatus); err != nil {
return err
}
+ log.WithFields(log.Fields{"height": block.Height, "hash": blockEnts.ID.String()}).Info("Block saved on disk")
c.orphanManage.Delete(&blockEnts.ID)
parent := c.index.GetNode(&block.PreviousBlockHash)
}
c.index.AddNode(node)
- log.WithFields(log.Fields{"height": block.Height, "hash": blockEnts.ID.String()}).Info("Block saved on disk")
return nil
}
func (c *Chain) processBlock(block *types.Block) (bool, error) {
blockHash := block.Hash()
if c.BlockExist(&blockHash) {
- log.WithField("hash", blockHash.String()).Info("Skip process due to block already been handled")
+ log.WithField("hash", blockHash.String()).Debug("Skip process due to block already been handled")
return c.orphanManage.BlockExist(&blockHash), nil
}
if !c.store.BlockExist(&block.PreviousBlockHash) {
+ log.WithField("hash", blockHash.String()).Debug("Add block to orphan manage")
c.orphanManage.Add(block)
return true, nil
}
bestNode := c.index.GetNode(&bestBlockHash)
if bestNode.parent == bestMainChain {
+ log.WithField("hash", blockHash.String()).Debug("Start to append block to the tail of mainchain")
return false, c.connectBlock(bestBlock)
}
if bestNode.height > bestMainChain.height && bestNode.workSum.Cmp(bestMainChain.workSum) >= 0 {
+ log.WithField("hash", blockHash.String()).Debug("Start to reorganize mainchain")
return false, c.reorganizeChain(bestBlock)
}
"math/big"
"sync"
+ log "github.com/sirupsen/logrus"
+
"github.com/bytom/config"
"github.com/bytom/database/storage"
"github.com/bytom/errors"
c.state.height = node.height
c.state.workSum = node.workSum
+ log.WithFields(log.Fields{
+ "height": c.state.height,
+ "hash": c.state.hash.String(),
+ "workSum": c.state.workSum,
+ }).Debug("Chain best status has been changed")
c.state.cond.Broadcast()
return nil
}