* fix the regular sync dust block problem
* fix the crazy log
* fix ci test
* change the version
* fix bug on handle orphan block
// 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 {
// 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
batch := s.db.NewBatch()
if err := saveUtxoView(batch, view); err != nil {
return err
batch.Set(calcMainChainIndexPrefix(bh.Height), binaryBlockHash)
s.cache.removeMainChainHash(bh.Height)
}
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
}
batch.Write()
return nil
}
}
if m.status.BestHash != block.PreviousBlockHash {
}
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")
targetHeight = peerHeight
}
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())
block, err := bk.msgFetcher.requireBlock(bk.syncPeer.ID(), i)
if err != nil {
bk.peers.ProcessIllegal(bk.syncPeer.ID(), security.LevelConnException, err.Error())
- 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
}
log.WithFields(log.Fields{"module": logModule, "height": bk.chain.BestBlockHeight()}).Info("regular sync success")
return nil
var (
// The full version string
var (
// The full version string
// GitCommit is set with --ldflags "-X main.gitCommit=$(git rev-parse HEAD)"
GitCommit string
Status *UpdateStatus
// GitCommit is set with --ldflags "-X main.gitCommit=$(git rev-parse HEAD)"
GitCommit string
Status *UpdateStatus