1111#include <common/memleak.h>
1212#include <common/pseudorand.h>
1313#include <common/random_select.h>
14+ #include <common/trace.h>
1415#include <errno.h>
1516#include <math.h>
1617#include <plugins/libplugin-pay.h>
18+ #include <stdio.h>
1719#include <sys/types.h>
1820#include <wire/peer_wire.h>
1921
@@ -2250,6 +2252,18 @@ static struct command_result *payment_finished(struct payment *p)
22502252 return command_finished (cmd , ret );
22512253}
22522254
2255+ const char * const payment_step_str [] =
2256+ {
2257+ [PAYMENT_STEP_INITIALIZED ] = "PAYMENT_STEP_INITIALIZED" ,
2258+ [PAYMENT_STEP_GOT_ROUTE ] = "PAYMENT_STEP_GOT_ROUTE" ,
2259+ [PAYMENT_STEP_RETRY_GETROUTE ] = "PAYMENT_STEP_RETRY_GETROUTE" ,
2260+ [PAYMENT_STEP_ONION_PAYLOAD ] = "PAYMENT_STEP_ONION_PAYLOAD" ,
2261+ [PAYMENT_STEP_SPLIT ] = "PAYMENT_STEP_SPLIT" ,
2262+ [PAYMENT_STEP_RETRY ] = "PAYMENT_STEP_RETRY" ,
2263+ [PAYMENT_STEP_FAILED ] = "PAYMENT_STEP_FAILED" ,
2264+ [PAYMENT_STEP_SUCCESS ] = "PAYMENT_STEP_SUCCESS" ,
2265+ };
2266+
22532267void payment_set_step (struct payment * p , enum payment_step newstep )
22542268{
22552269 p -> current_modifier = -1 ;
@@ -2264,19 +2278,26 @@ struct command_result *payment_continue(struct payment *p)
22642278{
22652279 struct payment_modifier * mod ;
22662280 void * moddata ;
2281+
2282+ trace_span_start ("payment_continue" , p );
22672283 /* If we are in the middle of calling the modifiers, continue calling
22682284 * them, otherwise we can continue with the payment state-machine. */
22692285 p -> current_modifier ++ ;
22702286 mod = p -> modifiers [p -> current_modifier ];
22712287
22722288 if (mod != NULL ) {
2289+ char * str = tal_fmt (tmpctx , "%d" , p -> current_modifier );
2290+ trace_span_tag (p , "modifier" , str );
2291+ trace_span_end (p );
22732292 /* There is another modifier, so call it. */
22742293 moddata = p -> modifier_data [p -> current_modifier ];
22752294 return mod -> post_step_cb (moddata , p );
22762295 } else {
22772296 /* There are no more modifiers, so reset the call chain and
22782297 * proceed to the next state. */
22792298 p -> current_modifier = -1 ;
2299+ trace_span_tag (p , "step" , payment_step_str [p -> step ]);
2300+ trace_span_end (p );
22802301 switch (p -> step ) {
22812302 case PAYMENT_STEP_INITIALIZED :
22822303 case PAYMENT_STEP_RETRY_GETROUTE :
@@ -2299,6 +2320,7 @@ struct command_result *payment_continue(struct payment *p)
22992320 return command_still_pending (payment_cmd (p ));
23002321 }
23012322 }
2323+ trace_span_end (p );
23022324 /* We should never get here, it'd mean one of the state machine called
23032325 * `payment_continue` after the final state. */
23042326 abort ();
0 commit comments