Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trace payment_continue and payment mods #7556

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions common/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ void trace_span_tag(const void *key, const char *name, const char *value)
size_t s = tal_count(span->tags);
tal_resize(&span->tags, s + 1);
span->tags[s].name = tal_strdup(span->tags, name);
if (strstarts(value, "\"")
&& strlen(value) > 1
&& strends(value, "\"")) {
value = tal_strndup(tmpctx, value + 1,
strlen(value) - 2);
}
span->tags[s].value = tal_strdup(span->tags, value);
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ PLUGIN_COMMANDO_OBJS := $(PLUGIN_COMMANDO_SRC:.c=.o)
PLUGIN_KEYSEND_SRC := plugins/keysend.c
PLUGIN_KEYSEND_OBJS := $(PLUGIN_KEYSEND_SRC:.c=.o)

PLUGIN_LIB_SRC := plugins/libplugin.c
PLUGIN_LIB_HEADER := plugins/libplugin.h
PLUGIN_LIB_SRC := plugins/libplugin.c common/trace.c
PLUGIN_LIB_HEADER := plugins/libplugin.h common/trace.h
PLUGIN_LIB_OBJS := $(PLUGIN_LIB_SRC:.c=.o)

PLUGIN_PAY_LIB_SRC := plugins/libplugin-pay.c
Expand Down
15 changes: 15 additions & 0 deletions plugins/bkpr/test/run-bkpr_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,21 @@ void towire_u8_array(u8 **pptr UNNEEDED, const u8 *arr UNNEEDED, size_t num UNNE
/* Generated stub for towire_wirestring */
void towire_wirestring(u8 **pptr UNNEEDED, const char *str UNNEEDED)
{ fprintf(stderr, "towire_wirestring called!\n"); abort(); }
/* Generated stub for trace_span_end */
void trace_span_end(const void *key UNNEEDED)
{ fprintf(stderr, "trace_span_end called!\n"); abort(); }
/* Generated stub for trace_span_resume */
void trace_span_resume(const void *key UNNEEDED)
{ fprintf(stderr, "trace_span_resume called!\n"); abort(); }
/* Generated stub for trace_span_start */
void trace_span_start(const char *name UNNEEDED, const void *key UNNEEDED)
{ fprintf(stderr, "trace_span_start called!\n"); abort(); }
/* Generated stub for trace_span_suspend */
void trace_span_suspend(const void *key UNNEEDED)
{ fprintf(stderr, "trace_span_suspend called!\n"); abort(); }
/* Generated stub for trace_span_tag */
void trace_span_tag(const void *key UNNEEDED, const char *name UNNEEDED, const char *value UNNEEDED)
{ fprintf(stderr, "trace_span_tag called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

static char *tmp_dsn(const tal_t *ctx)
Expand Down
15 changes: 15 additions & 0 deletions plugins/bkpr/test/run-recorder.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,21 @@ void towire_u8_array(u8 **pptr UNNEEDED, const u8 *arr UNNEEDED, size_t num UNNE
/* Generated stub for towire_wirestring */
void towire_wirestring(u8 **pptr UNNEEDED, const char *str UNNEEDED)
{ fprintf(stderr, "towire_wirestring called!\n"); abort(); }
/* Generated stub for trace_span_end */
void trace_span_end(const void *key UNNEEDED)
{ fprintf(stderr, "trace_span_end called!\n"); abort(); }
/* Generated stub for trace_span_resume */
void trace_span_resume(const void *key UNNEEDED)
{ fprintf(stderr, "trace_span_resume called!\n"); abort(); }
/* Generated stub for trace_span_start */
void trace_span_start(const char *name UNNEEDED, const void *key UNNEEDED)
{ fprintf(stderr, "trace_span_start called!\n"); abort(); }
/* Generated stub for trace_span_suspend */
void trace_span_suspend(const void *key UNNEEDED)
{ fprintf(stderr, "trace_span_suspend called!\n"); abort(); }
/* Generated stub for trace_span_tag */
void trace_span_tag(const void *key UNNEEDED, const char *name UNNEEDED, const char *value UNNEEDED)
{ fprintf(stderr, "trace_span_tag called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

static char *tmp_dsn(const tal_t *ctx)
Expand Down
22 changes: 22 additions & 0 deletions plugins/libplugin-pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
#include <common/memleak.h>
#include <common/pseudorand.h>
#include <common/random_select.h>
#include <common/trace.h>
#include <errno.h>
#include <math.h>
#include <plugins/libplugin-pay.h>
#include <stdio.h>
#include <sys/types.h>
#include <wire/peer_wire.h>

Expand Down Expand Up @@ -2252,6 +2254,18 @@ static void payment_finished(struct payment *p)
}
}

const char * const payment_step_str[] =
{
[PAYMENT_STEP_INITIALIZED] = "PAYMENT_STEP_INITIALIZED",
[PAYMENT_STEP_GOT_ROUTE] = "PAYMENT_STEP_GOT_ROUTE",
[PAYMENT_STEP_RETRY_GETROUTE] = "PAYMENT_STEP_RETRY_GETROUTE",
[PAYMENT_STEP_ONION_PAYLOAD] = "PAYMENT_STEP_ONION_PAYLOAD",
[PAYMENT_STEP_SPLIT] = "PAYMENT_STEP_SPLIT",
[PAYMENT_STEP_RETRY] = "PAYMENT_STEP_RETRY",
[PAYMENT_STEP_FAILED] = "PAYMENT_STEP_FAILED",
[PAYMENT_STEP_SUCCESS] = "PAYMENT_STEP_SUCCESS",
};

void payment_set_step(struct payment *p, enum payment_step newstep)
{
p->current_modifier = -1;
Expand All @@ -2266,19 +2280,26 @@ void payment_continue(struct payment *p)
{
struct payment_modifier *mod;
void *moddata;

trace_span_start("payment_continue", p);
/* If we are in the middle of calling the modifiers, continue calling
* them, otherwise we can continue with the payment state-machine. */
p->current_modifier++;
mod = p->modifiers[p->current_modifier];

if (mod != NULL) {
char *str = tal_fmt(tmpctx, "%d", p->current_modifier);
trace_span_tag(p, "modifier", str);
trace_span_end(p);
/* There is another modifier, so call it. */
moddata = p->modifier_data[p->current_modifier];
return mod->post_step_cb(moddata, p);
} else {
/* There are no more modifiers, so reset the call chain and
* proceed to the next state. */
p->current_modifier = -1;
trace_span_tag(p, "step", payment_step_str[p->step]);
trace_span_end(p);
switch (p->step) {
case PAYMENT_STEP_INITIALIZED:
case PAYMENT_STEP_RETRY_GETROUTE:
Expand All @@ -2305,6 +2326,7 @@ void payment_continue(struct payment *p)
return;
}
}
trace_span_end(p);
/* We should never get here, it'd mean one of the state machine called
* `payment_continue` after the final state. */
abort();
Expand Down
16 changes: 16 additions & 0 deletions plugins/libplugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <common/memleak.h>
#include <common/plugin.h>
#include <common/route.h>
#include <common/trace.h>
#include <errno.h>
#include <plugins/libplugin.h>
#include <stdio.h>
Expand Down Expand Up @@ -973,10 +974,18 @@ static void handle_rpc_reply(struct plugin *plugin, const jsmntok_t *toks)
if (out->cmd)
tal_del_destructor2(out->cmd, disable_request_cb, out);

trace_span_resume(out);

/* We want to free this if callback doesn't. */
tal_steal(tmpctx, out);

contenttok = json_get_member(buf, toks, "error");

/* Annotate the JSON-RPC span whether it succeeded or failed,
* and then emit it. */
trace_span_tag(out, "error", contenttok == NULL ? "true" : "false");
trace_span_end(out);

if (contenttok) {
if (out->errcb)
res = out->errcb(out->cmd, buf, contenttok, out->arg);
Expand Down Expand Up @@ -1007,6 +1016,13 @@ send_outreq(struct plugin *plugin, const struct out_req *req)
json_object_end(req->js);
json_stream_close(req->js, req->cmd);

/* We are about to hand control over to the RPC, so suspend
* the current span. It'll be resumed as soon as we have a
* result to pass to either the error or the success
* callback. */
trace_span_start("jsonrpc", req);
trace_span_tag(req, "id", req->id);
trace_span_suspend(req);
ld_rpc_send(plugin, req->js);

if (req->cmd != NULL)
Expand Down
9 changes: 9 additions & 0 deletions plugins/test/run-route-calc.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,15 @@ void towire_bigsize(u8 **pptr UNNEEDED, const bigsize_t val UNNEEDED)
/* Generated stub for towire_channel_id */
void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "towire_channel_id called!\n"); abort(); }
/* Generated stub for trace_span_end */
void trace_span_end(const void *key UNNEEDED)
{ fprintf(stderr, "trace_span_end called!\n"); abort(); }
/* Generated stub for trace_span_start */
void trace_span_start(const char *name UNNEEDED, const void *key UNNEEDED)
{ fprintf(stderr, "trace_span_start called!\n"); abort(); }
/* Generated stub for trace_span_tag */
void trace_span_tag(const void *key UNNEEDED, const char *name UNNEEDED, const char *value UNNEEDED)
{ fprintf(stderr, "trace_span_tag called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

#ifndef SUPERVERBOSE
Expand Down
9 changes: 9 additions & 0 deletions plugins/test/run-route-overlong.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,15 @@ void towire_bigsize(u8 **pptr UNNEEDED, const bigsize_t val UNNEEDED)
/* Generated stub for towire_channel_id */
void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "towire_channel_id called!\n"); abort(); }
/* Generated stub for trace_span_end */
void trace_span_end(const void *key UNNEEDED)
{ fprintf(stderr, "trace_span_end called!\n"); abort(); }
/* Generated stub for trace_span_start */
void trace_span_start(const char *name UNNEEDED, const void *key UNNEEDED)
{ fprintf(stderr, "trace_span_start called!\n"); abort(); }
/* Generated stub for trace_span_tag */
void trace_span_tag(const void *key UNNEEDED, const char *name UNNEEDED, const char *value UNNEEDED)
{ fprintf(stderr, "trace_span_tag called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

#ifndef SUPERVERBOSE
Expand Down
Loading