X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=blobdiff_plain;f=protocol%2Fblock.go;h=ad4647b55f57d54bc55892a24b3ecbee082bfa81;hp=1894f68b6f7af25c7c2da7840fb6e11674071471;hb=2cf5801b2e693a45de9b51ec9aa9c1f787d57105;hpb=cc968002ceac2dfd7665c2ac2b4c32ab6017b525 diff --git a/protocol/block.go b/protocol/block.go index 1894f68b..ad4647b5 100644 --- a/protocol/block.go +++ b/protocol/block.go @@ -86,19 +86,13 @@ func (c *Chain) connectBlock(block *types.Block) (err error) { 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 @@ -126,7 +120,7 @@ func (c *Chain) reorganizeChain(node *state.BlockNode) error { 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 { @@ -147,7 +141,7 @@ func (c *Chain) reorganizeChain(node *state.BlockNode) error { 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) @@ -158,7 +152,7 @@ func (c *Chain) saveBlock(block *types.Block) error { bcBlock := types.MapBlock(block) parent := c.index.GetNode(&block.PreviousBlockHash) - if err := validation.ValidateBlock(bcBlock, parent, block, c, c.engine, 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 { @@ -186,11 +180,11 @@ func (c *Chain) saveSubBlock(block *types.Block) *types.Block { 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 } @@ -230,7 +224,7 @@ func (c *Chain) blockProcesser() { 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 } @@ -248,12 +242,12 @@ func (c *Chain) processBlock(block *types.Block) (bool, error) { 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