4
4
#include <ccan/tal/str/str.h>
5
5
#include <ccan/time/time.h>
6
6
#include <common/bolt11.h>
7
+ #include <common/type_to_string.h>
7
8
#include <gossipd/gen_gossip_wire.h>
8
9
#include <gossipd/routing.h>
9
10
#include <lightningd/jsonrpc.h>
10
11
#include <lightningd/jsonrpc_errors.h>
11
12
#include <lightningd/lightningd.h>
13
+ #include <lightningd/log.h>
12
14
#include <lightningd/subd.h>
13
15
#include <sodium/randombytes.h>
14
16
@@ -131,6 +133,7 @@ static void json_pay_sendpay_resolve(const struct sendpay_result *r,
131
133
132
134
/* If we succeed, hurray */
133
135
if (r -> succeeded ) {
136
+ log_info (pay -> cmd -> ld -> log , "pay(%p): Success" , pay );
134
137
json_pay_success (pay -> cmd , & r -> preimage ,
135
138
pay -> getroute_tries , pay -> sendpay_tries );
136
139
return ;
@@ -140,13 +143,39 @@ static void json_pay_sendpay_resolve(const struct sendpay_result *r,
140
143
* below. If it is not, fail now. */
141
144
if (r -> errorcode != PAY_UNPARSEABLE_ONION &&
142
145
r -> errorcode != PAY_TRY_OTHER_ROUTE ) {
146
+ log_info (pay -> cmd -> ld -> log , "pay(%p): Failed, reporting to caller" , pay );
143
147
json_pay_failure (pay , r );
144
148
return ;
145
149
}
146
150
151
+ log_info (pay -> cmd -> ld -> log , "pay(%p): Try another route" , pay );
147
152
json_pay_try (pay );
148
153
}
149
154
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
+
150
179
static void json_pay_getroute_reply (struct subd * gossip UNUSED ,
151
180
const u8 * reply , const int * fds UNUSED ,
152
181
struct pay * pay )
@@ -215,6 +244,7 @@ static void json_pay_getroute_reply(struct subd *gossip UNUSED,
215
244
216
245
++ pay -> sendpay_tries ;
217
246
247
+ log_route (pay , route );
218
248
send_payment (pay -> try_parent ,
219
249
pay -> cmd -> ld , & pay -> payment_hash , route ,
220
250
& json_pay_sendpay_resolve , pay );
0 commit comments