33#include <ccan/tal/str/str.h>
44#include <ccan/time/time.h>
55#include <common/bolt11.h>
6+ #include <common/type_to_string.h>
67#include <gossipd/gen_gossip_wire.h>
78#include <gossipd/routing.h>
89#include <lightningd/jsonrpc.h>
910#include <lightningd/jsonrpc_errors.h>
1011#include <lightningd/lightningd.h>
12+ #include <lightningd/log.h>
1113#include <lightningd/subd.h>
1214
1315struct pay {
@@ -120,6 +122,7 @@ static void json_pay_sendpay_resolve(const struct sendpay_result *r,
120122
121123 /* If we succeed, hurray */
122124 if (r -> succeeded ) {
125+ log_info (pay -> cmd -> ld -> log , "pay(%p): Success" , pay );
123126 json_pay_success (pay -> cmd , & r -> preimage , pay -> tries );
124127 return ;
125128 }
@@ -128,13 +131,39 @@ static void json_pay_sendpay_resolve(const struct sendpay_result *r,
128131 * below. If it is not, fail now. */
129132 if (r -> errorcode != PAY_UNPARSEABLE_ONION &&
130133 r -> errorcode != PAY_TRY_OTHER_ROUTE ) {
134+ log_info (pay -> cmd -> ld -> log , "pay(%p): Failed, reporting to caller" , pay );
131135 json_pay_failure (pay , r );
132136 return ;
133137 }
134138
139+ log_info (pay -> cmd -> ld -> log , "pay(%p): Try another route" , pay );
135140 json_pay_try (pay );
136141}
137142
143+ /* Generates a string describing the route. Route should be a
144+ * tal_arr */
145+ static char const * stringify_route (const tal_t * ctx , struct route_hop * route )
146+ {
147+ size_t i ;
148+ char * rv = tal_strdup (ctx , "us" );
149+ for (i = 0 ; i < tal_count (route ); ++ i )
150+ tal_append_fmt (& rv , " -> %s (%" PRIu32 "msat, %" PRIu32 "blk) -> %s" ,
151+ type_to_string (ctx , struct short_channel_id , & route [i ].channel_id ),
152+ route [i ].amount , route [i ].delay ,
153+ type_to_string (ctx , struct pubkey , & route [i ].nodeid ));
154+ return rv ;
155+ }
156+
157+ static void log_route (struct pay * pay , struct route_hop * route )
158+ {
159+ const tal_t * tmpctx = tal_tmpctx (pay -> sendpay_parent );
160+
161+ log_info (pay -> cmd -> ld -> log , "pay(%p): sendpay via route: %s" ,
162+ pay , stringify_route (tmpctx , route ));
163+
164+ tal_free (tmpctx );
165+ }
166+
138167static void json_pay_getroute_reply (struct subd * gossip UNUSED ,
139168 const u8 * reply , const int * fds UNUSED ,
140169 struct pay * pay )
@@ -188,6 +217,7 @@ static void json_pay_getroute_reply(struct subd *gossip UNUSED,
188217 return ;
189218 }
190219
220+ log_route (pay , route );
191221 send_payment (pay -> sendpay_parent ,
192222 pay -> cmd -> ld , & pay -> payment_hash , route ,
193223 & json_pay_sendpay_resolve , pay );
0 commit comments