Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
expect_income() patch (#4346)
Browse files Browse the repository at this point in the history
expect_income() patch
  • Loading branch information
jiivan authored Jun 17, 2019
1 parent 156bb45 commit c67732e
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 28 deletions.
15 changes: 9 additions & 6 deletions golem/ethereum/transactionsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from twisted.internet import defer

from golem import model
from golem.core import common
from golem.core.deferred import call_later
from golem.core.service import LoopingCallService
from golem.ethereum.node import NodeProcess
Expand Down Expand Up @@ -475,19 +474,23 @@ def unlock_funds_for_payments(self, price: int, num: int) -> None:
self._payments_locked -= num

# pylint: disable=too-many-arguments
@sci_required()
def expect_income(
self,
sender_node: str,
task_id: str,
subtask_id: str,
payer_address: str,
value: int,
accepted_ts: int) -> None:
self._incomes_keeper.expect(
sender_node,
subtask_id,
payer_address,
value,
accepted_ts,
sender_node=sender_node,
task_id=task_id,
subtask_id=subtask_id,
payer_address=payer_address,
my_address=self._sci.get_eth_address(), # type: ignore
value=value,
accepted_ts=accepted_ts,
)

def settle_income(
Expand Down
1 change: 1 addition & 0 deletions golem/network/concent/received_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ def on_force_subtask_results_response(self, msg):
sub_msg = msg.subtask_results_accepted
self.task_server.subtask_accepted(
sender_node_id=msg.requestor_id,
task_id=msg.task_id,
subtask_id=msg.subtask_id,
payer_address=ttc.requestor_ethereum_address,
value=ttc.price,
Expand Down
14 changes: 8 additions & 6 deletions golem/task/taskserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from apps.appsmanager import AppsManager
from apps.core.task.coretask import CoreTask
from golem.clientconfigdescriptor import ClientConfigDescriptor
from golem.core.common import node_info_str, short_node_id
from golem.core.common import short_node_id
from golem.core.variables import MAX_CONNECT_SOCKET_ADDRESSES
from golem.environments.environment import SupportStatus, UnsupportReason
from golem.envs.docker.cpu import DockerCPUConfig
Expand Down Expand Up @@ -548,6 +548,7 @@ def subtask_rejected(self, sender_node_id, subtask_id):
def subtask_accepted(
self,
sender_node_id: str,
task_id: str,
subtask_id: str,
payer_address: str,
value: int,
Expand All @@ -556,11 +557,12 @@ def subtask_accepted(
logger.debug("Subtask %r result accepted", subtask_id)
self.task_result_sent(subtask_id)
self.client.transaction_system.expect_income(
sender_node_id,
subtask_id,
payer_address,
value,
accepted_ts,
sender_node=sender_node_id,
task_id=task_id,
subtask_id=subtask_id,
payer_address=payer_address,
value=value,
accepted_ts=accepted_ts,
)

def subtask_settled(self, sender_node_id, subtask_id, settled_ts):
Expand Down
12 changes: 6 additions & 6 deletions golem/task/tasksession.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import golem
from golem.core import common
from golem.core import golem_async
from golem.core.keysauth import KeysAuth
from golem.core import variables
from golem.docker.environment import DockerEnvironment
from golem.docker.image import DockerImage
Expand Down Expand Up @@ -759,11 +758,12 @@ def _react_to_subtask_results_accepted(
)

self.task_server.subtask_accepted(
self.key_id,
msg.subtask_id,
msg.task_to_compute.requestor_ethereum_address,
msg.task_to_compute.price,
msg.payment_ts,
sender_node=self.key_id,
task_id=msg.task_id,
subtask_id=msg.subtask_id,
payer_address=msg.task_to_compute.requestor_ethereum_address,
value=msg.task_to_compute.price,
accepted_ts=msg.payment_ts,
)
self.dropped()

Expand Down
10 changes: 10 additions & 0 deletions tests/golem/ethereum/test_transactionsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,16 @@ def test_backwards_compatibility_privkey(self):
# Shouldn't throw
self._make_ets(datadir=self.new_path / 'other', password=password)

def test_expect_income(self):
self.ets.expect_income(
sender_node='0xadbeef' + 'deadbeef' * 15,
task_id=str(uuid.uuid4()),
subtask_id=str(uuid.uuid4()),
payer_address='0x' + 40 * '1',
value=10,
accepted_ts=1,
)


class WithdrawTest(TransactionSystemBase):
def setUp(self):
Expand Down
11 changes: 6 additions & 5 deletions tests/golem/network/concent/test_received_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,12 @@ def test_force_subtask_results_response_accepted(

library.interpret(msg)
self.client.transaction_system.expect_income.assert_called_once_with(
msg.task_to_compute.requestor_id,
msg.subtask_id,
msg.task_to_compute.requestor_ethereum_address,
msg.task_to_compute.price,
msg.subtask_results_accepted.payment_ts,
sender_node=msg.task_to_compute.requestor_id,
task_id=msg.task_id,
subtask_id=msg.subtask_id,
payer_address=msg.task_to_compute.requestor_ethereum_address,
value=msg.task_to_compute.price,
accepted_ts=msg.subtask_results_accepted.payment_ts,
)

add_mock.assert_called_once_with(
Expand Down
11 changes: 6 additions & 5 deletions tests/golem/task/test_tasksession.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,11 +956,12 @@ def test_react_to_subtask_results_accepted(self):

# then
self.task_server.subtask_accepted.assert_called_once_with(
self.requestor_key_id,
sra.subtask_id,
sra.task_to_compute.requestor_ethereum_address, # noqa pylint:disable=no-member
sra.task_to_compute.price, # noqa pylint:disable=no-member
sra.payment_ts,
sender_node=self.requestor_key_id,
task_id=sra.task_id,
subtask_id=sra.subtask_id,
payer_address=sra.task_to_compute.requestor_ethereum_address, # noqa pylint:disable=no-member
value=sra.task_to_compute.price, # noqa pylint:disable=no-member
accepted_ts=sra.payment_ts,
)
cancel = self.task_session.concent_service.cancel_task_message
cancel.assert_called_once_with(
Expand Down

0 comments on commit c67732e

Please sign in to comment.