From ddcabb198f0c485452d00110ec5c6d1ed45ddfca Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 28 May 2024 18:49:28 +0200 Subject: [PATCH] p2p/discover: allow inbound updates with any seq --- p2p/discover/table.go | 4 +--- p2p/discover/table_test.go | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/p2p/discover/table.go b/p2p/discover/table.go index c75ed749cc..b119f855dc 100644 --- a/p2p/discover/table.go +++ b/p2p/discover/table.go @@ -622,9 +622,7 @@ func (tab *Table) bumpInBucket(b *bucket, newRecord *enode.Node, isInbound bool) // Note there is a special case for discv4: if the node contacts us (isInbound), // it is allowed to update its own entry. n = b.entries[i] - isUpdate := newRecord.Seq() > n.Seq() - isDiscv4Update := n.Seq() == 0 && newRecord.Seq() == 0 && isInbound - if !(isUpdate || isDiscv4Update) { + if newRecord.Seq() <= n.Seq() && !isInbound { return n, false } diff --git a/p2p/discover/table_test.go b/p2p/discover/table_test.go index 0f9a20fda1..0d833f82b5 100644 --- a/p2p/discover/table_test.go +++ b/p2p/discover/table_test.go @@ -295,14 +295,14 @@ func TestTable_addInboundNode(t *testing.T) { tab.addInboundNode(wrapNode(n2v2)) checkBucketContent(t, tab, []*enode.Node{n1.Node, n2v2}) - // Try updating n2 without sequence number change. The update - // should not be accepted. + // Try updating n2 without sequence number change. The update is accepted + // because it's inbound. newrec = n2.Record() newrec.Set(enr.IP{100, 100, 100, 100}) newrec.SetSeq(n2.Seq()) n2v3 := enode.SignNull(newrec, n2.ID()) tab.addInboundNode(wrapNode(n2v3)) - checkBucketContent(t, tab, []*enode.Node{n1.Node, n2v2}) + checkBucketContent(t, tab, []*enode.Node{n1.Node, n2v3}) } func TestTable_addFoundNode(t *testing.T) {