From 5368248e0f93841e265dd045627cb8ecacff9fee Mon Sep 17 00:00:00 2001 From: Offer Markovich Date: Fri, 31 May 2019 09:59:18 +0300 Subject: [PATCH] secrethash related changes If the target is asking for the secret but the initiator does not have it, emit and error. If secrethash provided with payment request and there is another inflight payment request with the same secrethash, emit an error --- raiden/api/python.py | 7 +++++-- raiden/transfer/mediated_transfer/initiator.py | 14 +++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/raiden/api/python.py b/raiden/api/python.py index 4bddd2e57e..bd3c41d0d3 100644 --- a/raiden/api/python.py +++ b/raiden/api/python.py @@ -755,8 +755,11 @@ def transfer_async( if secret is not None and not isinstance(secret, typing.T_Secret): raise InvalidSecret("secret is not valid.") - if secrethash is not None and not isinstance(secrethash, typing.T_SecretHash): - raise InvalidSecretHash("secrethash is not valid.") + if secrethash is not None: + if not isinstance(secrethash, typing.T_SecretHash): + raise InvalidSecretHash("secrethash is not valid.") + if current_state.payment_mapping.secrethashes_to_task.get(secrethash): + raise InvalidSecretHash("task with the same secrethash is still pending") log.debug( "Initiating transfer", diff --git a/raiden/transfer/mediated_transfer/initiator.py b/raiden/transfer/mediated_transfer/initiator.py index 9ae488c737..cbe5f564a2 100644 --- a/raiden/transfer/mediated_transfer/initiator.py +++ b/raiden/transfer/mediated_transfer/initiator.py @@ -319,7 +319,19 @@ def handle_secretrequest( elif not is_valid_secretrequest and is_message_from_target: initiator_state.received_secret_request = True - iteration = TransitionResult(initiator_state, list()) + + if initiator_state.transfer_description.secret == EMPTY_SECRET: + transfer_description = initiator_state.transfer_description + payment_failed = EventPaymentSentFailed( + payment_network_address=transfer_description.payment_network_address, + token_network_address=transfer_description.token_network_address, + identifier=transfer_description.payment_identifier, + target=transfer_description.target, + reason="Target requested the secret but secret is unknown to the Initiator", + ) + iteration = TransitionResult(initiator_state, [payment_failed]) + else: + iteration = TransitionResult(initiator_state, list()) else: iteration = TransitionResult(initiator_state, list())