common/coin_mvt: add struct mvt_account_id to separate channels from others.
What changed, and why it matters
This commit is a code-quality refactor in Core Lightning's internal accounting system. It replaces formatted channel ID strings with direct pointers to channel objects, and introduces a small helper structure that can hold either a channel pointer or an alternative account name. The change removes unnecessary string formatting and lookups, and updates the wire serialization format for on-chain coin movement records. There is no indication of a security vulnerability being fixed or introduced.
No security action required. Treat as normal code maintenance. Reviewers may want to confirm that the new wire format change is backward-compatible for the onchaind/lightningd interface, and that the empty-string sentinel for 'this channel' is handled consistently.
Security signals we found
Refactor only: no security-relevant logic changes observed
Wire format change for chain coin movements (account_name now always sent as wirestring, originating_acct removed from wire)
Assertions added in constructors and wire send path
No bounds checks, memory allocations, or cryptographic operations changed in a security-sensitive way
Evidence from the diff
The patch introduces struct mvt_account_id in common/coin_mvt.h, which holds either a const struct channel *channel or a const char *alt_account. It adds set_mvt_account_id() and new_mvt_account_id() constructors, and updates channel_coin_mvt and chain_coin_mvt to use this union-like structure instead of struct channel_id or formatted account-name strings. Callers in lightningd/channel_control.c, lightningd/coin_mvts.c, lightningd/notification.c, lightningd/onchain_control.c, onchaind/onchaind.c, and wallet/walletrpc.c are updated to pass channel pointers where available. The wire encoding in towire_chain_coin_mvt/fromwire_chain_coin_mvt now always writes/reads alt_account as a wirestring and asserts originating_acct is NULL on send; on receive it reconstructs the account ID from the string. On the lightningd side, an empty alt_account string from onchaind is reinterpreted as the channel itself, while a non-empty string sets the channel as the originating account. Several test stubs are updated for the new function signatures.
Changed components
common/coin_mvt.ccommon/coin_mvt.hlightningd/channel_control.clightningd/coin_mvts.clightningd/notification.clightningd/onchain_control.conchaind/onchaind.cwallet/walletrpc.cInspect captured patch +127 / −95
diff --git a/common/coin_mvt.c b/common/coin_mvt.c
index 22b642a5..da576926 100644
--- a/common/coin_mvt.c
+++ b/common/coin_mvt.c
@@ -48,8 +48,32 @@ enum mvt_tag *new_tag_arr(const tal_t *ctx, enum mvt_tag tag)
return tags;
}
+void set_mvt_account_id(struct mvt_account_id *acct_id,
+ const struct channel *channel,
+ const char *account_name TAKES)
+{
+ if (channel) {
+ assert(account_name == NULL);
+ acct_id->channel = channel;
+ acct_id->alt_account = NULL;
+ } else {
+ assert(account_name != NULL);
+ acct_id->channel = NULL;
+ acct_id->alt_account = tal_strdup(acct_id, account_name);
+ }
+}
+
+struct mvt_account_id *new_mvt_account_id(const tal_t *ctx,
+ const struct channel *channel,
+ const char *account_name TAKES)
+{
+ struct mvt_account_id *acct = tal(ctx, struct mvt_account_id);
+ set_mvt_account_id(acct, channel, account_name);
+ return acct;
+}
+
struct channel_coin_mvt *new_channel_coin_mvt(const tal_t *ctx,
- const struct channel_id *cid,
+ const struct channel *channel,
const struct sha256 *payment_hash TAKES,
const u64 *part_id,
const u64 *group_id,
@@ -60,7 +84,7 @@ struct channel_coin_mvt *new_channel_coin_mvt(const tal_t *ctx,
{
struct channel_coin_mvt *mvt = tal(ctx, struct channel_coin_mvt);
- mvt->chan_id = *cid;
+ set_mvt_account_id(&mvt->account, channel, NULL);
mvt->payment_hash = tal_dup_or_null(mvt, struct sha256, payment_hash);
if (!part_id) {
assert(!group_id);
@@ -89,6 +113,7 @@ struct channel_coin_mvt *new_channel_coin_mvt(const tal_t *ctx,
}
static struct chain_coin_mvt *new_chain_coin_mvt(const tal_t *ctx,
+ const struct channel *channel,
const char *account_name TAKES,
const struct bitcoin_txid *tx_txid,
const struct bitcoin_outpoint *outpoint,
@@ -102,7 +127,7 @@ static struct chain_coin_mvt *new_chain_coin_mvt(const tal_t *ctx,
{
struct chain_coin_mvt *mvt = tal(ctx, struct chain_coin_mvt);
- mvt->account_name = tal_strdup_or_null(mvt, account_name);
+ set_mvt_account_id(&mvt->account, channel, account_name);
mvt->tx_txid = tx_txid;
mvt->outpoint = outpoint;
mvt->originating_acct = NULL;
@@ -134,7 +159,8 @@ static struct chain_coin_mvt *new_chain_coin_mvt(const tal_t *ctx,
}
static struct chain_coin_mvt *new_chain_coin_mvt_sat(const tal_t *ctx,
- const char *account_name,
+ const struct channel *channel,
+ const char *account_name TAKES,
const struct bitcoin_txid *tx_txid,
const struct bitcoin_outpoint *outpoint,
const struct sha256 *payment_hash TAKES,
@@ -148,7 +174,7 @@ static struct chain_coin_mvt *new_chain_coin_mvt_sat(const tal_t *ctx,
ok = amount_sat_to_msat(&amt_msat, amt_sat);
assert(ok);
- return new_chain_coin_mvt(ctx, account_name, tx_txid,
+ return new_chain_coin_mvt(ctx, channel, account_name, tx_txid,
outpoint, payment_hash,
blockheight, tags, direction, amt_msat,
/* All amounts that are sat are
@@ -163,7 +189,7 @@ struct chain_coin_mvt *new_onchaind_withdraw(const tal_t *ctx,
struct amount_sat amount,
enum mvt_tag tag)
{
- return new_chain_coin_mvt_sat(ctx, NULL, spend_txid,
+ return new_chain_coin_mvt_sat(ctx, NULL, "", spend_txid,
outpoint, NULL,
blockheight,
take(new_tag_arr(NULL, tag)),
@@ -176,7 +202,7 @@ struct chain_coin_mvt *new_onchaind_deposit(const tal_t *ctx,
struct amount_sat amount,
enum mvt_tag tag)
{
- return new_chain_coin_mvt_sat(ctx, NULL, NULL,
+ return new_chain_coin_mvt_sat(ctx, NULL, "", NULL,
outpoint, NULL,
blockheight,
take(new_tag_arr(NULL, tag)),
@@ -184,7 +210,8 @@ struct chain_coin_mvt *new_onchaind_deposit(const tal_t *ctx,
}
struct chain_coin_mvt *new_coin_channel_close(const tal_t *ctx,
- const struct channel_id *chan_id,
+ const struct channel *channel,
+ const char *alt_account,
const struct bitcoin_txid *txid,
const struct bitcoin_outpoint *out,
u32 blockheight,
@@ -199,20 +226,17 @@ struct chain_coin_mvt *new_coin_channel_close(const tal_t *ctx,
if (is_splice)
tal_arr_expand(&tags, SPLICE);
- mvt = new_chain_coin_mvt(ctx, NULL, txid,
+ mvt = new_chain_coin_mvt(ctx, channel, alt_account, txid,
out, NULL, blockheight,
take(tags),
COIN_DEBIT, amount,
output_val,
output_count);
- if (chan_id)
- mvt->account_name = fmt_channel_id(mvt, chan_id);
-
return mvt;
}
struct chain_coin_mvt *new_coin_channel_open_proposed(const tal_t *ctx,
- const struct channel_id *chan_id,
+ const struct channel *channel,
const struct bitcoin_outpoint *out,
const struct node_id *peer_id,
const struct amount_msat amount,
@@ -222,10 +246,9 @@ struct chain_coin_mvt *new_coin_channel_open_proposed(const tal_t *ctx,
{
struct chain_coin_mvt *mvt;
- mvt = new_chain_coin_mvt(ctx, NULL, NULL, out, NULL, 0,
+ mvt = new_chain_coin_mvt(ctx, channel, NULL, NULL, out, NULL, 0,
take(new_tag_arr(NULL, CHANNEL_PROPOSED)),
COIN_CREDIT, amount, output_val, 0);
- mvt->account_name = fmt_channel_id(mvt, chan_id);
mvt->peer_id = tal_dup(mvt, struct node_id, peer_id);
/* If we're the opener, add to the tag list */
@@ -239,7 +262,7 @@ struct chain_coin_mvt *new_coin_channel_open_proposed(const tal_t *ctx,
}
struct chain_coin_mvt *new_coin_channel_open(const tal_t *ctx,
- const struct channel_id *chan_id,
+ const struct channel *channel,
const struct bitcoin_outpoint *out,
const struct node_id *peer_id,
u32 blockheight,
@@ -250,11 +273,10 @@ struct chain_coin_mvt *new_coin_channel_open(const tal_t *ctx,
{
struct chain_coin_mvt *mvt;
- mvt = new_chain_coin_mvt(ctx, NULL, NULL, out, NULL, blockheight,
+ mvt = new_chain_coin_mvt(ctx, channel, NULL, NULL, out, NULL, blockheight,
take(new_tag_arr(NULL, CHANNEL_OPEN)),
COIN_CREDIT, amount,
output_val, 0);
- mvt->account_name = fmt_channel_id(mvt, chan_id);
mvt->peer_id = tal_dup(mvt, struct node_id, peer_id);
/* If we're the opener, add to the tag list */
@@ -273,7 +295,7 @@ struct chain_coin_mvt *new_onchain_htlc_deposit(const tal_t *ctx,
struct amount_sat amount,
const struct sha256 *payment_hash)
{
- return new_chain_coin_mvt_sat(ctx, NULL, NULL,
+ return new_chain_coin_mvt_sat(ctx, NULL, "", NULL,
outpoint, payment_hash,
blockheight,
take(new_tag_arr(NULL, HTLC_FULFILL)),
@@ -289,7 +311,7 @@ struct chain_coin_mvt *new_onchain_htlc_withdraw(const tal_t *ctx,
{
/* An onchain htlc fulfillment to peer is a *deposit* of
* that output into their (external) account */
- return new_chain_coin_mvt_sat(ctx, EXTERNAL, NULL,
+ return new_chain_coin_mvt_sat(ctx, NULL, EXTERNAL, NULL,
outpoint, payment_hash,
blockheight,
take(new_tag_arr(NULL, HTLC_FULFILL)),
@@ -303,7 +325,7 @@ struct chain_coin_mvt *new_coin_external_spend_tags(const tal_t *ctx,
struct amount_sat amount,
enum mvt_tag *tags TAKES)
{
- return new_chain_coin_mvt(ctx, EXTERNAL, txid,
+ return new_chain_coin_mvt(ctx, NULL, EXTERNAL, txid,
outpoint, NULL, blockheight,
take(tags),
COIN_CREDIT, AMOUNT_MSAT(0), amount, 0);
@@ -327,7 +349,7 @@ struct chain_coin_mvt *new_coin_external_deposit_tags(const tal_t *ctx,
struct amount_sat amount,
enum mvt_tag *tags TAKES)
{
- return new_chain_coin_mvt_sat(ctx, EXTERNAL, NULL, outpoint, NULL,
+ return new_chain_coin_mvt_sat(ctx, NULL, EXTERNAL, NULL, outpoint, NULL,
blockheight, take(tags),
COIN_CREDIT, amount);
}
@@ -339,14 +361,14 @@ struct chain_coin_mvt *new_coin_external_deposit(const tal_t *ctx,
struct amount_sat amount,
enum mvt_tag tag)
{
- return new_chain_coin_mvt_sat(ctx, EXTERNAL, NULL, outpoint, NULL,
+ return new_chain_coin_mvt_sat(ctx, NULL, EXTERNAL, NULL, outpoint, NULL,
blockheight, take(new_tag_arr(NULL, tag)),
COIN_CREDIT, amount);
}
bool chain_mvt_is_external(const struct chain_coin_mvt *mvt)
{
- return streq(mvt->account_name, EXTERNAL);
+ return mvt->account.alt_account && streq(mvt->account.alt_account, EXTERNAL);
}
struct chain_coin_mvt *new_coin_wallet_deposit(const tal_t *ctx,
@@ -355,7 +377,7 @@ struct chain_coin_mvt *new_coin_wallet_deposit(const tal_t *ctx,
struct amount_sat amount,
enum mvt_tag tag)
{
- return new_chain_coin_mvt_sat(ctx, WALLET, NULL,
+ return new_chain_coin_mvt_sat(ctx, NULL, WALLET, NULL,
outpoint, NULL,
blockheight, take(new_tag_arr(NULL, tag)),
COIN_CREDIT, amount);
@@ -367,7 +389,7 @@ struct chain_coin_mvt *new_coin_wallet_deposit_tagged(const tal_t *ctx,
struct amount_sat amount,
enum mvt_tag *tags TAKES)
{
- return new_chain_coin_mvt_sat(ctx, WALLET, NULL,
+ return new_chain_coin_mvt_sat(ctx, NULL, WALLET, NULL,
outpoint, NULL,
blockheight,
take(tags),
@@ -381,37 +403,30 @@ struct chain_coin_mvt *new_coin_wallet_withdraw(const tal_t *ctx,
struct amount_sat amount,
enum mvt_tag tag)
{
- return new_chain_coin_mvt_sat(ctx, WALLET, spend_txid,
+ return new_chain_coin_mvt_sat(ctx, NULL, WALLET, spend_txid,
outpoint, NULL,
blockheight, take(new_tag_arr(NULL, tag)),
COIN_DEBIT, amount);
}
struct channel_coin_mvt *new_coin_channel_push(const tal_t *ctx,
- const struct channel_id *cid,
+ const struct channel *channel,
enum coin_mvt_dir direction,
struct amount_msat amount,
enum mvt_tag tag)
{
- return new_channel_coin_mvt(ctx, cid, NULL,
+ return new_channel_coin_mvt(ctx, channel, NULL,
NULL, NULL, direction, amount,
take(new_tag_arr(NULL, tag)),
AMOUNT_MSAT(0));
}
+/* This is used solely by onchaind. It always uses alt_account, with "" meaning
+ * the channel itself. */
void towire_chain_coin_mvt(u8 **pptr, const struct chain_coin_mvt *mvt)
{
- if (mvt->account_name) {
- towire_bool(pptr, true);
- towire_wirestring(pptr, mvt->account_name);
- } else
- towire_bool(pptr, false);
-
- if (mvt->originating_acct) {
- towire_bool(pptr, true);
- towire_wirestring(pptr, mvt->originating_acct);
- } else
- towire_bool(pptr, false);
+ towire_wirestring(pptr, mvt->account.alt_account);
+ assert(!mvt->originating_acct);
towire_bitcoin_outpoint(pptr, mvt->outpoint);
@@ -446,15 +461,8 @@ void towire_chain_coin_mvt(u8 **pptr, const struct chain_coin_mvt *mvt)
void fromwire_chain_coin_mvt(const u8 **cursor, size_t *max, struct chain_coin_mvt *mvt)
{
- if (fromwire_bool(cursor, max)) {
- mvt->account_name = fromwire_wirestring(mvt, cursor, max);
- } else
- mvt->account_name = NULL;
-
- if (fromwire_bool(cursor, max)) {
- mvt->originating_acct = fromwire_wirestring(mvt, cursor, max);
- } else
- mvt->originating_acct = NULL;
+ set_mvt_account_id(&mvt->account, NULL, take(fromwire_wirestring(NULL, cursor, max)));
+ mvt->originating_acct = NULL;
/* Read into non-const version */
struct bitcoin_outpoint *outpoint
diff --git a/common/coin_mvt.h b/common/coin_mvt.h
index aa696844..f9a4a697 100644
--- a/common/coin_mvt.h
+++ b/common/coin_mvt.h
@@ -49,9 +49,15 @@ struct channel_coin_mvt_id {
u64 group_id;
};
+/* Only one of these is set. */
+struct mvt_account_id {
+ const struct channel *channel;
+ const char *alt_account;
+};
+
struct channel_coin_mvt {
/* account_id */
- struct channel_id chan_id;
+ struct mvt_account_id account;
/* identifier */
struct sha256 *payment_hash;
@@ -73,7 +79,7 @@ struct channel_coin_mvt {
struct chain_coin_mvt {
/* account_id */
- const char *account_name;
+ struct mvt_account_id account;
const struct bitcoin_txid *tx_txid;
const struct bitcoin_outpoint *outpoint;
@@ -99,7 +105,7 @@ struct chain_coin_mvt {
/* When we pay to external accounts, it's useful
* to track which internal account it originated from */
- const char *originating_acct;
+ const struct mvt_account_id *originating_acct;
/* Number of outputs in spending tx; used by the
* `channel_close` event */
@@ -108,9 +114,19 @@ struct chain_coin_mvt {
enum mvt_tag *new_tag_arr(const tal_t *ctx, enum mvt_tag tag);
+/* Useful constructor for mvt_account_id: exactly one of channel/account_name must be NULL */
+void set_mvt_account_id(struct mvt_account_id *acct_id,
+ const struct channel *channel,
+ const char *account_name TAKES);
+
+/* Allocating version */
+struct mvt_account_id *new_mvt_account_id(const tal_t *ctx,
+ const struct channel *channel,
+ const char *account_name TAKES);
+
/* Either part_id and group_id both NULL, or neither are */
struct channel_coin_mvt *new_channel_coin_mvt(const tal_t *ctx,
- const struct channel_id *cid,
+ const struct channel *channel,
const struct sha256 *payment_hash TAKES,
const u64 *part_id,
const u64 *group_id,
@@ -136,7 +152,8 @@ struct chain_coin_mvt *new_onchaind_deposit(const tal_t *ctx,
NON_NULL_ARGS(2);
struct chain_coin_mvt *new_coin_channel_close(const tal_t *ctx,
- const struct channel_id *chan_id,
+ const struct channel *channel,
+ const char *alt_account,
const struct bitcoin_txid *txid,
const struct bitcoin_outpoint *out,
u32 blockheight,
@@ -144,20 +161,20 @@ struct chain_coin_mvt *new_coin_channel_close(const tal_t *ctx,
const struct amount_sat output_val,
u32 output_count,
bool is_splice)
- NON_NULL_ARGS(3, 4);
+ NON_NULL_ARGS(4, 5);
struct chain_coin_mvt *new_coin_channel_open_proposed(const tal_t *ctx,
- const struct channel_id *chan_id,
+ const struct channel *channel,
const struct bitcoin_outpoint *out,
const struct node_id *peer_id,
const struct amount_msat amount,
const struct amount_sat output_val,
bool is_opener,
bool is_leased)
- NON_NULL_ARGS(2, 3);
+ NON_NULL_ARGS(2, 3, 4);
struct chain_coin_mvt *new_coin_channel_open(const tal_t *ctx,
- const struct channel_id *chan_id,
+ const struct channel *channel,
const struct bitcoin_outpoint *out,
const struct node_id *peer_id,
u32 blockheight,
@@ -165,7 +182,7 @@ struct chain_coin_mvt *new_coin_channel_open(const tal_t *ctx,
const struct amount_sat output_val,
bool is_opener,
bool is_leased)
- NON_NULL_ARGS(2, 3);
+ NON_NULL_ARGS(2, 3, 4);
struct chain_coin_mvt *new_onchain_htlc_deposit(const tal_t *ctx,
const struct bitcoin_outpoint *outpoint,
@@ -234,7 +251,7 @@ struct chain_coin_mvt *new_coin_external_deposit(const tal_t *ctx,
NON_NULL_ARGS(2);
struct channel_coin_mvt *new_coin_channel_push(const tal_t *ctx,
- const struct channel_id *cid,
+ const struct channel *channel,
enum coin_mvt_dir direction,
struct amount_msat amount,
enum mvt_tag tag)
diff --git a/common/test/run-route_blinding_test.c b/common/test/run-route_blinding_test.c
index 3358319d..799c540e 100644
--- a/common/test/run-route_blinding_test.c
+++ b/common/test/run-route_blinding_test.c
@@ -17,9 +17,6 @@
#include <stdio.h>
/* AUTOGENERATED MOCKS START */
-/* Generated stub for fmt_channel_id */
-char *fmt_channel_id(const tal_t *ctx UNNEEDED, const struct channel_id *channel_id UNNEEDED)
-{ fprintf(stderr, "fmt_channel_id called!\n"); abort(); }
/* Generated stub for fromwire_channel_id */
bool fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct channel_id *channel_id UNNEEDED)
diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c
index 22386574..e6ab5169 100644
--- a/lightningd/channel_control.c
+++ b/lightningd/channel_control.c
@@ -960,13 +960,15 @@ static void channel_record_splice(struct channel *channel,
struct amount_msat orig_our_msats,
struct amount_sat orig_funding_sats,
struct bitcoin_outpoint *funding,
- u32 blockheight, struct bitcoin_txid *txid, const struct channel_inflight *inflight)
+ u32 blockheight,
+ const struct bitcoin_txid *txid,
+ const struct channel_inflight *inflight)
{
struct chain_coin_mvt *mvt;
u32 output_count;
output_count = inflight->funding_psbt->num_outputs;
- mvt = new_coin_channel_close(tmpctx, &channel->cid,
+ mvt = new_coin_channel_close(tmpctx, channel, NULL,
txid,
funding,
blockheight,
@@ -1002,7 +1004,7 @@ void channel_record_open(struct channel *channel, u32 blockheight, bool record_p
/* If it's not in a block yet, send a proposal */
if (blockheight > 0)
mvt = new_coin_channel_open(tmpctx,
- &channel->cid,
+ channel,
&channel->funding,
&channel->peer->id,
blockheight,
@@ -1012,7 +1014,7 @@ void channel_record_open(struct channel *channel, u32 blockheight, bool record_p
is_leased);
else
mvt = new_coin_channel_open_proposed(tmpctx,
- &channel->cid,
+ channel,
&channel->funding,
&channel->peer->id,
start_balance,
@@ -1025,7 +1027,7 @@ void channel_record_open(struct channel *channel, u32 blockheight, bool record_p
/* If we pushed sats, *now* record them */
if (is_pushed && record_push)
notify_channel_mvt(channel->peer->ld,
- new_coin_channel_push(tmpctx, &channel->cid,
+ new_coin_channel_push(tmpctx, channel,
channel->opener == REMOTE ? COIN_CREDIT : COIN_DEBIT,
channel->push,
is_leased ? LEASE_FEE : PUSHED));
diff --git a/lightningd/coin_mvts.c b/lightningd/coin_mvts.c
index 26df00b5..c365a7bf 100644
--- a/lightningd/coin_mvts.c
+++ b/lightningd/coin_mvts.c
@@ -10,7 +10,7 @@ struct channel_coin_mvt *new_channel_mvt_invoice_hin(const tal_t *ctx,
const struct htlc_in *hin,
const struct channel *channel)
{
- return new_channel_coin_mvt(ctx, &channel->cid,
+ return new_channel_coin_mvt(ctx, channel,
&hin->payment_hash, NULL, NULL,
COIN_CREDIT, hin->msat,
new_tag_arr(ctx, INVOICE),
@@ -30,7 +30,7 @@ struct channel_coin_mvt *new_channel_mvt_routed_hin(const tal_t *ctx,
hin->payload->amt_to_forward))
return NULL;
- return new_channel_coin_mvt(ctx, &channel->cid,
+ return new_channel_coin_mvt(ctx, channel,
&hin->payment_hash, NULL, NULL,
COIN_CREDIT, hin->msat,
new_tag_arr(ctx, ROUTED),
@@ -41,7 +41,7 @@ struct channel_coin_mvt *new_channel_mvt_invoice_hout(const tal_t *ctx,
const struct htlc_out *hout,
const struct channel *channel)
{
- return new_channel_coin_mvt(ctx, &channel->cid,
+ return new_channel_coin_mvt(ctx, channel,
&hout->payment_hash,
&hout->partid,
&hout->groupid,
@@ -54,7 +54,7 @@ struct channel_coin_mvt *new_channel_mvt_routed_hout(const tal_t *ctx,
const struct htlc_out *hout,
const struct channel *channel)
{
- return new_channel_coin_mvt(ctx, &channel->cid,
+ return new_channel_coin_mvt(ctx, channel,
&hout->payment_hash, NULL, NULL,
COIN_DEBIT, hout->msat,
new_tag_arr(ctx, ROUTED),
diff --git a/lightningd/notification.c b/lightningd/notification.c
index 6368ec27..7bef9feb 100644
--- a/lightningd/notification.c
+++ b/lightningd/notification.c
@@ -445,6 +445,16 @@ void notify_sendpay_failure(struct lightningd *ld,
notify_send(ld, n);
}
+static void json_add_mvt_account_id(struct json_stream *stream,
+ const char *fieldname,
+ const struct mvt_account_id *account_id)
+{
+ if (account_id->channel)
+ json_add_channel_id(stream, fieldname, &account_id->channel->cid);
+ else
+ json_add_string(stream, fieldname, account_id->alt_account);
+}
+
static void chain_movement_notification_serialize(struct json_stream *stream,
struct lightningd *ld,
const struct chain_coin_mvt *chain_mvt)
@@ -454,10 +464,11 @@ static void chain_movement_notification_serialize(struct json_stream *stream,
json_add_node_id(stream, "node_id", &ld->our_nodeid);
if (chain_mvt->peer_id)
json_add_node_id(stream, "peer_id", chain_mvt->peer_id);
- json_add_string(stream, "account_id", chain_mvt->account_name);
+ json_add_mvt_account_id(stream, "account_id", &chain_mvt->account);
+
if (chain_mvt->originating_acct)
- json_add_string(stream, "originating_account",
- chain_mvt->originating_acct);
+ json_add_mvt_account_id(stream, "originating_account", chain_mvt->originating_acct);
+
/* some 'journal entries' don't have a txid */
if (chain_mvt->tx_txid)
json_add_string(stream, "txid",
@@ -501,7 +512,7 @@ static void channel_movement_notification_serialize(struct json_stream *stream,
json_add_num(stream, "version", COIN_MVT_VERSION);
json_add_string(stream, "type", "channel_mvt");
json_add_node_id(stream, "node_id", &ld->our_nodeid);
- json_add_channel_id(stream, "account_id", &chan_mvt->chan_id);
+ json_add_mvt_account_id(stream, "account_id", &chan_mvt->account);
/* push funding / leases don't have a payment_hash */
if (chan_mvt->payment_hash)
json_add_sha256(stream, "payment_hash", chan_mvt->payment_hash);
diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c
index b82ef73d..e7758ce5 100644
--- a/lightningd/onchain_control.c
+++ b/lightningd/onchain_control.c
@@ -346,13 +346,14 @@ static void handle_onchain_log_coin_move(struct channel *channel, const u8 *msg)
return;
}
- /* Any 'ignored' payments get registered to the wallet */
- if (!mvt->account_name)
- mvt->account_name = fmt_channel_id(mvt,
- &channel->cid);
- else
- mvt->originating_acct = fmt_channel_id(mvt,
- &channel->cid);
+ /* onchaind uses an empty string to mean "this channel" */
+ if (streq(mvt->account.alt_account, "")) {
+ tal_free(mvt->account.alt_account);
+ set_mvt_account_id(&mvt->account, channel, NULL);
+ } else {
+ mvt->originating_acct = new_mvt_account_id(mvt, channel, NULL);
+ }
+
notify_chain_mvt(channel->peer->ld, mvt);
tal_free(mvt);
}
@@ -578,8 +579,7 @@ static void onchain_add_utxo(struct channel *channel, const u8 *msg)
mvt = new_coin_wallet_deposit(msg, &outpoint, blockheight,
amount, DEPOSIT);
- mvt->originating_acct = fmt_channel_id(mvt,
- &channel->cid);
+ mvt->originating_acct = new_mvt_account_id(mvt, channel, NULL);
notify_chain_mvt(channel->peer->ld, mvt);
}
diff --git a/onchaind/onchaind.c b/onchaind/onchaind.c
index 5dcb1d26..21c42c79 100644
--- a/onchaind/onchaind.c
+++ b/onchaind/onchaind.c
@@ -3465,7 +3465,7 @@ int main(int argc, char *argv[])
FUNDING_OUTPUT, NULL, NULL, NULL);
/* Record funding output spent */
- send_coin_mvt(take(new_coin_channel_close(NULL, NULL, &tx->txid,
+ send_coin_mvt(take(new_coin_channel_close(NULL, NULL, "", &tx->txid,
&funding, tx_blockheight,
our_msat,
funding_sats,
diff --git a/onchaind/test/run-grind_feerate-bug.c b/onchaind/test/run-grind_feerate-bug.c
index 30a31b0b..ab686613 100644
--- a/onchaind/test/run-grind_feerate-bug.c
+++ b/onchaind/test/run-grind_feerate-bug.c
@@ -103,7 +103,8 @@ void memleak_status_broken(void *unused UNNEEDED, const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "memleak_status_broken called!\n"); abort(); }
/* Generated stub for new_coin_channel_close */
struct chain_coin_mvt *new_coin_channel_close(const tal_t *ctx UNNEEDED,
- const struct channel_id *chan_id UNNEEDED,
+ const struct channel *channel UNNEEDED,
+ const char *alt_account UNNEEDED,
const struct bitcoin_txid *txid UNNEEDED,
const struct bitcoin_outpoint *out UNNEEDED,
u32 blockheight UNNEEDED,
diff --git a/onchaind/test/run-grind_feerate.c b/onchaind/test/run-grind_feerate.c
index ac714fcd..cb944889 100644
--- a/onchaind/test/run-grind_feerate.c
+++ b/onchaind/test/run-grind_feerate.c
@@ -153,7 +153,8 @@ void memleak_status_broken(void *unused UNNEEDED, const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "memleak_status_broken called!\n"); abort(); }
/* Generated stub for new_coin_channel_close */
struct chain_coin_mvt *new_coin_channel_close(const tal_t *ctx UNNEEDED,
- const struct channel_id *chan_id UNNEEDED,
+ const struct channel *channel UNNEEDED,
+ const char *alt_account UNNEEDED,
const struct bitcoin_txid *txid UNNEEDED,
const struct bitcoin_outpoint *out UNNEEDED,
u32 blockheight UNNEEDED,
diff --git a/plugins/bkpr/test/run-bkpr_db.c b/plugins/bkpr/test/run-bkpr_db.c
index 13801dca..75505df5 100644
--- a/plugins/bkpr/test/run-bkpr_db.c
+++ b/plugins/bkpr/test/run-bkpr_db.c
@@ -51,9 +51,6 @@ bool deprecated_ok_(bool deprecated_apis UNNEEDED,
/* Generated stub for first_fee_state */
enum htlc_state first_fee_state(enum side opener UNNEEDED)
{ fprintf(stderr, "first_fee_state called!\n"); abort(); }
-/* Generated stub for fmt_channel_id */
-char *fmt_channel_id(const tal_t *ctx UNNEEDED, const struct channel_id *channel_id UNNEEDED)
-{ fprintf(stderr, "fmt_channel_id called!\n"); abort(); }
/* Generated stub for fmt_wireaddr_without_port */
char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED)
{ fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); }
diff --git a/plugins/bkpr/test/run-recorder.c b/plugins/bkpr/test/run-recorder.c
index a6efe59c..8a887f95 100644
--- a/plugins/bkpr/test/run-recorder.c
+++ b/plugins/bkpr/test/run-recorder.c
@@ -57,9 +57,6 @@ bool deprecated_ok_(bool deprecated_apis UNNEEDED,
/* Generated stub for first_fee_state */
enum htlc_state first_fee_state(enum side opener UNNEEDED)
{ fprintf(stderr, "first_fee_state called!\n"); abort(); }
-/* Generated stub for fmt_channel_id */
-char *fmt_channel_id(const tal_t *ctx UNNEEDED, const struct channel_id *channel_id UNNEEDED)
-{ fprintf(stderr, "fmt_channel_id called!\n"); abort(); }
/* Generated stub for fmt_wireaddr_without_port */
char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED)
{ fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); }
diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c
index a2ec3571..72636193 100644
--- a/wallet/walletrpc.c
+++ b/wallet/walletrpc.c
@@ -948,7 +948,8 @@ static void maybe_notify_new_external_send(struct lightningd *ld,
0, amount,
DEPOSIT);
- mvt->originating_acct = WALLET;
+ mvt->originating_acct = new_mvt_account_id(mvt, NULL, WALLET);
+
notify_chain_mvt(ld, mvt);
tal_free(mvt);
}
Why this scored 17/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.