fix:add lock in addenr

Signed-off-by: Chen Kai <281165273grape@gmail.com>
This commit is contained in:
Chen Kai 2024-06-19 21:44:53 +08:00
parent 98047b22a3
commit 792b4746b8
2 changed files with 4 additions and 0 deletions

View file

@ -103,6 +103,8 @@ func (d *DiscV5API) AddEnr(enr string) (bool, error) {
}
// immediately add the node to the routing table
d.DiscV5.tab.mutex.Lock()
defer d.DiscV5.tab.mutex.Unlock()
d.DiscV5.tab.handleAddNode(addNodeOp{node: n, isInbound: false, forceSetLive: true})
return true, nil
}

View file

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