1010#include <common/memleak.h>
1111#include <common/pseudorand.h>
1212#include <common/random_select.h>
13+ #include <common/trace.h>
1314#include <errno.h>
1415#include <math.h>
1516#include <plugins/libplugin-pay.h>
17+ #include <stdio.h>
1618#include <sys/types.h>
1719#include <wire/peer_wire.h>
1820
@@ -2266,19 +2268,27 @@ void payment_continue(struct payment *p)
22662268{
22672269 struct payment_modifier * mod ;
22682270 void * moddata ;
2271+
2272+ trace_span_start ("payment_continue" , p );
22692273 /* If we are in the middle of calling the modifiers, continue calling
22702274 * them, otherwise we can continue with the payment state-machine. */
22712275 p -> current_modifier ++ ;
22722276 mod = p -> modifiers [p -> current_modifier ];
22732277
22742278 if (mod != NULL ) {
2279+ char str [2 ];
2280+ sprintf (str , "%d" , p -> current_modifier );
2281+ trace_span_tag (p , "modifier" , str );
2282+ trace_span_end (p );
22752283 /* There is another modifier, so call it. */
22762284 moddata = p -> modifier_data [p -> current_modifier ];
22772285 return mod -> post_step_cb (moddata , p );
22782286 } else {
22792287 /* There are no more modifiers, so reset the call chain and
22802288 * proceed to the next state. */
22812289 p -> current_modifier = -1 ;
2290+ trace_span_tag (p , "step" , payment_step_str [p -> step ]);
2291+ trace_span_end (p );
22822292 switch (p -> step ) {
22832293 case PAYMENT_STEP_INITIALIZED :
22842294 case PAYMENT_STEP_RETRY_GETROUTE :
@@ -2305,6 +2315,7 @@ void payment_continue(struct payment *p)
23052315 return ;
23062316 }
23072317 }
2318+ trace_span_end (p );
23082319 /* We should never get here, it'd mean one of the state machine called
23092320 * `payment_continue` after the final state. */
23102321 abort ();
@@ -2506,7 +2517,7 @@ local_channel_hints_listpeerchannels(struct command *cmd, const char *buffer,
25062517 const jsmntok_t * toks , struct payment * p )
25072518{
25082519 struct listpeers_channel * * chans ;
2509-
2520+ trace_span_resume ( p );
25102521 chans = json_to_listpeers_channels (tmpctx , buffer , toks );
25112522
25122523 for (size_t i = 0 ; i < tal_count (chans ); i ++ ) {
@@ -2556,6 +2567,7 @@ local_channel_hints_listpeerchannels(struct command *cmd, const char *buffer,
25562567 }
25572568 }
25582569
2570+ trace_span_end (p );
25592571 payment_continue (p );
25602572 return command_still_pending (cmd );
25612573}
@@ -2571,6 +2583,8 @@ static void local_channel_hints_cb(void *d UNUSED, struct payment *p)
25712583 if (p -> parent != NULL || p -> step != PAYMENT_STEP_INITIALIZED )
25722584 return payment_continue (p );
25732585
2586+ trace_span_start ("local_channel_hints_cb" , p );
2587+ trace_span_suspend (p );
25742588 req = jsonrpc_request_start (p -> plugin , NULL , "listpeerchannels" ,
25752589 local_channel_hints_listpeerchannels ,
25762590 local_channel_hints_listpeerchannels , p );
@@ -3125,6 +3139,7 @@ static void exemptfee_cb(struct exemptfee_data *d, struct payment *p)
31253139 if (p -> step != PAYMENT_STEP_INITIALIZED || p -> parent != NULL )
31263140 return payment_continue (p );
31273141
3142+ trace_span_start ("exemptfee_cb" , p );
31283143 if (amount_msat_greater_eq (d -> amount , p -> constraints .fee_budget )) {
31293144 paymod_log (
31303145 p , LOG_INFORM ,
@@ -3135,6 +3150,8 @@ static void exemptfee_cb(struct exemptfee_data *d, struct payment *p)
31353150 p -> constraints .fee_budget = d -> amount ;
31363151 p -> start_constraints -> fee_budget = d -> amount ;
31373152 }
3153+
3154+ trace_span_end (p );
31383155 return payment_continue (p );
31393156}
31403157
@@ -3343,6 +3360,7 @@ static void shadow_route_cb(struct shadow_route_data *d,
33433360 if (p -> step != PAYMENT_STEP_INITIALIZED )
33443361 return payment_continue (p );
33453362
3363+ trace_span_start ("shadow_route_cb" , p );
33463364 d -> destination = * p -> destination ;
33473365
33483366 /* Allow shadowroutes to consume up to 1/4th of our budget. */
@@ -3351,8 +3369,12 @@ static void shadow_route_cb(struct shadow_route_data *d,
33513369 = amount_msat_div (p -> constraints .fee_budget , 4 );
33523370
33533371 if (pseudorand (2 ) == 0 ) {
3372+ trace_span_tag (p , "shadow_route_cb" , "pseudorand(2) == 0" );
3373+ trace_span_end (p );
33543374 return payment_continue (p );
33553375 } else {
3376+ trace_span_tag (p , "shadow_route_cb" , "pseudorand(2) != 0" );
3377+ trace_span_end (p );
33563378 shadow_route_extend (d , p );
33573379 }
33583380}
@@ -3371,8 +3393,11 @@ static void direct_pay_override(struct payment *p) {
33713393 * anything. */
33723394 d = payment_mod_directpay_get_data (root );
33733395
3374- if (d -> chan == NULL )
3396+ if (d -> chan == NULL ) {
3397+ trace_span_tag (p , "direct_pay_override" , "d->chan == NULL" );
3398+ trace_span_end (p );
33753399 return payment_continue (p );
3400+ }
33763401
33773402 /* If we have a channel we need to make sure that it still has
33783403 * sufficient capacity. Look it up in the channel_hints. */
@@ -3402,7 +3427,7 @@ static void direct_pay_override(struct payment *p) {
34023427 payment_set_step (p , PAYMENT_STEP_GOT_ROUTE );
34033428 }
34043429
3405-
3430+ trace_span_end ( p );
34063431 payment_continue (p );
34073432}
34083433
@@ -3414,6 +3439,7 @@ static struct command_result *direct_pay_listpeerchannels(struct command *cmd,
34143439 const jsmntok_t * toks ,
34153440 struct payment * p )
34163441{
3442+ trace_span_resume (p );
34173443 struct listpeers_channel * * channels = json_to_listpeers_channels (tmpctx , buffer , toks );
34183444 struct direct_pay_data * d = payment_mod_directpay_get_data (p );
34193445
@@ -3464,7 +3490,8 @@ static void direct_pay_cb(struct direct_pay_data *d, struct payment *p)
34643490 return payment_continue (p );
34653491
34663492
3467-
3493+ trace_span_start ("direct_pay_cb" , p );
3494+ trace_span_suspend (p );
34683495 req = jsonrpc_request_start (p -> plugin , NULL , "listpeerchannels" ,
34693496 direct_pay_listpeerchannels ,
34703497 direct_pay_listpeerchannels ,
@@ -3720,7 +3747,7 @@ payee_incoming_limit_count(struct command *cmd,
37203747{
37213748 const jsmntok_t * channelstok ;
37223749 size_t num_channels = 0 ;
3723-
3750+ trace_span_start ( "payee_incoming_limit_count" , p );
37243751 channelstok = json_get_member (buf , result , "channels" );
37253752 assert (channelstok );
37263753
@@ -3753,6 +3780,7 @@ payee_incoming_limit_count(struct command *cmd,
37533780 payment_lower_max_htlcs (p , lim , why );
37543781 }
37553782
3783+ trace_span_end (p );
37563784 payment_continue (p );
37573785 return command_still_pending (cmd );
37583786}
@@ -3766,8 +3794,10 @@ static void payee_incoming_limit_step_cb(void *d UNUSED, struct payment *p)
37663794 || !payment_supports_mpp (p ))
37673795 return payment_continue (p );
37683796
3797+ trace_span_start ("payee_incoming_limit_step_cb" , p );
37693798 /* Get information on the destination. */
37703799 struct out_req * req ;
3800+ trace_span_end (p );
37713801 req = jsonrpc_request_start (p -> plugin , NULL , "listchannels" ,
37723802 & payee_incoming_limit_count ,
37733803 & payment_rpc_failure , p );
@@ -3796,6 +3826,8 @@ static void route_exclusions_step_cb(struct route_exclusions_data *d,
37963826{
37973827 if (p -> parent )
37983828 return payment_continue (p );
3829+
3830+ trace_span_start ("route_exclusions_step_cb" , p );
37993831 struct route_exclusion * * exclusions = d -> exclusions ;
38003832 for (size_t i = 0 ; i < tal_count (exclusions ); i ++ ) {
38013833 struct route_exclusion * e = exclusions [i ];
@@ -3814,6 +3846,7 @@ static void route_exclusions_step_cb(struct route_exclusions_data *d,
38143846 tal_arr_expand (& p -> excluded_nodes , e -> u .node_id );
38153847 }
38163848 }
3849+ trace_span_end (p );
38173850 payment_continue (p );
38183851}
38193852
0 commit comments