X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=blobdiff_plain;f=toolbar%2Fvote_reward%2Fsynchron%2Fblock_keeper.go;fp=toolbar%2Fvote_reward%2Fsynchron%2Fblock_keeper.go;h=368cb44fed8a70c5e468332bb8113f1adb00ff4a;hp=990348099863b1a6b9b6381307e86771aa29ace5;hb=de1c66cada24ab0f0bd22868de0049369810e1a0;hpb=bf344d15e46e6031e872d999d36e8352fa5f2bc4 diff --git a/toolbar/vote_reward/synchron/block_keeper.go b/toolbar/vote_reward/synchron/block_keeper.go index 99034809..368cb44f 100644 --- a/toolbar/vote_reward/synchron/block_keeper.go +++ b/toolbar/vote_reward/synchron/block_keeper.go @@ -84,7 +84,12 @@ func (c *ChainKeeper) syncChainStatus(db *gorm.DB, chainStatus *orm.ChainStatus) return err } - return c.DetachBlock(db, chainStatus, currentBlock) + preBlock, err := c.node.GetBlockByHash(currentBlock.PreviousBlockHash.String()) + if err != nil { + return err + } + + return c.DetachBlock(db, chainStatus, preBlock) } func (c *ChainKeeper) AttachBlock(db *gorm.DB, chainStatus *orm.ChainStatus, block *types.Block) error { @@ -131,11 +136,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.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 }