Skip to content

Commit 8c2821e

Browse files
Lagrang3rustyrussell
authored andcommitted
xpay: fix reported value of amount_sent_msat
Changelog-None Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
1 parent 7ee162b commit 8c2821e

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

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;
@@ -1151,7 +1158,7 @@ static struct command_result *do_inject(struct command *aux_cmd,
11511158
json_add_hex_talarr(req->js, "onion", onion);
11521159
json_add_sha256(req->js, "payment_hash", &attempt->payment->payment_hash);
11531160
/* If no route, its the same as delivery (self-pay) */
1154-
json_add_amount_msat(req->js, "amount_msat", initial_sent(attempt));
1161+
json_add_amount_msat(req->js, "amount_msat", inject_amount(attempt));
11551162
json_add_u32(req->js, "cltv_expiry", initial_cltv_delta(attempt) + effective_bheight);
11561163
json_add_u64(req->js, "partid", attempt->partid);
11571164
json_add_u64(req->js, "groupid", attempt->payment->group_id);
@@ -1466,7 +1473,8 @@ static struct command_result *getroutes_for(struct command *aux_cmd,
14661473
json_array_start(req->js, "layers");
14671474
/* Add local channels */
14681475
json_add_string(req->js, NULL, "auto.localchans");
1469-
/* We don't pay fees for ourselves */
1476+
/* For the MCF computation we must discard the cost of routing through
1477+
* our own channels because we don't pay fees for that. */
14701478
json_add_string(req->js, NULL, "auto.sourcefree");
14711479
/* Add xpay global channel */
14721480
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
@@ -1099,9 +1099,8 @@ def test_blinded_path_fees(node_factory):
10991099
assert ret["failed_parts"] == 0
11001100
assert ret["successful_parts"] == 1
11011101
assert ret["amount_msat"] == AMT_MSAT
1102-
assert ret["amount_sent_msat"] == AMT_MSAT + FEES_MSAT
1102+
assert ret["amount_sent_msat"] == AMT_MSAT
11031103

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

0 commit comments

Comments
 (0)