From 1280499d7b7d4c13de7e50836e1f2390a6a5b28b Mon Sep 17 00:00:00 2001 From: Jonathan Downing Date: Wed, 1 May 2024 16:28:32 -0500 Subject: [PATCH] Moved requestAndWait channel send to no-error case --- p2p/node/api.go | 12 ++++++++++-- p2p/node/p2p_services.go | 2 +- p2p/node/stats.go | 3 +-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/p2p/node/api.go b/p2p/node/api.go index d9b1e99b47..ed62deef41 100644 --- a/p2p/node/api.go +++ b/p2p/node/api.go @@ -181,6 +181,16 @@ func (p *P2PNode) requestAndWait(peerID peer.ID, location common.Location, data // Mark this peer as behaving well p.peerManager.MarkResponsivePeer(peerID, location) + select { + case resultChan <- recvd: + // Data sent successfully + default: + // Optionally log the missed send or handle it in another way + log.Global.WithFields(log.Fields{ + "peerId": peerID, + "message": "Channel is full, data not sent", + }).Warning("Missed data send") + } } else { log.Global.WithFields(log.Fields{ "peerId": peerID, @@ -192,8 +202,6 @@ func (p *P2PNode) requestAndWait(peerID peer.ID, location common.Location, data // Mark this peer as not responding p.peerManager.MarkUnresponsivePeer(peerID, location) } - // send the block to the result channel - resultChan <- recvd } // Request a data from the network for the specified slice diff --git a/p2p/node/p2p_services.go b/p2p/node/p2p_services.go index f6169ff9f1..3fe97d479c 100644 --- a/p2p/node/p2p_services.go +++ b/p2p/node/p2p_services.go @@ -75,7 +75,7 @@ func (p *P2PNode) requestFromPeer(peerID peer.ID, location common.Location, data "peerId": peerID, }).Warn("Peer did not respond in time") p.peerManager.MarkUnresponsivePeer(peerID, location) - return nil, nil + return nil, errors.New("peer did not respond in time") } if recvdType == nil { diff --git a/p2p/node/stats.go b/p2p/node/stats.go index c9e59a42d4..aab584a35e 100644 --- a/p2p/node/stats.go +++ b/p2p/node/stats.go @@ -9,7 +9,7 @@ import ( // Returns the number of peers in the routing table, as well as how many active // connections we currently have. -func (p *P2PNode) connectionStats() (int) { +func (p *P2PNode) connectionStats() int { peers := p.peerManager.GetHost().Network().Peers() numConnected := len(peers) @@ -30,7 +30,6 @@ func (p *P2PNode) statsLoop() { select { case <-ticker.C: peersConnected := p.connectionStats() - log.Global.Debugf("Number of peers connected: %d", peersConnected) case <-p.ctx.Done(): log.Global.Warnf("Context cancelled. Stopping stats loop...")