Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:unable to exit midway when snap-sync and fix:snapsync fail try #862

Merged
merged 2 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion consensus/model/meer_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type MeerChain interface {
GetBlockIDByTxHash(txhash *hash.Hash) uint64
SyncMode() downloader.SyncMode
Downloader() *downloader.Downloader
SyncTo(target common.Hash) error
SyncTo(target common.Hash, stop chan struct{}) error
Server() *p2p.Server
GetCurHeader() *types.Header
Synced() bool
Expand Down
5 changes: 2 additions & 3 deletions meerevm/meer/meerchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,10 +686,9 @@ func (b *MeerChain) Server() *p2p.Server {
return b.chain.Node().Server()
}

func (b *MeerChain) SyncTo(target common.Hash) error {
func (b *MeerChain) SyncTo(target common.Hash, stop chan struct{}) error {
mode := b.SyncMode()
quit := make(chan struct{})
err := b.Downloader().SyncQngWaitPeers(mode, target, quit)
err := b.Downloader().SyncQngWaitPeers(mode, target, stop)
if err != nil {
log.Info("Failed to trigger beacon sync", "err", err)
return err
Expand Down
7 changes: 5 additions & 2 deletions p2p/synch/snapsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ cleanup:
log.Trace("Snap-sync", "point", latest.GetHash().String(), "data_num", len(sds), "total", add)
}

err = ps.Chain().MeerChain().SyncTo(ps.snapStatus.GetSyncPoint().GetState().GetEVMHash())
err = ps.Chain().MeerChain().SyncTo(ps.snapStatus.GetSyncPoint().GetState().GetEVMHash(), ps.quit)
if err != nil {
log.Error(err.Error())
} else {
Expand Down Expand Up @@ -246,7 +246,7 @@ cleanup:
log.Info("Snap syncing", "cur", best.GraphState.String(), "peer", bestPeer.GetID().String(), "processID", ps.getProcessID())
ps.sy.p2p.Consensus().Events().Send(event.New(event.DownloaderStart))

err := ps.Chain().MeerChain().SyncTo(ps.snapStatus.GetSyncPoint().GetState().GetEVMHash())
err := ps.Chain().MeerChain().SyncTo(ps.snapStatus.GetSyncPoint().GetState().GetEVMHash(), ps.quit)
if err != nil {
log.Error(err.Error())
return true
Expand Down Expand Up @@ -279,6 +279,9 @@ func (ps *PeerSync) trySyncSnapStatus(pe *peers.Peer) *pb.SnapSyncRsp {
if !ps.IsRunning() {
return nil
}
if !pe.IsActive() {
break
}
rsp, err := ps.syncSnapStatus(pe)
if err != nil {
log.Warn("Snap-sync waiting for next try", "err", err.Error(), "cur", i, "max", tryReq)
Expand Down
Loading