Skip to content

Commit

Permalink
Fixed error when the DHT returns zero peers
Browse files Browse the repository at this point in the history
  • Loading branch information
devos50 authored and ichorid committed Oct 31, 2020
1 parent 9802174 commit 79c65aa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/tribler-core/tribler_core/modules/payout_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ async def do_payout(self, mid):
return None

self.logger.debug("Received %d nodes for DHT lookup", len(nodes))
if nodes:
try:
await self.bandwidth_community.do_payout(nodes[0], total_bytes)
except Exception as e:
self.logger.error("Error while doing bandwidth payout, error %s", e)
return None
if not nodes:
return None

try:
await self.bandwidth_community.do_payout(nodes[0], total_bytes)
except Exception as e:
self.logger.error("Error while doing bandwidth payout, error %s", e)
return None

# Remove the outstanding bytes; otherwise we will payout again
self.tribler_peers.pop(mid, None)
Expand Down
14 changes: 14 additions & 0 deletions src/tribler-core/tribler_core/modules/tests/test_payout_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ def err_connect_peer(_):
assert not res


@pytest.mark.asyncio
async def test_do_payout_no_dht_peers(payout_manager):
"""
Test whether we are not doing a payout when there are no peers returned by the DHT
"""
def connect_peer(_):
return succeed([])

payout_manager.update_peer(b'a', b'b', 10 * 1024 * 1024)
payout_manager.dht.connect_peer = connect_peer
res = await payout_manager.do_payout(b'a')
assert not res


@pytest.mark.asyncio
async def test_do_payout_error(payout_manager):
"""
Expand Down

0 comments on commit 79c65aa

Please sign in to comment.