@@ -92,6 +92,13 @@ static struct command_result *payment_rpc_failure(struct command *cmd,
92
92
json_tok_full_len (toks ), json_tok_full (buffer , toks ));
93
93
}
94
94
95
+ static void add_hintchan (struct payment * payment , const struct node_id * src ,
96
+ const struct node_id * dst , u16 cltv_expiry_delta ,
97
+ const struct short_channel_id scid , u32 fee_base_msat ,
98
+ u32 fee_proportional_millionths ,
99
+ const struct amount_msat * chan_htlc_min ,
100
+ const struct amount_msat * chan_htlc_max );
101
+
95
102
/*****************************************************************************
96
103
* previoussuccess
97
104
*
@@ -249,88 +256,23 @@ REGISTER_PAYMENT_MODIFIER(initial_sanity_checks, initial_sanity_checks_cb);
249
256
250
257
/*****************************************************************************
251
258
* selfpay
252
- *
253
- * Checks if the payment destination is the sender's node and perform a self
254
- * payment.
255
259
*/
256
260
257
- static struct command_result * selfpay_success (struct command * cmd ,
258
- const char * method UNUSED ,
259
- const char * buf ,
260
- const jsmntok_t * tok ,
261
- struct payment * payment )
262
- {
263
- struct preimage preimage ;
264
- const char * err ;
265
- err = json_scan (tmpctx , buf , tok , "{payment_preimage:%}" ,
266
- JSON_SCAN (json_to_preimage , & preimage ));
267
- if (err )
268
- plugin_err (
269
- cmd -> plugin , "selfpay didn't have payment_preimage: %.*s" ,
270
- json_tok_full_len (tok ), json_tok_full (buf , tok ));
271
-
272
-
273
- payment_note (payment , LOG_DBG , "Paid with self-pay." );
274
- return payment_success (payment , & preimage );
275
- }
276
- static struct command_result * selfpay_failure (struct command * cmd ,
277
- const char * method UNUSED ,
278
- const char * buf ,
279
- const jsmntok_t * tok ,
280
- struct payment * payment )
281
- {
282
- struct payment_result * result =
283
- tal_sendpay_result_from_json (tmpctx , buf , tok );
284
- if (result == NULL ) {
285
- plugin_log (pay_plugin -> plugin , LOG_UNUSUAL ,
286
- "Unable to parse sendpay failure: %.*s" ,
287
- json_tok_full_len (tok ), json_tok_full (buf , tok ));
288
- return payment_fail (payment , LIGHTNINGD ,
289
- "Self pay failed for unknown reason" );
290
- }
291
- return payment_fail (payment , result -> code , "%s" , result -> message );
292
- }
293
-
294
261
static struct command_result * selfpay_cb (struct payment * payment )
295
262
{
296
- if (!node_id_eq (& pay_plugin -> my_id ,
297
- & payment -> payment_info .destination )) {
298
- return payment_continue (payment );
299
- }
300
-
301
- struct command * cmd = payment_command (payment );
302
- if (!cmd )
303
- plugin_err (pay_plugin -> plugin ,
304
- "Selfpay: cannot get a valid cmd." );
305
-
306
- struct payment_info * pinfo = & payment -> payment_info ;
307
- struct out_req * req ;
308
- req = jsonrpc_request_start (cmd , "renesendpay" , selfpay_success ,
309
- selfpay_failure , payment );
310
- json_add_sha256 (req -> js , "payment_hash" , & pinfo -> payment_hash );
311
- json_add_u64 (req -> js , "partid" , 0 );
312
- json_add_u64 (req -> js , "groupid" , payment -> groupid );
313
- json_add_string (req -> js , "invoice" , pinfo -> invstr );
314
- json_add_node_id (req -> js , "destination" , & pinfo -> destination );
315
- json_add_amount_msat (req -> js , "amount_msat" , pinfo -> amount );
316
- json_add_amount_msat (req -> js , "total_amount_msat" , pinfo -> amount );
317
- json_add_u32 (req -> js , "final_cltv" , pinfo -> final_cltv );
318
- if (pinfo -> label )
319
- json_add_string (req -> js , "label" , pinfo -> label );
320
- if (pinfo -> description )
321
- json_add_string (req -> js , "description" , pinfo -> description );
322
- /* An empty route means a payment to oneself, pathlen=0 */
323
- json_array_start (req -> js , "route" );
324
- json_array_end (req -> js );
325
- if (pinfo -> payment_secret )
326
- json_add_secret (req -> js , "payment_secret" ,
327
- pinfo -> payment_secret );
328
- else {
329
- assert (pinfo -> blinded_paths );
330
- const struct blinded_path * bpath = pinfo -> blinded_paths [0 ];
331
- json_myadd_blinded_path (req -> js , "blinded_path" , bpath );
263
+ /* A different approach to self-pay: create a fake channel from the
264
+ * bolt11 destination to the routing_destination (a fake node_id). */
265
+ if (!payment -> payment_info .blinded_paths ) {
266
+ struct amount_msat htlc_min = AMOUNT_MSAT (0 );
267
+ struct amount_msat htlc_max = AMOUNT_MSAT ((u64 )1000 * 100000000 );
268
+ struct short_channel_id scid = {.u64 = 0 };
269
+ add_hintchan (payment , & payment -> payment_info .destination ,
270
+ payment -> routing_destination ,
271
+ /* cltv delta = */ 0 , scid ,
272
+ /* base fee = */ 0 ,
273
+ /* ppm = */ 0 , & htlc_min , & htlc_max );
332
274
}
333
- return send_outreq ( req );
275
+ return payment_continue ( payment );
334
276
}
335
277
336
278
REGISTER_PAYMENT_MODIFIER (selfpay , selfpay_cb );
@@ -755,8 +697,7 @@ static struct command_result *compute_routes_cb(struct payment *payment)
755
697
756
698
/* Send get_routes a note that it should discard the last hop because we
757
699
* are actually solving a multiple destinations problem. */
758
- bool blinded_destination =
759
- payment -> payment_info .blinded_paths != NULL ;
700
+ bool blinded_destination = true;
760
701
761
702
// TODO: add an algorithm selector here
762
703
/* We let this return an unlikely path, as it's better to try once than
@@ -1291,9 +1232,9 @@ REGISTER_PAYMENT_CONDITION(retry, retry_cb);
1291
1232
// add check pre-approved invoice
1292
1233
void * payment_virtual_program [] = {
1293
1234
/*0*/ OP_CALL , & previoussuccess_pay_mod ,
1294
- /*2*/ OP_CALL , & selfpay_pay_mod ,
1295
- /*4*/ OP_CALL , & knowledgerelax_pay_mod ,
1296
- /*6*/ OP_CALL , & getmychannels_pay_mod ,
1235
+ /*2*/ OP_CALL , & knowledgerelax_pay_mod ,
1236
+ /*4*/ OP_CALL , & getmychannels_pay_mod ,
1237
+ /*6*/ OP_CALL , & selfpay_pay_mod ,
1297
1238
/*8*/ OP_CALL , & refreshgossmap_pay_mod ,
1298
1239
/*10*/ OP_CALL , & routehints_pay_mod ,
1299
1240
/*12*/ OP_CALL , & blindedhints_pay_mod ,
0 commit comments