44#include <ccan/tal/str/str.h>
55#include <ccan/time/time.h>
66#include <common/bolt11.h>
7+ #include <common/type_to_string.h>
78#include <gossipd/gen_gossip_wire.h>
89#include <gossipd/routing.h>
910#include <lightningd/jsonrpc.h>
1011#include <lightningd/jsonrpc_errors.h>
1112#include <lightningd/lightningd.h>
13+ #include <lightningd/log.h>
1214#include <lightningd/subd.h>
1315#include <sodium/randombytes.h>
1416
@@ -131,6 +133,7 @@ static void json_pay_sendpay_resolve(const struct sendpay_result *r,
131133
132134 /* If we succeed, hurray */
133135 if (r -> succeeded ) {
136+ log_info (pay -> cmd -> ld -> log , "pay(%p): Success" , pay );
134137 json_pay_success (pay -> cmd , & r -> preimage ,
135138 pay -> getroute_tries , pay -> sendpay_tries );
136139 return ;
@@ -140,13 +143,39 @@ static void json_pay_sendpay_resolve(const struct sendpay_result *r,
140143 * below. If it is not, fail now. */
141144 if (r -> errorcode != PAY_UNPARSEABLE_ONION &&
142145 r -> errorcode != PAY_TRY_OTHER_ROUTE ) {
146+ log_info (pay -> cmd -> ld -> log , "pay(%p): Failed, reporting to caller" , pay );
143147 json_pay_failure (pay , r );
144148 return ;
145149 }
146150
151+ log_info (pay -> cmd -> ld -> log , "pay(%p): Try another route" , pay );
147152 json_pay_try (pay );
148153}
149154
155+ /* Generates a string describing the route. Route should be a
156+ * tal_arr */
157+ static char const * stringify_route (const tal_t * ctx , struct route_hop * route )
158+ {
159+ size_t i ;
160+ char * rv = tal_strdup (ctx , "us" );
161+ for (i = 0 ; i < tal_count (route ); ++ i )
162+ tal_append_fmt (& rv , " -> %s (%" PRIu32 "msat, %" PRIu32 "blk) -> %s" ,
163+ type_to_string (ctx , struct short_channel_id , & route [i ].channel_id ),
164+ route [i ].amount , route [i ].delay ,
165+ type_to_string (ctx , struct pubkey , & route [i ].nodeid ));
166+ return rv ;
167+ }
168+
169+ static void log_route (struct pay * pay , struct route_hop * route )
170+ {
171+ const tal_t * tmpctx = tal_tmpctx (pay -> try_parent );
172+
173+ log_info (pay -> cmd -> ld -> log , "pay(%p): sendpay via route: %s" ,
174+ pay , stringify_route (tmpctx , route ));
175+
176+ tal_free (tmpctx );
177+ }
178+
150179static void json_pay_getroute_reply (struct subd * gossip UNUSED ,
151180 const u8 * reply , const int * fds UNUSED ,
152181 struct pay * pay )
@@ -215,6 +244,7 @@ static void json_pay_getroute_reply(struct subd *gossip UNUSED,
215244
216245 ++ pay -> sendpay_tries ;
217246
247+ log_route (pay , route );
218248 send_payment (pay -> try_parent ,
219249 pay -> cmd -> ld , & pay -> payment_hash , route ,
220250 & json_pay_sendpay_resolve , pay );
0 commit comments