Golang implemented sidechain for Bytom
Révision | 3f53de9ec5cce160d620d98bf5b5b706e0ded743 (tree) |
---|---|
l'heure | 2019-09-20 23:43:46 |
Auteur | Paladz <yzhu101@uott...> |
Commiter | GitHub |
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
@@ -325,6 +325,7 @@ func (s *Store) SaveBlockHeader(blockHeader *types.BlockHeader) error { | ||
325 | 325 | |
326 | 326 | // SaveChainStatus save the core's newest status && delete old status |
327 | 327 | func (s *Store) SaveChainStatus(blockHeader, irrBlockHeader *types.BlockHeader, mainBlockHeaders []*types.BlockHeader, view *state.UtxoViewpoint, consensusResults []*state.ConsensusResult) error { |
328 | + currentStatus := loadBlockStoreStateJSON(s.db) | |
328 | 329 | batch := s.db.NewBatch() |
329 | 330 | if err := saveUtxoView(batch, view); err != nil { |
330 | 331 | return err |
@@ -364,6 +365,13 @@ func (s *Store) SaveChainStatus(blockHeader, irrBlockHeader *types.BlockHeader, | ||
364 | 365 | batch.Set(calcMainChainIndexPrefix(bh.Height), binaryBlockHash) |
365 | 366 | s.cache.removeMainChainHash(bh.Height) |
366 | 367 | } |
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 | + } | |
367 | 375 | batch.Write() |
368 | 376 | return nil |
369 | 377 | } |
@@ -445,7 +445,12 @@ out: | ||
445 | 445 | } |
446 | 446 | |
447 | 447 | 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") | |
449 | 454 | continue |
450 | 455 | } |
451 | 456 |
@@ -162,8 +162,7 @@ func (bk *blockKeeper) regularBlockSync() error { | ||
162 | 162 | targetHeight = peerHeight |
163 | 163 | } |
164 | 164 | |
165 | - i := bestHeight + 1 | |
166 | - for i <= targetHeight { | |
165 | + for i := bestHeight + 1; i <= targetHeight; { | |
167 | 166 | block, err := bk.msgFetcher.requireBlock(bk.syncPeer.ID(), i) |
168 | 167 | if err != nil { |
169 | 168 | bk.peers.ProcessIllegal(bk.syncPeer.ID(), security.LevelConnException, err.Error()) |
@@ -180,7 +179,14 @@ func (bk *blockKeeper) regularBlockSync() error { | ||
180 | 179 | i-- |
181 | 180 | continue |
182 | 181 | } |
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 | |
184 | 190 | } |
185 | 191 | log.WithFields(log.Fields{"module": logModule, "height": bk.chain.BestBlockHeight()}).Info("regular sync success") |
186 | 192 | return nil |
@@ -47,7 +47,7 @@ const ( | ||
47 | 47 | |
48 | 48 | var ( |
49 | 49 | // The full version string |
50 | - Version = "1.0.2" | |
50 | + Version = "1.0.3" | |
51 | 51 | // GitCommit is set with --ldflags "-X main.gitCommit=$(git rev-parse HEAD)" |
52 | 52 | GitCommit string |
53 | 53 | Status *UpdateStatus |