splice: Add and improve logging
What changed, and why it matters
This commit only adds and improves log messages in Core Lightning's splicing code. It does not change any security logic, network behavior, or cryptographic checks. The changes help developers diagnose problems by printing more detailed error and debug messages.
No security action needed. Treat as normal diagnostic logging improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds status_debug/status_broken logging calls in channeld.c, full_channel.c, and improves error messages in common/splice_script.c. It also introduces a helper new_error_msg() to include formatted amounts in splice script errors. No functional logic, validation, or protocol handling is altered.
Changed components
channeld/channeld.cchanneld/full_channel.ccommon/splice_script.cInspect captured patch +91 / −13
diff --git a/channeld/channeld.c b/channeld/channeld.c
index bd256476..65831fba 100644
--- a/channeld/channeld.c
+++ b/channeld/channeld.c
@@ -987,6 +987,10 @@ static struct bitcoin_signature *calc_commitsigs(const tal_t *ctx,
const u8 *msg;
struct bitcoin_signature *htlc_sigs;
+ status_debug("calc_commitsigs(%p, %p, %p, %p, %p, %d, %p, %p)",
+ ctx, peer, txs, funding_wscript, htlc_map,
+ (int)commit_index, remote_per_commit, commit_sig);
+
htlcs = collect_htlcs(tmpctx, htlc_map);
msg = towire_hsmd_sign_remote_commitment_tx(NULL, txs[0],
&remote_funding_pubkey,
@@ -3399,6 +3403,10 @@ static struct amount_sat check_balances(struct peer *peer,
"Unable to add HTLC balance");
}
+ status_debug("in[TX_INITIATOR] %s; in[TX_ACCEPTER] %s",
+ fmt_amount_m_as_sat(tmpctx, in[TX_INITIATOR]),
+ fmt_amount_m_as_sat(tmpctx, in[TX_ACCEPTER]));
+
for (size_t i = 0; i < psbt->num_inputs; i++)
if (i != chan_input_index)
add_amount_to_side(peer, in,
@@ -3452,6 +3460,11 @@ static struct amount_sat check_balances(struct peer *peer,
" %"PRIu64,
fmt_amount_msat(tmpctx, funding_amount),
peer->splicing->opener_relative);
+
+ status_debug("out[TX_INITIATOR] %s + %"PRId64,
+ fmt_amount_m_as_sat(tmpctx, out[TX_INITIATOR]),
+ peer->splicing->opener_relative);
+
if (!amount_msat_add_sat_s64(&out[TX_INITIATOR], out[TX_INITIATOR],
peer->splicing->opener_relative))
peer_failed_warn(peer->pps, &peer->channel_id,
@@ -3466,6 +3479,10 @@ static struct amount_sat check_balances(struct peer *peer,
peer_failed_warn(peer->pps, &peer->channel_id,
"Unable to add accepter funding to out amnt.");
+ status_debug("is in[TX_INITIATOR] %s less than out[TX_INITIATOR] %s?",
+ fmt_amount_m_as_sat(tmpctx, in[TX_INITIATOR]),
+ fmt_amount_m_as_sat(tmpctx, out[TX_INITIATOR]));
+
if (amount_msat_less(in[TX_INITIATOR], out[TX_INITIATOR])) {
msg = towire_channeld_splice_funding_error(NULL,
in[TX_INITIATOR],
diff --git a/channeld/full_channel.c b/channeld/full_channel.c
index c06663d6..b3690995 100644
--- a/channeld/full_channel.c
+++ b/channeld/full_channel.c
@@ -317,8 +317,10 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
&channel->basepoints[side],
&channel->basepoints[!side],
channel_has(channel, OPT_STATIC_REMOTEKEY),
- &keyset))
+ &keyset)) {
+ status_broken("channel_txs fails to derive keyset");
return NULL;
+ }
/* Figure out what @side will already be committed to. */
gather_htlcs(ctx, channel, side, &committed, NULL, NULL);
@@ -332,16 +334,53 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
side_pay = channel->view[side].owed[side];
other_side_pay = channel->view[side].owed[!side];
+ status_debug("channel->view[REMOTE].owed[REMOTE] %s;"
+ " channel->view[REMOTE].owed[LOCAL] %s;"
+ " channel->view[LOCAL].owed[REMOTE] %s;"
+ " channel->view[LOCAL].owed[LOCAL] %s;",
+ fmt_amount_m_as_sat(tmpctx,
+ channel->view[REMOTE].owed[REMOTE]),
+ fmt_amount_m_as_sat(tmpctx,
+ channel->view[REMOTE].owed[LOCAL]),
+ fmt_amount_m_as_sat(tmpctx,
+ channel->view[LOCAL].owed[REMOTE]),
+ fmt_amount_m_as_sat(tmpctx,
+ channel->view[LOCAL].owed[LOCAL]));
+
if (side == LOCAL) {
- if (!amount_msat_add_sat_s64(&side_pay, side_pay, splice_amnt))
+ if (!amount_msat_add_sat_s64(&side_pay, side_pay, splice_amnt)) {
+ status_broken("channel_txs fails to"
+ " amount_msat_add_sat_s64 %s + %"PRId64
+ " LOCAL (side_pay + splice_amnt)",
+ fmt_amount_m_as_sat(tmpctx, side_pay),
+ splice_amnt);
return NULL;
- if (!amount_msat_add_sat_s64(&other_side_pay, other_side_pay, remote_splice_amnt))
+ }
+ if (!amount_msat_add_sat_s64(&other_side_pay, other_side_pay, remote_splice_amnt)) {
+ status_broken("channel_txs fails to"
+ " amount_msat_add_sat_s64 %s + %"PRId64
+ " LOCAL (other_side_pay + remote_splice_amnt)",
+ fmt_amount_m_as_sat(tmpctx, other_side_pay),
+ remote_splice_amnt);
return NULL;
+ }
} else if (side == REMOTE) {
- if (!amount_msat_add_sat_s64(&side_pay, side_pay, remote_splice_amnt))
+ if (!amount_msat_add_sat_s64(&side_pay, side_pay, remote_splice_amnt)) {
+ status_broken("channel_txs fails to"
+ " amount_msat_add_sat_s64 %s + %"PRId64
+ " REMOTE (side_pay + remote_splice_amnt)",
+ fmt_amount_m_as_sat(tmpctx, side_pay),
+ remote_splice_amnt);
return NULL;
- if (!amount_msat_add_sat_s64(&other_side_pay, other_side_pay, splice_amnt))
+ }
+ if (!amount_msat_add_sat_s64(&other_side_pay, other_side_pay, splice_amnt)){
+ status_broken("channel_txs fails to"
+ " amount_msat_add_sat_s64 %s + %"PRId64
+ " REMOTE (other_side_pay + splice_amnt)",
+ fmt_amount_m_as_sat(tmpctx, other_side_pay),
+ splice_amnt);
return NULL;
+ }
}
txs = tal_arr(ctx, struct bitcoin_tx *, 1);
diff --git a/common/splice_script.c b/common/splice_script.c
index b5af2a74..209f5b0b 100644
--- a/common/splice_script.c
+++ b/common/splice_script.c
@@ -278,6 +278,19 @@ static struct splice_script_error *new_error(const tal_t *ctx,
return new_error_offset(ctx, type, token, phase, 0);
}
+static struct splice_script_error *new_error_msg(const tal_t *ctx,
+ enum splice_script_error_type type,
+ struct token *token,
+ const char *phase,
+ char *msg)
+{
+ struct splice_script_error *error = new_error(ctx, type, token, phase);
+
+ tal_append_fmt(&error->message, "%s", msg);
+
+ return error;
+}
+
static char *context_snippet(const tal_t *ctx,
const char *script,
struct splice_script_error *error)
@@ -2341,10 +2354,15 @@ static struct splice_script_error *calculate_amounts(const tal_t *ctx,
/* Do we know precisely how much we're getting? */
if (!right_wilds && !right_used_ppm) {
/* Then we can give sat amount errors */
- if (amount_sat_greater(left_total, right_total))
- return new_error(ctx, INSUFFICENT_FUNDS,
- left_wildcard_token ?: input[0],
- "calculate_amounts");
+ if (amount_sat_greater(left_total, right_total)) {
+ return new_error_msg(ctx, INSUFFICENT_FUNDS,
+ left_wildcard_token ?: input[0],
+ "calculate_amounts",
+ tal_fmt(tmpctx, "required: %s,"
+ " provided: %s",
+ fmt_amount_sat(tmpctx, left_total),
+ fmt_amount_sat(tmpctx, right_total)));
+ }
if (left_used_ppm && amount_sat_eq(left_total, right_total))
return new_error(ctx, PERCENT_IS_ZERO,
left_percent_token ?: input[0],
@@ -2759,11 +2777,13 @@ char *splice_to_string(const tal_t *ctx,
result->feerate_per_kw);
if (!amount_sat_is_zero(result->in_sat))
- tal_append_fmt(&str, "%sput %s%s into ", into_prefix,
+ tal_append_fmt(&str, "%sput %s%s %s ", into_prefix,
fmt_amount_sat(ctx, result->in_sat),
- fee_str);
+ fee_str,
+ result->in_ppm ? "and" : "into");
if (result->in_ppm)
- tal_append_fmt(&str, "%sput %s%s of rest into ", into_prefix,
+ tal_append_fmt(&str, "%s%s%s%s of rest into ", into_prefix,
+ amount_sat_is_zero(result->in_sat) ? "put " : "",
ppm_to_str(ctx, result->in_ppm),
fee_str);
@@ -2789,7 +2809,9 @@ char *splice_to_string(const tal_t *ctx,
fmt_amount_sat(ctx, result->out_sat),
fee_str);
if (result->out_ppm)
- tal_append_fmt(&str, " withdraw %s%s",
+ tal_append_fmt(&str, " %s %s%s",
+ amount_sat_is_zero(result->out_sat)
+ ? "withdraw" : "and",
ppm_to_str(ctx, result->out_ppm),
fee_str);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.