Skip to content

Commit c9216ce

Browse files
p2p/discv4: revert gotreply handler change from #8661 (#9119) (#9195) (#9210)
Co-authored-by: yperbasis <andrey.ashikhmin@gmail.com>
1 parent d079008 commit c9216ce

File tree

2 files changed

+19
-62
lines changed

2 files changed

+19
-62
lines changed

p2p/discover/v4_udp.go

Lines changed: 18 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ import (
2929
"time"
3030

3131
lru "github.com/hashicorp/golang-lru/v2"
32+
"github.com/ledgerwatch/log/v3"
33+
3234
"github.com/ledgerwatch/erigon/common/debug"
3335
"github.com/ledgerwatch/erigon/crypto"
3436
"github.com/ledgerwatch/erigon/p2p/discover/v4wire"
3537
"github.com/ledgerwatch/erigon/p2p/enode"
3638
"github.com/ledgerwatch/erigon/p2p/netutil"
37-
"github.com/ledgerwatch/log/v3"
3839
)
3940

4041
// Errors
@@ -610,74 +611,30 @@ func (t *UDPv4) loop() {
610611
}()
611612

612613
case r := <-t.gotreply:
613-
614-
type matchCandidate struct {
615-
el *list.Element
616-
errc chan error
617-
}
618-
619-
var matchCandidates []matchCandidate
620-
621-
mutex.Lock()
622-
for el := plist.Front(); el != nil; el = el.Next() {
623-
p := el.Value.(*replyMatcher)
624-
if p.from == r.from && p.ptype == r.data.Kind() && p.ip.Equal(r.ip) {
625-
candidate := matchCandidate{el, p.errc}
626-
p.errc = make(chan error, 1)
627-
matchCandidates = append(matchCandidates, candidate)
628-
}
629-
}
630-
mutex.Unlock()
631-
632-
if len(matchCandidates) == 0 {
633-
// if there are no matched candidates try again matching against
634-
// ip & port to handle node key changes
614+
func() {
635615
mutex.Lock()
636-
for el := plist.Front(); el != nil; el = el.Next() {
637-
p := el.Value.(*replyMatcher)
638-
if p.ptype == r.data.Kind() && p.ip.Equal(r.ip) && p.port == r.port {
639-
candidate := matchCandidate{el, p.errc}
640-
p.errc = make(chan error, 1)
641-
matchCandidates = append(matchCandidates, candidate)
642-
}
643-
}
644-
mutex.Unlock()
645-
646-
if len(matchCandidates) == 0 {
647-
r.matched <- false
648-
}
649-
}
616+
defer mutex.Unlock()
650617

651-
go func(r reply) {
652618
var matched bool // whether any replyMatcher considered the reply acceptable.
653-
for _, candidate := range matchCandidates {
654-
p := candidate.el.Value.(*replyMatcher)
655-
ok, requestDone := p.callback(r.data)
656-
matched = matched || ok
657-
p.reply = r.data
658-
659-
// Remove the matcher if callback indicates that all replies have been received.
660-
if requestDone {
661-
mutex.Lock()
662-
plist.Remove(candidate.el)
663-
mutex.Unlock()
664-
candidate.errc <- nil
665-
listUpdate <- candidate.el
666-
} else {
667-
select {
668-
case err := <-p.errc:
669-
candidate.errc <- err
670-
default:
671-
p.errc = candidate.errc
619+
for el := plist.Front(); el != nil; el = el.Next() {
620+
p := el.Value.(*replyMatcher)
621+
if (p.ptype == r.data.Kind()) && p.ip.Equal(r.ip) && (p.port == r.port) {
622+
ok, requestDone := p.callback(r.data)
623+
matched = matched || ok
624+
p.reply = r.data
625+
// Remove the matcher if callback indicates that all replies have been received.
626+
if requestDone {
627+
p.errc <- nil
628+
plist.Remove(el)
629+
listUpdate <- el
672630
}
631+
// Reset the continuous timeout counter (time drift detection)
632+
contTimeouts = 0
673633
}
674634
}
675-
676635
r.matched <- matched
677-
}(r)
636+
}()
678637

679-
// Reset the continuous timeout counter (time drift detection)
680-
contTimeouts = 0
681638
case key := <-t.gotkey:
682639
go func() {
683640
if key, err := v4wire.DecodePubkey(crypto.S256(), key); err == nil {

params/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var (
3333
const (
3434
VersionMajor = 2 // Major version component of the current release
3535
VersionMinor = 56 // Minor version component of the current release
36-
VersionMicro = 1 // Patch version component of the current release
36+
VersionMicro = 2 // Patch version component of the current release
3737
VersionModifier = "" // Modifier component of the current release
3838
VersionKeyCreated = "ErigonVersionCreated"
3939
VersionKeyFinished = "ErigonVersionFinished"

0 commit comments

Comments
 (0)