Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed unnecessary check in payouts #4250

Merged
merged 1 commit into from
Feb 25, 2019
Merged
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
23 changes: 4 additions & 19 deletions Tribler/community/triblertunnel/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,7 @@ def on_payout_block(self, source_address, data):
# Send the next payout
if payload.circuit_id in self.relay_from_to and block.transaction['down'] > payload.base_amount:
relay = self.relay_from_to[payload.circuit_id]
circuit_peer = self.get_peer_from_address(relay.peer.address)
if not circuit_peer:
self.logger.warning("%s Unable to find next peer %s for payout!", self.my_peer, relay.peer)
return

self.do_payout(circuit_peer, relay.circuit_id, block.transaction['down'] - payload.base_amount * 2,
self.do_payout(relay.peer, relay.circuit_id, block.transaction['down'] - payload.base_amount * 2,
payload.base_amount)

def on_balance_request_cell(self, source_address, data, _):
Expand Down Expand Up @@ -316,15 +311,6 @@ def update_torrent(self, peers, handle, download):
if self.active_data_circuits():
self.readd_bittorrent_peers()

def get_peer_from_address(self, address):
circuit_peer = None
for peer in self.get_peers():
if peer.address == address:
circuit_peer = peer
break

return circuit_peer

def do_payout(self, peer, circuit_id, amount, base_amount):
"""
Perform a payout to a specific peer.
Expand Down Expand Up @@ -371,19 +357,18 @@ def remove_circuit(self, circuit_id, additional_info='', remove_now=False, destr
if self.tribler_session:
self.tribler_session.notifier.notify(NTFY_TUNNEL, NTFY_REMOVE, circuit, additional_info)

circuit_peer = self.get_peer_from_address(circuit.peer.address)
if circuit.bytes_down >= 1024 * 1024 and self.bandwidth_wallet and circuit_peer:
if circuit.bytes_down >= 1024 * 1024 and self.bandwidth_wallet:
# We should perform a payout of the removed circuit.
if circuit.ctype == CIRCUIT_TYPE_RENDEZVOUS:
# We remove an e2e circuit as downloader. We pay the subsequent nodes in the downloader part of the e2e
# circuit. In addition, we pay for one hop seeder anonymity since we don't know the circuit length at
# the seeder side.
self.do_payout(circuit_peer, circuit_id, circuit.bytes_down * ((circuit.goal_hops * 2) + 1),
self.do_payout(circuit.peer, circuit_id, circuit.bytes_down * ((circuit.goal_hops * 2) + 1),
circuit.bytes_down)

if circuit.ctype == CIRCUIT_TYPE_DATA:
# We remove a regular data circuit as downloader. Pay the relay nodes and the exit nodes.
self.do_payout(circuit_peer, circuit_id, circuit.bytes_down * (circuit.goal_hops * 2 - 1),
self.do_payout(circuit.peer, circuit_id, circuit.bytes_down * (circuit.goal_hops * 2 - 1),
circuit.bytes_down)

# Reset the circuit byte counters so we do not payout again if we receive a destroy message.
Expand Down