p2p/discover: allow inbound updates with any seq

This commit is contained in:
Felix Lange 2024-05-28 18:49:28 +02:00
parent 9d0301dd82
commit ddcabb198f
2 changed files with 4 additions and 6 deletions

View file

@ -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
}

View file

@ -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) {