if err := utxoView.ApplyBlock(bcBlock, bcBlock.TransactionStatus); err != nil {
return err
}
+
node := c.index.GetNode(&bcBlock.ID)
if err := c.setState(node, utxoView); err != nil {
return err
}
+
for _, tx := range block.Transactions {
- for key, value := range tx.Entries {
- switch value.(type) {
- case *bc.Claim:
- c.store.SetWithdrawSpent(&key)
- default:
- continue
- }
- }
c.txPool.RemoveTransaction(&tx.Tx.ID)
}
return nil
return err
}
- log.WithFields(log.Fields{"height": node.Height, "hash": node.Hash.String()}).Debug("detach from mainchain")
+ log.WithFields(log.Fields{"module": logModule, "height": node.Height, "hash": node.Hash.String()}).Debug("detach from mainchain")
}
for _, attachNode := range attachNodes {
return err
}
- log.WithFields(log.Fields{"height": node.Height, "hash": node.Hash.String()}).Debug("attach from mainchain")
+ log.WithFields(log.Fields{"module": logModule, "height": node.Height, "hash": node.Hash.String()}).Debug("attach from mainchain")
}
return c.setState(node, utxoView)
bcBlock := types.MapBlock(block)
parent := c.index.GetNode(&block.PreviousBlockHash)
- if err := validation.ValidateBlock(bcBlock, parent, block, c.Authoritys, c.position); err != nil {
+ if err := validation.ValidateBlock(bcBlock, parent); err != nil {
return errors.Sub(ErrBadBlock, err)
}
if err := c.store.SaveBlock(block, bcBlock.TransactionStatus); err != nil {
for _, prevOrphan := range prevOrphans {
orphanBlock, ok := c.orphanManage.Get(prevOrphan)
if !ok {
- log.WithFields(log.Fields{"hash": prevOrphan.String()}).Warning("saveSubBlock fail to get block from orphanManage")
+ log.WithFields(log.Fields{"module": logModule, "hash": prevOrphan.String()}).Warning("saveSubBlock fail to get block from orphanManage")
continue
}
if err := c.saveBlock(orphanBlock); err != nil {
- log.WithFields(log.Fields{"hash": prevOrphan.String(), "height": orphanBlock.Height}).Warning("saveSubBlock fail to save block")
+ log.WithFields(log.Fields{"module": logModule, "hash": prevOrphan.String(), "height": orphanBlock.Height}).Warning("saveSubBlock fail to save block")
continue
}
func (c *Chain) processBlock(block *types.Block) (bool, error) {
blockHash := block.Hash()
if c.BlockExist(&blockHash) {
- log.WithFields(log.Fields{"hash": blockHash.String(), "height": block.Height}).Info("block has been processed")
+ log.WithFields(log.Fields{"module": logModule, "hash": blockHash.String(), "height": block.Height}).Info("block has been processed")
return c.orphanManage.BlockExist(&blockHash), nil
}
bestNode := c.index.GetNode(&bestBlockHash)
if bestNode.Parent == c.bestNode {
- log.Debug("append block to the end of mainchain")
+ log.WithFields(log.Fields{"module": logModule}).Debug("append block to the end of mainchain")
return false, c.connectBlock(bestBlock)
}
- if bestNode.Height > c.bestNode.Height && bestNode.WorkSum.Cmp(c.bestNode.WorkSum) >= 0 {
- log.Debug("start to reorganize chain")
+ if bestNode.Height > c.bestNode.Height {
+ log.WithFields(log.Fields{"module": logModule}).Debug("start to reorganize chain")
return false, c.reorganizeChain(bestNode)
}
return false, nil