Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ require (
github.com/mattn/go-sqlite3 v1.14.18
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416
github.com/olekukonko/tablewriter v0.0.5
github.com/optimism-java/utp-go v0.0.0-20240708082218-8e16d096da4a
github.com/optimism-java/utp-go v0.0.0-20240716050942-7583a3d702fd
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7
github.com/protolambda/bls12-381-util v0.1.0
github.com/protolambda/zrnt v0.32.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ github.com/optimism-java/utp-go v0.0.0-20240603010819-75be99daf402 h1:jssfGQq6xd
github.com/optimism-java/utp-go v0.0.0-20240603010819-75be99daf402/go.mod h1:DZ0jYzLzt4ZsCmhI/iqYgGFoNx45OfpEoKzXB8HVALQ=
github.com/optimism-java/utp-go v0.0.0-20240708082218-8e16d096da4a h1:yKF0O3VAaL0hB2mo+5ZU3+XtpMhclvXKs2WWrjFptxg=
github.com/optimism-java/utp-go v0.0.0-20240708082218-8e16d096da4a/go.mod h1:DZ0jYzLzt4ZsCmhI/iqYgGFoNx45OfpEoKzXB8HVALQ=
github.com/optimism-java/utp-go v0.0.0-20240716050942-7583a3d702fd h1:D8gytM7P1H2dGRBG+7sOSWBbAFOIbMSPWWbHPb8/rf4=
github.com/optimism-java/utp-go v0.0.0-20240716050942-7583a3d702fd/go.mod h1:DZ0jYzLzt4ZsCmhI/iqYgGFoNx45OfpEoKzXB8HVALQ=
github.com/optimism-java/zrnt v0.32.4-0.20240415084906-d9dbf06b32f7 h1:ZTQWXQ8xblCRUXhZs3h5qrBMSAHe8iNH7BG7a7IVFlI=
github.com/optimism-java/zrnt v0.32.4-0.20240415084906-d9dbf06b32f7/go.mod h1:A0fezkp9Tt3GBLATSPIbuY4ywYESyAuc/FFmPKg8Lqs=
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 h1:oYW+YCJ1pachXTQmzR3rNLYGGz4g/UgFcjb28p/viDM=
Expand Down
8 changes: 7 additions & 1 deletion p2p/discover/portal_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,11 @@ 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: true, forceSetLive: true})
added := p.table.handleAddNode(addNodeOp{node: n, isInbound: true, forceSetLive: true})
if !added {
p.Log.Warn("add node failed", "id", n.ID())
return
}
id := n.ID().String()
p.radiusCache.Set([]byte(id), MaxDistance)
}
Expand Down Expand Up @@ -1433,11 +1437,13 @@ func (p *PortalProtocol) Resolve(n *enode.Node) *enode.Node {
// It returns nil if the nodeId could not be resolved.
func (p *PortalProtocol) ResolveNodeId(id enode.ID) *enode.Node {
if id == p.Self().ID() {
p.Log.Debug("Resolve Self Id", "id", id.String())
return p.Self()
}

n := p.table.getNode(id)
if n != nil {
p.Log.Debug("found Id in table and will request enr from the node", "id", id.String())
// Try asking directly. This works if the Node is still responding on the endpoint we have.
if resp, err := p.RequestENR(n); err == nil {
return resp
Expand Down
5 changes: 5 additions & 0 deletions p2p/discover/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,27 +525,32 @@ func (tab *Table) removeIP(b *bucket, ip netip.Addr) {
// The caller must hold tab.mutex.
func (tab *Table) handleAddNode(req addNodeOp) bool {
if req.node.ID() == tab.self().ID() {
tab.log.Debug("this node is already in table", "id", req.node.ID())
return false
}
// For nodes from inbound contact, there is an additional safety measure: if the table
// is still initializing the node is not added.
if req.isInbound && !tab.isInitDone() {
tab.log.Debug("table is not ready")
return false
}

b := tab.bucket(req.node.ID())
n, _ := tab.bumpInBucket(b, req.node, req.isInbound)
if n != nil {
// Already in bucket.
tab.log.Debug("the node is already in table", "id", req.node.ID())
return false
}
if len(b.entries) >= bucketSize {
// Bucket full, maybe add as replacement.
tab.log.Debug("the bucket is full and will add in replacement", "id", req.node.ID())
tab.addReplacement(b, req.node)
return false
}
if !tab.addIP(b, req.node.IPAddr()) {
// Can't add: IP limit reached.
tab.log.Debug("IP limit reached", "id", req.node.ID())
return false
}

Expand Down