From 792b4746b872e8e1a1129fbc388524fa9779cf99 Mon Sep 17 00:00:00 2001 From: Chen Kai <281165273grape@gmail.com> Date: Wed, 19 Jun 2024 21:44:53 +0800 Subject: [PATCH] fix:add lock in addenr Signed-off-by: Chen Kai <281165273grape@gmail.com> --- p2p/discover/api.go | 2 ++ p2p/discover/portal_protocol.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/p2p/discover/api.go b/p2p/discover/api.go index d39702d9f51b..1e060684044f 100644 --- a/p2p/discover/api.go +++ b/p2p/discover/api.go @@ -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 } diff --git a/p2p/discover/portal_protocol.go b/p2p/discover/portal_protocol.go index baef3b17fe09..670a2f48faa3 100644 --- a/p2p/discover/portal_protocol.go +++ b/p2p/discover/portal_protocol.go @@ -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)