fix:add enr should add node immediately

Signed-off-by: Chen Kai <281165273grape@gmail.com>
This commit is contained in:
Chen Kai 2024-06-18 21:12:43 +08:00
parent f8c05e17eb
commit af02291ad4
3 changed files with 4 additions and 6 deletions

View file

@ -102,7 +102,8 @@ func (d *DiscV5API) AddEnr(enr string) (bool, error) {
return false, err
}
d.DiscV5.tab.addFoundNode(n, true)
// immediately add the node to the routing table
d.DiscV5.tab.handleAddNode(addNodeOp{node: n, isInbound: false, forceSetLive: true})
return true, nil
}

View file

@ -287,7 +287,8 @@ func (p *PortalProtocol) RoutingTableInfo() [][]string {
}
func (p *PortalProtocol) AddEnr(n *enode.Node) {
p.table.addFoundNode(n, true)
// immediately add the node to the routing table
p.table.handleAddNode(addNodeOp{node: n, isInbound: false, forceSetLive: true})
id := n.ID().String()
p.radiusCache.Set([]byte(id), MaxDistance)
}

View file

@ -268,10 +268,6 @@ func TestPortalWireProtocol(t *testing.T) {
time.Sleep(12 * time.Second)
assert.Equal(t, 2, len(node1.table.NodeList()))
assert.Equal(t, 2, len(node2.table.NodeList()))
assert.Equal(t, 2, len(node3.table.NodeList()))
slices.ContainsFunc(node1.table.NodeList(), func(n *enode.Node) bool {
return n.ID() == node2.localNode.Node().ID()
})