diff --git a/p2p/service.go b/p2p/service.go index 46697f3d..5b287a8d 100644 --- a/p2p/service.go +++ b/p2p/service.go @@ -2,6 +2,7 @@ package p2p import ( "encoding/base64" + "errors" "fmt" "github.com/Qitmeer/qng/common/hash" "github.com/Qitmeer/qng/common/roughtime" @@ -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 } diff --git a/p2p/synch/snapsync.go b/p2p/synch/snapsync.go index 51a82d1d..f55e7213 100644 --- a/p2p/synch/snapsync.go +++ b/p2p/synch/snapsync.go @@ -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 } @@ -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 @@ -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{}