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

Add verification method of eth address and requestor singularity in ForcePayment #560

Conversation

pawelkisielewicz
Copy link
Contributor

Resolves #545

@@ -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
Copy link
Contributor Author

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.

Copy link
Contributor Author

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

@cameel
Copy link
Contributor

cameel commented Jun 26, 2018

You have a typo in pull request name.

@pawelkisielewicz pawelkisielewicz changed the title Add verifivation method Add verification method of eth address and requestor singularity in ForcePayment Jun 26, 2018
@@ -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) \
Copy link
Contributor

@rwrzesien rwrzesien Jun 26, 2018

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]:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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:
Copy link
Contributor

@rwrzesien rwrzesien Jun 26, 2018

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.

Copy link
Contributor Author

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 :)

Copy link
Contributor

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
):

Copy link
Contributor

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.

Copy link
Contributor Author

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]
Copy link
Contributor

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..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor

@rwrzesien rwrzesien left a 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.

Copy link
Contributor

@kbeker kbeker left a 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

return False
if first_address != subtask_results_accepted.task_to_compute.requestor_ethereum_address:
return False
return True
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix indentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@dybi dybi left a 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

@@ -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:
Copy link
Contributor

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

Copy link
Contributor

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

@pawelkisielewicz pawelkisielewicz changed the title Add verification method of eth address and requestor singularity in ForcePayment [WIP] Add verification method of eth address and requestor singularity in ForcePayment Jun 27, 2018
@pawelkisielewicz pawelkisielewicz changed the title [WIP] Add verification method of eth address and requestor singularity in ForcePayment Add verification method of eth address and requestor singularity in ForcePayment Jun 27, 2018
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
Copy link
Contributor

@cameel cameel Jun 27, 2018

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)

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.. :)

Copy link
Contributor

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.

Copy link
Contributor Author

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()
Copy link
Contributor

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()

Copy link
Contributor Author

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):
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@rwrzesien rwrzesien left a 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.

Copy link
Contributor

@dybi dybi left a 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

@@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. please reanme it -> as it returns bool, the name of the function shpuld be in a form of a question
  2. please change list to 'List[SomeType]'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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)
Copy link
Contributor

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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rename

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please renametest class

Copy link
Contributor Author

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):
Copy link
Contributor

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

Copy link
Contributor Author

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):
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@dybi dybi left a 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


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):
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -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:
Copy link
Contributor

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 -> 👿 )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done ;)

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)
Copy link
Contributor

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

Copy link
Contributor Author

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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please renametest class

@kbeker
Copy link
Contributor

kbeker commented Jun 27, 2018

@pawelkisielewicz
Did you test it locally with geth and unmocked sci_backend?
Please ask @bartoszbetka tomorrow to deploy your branch od devel cluster and test it also there.

@pawelkisielewicz pawelkisielewicz force-pushed the bug-verify-eth-address-and-requestor-singularity-in-force-payment branch from 1181a91 to 028eb25 Compare June 28, 2018 08:53
@pawelkisielewicz pawelkisielewicz merged commit 2848ffd into master Jun 28, 2018
@pawelkisielewicz pawelkisielewicz deleted the bug-verify-eth-address-and-requestor-singularity-in-force-payment branch June 28, 2018 12:06
@cameel cameel added this to the 0.8.0 milestone Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants