diff --git a/bitcoin/short_channel_id.c b/bitcoin/short_channel_id.c index 634a3a12c..80e7d28a7 100644 --- a/bitcoin/short_channel_id.c +++ b/bitcoin/short_channel_id.c @@ -55,9 +55,9 @@ bool short_channel_id_from_str(const char *str, size_t strlen, char *fmt_short_channel_id(const tal_t *ctx, struct short_channel_id scid) { return tal_fmt(ctx, "%dx%dx%d", - short_channel_id_blocknum(&scid), - short_channel_id_txnum(&scid), - short_channel_id_outnum(&scid)); + short_channel_id_blocknum(scid), + short_channel_id_txnum(scid), + short_channel_id_outnum(scid)); } bool short_channel_id_dir_from_str(const char *str, size_t strlen, @@ -87,13 +87,15 @@ char *fmt_short_channel_id_dir(const tal_t *ctx, } void towire_short_channel_id(u8 **pptr, - const struct short_channel_id *short_channel_id) + struct short_channel_id short_channel_id) { - towire_u64(pptr, short_channel_id->u64); + towire_u64(pptr, short_channel_id.u64); } -void fromwire_short_channel_id(const u8 **cursor, size_t *max, - struct short_channel_id *short_channel_id) +struct short_channel_id fromwire_short_channel_id(const u8 **cursor, size_t *max) { - short_channel_id->u64 = fromwire_u64(cursor, max); + struct short_channel_id scid; + + scid.u64 = fromwire_u64(cursor, max); + return scid; } diff --git a/bitcoin/short_channel_id.h b/bitcoin/short_channel_id.h index d863ee369..46133e0d9 100644 --- a/bitcoin/short_channel_id.h +++ b/bitcoin/short_channel_id.h @@ -12,8 +12,12 @@ struct short_channel_id { u64 u64; }; -/* Define short_channel_id_eq (no padding) */ -STRUCTEQ_DEF(short_channel_id, 0, u64); + +static inline bool short_channel_id_eq(struct short_channel_id a, + struct short_channel_id b) +{ + return a.u64 == b.u64; +} /* BOLT #7: * @@ -32,32 +36,32 @@ struct short_channel_id_dir { int dir; }; -static inline u32 short_channel_id_blocknum(const struct short_channel_id *scid) +static inline u32 short_channel_id_blocknum(struct short_channel_id scid) { - return scid->u64 >> 40; + return scid.u64 >> 40; } -static inline bool is_stub_scid(const struct short_channel_id *scid) +static inline bool is_stub_scid(struct short_channel_id scid) { - return scid ? scid->u64 >> 40 == 1 && - ((scid->u64 >> 16) & 0x00FFFFFF) == 1 && - (scid->u64 & 0xFFFF) == 1 : false; + return scid.u64 >> 40 == 1 && + ((scid.u64 >> 16) & 0x00FFFFFF) == 1 && + (scid.u64 & 0xFFFF) == 1; } -static inline u32 short_channel_id_txnum(const struct short_channel_id *scid) +static inline u32 short_channel_id_txnum(struct short_channel_id scid) { - return (scid->u64 >> 16) & 0x00FFFFFF; + return (scid.u64 >> 16) & 0x00FFFFFF; } -static inline u16 short_channel_id_outnum(const struct short_channel_id *scid) +static inline u16 short_channel_id_outnum(struct short_channel_id scid) { - return scid->u64 & 0xFFFF; + return scid.u64 & 0xFFFF; } /* Subtly, at block N, depth is 1, hence the -1 here. eg. 103x1x0 is announceable * when height is 108. */ static inline bool -is_scid_depth_announceable(const struct short_channel_id *scid, +is_scid_depth_announceable(struct short_channel_id scid, unsigned int height) { return short_channel_id_blocknum(scid) + ANNOUNCE_MIN_DEPTH - 1 @@ -80,8 +84,7 @@ char *fmt_short_channel_id_dir(const tal_t *ctx, /* Marshal/unmarshal */ void towire_short_channel_id(u8 **pptr, - const struct short_channel_id *short_channel_id); -void fromwire_short_channel_id(const u8 **cursor, size_t *max, - struct short_channel_id *short_channel_id); + struct short_channel_id short_channel_id); +struct short_channel_id fromwire_short_channel_id(const u8 **cursor, size_t *max); #endif /* LIGHTNING_BITCOIN_SHORT_CHANNEL_ID_H */ diff --git a/channeld/channeld.c b/channeld/channeld.c index a2a49524a..4721b6ebb 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -440,8 +440,8 @@ static void check_mutual_splice_locked(struct peer *peer) || !peer->splice_state->locked_ready[REMOTE]) return; - if (short_channel_id_eq(&peer->short_channel_ids[LOCAL], - &peer->splice_state->short_channel_id)) + if (short_channel_id_eq(peer->short_channel_ids[LOCAL], + peer->splice_state->short_channel_id)) peer_failed_warn(peer->pps, &peer->channel_id, "Duplicate splice_locked events detected"); @@ -599,7 +599,7 @@ static void handle_peer_announcement_signatures(struct peer *peer, const u8 *msg wire_sync_write(MASTER_FD, take(towire_channeld_got_announcement(NULL, - &remote_scid, + remote_scid, &remote_node_sig, &remote_bitcoin_sig))); } diff --git a/common/bolt11.c b/common/bolt11.c index 53c692454..956af7ea8 100644 --- a/common/bolt11.c +++ b/common/bolt11.c @@ -450,7 +450,7 @@ static bool fromwire_route_info(const u8 **cursor, size_t *max, struct route_info *route_info) { fromwire_node_id(cursor, max, &route_info->pubkey); - fromwire_short_channel_id(cursor, max, &route_info->short_channel_id); + route_info->short_channel_id = fromwire_short_channel_id(cursor, max); route_info->fee_base_msat = fromwire_u32(cursor, max); route_info->fee_proportional_millionths = fromwire_u32(cursor, max); route_info->cltv_expiry_delta = fromwire_u16(cursor, max); @@ -460,7 +460,7 @@ static bool fromwire_route_info(const u8 **cursor, size_t *max, static void towire_route_info(u8 **pptr, const struct route_info *route_info) { towire_node_id(pptr, &route_info->pubkey); - towire_short_channel_id(pptr, &route_info->short_channel_id); + towire_short_channel_id(pptr, route_info->short_channel_id); towire_u32(pptr, route_info->fee_base_msat); towire_u32(pptr, route_info->fee_proportional_millionths); towire_u16(pptr, route_info->cltv_expiry_delta); diff --git a/common/bolt11_json.c b/common/bolt11_json.c index 8b5ad674c..c2e7f225d 100644 --- a/common/bolt11_json.c +++ b/common/bolt11_json.c @@ -80,7 +80,7 @@ void json_add_bolt11(struct json_stream *response, &b11->routes[i][n].pubkey); json_add_short_channel_id(response, "short_channel_id", - &b11->routes[i][n] + b11->routes[i][n] .short_channel_id); json_add_u64(response, "fee_base_msat", b11->routes[i][n].fee_base_msat); diff --git a/common/decode_array.c b/common/decode_array.c index 157eea48d..86119d4e5 100644 --- a/common/decode_array.c +++ b/common/decode_array.c @@ -52,7 +52,7 @@ struct short_channel_id *decode_short_ids(const tal_t *ctx, const u8 *encoded) scids = tal_arr(ctx, struct short_channel_id, 0); while (max) { struct short_channel_id scid; - fromwire_short_channel_id(&encoded, &max, &scid); + scid = fromwire_short_channel_id(&encoded, &max); tal_arr_expand(&scids, scid); } diff --git a/common/gossmap.c b/common/gossmap.c index 31a5a4d0f..4eef0426d 100644 --- a/common/gossmap.c +++ b/common/gossmap.c @@ -25,7 +25,7 @@ static bool chanidx_eq_id(const ptrint_t *pidx, struct short_channel_id scid) { struct short_channel_id pidxid = chanidx_id(pidx); - return short_channel_id_eq(&pidxid, &scid); + return short_channel_id_eq(pidxid, scid); } static size_t scid_hash(const struct short_channel_id scid) { @@ -785,10 +785,10 @@ static size_t insert_local_space(struct gossmap_localmods *localmods, } static struct localmod *find_localmod(struct gossmap_localmods *localmods, - const struct short_channel_id *scid) + struct short_channel_id scid) { for (size_t i = 0; i < tal_count(localmods->mods); i++) - if (short_channel_id_eq(&localmods->mods[i].scid, scid)) + if (short_channel_id_eq(localmods->mods[i].scid, scid)) return &localmods->mods[i]; return NULL; } @@ -796,7 +796,7 @@ static struct localmod *find_localmod(struct gossmap_localmods *localmods, bool gossmap_local_addchan(struct gossmap_localmods *localmods, const struct node_id *n1, const struct node_id *n2, - const struct short_channel_id *scid, + struct short_channel_id scid, const u8 *features) { be16 be16; @@ -818,7 +818,7 @@ bool gossmap_local_addchan(struct gossmap_localmods *localmods, if (node_id_cmp(n1, n2) > 0) return gossmap_local_addchan(localmods, n2, n1, scid, features); - mod.scid = *scid; + mod.scid = scid; mod.updates_set[0] = mod.updates_set[1] = false; /* We create fake local channel_announcement. */ @@ -848,7 +848,7 @@ bool gossmap_local_addchan(struct gossmap_localmods *localmods, off += 32; /* Set scid */ - be64 = be64_to_cpu(scid->u64); + be64 = be64_to_cpu(scid.u64); memcpy(localmods->local + off, &be64, sizeof(be64)); off += sizeof(be64); @@ -866,7 +866,7 @@ bool gossmap_local_addchan(struct gossmap_localmods *localmods, /* Insert a local-only channel_update. */ bool gossmap_local_updatechan(struct gossmap_localmods *localmods, - const struct short_channel_id *scid, + struct short_channel_id scid, struct amount_msat htlc_min, struct amount_msat htlc_max, u32 base_fee, @@ -884,7 +884,7 @@ bool gossmap_local_updatechan(struct gossmap_localmods *localmods, tal_resize(&localmods->mods, nmods + 1); mod = &localmods->mods[nmods]; - mod->scid = *scid; + mod->scid = scid; mod->updates_set[0] = mod->updates_set[1] = false; mod->local_off = 0xFFFFFFFF; } diff --git a/common/gossmap.h b/common/gossmap.h index 25f45c20c..c2a86b321 100644 --- a/common/gossmap.h +++ b/common/gossmap.h @@ -92,15 +92,15 @@ struct gossmap_localmods *gossmap_localmods_new(const tal_t *ctx); bool gossmap_local_addchan(struct gossmap_localmods *localmods, const struct node_id *n1, const struct node_id *n2, - const struct short_channel_id *scid, + struct short_channel_id scid, const u8 *features) - NON_NULL_ARGS(1,2,3,4); + NON_NULL_ARGS(1,2,3); /* Create a local-only channel_update: can apply to lcoal-only or * normal channels. Returns false if amounts don't fit in our * internal representation (implies channel unusable anyway). */ bool gossmap_local_updatechan(struct gossmap_localmods *localmods, - const struct short_channel_id *scid, + struct short_channel_id scid, struct amount_msat htlc_min, struct amount_msat htlc_max, u32 base_fee, diff --git a/common/gossmods_listpeerchannels.c b/common/gossmods_listpeerchannels.c index e725c0508..731c63ae7 100644 --- a/common/gossmods_listpeerchannels.c +++ b/common/gossmods_listpeerchannels.c @@ -20,9 +20,9 @@ void gossmod_add_localchan(struct gossmap_localmods *mods, void *cbarg UNUSED) { /* FIXME: features? */ - gossmap_local_addchan(mods, self, peer, &scidd->scid, NULL); + gossmap_local_addchan(mods, self, peer, scidd->scid, NULL); - gossmap_local_updatechan(mods, &scidd->scid, min, max, + gossmap_local_updatechan(mods, scidd->scid, min, max, fee_base.millisatoshis, /* Raw: gossmap */ fee_proportional, cltv_delta, diff --git a/common/json_stream.c b/common/json_stream.c index aa2c0dce2..f0667b37d 100644 --- a/common/json_stream.c +++ b/common/json_stream.c @@ -477,7 +477,7 @@ void json_add_outpoint(struct json_stream *result, const char *fieldname, void json_add_short_channel_id(struct json_stream *response, const char *fieldname, - const struct short_channel_id *scid) + struct short_channel_id scid) { json_add_str_fmt(response, fieldname, "%dx%dx%d", short_channel_id_blocknum(scid), diff --git a/common/json_stream.h b/common/json_stream.h index 950962ec2..b2963dfed 100644 --- a/common/json_stream.h +++ b/common/json_stream.h @@ -311,7 +311,7 @@ void json_add_outpoint(struct json_stream *result, const char *fieldname, /* '"fieldname" : "1234:5:6"' */ void json_add_short_channel_id(struct json_stream *response, const char *fieldname, - const struct short_channel_id *id); + struct short_channel_id id); /* JSON serialize a network address for a node */ void json_add_address(struct json_stream *response, const char *fieldname, diff --git a/common/test/run-bolt11.c b/common/test/run-bolt11.c index e43d09707..553def5a5 100644 --- a/common/test/run-bolt11.c +++ b/common/test/run-bolt11.c @@ -94,8 +94,8 @@ static void test_b11(const char *b11str, *er = &expect_b11->routes[i][j]; assert(node_id_eq(&er->pubkey, &r->pubkey)); assert(er->cltv_expiry_delta == r->cltv_expiry_delta); - assert(short_channel_id_eq(&er->short_channel_id, - &r->short_channel_id)); + assert(short_channel_id_eq(er->short_channel_id, + r->short_channel_id)); assert(er->fee_base_msat == r->fee_base_msat); assert(er->fee_proportional_millionths == r->fee_proportional_millionths); diff --git a/common/test/run-bolt12_merkle.c b/common/test/run-bolt12_merkle.c index b5065b787..228da66d0 100644 --- a/common/test/run-bolt12_merkle.c +++ b/common/test/run-bolt12_merkle.c @@ -168,7 +168,7 @@ int main(int argc, char *argv[]) v = tal_arr(tmpctx, u8, 0); if (!mk_short_channel_id(&scid, 1, 2, 3)) abort(); - towire_short_channel_id(&v, &scid); + towire_short_channel_id(&v, scid); tlv2 = tlv(2, v, tal_bytelen(v)); node_id_from_hexstr("0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518", strlen("0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518"), &nid); diff --git a/common/test/run-gossmap_canned.c b/common/test/run-gossmap_canned.c index 4b3f77190..88c055839 100644 --- a/common/test/run-gossmap_canned.c +++ b/common/test/run-gossmap_canned.c @@ -275,7 +275,7 @@ static u8 canned_map[] = { }; static void check_cannounce(const u8 *cannounce, - const struct short_channel_id *scid, + struct short_channel_id scid, const struct node_id *n1, const struct node_id *n2) { @@ -293,7 +293,7 @@ static void check_cannounce(const u8 *cannounce, &actual_n1, &actual_n2, &k, &k)); - assert(short_channel_id_eq(&actual_scid, scid)); + assert(short_channel_id_eq(actual_scid, scid)); if (node_id_cmp(n1, n2) < 0) { assert(node_id_eq(&actual_n1, n1)); assert(node_id_eq(&actual_n2, n2)); @@ -376,6 +376,6 @@ int main(int argc, char *argv[]) cann = gossmap_chan_get_announce(tmpctx, map, gossmap_find_chan(map, &scid12)); - check_cannounce(cann, &scid12, &l1, &l2); + check_cannounce(cann, scid12, &l1, &l2); common_shutdown(); } diff --git a/common/test/run-gossmap_local.c b/common/test/run-gossmap_local.c index f1519b0eb..222b32ce3 100644 --- a/common/test/run-gossmap_local.c +++ b/common/test/run-gossmap_local.c @@ -275,7 +275,7 @@ static u8 canned_map[] = { }; static void check_cannounce(const u8 *cannounce, - const struct short_channel_id *scid, + struct short_channel_id scid, const struct node_id *n1, const struct node_id *n2) { @@ -293,7 +293,7 @@ static void check_cannounce(const u8 *cannounce, &actual_n1, &actual_n2, &k, &k)); - assert(short_channel_id_eq(&actual_scid, scid)); + assert(short_channel_id_eq(actual_scid, scid)); if (node_id_cmp(n1, n2) < 0) { assert(node_id_eq(&actual_n1, n1)); assert(node_id_eq(&actual_n2, n2)); @@ -443,10 +443,10 @@ int main(int argc, char *argv[]) cann = gossmap_chan_get_announce(tmpctx, map, gossmap_find_chan(map, &scid12)); - check_cannounce(cann, &scid12, &l1, &l2); + check_cannounce(cann, scid12, &l1, &l2); cann = gossmap_chan_get_announce(tmpctx, map, gossmap_find_chan(map, &scid23)); - check_cannounce(cann, &scid23, &l2, &l3); + check_cannounce(cann, scid23, &l2, &l3); nann = gossmap_node_get_announce(tmpctx, map, gossmap_find_node(map, &l1)); @@ -463,7 +463,7 @@ int main(int argc, char *argv[]) assert(node_id_from_hexstr("0382ce59ebf18be7d84677c2e35f23294b9992ceca95491fcf8a56c6cb2d9de199", 66, &l4)); assert(short_channel_id_from_str("111x1x1", 7, &scid_local)); - assert(gossmap_local_addchan(mods, &l1, &l4, &scid_local, NULL)); + assert(gossmap_local_addchan(mods, &l1, &l4, scid_local, NULL)); /* Apply changes, check they work. */ gossmap_apply_localmods(map, mods); @@ -481,15 +481,15 @@ int main(int argc, char *argv[]) assert(!gossmap_find_node(map, &l4)); /* Now update it both local, and an existing one. */ - gossmap_local_updatechan(mods, &scid_local, + gossmap_local_updatechan(mods, scid_local, AMOUNT_MSAT(1), AMOUNT_MSAT(100000), 2, 3, 4, true, 0); /* Adding an existing channel is a noop. */ - assert(gossmap_local_addchan(mods, &l2, &l3, &scid23, NULL)); + assert(gossmap_local_addchan(mods, &l2, &l3, scid23, NULL)); - gossmap_local_updatechan(mods, &scid23, + gossmap_local_updatechan(mods, scid23, AMOUNT_MSAT(99), AMOUNT_MSAT(100), 101, 102, 103, true, 0); diff --git a/common/test/run-route-infloop.c b/common/test/run-route-infloop.c index 601f8af13..a7bd9b1c9 100644 --- a/common/test/run-route-infloop.c +++ b/common/test/run-route-infloop.c @@ -140,7 +140,7 @@ int main(int argc, char *argv[]) if (!c->half[dir].enabled) continue; scid = gossmap_chan_scid(gossmap, c); - assert(gossmap_local_updatechan(localmods, &scid, + assert(gossmap_local_updatechan(localmods, scid, amount_msat(fp16_to_u64(c->half[dir].htlc_min)), amount_msat(fp16_to_u64(c->half[dir].htlc_max)), 0, 0, 0, true, dir)); diff --git a/common/test/run-route-specific.c b/common/test/run-route-specific.c index 4ab0f4248..3b9bed0cc 100644 --- a/common/test/run-route-specific.c +++ b/common/test/run-route-specific.c @@ -82,7 +82,7 @@ static void update_connection(int store_fd, msg = towire_channel_update(tmpctx, &dummy_sig, &chainparams->genesis_blockhash, - &scid, 0, + scid, 0, ROUTING_OPT_HTLC_MAX_MSAT, node_id_idx(from, to) + (disable ? ROUTING_FLAGS_DISABLED : 0), @@ -130,7 +130,7 @@ static void add_connection(int store_fd, &dummy_sig, &dummy_sig, /* features */ NULL, &chainparams->genesis_blockhash, - &scid, + scid, ids[0], ids[1], &dummy_key, &dummy_key); write_to_store(store_fd, msg); diff --git a/common/test/run-route.c b/common/test/run-route.c index f3479098f..01ce12679 100644 --- a/common/test/run-route.c +++ b/common/test/run-route.c @@ -73,7 +73,7 @@ static void update_connection(int store_fd, msg = towire_channel_update(tmpctx, &dummy_sig, &chainparams->genesis_blockhash, - &scid, 0, + scid, 0, ROUTING_OPT_HTLC_MAX_MSAT, node_id_idx(from, to) + (disable ? ROUTING_FLAGS_DISABLED : 0), @@ -119,7 +119,7 @@ static void add_connection(int store_fd, &dummy_sig, &dummy_sig, /* features */ NULL, &chainparams->genesis_blockhash, - &scid, + scid, ids[0], ids[1], &dummy_key, &dummy_key); write_to_store(store_fd, msg); diff --git a/db/bindings.c b/db/bindings.c index eac0df0e8..be1cf14a6 100644 --- a/db/bindings.c +++ b/db/bindings.c @@ -178,10 +178,9 @@ void db_bind_pubkey(struct db_stmt *stmt, const struct pubkey *pk) db_bind_blob(stmt, der, PUBKEY_CMPR_LEN); } -void db_bind_short_channel_id(struct db_stmt *stmt, - const struct short_channel_id *id) +void db_bind_short_channel_id(struct db_stmt *stmt, struct short_channel_id scid) { - db_bind_u64(stmt, id->u64); + db_bind_u64(stmt, scid.u64); } void db_bind_short_channel_id_arr(struct db_stmt *stmt, @@ -191,7 +190,7 @@ void db_bind_short_channel_id_arr(struct db_stmt *stmt, size_t num = tal_count(id); for (size_t i = 0; i < num; ++i) - towire_short_channel_id(&ser, &id[i]); + towire_short_channel_id(&ser, id[i]); db_bind_talarr(stmt, ser); } @@ -401,10 +400,11 @@ void db_col_pubkey(struct db_stmt *stmt, assert(ok); } -void db_col_short_channel_id(struct db_stmt *stmt, const char *colname, - struct short_channel_id *dest) +struct short_channel_id db_col_short_channel_id(struct db_stmt *stmt, const char *colname) { - dest->u64 = db_col_u64(stmt, colname); + struct short_channel_id scid; + scid.u64 = db_col_u64(stmt, colname); + return scid; } void *db_col_optional_(tal_t *dst, @@ -435,7 +435,7 @@ db_col_short_channel_id_arr(const tal_t *ctx, struct db_stmt *stmt, const char * while (len != 0) { struct short_channel_id scid; - fromwire_short_channel_id(&ser, &len, &scid); + scid = fromwire_short_channel_id(&ser, &len); tal_arr_expand(&ret, scid); } diff --git a/db/bindings.h b/db/bindings.h index f29fde99c..e78e45868 100644 --- a/db/bindings.h +++ b/db/bindings.h @@ -37,7 +37,7 @@ void db_bind_node_id_arr(struct db_stmt *stmt, const struct node_id *ids); void db_bind_pubkey(struct db_stmt *stmt, const struct pubkey *p); void db_bind_short_channel_id(struct db_stmt *stmt, - const struct short_channel_id *id); + struct short_channel_id scid); void db_bind_short_channel_id_arr(struct db_stmt *stmt, const struct short_channel_id *id); void db_bind_signature(struct db_stmt *stmt, @@ -91,8 +91,7 @@ struct node_id *db_col_node_id_arr(const tal_t *ctx, struct db_stmt *stmt, const char *colname); void db_col_pubkey(struct db_stmt *stmt, const char *colname, struct pubkey *p); -void db_col_short_channel_id(struct db_stmt *stmt, const char *colname, - struct short_channel_id *dest); +struct short_channel_id db_col_short_channel_id(struct db_stmt *stmt, const char *colname); struct short_channel_id * db_col_short_channel_id_arr(const tal_t *ctx, struct db_stmt *stmt, const char *colname); bool db_col_signature(struct db_stmt *stmt, const char *colname, diff --git a/devtools/create-gossipstore.c b/devtools/create-gossipstore.c index 45b61b09f..bcab2c4da 100644 --- a/devtools/create-gossipstore.c +++ b/devtools/create-gossipstore.c @@ -196,7 +196,7 @@ int main(int argc, char *argv[]) &pubkey, &pubkey)) errx(1, "bad channel_announcement"); - if (!short_channel_id_eq(&scid, &scidsats[scidi].scid)) + if (!short_channel_id_eq(scid, scidsats[scidi].scid)) errx(1, "scid of channel_announcement does not match scid in csv"); if (last_announce) errx(1, "Expected update before announce"); @@ -209,8 +209,8 @@ int main(int argc, char *argv[]) /* We assume update immediately follows announcement */ timestamp = get_update_timestamp(inmsg, &scid); if (last_announce) { - if (scidsats && !short_channel_id_eq(&scid, - &scidsats[scidi].scid)) + if (scidsats && !short_channel_id_eq(scid, + scidsats[scidi].scid)) errx(1, "scid of channel_update does not match scid in csv"); /* Now we have timestamp, write out announce */ diff --git a/devtools/mkencoded.c b/devtools/mkencoded.c index 76a2bc20a..368b66993 100644 --- a/devtools/mkencoded.c +++ b/devtools/mkencoded.c @@ -30,7 +30,7 @@ int main(int argc, char *argv[]) if (!short_channel_id_from_str(argv[i], strlen(argv[i]), &scid)) errx(1, "Invalid short_channel_id %s", argv[i]); - towire_short_channel_id(&data, &scid); + towire_short_channel_id(&data, scid); } } else { data = tal_hexdata(NULL, argv[2], strlen(argv[2])); diff --git a/devtools/mkgossip.c b/devtools/mkgossip.c index 63a92467d..374b91427 100644 --- a/devtools/mkgossip.c +++ b/devtools/mkgossip.c @@ -119,7 +119,7 @@ static u32 crc32_of_update(const u8 *channel_update) } static void print_update(const struct bitcoin_blkid *chainhash, - const struct short_channel_id *scid, + struct short_channel_id scid, const struct update_opts *opts, bool is_lesser_key, const struct privkey *privkey) @@ -147,7 +147,7 @@ static void print_update(const struct bitcoin_blkid *chainhash, printf("type=channel_update\n"); printf(" signature=%s\n", sig_notation(privkey, &hash, &sig)); printf(" chain_hash=%s\n", tal_hexstr(NULL, chainhash, sizeof(*chainhash))); - printf(" short_channel_id=%s\n", fmt_short_channel_id(NULL, *scid)); + printf(" short_channel_id=%s\n", fmt_short_channel_id(NULL, scid)); printf(" timestamp=%u\n", opts->timestamp); printf(" message_flags=%u\n", ROUTING_OPT_HTLC_MAX_MSAT); @@ -307,7 +307,7 @@ int main(int argc, char *argv[]) &bitcoinsig[lesser_key], &bitcoinsig[!lesser_key], features, &chainhash, - &scid, + scid, &nodeid[lesser_key], &nodeid[!lesser_key], &bitcoin[lesser_key], @@ -341,12 +341,12 @@ int main(int argc, char *argv[]) fmt_pubkey(NULL, &bitcoin[!lesser_key])); printf("\n#Node 1:\n"); - print_update(&chainhash, &scid, &opts[0], lesser_key == 0, + print_update(&chainhash, scid, &opts[0], lesser_key == 0, &node_privkey[0]); print_nannounce(&nodeid[0], &opts[0], &node_privkey[0]); printf("\n#Node 2:\n"); - print_update(&chainhash, &scid, &opts[1], lesser_key == 1, + print_update(&chainhash, scid, &opts[1], lesser_key == 1, &node_privkey[1]); print_nannounce(&nodeid[1], &opts[1], &node_privkey[1]); diff --git a/devtools/print_wire.c b/devtools/print_wire.c index 04b0b9a7e..ed28805ae 100644 --- a/devtools/print_wire.c +++ b/devtools/print_wire.c @@ -325,7 +325,7 @@ fail: return false; } -#define PRINTWIRE_TYPE_TO_STRING(T, N, ADDR) \ +#define PRINTWIRE_TYPE_TO_STRING(T, N) \ bool printwire_##N(const char *fieldname, const u8 **cursor, \ size_t *plen) \ { \ @@ -335,7 +335,7 @@ fail: printf("**TRUNCATED " stringify(N) "\n"); \ return false; \ } \ - const char *s = fmt_##N(NULL, ADDR v); \ + const char *s = fmt_##N(NULL, &v); \ printf("%s\n", s); \ tal_free(s); \ return true; \ @@ -357,9 +357,7 @@ fail: } #define PRINTWIRE_STRUCT_TYPE_TO_STRING(T) \ - PRINTWIRE_TYPE_TO_STRING(struct T, T, &) -#define PRINTWIRE_STRUCT_TYPE_TO_STRING_NOADDR_FMT(T) \ - PRINTWIRE_TYPE_TO_STRING(struct T, T, ) + PRINTWIRE_TYPE_TO_STRING(struct T, T) PRINTWIRE_STRUCT_TYPE_TO_STRING(bip340sig) PRINTWIRE_STRUCT_TYPE_TO_STRING(bitcoin_blkid) @@ -370,7 +368,7 @@ PRINTWIRE_STRUCT_TYPE_TO_STRING(preimage) PRINTWIRE_STRUCT_TYPE_TO_STRING(pubkey) PRINTWIRE_STRUCT_TYPE_TO_STRING(sha256) PRINTWIRE_STRUCT_TYPE_TO_STRING(secret) -PRINTWIRE_STRUCT_TYPE_TO_STRING_NOADDR_FMT(short_channel_id) +PRINTWIRE_ASSIGNABLE_STRUCT_TO_STRING(short_channel_id) PRINTWIRE_ASSIGNABLE_STRUCT_TO_STRING(amount_sat) PRINTWIRE_ASSIGNABLE_STRUCT_TO_STRING(amount_msat) -PRINTWIRE_TYPE_TO_STRING(secp256k1_ecdsa_signature, secp256k1_ecdsa_signature, &) +PRINTWIRE_TYPE_TO_STRING(secp256k1_ecdsa_signature, secp256k1_ecdsa_signature) diff --git a/gossipd/gossipd.c b/gossipd/gossipd.c index 08989fcef..d51219c31 100644 --- a/gossipd/gossipd.c +++ b/gossipd/gossipd.c @@ -464,8 +464,8 @@ static void new_blockheight(struct daemon *daemon, const u8 *msg) /* Check if we can now send any deferred queries. */ for (size_t i = 0; i < tal_count(daemon->deferred_txouts); i++) { - const struct short_channel_id *scid - = &daemon->deferred_txouts[i]; + const struct short_channel_id scid + = daemon->deferred_txouts[i]; if (!is_scid_depth_announceable(scid, daemon->current_blockheight)) diff --git a/gossipd/gossmap_manage.c b/gossipd/gossmap_manage.c index f410912a6..884acfb10 100644 --- a/gossipd/gossmap_manage.c +++ b/gossipd/gossmap_manage.c @@ -258,7 +258,7 @@ static void remove_channel(struct gossmap_manage *gm, /* Put in tombstone marker. */ gossip_store_add(gm->daemon->gs, - towire_gossip_store_delete_chan(tmpctx, &scid), + towire_gossip_store_delete_chan(tmpctx, scid), 0); /* Delete from store */ @@ -565,10 +565,10 @@ const char *gossmap_manage_channel_announcement(const tal_t *ctx, } /* Don't know blockheight yet, or not yet deep enough? Don't even ask */ - if (!is_scid_depth_announceable(&scid, blockheight)) { + if (!is_scid_depth_announceable(scid, blockheight)) { /* Don't expect to be more than 12 blocks behind! */ if (blockheight != 0 - && short_channel_id_blocknum(&scid) > blockheight + 12) { + && short_channel_id_blocknum(scid) > blockheight + 12) { return tal_fmt(ctx, "Bad gossip order: ignoring channel_announcement %s at blockheight %u", fmt_short_channel_id(tmpctx, scid), @@ -596,7 +596,7 @@ const char *gossmap_manage_channel_announcement(const tal_t *ctx, /* Ask lightningd about this scid: see * gossmap_manage_handle_get_txout_reply */ daemon_conn_send(gm->daemon->master, - take(towire_gossipd_get_txout(NULL, &scid))); + take(towire_gossipd_get_txout(NULL, scid))); return NULL; } @@ -1154,7 +1154,7 @@ void gossmap_manage_new_block(struct gossmap_manage *gm, u32 new_blockheight) scid.u64 = idx; /* Stop when we are at unreachable heights */ - if (!is_scid_depth_announceable(&scid, new_blockheight)) + if (!is_scid_depth_announceable(scid, new_blockheight)) break; map_del(&gm->early_ann_map, scid); @@ -1171,7 +1171,7 @@ void gossmap_manage_new_block(struct gossmap_manage *gm, u32 new_blockheight) /* Ask lightningd about this scid: see * gossmap_manage_handle_get_txout_reply */ daemon_conn_send(gm->daemon->master, - take(towire_gossipd_get_txout(NULL, &scid))); + take(towire_gossipd_get_txout(NULL, scid))); } for (size_t i = 0; i < tal_count(gm->dying_channels); i++) { @@ -1226,7 +1226,7 @@ void gossmap_manage_channel_spent(struct gossmap_manage *gm, fmt_short_channel_id(tmpctx, scid)); /* Save to gossip_store in case we restart */ - msg = towire_gossip_store_chan_dying(tmpctx, &cd.scid, cd.deadline); + msg = towire_gossip_store_chan_dying(tmpctx, cd.scid, cd.deadline); cd.gossmap_offset = gossip_store_add(gm->daemon->gs, msg, 0); tal_arr_expand(&gm->dying_channels, cd); @@ -1355,13 +1355,13 @@ void gossmap_manage_tell_lightningd_locals(struct daemon *daemon, if (cupdate) daemon_conn_send(daemon->master, take(towire_gossipd_init_cupdate(NULL, - &scid, + scid, cupdate))); cupdate = gossmap_chan_get_update(tmpctx, gossmap, chan, 1); if (cupdate) daemon_conn_send(daemon->master, take(towire_gossipd_init_cupdate(NULL, - &scid, + scid, cupdate))); } diff --git a/gossipd/queries.c b/gossipd/queries.c index 6c8ce1215..c33bb9670 100644 --- a/gossipd/queries.c +++ b/gossipd/queries.c @@ -37,7 +37,7 @@ static u8 *encoding_start(const tal_t *ctx, bool prepend_encoding) /* Marshal a single short_channel_id */ static void encoding_add_short_channel_id(u8 **encoded, - const struct short_channel_id *scid) + struct short_channel_id scid) { towire_short_channel_id(encoded, scid); } @@ -114,7 +114,7 @@ bool query_short_channel_ids(struct daemon *daemon, * ascending order. */ assert(i == 0 || scids[i].u64 > scids[i-1].u64); - encoding_add_short_channel_id(&encoded, &scids[i]); + encoding_add_short_channel_id(&encoded, scids[i]); } if (!encoding_end(encoded, max_encoded_bytes)) { @@ -290,7 +290,7 @@ static void send_reply_channel_range(struct peer *peer, /* Encode them all */ for (size_t i = 0; i < num_scids; i++) - encoding_add_short_channel_id(&encoded_scids, &scids[i]); + encoding_add_short_channel_id(&encoded_scids, scids[i]); encoding_end(encoded_scids, tal_bytelen(encoded_scids)); if (tstamps) { @@ -506,8 +506,8 @@ static struct short_channel_id *gather_range(const tal_t *ctx, } scid = gossmap_chan_scid(gossmap, chan); - if (short_channel_id_blocknum(&scid) < first_blocknum - || short_channel_id_blocknum(&scid) > end_block) { + if (short_channel_id_blocknum(scid) < first_blocknum + || short_channel_id_blocknum(scid) > end_block) { continue; } @@ -564,8 +564,8 @@ static void queue_channel_ranges(struct peer *peer, n = limit; /* ... and reduce to a block boundary. */ - while (short_channel_id_blocknum(&scids[off + n - 1]) - == short_channel_id_blocknum(&scids[off + limit])) { + while (short_channel_id_blocknum(scids[off + n - 1]) + == short_channel_id_blocknum(scids[off + limit])) { /* We assume one block doesn't have limit # * channels. If it does, we have to violate * spec and send over multiple blocks. */ @@ -573,7 +573,7 @@ static void queue_channel_ranges(struct peer *peer, status_broken("reply_channel_range: " "could not fit %zu scids for %u!", limit, - short_channel_id_blocknum(&scids[off + n - 1])); + short_channel_id_blocknum(scids[off + n - 1])); n = limit; break; } @@ -581,7 +581,7 @@ static void queue_channel_ranges(struct peer *peer, } /* Get *next* channel, add num blocks */ this_num_blocks - = short_channel_id_blocknum(&scids[off + n]) + = short_channel_id_blocknum(scids[off + n]) - first_blocknum; } else /* Last one must end with correct total */ diff --git a/gossipd/seeker.c b/gossipd/seeker.c index f23bc1268..f62d4a99f 100644 --- a/gossipd/seeker.c +++ b/gossipd/seeker.c @@ -488,7 +488,7 @@ static bool get_unannounced_nodes(const tal_t *ctx, /* Sort them into order, and remove duplicates! */ asort(*scids, num, cmp_scid, NULL); for (size_t i = 1; i < tal_count(*scids); i++) { - if (short_channel_id_eq(&(*scids)[i], &(*scids)[i-1])) { + if (short_channel_id_eq((*scids)[i], (*scids)[i-1])) { tal_arr_remove(scids, i); } } diff --git a/gossipd/test/run-check_channel_announcement.c b/gossipd/test/run-check_channel_announcement.c index 284d1d21b..902065c8b 100644 --- a/gossipd/test/run-check_channel_announcement.c +++ b/gossipd/test/run-check_channel_announcement.c @@ -104,7 +104,7 @@ int main(int argc, char *argv[]) &bitcoin_signature_2, NULL, &chain_hash, - &short_channel_id, + short_channel_id, &node_id_1, &node_id_2, &bitcoin_key_1, diff --git a/gossipd/test/run-extended-info.c b/gossipd/test/run-extended-info.c index 4b14e1080..7f8c8f6ab 100644 --- a/gossipd/test/run-extended-info.c +++ b/gossipd/test/run-extended-info.c @@ -243,7 +243,7 @@ static u8 *get_scid_array(const tal_t *ctx, json_for_each_arr(i, t, arr) { struct short_channel_id scid; assert(json_to_short_channel_id(test_vector, t, &scid)); - encoding_add_short_channel_id(&encoded, &scid); + encoding_add_short_channel_id(&encoded, scid); } assert(json_tok_streq(test_vector, encoding, "UNCOMPRESSED")); diff --git a/hsmd/libhsmd.c b/hsmd/libhsmd.c index 0c8f91ede..c90edc7e1 100644 --- a/hsmd/libhsmd.c +++ b/hsmd/libhsmd.c @@ -1151,7 +1151,7 @@ static u8 *handle_channel_update_sig(struct hsmd_client *c, const u8 *msg_in) sign_hash(&node_pkey, &hash, &sig); cu = towire_channel_update(tmpctx, &sig, &chain_hash, - &scid, timestamp, message_flags, channel_flags, + scid, timestamp, message_flags, channel_flags, cltv_expiry_delta, htlc_minimum, fee_base_msat, fee_proportional_mill, htlc_maximum); diff --git a/lightningd/channel.c b/lightningd/channel.c index eeeb08789..711546a2b 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -619,7 +619,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid, } /* scid is NULL when opening a new channel so we don't * need to set error in that case as well */ - if (is_stub_scid(scid)) + if (scid && is_stub_scid(*scid)) channel->error = towire_errorfmt(peer->ld, &channel->cid, "We can't be together anymore."); @@ -675,7 +675,7 @@ struct channel_inflight *channel_inflight_find(struct channel *channel, } struct channel *any_channel_by_scid(struct lightningd *ld, - const struct short_channel_id *scid, + struct short_channel_id scid, bool privacy_leak_ok) { struct peer *p; @@ -693,7 +693,7 @@ struct channel *any_channel_by_scid(struct lightningd *ld, * channel. */ if (chan->alias[LOCAL] && - short_channel_id_eq(scid, chan->alias[LOCAL])) + short_channel_id_eq(scid, *chan->alias[LOCAL])) return chan; /* BOLT #2: * - if `channel_type` has `option_scid_alias` set: @@ -704,7 +704,7 @@ struct channel *any_channel_by_scid(struct lightningd *ld, && channel_type_has(chan->type, OPT_SCID_ALIAS)) continue; if (chan->scid - && short_channel_id_eq(scid, chan->scid)) + && short_channel_id_eq(scid, *chan->scid)) return chan; } } @@ -768,24 +768,24 @@ struct channel *find_channel_by_id(const struct peer *peer, } struct channel *find_channel_by_scid(const struct peer *peer, - const struct short_channel_id *scid) + struct short_channel_id scid) { struct channel *c; list_for_each(&peer->channels, c, list) { - if (c->scid && short_channel_id_eq(c->scid, scid)) + if (c->scid && short_channel_id_eq(*c->scid, scid)) return c; } return NULL; } struct channel *find_channel_by_alias(const struct peer *peer, - const struct short_channel_id *alias, + struct short_channel_id alias, enum side side) { struct channel *c; list_for_each(&peer->channels, c, list) { - if (c->alias[side] && short_channel_id_eq(c->alias[side], alias)) + if (c->alias[side] && short_channel_id_eq(*c->alias[side], alias)) return c; } return NULL; @@ -901,7 +901,7 @@ void channel_fail_permanent(struct channel *channel, { /* Don't do anything if it's an stub channel because * peer has already closed it unilatelrally. */ - if (is_stub_scid(channel->scid)) + if (channel->scid && is_stub_scid(*channel->scid)) return; struct lightningd *ld = channel->peer->ld; @@ -1095,14 +1095,14 @@ bool channel_is_connected(const struct channel *channel) return channel->owner && channel->owner->talks_to_peer; } -const struct short_channel_id * +struct short_channel_id channel_scid_or_local_alias(const struct channel *chan) { assert(chan->scid != NULL || chan->alias[LOCAL] != NULL); if (chan->scid != NULL) - return chan->scid; + return *chan->scid; else - return chan->alias[LOCAL]; + return *chan->alias[LOCAL]; } const u8 *channel_update_for_error(const tal_t *ctx, diff --git a/lightningd/channel.h b/lightningd/channel.h index 979853293..69f8181f6 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -739,7 +739,7 @@ struct channel *channel_by_dbid(struct lightningd *ld, const u64 dbid); /* Includes both real scids and aliases. If !privacy_leak_ok, then private * channels' real scids are not included. */ struct channel *any_channel_by_scid(struct lightningd *ld, - const struct short_channel_id *scid, + struct short_channel_id scid, bool privacy_leak_ok); /* Get channel by channel_id */ @@ -752,11 +752,11 @@ struct channel *find_channel_by_id(const struct peer *peer, /* Find this channel within peer */ struct channel *find_channel_by_scid(const struct peer *peer, - const struct short_channel_id *scid); + struct short_channel_id scid); /* Find a channel by its alias, either local or remote. */ struct channel *find_channel_by_alias(const struct peer *peer, - const struct short_channel_id *alias, + struct short_channel_id alias, enum side side); /* Do we have any channel with option_anchors_zero_fee_htlc_tx? (i.e. we @@ -779,7 +779,7 @@ static inline bool channel_has(const struct channel *channel, int f) * don't have a scid yet, e.g., for `zeroconf` channels, so we resort * to referencing it by the local alias, which we have in that case. */ -const struct short_channel_id *channel_scid_or_local_alias(const struct channel *chan); +struct short_channel_id channel_scid_or_local_alias(const struct channel *chan); void get_channel_basepoints(struct lightningd *ld, const struct node_id *peer_id, diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index 088a18329..fe1981960 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -767,7 +767,7 @@ bool depthcb_update_scid(struct channel *channel, } /* No change? Great. */ - if (channel->scid && short_channel_id_eq(channel->scid, &scid)) + if (channel->scid && short_channel_id_eq(*channel->scid, scid)) return true; if (!channel->scid) { @@ -976,7 +976,7 @@ void lockin_has_completed(struct channel *channel, bool record_push) * is zero) */ channel_record_open(channel, channel->scid ? - short_channel_id_blocknum(channel->scid) : 0, + short_channel_id_blocknum(*channel->scid) : 0, record_push); } @@ -1695,7 +1695,7 @@ bool peer_start_channeld(struct channel *channel, htlcs, channel->scid != NULL, channel->remote_channel_ready, - &scid, + scid, reconnected, /* Anything that indicates we are or have * shut down */ @@ -1718,7 +1718,7 @@ bool peer_start_channeld(struct channel *channel, ld->experimental_upgrade_protocol, cast_const2(const struct inflight **, inflights), - channel->alias[LOCAL]); + *channel->alias[LOCAL]); /* We don't expect a response: we are triggered by funding_depth_cb. */ subd_send_msg(channel->owner, take(initmsg)); diff --git a/lightningd/channel_gossip.c b/lightningd/channel_gossip.c index 36d47b29d..4648d1ef3 100644 --- a/lightningd/channel_gossip.c +++ b/lightningd/channel_gossip.c @@ -89,7 +89,7 @@ static bool channel_announceable(const struct channel *channel, { if (!channel->scid) return false; - return is_scid_depth_announceable(channel->scid, block_height); + return is_scid_depth_announceable(*channel->scid, block_height); } static void check_channel_gossip(const struct channel *channel) @@ -123,7 +123,7 @@ static void check_channel_gossip(const struct channel *channel) assert(channel->scid); /* If we have sigs, they don't match */ if (cg->remote_sigs) - assert(!channel->scid || !short_channel_id_eq(&cg->remote_sigs->scid, channel->scid)); + assert(!channel->scid || !short_channel_id_eq(cg->remote_sigs->scid, *channel->scid)); assert(!cg->refresh_timer); return; case CGOSSIP_ANNOUNCED: @@ -242,7 +242,11 @@ static void send_private_cupdate(struct channel *channel, bool even_if_redundant { struct channel_gossip *cg = channel->channel_gossip; const u8 *cupdate; - const struct short_channel_id *scid; + struct short_channel_id scid; + + /* Only useful channels: not if closing */ + if (!channel_state_can_add_htlc(channel->state)) + return; /* BOLT #7: * @@ -256,13 +260,9 @@ static void send_private_cupdate(struct channel *channel, bool even_if_redundant /* We prefer their alias, if possible: they might not have seen the block which * mined the funding tx yet, so the scid would be meaningless to them. */ if (channel->alias[REMOTE]) - scid = channel->alias[REMOTE]; + scid = *channel->alias[REMOTE]; else - scid = channel->scid; - - /* Only useful channels: not if closing */ - if (!channel_state_can_add_htlc(channel->state)) - return; + scid = *channel->scid; /* We always set "enabled" on unannounced channels, since if peer * receives it, that's what it means */ @@ -328,7 +328,7 @@ static void broadcast_public_cupdate(struct channel *channel, enable = ok_if_disconnected; } - cupdate = unsigned_channel_update(tmpctx, channel, channel->scid, + cupdate = unsigned_channel_update(tmpctx, channel, *channel->scid, have_old ? &old_timestamp : NULL, true, enable); @@ -401,7 +401,7 @@ static bool apply_remote_sigs(struct channel *channel) if (!cg->remote_sigs) return false; - if (!short_channel_id_eq(&cg->remote_sigs->scid, channel->scid)) { + if (!short_channel_id_eq(cg->remote_sigs->scid, *channel->scid)) { log_debug(channel->log, "We have remote sigs, but wrong scid!"); return false; } @@ -462,7 +462,7 @@ static void send_channel_announce_sigs(struct channel *channel) } msg = towire_announcement_signatures(NULL, - &channel->cid, channel->scid, + &channel->cid, *channel->scid, &local_node_sig, &local_bitcoin_sig); msg_to_peer(channel, take(msg)); } @@ -720,8 +720,8 @@ void channel_gossip_scid_changed(struct channel *channel) /* Maybe remote announcement signatures now apply? If not, * free them */ if (cg->remote_sigs - && !short_channel_id_eq(&cg->remote_sigs->scid, - channel->scid)) { + && !short_channel_id_eq(cg->remote_sigs->scid, + *channel->scid)) { cg->remote_sigs = tal_free(cg->remote_sigs); } @@ -975,7 +975,7 @@ static struct channel *lookup_by_peer_remote_alias(struct lightningd *ld, list_for_each(&p->channels, chan, list) { if (chan->alias[REMOTE] - && short_channel_id_eq(&scid, chan->alias[REMOTE])) { + && short_channel_id_eq(scid, *chan->alias[REMOTE])) { return chan; } } @@ -992,7 +992,7 @@ void channel_gossip_set_remote_update(struct lightningd *ld, struct channel *channel; struct channel_gossip *cg; - channel = any_channel_by_scid(ld, &update->scid, true); + channel = any_channel_by_scid(ld, update->scid, true); if (!channel) { channel = lookup_by_peer_remote_alias(ld, source, update->scid); if (channel) diff --git a/lightningd/closed_channel.c b/lightningd/closed_channel.c index 11ae1133d..0c1df3870 100644 --- a/lightningd/closed_channel.c +++ b/lightningd/closed_channel.c @@ -20,15 +20,15 @@ static void json_add_closed_channel(struct json_stream *response, json_add_channel_id(response, "channel_id", &channel->cid); if (channel->scid) json_add_short_channel_id(response, "short_channel_id", - channel->scid); + *channel->scid); if (channel->alias[LOCAL] || channel->alias[REMOTE]) { json_object_start(response, "alias"); if (channel->alias[LOCAL]) json_add_short_channel_id(response, "local", - channel->alias[LOCAL]); + *channel->alias[LOCAL]); if (channel->alias[REMOTE]) json_add_short_channel_id(response, "remote", - channel->alias[REMOTE]); + *channel->alias[REMOTE]); json_object_end(response); } json_add_string(response, "opener", diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index 3a595f32f..58cd7dd27 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -1042,7 +1042,7 @@ static enum watch_result opening_depth_cb(struct lightningd *ld, TX_CHANNEL_FUNDING, inflight->channel->dbid); inflight->channel->scid = tal_dup(inflight->channel, struct short_channel_id, &scid); wallet_channel_save(ld->wallet, inflight->channel); - } else if (!short_channel_id_eq(inflight->channel->scid, &scid)) { + } else if (!short_channel_id_eq(*inflight->channel->scid, scid)) { /* We freaked out if required when original was * removed, so just update now */ log_info(inflight->channel->log, "Short channel id changed from %s->%s", @@ -1962,7 +1962,7 @@ static void handle_channel_locked(struct subd *dualopend, REASON_UNKNOWN, "Lockin complete"); channel_record_open(channel, - short_channel_id_blocknum(channel->scid), + short_channel_id_blocknum(*channel->scid), true); /* Empty out the inflights */ @@ -4005,7 +4005,7 @@ bool peer_start_dualopend(struct peer *peer, &channel->local_funding_pubkey, channel->minimum_depth, peer->ld->config.require_confirmed_inputs, - channel->alias[LOCAL], + *channel->alias[LOCAL], peer->ld->dev_any_channel_type); subd_send_msg(channel->owner, take(msg)); return true; @@ -4118,7 +4118,7 @@ bool peer_restart_dualopend(struct peer *peer, channel->type, channel->req_confirmed_ins[LOCAL], channel->req_confirmed_ins[REMOTE], - channel->alias[LOCAL]); + *channel->alias[LOCAL]); subd_send_msg(channel->owner, take(msg)); return true; diff --git a/lightningd/forwards.c b/lightningd/forwards.c index c06877928..071abc1ac 100644 --- a/lightningd/forwards.c +++ b/lightningd/forwards.c @@ -100,7 +100,7 @@ void json_add_forwarding_fields(struct json_stream *response, /* Only for forward_event */ if (payment_hash) json_add_sha256(response, "payment_hash", payment_hash); - json_add_short_channel_id(response, "in_channel", &cur->channel_in); + json_add_short_channel_id(response, "in_channel", cur->channel_in); #ifdef COMPAT_V0121 if (cur->htlc_id_in != HTLC_INVALID_ID) @@ -110,7 +110,7 @@ void json_add_forwarding_fields(struct json_stream *response, /* This can be unknown if we failed before channel lookup */ if (cur->channel_out.u64 != 0) { json_add_short_channel_id(response, "out_channel", - &cur->channel_out); + cur->channel_out); if (cur->htlc_id_out) json_add_u64(response, "out_htlc_id", *cur->htlc_id_out); } @@ -292,7 +292,7 @@ static struct command_result *json_delforward(struct command *cmd, #endif if (!wallet_forward_delete(cmd->ld->wallet, - chan_in, htlc_id, *status)) + *chan_in, htlc_id, *status)) return command_fail(cmd, DELFORWARD_NOT_FOUND, "Could not find that forward"); diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index b955fccb8..8b49ccf17 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -27,7 +27,7 @@ static void got_txout(struct bitcoind *bitcoind, const struct bitcoin_tx_output *output, - struct short_channel_id *scid) + struct short_channel_id scid) { const u8 *script; struct amount_sat sat; @@ -43,16 +43,19 @@ static void got_txout(struct bitcoind *bitcoind, subd_send_msg( bitcoind->ld->gossip, - towire_gossipd_get_txout_reply(scid, scid, sat, script)); - tal_free(scid); + take(towire_gossipd_get_txout_reply(NULL, scid, sat, script))); } static void got_filteredblock(struct bitcoind *bitcoind, - const struct filteredblock *fb, - struct short_channel_id *scid) + const struct filteredblock *fb, + struct short_channel_id *scidp) { struct filteredblock_outpoint *fbo = NULL, *o; struct bitcoin_tx_output txo; + struct short_channel_id scid = *scidp; + + /* Don't leak this! */ + tal_free(scidp); /* If we failed to the filtered block we report the failure to * got_txout. */ @@ -93,24 +96,24 @@ static void get_txout(struct subd *gossip, const u8 *msg) tal_hex(msg, msg)); /* FIXME: Block less than 6 deep? */ - blockheight = short_channel_id_blocknum(&scid); + blockheight = short_channel_id_blocknum(scid); - op = wallet_outpoint_for_scid(tmpctx, gossip->ld->wallet, &scid); + op = wallet_outpoint_for_scid(tmpctx, gossip->ld->wallet, scid); if (op) { subd_send_msg(gossip, take(towire_gossipd_get_txout_reply( - NULL, &scid, op->sat, op->scriptpubkey))); + NULL, scid, op->sat, op->scriptpubkey))); } else if (wallet_have_block(gossip->ld->wallet, blockheight)) { /* We should have known about this outpoint since its header * is in the DB. The fact that we don't means that this is * either a spent outpoint or an invalid one. Return a * failure. */ subd_send_msg(gossip, take(towire_gossipd_get_txout_reply( - NULL, &scid, AMOUNT_SAT(0), NULL))); + NULL, scid, AMOUNT_SAT(0), NULL))); } else { /* Make a pointer of a copy of scid here, for got_filteredblock */ bitcoind_getfilteredblock(topo->bitcoind, - short_channel_id_blocknum(&scid), + short_channel_id_blocknum(scid), got_filteredblock, tal_dup(gossip, struct short_channel_id, &scid)); } @@ -127,7 +130,7 @@ static void handle_init_cupdate(struct lightningd *ld, const u8 *msg) tal_hex(msg, msg)); } - channel = any_channel_by_scid(ld, &scid, true); + channel = any_channel_by_scid(ld, scid, true); if (!channel) { log_broken(ld->log, "init_cupdate for unknown scid %s", fmt_short_channel_id(tmpctx, scid)); diff --git a/lightningd/gossip_generation.c b/lightningd/gossip_generation.c index 0cbb78468..f16b220f6 100644 --- a/lightningd/gossip_generation.c +++ b/lightningd/gossip_generation.c @@ -34,7 +34,7 @@ static u8 *create_channel_announcement_dir(const tal_t *ctx, &bitcoin_signature[second], features, &chainparams->genesis_blockhash, - &scid, + scid, &node_id[first], &node_id[second], &funding_pubkey[first], @@ -80,7 +80,7 @@ u8 *create_channel_announcement(const tal_t *ctx, u8 *unsigned_channel_update(const tal_t *ctx, const struct channel *channel, - const struct short_channel_id *scid, + struct short_channel_id scid, const u32 *old_timestamp, bool forwardable, bool enabled) diff --git a/lightningd/gossip_generation.h b/lightningd/gossip_generation.h index 85d085924..64431bdc0 100644 --- a/lightningd/gossip_generation.h +++ b/lightningd/gossip_generation.h @@ -38,7 +38,7 @@ u8 *create_channel_announcement(const tal_t *ctx, */ u8 *unsigned_channel_update(const tal_t *ctx, const struct channel *channel, - const struct short_channel_id *scid, + struct short_channel_id scid, const u32 *old_timestamp, bool forwardable, bool enabled); diff --git a/lightningd/notification.c b/lightningd/notification.c index c08240339..132522a3c 100644 --- a/lightningd/notification.c +++ b/lightningd/notification.c @@ -269,7 +269,7 @@ static void channel_state_changed_notification_serialize(struct json_stream *str json_add_node_id(stream, "peer_id", peer_id); json_add_channel_id(stream, "channel_id", cid); if (scid) - json_add_short_channel_id(stream, "short_channel_id", scid); + json_add_short_channel_id(stream, "short_channel_id", *scid); else json_add_null(stream, "short_channel_id"); json_add_timeiso(stream, "timestamp", timestamp); @@ -318,7 +318,7 @@ static void forward_event_notification_serialize(struct json_stream *stream, * the the sender is using probably using the REMOTE * alias. The LOCAL one is controlled by us, and we keep it * stable. */ - cur->channel_in = *channel_scid_or_local_alias(in->key.channel); + cur->channel_in = channel_scid_or_local_alias(in->key.channel); cur->msat_in = in->msat; if (scid_out) { diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index 21313b622..a5e415e29 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -1574,7 +1574,7 @@ enum watch_result onchaind_funding_spent(struct channel *channel, /* This could be a mutual close, but it doesn't matter. * We don't need this for stub channels as well */ - if (!is_stub_scid(channel->scid)) + if (!channel->scid || !is_stub_scid(*channel->scid)) bitcoin_txid(channel->last_tx, &our_last_txid); else /* Dummy txid for stub channel to make valgrind happy. */ diff --git a/lightningd/pay.c b/lightningd/pay.c index 201d9cffc..e4e9a68a5 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -181,7 +181,7 @@ json_add_routefail_info(struct json_stream *js, json_add_node_id(js, "erring_node", erring_node); if (erring_channel != NULL) { - json_add_short_channel_id(js, "erring_channel", erring_channel); + json_add_short_channel_id(js, "erring_channel", *erring_channel); json_add_num(js, "erring_direction", channel_dir); } @@ -342,7 +342,7 @@ static struct routing_failure* immediate_routing_failure(const tal_t *ctx, const struct lightningd *ld, enum onion_wire failcode, - const struct short_channel_id *channel0, + struct short_channel_id channel0, const struct node_id *dstid) { struct routing_failure *routing_failure; @@ -355,7 +355,7 @@ immediate_routing_failure(const tal_t *ctx, routing_failure->erring_node = tal_dup(routing_failure, struct node_id, &ld->id); routing_failure->erring_channel = - tal_dup(routing_failure, struct short_channel_id, channel0); + tal_dup(routing_failure, struct short_channel_id, &channel0); routing_failure->channel_dir = node_id_idx(&ld->id, dstid); routing_failure->msg = NULL; @@ -797,11 +797,11 @@ static struct channel * find_channel_for_htlc_add(struct lightningd *ld, struct command *cmd, const struct node_id *node, - const struct short_channel_id *scid_or_alias, + struct short_channel_id scid_or_alias, const struct amount_msat *amount) { struct channel *channel; - const struct short_channel_id *scid; + struct short_channel_id scid; struct peer *peer = peer_by_id(ld, node); if (!peer) return NULL; @@ -818,7 +818,7 @@ find_channel_for_htlc_add(struct lightningd *ld, /* We used to ignore scid: now all-zero means "any" */ if (!channel - && (memeqzero(scid_or_alias, sizeof(*scid_or_alias)) + && (memeqzero(&scid_or_alias, sizeof(scid_or_alias)) || command_deprecated_in_ok(cmd, "channel.ignored", "v0.12", "v24.02"))) { @@ -831,7 +831,7 @@ find_channel_for_htlc_add(struct lightningd *ld, } log_debug(ld->log, "No channel found for selector %s (%s)", - fmt_short_channel_id(tmpctx, *scid_or_alias), + fmt_short_channel_id(tmpctx, scid_or_alias), fmt_amount_msat(tmpctx, *amount)); return NULL; @@ -839,9 +839,9 @@ found: scid = channel_scid_or_local_alias(channel); log_debug( ld->log, "Selected channel %s (%s) for selector %s (%s)", - fmt_short_channel_id(tmpctx, *scid), + fmt_short_channel_id(tmpctx, scid), fmt_amount_msat(tmpctx, channel->our_msat), - fmt_short_channel_id(tmpctx, *scid_or_alias), + fmt_short_channel_id(tmpctx, scid_or_alias), fmt_amount_msat(tmpctx, *amount)); return channel; @@ -1062,7 +1062,7 @@ send_payment_core(struct lightningd *ld, return ret; channel = find_channel_for_htlc_add(ld, cmd, &first_hop->node_id, - &first_hop->scid, &msat); + first_hop->scid, &msat); if (!channel) { struct json_stream *data = json_stream_fail(cmd, PAY_TRY_OTHER_ROUTE, diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 99d98990e..4bf96e660 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -894,7 +894,7 @@ static void json_add_channel(struct lightningd *ld, if (channel->scid) json_add_short_channel_id(response, "short_channel_id", - channel->scid); + *channel->scid); /* If there is any way we can use the channel we'd better have * a direction attached. Technically we could always add it, @@ -997,10 +997,10 @@ static void json_add_channel(struct lightningd *ld, json_object_start(response, "alias"); if (channel->alias[LOCAL]) json_add_short_channel_id(response, "local", - channel->alias[LOCAL]); + *channel->alias[LOCAL]); if (channel->alias[REMOTE]) json_add_short_channel_id(response, "remote", - channel->alias[REMOTE]); + *channel->alias[REMOTE]); json_object_end(response); } @@ -2027,7 +2027,7 @@ static enum watch_result funding_depth_cb(struct lightningd *ld, struct channel *channel) { /* This is stub channel, we don't activate anything! */ - if (is_stub_scid(channel->scid)) + if (channel->scid && is_stub_scid(*channel->scid)) return DELETE_WATCH; /* We only use this to watch the current funding tx */ @@ -2432,7 +2432,7 @@ command_find_channel(struct command *cmd, return command_fail_badparam(cmd, name, buffer, tok, "Channel id not found"); } else if (json_to_short_channel_id(buffer, tok, &scid)) { - *channel = any_channel_by_scid(ld, &scid, true); + *channel = any_channel_by_scid(ld, scid, true); if (!*channel) return command_fail_badparam(cmd, name, buffer, tok, "Short channel id not found"); @@ -3053,7 +3053,8 @@ static void set_channel_config(struct command *cmd, struct channel *channel, json_add_string(response, "channel_id", fmt_channel_id(tmpctx, &channel->cid)); if (channel->scid) - json_add_short_channel_id(response, "short_channel_id", channel->scid); + json_add_short_channel_id(response, "short_channel_id", + *channel->scid); json_add_amount_msat(response, "fee_base_msat", amount_msat(channel->feerate_base)); @@ -3382,7 +3383,7 @@ static struct command_result *json_dev_forget_channel(struct command *cmd, if (scid) { if (!channel->scid) continue; - if (!short_channel_id_eq(channel->scid, scid)) + if (!short_channel_id_eq(*channel->scid, *scid)) continue; } if (forget->channel) { diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 43b0b18b1..c7f7dc166 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -539,6 +539,7 @@ static void rcvd_htlc_reply(struct subd *subd, const u8 *msg, const int *fds UNU } else if (hout->in) { struct onionreply *failonion; + struct short_channel_id scid; failonion = create_onionreply(hout, hout->in->shared_secret, @@ -547,10 +548,11 @@ static void rcvd_htlc_reply(struct subd *subd, const u8 *msg, const int *fds UNU /* here we haven't called connect_htlc_out(), * so set htlc field with NULL (db wants it to exist!) */ + scid = channel_scid_or_local_alias(hout->key.channel); wallet_forwarded_payment_add(ld->wallet, hout->in, FORWARD_STYLE_TLV, - channel_scid_or_local_alias(hout->key.channel), NULL, + &scid, NULL, FORWARD_LOCAL_FAILED, fromwire_peektype(hout->failmsg)); } @@ -713,8 +715,12 @@ static void forward_htlc(struct htlc_in *hin, if (forward_to) { next = channel_by_cid(ld, forward_to); /* Update this to where we're actually trying to send. */ - if (next) - forward_scid = channel_scid_or_local_alias(next); + if (next) { + struct short_channel_id next_scid; + next_scid = channel_scid_or_local_alias(next); + forward_scid = tal_dup(tmpctx, struct short_channel_id, + &next_scid); + } } else next = NULL; @@ -1080,7 +1086,7 @@ static void htlc_accepted_hook_serialize(struct htlc_accepted_hook_payload *p, if (p->payload->forward_channel) json_add_short_channel_id(s, "short_channel_id", - p->payload->forward_channel); + *p->payload->forward_channel); if (p->payload->forward_node_id) json_add_pubkey(s, "next_node_id", p->payload->forward_node_id); @@ -1217,7 +1223,7 @@ static struct channel_id *calc_forwarding_channel(struct lightningd *ld, fmt_short_channel_id(tmpctx, *p->forward_channel), hp->hin->key.id); - c = any_channel_by_scid(ld, p->forward_channel, false); + c = any_channel_by_scid(ld, *p->forward_channel, false); if (!c) { log_unusual(hp->channel->log, "No peer channel with scid=%s", @@ -1256,7 +1262,7 @@ static struct channel_id *calc_forwarding_channel(struct lightningd *ld, log_debug(hp->channel->log, "Chose channel %s for peer %s", fmt_short_channel_id(tmpctx, - *channel_scid_or_local_alias(best)), + channel_scid_or_local_alias(best)), fmt_node_id(tmpctx, &peer->id)); } else if (best != c) { log_debug(hp->channel->log, @@ -1264,7 +1270,7 @@ static struct channel_id *calc_forwarding_channel(struct lightningd *ld, fmt_short_channel_id(tmpctx, *p->forward_channel), fmt_short_channel_id(tmpctx, - *channel_scid_or_local_alias(best))); + channel_scid_or_local_alias(best))); } log_debug(hp->channel->log, @@ -1272,7 +1278,7 @@ static struct channel_id *calc_forwarding_channel(struct lightningd *ld, " over channel with scid=%s with peer %s", hp->hin->key.id, fmt_short_channel_id(tmpctx, - *channel_scid_or_local_alias(best)), + channel_scid_or_local_alias(best)), fmt_node_id(tmpctx, &best->peer->id)); return tal_dup(hp, struct channel_id, &best->cid); @@ -1473,10 +1479,11 @@ static void fulfill_our_htlc_out(struct channel *channel, struct htlc_out *hout, log_unusual(channel->log, "FUNDS LOSS of %s: peer took funds onchain before we could time out the HTLC, but we abandoned incoming HTLC to save the incoming channel", fmt_amount_msat(tmpctx, hout->msat)); } else { + struct short_channel_id scid = channel_scid_or_local_alias(hout->key.channel); fulfill_htlc(hout->in, preimage); wallet_forwarded_payment_add(ld->wallet, hout->in, FORWARD_STYLE_TLV, - channel_scid_or_local_alias(hout->key.channel), hout, + &scid, hout, FORWARD_SETTLED, 0); } } @@ -1605,14 +1612,16 @@ static bool peer_failed_our_htlc(struct channel *channel, fromwire_peektype(hout->failmsg)); htlc_out_check(hout, __func__); - if (hout->in) + if (hout->in) { + struct short_channel_id scid = channel_scid_or_local_alias(channel); wallet_forwarded_payment_add(ld->wallet, hout->in, FORWARD_STYLE_TLV, - channel_scid_or_local_alias(channel), + &scid, hout, FORWARD_FAILED, hout->failmsg ? fromwire_peektype(hout->failmsg) : 0); + } return true; } @@ -1765,6 +1774,7 @@ void onchain_failed_our_htlc(const struct channel *channel, payment_failed(ld, hout, localfail); tal_free(localfail); } else if (hout->in) { + struct short_channel_id scid = channel_scid_or_local_alias(channel); log_debug(channel->log, "HTLC id %"PRIu64" has incoming", htlc->id); /* Careful! We might have already timed out incoming @@ -1777,7 +1787,7 @@ void onchain_failed_our_htlc(const struct channel *channel, } wallet_forwarded_payment_add(hout->key.channel->peer->ld->wallet, hout->in, FORWARD_STYLE_TLV, - channel_scid_or_local_alias(channel), hout, + &scid, hout, FORWARD_LOCAL_FAILED, hout->failmsg ? fromwire_peektype(hout->failmsg) @@ -1935,9 +1945,12 @@ static bool update_out_htlc(struct channel *channel, hout->msat); if (hout->in) { + struct short_channel_id scid; + scid = channel_scid_or_local_alias(channel); + wallet_forwarded_payment_add(ld->wallet, hout->in, FORWARD_STYLE_TLV, - channel_scid_or_local_alias(channel), hout, + &scid, hout, FORWARD_OFFERED, 0); } } @@ -2978,7 +2991,7 @@ static struct command_result *param_channel(struct command *cmd, "unknown channel"); return NULL; } else if (json_to_short_channel_id(buffer, tok, &scid)) { - *chan = any_channel_by_scid(cmd->ld, &scid, true); + *chan = any_channel_by_scid(cmd->ld, scid, true); if (!*chan) return command_fail_badparam(cmd, name, buffer, tok, "unknown channel"); @@ -3019,7 +3032,7 @@ static struct command_result *json_listhtlcs(struct command *cmd, &scid, &htlc_id, &cltv_expiry, &owner, &msat, &payment_hash, &hstate)) { json_object_start(response, NULL); - json_add_short_channel_id(response, "short_channel_id", &scid); + json_add_short_channel_id(response, "short_channel_id", scid); json_add_u64(response, "id", htlc_id); json_add_u32(response, "expiry", cltv_expiry); json_add_string(response, "direction", diff --git a/lightningd/routehint.c b/lightningd/routehint.c index 900480765..440f713d4 100644 --- a/lightningd/routehint.c +++ b/lightningd/routehint.c @@ -8,10 +8,10 @@ #include static bool scid_in_arr(const struct short_channel_id *scidarr, - const struct short_channel_id *scid) + struct short_channel_id scid) { for (size_t i = 0; i < tal_count(scidarr); i++) - if (short_channel_id_eq(&scidarr[i], scid)) + if (short_channel_id_eq(scidarr[i], scid)) return true; return false; @@ -93,7 +93,7 @@ routehint_candidates(const tal_t *ctx, } /* Note: listincoming returns real scid or local alias if no real scid. */ - candidate.c = any_channel_by_scid(ld, &r->short_channel_id, true); + candidate.c = any_channel_by_scid(ld, r->short_channel_id, true); if (!candidate.c) { log_debug(ld->log, "%s: channel not found in peer %s", fmt_short_channel_id(tmpctx, r->short_channel_id), @@ -147,9 +147,9 @@ routehint_candidates(const tal_t *ctx, if (hints) { log_debug(ld->log, "We have hints!"); /* Allow specification by alias, too */ - if (!scid_in_arr(hints, &r->short_channel_id) + if (!scid_in_arr(hints, r->short_channel_id) && (!candidate.c->alias[REMOTE] - || !scid_in_arr(hints, candidate.c->alias[REMOTE]))) { + || !scid_in_arr(hints, *candidate.c->alias[REMOTE]))) { log_debug(ld->log, "scid %s not in hints", fmt_short_channel_id(tmpctx, r->short_channel_id)); diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index fc5a115e8..48af20182 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -10,7 +10,7 @@ /* AUTOGENERATED MOCKS START */ /* Generated stub for any_channel_by_scid */ struct channel *any_channel_by_scid(struct lightningd *ld UNNEEDED, - const struct short_channel_id *scid UNNEEDED, + struct short_channel_id scid UNNEEDED, bool privacy_leak_ok UNNEEDED) { fprintf(stderr, "any_channel_by_scid called!\n"); abort(); } /* Generated stub for bip32_pubkey */ @@ -216,7 +216,7 @@ bool dev_disconnect_permanent(struct lightningd *ld UNNEEDED) /* Generated stub for encode_scriptpubkey_to_addr */ char *encode_scriptpubkey_to_addr(const tal_t *ctx UNNEEDED, const struct chainparams *chainparams UNNEEDED, - const u8 *scriptPubkey UNNEEDED) + const u8 *scriptpubkey UNNEEDED) { fprintf(stderr, "encode_scriptpubkey_to_addr called!\n"); abort(); } /* Generated stub for encrypt_tlv_encrypted_data */ u8 *encrypt_tlv_encrypted_data(const tal_t *ctx UNNEEDED, @@ -548,7 +548,7 @@ void json_add_sha256(struct json_stream *result UNNEEDED, const char *fieldname /* Generated stub for json_add_short_channel_id */ void json_add_short_channel_id(struct json_stream *response UNNEEDED, const char *fieldname UNNEEDED, - const struct short_channel_id *id UNNEEDED) + struct short_channel_id id UNNEEDED) { fprintf(stderr, "json_add_short_channel_id called!\n"); abort(); } /* Generated stub for json_add_string */ void json_add_string(struct json_stream *js UNNEEDED, diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index 9b6002365..855a2d262 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -357,7 +357,7 @@ static void channel_hints_update(struct payment *p, /* Try and look for an existing hint: */ for (size_t i=0; ichannel_hints); i++) { struct channel_hint *hint = &root->channel_hints[i]; - if (short_channel_id_eq(&hint->scid.scid, &scid) && + if (short_channel_id_eq(hint->scid.scid, scid) && hint->scid.dir == direction) { bool modified = false; /* Prefer to disable a channel. */ @@ -491,7 +491,7 @@ static struct channel_hint *payment_chanhints_get(struct payment *p, struct channel_hint *curhint; for (size_t j = 0; j < tal_count(root->channel_hints); j++) { curhint = &root->channel_hints[j]; - if (short_channel_id_eq(&curhint->scid.scid, &h->scid) && + if (short_channel_id_eq(curhint->scid.scid, h->scid) && curhint->scid.dir == h->direction) { return curhint; } @@ -639,11 +639,11 @@ static const struct node_id *payment_get_excluded_nodes(const tal_t *ctx, /* FIXME: This is slow! */ static const struct channel_hint *find_hint(const struct channel_hint *hints, - const struct short_channel_id *scid, + struct short_channel_id scid, int dir) { for (size_t i = 0; i < tal_count(hints); i++) { - if (short_channel_id_eq(scid, &hints[i].scid.scid) + if (short_channel_id_eq(scid, hints[i].scid.scid) && dir == hints[i].scid.dir) return &hints[i]; } @@ -687,7 +687,7 @@ static bool payment_route_check(const struct gossmap *gossmap, return false; scid = gossmap_chan_scid(gossmap, c); - hint = find_hint(payment_root(p)->channel_hints, &scid, dir); + hint = find_hint(payment_root(p)->channel_hints, scid, dir); if (!hint) return true; @@ -1640,7 +1640,7 @@ static struct command_result *payment_createonion_success(struct command *cmd, json_add_amount_msat(req->js, "amount_msat", first->amount); json_add_num(req->js, "delay", first->delay); json_add_node_id(req->js, "id", &first->node_id); - json_add_short_channel_id(req->js, "channel", &first->scid); + json_add_short_channel_id(req->js, "channel", first->scid); json_object_end(req->js); json_add_sha256(req->js, "payment_hash", p->payment_hash); @@ -1719,7 +1719,7 @@ static void payment_add_hop_onion_payload(struct payment *p, if (!final) tlvstream_set_short_channel_id(fields, TLV_PAYLOAD_SHORT_CHANNEL_ID, - &next->scid); + next->scid); if (payment_secret != NULL) { assert(final); @@ -2158,7 +2158,7 @@ static void payment_finished(struct payment *p) if (failure->erring_channel) json_add_short_channel_id( ret, "erring_channel", - failure->erring_channel); + *failure->erring_channel); if (failure->erring_direction) json_add_num( @@ -2635,7 +2635,7 @@ static bool routehint_excluded(struct payment *p, return true; for (size_t j = 0; j < tal_count(chans); j++) - if (short_channel_id_eq(&chans[j].scid, &r->short_channel_id)) + if (short_channel_id_eq(chans[j].scid, r->short_channel_id)) return true; /* Skip the capacity check if this is the last hop @@ -2664,7 +2664,7 @@ static bool routehint_excluded(struct payment *p, * channel, which is greater than the destination. */ for (size_t j = 0; j < tal_count(hints); j++) { - if (!short_channel_id_eq(&hints[j].scid.scid, &r->short_channel_id)) + if (!short_channel_id_eq(hints[j].scid.scid, r->short_channel_id)) continue; /* We exclude on equality because we set the estimate * to the smallest failed attempt. */ @@ -3304,7 +3304,7 @@ static void direct_pay_override(struct payment *p) { * sufficient capacity. Look it up in the channel_hints. */ for (size_t i=0; ichannel_hints); i++) { struct short_channel_id_dir *cur = &root->channel_hints[i].scid; - if (short_channel_id_eq(&cur->scid, &d->chan->scid) && + if (short_channel_id_eq(cur->scid, d->chan->scid) && cur->dir == d->chan->dir) { hint = &root->channel_hints[i]; break; diff --git a/plugins/pay.c b/plugins/pay.c index 10fe4c6ad..e44897105 100644 --- a/plugins/pay.c +++ b/plugins/pay.c @@ -122,7 +122,7 @@ static void json_add_sendpay_result(struct json_stream *s, const struct payment_ if (r->erring_channel) json_add_short_channel_id(s, "erring_channel", - r->erring_channel); + *r->erring_channel); if (r->erring_direction) json_add_num(s, "erring_direction", @@ -779,7 +779,7 @@ static void on_payment_failure(struct payment *payment) if (failure->erring_channel) json_add_short_channel_id( ret, "erring_channel", - failure->erring_channel); + *failure->erring_channel); if (failure->erring_direction) json_add_num( diff --git a/plugins/renepay/flow.h b/plugins/renepay/flow.h index dcd8aaace..407ba821f 100644 --- a/plugins/renepay/flow.h +++ b/plugins/renepay/flow.h @@ -57,9 +57,9 @@ static inline size_t hash_scid(const struct short_channel_id scid) } static inline bool chan_extra_eq_scid(const struct chan_extra *cd, - const struct short_channel_id scid) + struct short_channel_id scid) { - return short_channel_id_eq(&scid, &cd->scid); + return short_channel_id_eq(scid, cd->scid); } HTABLE_DEFINE_TYPE(struct chan_extra, diff --git a/plugins/renepay/pay.c b/plugins/renepay/pay.c index f9d7207de..e20b3b0a8 100644 --- a/plugins/renepay/pay.c +++ b/plugins/renepay/pay.c @@ -315,7 +315,7 @@ static void sendpay_new_flows(struct payment *p) json_add_node_id(req->js, "id", &pf->path_nodes[j]); json_add_short_channel_id(req->js, "channel", - &pf->path_scidds[j].scid); + pf->path_scidds[j].scid); json_add_amount_msat(req->js, "amount_msat", pf->amounts[j]); json_add_num(req->js, "direction", diff --git a/plugins/renepay/test/run-mcf-diamond.c b/plugins/renepay/test/run-mcf-diamond.c index 731eaca06..1a1442a7b 100644 --- a/plugins/renepay/test/run-mcf-diamond.c +++ b/plugins/renepay/test/run-mcf-diamond.c @@ -107,8 +107,8 @@ int main(int argc, char *argv[]) mods = gossmap_localmods_new(tmpctx); /* 1->2->4 has capacity 10k sat, 1->3->4 has capacity 5k sat (lower fee!) */ - assert(gossmap_local_addchan(mods, &l1, &l2, &scid12, NULL)); - assert(gossmap_local_updatechan(mods, &scid12, + assert(gossmap_local_addchan(mods, &l1, &l2, scid12, NULL)); + assert(gossmap_local_updatechan(mods, scid12, /*htlc_min=*/ AMOUNT_MSAT(0), /*htlc_max=*/ AMOUNT_MSAT(10000000), /*base_fee=*/ 0, @@ -116,22 +116,22 @@ int main(int argc, char *argv[]) /* delay =*/ 5, /* enabled=*/ true, /* dir =*/ 0)); - assert(gossmap_local_addchan(mods, &l2, &l4, &scid24, NULL)); - assert(gossmap_local_updatechan(mods, &scid24, + assert(gossmap_local_addchan(mods, &l2, &l4, scid24, NULL)); + assert(gossmap_local_updatechan(mods, scid24, AMOUNT_MSAT(0), AMOUNT_MSAT(10000000), 0, 1002, 5, true, 0)); - assert(gossmap_local_addchan(mods, &l1, &l3, &scid13, NULL)); - assert(gossmap_local_updatechan(mods, &scid13, + assert(gossmap_local_addchan(mods, &l1, &l3, scid13, NULL)); + assert(gossmap_local_updatechan(mods, scid13, AMOUNT_MSAT(0), AMOUNT_MSAT(5000000), 0, 503, 5, true, 0)); - assert(gossmap_local_addchan(mods, &l3, &l4, &scid34, NULL)); - assert(gossmap_local_updatechan(mods, &scid34, + assert(gossmap_local_addchan(mods, &l3, &l4, scid34, NULL)); + assert(gossmap_local_updatechan(mods, scid34, AMOUNT_MSAT(0), AMOUNT_MSAT(5000000), 0, 504, 5, diff --git a/plugins/renepay/test/run-mcf.c b/plugins/renepay/test/run-mcf.c index e9970ac77..a6fd478d1 100644 --- a/plugins/renepay/test/run-mcf.c +++ b/plugins/renepay/test/run-mcf.c @@ -402,7 +402,7 @@ int main(int argc, char *argv[]) /* Should have filled in some extra data! */ struct chan_extra *ce = chan_extra_map_get(chan_extra_map, scid12); - assert(short_channel_id_eq(&ce->scid, &scid12)); + assert(short_channel_id_eq(ce->scid, scid12)); /* l1->l2 dir is 1 */ assert(ce->half[1].num_htlcs == 1); assert(amount_msat_eq(ce->half[1].htlc_total, AMOUNT_MSAT(500000000 + 500000 + 20))); @@ -414,7 +414,7 @@ int main(int argc, char *argv[]) assert(amount_msat_eq(ce->half[0].known_max, AMOUNT_MSAT(1000000000))); ce = chan_extra_map_get(chan_extra_map, scid23); - assert(short_channel_id_eq(&ce->scid, &scid23)); + assert(short_channel_id_eq(ce->scid, scid23)); /* l2->l3 dir is 0 */ assert(ce->half[0].num_htlcs == 1); assert(amount_msat_eq(ce->half[0].htlc_total, AMOUNT_MSAT(500000000))); @@ -438,8 +438,8 @@ int main(int argc, char *argv[]) assert(short_channel_id_from_str("111x1x1", 7, &scid13)); /* 400,000sat channel from 1->3, basefee 0, ppm 1000, delay 5 */ - assert(gossmap_local_addchan(mods, &l1, &l3, &scid13, NULL)); - assert(gossmap_local_updatechan(mods, &scid13, + assert(gossmap_local_addchan(mods, &l1, &l3, scid13, NULL)); + assert(gossmap_local_updatechan(mods, scid13, AMOUNT_MSAT(0), AMOUNT_MSAT(400000000), 0, 1000, 5, diff --git a/plugins/renepay/uncertainty_network.c b/plugins/renepay/uncertainty_network.c index a41470af4..785782896 100644 --- a/plugins/renepay/uncertainty_network.c +++ b/plugins/renepay/uncertainty_network.c @@ -66,9 +66,9 @@ static void add_hintchan( MAX_CAP); /* FIXME: features? */ gossmap_local_addchan(local_gossmods, - src, dst, &scid, NULL); + src, dst, scid, NULL); gossmap_local_updatechan(local_gossmods, - &scid, + scid, /* We assume any HTLC is allowed */ AMOUNT_MSAT(0), MAX_CAP, fee_base_msat, fee_proportional_millionths, diff --git a/plugins/sql.c b/plugins/sql.c index effd4100f..ed331e466 100644 --- a/plugins/sql.c +++ b/plugins/sql.c @@ -856,7 +856,7 @@ static struct command_result *channels_refresh(struct command *cmd, listchannels_one_done, forward_error, dbq); - json_add_short_channel_id(req->js, "short_channel_id", &scid); + json_add_short_channel_id(req->js, "short_channel_id", scid); return send_outreq(cmd->plugin, req); } else if (type == WIRE_GOSSIP_STORE_DELETE_CHAN) { /* This can fail if entry not fully written yet. */ diff --git a/plugins/test/run-route-calc.c b/plugins/test/run-route-calc.c index 0cc9bc662..a9d97c245 100644 --- a/plugins/test/run-route-calc.c +++ b/plugins/test/run-route-calc.c @@ -112,7 +112,7 @@ void json_add_sha256(struct json_stream *result UNNEEDED, const char *fieldname /* Generated stub for json_add_short_channel_id */ void json_add_short_channel_id(struct json_stream *response UNNEEDED, const char *fieldname UNNEEDED, - const struct short_channel_id *id UNNEEDED) + struct short_channel_id id UNNEEDED) { fprintf(stderr, "json_add_short_channel_id called!\n"); abort(); } /* Generated stub for json_add_string */ void json_add_string(struct json_stream *js UNNEEDED, @@ -289,7 +289,7 @@ static void write_to_store(int store_fd, const u8 *msg) static void update_connection(int store_fd, const struct node_id *from, const struct node_id *to, - const struct short_channel_id *scid, + struct short_channel_id scid, struct amount_msat min, struct amount_msat max, u32 base_fee, s32 proportional_fee, @@ -366,14 +366,14 @@ static struct short_channel_id_dir add_connection(int store_fd, char from, char &dummy_sig, &dummy_sig, /* features */ NULL, &chainparams->genesis_blockhash, - &scidd.scid, + scidd.scid, ids[0], ids[1], &dummy_key, &dummy_key); write_to_store(store_fd, msg); msg = towire_gossip_store_channel_amount(tmpctx, capacity); write_to_store(store_fd, msg); - update_connection(store_fd, &from_id, &to_id, &scidd.scid, + update_connection(store_fd, &from_id, &to_id, scidd.scid, AMOUNT_MSAT(0), amount_msat(capacity.satoshis * 1000), base_fee, proportional_fee, @@ -492,7 +492,7 @@ int main(int argc, char *argv[]) assert(tal_count(r) == ARRAY_SIZE(path)); for (size_t j = 0; j < ARRAY_SIZE(path); j++) { - assert(short_channel_id_eq(&r[j].scid, &path[j].scid)); + assert(short_channel_id_eq(r[j].scid, path[j].scid)); assert(r[j].direction == path[j].dir); } diff --git a/plugins/test/run-route-overlong.c b/plugins/test/run-route-overlong.c index 2b28bf8af..39b743777 100644 --- a/plugins/test/run-route-overlong.c +++ b/plugins/test/run-route-overlong.c @@ -109,7 +109,7 @@ void json_add_sha256(struct json_stream *result UNNEEDED, const char *fieldname /* Generated stub for json_add_short_channel_id */ void json_add_short_channel_id(struct json_stream *response UNNEEDED, const char *fieldname UNNEEDED, - const struct short_channel_id *id UNNEEDED) + struct short_channel_id id UNNEEDED) { fprintf(stderr, "json_add_short_channel_id called!\n"); abort(); } /* Generated stub for json_add_string */ void json_add_string(struct json_stream *js UNNEEDED, @@ -286,7 +286,7 @@ static void write_to_store(int store_fd, const u8 *msg) static void update_connection(int store_fd, const struct node_id *from, const struct node_id *to, - const struct short_channel_id *scid, + struct short_channel_id scid, struct amount_msat min, struct amount_msat max, u32 base_fee, s32 proportional_fee, @@ -321,7 +321,7 @@ static void update_connection(int store_fd, static void add_connection(int store_fd, const struct node_id *from, const struct node_id *to, - const struct short_channel_id *scid, + struct short_channel_id scid, struct amount_msat min, struct amount_msat max, u32 base_fee, s32 proportional_fee, @@ -402,7 +402,7 @@ int main(int argc, char *argv[]) if (!mk_short_channel_id(&scid, i, i-1, 0)) abort(); - add_connection(store_fd, &ids[i-1], &ids[i], &scid, + add_connection(store_fd, &ids[i-1], &ids[i], scid, AMOUNT_MSAT(0), AMOUNT_MSAT(1000000 * 1000), 0, 0, 0); @@ -415,7 +415,7 @@ int main(int argc, char *argv[]) continue; if (!mk_short_channel_id(&scid, i, 1, 0)) abort(); - add_connection(store_fd, &ids[1], &ids[i], &scid, + add_connection(store_fd, &ids[1], &ids[i], scid, AMOUNT_MSAT(0), AMOUNT_MSAT(1000000 * 1000), 1 << i, 0, 0); diff --git a/plugins/topology.c b/plugins/topology.c index 332d18bad..f8593043e 100644 --- a/plugins/topology.c +++ b/plugins/topology.c @@ -53,7 +53,7 @@ static bool can_carry(const struct gossmap *map, switch (excludes[i]->type) { case EXCLUDE_CHANNEL: scid = gossmap_chan_scid(map, c); - if (short_channel_id_eq(&excludes[i]->u.chan_id.scid, &scid) + if (short_channel_id_eq(excludes[i]->u.chan_id.scid, scid) && dir == excludes[i]->u.chan_id.dir) return false; continue; @@ -78,7 +78,7 @@ static void json_add_route_hop(struct json_stream *js, /* Imitate what getroute/sendpay use */ json_object_start(js, fieldname); json_add_node_id(js, "id", &r->node_id); - json_add_short_channel_id(js, "channel", &r->scid); + json_add_short_channel_id(js, "channel", r->scid); json_add_num(js, "direction", r->direction); json_add_amount_msat(js, "amount_msat", r->amount); json_add_num(js, "delay", r->delay); @@ -261,7 +261,7 @@ static void json_add_halfchan(struct json_stream *response, json_object_start(response, NULL); json_add_node_id(response, "source", &node_id[dir]); json_add_node_id(response, "destination", &node_id[!dir]); - json_add_short_channel_id(response, "short_channel_id", &scid); + json_add_short_channel_id(response, "short_channel_id", scid); json_add_num(response, "direction", dir); json_add_bool(response, "public", !gossmap_chan_is_localmod(gossmap, c)); @@ -650,7 +650,7 @@ listpeerchannels_listincoming_done(struct command *cmd, json_object_start(js, NULL); gossmap_node_get_id(gossmap, peer, &peer_id); json_add_node_id(js, "id", &peer_id); - json_add_short_channel_id(js, "short_channel_id", &scid); + json_add_short_channel_id(js, "short_channel_id", scid); json_add_amount_msat(js, "fee_base_msat", amount_msat(ourchan->half[!dir].base_fee)); json_add_amount_msat(js, "htlc_min_msat", diff --git a/tests/fuzz/fuzz-wire-announcement_signatures.c b/tests/fuzz/fuzz-wire-announcement_signatures.c index 29ee55957..07f1be673 100644 --- a/tests/fuzz/fuzz-wire-announcement_signatures.c +++ b/tests/fuzz/fuzz-wire-announcement_signatures.c @@ -13,7 +13,7 @@ struct announcement_signatures { static void *encode(const tal_t *ctx, const struct announcement_signatures *s) { return towire_announcement_signatures( - ctx, &s->channel_id, &s->short_channel_id, &s->node_signature, + ctx, &s->channel_id, s->short_channel_id, &s->node_signature, &s->bitcoin_signature); } diff --git a/tests/fuzz/fuzz-wire-channel_announcement.c b/tests/fuzz/fuzz-wire-channel_announcement.c index 1edcd6f78..b73cb609a 100644 --- a/tests/fuzz/fuzz-wire-channel_announcement.c +++ b/tests/fuzz/fuzz-wire-channel_announcement.c @@ -25,7 +25,7 @@ static void *encode(const tal_t *ctx, const struct channel_announcement *s) return towire_channel_announcement( ctx, &s->node_signature_1, &s->node_signature_2, &s->bitcoin_signature_1, &s->bitcoin_signature_2, s->features, - &s->chain_hash, &s->short_channel_id, &s->node_id_1, &s->node_id_2, + &s->chain_hash, s->short_channel_id, &s->node_id_1, &s->node_id_2, &s->bitcoin_key_1, &s->bitcoin_key_2); } diff --git a/tests/fuzz/fuzz-wire-channel_update.c b/tests/fuzz/fuzz-wire-channel_update.c index 26c89be1c..7539e229e 100644 --- a/tests/fuzz/fuzz-wire-channel_update.c +++ b/tests/fuzz/fuzz-wire-channel_update.c @@ -20,7 +20,7 @@ struct channel_update { static void *encode(const tal_t *ctx, const struct channel_update *s) { return towire_channel_update( - ctx, &s->signature, &s->chain_hash, &s->short_channel_id, + ctx, &s->signature, &s->chain_hash, s->short_channel_id, s->timestamp, s->message_flags, s->channel_flags, s->cltv_expiry_delta, s->htlc_minimum_msat, s->fee_base_msat, s->fee_proportional_millionths, s->htlc_maximum_msat); diff --git a/tools/generate-wire.py b/tools/generate-wire.py index 92ebf7b9d..ebf7614d5 100755 --- a/tools/generate-wire.py +++ b/tools/generate-wire.py @@ -195,7 +195,8 @@ class Type(FieldSet): 'amount_sat', 'amount_msat', 'bigsize', - 'varint' + 'varint', + 'short_channel_id' ] typedefs = [ diff --git a/wallet/db.c b/wallet/db.c index 3459d16a0..c283556eb 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -1589,7 +1589,7 @@ static void migrate_channels_scids_as_integers(struct lightningd *ld, stmt = db_prepare_v2(db, SQL("UPDATE channels" " SET scid = ?" " WHERE short_channel_id = ?")); - db_bind_short_channel_id(stmt, &scid); + db_bind_short_channel_id(stmt, scid); db_bind_text(stmt, scids[i]); db_exec_prepared_v2(stmt); @@ -1644,7 +1644,7 @@ static void migrate_payments_scids_as_integers(struct lightningd *ld, update_stmt = db_prepare_v2(db, SQL("UPDATE payments SET" " failscid = ?" " WHERE id = ?")); - db_bind_short_channel_id(update_stmt, &scid); + db_bind_short_channel_id(update_stmt, scid); db_bind_u64(update_stmt, db_col_u64(stmt, "id")); db_exec_prepared_v2(update_stmt); tal_free(update_stmt); @@ -1991,7 +1991,7 @@ static void migrate_initialize_alias_local(struct lightningd *ld, " WHERE id = ?;")); /* We don't even check for clashes! */ randombytes_buf(&alias, sizeof(alias)); - db_bind_short_channel_id(stmt, &alias); + db_bind_short_channel_id(stmt, alias); db_bind_u64(stmt, ids[i]); db_exec_prepared_v2(stmt); tal_free(stmt); diff --git a/wallet/test/run-db.c b/wallet/test/run-db.c index 04253603b..eb886529b 100644 --- a/wallet/test/run-db.c +++ b/wallet/test/run-db.c @@ -32,7 +32,7 @@ const struct peer_update *channel_gossip_get_remote_update(const struct channel void channel_gossip_update(struct channel *channel UNNEEDED) { fprintf(stderr, "channel_gossip_update called!\n"); abort(); } /* Generated stub for channel_scid_or_local_alias */ -const struct short_channel_id *channel_scid_or_local_alias(const struct channel *chan UNNEEDED) +struct short_channel_id channel_scid_or_local_alias(const struct channel *chan UNNEEDED) { fprintf(stderr, "channel_scid_or_local_alias called!\n"); abort(); } /* Generated stub for connect_htlc_in */ void connect_htlc_in(struct htlc_in_map *map UNNEEDED, struct htlc_in *hin UNNEEDED) diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index 13de88200..351519faa 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -221,7 +221,7 @@ void ecdh(const struct pubkey *point UNNEEDED, struct secret *ss UNNEEDED) /* Generated stub for encode_scriptpubkey_to_addr */ char *encode_scriptpubkey_to_addr(const tal_t *ctx UNNEEDED, const struct chainparams *chainparams UNNEEDED, - const u8 *scriptPubkey UNNEEDED) + const u8 *scriptpubkey UNNEEDED) { fprintf(stderr, "encode_scriptpubkey_to_addr called!\n"); abort(); } /* Generated stub for fatal */ void fatal(const char *fmt UNNEEDED, ...) @@ -483,7 +483,7 @@ void json_add_sha256(struct json_stream *result UNNEEDED, const char *fieldname /* Generated stub for json_add_short_channel_id */ void json_add_short_channel_id(struct json_stream *response UNNEEDED, const char *fieldname UNNEEDED, - const struct short_channel_id *id UNNEEDED) + struct short_channel_id id UNNEEDED) { fprintf(stderr, "json_add_short_channel_id called!\n"); abort(); } /* Generated stub for json_add_string */ void json_add_string(struct json_stream *js UNNEEDED, @@ -1004,7 +1004,7 @@ void topology_add_sync_waiter_(const tal_t *ctx UNNEEDED, void *arg UNNEEDED) { fprintf(stderr, "topology_add_sync_waiter_ called!\n"); abort(); } /* Generated stub for towire_announcement_signatures */ -u8 *towire_announcement_signatures(const tal_t *ctx UNNEEDED, const struct channel_id *channel_id UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED, const secp256k1_ecdsa_signature *node_signature UNNEEDED, const secp256k1_ecdsa_signature *bitcoin_signature UNNEEDED) +u8 *towire_announcement_signatures(const tal_t *ctx UNNEEDED, const struct channel_id *channel_id UNNEEDED, struct short_channel_id short_channel_id UNNEEDED, const secp256k1_ecdsa_signature *node_signature UNNEEDED, const secp256k1_ecdsa_signature *bitcoin_signature UNNEEDED) { fprintf(stderr, "towire_announcement_signatures called!\n"); abort(); } /* Generated stub for towire_channeld_dev_memleak */ u8 *towire_channeld_dev_memleak(const tal_t *ctx UNNEEDED) @@ -1165,7 +1165,7 @@ void try_reconnect(const tal_t *ctx UNNEEDED, /* Generated stub for unsigned_channel_update */ u8 *unsigned_channel_update(const tal_t *ctx UNNEEDED, const struct channel *channel UNNEEDED, - const struct short_channel_id *scid UNNEEDED, + struct short_channel_id scid UNNEEDED, const u32 *old_timestamp UNNEEDED, bool forwardable UNNEEDED, bool enabled UNNEEDED) @@ -1626,7 +1626,7 @@ static bool channelseq(struct channel *c1, struct channel *c2) CHECK(c1->their_shachain.id == c2->their_shachain.id); CHECK_MSG(node_id_eq(&p1->id, &p2->id), "NodeIDs do not match"); CHECK((c1->scid == NULL && c2->scid == NULL) - || short_channel_id_eq(c1->scid, c2->scid)); + || short_channel_id_eq(*c1->scid, *c2->scid)); CHECK(amount_msat_eq(c1->our_msat, c2->our_msat)); CHECK((c1->shutdown_scriptpubkey[REMOTE] == NULL && c2->shutdown_scriptpubkey[REMOTE] == NULL) || tal_arr_eq( c1->shutdown_scriptpubkey[REMOTE], diff --git a/wallet/wallet.c b/wallet/wallet.c index 4209bbf3d..4e98b8ef8 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -1487,6 +1487,20 @@ static bool wallet_channel_config_load(struct wallet *w, const u64 id, return ok; } +static struct short_channel_id *db_col_optional_scid(const tal_t *ctx, + struct db_stmt *stmt, + const char *colname) +{ + struct short_channel_id *scid; + + if (db_col_is_null(stmt, colname)) + return NULL; + + scid = tal(tmpctx, struct short_channel_id); + *scid = db_col_short_channel_id(stmt, colname); + return scid; +} + /** * wallet_stmt2channel - Helper to populate a wallet_channel from a `db_stmt` */ @@ -1532,11 +1546,9 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm } } - scid = db_col_optional(tmpctx, stmt, "scid", short_channel_id); - alias[LOCAL] = db_col_optional(tmpctx, stmt, "alias_local", - short_channel_id); - alias[REMOTE] = db_col_optional(tmpctx, stmt, "alias_remote", - short_channel_id); + scid = db_col_optional_scid(tmpctx, stmt, "scid"); + alias[LOCAL] = db_col_optional_scid(tmpctx, stmt, "alias_local"); + alias[REMOTE] = db_col_optional_scid(tmpctx, stmt, "alias_remote"); ok &= wallet_shachain_load(w, db_col_u64(stmt, "shachain_remote_id"), &wshachain); @@ -1786,11 +1798,9 @@ static struct closed_channel *wallet_stmt2closed_channel(const tal_t *ctx, /* Can be missing in older dbs! */ cc->peer_id = db_col_optional(cc, stmt, "p.node_id", node_id); db_col_channel_id(stmt, "full_channel_id", &cc->cid); - cc->scid = db_col_optional(cc, stmt, "scid", short_channel_id); - cc->alias[LOCAL] = db_col_optional(cc, stmt, "alias_local", - short_channel_id); - cc->alias[REMOTE] = db_col_optional(cc, stmt, "alias_remote", - short_channel_id); + cc->scid = db_col_optional_scid(cc, stmt, "scid"); + cc->alias[LOCAL] = db_col_optional_scid(cc, stmt, "alias_local"); + cc->alias[REMOTE] = db_col_optional_scid(cc, stmt, "alias_remote"); cc->opener = db_col_int(stmt, "funder"); cc->closer = db_col_int(stmt, "closer"); cc->channel_flags = db_col_int(stmt, "channel_flags"); @@ -2288,7 +2298,7 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) " WHERE id=?")); // 54 db_bind_u64(stmt, chan->their_shachain.id); if (chan->scid) - db_bind_short_channel_id(stmt, chan->scid); + db_bind_short_channel_id(stmt, *chan->scid); else db_bind_null(stmt); @@ -2357,12 +2367,12 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) db_bind_amount_msat(stmt, &chan->htlc_maximum_msat); if (chan->alias[LOCAL] != NULL) - db_bind_short_channel_id(stmt, chan->alias[LOCAL]); + db_bind_short_channel_id(stmt, *chan->alias[LOCAL]); else db_bind_null(stmt); if (chan->alias[REMOTE] != NULL) - db_bind_short_channel_id(stmt, chan->alias[REMOTE]); + db_bind_short_channel_id(stmt, *chan->alias[REMOTE]); else db_bind_null(stmt); @@ -3778,7 +3788,7 @@ void wallet_payment_get_failinfo(const tal_t *ctx, *failindex = db_col_int(stmt, "failindex"); *failcode = (enum onion_wire) db_col_int(stmt, "failcode"); *failnode = db_col_optional(ctx, stmt, "failnode", node_id); - *failchannel = db_col_optional(ctx, stmt, "failscid", short_channel_id); + *failchannel = db_col_optional_scid(ctx, stmt, "failscid"); if (*failchannel) { /* For pre-0.6.2 dbs, direction will be 0 */ *faildirection = db_col_int(stmt, "faildirection"); @@ -3839,7 +3849,7 @@ void wallet_payment_set_failinfo(struct wallet *wallet, db_bind_null(stmt); if (failchannel) { - db_bind_short_channel_id(stmt, failchannel); + db_bind_short_channel_id(stmt, *failchannel); db_bind_int(stmt, faildirection); } else { db_bind_null(stmt); @@ -4419,7 +4429,7 @@ bool wallet_have_block(struct wallet *w, u32 blockheight) } struct outpoint *wallet_outpoint_for_scid(const tal_t *ctx, struct wallet *w, - const struct short_channel_id *scid) + struct short_channel_id scid) { struct db_stmt *stmt; struct outpoint *op; @@ -4857,7 +4867,7 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in, updated_index = forward_index_update_status(w->ld, state, - *channel_scid_or_local_alias(in->key.channel), + channel_scid_or_local_alias(in->key.channel), in->key.id, in->msat, scid_out); @@ -4883,7 +4893,7 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in, ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")); id = forward_index_created(w->ld, state, - *channel_scid_or_local_alias(in->key.channel), + channel_scid_or_local_alias(in->key.channel), in->key.id, in->msat, scid_out); @@ -4910,7 +4920,7 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in, db_bind_short_channel_id(stmt, channel_scid_or_local_alias(in->key.channel)); if (scid_out) - db_bind_short_channel_id(stmt, scid_out); + db_bind_short_channel_id(stmt, *scid_out); else db_bind_null(stmt); db_bind_amount_msat(stmt, &in->msat); @@ -5027,7 +5037,7 @@ const struct forwarding *wallet_forwarded_payments_get(const tal_t *ctx, if (chan_in) { // specific in_channel db_bind_int(stmt, 0); - db_bind_short_channel_id(stmt, chan_in); + db_bind_short_channel_id(stmt, *chan_in); } else { // any in_channel db_bind_int(stmt, 1); @@ -5037,7 +5047,7 @@ const struct forwarding *wallet_forwarded_payments_get(const tal_t *ctx, if (chan_out) { // specific out_channel db_bind_int(stmt, 0); - db_bind_short_channel_id(stmt, chan_out); + db_bind_short_channel_id(stmt, *chan_out); } else { // any out_channel db_bind_int(stmt, 1); @@ -5147,7 +5157,7 @@ const struct forwarding *wallet_forwarded_payments_get(const tal_t *ctx, cur->fee = AMOUNT_MSAT(0); } - db_col_short_channel_id(stmt, "in_channel_scid", &cur->channel_in); + cur->channel_in = db_col_short_channel_id(stmt, "in_channel_scid"); #ifdef COMPAT_V0121 /* This can happen due to migration! */ @@ -5160,7 +5170,7 @@ const struct forwarding *wallet_forwarded_payments_get(const tal_t *ctx, #endif if (!db_col_is_null(stmt, "out_channel_scid")) { - db_col_short_channel_id(stmt, "out_channel_scid", &cur->channel_out); + cur->channel_out = db_col_short_channel_id(stmt, "out_channel_scid"); } else { assert(cur->status == FORWARD_LOCAL_FAILED); cur->channel_out.u64 = 0; @@ -5200,7 +5210,7 @@ const struct forwarding *wallet_forwarded_payments_get(const tal_t *ctx, } bool wallet_forward_delete(struct wallet *w, - const struct short_channel_id *chan_in, + struct short_channel_id chan_in, const u64 *htlc_id, enum forward_status state) { @@ -5271,7 +5281,7 @@ bool wallet_forward_delete(struct wallet *w, * need an extra lookup */ forward_index_deleted(w->ld, state, - *chan_in, + chan_in, htlc_id ? *htlc_id : HTLC_INVALID_ID, NULL, NULL); } @@ -5974,7 +5984,7 @@ struct wallet_htlc_iter *wallet_htlcs_first(const tal_t *ctx, struct wallet_htlc_iter *i = tal(ctx, struct wallet_htlc_iter); if (chan) { - i->scid = *channel_scid_or_local_alias(chan); + i->scid = channel_scid_or_local_alias(chan); assert(i->scid.u64 != 0); assert(chan->dbid != 0); @@ -6030,9 +6040,9 @@ struct wallet_htlc_iter *wallet_htlcs_next(struct wallet *w, *scid = iter->scid; else { if (db_col_is_null(iter->stmt, "channels.scid")) - db_col_short_channel_id(iter->stmt, "channels.alias_local", scid); + *scid = db_col_short_channel_id(iter->stmt, "channels.alias_local"); else { - db_col_short_channel_id(iter->stmt, "channels.scid", scid); + *scid = db_col_short_channel_id(iter->stmt, "channels.scid"); db_col_ignore(iter->stmt, "channels.alias_local"); } } diff --git a/wallet/wallet.h b/wallet/wallet.h index 0d64c9cd4..45f59d283 100644 --- a/wallet/wallet.h +++ b/wallet/wallet.h @@ -1142,7 +1142,7 @@ bool wallet_outpoint_spend(const tal_t *ctx, struct wallet *w, const struct bitcoin_outpoint *outpoint); struct outpoint *wallet_outpoint_for_scid(const tal_t *ctx, struct wallet *w, - const struct short_channel_id *scid); + struct short_channel_id scid); void wallet_utxoset_add(struct wallet *w, const struct bitcoin_outpoint *outpoint, @@ -1260,7 +1260,7 @@ const struct forwarding *wallet_forwarded_payments_get(const tal_t *ctx, * Returns false if not found */ bool wallet_forward_delete(struct wallet *w, - const struct short_channel_id *chan_in, + struct short_channel_id chan_in, const u64 *htlc_id, enum forward_status state); diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c index 561be6dab..5da27b1fd 100644 --- a/wallet/walletrpc.c +++ b/wallet/walletrpc.c @@ -370,7 +370,7 @@ static struct command_result *json_listfunds(struct command *cmd, if (c->scid) json_add_short_channel_id(response, "short_channel_id", - c->scid); + *c->scid); json_add_amount_msat(response, "our_amount_msat", diff --git a/wire/test/run-peer-wire.c b/wire/test/run-peer-wire.c index 7997bf6bd..ad5379580 100644 --- a/wire/test/run-peer-wire.c +++ b/wire/test/run-peer-wire.c @@ -245,7 +245,7 @@ static void *towire_struct_channel_announcement(const tal_t *ctx, &s->bitcoin_signature_2, s->features, &s->chain_hash, - &s->short_channel_id, + s->short_channel_id, &s->node_id_1, &s->node_id_2, &s->bitcoin_key_1, @@ -405,7 +405,7 @@ static void *towire_struct_channel_update(const tal_t *ctx, return towire_channel_update(ctx, &s->signature, &s->chain_hash, - &s->short_channel_id, + s->short_channel_id, s->timestamp, s->message_flags, s->channel_flags, @@ -464,7 +464,7 @@ static void *towire_struct_announcement_signatures(const tal_t *ctx, { return towire_announcement_signatures(ctx, &s->channel_id, - &s->short_channel_id, + s->short_channel_id, &s->announcement_node_signature, &s->announcement_bitcoin_signature); } @@ -756,27 +756,33 @@ static bool channel_announcement_eq(const struct msg_channel_announcement *a, return eq_upto(a, b, features) && eq_var(a, b, features) && eq_field(a, b, chain_hash) - && short_channel_id_eq(&a->short_channel_id, - &b->short_channel_id) + && short_channel_id_eq(a->short_channel_id, + b->short_channel_id) && eq_field(a, b, node_id_1) && eq_field(a, b, node_id_2) && eq_between(a, b, bitcoin_key_1, bitcoin_key_2); } +static bool short_channel_id_ptr_eq(const struct short_channel_id *ap, + const struct short_channel_id *bp) +{ + return short_channel_id_eq(*ap, *bp); +} + static bool channel_ready_eq(const struct msg_channel_ready *a, const struct msg_channel_ready *b) { if (!eq_upto(a, b, tlvs)) return false; - return eq_tlv(a, b, short_channel_id, short_channel_id_eq); + return eq_tlv(a, b, short_channel_id, short_channel_id_ptr_eq); } static bool announcement_signatures_eq(const struct msg_announcement_signatures *a, const struct msg_announcement_signatures *b) { return eq_upto(a, b, short_channel_id) && - short_channel_id_eq(&a->short_channel_id, &b->short_channel_id); + short_channel_id_eq(a->short_channel_id, b->short_channel_id); } static bool update_fail_htlc_eq(const struct msg_update_fail_htlc *a, @@ -878,7 +884,7 @@ static bool channel_update_eq(const struct msg_channel_update *a, const struct msg_channel_update *b) { return eq_upto(a, b, short_channel_id) && - short_channel_id_eq(&a->short_channel_id, &b->short_channel_id); + short_channel_id_eq(a->short_channel_id, b->short_channel_id); } static bool accept_channel_eq(const struct msg_accept_channel *a, diff --git a/wire/test/run-tlvstream.c b/wire/test/run-tlvstream.c index 50aad00f1..68420fb90 100644 --- a/wire/test/run-tlvstream.c +++ b/wire/test/run-tlvstream.c @@ -360,7 +360,7 @@ static bool tlv_n1_eq(const struct tlv_n1 *a, const struct tlv_n1 *b) if (a->tlv2) { if (!b->tlv2) return false; - if (!short_channel_id_eq(a->tlv2, b->tlv2)) + if (!short_channel_id_eq(*a->tlv2, *b->tlv2)) return false; } else if (b->tlv2) return false; diff --git a/wire/tlvstream.c b/wire/tlvstream.c index 93b91afa9..215d30a8b 100644 --- a/wire/tlvstream.c +++ b/wire/tlvstream.c @@ -66,7 +66,7 @@ void tlvstream_set_raw(struct tlv_field **stream, u64 type, const void *value TA } void tlvstream_set_short_channel_id(struct tlv_field **stream, u64 type, - struct short_channel_id *value) + struct short_channel_id value) { u8 *ser = tal_arr(NULL, u8, 0); towire_short_channel_id(&ser, value); diff --git a/wire/tlvstream.h b/wire/tlvstream.h index 469390702..0b3f71735 100644 --- a/wire/tlvstream.h +++ b/wire/tlvstream.h @@ -67,7 +67,7 @@ extern const u64 *FROMWIRE_TLV_ANY_TYPE; /* Generic primitive setters for tlvstreams. */ void tlvstream_set_raw(struct tlv_field **stream, u64 type, const void *value TAKES, size_t valuelen); void tlvstream_set_short_channel_id(struct tlv_field **stream, u64 type, - struct short_channel_id *value); + struct short_channel_id value); void tlvstream_set_tu64(struct tlv_field **stream, u64 type, u64 value); void tlvstream_set_tu32(struct tlv_field **stream, u64 type, u32 value);