OSDN Git Service

fix update status
authorwz <mars@bytom.io>
Fri, 30 Aug 2019 02:06:27 +0000 (10:06 +0800)
committerwz <mars@bytom.io>
Fri, 30 Aug 2019 02:06:27 +0000 (10:06 +0800)
toolbar/vote_reward/synchron/block_keeper.go

index c63242a..afcba27 100644 (file)
@@ -79,12 +79,12 @@ func (c *ChainKeeper) syncChainStatus(db *gorm.DB, chainStatus *orm.ChainStatus)
        }
 
        log.WithField("block height", chainStatus.BlockHeight).Debug("the prev hash of remote is not equals the hash of current best block, must rollback")
-       currentBlock, err := c.node.GetBlockByHash(chainStatus.BlockHash)
+       preBlock, err := c.node.GetBlockByHeight(chainStatus.BlockHeight - 1)
        if err != nil {
                return err
        }
 
-       return c.DetachBlock(db, chainStatus, currentBlock)
+       return c.DetachBlock(db, chainStatus, preBlock)
 }
 
 func (c *ChainKeeper) AttachBlock(db *gorm.DB, chainStatus *orm.ChainStatus, block *types.Block) error {
@@ -131,11 +131,11 @@ func (c *ChainKeeper) AttachBlock(db *gorm.DB, chainStatus *orm.ChainStatus, blo
 }
 
 func (c *ChainKeeper) DetachBlock(db *gorm.DB, chainStatus *orm.ChainStatus, block *types.Block) error {
-       if err := db.Where(&orm.Utxo{VoteHeight: block.Height}).Delete(&orm.Utxo{}).Error; err != nil {
+       if err := db.Where(&orm.Utxo{VoteHeight: chainStatus.BlockHeight}).Delete(&orm.Utxo{}).Error; err != nil {
                return err
        }
 
-       if err := db.Model(&orm.Utxo{}).Where(&orm.Utxo{VetoHeight: block.Height}).Update("veto_height", 0).Error; err != nil {
+       if err := db.Model(&orm.Utxo{}).Where(&orm.Utxo{VetoHeight: chainStatus.BlockHeight}).Update("veto_height", 0).Error; err != nil {
                return err
        }