Skip to content

Commit 7ed860d

Browse files
authored
eth: don't wait for snap registration if we're not running snap (ethereum#22272)
Prevents a situation where we (not running snap) connects with a peer running snap, and get stalled waiting for snap registration to succeed (which will never happen), which cause a waitgroup wait to halt shutdown
1 parent fba5a63 commit 7ed860d

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

eth/peerset.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func newPeerSet() *peerSet {
7373
func (ps *peerSet) registerSnapExtension(peer *snap.Peer) error {
7474
// Reject the peer if it advertises `snap` without `eth` as `snap` is only a
7575
// satellite protocol meaningful with the chain selection of `eth`
76-
if !peer.SupportsCap(eth.ProtocolName, eth.ProtocolVersions) {
76+
if !peer.RunningCap(eth.ProtocolName, eth.ProtocolVersions) {
7777
return errSnapWithoutEth
7878
}
7979
// Ensure nobody can double connect
@@ -101,7 +101,7 @@ func (ps *peerSet) registerSnapExtension(peer *snap.Peer) error {
101101
// by the peerset.
102102
func (ps *peerSet) waitSnapExtension(peer *eth.Peer) (*snap.Peer, error) {
103103
// If the peer does not support a compatible `snap`, don't wait
104-
if !peer.SupportsCap(snap.ProtocolName, snap.ProtocolVersions) {
104+
if !peer.RunningCap(snap.ProtocolName, snap.ProtocolVersions) {
105105
return nil, nil
106106
}
107107
// Ensure nobody can double connect

p2p/peer.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,14 @@ func (p *Peer) Caps() []Cap {
158158
return p.rw.caps
159159
}
160160

161-
// SupportsCap returns true if the peer supports any of the enumerated versions
162-
// of a specific protocol.
163-
func (p *Peer) SupportsCap(protocol string, versions []uint) bool {
164-
for _, cap := range p.rw.caps {
165-
if cap.Name == protocol {
166-
for _, ver := range versions {
167-
if cap.Version == ver {
168-
return true
169-
}
161+
// RunningCap returns true if the peer is actively connected using any of the
162+
// enumerated versions of a specific protocol, meaning that at least one of the
163+
// versions is supported by both this node and the peer p.
164+
func (p *Peer) RunningCap(protocol string, versions []uint) bool {
165+
if proto, ok := p.running[protocol]; ok {
166+
for _, ver := range versions {
167+
if proto.Version == ver {
168+
return true
170169
}
171170
}
172171
}

0 commit comments

Comments
 (0)