Skip to content

Commit 85e469f

Browse files
holimanfjl
authored andcommitted
eth/protocols/snap: fix problems due to idle-but-busy peers (#25651)
1 parent 69568c5 commit 85e469f

File tree

1 file changed

+55
-35
lines changed

1 file changed

+55
-35
lines changed

eth/protocols/snap/sync.go

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,14 +2248,18 @@ func (s *Syncer) OnAccounts(peer SyncPeer, id uint64, hashes []common.Hash, acco
22482248
// Whether or not the response is valid, we can mark the peer as idle and
22492249
// notify the scheduler to assign a new task. If the response is invalid,
22502250
// we'll drop the peer in a bit.
2251+
defer func() {
2252+
s.lock.Lock()
2253+
defer s.lock.Unlock()
2254+
if _, ok := s.peers[peer.ID()]; ok {
2255+
s.accountIdlers[peer.ID()] = struct{}{}
2256+
}
2257+
select {
2258+
case s.update <- struct{}{}:
2259+
default:
2260+
}
2261+
}()
22512262
s.lock.Lock()
2252-
if _, ok := s.peers[peer.ID()]; ok {
2253-
s.accountIdlers[peer.ID()] = struct{}{}
2254-
}
2255-
select {
2256-
case s.update <- struct{}{}:
2257-
default:
2258-
}
22592263
// Ensure the response is for a valid request
22602264
req, ok := s.accountReqs[id]
22612265
if !ok {
@@ -2360,14 +2364,18 @@ func (s *Syncer) onByteCodes(peer SyncPeer, id uint64, bytecodes [][]byte) error
23602364
// Whether or not the response is valid, we can mark the peer as idle and
23612365
// notify the scheduler to assign a new task. If the response is invalid,
23622366
// we'll drop the peer in a bit.
2367+
defer func() {
2368+
s.lock.Lock()
2369+
defer s.lock.Unlock()
2370+
if _, ok := s.peers[peer.ID()]; ok {
2371+
s.bytecodeIdlers[peer.ID()] = struct{}{}
2372+
}
2373+
select {
2374+
case s.update <- struct{}{}:
2375+
default:
2376+
}
2377+
}()
23632378
s.lock.Lock()
2364-
if _, ok := s.peers[peer.ID()]; ok {
2365-
s.bytecodeIdlers[peer.ID()] = struct{}{}
2366-
}
2367-
select {
2368-
case s.update <- struct{}{}:
2369-
default:
2370-
}
23712379
// Ensure the response is for a valid request
23722380
req, ok := s.bytecodeReqs[id]
23732381
if !ok {
@@ -2469,14 +2477,18 @@ func (s *Syncer) OnStorage(peer SyncPeer, id uint64, hashes [][]common.Hash, slo
24692477
// Whether or not the response is valid, we can mark the peer as idle and
24702478
// notify the scheduler to assign a new task. If the response is invalid,
24712479
// we'll drop the peer in a bit.
2480+
defer func() {
2481+
s.lock.Lock()
2482+
defer s.lock.Unlock()
2483+
if _, ok := s.peers[peer.ID()]; ok {
2484+
s.storageIdlers[peer.ID()] = struct{}{}
2485+
}
2486+
select {
2487+
case s.update <- struct{}{}:
2488+
default:
2489+
}
2490+
}()
24722491
s.lock.Lock()
2473-
if _, ok := s.peers[peer.ID()]; ok {
2474-
s.storageIdlers[peer.ID()] = struct{}{}
2475-
}
2476-
select {
2477-
case s.update <- struct{}{}:
2478-
default:
2479-
}
24802492
// Ensure the response is for a valid request
24812493
req, ok := s.storageReqs[id]
24822494
if !ok {
@@ -2596,14 +2608,18 @@ func (s *Syncer) OnTrieNodes(peer SyncPeer, id uint64, trienodes [][]byte) error
25962608
// Whether or not the response is valid, we can mark the peer as idle and
25972609
// notify the scheduler to assign a new task. If the response is invalid,
25982610
// we'll drop the peer in a bit.
2611+
defer func() {
2612+
s.lock.Lock()
2613+
defer s.lock.Unlock()
2614+
if _, ok := s.peers[peer.ID()]; ok {
2615+
s.trienodeHealIdlers[peer.ID()] = struct{}{}
2616+
}
2617+
select {
2618+
case s.update <- struct{}{}:
2619+
default:
2620+
}
2621+
}()
25992622
s.lock.Lock()
2600-
if _, ok := s.peers[peer.ID()]; ok {
2601-
s.trienodeHealIdlers[peer.ID()] = struct{}{}
2602-
}
2603-
select {
2604-
case s.update <- struct{}{}:
2605-
default:
2606-
}
26072623
// Ensure the response is for a valid request
26082624
req, ok := s.trienodeHealReqs[id]
26092625
if !ok {
@@ -2691,14 +2707,18 @@ func (s *Syncer) onHealByteCodes(peer SyncPeer, id uint64, bytecodes [][]byte) e
26912707
// Whether or not the response is valid, we can mark the peer as idle and
26922708
// notify the scheduler to assign a new task. If the response is invalid,
26932709
// we'll drop the peer in a bit.
2710+
defer func() {
2711+
s.lock.Lock()
2712+
defer s.lock.Unlock()
2713+
if _, ok := s.peers[peer.ID()]; ok {
2714+
s.bytecodeHealIdlers[peer.ID()] = struct{}{}
2715+
}
2716+
select {
2717+
case s.update <- struct{}{}:
2718+
default:
2719+
}
2720+
}()
26942721
s.lock.Lock()
2695-
if _, ok := s.peers[peer.ID()]; ok {
2696-
s.bytecodeHealIdlers[peer.ID()] = struct{}{}
2697-
}
2698-
select {
2699-
case s.update <- struct{}{}:
2700-
default:
2701-
}
27022722
// Ensure the response is for a valid request
27032723
req, ok := s.bytecodeHealReqs[id]
27042724
if !ok {

0 commit comments

Comments
 (0)