-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add verification method of eth address and requestor singularity in ForcePayment #560
Add verification method of eth address and requestor singularity in ForcePayment #560
Conversation
concent_api/core/message_handlers.py
Outdated
@@ -671,6 +676,11 @@ def handle_send_force_payment(client_message: message.concents.ForcePayment) -> | |||
reason = message.concents.ServiceRefused.REASON.DuplicateRequest | |||
) | |||
|
|||
if not are_eth_addresses_and_singularities_equal_in_all_subtask_results_accepted_list(client_message): | |||
return message.concents.ServiceRefused( | |||
reason = message.concents.ServiceRefused.REASON.DuplicateRequest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
REASON will be changed. I wait until Golem add new REASON and I will change it. But you can give me your feedback for the rest of code now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed according to @lukasz-glen suggestion
You have a typo in pull request name. |
concent_api/core/message_handlers.py
Outdated
@@ -653,13 +657,14 @@ def get_clients_eth_accounts(task_to_compute: message.tasks.TaskToCompute): | |||
return (requestor_eth_address, provider_eth_address) | |||
|
|||
|
|||
def handle_send_force_payment(client_message: message.concents.ForcePayment) -> message.concents.ForcePaymentCommitted: # pylint: disable=inconsistent-return-statements | |||
def handle_send_force_payment(client_message: message.concents.ForcePayment) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't brake signatures this way, please check coding-style. It should something like
def handle_send_force_payment(
client_message: message.concents.ForcePayment
) -> Union[ServiceRefused, ForcePaymentRejected, ForcePaymentCommitted]:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
concent_api/core/message_handlers.py
Outdated
subtask_results_accepted_list = force_payment.subtask_results_accepted_list | ||
|
||
first_key = subtask_results_accepted_list[0].task_to_compute.requestor_ethereum_public_key | ||
for subtask_results_accepted in subtask_results_accepted_list: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not performing both checks in single loop ? And with single if
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in one loop, but i left two if
. This variables, like subtask_results_accepted.task_to_compute.requestor_ethereum_public_key
are pretty long and it's hard to read it in one if. I think it is the best way.. unless you have better idea :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can split if
into several lines, something like:
if (
first_key != subtask_results_accepted.task_to_compute.requestor_ethereum_public_key or
first_address != subtask_results_accepted.task_to_compute.requestor_ethereum_address
):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have looked at the code now, please combine it into single if
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, done :)
|
||
|
||
REQUESTOR_PUBLIC_KEY = generate_ecc_key_pair()[1] | ||
REQUESTOR_ETH_ADDRESS = generate_priv_and_pub_eth_account_key()[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have this available in ConcentIntegrationTestCase
in self.
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small changes might be applied or at least clarification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small changes, but please also test it locally with synced geth and on cluster
concent_api/core/message_handlers.py
Outdated
return False | ||
if first_address != subtask_results_accepted.task_to_compute.requestor_ethereum_address: | ||
return False | ||
return True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should be placed in core/utils.py
not in core/message_handler.py
. I remember that, there are more functions like this that can be removed from this file and transferred to utils
. It might be another issue and be done in new PR, but this function should be placed there right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
concent_api/core/message_handlers.py
Outdated
@@ -653,13 +657,15 @@ def get_clients_eth_accounts(task_to_compute: message.tasks.TaskToCompute): | |||
return (requestor_eth_address, provider_eth_address) | |||
|
|||
|
|||
def handle_send_force_payment(client_message: message.concents.ForcePayment) -> message.concents.ForcePaymentCommitted: # pylint: disable=inconsistent-return-statements | |||
def handle_send_force_payment( | |||
client_message: message.concents.ForcePayment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix indentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some changes are needed
concent_api/core/utils.py
Outdated
@@ -84,3 +85,19 @@ def hex_to_bytes_convert(client_public_key: str): | |||
key_bytes = decode_hex(client_public_key) | |||
assert len(key_bytes) == GOLEM_PUBLIC_KEY_LENGTH | |||
return key_bytes | |||
|
|||
|
|||
def are_eth_addresses_and_singularities_equal_in_all_subtask_results_accepted_list(force_payment: ForcePayment) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to pass whole ForcePayment
message; it will suffice if you pass just a subtask_results_accepted_list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as disuccesd, please remove this function and refactor verify_message_subtask_results_accepted
and enhance it with check of requestor_ethereum_address
concent_api/core/subtask_helpers.py
Outdated
is_ethereum_address_key_equal = len( | ||
set(subtask_results_accepted.task_to_compute.requestor_ethereum_address for subtask_results_accepted in subtask_results_accepted_list)) == 1 | ||
is_ethereum_public_key_equal = len( | ||
set(subtask_results_accepted.task_to_compute.requestor_ethereum_public_key for subtask_results_accepted in subtask_results_accepted_list)) == 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the style here. This should be:
is_ethereum_public_key_equal = len(
set(subtask_results_accepted.task_to_compute.requestor_ethereum_public_key for subtask_results_accepted in subtask_results_accepted_list)
) == 1
But I'd just use helper variables if you want to make it shorter:
unique_public_keys = set(subtask_results_accepted.task_to_compute.requestor_public_key for subtask_results_accepted in subtask_results_accepted_list)
unique_ethereum_addresses = set(subtask_results_accepted.task_to_compute.requestor_ethereum_address for subtask_results_accepted in subtask_results_accepted_list)
unique_ethereum_public_keys = set(subtask_results_accepted.task_to_compute.requestor_ethereum_public_key for subtask_results_accepted in subtask_results_accepted_list)
is_public_key_equal = (len(public_keys) == 1)
is_ethereum_address_key_equal = (len(ethereum_addresses) == 1)
is_ethereum_public_key_equal = (len(ethereum_public_keys) == 1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, and Your suggestion is short and easy to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It still does not follow our styie. If you insist on having the parameter on a separate line then the closing parenthesis must be on a separate line too:
unique_public_keys = set(
subtask_results_accepted.task_to_compute.requestor_public_key for subtask_results_accepted in subtask_results_accepted_list
)
It would be better to just keep it in a single line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. It is a long line.. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not have hard line length limit. Just a suggestion to limit length to 120. The goal is readability. Sometimes it's more readable to just leave a long line as is. Especially when there are several similar long lines next to each other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok :) it's done
from utils.testing_helpers import generate_ecc_key_pair | ||
|
||
|
||
CONCENT_PRIVATE_KEY, CONCENT_PUBLIC_KEY = generate_ecc_key_pair() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add parentheses
(CONCENT_PRIVATE_KEY, CONCENT_PUBLIC_KEY) = generate_ecc_key_pair()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
|
||
@override_settings(CONCENT_PUBLIC_KEY=CONCENT_PUBLIC_KEY) | ||
class TestAreEthAddressesAndSingularitiesEqual(ConcentIntegrationTestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"singularity" is a property of a value (I think "uniqueness" would be a better word here though). You're not comparing singularities. You're checking if the values are singular (unique). The name of the class does not make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good after fixes, but please also apply other reviewers comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some changes are needed
concent_api/core/subtask_helpers.py
Outdated
@@ -146,11 +146,21 @@ def update_subtask_state( | |||
subtask.save() | |||
|
|||
|
|||
def verify_message_subtask_results_accepted(subtask_results_accepted_list: dict) -> bool: | |||
def verify_message_subtask_results_accepted(subtask_results_accepted_list: list) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- please reanme it -> as it returns
bool
, the name of the function shpuld be in a form of a question - please change
list
to 'List[SomeType]'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
concent_api/core/subtask_helpers.py
Outdated
unique_ethereum_public_keys = set( | ||
subtask_results_accepted.task_to_compute.requestor_ethereum_public_key for subtask_results_accepted in subtask_results_accepted_list) | ||
|
||
is_public_key_equal = (len(unique_public_keys) == 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename (one key is equal to what?); it's supposed to be unique
not equal
; the same for lines below
|
||
|
||
@override_settings(CONCENT_PUBLIC_KEY=CONCENT_PUBLIC_KEY) | ||
class TestAreEthAddressesAndKeysAreSingular(ConcentIntegrationTestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please rename
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please renametest class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed to TestAreEthereumAddressesAndKeysUnique
. Is it ok ??
|
||
|
||
@override_settings(CONCENT_PUBLIC_KEY=CONCENT_PUBLIC_KEY) | ||
class TestAreEthAddressesAndKeysAreSingular(ConcentIntegrationTestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please refactor - extract repeated values to setUp
, etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
|
||
@override_settings(CONCENT_PUBLIC_KEY=CONCENT_PUBLIC_KEY) | ||
class TestAreEthAddressesAndKeysAreSingular(ConcentIntegrationTestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add test for missing condition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pleass address issues; also please write "done" below issue that has been addressed
concent_api/core/message_handlers.py
Outdated
|
||
if not verify_message_subtask_results_accepted(client_message.subtask_results_accepted_list): | ||
if not are_keys_and_addresses_in_message_subtask_results_accepted_unique(client_message.subtask_results_accepted_list): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are_keys_and_addresses_in_message_subtask_results_accepted_unique
-> are_keys_and_addresses_unique_in_message_subtask_results_accepted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
concent_api/core/subtask_helpers.py
Outdated
@@ -146,11 +146,18 @@ def update_subtask_state( | |||
subtask.save() | |||
|
|||
|
|||
def verify_message_subtask_results_accepted(subtask_results_accepted_list: dict) -> bool: | |||
def are_keys_and_addresses_in_message_subtask_results_accepted_unique(subtask_results_accepted_list: list) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
list
-> List[SomeType]
(#2 warning -> 👿 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done ;)
concent_api/core/subtask_helpers.py
Outdated
unique_ethereum_public_keys = set(subtask_results_accepted.task_to_compute.requestor_ethereum_public_key for subtask_results_accepted in subtask_results_accepted_list) | ||
|
||
is_public_key_unique = (len(unique_public_keys) == 1) | ||
is_ethereum_address_key_unique = (len(unique_ethereum_addresses) == 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_ethereum_address_key_unique
-> is_ethereum_address_unique
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
|
||
@override_settings(CONCENT_PUBLIC_KEY=CONCENT_PUBLIC_KEY) | ||
class TestAreEthAddressesAndKeysAreSingular(ConcentIntegrationTestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please renametest class
@pawelkisielewicz |
1181a91
to
028eb25
Compare
Resolves #545