Skip to content

plugin: sendpay_success and sendpay_failure notifications#2945

Merged
rustyrussell merged 10 commits intoElementsProject:masterfrom
trueptolemy:sendpay-notifications
Sep 11, 2019
Merged

plugin: sendpay_success and sendpay_failure notifications#2945
rustyrussell merged 10 commits intoElementsProject:masterfrom
trueptolemy:sendpay-notifications

Conversation

@trueptolemy
Copy link
Contributor

@trueptolemy trueptolemy commented Aug 11, 2019

Long long ago, @ZmnSCPxj mentioned sendpay_success and sendpay_failure notifications.

My first thought was to combine these two case into one notification type, sendpay_result.
But I found the json fields are two different between sendpay success and failure, so finally I divided sendpay_result into sendpay_success and sendpay_failure again.

For these two notification type, I still use the original notification interface, because I'm not sure whether #2944 is valid.

I pre-present these ideas here though I'll wait for 0.7.3 to add CHANGELOG,

@trueptolemy trueptolemy requested a review from cdecker as a code owner August 11, 2019 19:35
@trueptolemy trueptolemy force-pushed the sendpay-notifications branch 2 times, most recently from 8b34063 to 24db409 Compare August 14, 2019 07:18
@trueptolemy trueptolemy force-pushed the sendpay-notifications branch 2 times, most recently from 89141be to cc2f36a Compare August 23, 2019 22:08
Copy link
Contributor

@rustyrussell rustyrussell left a comment

Choose a reason for hiding this comment

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

I love a PR where my only complaint is the details of the testing.

This is awesome! Trivial inversion of the testing/plugin pattern, and I look forward to committing!

check_result = check(fail, response)
return check_result
plugin.log("no record")
return False
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, I just undid similar logic in plugins/forward_payment_status.py.

Turns out it's better to have the plugin just save up the notifications and spew them back on command, then have the comparison logic in the test itself. That way, if something goes wrong, it's much easier to debug (and also to enhance the tests in future, since they only need to be changed in one place).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you :-)
I'll learn from plugins/forward_payment_status.py!

@trueptolemy trueptolemy force-pushed the sendpay-notifications branch 7 times, most recently from cefc9b5 to bb6d6bf Compare August 30, 2019 07:11
@trueptolemy
Copy link
Contributor Author

Modified the test and the test plugin. @rustyrussell What about now?

Copy link
Contributor

@rustyrussell rustyrussell left a comment

Choose a reason for hiding this comment

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

Ack bb6d6bf

Sorry for the delay!
But, of course, now it needs rebase. Since it's your code which changed, I'll leave that to you.

@rustyrussell rustyrussell added this to the 0.7.3 milestone Sep 9, 2019
@trueptolemy trueptolemy force-pushed the sendpay-notifications branch 2 times, most recently from e3e5513 to beb51b8 Compare September 9, 2019 02:38
@trueptolemy
Copy link
Contributor Author

Thank you! :-)
Rebased. Wait for Travis-CI to pass.

trueptolemy and others added 7 commits September 10, 2019 16:12
`sendpay_success`

A notification for topic `sendpay_success` is sent every time a sendpay
success(with `complete` status). The json is same as the return value of
command `sendpay`/`waitsendpay` when these cammand succeeds.

```json
{
	"sendpay_success": {
  "id": 1,
  "payment_hash": "5c85bf402b87d4860f4a728e2e58a2418bda92cd7aea0ce494f11670cfbfb206",
  "destination": "035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
  "msatoshi": 100000000,
  "amount_msat": "100000000msat",
  "msatoshi_sent": 100001001,
  "amount_sent_msat": "100001001msat",
  "created_at": 1561390572,
  "status": "complete",
  "payment_preimage": "9540d98095fd7f37687ebb7759e733934234d4f934e34433d4998a37de3733ee"
  }
}
```
`sendpay` doesn't wait for the result of sendpay and `waitsendpay`
returns the result of sendpay in specified time or timeout, but
`sendpay_success` will always return the result anytime when sendpay
successes if is was subscribed.
We will also call this warped function in the json process of the 'sendpay_failure' notification.
…ails

pPayment field includes the basic information of the payment, so the return valves of 'sendpay_success()' and 'sendpay_fail()' should include this field.
Note "immediate_routing_failure" is before payment creation, and for this case, return won't include payment fields.
(The json when sendpay successes is too different when sendpay fails, so
divide the sendpay result into two notifications: `sendpay_success` and
`sendpay_failure`)

`sendpay_failure`

A notification for topic `sendpay_failure` is sent every time a sendpay
success(with `failed` status). The json is same as the return value of
command `sendpay`/`waitsendpay` when this cammand fails.

```json
{
  "sendpay_failure": {
  "code": 204,
  "message": "failed: WIRE_UNKNOWN_NEXT_PEER (reply from remote)",
  "data": {
    "id": 2,
    "payment_hash": "9036e3bdbd2515f1e653cb9f22f8e4c49b73aa2c36e937c926f43e33b8db8851",
    "destination": "035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
    "msatoshi": 100000000,
    "amount_msat": "100000000msat",
    "msatoshi_sent": 100001001,
    "amount_sent_msat": "100001001msat",
    "created_at": 1561395134,
    "status": "failed",
    "erring_index": 1,
    "failcode": 16394,
    "failcodename": "WIRE_UNKNOWN_NEXT_PEER",
    "erring_node": "022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59",
    "erring_channel": "103x2x1",
    "erring_direction": 0
    }
  }
}
```
`sendpay` doesn't wait for the result of sendpay and `waitsendpay`
returns the result of sendpay in specified time or timeout, but
`sendpay_failure` will always return the result anytime when sendpay
fails if is was subscribed.
Copy link
Contributor

@rustyrussell rustyrussell left a comment

Choose a reason for hiding this comment

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

Ack 951fea4

@rustyrussell rustyrussell merged commit 8df27a7 into ElementsProject:master Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants