diff --git a/lightningd/channel_gossip.c b/lightningd/channel_gossip.c index 4648d1ef3..3dcc59e11 100644 --- a/lightningd/channel_gossip.c +++ b/lightningd/channel_gossip.c @@ -420,7 +420,6 @@ static void send_channel_announce_sigs(struct channel *channel) struct lightningd *ld = channel->peer->ld; struct sha256_double hash; secp256k1_ecdsa_signature local_node_sig, local_bitcoin_sig; - struct pubkey mykey; const u8 *ca, *msg; /* If it's already closing, don't bother. */ @@ -446,10 +445,7 @@ static void send_channel_announce_sigs(struct channel *channel) /* Double-check that HSM gave valid signatures. */ sha256_double(&hash, ca + offset, tal_count(ca) - offset); - if (!pubkey_from_node_id(&mykey, &ld->id)) - fatal("Could not convert own public key"); - - if (!check_signed_hash(&hash, &local_node_sig, &mykey)) { + if (!check_signed_hash(&hash, &local_node_sig, &ld->our_pubkey)) { channel_internal_error(channel, "HSM returned an invalid node signature"); return; diff --git a/lightningd/coin_mvts.c b/lightningd/coin_mvts.c index 68bdde72a..74f940384 100644 --- a/lightningd/coin_mvts.c +++ b/lightningd/coin_mvts.c @@ -13,7 +13,7 @@ void notify_channel_mvt(struct lightningd *ld, const struct channel_coin_mvt *mv timestamp = time_now().ts.tv_sec; cm = finalize_channel_mvt(mvt, mvt, chainparams->lightning_hrp, - timestamp, &ld->id); + timestamp, &ld->our_nodeid); notify_coin_mvt(ld, cm); } @@ -25,7 +25,7 @@ void notify_chain_mvt(struct lightningd *ld, const struct chain_coin_mvt *mvt) timestamp = time_now().ts.tv_sec; cm = finalize_chain_mvt(mvt, mvt, chainparams->lightning_hrp, - timestamp, &ld->id); + timestamp, &ld->our_nodeid); notify_coin_mvt(ld, cm); } @@ -114,7 +114,7 @@ void send_account_balance_snapshot(struct lightningd *ld, u32 blockheight) snap->blockheight = blockheight; snap->timestamp = time_now().ts.tv_sec; - snap->node_id = &ld->id; + snap->node_id = &ld->our_nodeid; /* Add the 'wallet' account balance */ snap->accts = tal_arr(snap, struct account_balance *, 1); diff --git a/lightningd/connect_control.c b/lightningd/connect_control.c index 2073bddd3..f0cafb8bf 100644 --- a/lightningd/connect_control.c +++ b/lightningd/connect_control.c @@ -756,7 +756,7 @@ int connectd_init(struct lightningd *ld) msg = towire_connectd_init(tmpctx, chainparams, ld->our_features, - &ld->id, + &ld->our_nodeid, wireaddrs, listen_announce, ld->proxyaddr, diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index dd0ca83f5..b318f7604 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -280,7 +280,7 @@ void gossip_init(struct lightningd *ld, int connectd_fd) NULL, chainparams, ld->our_features, - &ld->id, + &ld->our_nodeid, ld->dev_gossip_time ? &ld->dev_gossip_time: NULL, ld->dev_fast_gossip, ld->dev_fast_gossip_prune); diff --git a/lightningd/gossip_generation.c b/lightningd/gossip_generation.c index f16b220f6..22877c9c0 100644 --- a/lightningd/gossip_generation.c +++ b/lightningd/gossip_generation.c @@ -70,7 +70,7 @@ u8 *create_channel_announcement(const tal_t *ctx, copysig_or_zero(&bitcoin_signature[REMOTE], remote_bitcoin_signature); copysig_or_zero(&node_signature[LOCAL], local_node_signature); copysig_or_zero(&node_signature[REMOTE], remote_node_signature); - node_id[LOCAL] = channel->peer->ld->id; + node_id[LOCAL] = channel->peer->ld->our_nodeid; node_id[REMOTE] = channel->peer->id; funding_pubkey[LOCAL] = channel->local_funding_pubkey; funding_pubkey[REMOTE] = channel->channel_info.remote_fundingkey; @@ -104,7 +104,7 @@ u8 *unsigned_channel_update(const tal_t *ctx, * | 0 | `direction` | Direction this update refers to. | * | 1 | `disable` | Disable the channel. | */ - channel_flags = node_id_idx(&channel->peer->ld->id, + channel_flags = node_id_idx(&channel->peer->ld->our_nodeid, &channel->peer->id); if (!enabled) channel_flags |= ROUTING_FLAGS_DISABLED; @@ -372,7 +372,7 @@ static u8 *create_nannounce(const tal_t *ctx, towire_node_announcement(ctx, sig, ld->our_features->bits[NODE_ANNOUNCE_FEATURE], timestamp, - &ld->id, ld->rgb, ld->alias, + &ld->our_nodeid, ld->rgb, ld->alias, addresses, na_tlv); return announcement; diff --git a/lightningd/hsm_control.c b/lightningd/hsm_control.c index 93884a90f..a70ea476a 100644 --- a/lightningd/hsm_control.c +++ b/lightningd/hsm_control.c @@ -48,7 +48,7 @@ int hsm_get_client_fd(struct lightningd *ld, int hsm_get_global_fd(struct lightningd *ld, u64 permissions) { - int fd = hsm_get_fd(ld, &ld->id, 0, permissions); + int fd = hsm_get_fd(ld, &ld->our_nodeid, 0, permissions); if (fd < 0) fatal("Could not read fd from HSM: %s", strerror(errno)); @@ -141,7 +141,7 @@ struct ext_key *hsm_init(struct lightningd *ld) if (fromwire_hsmd_init_reply_v4(ld, msg, &hsm_version, &ld->hsm_capabilities, - &ld->id, bip32_base, + &ld->our_nodeid, bip32_base, &ld->bolt12_base)) { /* nothing to do. */ } else { @@ -150,6 +150,10 @@ struct ext_key *hsm_init(struct lightningd *ld) errx(EXITCODE_HSM_GENERIC_ERROR, "HSM did not give init reply"); } + if (!pubkey_from_node_id(&ld->our_pubkey, &ld->our_nodeid)) + errx(EXITCODE_HSM_GENERIC_ERROR, "HSM gave invalid node id %s", + fmt_node_id(tmpctx, &ld->our_nodeid)); + if (hsm_version < HSM_MIN_VERSION) errx(EXITCODE_HSM_GENERIC_ERROR, "HSM version %u below minimum %u", diff --git a/lightningd/invoice.c b/lightningd/invoice.c index 7060f848e..f43e96752 100644 --- a/lightningd/invoice.c +++ b/lightningd/invoice.c @@ -1200,7 +1200,7 @@ static struct command_result *json_invoice(struct command *cmd, info->b11->chain = chainparams; info->b11->timestamp = time_now().ts.tv_sec; info->b11->payment_hash = rhash; - info->b11->receiver_id = cmd->ld->id; + info->b11->receiver_id = cmd->ld->our_nodeid; info->b11->min_final_cltv_expiry = *cltv; info->b11->expiry = *expiry; info->b11->description = tal_steal(info->b11, desc_val); @@ -1641,12 +1641,9 @@ static void add_stub_blindedpath(const tal_t *ctx, struct blinded_path *path; struct privkey blinding; struct tlv_encrypted_data_tlv *tlv; - struct pubkey me; path = tal(NULL, struct blinded_path); - if (!pubkey_from_node_id(&me, &ld->id)) - abort(); - sciddir_or_pubkey_from_pubkey(&path->first_node_id, &me); + sciddir_or_pubkey_from_pubkey(&path->first_node_id, &ld->our_pubkey); randombytes_buf(&blinding, sizeof(blinding)); if (!pubkey_from_privkey(&blinding, &path->blinding)) abort(); diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 984bbed77..f4483dd97 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -1416,7 +1416,7 @@ int main(int argc, char *argv[]) * tal_bytelen() to get the length. */ log_info(ld->log, "--------------------------------------------------"); log_info(ld->log, "Server started with public key %s, alias %s (color #%s) and lightningd %s", - fmt_node_id(tmpctx, &ld->id), + fmt_node_id(tmpctx, &ld->our_nodeid), json_escape(tmpctx, (const char *)ld->alias)->s, tal_hex(tmpctx, ld->rgb), version()); ld->state = LD_STATE_RUNNING; diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index e9594c109..49a25b7d8 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -147,8 +147,9 @@ struct lightningd { struct logger *log; const char **logfiles; - /* This is us. */ - struct node_id id; + /* This is us, in both node_id and pubkey form */ + struct node_id our_nodeid; + struct pubkey our_pubkey; /* The public base for our payer_id keys */ struct pubkey bolt12_base; diff --git a/lightningd/offer.c b/lightningd/offer.c index a62ad418a..0156fc808 100644 --- a/lightningd/offer.c +++ b/lightningd/offer.c @@ -450,9 +450,7 @@ static struct command_result *json_createinvoicerequest(struct command *cmd, invreq->invreq_payer_id = tal(invreq, struct pubkey); if (*exposeid) { - if (!pubkey_from_node_id(invreq->invreq_payer_id, - &cmd->ld->id)) - fatal("Our ID is invalid?"); + *invreq->invreq_payer_id = cmd->ld->our_pubkey; } else if (!payer_key(cmd->ld, invreq->invreq_metadata, tal_bytelen(invreq->invreq_metadata), diff --git a/lightningd/options.c b/lightningd/options.c index 184d424a9..2954ffeae 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -1768,14 +1768,14 @@ void setup_color_and_alias(struct lightningd *ld) { if (!ld->rgb) /* You can't get much red by default */ - ld->rgb = tal_dup_arr(ld, u8, ld->id.k, 3, 0); + ld->rgb = tal_dup_arr(ld, u8, ld->our_nodeid.k, 3, 0); if (!ld->alias) { u64 adjective, noun; char *name; - memcpy(&adjective, ld->id.k+3, sizeof(adjective)); - memcpy(&noun, ld->id.k+3+sizeof(adjective), sizeof(noun)); + memcpy(&adjective, ld->our_nodeid.k+3, sizeof(adjective)); + memcpy(&noun, ld->our_nodeid.k+3+sizeof(adjective), sizeof(noun)); noun %= ARRAY_SIZE(codename_noun); adjective %= ARRAY_SIZE(codename_adjective); diff --git a/lightningd/pay.c b/lightningd/pay.c index f871399c6..aed480447 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -353,10 +353,10 @@ immediate_routing_failure(const tal_t *ctx, routing_failure->erring_index = 0; routing_failure->failcode = failcode; routing_failure->erring_node = - tal_dup(routing_failure, struct node_id, &ld->id); + tal_dup(routing_failure, struct node_id, &ld->our_nodeid); routing_failure->erring_channel = tal_dup(routing_failure, struct short_channel_id, &channel0); - routing_failure->channel_dir = node_id_idx(&ld->id, dstid); + routing_failure->channel_dir = node_id_idx(&ld->our_nodeid, dstid); routing_failure->msg = NULL; return routing_failure; @@ -378,14 +378,14 @@ local_routing_failure(const tal_t *ctx, routing_failure->failcode = failcode; routing_failure->erring_node = - tal_dup(routing_failure, struct node_id, &ld->id); + tal_dup(routing_failure, struct node_id, &ld->our_nodeid); if (payment->route_nodes != NULL && payment->route_channels != NULL) { routing_failure->erring_channel = tal_dup(routing_failure, struct short_channel_id, &payment->route_channels[0]); routing_failure->channel_dir = - node_id_idx(&ld->id, &payment->route_nodes[0]); + node_id_idx(&ld->our_nodeid, &payment->route_nodes[0]); } else { routing_failure->erring_channel = NULL; } @@ -444,7 +444,7 @@ remote_routing_failure(const tal_t *ctx, erring_channel = &route_channels[origin_index]; /* Single hop? */ if (origin_index == 0) - dir = node_id_idx(&ld->id, + dir = node_id_idx(&ld->our_nodeid, &route_nodes[origin_index]); else dir = node_id_idx(&route_nodes[origin_index - 1], @@ -1067,8 +1067,8 @@ send_payment_core(struct lightningd *ld, "peer found"); json_add_routefail_info(data, 0, WIRE_UNKNOWN_NEXT_PEER, - &ld->id, NULL, - node_id_idx(&ld->id, + &ld->our_nodeid, NULL, + node_id_idx(&ld->our_nodeid, &first_hop->node_id), NULL); json_object_end(data); @@ -1434,7 +1434,7 @@ static struct command_result *self_payment(struct lightningd *ld, partid, groupid, PAYMENT_PENDING, - &ld->id, + &ld->our_nodeid, msat, msat, msat, @@ -1458,7 +1458,7 @@ static struct command_result *self_payment(struct lightningd *ld, /* tell_waiters_failed expects one of these! */ fail = tal(payment, struct routing_failure); fail->failcode = WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS; - fail->erring_node = &ld->id; + fail->erring_node = &ld->our_nodeid; fail->erring_index = 0; fail->erring_channel = NULL; fail->msg = NULL; diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 5f56e4c17..bb7a2fb67 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -105,7 +105,7 @@ struct peer *new_peer(struct lightningd *ld, u64 dbid, peer->connected_incoming = connected_incoming; peer->remote_addr = NULL; list_head_init(&peer->channels); - peer->direction = node_id_idx(&peer->ld->id, &peer->id); + peer->direction = node_id_idx(&peer->ld->our_nodeid, &peer->id); peer->connected = PEER_DISCONNECTED; peer->last_connect_attempt.ts.tv_sec = peer->last_connect_attempt.ts.tv_nsec = 0; @@ -901,7 +901,7 @@ static void NON_NULL_ARGS(1, 2, 4, 5) json_add_channel(struct command *cmd, * why bother if we can't use it? */ if (channel->scid || channel->alias[LOCAL] || channel->alias[REMOTE]) json_add_num(response, "direction", - node_id_idx(&ld->id, &channel->peer->id)); + node_id_idx(&ld->our_nodeid, &channel->peer->id)); json_add_string(response, "channel_id", fmt_channel_id(tmpctx, &channel->cid)); @@ -2679,7 +2679,7 @@ static struct command_result *json_getinfo(struct command *cmd, return command_param_failed(); response = json_stream_success(cmd); - json_add_node_id(response, "id", &cmd->ld->id); + json_add_node_id(response, "id", &cmd->ld->our_nodeid); json_add_string(response, "alias", (const char *)cmd->ld->alias); json_add_hex_talarr(response, "color", cmd->ld->rgb); diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index 4f27c95dc..b6f0791a9 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -2295,7 +2295,7 @@ int main(int argc, const char *argv[]) ld->peers_by_dbid = tal(ld, struct peer_dbid_map); peer_dbid_map_init(ld->peers_by_dbid); ld->rr_counter = 0; - node_id_from_hexstr("02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc", 66, &ld->id); + node_id_from_hexstr("02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc", 66, &ld->our_nodeid); /* Accessed in peer destructor sanity check */ ld->htlcs_in = tal(ld, struct htlc_in_map); htlc_in_map_init(ld->htlcs_in); diff --git a/wallet/wallet.c b/wallet/wallet.c index 93eb22fcb..ef0ec38d5 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -2416,7 +2416,7 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) db_bind_u64(stmt, chan->channel_info.their_config.id); /* Any pubkey works here: use our own node id */ if (chan->has_future_per_commitment_point) - db_bind_node_id(stmt, &chan->peer->ld->id); + db_bind_node_id(stmt, &chan->peer->ld->our_nodeid); else db_bind_null(stmt); db_bind_u64(stmt, chan->dbid); @@ -4237,14 +4237,14 @@ bool wallet_sanity_check(struct wallet *w) db_col_node_id(stmt, "blobval", &id); tal_free(stmt); - if (!node_id_eq(&id, &w->ld->id)) { + if (!node_id_eq(&id, &w->ld->our_nodeid)) { log_broken(w->log, "Wallet node_id does not " "match HSM: %s " "!= %s. " "Did your hsm_secret change?", fmt_node_id(tmpctx, &id), fmt_node_id(tmpctx, - &w->ld->id)); + &w->ld->our_nodeid)); return false; } } else { @@ -4252,7 +4252,7 @@ bool wallet_sanity_check(struct wallet *w) /* Still a pristine wallet, claim it for the node_id we are now */ stmt = db_prepare_v2(w->db, SQL("INSERT INTO vars (name, blobval) " "VALUES ('node_id', ?);")); - db_bind_node_id(stmt, &w->ld->id); + db_bind_node_id(stmt, &w->ld->our_nodeid); db_exec_prepared_v2(take(stmt)); } return true;