common/coin_mvt: make more fields const, reorder fields.
What changed, and why it matters
This is a routine code cleanup in Core Lightning's internal accounting structures. It reorders struct fields for consistency and marks two pointer fields as 'const' (read-only after creation). There is no functional change visible in the diff, and no security issue is indicated.
No action required. Treat as normal refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies common/coin_mvt.h and common/coin_mvt.c. In the header, it moves common fields (account, tags, credit, debit) to the top of channel_coin_mvt and chain_coin_mvt, and changes payment_hash and part_and_group pointers from mutable to const. The C file is updated to use temporary local variables when writing to newly allocated objects before assigning them to the const pointers. No logic, allocation sizes, parsing bounds, or control flow changes are present.
Changed components
common/coin_mvt.ccommon/coin_mvt.hInspect captured patch +21 / −23
diff --git a/common/coin_mvt.c b/common/coin_mvt.c
index da576926..078984c0 100644
--- a/common/coin_mvt.c
+++ b/common/coin_mvt.c
@@ -90,9 +90,11 @@ struct channel_coin_mvt *new_channel_coin_mvt(const tal_t *ctx,
assert(!group_id);
mvt->part_and_group = NULL;
} else {
- mvt->part_and_group = tal(mvt, struct channel_coin_mvt_id);
- mvt->part_and_group->part_id = *part_id;
- mvt->part_and_group->group_id = *group_id;
+ /* Temporary for non-const */
+ struct channel_coin_mvt_id *pg;
+ mvt->part_and_group = pg = tal(mvt, struct channel_coin_mvt_id);
+ pg->part_id = *part_id;
+ pg->group_id = *group_id;
}
mvt->tags = tal_dup_talarr(mvt, enum mvt_tag, tags);
@@ -478,8 +480,9 @@ void fromwire_chain_coin_mvt(const u8 **cursor, size_t *max, struct chain_coin_m
mvt->tx_txid = NULL;
if (fromwire_bool(cursor, max)) {
- mvt->payment_hash = tal(mvt, struct sha256);
- fromwire_sha256(cursor, max, mvt->payment_hash);
+ struct sha256 *ph;
+ mvt->payment_hash = ph = tal(mvt, struct sha256);
+ fromwire_sha256(cursor, max, ph);
} else
mvt->payment_hash = NULL;
mvt->blockheight = fromwire_u32(cursor, max);
diff --git a/common/coin_mvt.h b/common/coin_mvt.h
index f9a4a697..668c329d 100644
--- a/common/coin_mvt.h
+++ b/common/coin_mvt.h
@@ -56,22 +56,19 @@ struct mvt_account_id {
};
struct channel_coin_mvt {
- /* account_id */
+ /* Common fields */
struct mvt_account_id account;
+ enum mvt_tag *tags;
+ /* only one or the other */
+ struct amount_msat credit;
+ struct amount_msat debit;
/* identifier */
- struct sha256 *payment_hash;
+ const struct sha256 *payment_hash;
/* multi-part payments may share a payment hash,
* so we should also record part-id and group-id for them */
- struct channel_coin_mvt_id *part_and_group;
-
- /* label / tag array */
- enum mvt_tag *tags;
-
- /* only one or the other */
- struct amount_msat credit;
- struct amount_msat debit;
+ const struct channel_coin_mvt_id *part_and_group;
/* Fees collected (or paid) on this mvt */
struct amount_msat fees;
@@ -80,6 +77,11 @@ struct channel_coin_mvt {
struct chain_coin_mvt {
/* account_id */
struct mvt_account_id account;
+ enum mvt_tag *tags;
+ /* only one or the other */
+ struct amount_msat credit;
+ struct amount_msat debit;
+
const struct bitcoin_txid *tx_txid;
const struct bitcoin_outpoint *outpoint;
@@ -88,18 +90,11 @@ struct chain_coin_mvt {
const struct node_id *peer_id;
/* some on-chain movements have a payment hash */
- struct sha256 *payment_hash;
-
- /* label / tag array */
- enum mvt_tag *tags;
+ const struct sha256 *payment_hash;
/* block this transaction is confirmed in */
u32 blockheight;
- /* only one or the other */
- struct amount_msat credit;
- struct amount_msat debit;
-
/* total value of output (useful for tracking external outs) */
struct amount_sat output_val;
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.