common: make chain_coin_mvt's outpoint member a non-pointer.
What changed, and why it matters
This commit is a straightforward internal code cleanup: it changes a data structure so that a transaction reference (outpoint) is stored directly inside the structure rather than as a separate pointer. The commit author states the pointer was always expected to be set anyway, and the change removes a misleading comment suggesting it could be absent. There is no indication this fixes a security bug or changes externally observable behavior in a risky way.
No security action required. Treat as normal code-quality refactor during review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch converts struct chain_coin_mvt’s outpoint member from const struct bitcoin_outpoint *outpoint to struct bitcoin_outpoint outpoint. It updates allocation, serialization (towire/fromwire), and JSON notification output to use the embedded value. A comment in lightningd/notification.c that claimed some chain ledger entries lack a UTXO is removed, and the JSON fields utxo_txid/vout are now always emitted. The change is presented as a correctness/cleanup refactor, not a security fix.
Changed components
common/coin_mvt.ccommon/coin_mvt.hlightningd/notification.cInspect captured patch +9 / −18
diff --git a/common/coin_mvt.c b/common/coin_mvt.c
index 98431b4f..e9a05910 100644
--- a/common/coin_mvt.c
+++ b/common/coin_mvt.c
@@ -1,6 +1,5 @@
#include "config.h"
#include <assert.h>
-#include <bitcoin/tx.h>
#include <ccan/bitops/bitops.h>
#include <ccan/ccan/cast/cast.h>
#include <ccan/tal/str/str.h>
@@ -180,7 +179,7 @@ static struct chain_coin_mvt *new_chain_coin_mvt(const tal_t *ctx,
set_mvt_account_id(&mvt->account, channel, account_name);
mvt->timestamp = timestamp;
mvt->tx_txid = tx_txid;
- mvt->outpoint = outpoint;
+ mvt->outpoint = *outpoint;
mvt->originating_acct = NULL;
/* Most chain event's don't have a peer (only channel_opens) */
@@ -484,7 +483,7 @@ void towire_chain_coin_mvt(u8 **pptr, const struct chain_coin_mvt *mvt)
towire_wirestring(pptr, mvt->account.alt_account);
assert(!mvt->originating_acct);
- towire_bitcoin_outpoint(pptr, mvt->outpoint);
+ towire_bitcoin_outpoint(pptr, &mvt->outpoint);
if (mvt->tx_txid) {
towire_bool(pptr, true);
@@ -518,11 +517,7 @@ void fromwire_chain_coin_mvt(const u8 **cursor, size_t *max, struct chain_coin_m
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
- = tal(mvt, struct bitcoin_outpoint);
- fromwire_bitcoin_outpoint(cursor, max, outpoint);
- mvt->outpoint = outpoint;
+ fromwire_bitcoin_outpoint(cursor, max, &mvt->outpoint);
if (fromwire_bool(cursor, max)) {
mvt->tx_txid = tal(mvt, struct bitcoin_txid);
diff --git a/common/coin_mvt.h b/common/coin_mvt.h
index 7f29b1b6..3fffe61a 100644
--- a/common/coin_mvt.h
+++ b/common/coin_mvt.h
@@ -2,6 +2,7 @@
#define LIGHTNING_COMMON_COIN_MVT_H
#include "config.h"
+#include <bitcoin/tx.h>
#include <common/amount.h>
#include <common/channel_id.h>
#include <common/utils.h>
@@ -87,9 +88,9 @@ struct chain_coin_mvt {
struct amount_msat credit;
struct amount_msat debit;
u64 timestamp;
+ struct bitcoin_outpoint outpoint;
const struct bitcoin_txid *tx_txid;
- const struct bitcoin_outpoint *outpoint;
/* The id of the peer we have this channel with.
* Only on our channel_open events */
diff --git a/lightningd/notification.c b/lightningd/notification.c
index d01d28be..2c95ca4d 100644
--- a/lightningd/notification.c
+++ b/lightningd/notification.c
@@ -501,15 +501,10 @@ static void chain_movement_notification_serialize(struct json_stream *stream,
json_add_string(stream, "txid",
fmt_bitcoin_txid(tmpctx,
chain_mvt->tx_txid));
- /* some chain ledger entries aren't associated with a utxo
- * e.g. journal updates (due to penalty/state loss) and
- * chain_fee entries */
- if (chain_mvt->outpoint) {
- json_add_string(stream, "utxo_txid",
- fmt_bitcoin_txid(tmpctx,
- &chain_mvt->outpoint->txid));
- json_add_u32(stream, "vout", chain_mvt->outpoint->n);
- }
+ json_add_string(stream, "utxo_txid",
+ fmt_bitcoin_txid(tmpctx,
+ &chain_mvt->outpoint.txid));
+ json_add_u32(stream, "vout", chain_mvt->outpoint.n);
/* on-chain htlcs include a payment hash */
if (chain_mvt->payment_hash)
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.