Skip to content

Commit 087a29b

Browse files
JssDWtvincenzopalazzo
authored andcommitted
libplugin-pay: trace payment_continue
Changelog-Added: Plugins: `pay` now has tracing support for various payment steps.
1 parent 2c09f9d commit 087a29b

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

plugins/libplugin-pay.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
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+
22532267
void 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();

plugins/test/run-route-calc.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,15 @@ void towire_bigsize(u8 **pptr UNNEEDED, const bigsize_t val UNNEEDED)
314314
/* Generated stub for towire_channel_id */
315315
void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED)
316316
{ fprintf(stderr, "towire_channel_id called!\n"); abort(); }
317+
/* Generated stub for trace_span_end */
318+
void trace_span_end(const void *key UNNEEDED)
319+
{ fprintf(stderr, "trace_span_end called!\n"); abort(); }
320+
/* Generated stub for trace_span_start */
321+
void trace_span_start(const char *name UNNEEDED, const void *key UNNEEDED)
322+
{ fprintf(stderr, "trace_span_start called!\n"); abort(); }
323+
/* Generated stub for trace_span_tag */
324+
void trace_span_tag(const void *key UNNEEDED, const char *name UNNEEDED, const char *value UNNEEDED)
325+
{ fprintf(stderr, "trace_span_tag called!\n"); abort(); }
317326
/* AUTOGENERATED MOCKS END */
318327

319328
#ifndef SUPERVERBOSE

plugins/test/run-route-overlong.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,15 @@ void towire_bigsize(u8 **pptr UNNEEDED, const bigsize_t val UNNEEDED)
311311
/* Generated stub for towire_channel_id */
312312
void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED)
313313
{ fprintf(stderr, "towire_channel_id called!\n"); abort(); }
314+
/* Generated stub for trace_span_end */
315+
void trace_span_end(const void *key UNNEEDED)
316+
{ fprintf(stderr, "trace_span_end called!\n"); abort(); }
317+
/* Generated stub for trace_span_start */
318+
void trace_span_start(const char *name UNNEEDED, const void *key UNNEEDED)
319+
{ fprintf(stderr, "trace_span_start called!\n"); abort(); }
320+
/* Generated stub for trace_span_tag */
321+
void trace_span_tag(const void *key UNNEEDED, const char *name UNNEEDED, const char *value UNNEEDED)
322+
{ fprintf(stderr, "trace_span_tag called!\n"); abort(); }
314323
/* AUTOGENERATED MOCKS END */
315324

316325
#ifndef SUPERVERBOSE

0 commit comments

Comments
 (0)