• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: 提交

Golang implemented sidechain for Bytom


Commit MetaInfo

修订版3f53de9ec5cce160d620d98bf5b5b706e0ded743 (tree)
时间2019-09-20 23:43:46
作者Paladz <yzhu101@uott...>
CommiterGitHub

Log Message

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

更改概述

差异

--- a/database/store.go
+++ b/database/store.go
@@ -325,6 +325,7 @@ func (s *Store) SaveBlockHeader(blockHeader *types.BlockHeader) error {
325325
326326 // SaveChainStatus save the core's newest status && delete old status
327327 func (s *Store) SaveChainStatus(blockHeader, irrBlockHeader *types.BlockHeader, mainBlockHeaders []*types.BlockHeader, view *state.UtxoViewpoint, consensusResults []*state.ConsensusResult) error {
328+ currentStatus := loadBlockStoreStateJSON(s.db)
328329 batch := s.db.NewBatch()
329330 if err := saveUtxoView(batch, view); err != nil {
330331 return err
@@ -364,6 +365,13 @@ func (s *Store) SaveChainStatus(blockHeader, irrBlockHeader *types.BlockHeader,
364365 batch.Set(calcMainChainIndexPrefix(bh.Height), binaryBlockHash)
365366 s.cache.removeMainChainHash(bh.Height)
366367 }
368+
369+ if currentStatus != nil {
370+ for i := blockHeader.Height + 1; i <= currentStatus.Height; i++ {
371+ batch.Delete(calcMainChainIndexPrefix(i))
372+ s.cache.removeMainChainHash(i)
373+ }
374+ }
367375 batch.Write()
368376 return nil
369377 }
--- a/net/websocket/wsnotificationmaneger.go
+++ b/net/websocket/wsnotificationmaneger.go
@@ -445,7 +445,12 @@ out:
445445 }
446446
447447 if m.status.BestHash != block.PreviousBlockHash {
448- 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")
448+ log.WithFields(log.Fields{
449+ "module": logModule,
450+ "block_height": block.Height,
451+ "status_block_hash": m.status.BestHash.String(),
452+ "retrive_block_PrevHash": block.PreviousBlockHash.String(),
453+ }).Warning("The previousBlockHash of the received block is not the same as the hash of the previous block")
449454 continue
450455 }
451456
--- a/netsync/chainmgr/block_keeper.go
+++ b/netsync/chainmgr/block_keeper.go
@@ -162,8 +162,7 @@ func (bk *blockKeeper) regularBlockSync() error {
162162 targetHeight = peerHeight
163163 }
164164
165- i := bestHeight + 1
166- for i <= targetHeight {
165+ for i := bestHeight + 1; i <= targetHeight; {
167166 block, err := bk.msgFetcher.requireBlock(bk.syncPeer.ID(), i)
168167 if err != nil {
169168 bk.peers.ProcessIllegal(bk.syncPeer.ID(), security.LevelConnException, err.Error())
@@ -180,7 +179,14 @@ func (bk *blockKeeper) regularBlockSync() error {
180179 i--
181180 continue
182181 }
183- i = bk.chain.BestBlockHeight() + 1
182+
183+ //This code is used to preventing the sync peer return a dust block which will not change the node's chain status
184+ if bestHeight = bk.chain.BestBlockHeight(); i == bestHeight+1 {
185+ log.WithFields(log.Fields{"module": logModule, "height": i}).Warn("stop regular sync due to loop sync same height")
186+ return nil
187+ }
188+
189+ i = bestHeight + 1
184190 }
185191 log.WithFields(log.Fields{"module": logModule, "height": bk.chain.BestBlockHeight()}).Info("regular sync success")
186192 return nil
--- a/version/version.go
+++ b/version/version.go
@@ -47,7 +47,7 @@ const (
4747
4848 var (
4949 // The full version string
50- Version = "1.0.2"
50+ Version = "1.0.3"
5151 // GitCommit is set with --ldflags "-X main.gitCommit=$(git rev-parse HEAD)"
5252 GitCommit string
5353 Status *UpdateStatus
Show on old repository browser