Skip to content

Commit

Permalink
fix:add lock in addenr
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Kai <281165273grape@gmail.com>
  • Loading branch information
GrapeBaBa committed Jun 19, 2024
1 parent 98047b2 commit 792b474
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions p2p/discover/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions p2p/discover/portal_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 792b474

Please sign in to comment.