mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 10:46:58 +01:00
log: add channel_state logging ability.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
89235e0904
commit
1518f4424e
3 changed files with 46 additions and 50 deletions
24
daemon/log.c
24
daemon/log.c
|
@ -1,6 +1,7 @@
|
||||||
#include "bitcoin/locktime.h"
|
#include "bitcoin/locktime.h"
|
||||||
#include "bitcoin/pubkey.h"
|
#include "bitcoin/pubkey.h"
|
||||||
#include "bitcoin/tx.h"
|
#include "bitcoin/tx.h"
|
||||||
|
#include "channel.h"
|
||||||
#include "controlled_time.h"
|
#include "controlled_time.h"
|
||||||
#include "htlc.h"
|
#include "htlc.h"
|
||||||
#include "lightningd.h"
|
#include "lightningd.h"
|
||||||
|
@ -326,8 +327,29 @@ static char *to_string_(const tal_t *ctx,
|
||||||
h->src ? to_string(ctx, lr, struct pubkey,
|
h->src ? to_string(ctx, lr, struct pubkey,
|
||||||
h->src->peer->id)
|
h->src->peer->id)
|
||||||
: "local");
|
: "local");
|
||||||
} else if (streq(structname, "struct rval"))
|
} else if (streq(structname, "struct rval")) {
|
||||||
s = tal_hexstr(ctx, u.rval, sizeof(*u.rval));
|
s = tal_hexstr(ctx, u.rval, sizeof(*u.rval));
|
||||||
|
} else if (streq(structname, "struct channel_oneside")) {
|
||||||
|
s = tal_fmt(ctx, "{ pay_msat=%u"
|
||||||
|
" fee_msat=%u"
|
||||||
|
" num_htlcs=%u }",
|
||||||
|
u.channel_oneside->pay_msat,
|
||||||
|
u.channel_oneside->fee_msat,
|
||||||
|
u.channel_oneside->num_htlcs);
|
||||||
|
} else if (streq(structname, "struct channel_state")) {
|
||||||
|
s = tal_fmt(ctx, "{ anchor=%"PRIu64
|
||||||
|
" fee_rate=%"PRIu64
|
||||||
|
" num_nondust=%u"
|
||||||
|
" ours=%s"
|
||||||
|
" theirs=%s }",
|
||||||
|
u.cstate->anchor,
|
||||||
|
u.cstate->fee_rate,
|
||||||
|
u.cstate->num_nondust,
|
||||||
|
to_string(ctx, lr, struct channel_oneside,
|
||||||
|
&u.cstate->side[OURS]),
|
||||||
|
to_string(ctx, lr, struct channel_oneside,
|
||||||
|
&u.cstate->side[THEIRS]));
|
||||||
|
}
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,8 @@ union loggable_structs {
|
||||||
const struct bitcoin_tx *bitcoin_tx;
|
const struct bitcoin_tx *bitcoin_tx;
|
||||||
const struct htlc *htlc;
|
const struct htlc *htlc;
|
||||||
const struct rval *rval;
|
const struct rval *rval;
|
||||||
|
const struct channel_state *cstate;
|
||||||
|
const struct channel_oneside *channel_oneside;
|
||||||
const char *charp_;
|
const char *charp_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -207,22 +207,12 @@ void debug_dump_peers(struct lightningd_state *dstate)
|
||||||
if (!peer->local.commit
|
if (!peer->local.commit
|
||||||
|| !peer->remote.commit)
|
|| !peer->remote.commit)
|
||||||
continue;
|
continue;
|
||||||
log_debug(peer->log,
|
log_debug_struct(peer->log, "our cstate: %s",
|
||||||
"Local cstate: pay %u/%u fee %u/%u htlcs %u/%u",
|
struct channel_state,
|
||||||
peer->local.commit->cstate->side[OURS].pay_msat,
|
peer->local.commit->cstate);
|
||||||
peer->local.commit->cstate->side[THEIRS].pay_msat,
|
log_debug_struct(peer->log, "their cstate: %s",
|
||||||
peer->local.commit->cstate->side[OURS].fee_msat,
|
struct channel_state,
|
||||||
peer->local.commit->cstate->side[THEIRS].fee_msat,
|
peer->remote.commit->cstate);
|
||||||
peer->local.commit->cstate->side[OURS].num_htlcs,
|
|
||||||
peer->local.commit->cstate->side[THEIRS].num_htlcs);
|
|
||||||
log_debug(peer->log,
|
|
||||||
"Remote cstate: pay %u/%u fee %u/%u htlcs %u/%u",
|
|
||||||
peer->remote.commit->cstate->side[OURS].pay_msat,
|
|
||||||
peer->remote.commit->cstate->side[THEIRS].pay_msat,
|
|
||||||
peer->remote.commit->cstate->side[OURS].fee_msat,
|
|
||||||
peer->remote.commit->cstate->side[THEIRS].fee_msat,
|
|
||||||
peer->remote.commit->cstate->side[OURS].num_htlcs,
|
|
||||||
peer->remote.commit->cstate->side[THEIRS].num_htlcs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -996,13 +986,8 @@ static Pkt *handle_pkt_commit(struct peer *peer, const Pkt *pkt)
|
||||||
ci->cstate, LOCAL, &to_them_only);
|
ci->cstate, LOCAL, &to_them_only);
|
||||||
bitcoin_txid(ci->tx, &ci->txid);
|
bitcoin_txid(ci->tx, &ci->txid);
|
||||||
|
|
||||||
log_debug(peer->log, "Check tx %"PRIu64" sig for %u/%u msatoshis, %u/%u htlcs (%u non-dust)",
|
log_debug(peer->log, "Check tx %"PRIu64" sig", ci->commit_num);
|
||||||
ci->commit_num,
|
log_add_struct(peer->log, " for %s", struct channel_state, ci->cstate);
|
||||||
ci->cstate->side[THEIRS].pay_msat,
|
|
||||||
ci->cstate->side[OURS].pay_msat,
|
|
||||||
ci->cstate->side[THEIRS].num_htlcs,
|
|
||||||
ci->cstate->side[OURS].num_htlcs,
|
|
||||||
ci->cstate->num_nondust);
|
|
||||||
log_add_struct(peer->log, " (txid %s)", struct sha256_double, &ci->txid);
|
log_add_struct(peer->log, " (txid %s)", struct sha256_double, &ci->txid);
|
||||||
|
|
||||||
/* BOLT #2:
|
/* BOLT #2:
|
||||||
|
@ -1933,24 +1918,14 @@ static void forget_uncommitted_changes(struct peer *peer)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
log_debug(peer->log, "Forgetting uncommitted");
|
log_debug(peer->log, "Forgetting uncommitted");
|
||||||
log_debug(peer->log, "LOCAL: changing from (us) %u/%u and (them) %u/%u to %u/%u and %u/%u",
|
log_debug_struct(peer->log, "LOCAL: changing from %s",
|
||||||
peer->local.staging_cstate->side[OURS].pay_msat,
|
struct channel_state, peer->local.staging_cstate);
|
||||||
peer->local.staging_cstate->side[OURS].fee_msat,
|
log_add_struct(peer->log, " to %s",
|
||||||
peer->local.staging_cstate->side[THEIRS].pay_msat,
|
struct channel_state, peer->local.commit->cstate);
|
||||||
peer->local.staging_cstate->side[THEIRS].fee_msat,
|
log_debug_struct(peer->log, "REMOTE: changing from %s",
|
||||||
peer->local.commit->cstate->side[OURS].pay_msat,
|
struct channel_state, peer->remote.staging_cstate);
|
||||||
peer->local.commit->cstate->side[OURS].fee_msat,
|
log_add_struct(peer->log, " to %s",
|
||||||
peer->local.commit->cstate->side[THEIRS].pay_msat,
|
struct channel_state, peer->remote.commit->cstate);
|
||||||
peer->local.commit->cstate->side[THEIRS].fee_msat);
|
|
||||||
log_debug(peer->log, "REMOTE: changing from (us) %u/%u and (them) %u/%u to %u/%u and %u/%u",
|
|
||||||
peer->remote.staging_cstate->side[OURS].pay_msat,
|
|
||||||
peer->remote.staging_cstate->side[OURS].fee_msat,
|
|
||||||
peer->remote.staging_cstate->side[THEIRS].pay_msat,
|
|
||||||
peer->remote.staging_cstate->side[THEIRS].fee_msat,
|
|
||||||
peer->remote.commit->cstate->side[OURS].pay_msat,
|
|
||||||
peer->remote.commit->cstate->side[OURS].fee_msat,
|
|
||||||
peer->remote.commit->cstate->side[THEIRS].pay_msat,
|
|
||||||
peer->remote.commit->cstate->side[THEIRS].fee_msat);
|
|
||||||
|
|
||||||
tal_free(peer->local.staging_cstate);
|
tal_free(peer->local.staging_cstate);
|
||||||
tal_free(peer->remote.staging_cstate);
|
tal_free(peer->remote.staging_cstate);
|
||||||
|
@ -2249,14 +2224,11 @@ static void do_commit(struct peer *peer, struct command *jsoncmd)
|
||||||
bitcoin_txid(ci->tx, &ci->txid);
|
bitcoin_txid(ci->tx, &ci->txid);
|
||||||
|
|
||||||
if (!to_us_only) {
|
if (!to_us_only) {
|
||||||
log_debug(peer->log, "Signing tx %"PRIu64" for %u/%u msatoshis, %u/%u htlcs (%u non-dust)",
|
log_debug(peer->log, "Signing tx %"PRIu64, ci->commit_num);
|
||||||
ci->commit_num,
|
log_add_struct(peer->log, " for %s",
|
||||||
ci->cstate->side[OURS].pay_msat,
|
struct channel_state, ci->cstate);
|
||||||
ci->cstate->side[THEIRS].pay_msat,
|
log_add_struct(peer->log, " (txid %s)",
|
||||||
ci->cstate->side[OURS].num_htlcs,
|
struct sha256_double, &ci->txid);
|
||||||
ci->cstate->side[THEIRS].num_htlcs,
|
|
||||||
ci->cstate->num_nondust);
|
|
||||||
log_add_struct(peer->log, " (txid %s)", struct sha256_double, &ci->txid);
|
|
||||||
|
|
||||||
ci->sig = tal(ci, struct bitcoin_signature);
|
ci->sig = tal(ci, struct bitcoin_signature);
|
||||||
ci->sig->stype = SIGHASH_ALL;
|
ci->sig->stype = SIGHASH_ALL;
|
||||||
|
|
Loading…
Add table
Reference in a new issue