Skip to content

Commit

Permalink
fix:add enr should add node immediately
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Kai <[email protected]>
  • Loading branch information
GrapeBaBa committed Jun 18, 2024
1 parent f8c05e1 commit af02291
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
3 changes: 2 additions & 1 deletion p2p/discover/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion p2p/discover/portal_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 0 additions & 4 deletions p2p/discover/portal_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
Expand Down

0 comments on commit af02291

Please sign in to comment.