@@ -601,12 +601,54 @@ static struct command_result *sendroutes_done(struct command *cmd,
601601 return payment_continue (payment );
602602}
603603
604+ static struct command_result * unreserve_done (struct command * aux_cmd ,
605+ const char * method UNUSED ,
606+ const char * buf UNUSED ,
607+ const jsmntok_t * result UNUSED ,
608+ struct route * route UNUSED )
609+ {
610+ return aux_command_done (aux_cmd );
611+ }
612+
613+ static struct command_result *
614+ unreserve_fail (struct command * aux_cmd , const char * method , const char * buf ,
615+ const jsmntok_t * result , struct route * route UNUSED )
616+ {
617+ plugin_log (aux_cmd -> plugin , LOG_UNUSUAL , "%s failed: %.*s" , method ,
618+ json_tok_full_len (result ), json_tok_full (buf , result ));
619+ return aux_command_done (aux_cmd );
620+ }
621+
622+ static void unreserve_route (struct route * route , struct command * aux_cmd )
623+ {
624+ struct out_req * req =
625+ jsonrpc_request_start (aux_cmd , "askrene-unreserve" , unreserve_done ,
626+ unreserve_fail , route );
627+ json_array_start (req -> js , "path" );
628+ for (size_t i = 0 ; i < tal_count (route -> hops ); i ++ ) {
629+ const struct route_hop * hop = & route -> hops [i ];
630+ struct short_channel_id_dir scidd = {.scid = hop -> scid ,
631+ .dir = hop -> direction };
632+ json_object_start (req -> js , NULL );
633+ json_add_short_channel_id_dir (req -> js , "short_channel_id_dir" ,
634+ scidd );
635+ json_add_amount_msat (req -> js , "amount_msat" , hop -> amount );
636+ json_object_end (req -> js );
637+ }
638+ json_array_end (req -> js );
639+ send_outreq (req );
640+ }
641+
604642static struct command_result * reserve_done (struct command * cmd ,
605643 const char * method UNUSED ,
606644 const char * buf UNUSED ,
607645 const jsmntok_t * result UNUSED ,
608- struct route * route UNUSED )
646+ struct route * route )
609647{
648+ /* A new command is issued to handle the destruction of this route.
649+ * I hope aux_cmd outlives the current payment session cmd. */
650+ struct command * aux_cmd = aux_command (cmd );
651+ tal_add_destructor2 (route , unreserve_route , aux_cmd );
610652 return command_still_pending (cmd );
611653}
612654
0 commit comments