From: Paladz Date: Fri, 20 Sep 2019 14:43:46 +0000 (+0800) Subject: fix the regular sync dust block problem (#400) X-Git-Tag: v1.0.5~42 X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=commitdiff_plain;h=3f53de9ec5cce160d620d98bf5b5b706e0ded743 fix the regular sync dust block problem (#400) * fix the regular sync dust block problem * fix the crazy log * fix ci test * change the version * fix bug on handle orphan block --- diff --git a/database/store.go b/database/store.go index 6abd41fb..0be3df02 100644 --- a/database/store.go +++ b/database/store.go @@ -325,6 +325,7 @@ func (s *Store) SaveBlockHeader(blockHeader *types.BlockHeader) error { // SaveChainStatus save the core's newest status && delete old status func (s *Store) SaveChainStatus(blockHeader, irrBlockHeader *types.BlockHeader, mainBlockHeaders []*types.BlockHeader, view *state.UtxoViewpoint, consensusResults []*state.ConsensusResult) error { + currentStatus := loadBlockStoreStateJSON(s.db) batch := s.db.NewBatch() if err := saveUtxoView(batch, view); err != nil { return err @@ -364,6 +365,13 @@ func (s *Store) SaveChainStatus(blockHeader, irrBlockHeader *types.BlockHeader, batch.Set(calcMainChainIndexPrefix(bh.Height), binaryBlockHash) s.cache.removeMainChainHash(bh.Height) } + + if currentStatus != nil { + for i := blockHeader.Height + 1; i <= currentStatus.Height; i++ { + batch.Delete(calcMainChainIndexPrefix(i)) + s.cache.removeMainChainHash(i) + } + } batch.Write() return nil } diff --git a/net/websocket/wsnotificationmaneger.go b/net/websocket/wsnotificationmaneger.go index f92e6ef1..b1d692a0 100644 --- a/net/websocket/wsnotificationmaneger.go +++ b/net/websocket/wsnotificationmaneger.go @@ -445,7 +445,12 @@ out: } if m.status.BestHash != block.PreviousBlockHash { - log.WithFields(log.Fields{"module": logModule, "blockHeight": block.Height, "previousBlockHash": m.status.BestHash, "rcvBlockPrevHash": block.PreviousBlockHash}).Warning("The previousBlockHash of the received block is not the same as the hash of the previous block") + log.WithFields(log.Fields{ + "module": logModule, + "block_height": block.Height, + "status_block_hash": m.status.BestHash.String(), + "retrive_block_PrevHash": block.PreviousBlockHash.String(), + }).Warning("The previousBlockHash of the received block is not the same as the hash of the previous block") continue } diff --git a/netsync/chainmgr/block_keeper.go b/netsync/chainmgr/block_keeper.go index 80c12779..c670d23a 100644 --- a/netsync/chainmgr/block_keeper.go +++ b/netsync/chainmgr/block_keeper.go @@ -162,8 +162,7 @@ func (bk *blockKeeper) regularBlockSync() error { targetHeight = peerHeight } - i := bestHeight + 1 - for i <= targetHeight { + for i := bestHeight + 1; i <= targetHeight; { block, err := bk.msgFetcher.requireBlock(bk.syncPeer.ID(), i) if err != nil { bk.peers.ProcessIllegal(bk.syncPeer.ID(), security.LevelConnException, err.Error()) @@ -180,7 +179,14 @@ func (bk *blockKeeper) regularBlockSync() error { i-- continue } - i = bk.chain.BestBlockHeight() + 1 + + //This code is used to preventing the sync peer return a dust block which will not change the node's chain status + if bestHeight = bk.chain.BestBlockHeight(); i == bestHeight+1 { + log.WithFields(log.Fields{"module": logModule, "height": i}).Warn("stop regular sync due to loop sync same height") + return nil + } + + i = bestHeight + 1 } log.WithFields(log.Fields{"module": logModule, "height": bk.chain.BestBlockHeight()}).Info("regular sync success") return nil diff --git a/version/version.go b/version/version.go index 88a55644..000ffeb8 100644 --- a/version/version.go +++ b/version/version.go @@ -47,7 +47,7 @@ const ( var ( // The full version string - Version = "1.0.2" + Version = "1.0.3" // GitCommit is set with --ldflags "-X main.gitCommit=$(git rev-parse HEAD)" GitCommit string Status *UpdateStatus