OSDN Git Service

fix the regular sync dust block problem (#400) 1.0.3 v1.0.3
authorPaladz <yzhu101@uottawa.ca>
Fri, 20 Sep 2019 14:43:46 +0000 (22:43 +0800)
committerGitHub <noreply@github.com>
Fri, 20 Sep 2019 14:43:46 +0000 (22:43 +0800)
* fix the regular sync dust block problem

* fix the crazy log

* fix ci test

* change the version

* fix bug on handle orphan block

database/store.go
net/websocket/wsnotificationmaneger.go
netsync/chainmgr/block_keeper.go
version/version.go

index 6abd41f..0be3df0 100644 (file)
@@ -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
 }
index f92e6ef..b1d692a 100644 (file)
@@ -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
                }
 
index 80c1277..c670d23 100644 (file)
@@ -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
index 88a5564..000ffeb 100644 (file)
@@ -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