@@ -343,6 +343,13 @@ send_payment_req(struct command *aux_cmd,
343343
344344/* For self-pay, we don't have hops. */
345345static 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" );
0 commit comments