db: helper for binding/reading bitcoin_outpoint.
What changed, and why it matters
This commit adds two small helper functions for storing and retrieving Bitcoin transaction outpoints (a transaction ID plus an output number) in the database. It is purely a code-cleanup/refactoring change: it introduces no new behavior, no bug fixes, and no security-sensitive logic. The helpers simply serialize/deserialize a standard data structure in the same way other nearby helpers already do for txids and channel IDs.
No action required. This is a benign refactoring/helper addition.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch adds db_bind_outpoint() and db_col_outpoint() to db/bindings.c/h. db_bind_outpoint() concatenates the 32-byte txid with a big-endian 32-bit vout and binds the resulting 36-byte blob. db_col_outpoint() reads a 36-byte blob, splits it back into txid and vout, and asserts the column length is exactly 36 bytes. There is no change to callers, no SQL schema change, no memory-management bug, no integer overflow, and no cryptographic operation. The assert prevents reading malformed column data.
Changed components
db/bindings.cdb/bindings.hInspect captured patch +23 / −0
diff --git a/db/bindings.c b/db/bindings.c
index 63a22458..ceb251f3 100644
--- a/db/bindings.c
+++ b/db/bindings.c
@@ -140,6 +140,15 @@ void db_bind_txid(struct db_stmt *stmt, const struct bitcoin_txid *t)
db_bind_sha256d(stmt, &t->shad);
}
+void db_bind_outpoint(struct db_stmt *stmt, const struct bitcoin_outpoint *o)
+{
+ u8 *ser = tal_arr(stmt, u8, sizeof(o->txid.shad.sha.u.u8) + sizeof(be32));
+ be32 be_vout = cpu_to_be32(o->n);
+ memcpy(ser, o->txid.shad.sha.u.u8, sizeof(o->txid.shad.sha.u.u8));
+ memcpy(ser + sizeof(o->txid.shad.sha.u.u8), &be_vout, sizeof(be32));
+ db_bind_blob(stmt, ser, tal_bytelen(ser));
+}
+
void db_bind_channel_id(struct db_stmt *stmt, const struct channel_id *id)
{
db_bind_blob(stmt, id->id, sizeof(id->id));
@@ -618,6 +627,18 @@ void db_col_txid(struct db_stmt *stmt, const char *colname, struct bitcoin_txid
db_col_sha256d(stmt, colname, &t->shad);
}
+void db_col_outpoint(struct db_stmt *stmt, const char *colname, struct bitcoin_outpoint *o)
+{
+ be32 be_vout;
+ size_t col = db_query_colnum(stmt, colname);
+ const u8 *raw;
+ assert(db_column_bytes(stmt, col) == sizeof(o->txid.shad.sha.u.u8) + sizeof(be32));
+ raw = db_column_blob(stmt, col);
+ memcpy(o->txid.shad.sha.u.u8, raw, sizeof(o->txid.shad.sha.u.u8));
+ memcpy(&be_vout, raw + sizeof(o->txid.shad.sha.u.u8), sizeof(be_vout));
+ o->n = be32_to_cpu(be_vout);
+}
+
struct onionreply *db_col_onionreply(const tal_t *ctx,
struct db_stmt *stmt, const char *colname)
{
diff --git a/db/bindings.h b/db/bindings.h
index 910b07a3..d6b02fcf 100644
--- a/db/bindings.h
+++ b/db/bindings.h
@@ -30,6 +30,7 @@ void db_bind_sha256d(struct db_stmt *stmt, const struct sha256_double *s);
void db_bind_secret(struct db_stmt *stmt, const struct secret *s);
void db_bind_secret_arr(struct db_stmt *stmt, const struct secret *s);
void db_bind_txid(struct db_stmt *stmt, const struct bitcoin_txid *t);
+void db_bind_outpoint(struct db_stmt *stmt, const struct bitcoin_outpoint *o);
void db_bind_channel_id(struct db_stmt *stmt, const struct channel_id *id);
void db_bind_channel_type(struct db_stmt *stmt, const struct channel_type *type);
void db_bind_node_id(struct db_stmt *stmt, const struct node_id *ni);
@@ -100,6 +101,7 @@ struct timeabs db_col_timeabs(struct db_stmt *stmt, const char *colname);
struct bitcoin_tx *db_col_tx(const tal_t *ctx, struct db_stmt *stmt, const char *colname);
struct wally_psbt *db_col_psbt(const tal_t *ctx, struct db_stmt *stmt, const char *colname);
struct bitcoin_tx *db_col_psbt_to_tx(const tal_t *ctx, struct db_stmt *stmt, const char *colname);
+void db_col_outpoint(struct db_stmt *stmt, const char *colname, struct bitcoin_outpoint *o);
struct onionreply *db_col_onionreply(const tal_t *ctx,
struct db_stmt *stmt, const char *colname);
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.