From 565927e4f6297ef2bf43ee01a1cb67043df368f4 Mon Sep 17 00:00:00 2001 From: HarkerK Date: Thu, 14 Jul 2022 02:49:21 +0900 Subject: [PATCH 1/2] fix: prevent infinite loop that happens when there is only 1 peer --- p2p/connection_pool.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/p2p/connection_pool.go b/p2p/connection_pool.go index 0b5189fd..d44b9b28 100644 --- a/p2p/connection_pool.go +++ b/p2p/connection_pool.go @@ -460,6 +460,8 @@ func broadcast_Block_Coded(cbl *block.Complete_Block, PeerID uint64, first_seen }(v, count) count++ + } else if len(connections) == 1 && (PeerID == v.Peer_ID || v.Peer_ID == GetPeerID()) { + goto done } } } From 5a81ec276cdc33fd085ccb5e260c54686461e754 Mon Sep 17 00:00:00 2001 From: HarkerK Date: Thu, 14 Jul 2022 03:04:10 +0900 Subject: [PATCH 2/2] maybe this is better --- p2p/connection_pool.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/p2p/connection_pool.go b/p2p/connection_pool.go index d44b9b28..e53b467a 100644 --- a/p2p/connection_pool.go +++ b/p2p/connection_pool.go @@ -418,6 +418,9 @@ func broadcast_Block_Coded(cbl *block.Complete_Block, PeerID uint64, first_seen globals.Logger.Error(nil, "we want to broadcast block, but donot have peers, most possibly block will go stale") return } + if len(connections) == 1 && (PeerID == connections[0].Peer_ID || connections[0].Peer_ID == GetPeerID()) { + return + } for _, v := range connections { select { case <-Exit_Event: @@ -460,8 +463,6 @@ func broadcast_Block_Coded(cbl *block.Complete_Block, PeerID uint64, first_seen }(v, count) count++ - } else if len(connections) == 1 && (PeerID == v.Peer_ID || v.Peer_ID == GetPeerID()) { - goto done } } }