Skip to content

Commit 0c287ab

Browse files
committed
xpay: fix reported value of amount_sent_msat
Changelog-None Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
1 parent 8b80ed8 commit 0c287ab

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

plugins/xpay/xpay.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,13 @@ send_payment_req(struct command *aux_cmd,
343343

344344
/* For self-pay, we don't have hops. */
345345
static struct amount_msat initial_sent(const struct attempt *attempt)
346+
{
347+
if (tal_count(attempt->hops) == 0)
348+
return attempt->delivers;
349+
return attempt->hops[0].amount_out;
350+
}
351+
352+
static struct amount_msat inject_amount(const struct attempt *attempt)
346353
{
347354
if (tal_count(attempt->hops) == 0)
348355
return attempt->delivers;
@@ -1143,7 +1150,7 @@ static struct command_result *do_inject(struct command *aux_cmd,
11431150
json_add_hex_talarr(req->js, "onion", onion);
11441151
json_add_sha256(req->js, "payment_hash", &attempt->payment->payment_hash);
11451152
/* If no route, its the same as delivery (self-pay) */
1146-
json_add_amount_msat(req->js, "amount_msat", initial_sent(attempt));
1153+
json_add_amount_msat(req->js, "amount_msat", inject_amount(attempt));
11471154
json_add_u32(req->js, "cltv_expiry", initial_cltv_delta(attempt) + effective_bheight);
11481155
json_add_u64(req->js, "partid", attempt->partid);
11491156
json_add_u64(req->js, "groupid", attempt->payment->group_id);
@@ -1458,7 +1465,8 @@ static struct command_result *getroutes_for(struct command *aux_cmd,
14581465
json_array_start(req->js, "layers");
14591466
/* Add local channels */
14601467
json_add_string(req->js, NULL, "auto.localchans");
1461-
/* We don't pay fees for ourselves */
1468+
/* For the MCF computation we must discard the cost of routing through
1469+
* our own channels because we don't pay fees for that. */
14621470
json_add_string(req->js, NULL, "auto.sourcefree");
14631471
/* Add xpay global channel */
14641472
json_add_string(req->js, NULL, "xpay");

tests/test_xpay.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,9 +1097,8 @@ def test_bolt12_fees(node_factory):
10971097
assert ret["failed_parts"] == 0
10981098
assert ret["successful_parts"] == 1
10991099
assert ret["amount_msat"] == AMT_MSAT
1100-
assert ret["amount_sent_msat"] == AMT_MSAT + FEES_MSAT
1100+
assert ret["amount_sent_msat"] == AMT_MSAT
11011101

1102-
# we pay fees to ourselves
11031102
htlcs = l1.rpc.listhtlcs()["htlcs"]
11041103
assert len(htlcs) == 1
11051104
assert htlcs[0]["payment_hash"] == b12_decode["invoice_payment_hash"]

0 commit comments

Comments
 (0)