Skip to content

Commit

Permalink
fix:snapsync network abnormality leads to status error
Browse files Browse the repository at this point in the history
  • Loading branch information
lochjin committed Dec 3, 2024
1 parent 5873a46 commit b3a013e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
3 changes: 3 additions & 0 deletions meerevm/meer/meerchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,9 @@ func (b *MeerChain) SyncTo(target common.Hash) error {
if system.InterruptRequested(b.consensus.Interrupt()) {
return errors.New("System interrupt")
}
if b.IsShutdown() {
return errors.New("MeerChain is shutdown")
}
}
}

Expand Down
1 change: 0 additions & 1 deletion p2p/synch/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func (ps *PeerSync) processConnected(msg *ConnectedMsg) {
func (ps *PeerSync) immediatelyConnected(pe *peers.Peer) {
pe.HSlock.Lock()
defer pe.HSlock.Unlock()

ps.Connection(pe)
}

Expand Down
16 changes: 7 additions & 9 deletions p2p/synch/peersync.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,10 @@ func (ps *PeerSync) handleStallSample() {
return
}
lbid := ps.Chain().BlockDAG().GetLastBlockID()
if ps.lastBlockID <= 0 {
ps.lastBlockID = lbid
return
}
if ps.lastBlockID != lbid {
return
}
ps.lastBlockID = lbid
ps.TryAgainUpdateSyncPeer(true)
}

Expand Down Expand Up @@ -734,11 +731,12 @@ func (ps *PeerSync) getProcessID() string {

func NewPeerSync(sy *Sync) *PeerSync {
peerSync := &PeerSync{
sy: sy,
msgChan: make(chan interface{}),
quit: make(chan struct{}),
pause: false,
interrupt: make(chan struct{}),
sy: sy,
msgChan: make(chan interface{}),
quit: make(chan struct{}),
pause: false,
interrupt: make(chan struct{}),
lastBlockID: meerdag.MaxId,
}

return peerSync
Expand Down
15 changes: 13 additions & 2 deletions p2p/synch/snapsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,19 @@ cleanup:
}
add := 0
ps.snapStatus.locker.Lock()
tryReq := 10
var ret *pb.SnapSyncRsp

for !ps.snapStatus.isPointCompleted() {
ret, err := ps.syncSnapStatus(bestPeer)
for i := 0; i < tryReq; i++ {
ret, err = ps.syncSnapStatus(bestPeer)
if err != nil {
log.Warn("Snap-sync waiting for next try", "err", err.Error(), "cur", i, "max", tryReq)
time.Sleep(time.Second * 5)
continue
}
break
}
if err != nil {
log.Warn("Snap-sync", "err", err.Error())
break
Expand All @@ -106,8 +117,8 @@ cleanup:
break
}
ps.snapStatus.setSyncPoint(latest)
log.Trace("Snap-sync status update point", "point", latest.GetHash().String())
add += len(sds)
log.Trace("Snap-sync", "point", latest.GetHash().String(), "data_num", len(sds), "total", add)
}
ps.snapStatus.locker.Unlock()
err = ps.Chain().MeerChain().SyncTo(ps.snapStatus.GetSyncPoint().GetState().GetEVMHash())
Expand Down

0 comments on commit b3a013e

Please sign in to comment.