mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-23 06:55:13 +01:00
libplugin-pay: fix command logging
We were dereferencing the first character of the id, (always '"') which meant everything was id 34. Before: plugin-pay: cmd 34 partid 5 After: cmd pytest:pay#62/cln:pay#105 partid 0 Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Changelog-Fixed: `pay`: debug logging now uses correct JSON ids.
This commit is contained in:
parent
ec8293d215
commit
bc22a8db4f
1 changed files with 10 additions and 27 deletions
|
@ -178,31 +178,18 @@ struct payment *payment_root(struct payment *p)
|
||||||
return payment_root(p->parent);
|
return payment_root(p->parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static const char *paymod_log_header(const tal_t *ctx,
|
||||||
paymod_log_header(struct payment *p, const char **type, u64 *id)
|
struct payment *p)
|
||||||
{
|
{
|
||||||
struct payment *root = payment_root(p);
|
const char *id = payment_cmd(p)->id;
|
||||||
/* We prefer to show the command ID here since it is also known
|
if (strstarts(id, "\""))
|
||||||
* by `lightningd`, so in theory it can be used to correlate
|
return tal_strndup(ctx, id+1, strlen(id+1)-1);
|
||||||
* debugging logs between the main `lightningd` and whatever
|
return tal_strdup(ctx, id);
|
||||||
* plugin is using the paymod system.
|
|
||||||
* We only fall back to a unique id per root payment if there
|
|
||||||
* is no command with an id associated with this payment.
|
|
||||||
*/
|
|
||||||
if (root->cmd && root->cmd->id) {
|
|
||||||
*type = "cmd";
|
|
||||||
*id = *root->cmd->id;
|
|
||||||
} else {
|
|
||||||
*type = "id";
|
|
||||||
*id = root->id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
paymod_log(struct payment *p, enum log_level l, const char *fmt, ...)
|
paymod_log(struct payment *p, enum log_level l, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
const char *type;
|
|
||||||
u64 id;
|
|
||||||
char *txt;
|
char *txt;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
|
@ -210,15 +197,12 @@ paymod_log(struct payment *p, enum log_level l, const char *fmt, ...)
|
||||||
txt = tal_vfmt(tmpctx, fmt, ap);
|
txt = tal_vfmt(tmpctx, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
paymod_log_header(p, &type, &id);
|
plugin_log(p->plugin, l, "cmd %s partid %"PRIu32": %s",
|
||||||
plugin_log(p->plugin, l, "%s %"PRIu64" partid %"PRIu32": %s",
|
paymod_log_header(tmpctx, p), p->partid, txt);
|
||||||
type, id, p->partid, txt);
|
|
||||||
}
|
}
|
||||||
static void
|
static void
|
||||||
paymod_err(struct payment *p, const char *fmt, ...)
|
paymod_err(struct payment *p, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
const char *type;
|
|
||||||
u64 id;
|
|
||||||
char *txt;
|
char *txt;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
|
@ -226,9 +210,8 @@ paymod_err(struct payment *p, const char *fmt, ...)
|
||||||
txt = tal_vfmt(tmpctx, fmt, ap);
|
txt = tal_vfmt(tmpctx, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
paymod_log_header(p, &type, &id);
|
plugin_err(p->plugin, "cmd %s partid %"PRIu32": %s",
|
||||||
plugin_err(p->plugin, "%s %"PRIu64" partid %"PRIu32": %s",
|
paymod_log_header(tmpctx, p), p->partid, txt);
|
||||||
type, id, p->partid, txt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generic handler for RPC failures that should end up failing the payment. */
|
/* Generic handler for RPC failures that should end up failing the payment. */
|
||||||
|
|
Loading…
Add table
Reference in a new issue