Skip to content

Commit

Permalink
Merge pull request #866 from lochjin/dev2.0
Browse files Browse the repository at this point in the history
fix:continue snap sync error
  • Loading branch information
dindinw authored Dec 23, 2024
2 parents 947a8de + 6d5bfb8 commit e1b6e07
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions p2p/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package p2p

import (
"encoding/base64"
"errors"
"fmt"
"github.com/Qitmeer/qng/common/hash"
"github.com/Qitmeer/qng/common/roughtime"
Expand Down Expand Up @@ -780,6 +781,12 @@ func NewService(cfg *config.Config, consensus model.Consensus, param *params.Par

s.sy = synch.NewSync(s)
s.rebroadcast = NewRebroadcast(s)

if !s.IsSnap() {
if s.sy.PeerSync().IsSnapSync() {
return nil, errors.New("There is an unfinished snap-sync, please enable the snap service")
}
}
return s, nil
}

Expand Down
4 changes: 3 additions & 1 deletion p2p/synch/snapsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func (ps *PeerSync) startSnapSync() bool {
if !ps.sy.p2p.IsSnap() {
if ps.IsSnapSync() {
log.Error("There is an unfinished snap-sync, please enable the snap service")
return true
}
return false
}
Expand Down Expand Up @@ -263,6 +264,7 @@ cleanup:
bestPeer.UpdateSyncPoint(sp.GetHash())
log.Debug("Snap-sync update sync point", "point", sp.GetHash().String())
}
ps.snapStatus.SetTarget(sp.GetHash(), sp.GetState().Root())
if ps.snapStatus.IsCompleted() {
log.Info("Snap-sync has ended", "spend", time.Since(startTime).Truncate(time.Second).String(), "processID", ps.getProcessID())
ps.snapStatus = nil
Expand Down Expand Up @@ -410,7 +412,7 @@ func (ps *PeerSync) getSnapSyncPeer(timeout int, exclude map[peer.ID]struct{}) (
func (s *Sync) sendSnapSyncRequest(stream network.Stream, pe *peers.Peer) (*pb.SnapSyncRsp, *common.Error) {
e := ReadRspCode(stream, s.p2p)
if !e.Code.IsSuccess() {
e.Add("get block date request rsp")
e.Add("snap-sync request rsp")
return nil, e
}
msg := &pb.SnapSyncRsp{}
Expand Down

0 comments on commit e1b6e07

Please sign in to comment.