Browse Source

Use node_id everywhere for nodes.

I tried to just do gossipd, but it was uncontainable, so this ended up being
a complete sweep.

We didn't get much space saving in gossipd, even though we should save
24 bytes per node.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
pr-2587
Rusty Russell 6 years ago
committed by neil saitug
parent
commit
a2fa699e0e
  1. 1
      channeld/Makefile
  2. 4
      channeld/channel_wire.csv
  3. 25
      channeld/channeld.c
  4. 34
      common/bolt11.c
  5. 8
      common/bolt11.h
  6. 21
      common/test/run-bolt11.c
  7. 6
      common/test/run-funding_tx.c
  8. 4
      common/utxo.c
  9. 3
      common/utxo.h
  10. 1
      connectd/Makefile
  11. 4
      connectd/connect_gossip_wire.csv
  12. 12
      connectd/connect_wire.csv
  13. 133
      connectd/connectd.c
  14. 3
      connectd/connectd.h
  15. 6
      connectd/peer_exchange_initmsg.c
  16. 4
      connectd/peer_exchange_initmsg.h
  17. 1
      devtools/Makefile
  18. 4
      devtools/bolt11-cli.c
  19. 1
      gossipd/Makefile
  20. 4
      gossipd/gossip_constants.h
  21. 2
      gossipd/gossip_peerd_wire.csv
  22. 24
      gossipd/gossip_wire.csv
  23. 104
      gossipd/gossipd.c
  24. 145
      gossipd/routing.c
  25. 28
      gossipd/routing.h
  26. 1
      gossipd/test/Makefile
  27. 30
      gossipd/test/run-bench-find_route.c
  28. 30
      gossipd/test/run-find_route-specific.c
  29. 53
      gossipd/test/run-find_route.c
  30. 1
      hsmd/Makefile
  31. 10
      hsmd/hsm_wire.csv
  32. 30
      hsmd/hsmd.c
  33. 8
      lightningd/channel.c
  34. 4
      lightningd/channel.h
  35. 24
      lightningd/connect_control.c
  36. 2
      lightningd/connect_control.h
  37. 55
      lightningd/gossip_control.c
  38. 20
      lightningd/gossip_msg.c
  39. 6
      lightningd/gossip_msg.h
  40. 8
      lightningd/hsm_control.c
  41. 4
      lightningd/hsm_control.h
  42. 8
      lightningd/invoice.c
  43. 2
      lightningd/json.c
  44. 2
      lightningd/lightningd.c
  45. 2
      lightningd/lightningd.h
  46. 8
      lightningd/notification.c
  47. 4
      lightningd/notification.h
  48. 8
      lightningd/opening_control.c
  49. 9
      lightningd/options.c
  50. 63
      lightningd/pay.c
  51. 64
      lightningd/peer_control.c
  52. 7
      lightningd/peer_control.h
  53. 10
      lightningd/peer_htlcs.c
  54. 14
      lightningd/ping.c
  55. 61
      lightningd/test/run-invoice-select-inchan.c
  56. 14
      plugins/pay.c
  57. 1
      wallet/test/Makefile
  58. 3
      wallet/test/run-db.c
  59. 71
      wallet/test/run-wallet.c
  60. 30
      wallet/wallet.c
  61. 10
      wallet/wallet.h
  62. 2
      wallet/walletrpc.c
  63. 2
      wire/towire.c

1
channeld/Makefile

@ -56,6 +56,7 @@ CHANNELD_COMMON_OBJS := \
common/key_derive.o \ common/key_derive.o \
common/memleak.o \ common/memleak.o \
common/msg_queue.o \ common/msg_queue.o \
common/node_id.o \
common/peer_billboard.o \ common/peer_billboard.o \
common/peer_failed.o \ common/peer_failed.o \
common/permute_tx.o \ common/permute_tx.o \

4
channeld/channel_wire.csv

@ -27,8 +27,8 @@ channel_init,,fee_proportional,u32
channel_init,,local_msatoshi,struct amount_msat channel_init,,local_msatoshi,struct amount_msat
channel_init,,our_basepoints,struct basepoints channel_init,,our_basepoints,struct basepoints
channel_init,,our_funding_pubkey,struct pubkey channel_init,,our_funding_pubkey,struct pubkey
channel_init,,local_node_id,struct pubkey channel_init,,local_node_id,struct node_id
channel_init,,remote_node_id,struct pubkey channel_init,,remote_node_id,struct node_id
channel_init,,commit_msec,u32 channel_init,,commit_msec,u32
channel_init,,cltv_delta,u16 channel_init,,cltv_delta,u16
channel_init,,last_was_revoke,bool channel_init,,last_was_revoke,bool

Can't render this file because it has a wrong number of fields in line 6.

25
channeld/channeld.c

@ -33,6 +33,7 @@
#include <common/key_derive.h> #include <common/key_derive.h>
#include <common/memleak.h> #include <common/memleak.h>
#include <common/msg_queue.h> #include <common/msg_queue.h>
#include <common/node_id.h>
#include <common/peer_billboard.h> #include <common/peer_billboard.h>
#include <common/peer_failed.h> #include <common/peer_failed.h>
#include <common/ping.h> #include <common/ping.h>
@ -117,7 +118,7 @@ struct peer {
u32 desired_feerate; u32 desired_feerate;
/* Announcement related information */ /* Announcement related information */
struct pubkey node_ids[NUM_SIDES]; struct node_id node_ids[NUM_SIDES];
struct short_channel_id short_channel_ids[NUM_SIDES]; struct short_channel_id short_channel_ids[NUM_SIDES];
secp256k1_ecdsa_signature announcement_node_sigs[NUM_SIDES]; secp256k1_ecdsa_signature announcement_node_sigs[NUM_SIDES];
secp256k1_ecdsa_signature announcement_bitcoin_sigs[NUM_SIDES]; secp256k1_ecdsa_signature announcement_bitcoin_sigs[NUM_SIDES];
@ -343,6 +344,7 @@ static void send_announcement_signatures(struct peer *peer)
size_t offset = 258; size_t offset = 258;
struct sha256_double hash; struct sha256_double hash;
const u8 *msg, *ca, *req; const u8 *msg, *ca, *req;
struct pubkey mykey;
status_trace("Exchanging announcement signatures."); status_trace("Exchanging announcement signatures.");
ca = create_channel_announcement(tmpctx, peer); ca = create_channel_announcement(tmpctx, peer);
@ -358,8 +360,13 @@ static void send_announcement_signatures(struct peer *peer)
/* Double-check that HSM gave valid signatures. */ /* Double-check that HSM gave valid signatures. */
sha256_double(&hash, ca + offset, tal_count(ca) - offset); sha256_double(&hash, ca + offset, tal_count(ca) - offset);
if (!pubkey_from_node_id(&mykey, &peer->node_ids[LOCAL]))
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Could not convert my id '%s' to pubkey",
type_to_string(tmpctx, struct node_id,
&peer->node_ids[LOCAL]));
if (!check_signed_hash(&hash, &peer->announcement_node_sigs[LOCAL], if (!check_signed_hash(&hash, &peer->announcement_node_sigs[LOCAL],
&peer->node_ids[LOCAL])) { &mykey)) {
/* It's ok to fail here, the channel announcement is /* It's ok to fail here, the channel announcement is
* unique, unlike the channel update which may have * unique, unlike the channel update which may have
* been replaced in the meantime. */ * been replaced in the meantime. */
@ -399,6 +406,12 @@ static u8 *create_channel_announcement(const tal_t *ctx, struct peer *peer)
second = LOCAL; second = LOCAL;
} }
/* FIXME */
struct pubkey pk1, pk2;
if (!pubkey_from_node_id(&pk1, &peer->node_ids[first])
|| !pubkey_from_node_id(&pk2, &peer->node_ids[second]))
abort();
cannounce = towire_channel_announcement( cannounce = towire_channel_announcement(
ctx, &peer->announcement_node_sigs[first], ctx, &peer->announcement_node_sigs[first],
&peer->announcement_node_sigs[second], &peer->announcement_node_sigs[second],
@ -406,8 +419,8 @@ static u8 *create_channel_announcement(const tal_t *ctx, struct peer *peer)
&peer->announcement_bitcoin_sigs[second], &peer->announcement_bitcoin_sigs[second],
features, features,
&peer->chain_hash, &peer->chain_hash,
&peer->short_channel_ids[LOCAL], &peer->node_ids[first], &peer->short_channel_ids[LOCAL], &pk1,
&peer->node_ids[second], &peer->channel->funding_pubkey[first], &pk2, &peer->channel->funding_pubkey[first],
&peer->channel->funding_pubkey[second]); &peer->channel->funding_pubkey[second]);
tal_free(features); tal_free(features);
return cannounce; return cannounce;
@ -2883,8 +2896,8 @@ static void init_channel(struct peer *peer)
tal_free(failed); tal_free(failed);
tal_free(failed_sides); tal_free(failed_sides);
peer->channel_direction = get_channel_direction( peer->channel_direction = node_id_idx(&peer->node_ids[LOCAL],
&peer->node_ids[LOCAL], &peer->node_ids[REMOTE]); &peer->node_ids[REMOTE]);
/* Default desired feerate is the feerate we set for them last. */ /* Default desired feerate is the feerate we set for them last. */
if (peer->channel->funder == LOCAL) if (peer->channel->funder == LOCAL)

34
common/bolt11.c

@ -279,8 +279,6 @@ static char *decode_n(struct bolt11 *b11,
u5 **data, size_t *data_len, u5 **data, size_t *data_len,
size_t data_length, bool *have_n) size_t data_length, bool *have_n)
{ {
u8 der[PUBKEY_CMPR_LEN];
if (*have_n) if (*have_n)
return unknown_field(b11, hu5, data, data_len, 'n', return unknown_field(b11, hu5, data, data_len, 'n',
data_length); data_length);
@ -294,10 +292,12 @@ static char *decode_n(struct bolt11 *b11,
return unknown_field(b11, hu5, data, data_len, 'n', return unknown_field(b11, hu5, data, data_len, 'n',
data_length); data_length);
pull_bits_certain(hu5, data, data_len, der, data_length * 5, false); pull_bits_certain(hu5, data, data_len, &b11->receiver_id.k,
if (!pubkey_from_der(der, sizeof(der), &b11->receiver_id)) data_length * 5, false);
return tal_fmt(b11, "n: invalid pubkey %.*s", if (!node_id_valid(&b11->receiver_id))
(int)sizeof(der), der); return tal_fmt(b11, "n: invalid pubkey %s",
type_to_string(tmpctx, struct node_id,
&b11->receiver_id));
*have_n = true; *have_n = true;
return NULL; return NULL;
@ -377,7 +377,7 @@ static char *decode_f(struct bolt11 *b11,
static bool fromwire_route_info(const u8 **cursor, size_t *max, static bool fromwire_route_info(const u8 **cursor, size_t *max,
struct route_info *route_info) struct route_info *route_info)
{ {
fromwire_pubkey(cursor, max, &route_info->pubkey); fromwire_node_id(cursor, max, &route_info->pubkey);
fromwire_short_channel_id(cursor, max, &route_info->short_channel_id); fromwire_short_channel_id(cursor, max, &route_info->short_channel_id);
route_info->fee_base_msat = fromwire_u32(cursor, max); route_info->fee_base_msat = fromwire_u32(cursor, max);
route_info->fee_proportional_millionths = fromwire_u32(cursor, max); route_info->fee_proportional_millionths = fromwire_u32(cursor, max);
@ -387,7 +387,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) static void towire_route_info(u8 **pptr, const struct route_info *route_info)
{ {
towire_pubkey(pptr, &route_info->pubkey); 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_base_msat);
towire_u32(pptr, route_info->fee_proportional_millionths); towire_u32(pptr, route_info->fee_proportional_millionths);
@ -697,16 +697,22 @@ struct bolt11 *bolt11_decode(const tal_t *ctx, const char *str,
* performing signature recovery. * performing signature recovery.
*/ */
if (!have_n) { if (!have_n) {
struct pubkey k;
if (!secp256k1_ecdsa_recover(secp256k1_ctx, if (!secp256k1_ecdsa_recover(secp256k1_ctx,
&b11->receiver_id.pubkey, &k.pubkey,
&sig, &sig,
(const u8 *)&hash)) (const u8 *)&hash))
return decode_fail(b11, fail, return decode_fail(b11, fail,
"signature recovery failed"); "signature recovery failed");
node_id_from_pubkey(&b11->receiver_id, &k);
} else { } else {
struct pubkey k;
/* n parsing checked this! */
if (!pubkey_from_node_id(&k, &b11->receiver_id))
abort();
if (!secp256k1_ecdsa_verify(secp256k1_ctx, &b11->sig, if (!secp256k1_ecdsa_verify(secp256k1_ctx, &b11->sig,
(const u8 *)&hash, (const u8 *)&hash,
&b11->receiver_id.pubkey)) &k.pubkey))
return decode_fail(b11, fail, "invalid signature"); return decode_fail(b11, fail, "invalid signature");
} }
@ -785,12 +791,10 @@ static void encode_h(u5 **data, const struct sha256 *hash)
push_field(data, 'h', hash, 256); push_field(data, 'h', hash, 256);
} }
static void encode_n(u5 **data, const struct pubkey *id) static void encode_n(u5 **data, const struct node_id *id)
{ {
u8 der[PUBKEY_CMPR_LEN]; assert(node_id_valid(id));
push_field(data, 'n', id->k, sizeof(id->k) * CHAR_BIT);
pubkey_to_der(der, id);
push_field(data, 'n', der, sizeof(der) * CHAR_BIT);
} }
static void encode_x(u5 **data, u64 expiry) static void encode_x(u5 **data, u64 expiry)

8
common/bolt11.h

@ -8,6 +8,7 @@
#include <ccan/short_types/short_types.h> #include <ccan/short_types/short_types.h>
#include <ccan/take/take.h> #include <ccan/take/take.h>
#include <common/hash_u5.h> #include <common/hash_u5.h>
#include <common/node_id.h>
#include <secp256k1_recovery.h> #include <secp256k1_recovery.h>
/* We only have 10 bits for the field length, meaning < 640 bytes */ /* We only have 10 bits for the field length, meaning < 640 bytes */
@ -29,10 +30,11 @@ struct bolt11_field {
*/ */
struct route_info { struct route_info {
struct pubkey pubkey; /* This is 33 bytes, so we pack cltv_expiry_delta next to it */
struct node_id pubkey;
u16 cltv_expiry_delta;
struct short_channel_id short_channel_id; struct short_channel_id short_channel_id;
u32 fee_base_msat, fee_proportional_millionths; u32 fee_base_msat, fee_proportional_millionths;
u16 cltv_expiry_delta;
}; };
struct bolt11 { struct bolt11 {
@ -41,7 +43,7 @@ struct bolt11 {
struct amount_msat *msat; /* NULL if not specified. */ struct amount_msat *msat; /* NULL if not specified. */
struct sha256 payment_hash; struct sha256 payment_hash;
struct pubkey receiver_id; struct node_id receiver_id;
/* description_hash valid if and only if description is NULL. */ /* description_hash valid if and only if description is NULL. */
const char *description; const char *description;

21
common/test/run-bolt11.c

@ -2,6 +2,7 @@
#include "../bech32.c" #include "../bech32.c"
#include "../bech32_util.c" #include "../bech32_util.c"
#include "../bolt11.c" #include "../bolt11.c"
#include "../node_id.c"
#include "../hash_u5.c" #include "../hash_u5.c"
#include <ccan/err/err.h> #include <ccan/err/err.h>
#include <ccan/mem/mem.h> #include <ccan/mem/mem.h>
@ -10,9 +11,9 @@
#include <wally_core.h> #include <wally_core.h>
/* AUTOGENERATED MOCKS START */ /* AUTOGENERATED MOCKS START */
/* Generated stub for fromwire_pubkey */ /* Generated stub for fromwire_node_id */
void fromwire_pubkey(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct pubkey *pubkey UNNEEDED) void fromwire_node_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct node_id *id UNNEEDED)
{ fprintf(stderr, "fromwire_pubkey called!\n"); abort(); } { fprintf(stderr, "fromwire_node_id called!\n"); abort(); }
/* Generated stub for fromwire_short_channel_id */ /* Generated stub for fromwire_short_channel_id */
void fromwire_short_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, void fromwire_short_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct short_channel_id *short_channel_id UNNEEDED) struct short_channel_id *short_channel_id UNNEEDED)
@ -23,9 +24,9 @@ u16 fromwire_u16(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
/* Generated stub for fromwire_u32 */ /* Generated stub for fromwire_u32 */
u32 fromwire_u32(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) u32 fromwire_u32(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_u32 called!\n"); abort(); } { fprintf(stderr, "fromwire_u32 called!\n"); abort(); }
/* Generated stub for towire_pubkey */ /* Generated stub for towire_node_id */
void towire_pubkey(u8 **pptr UNNEEDED, const struct pubkey *pubkey UNNEEDED) void towire_node_id(u8 **pptr UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "towire_pubkey called!\n"); abort(); } { fprintf(stderr, "towire_node_id called!\n"); abort(); }
/* Generated stub for towire_short_channel_id */ /* Generated stub for towire_short_channel_id */
void towire_short_channel_id(u8 **pptr UNNEEDED, void towire_short_channel_id(u8 **pptr UNNEEDED,
const struct short_channel_id *short_channel_id UNNEEDED) const struct short_channel_id *short_channel_id UNNEEDED)
@ -36,6 +37,10 @@ void towire_u16(u8 **pptr UNNEEDED, u16 v UNNEEDED)
/* Generated stub for towire_u32 */ /* Generated stub for towire_u32 */
void towire_u32(u8 **pptr UNNEEDED, u32 v UNNEEDED) void towire_u32(u8 **pptr UNNEEDED, u32 v UNNEEDED)
{ fprintf(stderr, "towire_u32 called!\n"); abort(); } { fprintf(stderr, "towire_u32 called!\n"); abort(); }
/* Generated stub for type_to_string_ */
const char *type_to_string_(const tal_t *ctx UNNEEDED, const char *typename UNNEEDED,
union printable_types u UNNEEDED)
{ fprintf(stderr, "type_to_string_ called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */ /* AUTOGENERATED MOCKS END */
static struct privkey privkey; static struct privkey privkey;
@ -120,7 +125,7 @@ int main(void)
setup_locale(); setup_locale();
struct bolt11 *b11; struct bolt11 *b11;
struct pubkey node; struct node_id node;
struct amount_msat msatoshi; struct amount_msat msatoshi;
const char *badstr; const char *badstr;
@ -144,7 +149,7 @@ int main(void)
* > ### Please make a donation of any amount using payment_hash 0001020304050607080900010203040506070809000102030405060708090102 to me @03e7156ae33b0a208d0744199163177e909e80176e55d97a2f221ede0f934dd9ad * > ### Please make a donation of any amount using payment_hash 0001020304050607080900010203040506070809000102030405060708090102 to me @03e7156ae33b0a208d0744199163177e909e80176e55d97a2f221ede0f934dd9ad
* > lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d73gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ecky03ylcqca784w * > lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d73gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ecky03ylcqca784w
*/ */
if (!pubkey_from_hexstr("03e7156ae33b0a208d0744199163177e909e80176e55d97a2f221ede0f934dd9ad", strlen("03e7156ae33b0a208d0744199163177e909e80176e55d97a2f221ede0f934dd9ad"), &node)) if (!node_id_from_hexstr("03e7156ae33b0a208d0744199163177e909e80176e55d97a2f221ede0f934dd9ad", strlen("03e7156ae33b0a208d0744199163177e909e80176e55d97a2f221ede0f934dd9ad"), &node))
abort(); abort();
/* BOLT #11: /* BOLT #11:

6
common/test/run-funding_tx.c

@ -28,6 +28,9 @@ void fromwire_bitcoin_txid(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
/* Generated stub for fromwire_bool */ /* Generated stub for fromwire_bool */
bool fromwire_bool(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) bool fromwire_bool(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_bool called!\n"); abort(); } { fprintf(stderr, "fromwire_bool called!\n"); abort(); }
/* Generated stub for fromwire_node_id */
void fromwire_node_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct node_id *id UNNEEDED)
{ fprintf(stderr, "fromwire_node_id called!\n"); abort(); }
/* Generated stub for fromwire_pubkey */ /* Generated stub for fromwire_pubkey */
void fromwire_pubkey(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct pubkey *pubkey UNNEEDED) void fromwire_pubkey(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct pubkey *pubkey UNNEEDED)
{ fprintf(stderr, "fromwire_pubkey called!\n"); abort(); } { fprintf(stderr, "fromwire_pubkey called!\n"); abort(); }
@ -46,6 +49,9 @@ void towire_bitcoin_txid(u8 **pptr UNNEEDED, const struct bitcoin_txid *txid UNN
/* Generated stub for towire_bool */ /* Generated stub for towire_bool */
void towire_bool(u8 **pptr UNNEEDED, bool v UNNEEDED) void towire_bool(u8 **pptr UNNEEDED, bool v UNNEEDED)
{ fprintf(stderr, "towire_bool called!\n"); abort(); } { fprintf(stderr, "towire_bool called!\n"); abort(); }
/* Generated stub for towire_node_id */
void towire_node_id(u8 **pptr UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "towire_node_id called!\n"); abort(); }
/* Generated stub for towire_pubkey */ /* Generated stub for towire_pubkey */
void towire_pubkey(u8 **pptr UNNEEDED, const struct pubkey *pubkey UNNEEDED) void towire_pubkey(u8 **pptr UNNEEDED, const struct pubkey *pubkey UNNEEDED)
{ fprintf(stderr, "towire_pubkey called!\n"); abort(); } { fprintf(stderr, "towire_pubkey called!\n"); abort(); }

4
common/utxo.c

@ -17,7 +17,7 @@ void towire_utxo(u8 **pptr, const struct utxo *utxo)
towire_bool(pptr, is_unilateral_close); towire_bool(pptr, is_unilateral_close);
if (is_unilateral_close) { if (is_unilateral_close) {
towire_u64(pptr, utxo->close_info->channel_id); towire_u64(pptr, utxo->close_info->channel_id);
towire_pubkey(pptr, &utxo->close_info->peer_id); towire_node_id(pptr, &utxo->close_info->peer_id);
towire_pubkey(pptr, &utxo->close_info->commitment_point); towire_pubkey(pptr, &utxo->close_info->commitment_point);
} }
} }
@ -39,7 +39,7 @@ struct utxo *fromwire_utxo(const tal_t *ctx, const u8 **ptr, size_t *max)
if (fromwire_bool(ptr, max)) { if (fromwire_bool(ptr, max)) {
utxo->close_info = tal(utxo, struct unilateral_close_info); utxo->close_info = tal(utxo, struct unilateral_close_info);
utxo->close_info->channel_id = fromwire_u64(ptr, max); utxo->close_info->channel_id = fromwire_u64(ptr, max);
fromwire_pubkey(ptr, max, &utxo->close_info->peer_id); fromwire_node_id(ptr, max, &utxo->close_info->peer_id);
fromwire_pubkey(ptr, max, &utxo->close_info->commitment_point); fromwire_pubkey(ptr, max, &utxo->close_info->commitment_point);
} else { } else {
utxo->close_info = NULL; utxo->close_info = NULL;

3
common/utxo.h

@ -7,6 +7,7 @@
#include <ccan/short_types/short_types.h> #include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h> #include <ccan/tal/tal.h>
#include <common/amount.h> #include <common/amount.h>
#include <common/node_id.h>
#include <stdbool.h> #include <stdbool.h>
struct ext_key; struct ext_key;
@ -14,7 +15,7 @@ struct ext_key;
/* Information needed for their_unilateral/to-us outputs */ /* Information needed for their_unilateral/to-us outputs */
struct unilateral_close_info { struct unilateral_close_info {
u64 channel_id; u64 channel_id;
struct pubkey peer_id; struct node_id peer_id;
struct pubkey commitment_point; struct pubkey commitment_point;
}; };

1
connectd/Makefile

@ -53,6 +53,7 @@ CONNECTD_COMMON_OBJS := \
common/key_derive.o \ common/key_derive.o \
common/memleak.o \ common/memleak.o \
common/msg_queue.o \ common/msg_queue.o \
common/node_id.o \
common/pseudorand.o \ common/pseudorand.o \
common/status.o \ common/status.o \
common/status_wire.o \ common/status_wire.o \

4
connectd/connect_gossip_wire.csv

@ -2,7 +2,7 @@
# Communication between gossipd and connectd. # Communication between gossipd and connectd.
gossip_new_peer,4000 gossip_new_peer,4000
gossip_new_peer,,id,struct pubkey gossip_new_peer,,id,struct node_id
# Did we negotiate LOCAL_GOSSIP_QUERIES? # Did we negotiate LOCAL_GOSSIP_QUERIES?
gossip_new_peer,,gossip_queries_feature,bool gossip_new_peer,,gossip_queries_feature,bool
# Did they offer LOCAL_INITIAL_ROUTING_SYNC? # Did they offer LOCAL_INITIAL_ROUTING_SYNC?
@ -14,7 +14,7 @@ gossip_new_peer_reply,,success,bool
# Connectd asks gossipd for any known addresses for that node. # Connectd asks gossipd for any known addresses for that node.
gossip_get_addrs,4001 gossip_get_addrs,4001
gossip_get_addrs,,id,struct pubkey gossip_get_addrs,,id,struct node_id
gossip_get_addrs_reply,4101 gossip_get_addrs_reply,4101
gossip_get_addrs_reply,,num,u16 gossip_get_addrs_reply,,num,u16

Can't render this file because it has a wrong number of fields in line 4.

12
connectd/connect_wire.csv

@ -3,7 +3,7 @@
#include <lightningd/gossip_msg.h> #include <lightningd/gossip_msg.h>
connectctl_init,2000 connectctl_init,2000
connectctl_init,,id,struct pubkey connectctl_init,,id,struct node_id
connectctl_init,,num_wireaddrs,u16 connectctl_init,,num_wireaddrs,u16
connectctl_init,,wireaddrs,num_wireaddrs*struct wireaddr_internal connectctl_init,,wireaddrs,num_wireaddrs*struct wireaddr_internal
connectctl_init,,listen_announce,num_wireaddrs*enum addr_listen_announce connectctl_init,,listen_announce,num_wireaddrs*enum addr_listen_announce
@ -30,24 +30,24 @@ connectctl_activate_reply,2125
# connectd->master: disconnect this peer please (due to reconnect). # connectd->master: disconnect this peer please (due to reconnect).
connect_reconnected,2112 connect_reconnected,2112
connect_reconnected,,id,struct pubkey connect_reconnected,,id,struct node_id
# Master -> connectd: connect to a peer. # Master -> connectd: connect to a peer.
connectctl_connect_to_peer,2001 connectctl_connect_to_peer,2001
connectctl_connect_to_peer,,id,struct pubkey connectctl_connect_to_peer,,id,struct node_id
connectctl_connect_to_peer,,seconds_waited,u32 connectctl_connect_to_peer,,seconds_waited,u32
connectctl_connect_to_peer,,addrhint,?struct wireaddr_internal connectctl_connect_to_peer,,addrhint,?struct wireaddr_internal
# Connectd->master: connect failed. # Connectd->master: connect failed.
connectctl_connect_failed,2020 connectctl_connect_failed,2020
connectctl_connect_failed,,id,struct pubkey connectctl_connect_failed,,id,struct node_id
connectctl_connect_failed,,failreason,wirestring connectctl_connect_failed,,failreason,wirestring
connectctl_connect_failed,,seconds_to_delay,u32 connectctl_connect_failed,,seconds_to_delay,u32
connectctl_connect_failed,,addrhint,?struct wireaddr_internal connectctl_connect_failed,,addrhint,?struct wireaddr_internal
# Connectd -> master: we got a peer. Two fds: peer and gossip # Connectd -> master: we got a peer. Two fds: peer and gossip
connect_peer_connected,2002 connect_peer_connected,2002
connect_peer_connected,,id,struct pubkey connect_peer_connected,,id,struct node_id
connect_peer_connected,,addr,struct wireaddr_internal connect_peer_connected,,addr,struct wireaddr_internal
connect_peer_connected,,crypto_state,struct crypto_state connect_peer_connected,,crypto_state,struct crypto_state
connect_peer_connected,,gflen,u16 connect_peer_connected,,gflen,u16
@ -57,7 +57,7 @@ connect_peer_connected,,localfeatures,lflen*u8
# master -> connectd: peer has disconnected. # master -> connectd: peer has disconnected.
connectctl_peer_disconnected,2015 connectctl_peer_disconnected,2015
connectctl_peer_disconnected,,id,struct pubkey connectctl_peer_disconnected,,id,struct node_id
# master -> connectd: do you have a memleak? # master -> connectd: do you have a memleak?
connect_dev_memleak,2033 connect_dev_memleak,2033

Can't render this file because it has a wrong number of fields in line 5.

133
connectd/connectd.c

@ -7,6 +7,7 @@
* up to lightningd which will fire up a specific per-peer daemon to talk to * up to lightningd which will fire up a specific per-peer daemon to talk to
* it. * it.
*/ */
#include <ccan/array_size/array_size.h>
#include <ccan/asort/asort.h> #include <ccan/asort/asort.h>
#include <ccan/build_assert/build_assert.h> #include <ccan/build_assert/build_assert.h>
#include <ccan/cast/cast.h> #include <ccan/cast/cast.h>
@ -86,9 +87,9 @@
* peers are already connected. The HTABLE_DEFINE_TYPE() macro needs a * peers are already connected. The HTABLE_DEFINE_TYPE() macro needs a
* keyof() function to extract the key. For this simple use case, that's the * keyof() function to extract the key. For this simple use case, that's the
* identity function: */ * identity function: */
static const struct pubkey *pubkey_keyof(const struct pubkey *pk) static const struct node_id *node_id_keyof(const struct node_id *pc)
{ {
return pk; return pc;
} }
/*~ We also need to define a hashing function. siphash24 is a fast yet /*~ We also need to define a hashing function. siphash24 is a fast yet
@ -97,26 +98,29 @@ static const struct pubkey *pubkey_keyof(const struct pubkey *pk)
* use this unless it's a proven bottleneck. siphash_seed() is a function in * use this unless it's a proven bottleneck. siphash_seed() is a function in
* common/pseudorand which sets up a seed for our hashing; it's different * common/pseudorand which sets up a seed for our hashing; it's different
* every time the program is run. */ * every time the program is run. */
static size_t pubkey_hash(const struct pubkey *id) static size_t node_id_hash(const struct node_id *id)
{ {
return siphash24(siphash_seed(), id, sizeof(*id)); return siphash24(siphash_seed(), id->k, sizeof(id->k));
} }
/*~ This defines 'struct pubkey_set' which contains 'struct pubkey' pointers. */ /*~ This defines 'struct node_set' which contains 'struct node_id' pointers. */
HTABLE_DEFINE_TYPE(struct pubkey, HTABLE_DEFINE_TYPE(struct node_id,
pubkey_keyof, node_id_keyof,
pubkey_hash, node_id_hash,
pubkey_eq, node_id_eq,
pubkey_set); node_set);
/*~ This is the global state, like `struct lightningd *ld` in lightningd. */ /*~ This is the global state, like `struct lightningd *ld` in lightningd. */
struct daemon { struct daemon {
/* Who am I? */ /* Who am I? */
struct pubkey id; struct node_id id;
/* pubkey equivalent. */
struct pubkey mykey;
/* Peers that we've handed to `lightningd`, which it hasn't told us /* Peers that we've handed to `lightningd`, which it hasn't told us
* have disconnected. */ * have disconnected. */
struct pubkey_set peers; struct node_set peers;
/* Peers we are trying to reach */ /* Peers we are trying to reach */
struct list_head connecting; struct list_head connecting;
@ -155,7 +159,7 @@ struct connecting {
struct daemon *daemon; struct daemon *daemon;
/* The ID of the peer (not necessarily unique, in transit!) */ /* The ID of the peer (not necessarily unique, in transit!) */
struct pubkey id; struct node_id id;
/* We iterate through the tal_count(addrs) */ /* We iterate through the tal_count(addrs) */
size_t addrnum; size_t addrnum;
@ -236,7 +240,7 @@ static void destroy_connecting(struct connecting *connect)
/*~ Most simple search functions start with find_; in this case, search /*~ Most simple search functions start with find_; in this case, search
* for an existing attempt to connect the given peer id. */ * for an existing attempt to connect the given peer id. */
static struct connecting *find_connecting(struct daemon *daemon, static struct connecting *find_connecting(struct daemon *daemon,
const struct pubkey *id) const struct node_id *id)
{ {
struct connecting *i; struct connecting *i;
@ -246,7 +250,7 @@ static struct connecting *find_connecting(struct daemon *daemon,
* members (unnecessary here, as there's no padding in a `struct * members (unnecessary here, as there's no padding in a `struct
* pubkey`). */ * pubkey`). */
list_for_each(&daemon->connecting, i, list) list_for_each(&daemon->connecting, i, list)
if (pubkey_eq(id, &i->id)) if (node_id_eq(id, &i->id))
return i; return i;
return NULL; return NULL;
} }
@ -255,7 +259,7 @@ static struct connecting *find_connecting(struct daemon *daemon,
* to try the next address. */ * to try the next address. */
static void connected_to_peer(struct daemon *daemon, static void connected_to_peer(struct daemon *daemon,
struct io_conn *conn, struct io_conn *conn,
const struct pubkey *id) const struct node_id *id)
{ {
/* Don't call destroy_io_conn */ /* Don't call destroy_io_conn */
io_set_finish(conn, NULL, NULL); io_set_finish(conn, NULL, NULL);
@ -277,7 +281,7 @@ static void connected_to_peer(struct daemon *daemon,
* when you're connected to it like we are: there are also 'globalfeatures' * when you're connected to it like we are: there are also 'globalfeatures'
* which specify requirements to route a payment through a node. */ * which specify requirements to route a payment through a node. */
static int get_gossipfd(struct daemon *daemon, static int get_gossipfd(struct daemon *daemon,
const struct pubkey *id, const struct node_id *id,
const u8 *localfeatures) const u8 *localfeatures)
{ {
bool gossip_queries_feature, initial_routing_sync, success; bool gossip_queries_feature, initial_routing_sync, success;
@ -313,7 +317,7 @@ static int get_gossipfd(struct daemon *daemon,
* give up on connecting this peer. */ * give up on connecting this peer. */
if (!success) { if (!success) {
status_broken("Gossipd did not give us an fd: losing peer %s", status_broken("Gossipd did not give us an fd: losing peer %s",
type_to_string(tmpctx, struct pubkey, id)); type_to_string(tmpctx, struct node_id, id));
return -1; return -1;
} }
@ -326,7 +330,7 @@ static int get_gossipfd(struct daemon *daemon,
* can call peer_connected again. */ * can call peer_connected again. */
struct peer_reconnected { struct peer_reconnected {
struct daemon *daemon; struct daemon *daemon;
struct pubkey id; struct node_id id;
const u8 *peer_connected_msg; const u8 *peer_connected_msg;
const u8 *localfeatures; const u8 *localfeatures;
}; };
@ -341,7 +345,7 @@ static struct io_plan *retry_peer_connected(struct io_conn *conn,
/*~ As you can see, we've had issues with this code before :( */ /*~ As you can see, we've had issues with this code before :( */
status_trace("peer %s: processing now old peer gone", status_trace("peer %s: processing now old peer gone",
type_to_string(tmpctx, struct pubkey, &pr->id)); type_to_string(tmpctx, struct node_id, &pr->id));
/*~ Usually the pattern is to return this directly, but we have to free /*~ Usually the pattern is to return this directly, but we have to free
* our temporary structure. */ * our temporary structure. */
@ -356,7 +360,7 @@ static struct io_plan *retry_peer_connected(struct io_conn *conn,
* the old one. We wait until it tells us that's happened. */ * the old one. We wait until it tells us that's happened. */
static struct io_plan *peer_reconnected(struct io_conn *conn, static struct io_plan *peer_reconnected(struct io_conn *conn,
struct daemon *daemon, struct daemon *daemon,
const struct pubkey *id, const struct node_id *id,
const u8 *peer_connected_msg TAKES, const u8 *peer_connected_msg TAKES,
const u8 *localfeatures TAKES) const u8 *localfeatures TAKES)
{ {
@ -364,7 +368,7 @@ static struct io_plan *peer_reconnected(struct io_conn *conn,
struct peer_reconnected *pr; struct peer_reconnected *pr;
status_trace("peer %s: reconnect", status_trace("peer %s: reconnect",
type_to_string(tmpctx, struct pubkey, id)); type_to_string(tmpctx, struct node_id, id));
/* Tell master to kill it: will send peer_disconnect */ /* Tell master to kill it: will send peer_disconnect */
msg = towire_connect_reconnected(NULL, id); msg = towire_connect_reconnected(NULL, id);
@ -387,7 +391,7 @@ static struct io_plan *peer_reconnected(struct io_conn *conn,
/*~ ccan/io supports waiting on an address: in this case, the key in /*~ ccan/io supports waiting on an address: in this case, the key in
* the peer set. When someone calls `io_wake()` on that address, it * the peer set. When someone calls `io_wake()` on that address, it
* will call retry_peer_connected above. */ * will call retry_peer_connected above. */
return io_wait(conn, pubkey_set_get(&daemon->peers, id), return io_wait(conn, node_set_get(&daemon->peers, id),
/*~ The notleak() wrapper is a DEVELOPER-mode hack so /*~ The notleak() wrapper is a DEVELOPER-mode hack so
* that our memory leak detection doesn't consider 'pr' * that our memory leak detection doesn't consider 'pr'
* (which is not referenced from our code) to be a * (which is not referenced from our code) to be a
@ -399,13 +403,13 @@ static struct io_plan *peer_reconnected(struct io_conn *conn,
* INIT messages are exchanged, and also by the retry code above. */ * INIT messages are exchanged, and also by the retry code above. */
struct io_plan *peer_connected(struct io_conn *conn, struct io_plan *peer_connected(struct io_conn *conn,
struct daemon *daemon, struct daemon *daemon,
const struct pubkey *id, const struct node_id *id,
const u8 *peer_connected_msg TAKES, const u8 *peer_connected_msg TAKES,
const u8 *localfeatures TAKES) const u8 *localfeatures TAKES)
{ {
int gossip_fd; int gossip_fd;
if (pubkey_set_get(&daemon->peers, id)) if (node_set_get(&daemon->peers, id))
return peer_reconnected(conn, daemon, id, peer_connected_msg, return peer_reconnected(conn, daemon, id, peer_connected_msg,
localfeatures); localfeatures);
@ -432,7 +436,7 @@ struct io_plan *peer_connected(struct io_conn *conn,
/*~ Finally, we add it to the set of pubkeys: tal_dup will handle /*~ Finally, we add it to the set of pubkeys: tal_dup will handle
* take() args for us, by simply tal_steal()ing it. */ * take() args for us, by simply tal_steal()ing it. */
pubkey_set_add(&daemon->peers, tal_dup(daemon, struct pubkey, id)); node_set_add(&daemon->peers, tal_dup(daemon, struct node_id, id));
/*~ We want to free the connection, but not close the fd (which is /*~ We want to free the connection, but not close the fd (which is
* queued to go to lightningd), so use this variation on io_close: */ * queued to go to lightningd), so use this variation on io_close: */
@ -443,14 +447,16 @@ struct io_plan *peer_connected(struct io_conn *conn,
* in; we hand it straight to peer_exchange_initmsg() to send and receive INIT * in; we hand it straight to peer_exchange_initmsg() to send and receive INIT
* and call peer_connected(). */ * and call peer_connected(). */
static struct io_plan *handshake_in_success(struct io_conn *conn, static struct io_plan *handshake_in_success(struct io_conn *conn,
const struct pubkey *id, const struct pubkey *id_key,
const struct wireaddr_internal *addr, const struct wireaddr_internal *addr,
const struct crypto_state *cs, const struct crypto_state *cs,
struct daemon *daemon) struct daemon *daemon)
{ {
struct node_id id;
node_id_from_pubkey(&id, id_key);
status_trace("Connect IN from %s", status_trace("Connect IN from %s",
type_to_string(tmpctx, struct pubkey, id)); type_to_string(tmpctx, struct node_id, &id));
return peer_exchange_initmsg(conn, daemon, cs, id, addr); return peer_exchange_initmsg(conn, daemon, cs, &id, addr);
} }
/*~ When we get a connection in we set up its network address then call /*~ When we get a connection in we set up its network address then call
@ -494,31 +500,44 @@ static struct io_plan *connection_in(struct io_conn *conn, struct daemon *daemon
* Note, again, the notleak() to avoid our simplistic leak detection * Note, again, the notleak() to avoid our simplistic leak detection
* code from thinking `conn` (which we don't keep a pointer to) is * code from thinking `conn` (which we don't keep a pointer to) is
* leaked */ * leaked */
return responder_handshake(notleak(conn), &daemon->id, &addr, return responder_handshake(notleak(conn), &daemon->mykey, &addr,
handshake_in_success, daemon); handshake_in_success, daemon);
} }
/*~ These are the mirror functions for the connecting-out case. */ /*~ These are the mirror functions for the connecting-out case. */
static struct io_plan *handshake_out_success(struct io_conn *conn, static struct io_plan *handshake_out_success(struct io_conn *conn,
const struct pubkey *id, const struct pubkey *key,
const struct wireaddr_internal *addr, const struct wireaddr_internal *addr,
const struct crypto_state *cs, const struct crypto_state *cs,
struct connecting *connect) struct connecting *connect)
{ {
struct node_id id;
node_id_from_pubkey(&id, key);
connect->connstate = "Exchanging init messages"; connect->connstate = "Exchanging init messages";
status_trace("Connect OUT to %s", status_trace("Connect OUT to %s",
type_to_string(tmpctx, struct pubkey, id)); type_to_string(tmpctx, struct node_id, &id));
return peer_exchange_initmsg(conn, connect->daemon, cs, id, addr); return peer_exchange_initmsg(conn, connect->daemon, cs, &id, addr);
} }
struct io_plan *connection_out(struct io_conn *conn, struct connecting *connect) struct io_plan *connection_out(struct io_conn *conn, struct connecting *connect)
{ {
struct pubkey outkey;
/* This shouldn't happen: lightningd should not give invalid ids! */
if (!pubkey_from_node_id(&outkey, &connect->id)) {
status_broken("Connection out to invalid id %s",
type_to_string(tmpctx, struct node_id,
&connect->id));
return io_close(conn);
}
/* FIXME: Timeout */ /* FIXME: Timeout */
status_trace("Connected out for %s", status_trace("Connected out for %s",
type_to_string(tmpctx, struct pubkey, &connect->id)); type_to_string(tmpctx, struct node_id, &connect->id));
connect->connstate = "Cryptographic handshake"; connect->connstate = "Cryptographic handshake";
return initiator_handshake(conn, &connect->daemon->id, &connect->id, return initiator_handshake(conn, &connect->daemon->mykey, &outkey,
&connect->addrs[connect->addrnum], &connect->addrs[connect->addrnum],
handshake_out_success, connect); handshake_out_success, connect);
} }
@ -526,7 +545,7 @@ struct io_plan *connection_out(struct io_conn *conn, struct connecting *connect)
/*~ When we've exhausted all addresses without success, we come here. */ /*~ When we've exhausted all addresses without success, we come here. */
static void PRINTF_FMT(5,6) static void PRINTF_FMT(5,6)
connect_failed(struct daemon *daemon, connect_failed(struct daemon *daemon,
const struct pubkey *id, const struct node_id *id,
u32 seconds_waited, u32 seconds_waited,
const struct wireaddr_internal *addrhint, const struct wireaddr_internal *addrhint,
const char *errfmt, ...) const char *errfmt, ...)
@ -556,7 +575,7 @@ static void PRINTF_FMT(5,6)
daemon_conn_send(daemon->master, take(msg)); daemon_conn_send(daemon->master, take(msg));
status_trace("Failed connected out for %s: %s", status_trace("Failed connected out for %s: %s",
type_to_string(tmpctx, struct pubkey, id), type_to_string(tmpctx, struct node_id, id),
err); err);
} }
@ -1114,6 +1133,12 @@ static struct io_plan *connect_init(struct io_conn *conn,
master_badmsg(WIRE_CONNECTCTL_INIT, msg); master_badmsg(WIRE_CONNECTCTL_INIT, msg);
} }
if (!pubkey_from_node_id(&daemon->mykey, &daemon->id))
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Invalid id for me %s",
type_to_string(tmpctx, struct node_id,
&daemon->id));
/* Resolve Tor proxy address if any: we need an addrinfo to connect() /* Resolve Tor proxy address if any: we need an addrinfo to connect()
* to. */ * to. */
if (proxyaddr) { if (proxyaddr) {
@ -1188,14 +1213,12 @@ static struct io_plan *connect_activate(struct io_conn *conn,
} }
/*~ This is where we'd put a BOLT #10 reference, but it doesn't exist :( */ /*~ This is where we'd put a BOLT #10 reference, but it doesn't exist :( */
static const char *seedname(const tal_t *ctx, const struct pubkey *id) static const char *seedname(const tal_t *ctx, const struct node_id *id)
{ {
char bech32[100]; char bech32[100];
u8 der[PUBKEY_CMPR_LEN];
u5 *data = tal_arr(ctx, u5, 0); u5 *data = tal_arr(ctx, u5, 0);
pubkey_to_der(der, id); bech32_push_bits(&data, id->k, ARRAY_SIZE(id->k)*8);
bech32_push_bits(&data, der, PUBKEY_CMPR_LEN*8);
bech32_encode(bech32, "ln", data, tal_count(data), sizeof(bech32)); bech32_encode(bech32, "ln", data, tal_count(data), sizeof(bech32));
return tal_fmt(ctx, "%s.lseed.bitcoinstats.com", bech32); return tal_fmt(ctx, "%s.lseed.bitcoinstats.com", bech32);
} }
@ -1208,7 +1231,7 @@ static const char *seedname(const tal_t *ctx, const struct pubkey *id)
* has the nice property that DNS is cached, and the seed only sees a request * has the nice property that DNS is cached, and the seed only sees a request
* from the ISP, not directly from the user. */ * from the ISP, not directly from the user. */
static void add_seed_addrs(struct wireaddr_internal **addrs, static void add_seed_addrs(struct wireaddr_internal **addrs,
const struct pubkey *id, const struct node_id *id,
struct sockaddr *broken_reply) struct sockaddr *broken_reply)
{ {
struct wireaddr_internal a; struct wireaddr_internal a;
@ -1232,7 +1255,7 @@ static void add_seed_addrs(struct wireaddr_internal **addrs,
/*~ This asks gossipd for any addresses advertized by the node. */ /*~ This asks gossipd for any addresses advertized by the node. */
static void add_gossip_addrs(struct wireaddr_internal **addrs, static void add_gossip_addrs(struct wireaddr_internal **addrs,
const struct pubkey *id) const struct node_id *id)
{ {
u8 *msg; u8 *msg;
struct wireaddr *normal_addrs; struct wireaddr *normal_addrs;
@ -1266,7 +1289,7 @@ static void add_gossip_addrs(struct wireaddr_internal **addrs,
* That's a pretty ugly interface: we should use TAKEN, but we only have one * That's a pretty ugly interface: we should use TAKEN, but we only have one
* caller so it's marginal. */ * caller so it's marginal. */
static void try_connect_peer(struct daemon *daemon, static void try_connect_peer(struct daemon *daemon,
const struct pubkey *id, const struct node_id *id,
u32 seconds_waited, u32 seconds_waited,
struct wireaddr_internal *addrhint) struct wireaddr_internal *addrhint)
{ {
@ -1275,7 +1298,7 @@ static void try_connect_peer(struct daemon *daemon,
struct connecting *connect; struct connecting *connect;
/* Already done? May happen with timer. */ /* Already done? May happen with timer. */
if (pubkey_set_get(&daemon->peers, id)) if (node_set_get(&daemon->peers, id))
return; return;
/* If we're trying to connect it right now, that's OK. */ /* If we're trying to connect it right now, that's OK. */
@ -1340,7 +1363,7 @@ static void try_connect_peer(struct daemon *daemon,
static struct io_plan *connect_to_peer(struct io_conn *conn, static struct io_plan *connect_to_peer(struct io_conn *conn,
struct daemon *daemon, const u8 *msg) struct daemon *daemon, const u8 *msg)
{ {
struct pubkey id; struct node_id id;
u32 seconds_waited; u32 seconds_waited;
struct wireaddr_internal *addrhint; struct wireaddr_internal *addrhint;
@ -1357,25 +1380,25 @@ static struct io_plan *connect_to_peer(struct io_conn *conn,
static struct io_plan *peer_disconnected(struct io_conn *conn, static struct io_plan *peer_disconnected(struct io_conn *conn,
struct daemon *daemon, const u8 *msg) struct daemon *daemon, const u8 *msg)
{ {
struct pubkey id, *key; struct node_id id, *node;
if (!fromwire_connectctl_peer_disconnected(msg, &id)) if (!fromwire_connectctl_peer_disconnected(msg, &id))
master_badmsg(WIRE_CONNECTCTL_PEER_DISCONNECTED, msg); master_badmsg(WIRE_CONNECTCTL_PEER_DISCONNECTED, msg);
/* We should stay in sync with lightningd at all times. */ /* We should stay in sync with lightningd at all times. */
key = pubkey_set_get(&daemon->peers, &id); node = node_set_get(&daemon->peers, &id);
if (!key) if (!node)
status_failed(STATUS_FAIL_INTERNAL_ERROR, status_failed(STATUS_FAIL_INTERNAL_ERROR,
"peer_disconnected unknown peer: %s", "peer_disconnected unknown peer: %s",
type_to_string(tmpctx, struct pubkey, &id)); type_to_string(tmpctx, struct node_id, &id));
pubkey_set_del(&daemon->peers, key); node_set_del(&daemon->peers, node);
/* Wake up in case there's a reconnecting peer waiting in io_wait. */ /* Wake up in case there's a reconnecting peer waiting in io_wait. */
io_wake(key); io_wake(node);
/* Note: deleting from a htable (a-la pubkey_set_del) does not free it: /* Note: deleting from a htable (a-la node_set_del) does not free it:
* htable doesn't assume it's a tal object at all. */ * htable doesn't assume it's a tal object at all. */
tal_free(key); tal_free(node);
/* Read the next message from lightningd. */ /* Read the next message from lightningd. */
return daemon_conn_read_next(conn, daemon->master); return daemon_conn_read_next(conn, daemon->master);
@ -1491,7 +1514,7 @@ int main(int argc, char *argv[])
/* Allocate and set up our simple top-level structure. */ /* Allocate and set up our simple top-level structure. */
daemon = tal(NULL, struct daemon); daemon = tal(NULL, struct daemon);
pubkey_set_init(&daemon->peers); node_set_init(&daemon->peers);
list_head_init(&daemon->connecting); list_head_init(&daemon->connecting);
daemon->listen_fds = tal_arr(daemon, struct listen_fd, 0); daemon->listen_fds = tal_arr(daemon, struct listen_fd, 0);
/* stdin == control */ /* stdin == control */

3
connectd/connectd.h

@ -7,6 +7,7 @@
struct io_conn; struct io_conn;
struct connecting; struct connecting;
struct daemon; struct daemon;
struct node_id;
/* Called by io_tor_connect once it has a connection out. */ /* Called by io_tor_connect once it has a connection out. */
struct io_plan *connection_out(struct io_conn *conn, struct connecting *connect); struct io_plan *connection_out(struct io_conn *conn, struct connecting *connect);
@ -14,7 +15,7 @@ struct io_plan *connection_out(struct io_conn *conn, struct connecting *connect)
/* Called by peer_exchange_initmsg if successful. */ /* Called by peer_exchange_initmsg if successful. */
struct io_plan *peer_connected(struct io_conn *conn, struct io_plan *peer_connected(struct io_conn *conn,
struct daemon *daemon, struct daemon *daemon,
const struct pubkey *id TAKES, const struct node_id *id TAKES,
const u8 *peer_connected_msg TAKES, const u8 *peer_connected_msg TAKES,
const u8 *lfeatures TAKES); const u8 *lfeatures TAKES);

6
connectd/peer_exchange_initmsg.c

@ -14,7 +14,7 @@ struct peer {
struct daemon *daemon; struct daemon *daemon;
/* The ID of the peer */ /* The ID of the peer */
struct pubkey id; struct node_id id;
/* Where it's connected to/from. */ /* Where it's connected to/from. */
struct wireaddr_internal addr; struct wireaddr_internal addr;
@ -51,7 +51,7 @@ static struct io_plan *peer_init_received(struct io_conn *conn,
if (!fromwire_init(peer, msg, &globalfeatures, &localfeatures)) { if (!fromwire_init(peer, msg, &globalfeatures, &localfeatures)) {
status_trace("peer %s bad fromwire_init '%s', closing", status_trace("peer %s bad fromwire_init '%s', closing",
type_to_string(tmpctx, struct pubkey, &peer->id), type_to_string(tmpctx, struct node_id, &peer->id),
tal_hex(tmpctx, msg)); tal_hex(tmpctx, msg));
return io_close(conn); return io_close(conn);
} }
@ -131,7 +131,7 @@ static struct io_plan *peer_write_postclose(struct io_conn *conn,
struct io_plan *peer_exchange_initmsg(struct io_conn *conn, struct io_plan *peer_exchange_initmsg(struct io_conn *conn,
struct daemon *daemon, struct daemon *daemon,
const struct crypto_state *cs, const struct crypto_state *cs,
const struct pubkey *id, const struct node_id *id,
const struct wireaddr_internal *addr) const struct wireaddr_internal *addr)
{ {
/* If conn is closed, forget peer */ /* If conn is closed, forget peer */

4
connectd/peer_exchange_initmsg.h

@ -5,14 +5,14 @@
struct crypto_state; struct crypto_state;
struct daemon; struct daemon;
struct io_conn; struct io_conn;
struct pubkey; struct node_id;
struct wireaddr_internal; struct wireaddr_internal;
/* If successful, calls peer_connected() */ /* If successful, calls peer_connected() */
struct io_plan *peer_exchange_initmsg(struct io_conn *conn, struct io_plan *peer_exchange_initmsg(struct io_conn *conn,
struct daemon *daemon, struct daemon *daemon,
const struct crypto_state *cs, const struct crypto_state *cs,
const struct pubkey *id, const struct node_id *id,
const struct wireaddr_internal *addr); const struct wireaddr_internal *addr);
#endif /* LIGHTNING_CONNECTD_PEER_EXCHANGE_INITMSG_H */ #endif /* LIGHTNING_CONNECTD_PEER_EXCHANGE_INITMSG_H */

1
devtools/Makefile

@ -12,6 +12,7 @@ DEVTOOLS_COMMON_OBJS := \
common/bolt11.o \ common/bolt11.o \
common/decode_short_channel_ids.o \ common/decode_short_channel_ids.o \
common/hash_u5.o \ common/hash_u5.o \
common/node_id.o \
common/type_to_string.o \ common/type_to_string.o \
common/utils.o \ common/utils.o \
common/version.o \ common/version.o \

4
devtools/bolt11-cli.c

@ -101,7 +101,7 @@ int main(int argc, char *argv[])
printf("expiry: %"PRIu64" (%s)\n", printf("expiry: %"PRIu64" (%s)\n",
b11->expiry, fmt_time(ctx, b11->timestamp + b11->expiry)); b11->expiry, fmt_time(ctx, b11->timestamp + b11->expiry));
printf("payee: %s\n", printf("payee: %s\n",
type_to_string(ctx, struct pubkey, &b11->receiver_id)); type_to_string(ctx, struct node_id, &b11->receiver_id));
printf("payment_hash: %s\n", printf("payment_hash: %s\n",
tal_hexstr(ctx, &b11->payment_hash, sizeof(b11->payment_hash))); tal_hexstr(ctx, &b11->payment_hash, sizeof(b11->payment_hash)));
printf("min_final_cltv_expiry: %u\n", b11->min_final_cltv_expiry); printf("min_final_cltv_expiry: %u\n", b11->min_final_cltv_expiry);
@ -149,7 +149,7 @@ int main(int argc, char *argv[])
printf("route: (node/chanid/fee/expirydelta) "); printf("route: (node/chanid/fee/expirydelta) ");
for (size_t n = 0; n < tal_count(b11->routes[i]); n++) { for (size_t n = 0; n < tal_count(b11->routes[i]); n++) {
printf(" %s/%s/%u/%u/%u", printf(" %s/%s/%u/%u/%u",
type_to_string(ctx, struct pubkey, type_to_string(ctx, struct node_id,
&b11->routes[i][n].pubkey), &b11->routes[i][n].pubkey),
type_to_string(ctx, struct short_channel_id, type_to_string(ctx, struct short_channel_id,
&b11->routes[i][n].short_channel_id), &b11->routes[i][n].short_channel_id),

1
gossipd/Makefile

@ -53,6 +53,7 @@ GOSSIPD_COMMON_OBJS := \
common/key_derive.o \ common/key_derive.o \
common/memleak.o \ common/memleak.o \
common/msg_queue.o \ common/msg_queue.o \
common/node_id.o \
common/ping.o \ common/ping.o \
common/pseudorand.o \ common/pseudorand.o \
common/status.o \ common/status.o \

4
gossipd/gossip_constants.h

@ -40,8 +40,4 @@
*/ */
#define ANNOUNCE_MIN_DEPTH 6 #define ANNOUNCE_MIN_DEPTH 6
/* Utility function that, given a source and a destination, gives us
* the direction bit the matching channel should get */
#define get_channel_direction(from, to) (pubkey_cmp(from, to) > 0)
#endif /* LIGHTNING_GOSSIPD_GOSSIP_CONSTANTS_H */ #endif /* LIGHTNING_GOSSIPD_GOSSIP_CONSTANTS_H */

2
gossipd/gossip_peerd_wire.csv

@ -18,7 +18,7 @@ gossipd_send_gossip,,gossip,len*u8
# we (and peer) can update it already. # we (and peer) can update it already.
gossipd_local_add_channel,3503 gossipd_local_add_channel,3503
gossipd_local_add_channel,,short_channel_id,struct short_channel_id gossipd_local_add_channel,,short_channel_id,struct short_channel_id
gossipd_local_add_channel,,remote_node_id,struct pubkey gossipd_local_add_channel,,remote_node_id,struct node_id
gossipd_local_add_channel,,satoshis,struct amount_sat gossipd_local_add_channel,,satoshis,struct amount_sat
# Send this channel_update. # Send this channel_update.

Can't render this file because it has a wrong number of fields in line 2.

24
gossipd/gossip_wire.csv

@ -6,7 +6,7 @@
gossipctl_init,3000 gossipctl_init,3000
gossipctl_init,,broadcast_interval_msec,u32 gossipctl_init,,broadcast_interval_msec,u32
gossipctl_init,,chain_hash,struct bitcoin_blkid gossipctl_init,,chain_hash,struct bitcoin_blkid
gossipctl_init,,id,struct pubkey gossipctl_init,,id,struct node_id
gossipctl_init,,gflen,u16 gossipctl_init,,gflen,u16
gossipctl_init,,globalfeatures,gflen*u8 gossipctl_init,,globalfeatures,gflen*u8
gossipctl_init,,rgb,3*u8 gossipctl_init,,rgb,3*u8
@ -19,7 +19,7 @@ gossipctl_init,,dev_unknown_channel_satoshis,?struct amount_sat
# Pass JSON-RPC getnodes call through # Pass JSON-RPC getnodes call through
gossip_getnodes_request,3005 gossip_getnodes_request,3005
gossip_getnodes_request,,id,?struct pubkey gossip_getnodes_request,,id,?struct node_id
#include <lightningd/gossip_msg.h> #include <lightningd/gossip_msg.h>
gossip_getnodes_reply,3105 gossip_getnodes_reply,3105
@ -28,8 +28,8 @@ gossip_getnodes_reply,,nodes,num_nodes*struct gossip_getnodes_entry
# Pass JSON-RPC getroute call through # Pass JSON-RPC getroute call through
gossip_getroute_request,3006 gossip_getroute_request,3006
gossip_getroute_request,,source,struct pubkey gossip_getroute_request,,source,struct node_id
gossip_getroute_request,,destination,struct pubkey gossip_getroute_request,,destination,struct node_id
gossip_getroute_request,,msatoshi,struct amount_msat gossip_getroute_request,,msatoshi,struct amount_msat
# We don't pass doubles, so pass riskfactor * 1000000. # We don't pass doubles, so pass riskfactor * 1000000.
gossip_getroute_request,,riskfactor_by_million,u64 gossip_getroute_request,,riskfactor_by_million,u64
@ -45,7 +45,7 @@ gossip_getroute_reply,,hops,num_hops*struct route_hop
gossip_getchannels_request,3007 gossip_getchannels_request,3007
gossip_getchannels_request,,short_channel_id,?struct short_channel_id gossip_getchannels_request,,short_channel_id,?struct short_channel_id
gossip_getchannels_request,,source,?struct pubkey gossip_getchannels_request,,source,?struct node_id
gossip_getchannels_reply,3107 gossip_getchannels_reply,3107
gossip_getchannels_reply,,num_channels,u32 gossip_getchannels_reply,,num_channels,u32
@ -53,12 +53,12 @@ gossip_getchannels_reply,,nodes,num_channels*struct gossip_getchannels_entry
# Ping/pong test. Waits for a reply if it expects one. # Ping/pong test. Waits for a reply if it expects one.
gossip_ping,3008 gossip_ping,3008
gossip_ping,,id,struct pubkey gossip_ping,,id,struct node_id
gossip_ping,,num_pong_bytes,u16 gossip_ping,,num_pong_bytes,u16
gossip_ping,,len,u16 gossip_ping,,len,u16
gossip_ping_reply,3108 gossip_ping_reply,3108
gossip_ping_reply,,id,struct pubkey gossip_ping_reply,,id,struct node_id
# False if id in gossip_ping was unknown. # False if id in gossip_ping was unknown.
gossip_ping_reply,,sent,bool gossip_ping_reply,,sent,bool
# 0 == no pong expected # 0 == no pong expected
@ -66,7 +66,7 @@ gossip_ping_reply,,totlen,u16
# Test of query_short_channel_ids. Master->gossipd # Test of query_short_channel_ids. Master->gossipd
gossip_query_scids,3031 gossip_query_scids,3031
gossip_query_scids,,id,struct pubkey gossip_query_scids,,id,struct node_id
gossip_query_scids,,num_ids,u16 gossip_query_scids,,num_ids,u16
gossip_query_scids,,ids,num_ids*struct short_channel_id gossip_query_scids,,ids,num_ids*struct short_channel_id
@ -77,13 +77,13 @@ gossip_scids_reply,,complete,bool
# Test gossip timestamp filtering. # Test gossip timestamp filtering.
gossip_send_timestamp_filter,3028 gossip_send_timestamp_filter,3028
gossip_send_timestamp_filter,,id,struct pubkey gossip_send_timestamp_filter,,id,struct node_id
gossip_send_timestamp_filter,,first_timestamp,u32 gossip_send_timestamp_filter,,first_timestamp,u32
gossip_send_timestamp_filter,,timestamp_range,u32 gossip_send_timestamp_filter,,timestamp_range,u32
# Test of query_channel_range. Master->gossipd # Test of query_channel_range. Master->gossipd
gossip_query_channel_range,3029 gossip_query_channel_range,3029
gossip_query_channel_range,,id,struct pubkey gossip_query_channel_range,,id,struct node_id
gossip_query_channel_range,,first_blocknum,u32 gossip_query_channel_range,,first_blocknum,u32
gossip_query_channel_range,,number_of_blocks,u32 gossip_query_channel_range,,number_of_blocks,u32
@ -104,7 +104,7 @@ gossip_get_channel_peer,3009
gossip_get_channel_peer,,channel_id,struct short_channel_id gossip_get_channel_peer,,channel_id,struct short_channel_id
gossip_get_channel_peer_reply,3109 gossip_get_channel_peer_reply,3109
gossip_get_channel_peer_reply,,peer_id,?struct pubkey gossip_get_channel_peer_reply,,peer_id,?struct node_id
# gossipd->master: we're closing this channel. # gossipd->master: we're closing this channel.
gossip_local_channel_close,3027 gossip_local_channel_close,3027
@ -123,7 +123,7 @@ gossip_get_txout_reply,,outscript,len*u8
# master->gossipd an htlc failed with this onion error. # master->gossipd an htlc failed with this onion error.
gossip_payment_failure,3021 gossip_payment_failure,3021
gossip_payment_failure,,erring_node,struct pubkey gossip_payment_failure,,erring_node,struct node_id
gossip_payment_failure,,erring_channel,struct short_channel_id gossip_payment_failure,,erring_channel,struct short_channel_id
gossip_payment_failure,,erring_channel_direction,u8 gossip_payment_failure,,erring_channel_direction,u8
gossip_payment_failure,,len,u16 gossip_payment_failure,,len,u16

Can't render this file because it has a wrong number of fields in line 6.

104
gossipd/gossipd.c

@ -84,7 +84,7 @@ static bool suppress_gossip = false;
/*~ The core daemon structure: */ /*~ The core daemon structure: */
struct daemon { struct daemon {
/* Who am I? Helps us find ourself in the routing map. */ /* Who am I? Helps us find ourself in the routing map. */
struct pubkey id; struct node_id id;
/* Peers we are gossiping to: id is unique */ /* Peers we are gossiping to: id is unique */
struct list_head peers; struct list_head peers;
@ -127,7 +127,7 @@ struct peer {
struct daemon *daemon; struct daemon *daemon;
/* The ID of the peer (always unique) */ /* The ID of the peer (always unique) */
struct pubkey id; struct node_id id;
/* The two features gossip cares about (so far) */ /* The two features gossip cares about (so far) */
bool gossip_queries_feature, initial_routing_sync_feature; bool gossip_queries_feature, initial_routing_sync_feature;
@ -143,7 +143,7 @@ struct peer {
size_t scid_query_idx; size_t scid_query_idx;
/* Are there outstanding node_announcements from scid_queries? */ /* Are there outstanding node_announcements from scid_queries? */
struct pubkey *scid_query_nodes; struct node_id *scid_query_nodes;
size_t scid_query_nodes_idx; size_t scid_query_nodes_idx;
/* If this is NULL, we're syncing gossip now. */ /* If this is NULL, we're syncing gossip now. */
@ -179,7 +179,7 @@ static void peer_disable_channels(struct daemon *daemon, struct node *node)
struct chan *c; struct chan *c;
for (c = first_chan(node, &i); c; c = next_chan(node, &i)) { for (c = first_chan(node, &i); c; c = next_chan(node, &i)) {
if (pubkey_eq(&other_node(node, c)->id, &daemon->id)) if (node_id_eq(&other_node(node, c)->id, &daemon->id))
c->local_disabled = true; c->local_disabled = true;
} }
} }
@ -211,12 +211,12 @@ static void destroy_peer(struct peer *peer)
} }
/* Search for a peer. */ /* Search for a peer. */
static struct peer *find_peer(struct daemon *daemon, const struct pubkey *id) static struct peer *find_peer(struct daemon *daemon, const struct node_id *id)
{ {
struct peer *peer; struct peer *peer;
list_for_each(&daemon->peers, peer, list) list_for_each(&daemon->peers, peer, list)
if (pubkey_eq(&peer->id, id)) if (node_id_eq(&peer->id, id))
return peer; return peer;
return NULL; return NULL;
} }
@ -372,9 +372,13 @@ static u8 *create_node_announcement(const tal_t *ctx, struct daemon *daemon,
for (i = 0; i < tal_count(daemon->announcable); i++) for (i = 0; i < tal_count(daemon->announcable); i++)
towire_wireaddr(&addresses, &daemon->announcable[i]); towire_wireaddr(&addresses, &daemon->announcable[i]);
/* FIXME */
struct pubkey me;
if (!pubkey_from_node_id(&me, &daemon->id))
abort();
announcement = announcement =
towire_node_announcement(ctx, sig, daemon->globalfeatures, timestamp, towire_node_announcement(ctx, sig, daemon->globalfeatures, timestamp,
&daemon->id, daemon->rgb, daemon->alias, &me, daemon->rgb, daemon->alias,
addresses); addresses);
return announcement; return announcement;
} }
@ -546,7 +550,7 @@ static const u8 *handle_query_short_channel_ids(struct peer *peer, const u8 *msg
if (!bitcoin_blkid_eq(&peer->daemon->chain_hash, &chain)) { if (!bitcoin_blkid_eq(&peer->daemon->chain_hash, &chain)) {
status_trace("%s sent query_short_channel_ids chainhash %s", status_trace("%s sent query_short_channel_ids chainhash %s",
type_to_string(tmpctx, struct pubkey, &peer->id), type_to_string(tmpctx, struct node_id, &peer->id),
type_to_string(tmpctx, struct bitcoin_blkid, &chain)); type_to_string(tmpctx, struct bitcoin_blkid, &chain));
return NULL; return NULL;
} }
@ -579,7 +583,7 @@ static const u8 *handle_query_short_channel_ids(struct peer *peer, const u8 *msg
*/ */
peer->scid_queries = tal_steal(peer, scids); peer->scid_queries = tal_steal(peer, scids);
peer->scid_query_idx = 0; peer->scid_query_idx = 0;
peer->scid_query_nodes = tal_arr(peer, struct pubkey, 0); peer->scid_query_nodes = tal_arr(peer, struct node_id, 0);
/* Notify the daemon_conn-write loop to invoke create_next_scid_reply */ /* Notify the daemon_conn-write loop to invoke create_next_scid_reply */
daemon_conn_wake(peer->dc); daemon_conn_wake(peer->dc);
@ -606,7 +610,7 @@ static u8 *handle_gossip_timestamp_filter(struct peer *peer, const u8 *msg)
if (!bitcoin_blkid_eq(&peer->daemon->chain_hash, &chain_hash)) { if (!bitcoin_blkid_eq(&peer->daemon->chain_hash, &chain_hash)) {
status_trace("%s sent gossip_timestamp_filter chainhash %s", status_trace("%s sent gossip_timestamp_filter chainhash %s",
type_to_string(tmpctx, struct pubkey, &peer->id), type_to_string(tmpctx, struct node_id, &peer->id),
type_to_string(tmpctx, struct bitcoin_blkid, type_to_string(tmpctx, struct bitcoin_blkid,
&chain_hash)); &chain_hash));
return NULL; return NULL;
@ -760,7 +764,7 @@ static u8 *handle_query_channel_range(struct peer *peer, const u8 *msg)
* but give an empty response with the `complete` flag unset? */ * but give an empty response with the `complete` flag unset? */
if (!bitcoin_blkid_eq(&peer->daemon->chain_hash, &chain_hash)) { if (!bitcoin_blkid_eq(&peer->daemon->chain_hash, &chain_hash)) {
status_trace("%s sent query_channel_range chainhash %s", status_trace("%s sent query_channel_range chainhash %s",
type_to_string(tmpctx, struct pubkey, &peer->id), type_to_string(tmpctx, struct node_id, &peer->id),
type_to_string(tmpctx, struct bitcoin_blkid, type_to_string(tmpctx, struct bitcoin_blkid,
&chain_hash)); &chain_hash));
return NULL; return NULL;
@ -839,7 +843,7 @@ static const u8 *handle_reply_channel_range(struct peer *peer, const u8 *msg)
} }
status_debug("peer %s reply_channel_range %u+%u (of %u+%u) %zu scids", status_debug("peer %s reply_channel_range %u+%u (of %u+%u) %zu scids",
type_to_string(tmpctx, struct pubkey, &peer->id), type_to_string(tmpctx, struct node_id, &peer->id),
first_blocknum, number_of_blocks, first_blocknum, number_of_blocks,
peer->range_first_blocknum, peer->range_first_blocknum,
peer->range_end_blocknum - peer->range_first_blocknum, peer->range_end_blocknum - peer->range_first_blocknum,
@ -986,13 +990,14 @@ static u8 *handle_reply_short_channel_ids_end(struct peer *peer, const u8 *msg)
* and reappeared) we'd just end up sending two node_announcement for the * and reappeared) we'd just end up sending two node_announcement for the
* same node. * same node.
*/ */
static int pubkey_order(const struct pubkey *k1, const struct pubkey *k2, static int pubkey_order(const struct node_id *k1,
const struct node_id *k2,
void *unused UNUSED) void *unused UNUSED)
{ {
return pubkey_cmp(k1, k2); return node_id_cmp(k1, k2);
} }
static void uniquify_node_ids(struct pubkey **ids) static void uniquify_node_ids(struct node_id **ids)
{ {
size_t dst, src; size_t dst, src;
@ -1011,7 +1016,7 @@ static void uniquify_node_ids(struct pubkey **ids)
/* Compact the array */ /* Compact the array */
for (dst = 0, src = 0; src < tal_count(*ids); src++) { for (dst = 0, src = 0; src < tal_count(*ids); src++) {
if (dst && pubkey_eq(&(*ids)[dst-1], &(*ids)[src])) if (dst && node_id_eq(&(*ids)[dst-1], &(*ids)[src]))
continue; continue;
(*ids)[dst++] = (*ids)[src]; (*ids)[dst++] = (*ids)[src];
} }
@ -1335,7 +1340,7 @@ static bool local_direction(struct daemon *daemon,
int *direction) int *direction)
{ {
for (*direction = 0; *direction < 2; (*direction)++) { for (*direction = 0; *direction < 2; (*direction)++) {
if (pubkey_eq(&chan->nodes[*direction]->id, &daemon->id)) if (node_id_eq(&chan->nodes[*direction]->id, &daemon->id))
return true; return true;
} }
return false; return false;
@ -1356,7 +1361,7 @@ static bool handle_get_update(struct peer *peer, const u8 *msg)
if (!fromwire_gossipd_get_update(msg, &scid)) { if (!fromwire_gossipd_get_update(msg, &scid)) {
status_broken("peer %s sent bad gossip_get_update %s", status_broken("peer %s sent bad gossip_get_update %s",
type_to_string(tmpctx, struct pubkey, &peer->id), type_to_string(tmpctx, struct node_id, &peer->id),
tal_hex(tmpctx, msg)); tal_hex(tmpctx, msg));
return false; return false;
} }
@ -1365,7 +1370,7 @@ static bool handle_get_update(struct peer *peer, const u8 *msg)
chan = get_channel(rstate, &scid); chan = get_channel(rstate, &scid);
if (!chan) { if (!chan) {
status_unusual("peer %s scid %s: unknown channel", status_unusual("peer %s scid %s: unknown channel",
type_to_string(tmpctx, struct pubkey, &peer->id), type_to_string(tmpctx, struct node_id, &peer->id),
type_to_string(tmpctx, struct short_channel_id, type_to_string(tmpctx, struct short_channel_id,
&scid)); &scid));
update = NULL; update = NULL;
@ -1375,7 +1380,7 @@ static bool handle_get_update(struct peer *peer, const u8 *msg)
/* We want the update that comes from our end. */ /* We want the update that comes from our end. */
if (!local_direction(peer->daemon, chan, &direction)) { if (!local_direction(peer->daemon, chan, &direction)) {
status_unusual("peer %s scid %s: not our channel?", status_unusual("peer %s scid %s: not our channel?",
type_to_string(tmpctx, struct pubkey, &peer->id), type_to_string(tmpctx, struct node_id, &peer->id),
type_to_string(tmpctx, type_to_string(tmpctx,
struct short_channel_id, struct short_channel_id,
&scid)); &scid));
@ -1391,7 +1396,7 @@ static bool handle_get_update(struct peer *peer, const u8 *msg)
update = chan->half[direction].channel_update; update = chan->half[direction].channel_update;
out: out:
status_trace("peer %s schanid %s: %s update", status_trace("peer %s schanid %s: %s update",
type_to_string(tmpctx, struct pubkey, &peer->id), type_to_string(tmpctx, struct node_id, &peer->id),
type_to_string(tmpctx, struct short_channel_id, &scid), type_to_string(tmpctx, struct short_channel_id, &scid),
update ? "got" : "no"); update ? "got" : "no");
@ -1442,7 +1447,7 @@ static bool handle_local_channel_update(struct peer *peer, const u8 *msg)
&fee_proportional_millionths, &fee_proportional_millionths,
&htlc_maximum)) { &htlc_maximum)) {
status_broken("peer %s bad local_channel_update %s", status_broken("peer %s bad local_channel_update %s",
type_to_string(tmpctx, struct pubkey, &peer->id), type_to_string(tmpctx, struct node_id, &peer->id),
tal_hex(tmpctx, msg)); tal_hex(tmpctx, msg));
return false; return false;
} }
@ -1451,7 +1456,7 @@ static bool handle_local_channel_update(struct peer *peer, const u8 *msg)
chan = get_channel(peer->daemon->rstate, &scid); chan = get_channel(peer->daemon->rstate, &scid);
if (!chan) { if (!chan) {
status_trace("peer %s local_channel_update for unknown %s", status_trace("peer %s local_channel_update for unknown %s",
type_to_string(tmpctx, struct pubkey, &peer->id), type_to_string(tmpctx, struct node_id, &peer->id),
type_to_string(tmpctx, struct short_channel_id, type_to_string(tmpctx, struct short_channel_id,
&scid)); &scid));
return true; return true;
@ -1460,7 +1465,7 @@ static bool handle_local_channel_update(struct peer *peer, const u8 *msg)
/* You shouldn't be asking for a non-local channel though. */ /* You shouldn't be asking for a non-local channel though. */
if (!local_direction(peer->daemon, chan, &direction)) { if (!local_direction(peer->daemon, chan, &direction)) {
status_broken("peer %s bad local_channel_update for non-local %s", status_broken("peer %s bad local_channel_update for non-local %s",
type_to_string(tmpctx, struct pubkey, &peer->id), type_to_string(tmpctx, struct node_id, &peer->id),
type_to_string(tmpctx, struct short_channel_id, type_to_string(tmpctx, struct short_channel_id,
&scid)); &scid));
return false; return false;
@ -1555,7 +1560,7 @@ static struct io_plan *peer_msg_in(struct io_conn *conn,
case WIRE_CHANNEL_REESTABLISH: case WIRE_CHANNEL_REESTABLISH:
case WIRE_ANNOUNCEMENT_SIGNATURES: case WIRE_ANNOUNCEMENT_SIGNATURES:
status_broken("peer %s: relayed unexpected msg of type %s", status_broken("peer %s: relayed unexpected msg of type %s",
type_to_string(tmpctx, struct pubkey, &peer->id), type_to_string(tmpctx, struct node_id, &peer->id),
wire_type_name(fromwire_peektype(msg))); wire_type_name(fromwire_peektype(msg)));
return io_close(conn); return io_close(conn);
} }
@ -1582,7 +1587,7 @@ static struct io_plan *peer_msg_in(struct io_conn *conn,
/* Anything else should not have been sent to us: close on it */ /* Anything else should not have been sent to us: close on it */
status_broken("peer %s: unexpected cmd of type %i %s", status_broken("peer %s: unexpected cmd of type %i %s",
type_to_string(tmpctx, struct pubkey, &peer->id), type_to_string(tmpctx, struct node_id, &peer->id),
fromwire_peektype(msg), fromwire_peektype(msg),
gossip_peerd_wire_type_name(fromwire_peektype(msg))); gossip_peerd_wire_type_name(fromwire_peektype(msg)));
return io_close(conn); return io_close(conn);
@ -1704,7 +1709,7 @@ static struct io_plan *connectd_get_address(struct io_conn *conn,
struct daemon *daemon, struct daemon *daemon,
const u8 *msg) const u8 *msg)
{ {
struct pubkey id; struct node_id id;
struct node *node; struct node *node;
const struct wireaddr *addrs; const struct wireaddr *addrs;
@ -1903,7 +1908,7 @@ static struct io_plan *gossip_init(struct io_conn *conn,
static struct io_plan *getroute_req(struct io_conn *conn, struct daemon *daemon, static struct io_plan *getroute_req(struct io_conn *conn, struct daemon *daemon,
const u8 *msg) const u8 *msg)
{ {
struct pubkey source, destination; struct node_id source, destination;
struct amount_msat msat; struct amount_msat msat;
u32 final_cltv; u32 final_cltv;
u64 riskfactor_by_million; u64 riskfactor_by_million;
@ -1928,8 +1933,8 @@ static struct io_plan *getroute_req(struct io_conn *conn, struct daemon *daemon,
master_badmsg(WIRE_GOSSIP_GETROUTE_REQUEST, msg); master_badmsg(WIRE_GOSSIP_GETROUTE_REQUEST, msg);
status_trace("Trying to find a route from %s to %s for %s", status_trace("Trying to find a route from %s to %s for %s",
pubkey_to_hexstr(tmpctx, &source), type_to_string(tmpctx, struct node_id, &source),
pubkey_to_hexstr(tmpctx, &destination), type_to_string(tmpctx, struct node_id, &destination),
type_to_string(tmpctx, struct amount_msat, &msat)); type_to_string(tmpctx, struct amount_msat, &msat));
/* routing.c does all the hard work; can return NULL. */ /* routing.c does all the hard work; can return NULL. */
@ -1942,11 +1947,6 @@ static struct io_plan *getroute_req(struct io_conn *conn, struct daemon *daemon,
return daemon_conn_read_next(conn, daemon->master); return daemon_conn_read_next(conn, daemon->master);
} }
#define raw_pubkey(arr, id) \
do { BUILD_ASSERT(sizeof(arr) == sizeof(*id)); \
memcpy(arr, id, sizeof(*id)); \
} while(0)
/*~ When someone asks lightningd to `listchannels`, gossipd does the work: /*~ When someone asks lightningd to `listchannels`, gossipd does the work:
* marshalling the channel information for all channels into an array of * marshalling the channel information for all channels into an array of
* gossip_getchannels_entry, which lightningd converts to JSON. Each channel * gossip_getchannels_entry, which lightningd converts to JSON. Each channel
@ -1978,8 +1978,8 @@ static void append_half_channel(struct gossip_getchannels_entry **entries,
* pubkeys to DER and back: that proves quite expensive, and we assume * pubkeys to DER and back: that proves quite expensive, and we assume
* we're on the same architecture as lightningd, so we just send them * we're on the same architecture as lightningd, so we just send them
* raw in this case. */ * raw in this case. */
raw_pubkey(e.source, &chan->nodes[idx]->id); e.source = chan->nodes[idx]->id;
raw_pubkey(e.destination, &chan->nodes[!idx]->id); e.destination = chan->nodes[!idx]->id;
e.sat = chan->sat; e.sat = chan->sat;
e.channel_flags = c->channel_flags; e.channel_flags = c->channel_flags;
e.message_flags = c->message_flags; e.message_flags = c->message_flags;
@ -2011,7 +2011,7 @@ static struct io_plan *getchannels_req(struct io_conn *conn,
struct gossip_getchannels_entry *entries; struct gossip_getchannels_entry *entries;
struct chan *chan; struct chan *chan;
struct short_channel_id *scid; struct short_channel_id *scid;
struct pubkey *source; struct node_id *source;
/* Note: scid is marked optional in gossip_wire.csv */ /* Note: scid is marked optional in gossip_wire.csv */
if (!fromwire_gossip_getchannels_request(msg, msg, &scid, &source)) if (!fromwire_gossip_getchannels_request(msg, msg, &scid, &source))
@ -2060,7 +2060,7 @@ static void append_node(const struct gossip_getnodes_entry ***entries,
struct gossip_getnodes_entry *e; struct gossip_getnodes_entry *e;
e = tal(*entries, struct gossip_getnodes_entry); e = tal(*entries, struct gossip_getnodes_entry);
raw_pubkey(e->nodeid, &n->id); e->nodeid = n->id;
e->last_timestamp = n->last_timestamp; e->last_timestamp = n->last_timestamp;
/* Timestamp on wire is an unsigned 32 bit: we use a 64-bit signed, so /* Timestamp on wire is an unsigned 32 bit: we use a 64-bit signed, so
* -1 means "we never received a channel_update". */ * -1 means "we never received a channel_update". */
@ -2083,7 +2083,7 @@ static struct io_plan *getnodes(struct io_conn *conn, struct daemon *daemon,
u8 *out; u8 *out;
struct node *n; struct node *n;
const struct gossip_getnodes_entry **nodes; const struct gossip_getnodes_entry **nodes;
struct pubkey *id; struct node_id *id;
if (!fromwire_gossip_getnodes_request(tmpctx, msg, &id)) if (!fromwire_gossip_getnodes_request(tmpctx, msg, &id))
master_badmsg(WIRE_GOSSIP_GETNODES_REQUEST, msg); master_badmsg(WIRE_GOSSIP_GETNODES_REQUEST, msg);
@ -2113,7 +2113,7 @@ static struct io_plan *getnodes(struct io_conn *conn, struct daemon *daemon,
static struct io_plan *ping_req(struct io_conn *conn, struct daemon *daemon, static struct io_plan *ping_req(struct io_conn *conn, struct daemon *daemon,
const u8 *msg) const u8 *msg)
{ {
struct pubkey id; struct node_id id;
u16 num_pong_bytes, len; u16 num_pong_bytes, len;
struct peer *peer; struct peer *peer;
u8 *ping; u8 *ping;
@ -2268,7 +2268,7 @@ static struct io_plan *query_scids_req(struct io_conn *conn,
struct daemon *daemon, struct daemon *daemon,
const u8 *msg) const u8 *msg)
{ {
struct pubkey id; struct node_id id;
struct short_channel_id *scids; struct short_channel_id *scids;
struct peer *peer; struct peer *peer;
u8 *encoded; u8 *encoded;
@ -2289,13 +2289,13 @@ static struct io_plan *query_scids_req(struct io_conn *conn,
peer = find_peer(daemon, &id); peer = find_peer(daemon, &id);
if (!peer) { if (!peer) {
status_broken("query_scids: unknown peer %s", status_broken("query_scids: unknown peer %s",
type_to_string(tmpctx, struct pubkey, &id)); type_to_string(tmpctx, struct node_id, &id));
goto fail; goto fail;
} }
if (!peer->gossip_queries_feature) { if (!peer->gossip_queries_feature) {
status_broken("query_scids: no gossip_query support in peer %s", status_broken("query_scids: no gossip_query support in peer %s",
type_to_string(tmpctx, struct pubkey, &id)); type_to_string(tmpctx, struct node_id, &id));
goto fail; goto fail;
} }
@ -2342,7 +2342,7 @@ static struct io_plan *send_timestamp_filter(struct io_conn *conn,
struct daemon *daemon, struct daemon *daemon,
const u8 *msg) const u8 *msg)
{ {
struct pubkey id; struct node_id id;
u32 first, range; u32 first, range;
struct peer *peer; struct peer *peer;
@ -2352,13 +2352,13 @@ static struct io_plan *send_timestamp_filter(struct io_conn *conn,
peer = find_peer(daemon, &id); peer = find_peer(daemon, &id);
if (!peer) { if (!peer) {
status_broken("send_timestamp_filter: unknown peer %s", status_broken("send_timestamp_filter: unknown peer %s",
type_to_string(tmpctx, struct pubkey, &id)); type_to_string(tmpctx, struct node_id, &id));
goto out; goto out;
} }
if (!peer->gossip_queries_feature) { if (!peer->gossip_queries_feature) {
status_broken("send_timestamp_filter: no gossip_query support in peer %s", status_broken("send_timestamp_filter: no gossip_query support in peer %s",
type_to_string(tmpctx, struct pubkey, &id)); type_to_string(tmpctx, struct node_id, &id));
goto out; goto out;
} }
@ -2375,7 +2375,7 @@ static struct io_plan *query_channel_range(struct io_conn *conn,
struct daemon *daemon, struct daemon *daemon,
const u8 *msg) const u8 *msg)
{ {
struct pubkey id; struct node_id id;
u32 first_blocknum, number_of_blocks; u32 first_blocknum, number_of_blocks;
struct peer *peer; struct peer *peer;
@ -2386,13 +2386,13 @@ static struct io_plan *query_channel_range(struct io_conn *conn,
peer = find_peer(daemon, &id); peer = find_peer(daemon, &id);
if (!peer) { if (!peer) {
status_broken("query_channel_range: unknown peer %s", status_broken("query_channel_range: unknown peer %s",
type_to_string(tmpctx, struct pubkey, &id)); type_to_string(tmpctx, struct node_id, &id));
goto fail; goto fail;
} }
if (!peer->gossip_queries_feature) { if (!peer->gossip_queries_feature) {
status_broken("query_channel_range: no gossip_query support in peer %s", status_broken("query_channel_range: no gossip_query support in peer %s",
type_to_string(tmpctx, struct pubkey, &id)); type_to_string(tmpctx, struct node_id, &id));
goto fail; goto fail;
} }
@ -2497,7 +2497,7 @@ static struct io_plan *get_channel_peer(struct io_conn *conn,
{ {
struct short_channel_id scid; struct short_channel_id scid;
struct chan *chan; struct chan *chan;
const struct pubkey *key; const struct node_id *key;
int direction; int direction;
if (!fromwire_gossip_get_channel_peer(msg, &scid)) if (!fromwire_gossip_get_channel_peer(msg, &scid))
@ -2606,7 +2606,7 @@ static struct io_plan *handle_payment_failure(struct io_conn *conn,
struct daemon *daemon, struct daemon *daemon,
const u8 *msg) const u8 *msg)
{ {
struct pubkey erring_node; struct node_id erring_node;
struct short_channel_id erring_channel; struct short_channel_id erring_channel;
u8 erring_channel_direction; u8 erring_channel_direction;
u8 *error; u8 *error;

145
gossipd/routing.c

@ -33,8 +33,8 @@ struct pending_cannouncement {
/* Unpacked fields here */ /* Unpacked fields here */
struct short_channel_id short_channel_id; struct short_channel_id short_channel_id;
struct pubkey node_id_1; struct node_id node_id_1;
struct pubkey node_id_2; struct node_id node_id_2;
struct pubkey bitcoin_key_1; struct pubkey bitcoin_key_1;
struct pubkey bitcoin_key_2; struct pubkey bitcoin_key_2;
@ -50,21 +50,21 @@ struct pending_cannouncement {
}; };
struct pending_node_announce { struct pending_node_announce {
struct pubkey nodeid; struct node_id nodeid;
u8 *node_announcement; u8 *node_announcement;
u32 timestamp; u32 timestamp;
}; };
static const struct pubkey * static const struct node_id *
pending_node_announce_keyof(const struct pending_node_announce *a) pending_node_announce_keyof(const struct pending_node_announce *a)
{ {
return &a->nodeid; return &a->nodeid;
} }
static bool pending_node_announce_eq(const struct pending_node_announce *pna, static bool pending_node_announce_eq(const struct pending_node_announce *pna,
const struct pubkey *key) const struct node_id *pc)
{ {
return pubkey_eq(&pna->nodeid, key); return node_id_eq(&pna->nodeid, pc);
} }
HTABLE_DEFINE_TYPE(struct pending_node_announce, pending_node_announce_keyof, HTABLE_DEFINE_TYPE(struct pending_node_announce, pending_node_announce_keyof,
@ -147,7 +147,7 @@ struct chan *next_chan(const struct node *node, struct chan_map_iter *i)
struct routing_state *new_routing_state(const tal_t *ctx, struct routing_state *new_routing_state(const tal_t *ctx,
const struct chainparams *chainparams, const struct chainparams *chainparams,
const struct pubkey *local_id, const struct node_id *local_id,
u32 prune_timeout, u32 prune_timeout,
const u32 *dev_gossip_time, const u32 *dev_gossip_time,
const struct amount_sat *dev_unknown_channel_satoshis) const struct amount_sat *dev_unknown_channel_satoshis)
@ -181,19 +181,19 @@ struct routing_state *new_routing_state(const tal_t *ctx,
} }
const struct pubkey *node_map_keyof_node(const struct node *n) const struct node_id *node_map_keyof_node(const struct node *n)
{ {
return &n->id; return &n->id;
} }
size_t node_map_hash_key(const struct pubkey *key) size_t node_map_hash_key(const struct node_id *pc)
{ {
return siphash24(siphash_seed(), key, sizeof(*key)); return siphash24(siphash_seed(), pc->k, sizeof(pc->k));
} }
bool node_map_node_eq(const struct node *n, const struct pubkey *key) bool node_map_node_eq(const struct node *n, const struct node_id *pc)
{ {
return pubkey_eq(&n->id, key); return node_id_eq(&n->id, pc);
} }
@ -212,13 +212,14 @@ static void destroy_node(struct node *node, struct routing_state *rstate)
chan_map_clear(&node->chans.map); chan_map_clear(&node->chans.map);
} }
struct node *get_node(struct routing_state *rstate, const struct pubkey *id) struct node *get_node(struct routing_state *rstate,
const struct node_id *id)
{ {
return node_map_get(rstate->nodes, id); return node_map_get(rstate->nodes, id);
} }
static struct node *new_node(struct routing_state *rstate, static struct node *new_node(struct routing_state *rstate,
const struct pubkey *id) const struct node_id *id)
{ {
struct node *n; struct node *n;
@ -373,12 +374,12 @@ static void bad_gossip_order(const u8 *msg, const char *source,
struct chan *new_chan(struct routing_state *rstate, struct chan *new_chan(struct routing_state *rstate,
const struct short_channel_id *scid, const struct short_channel_id *scid,
const struct pubkey *id1, const struct node_id *id1,
const struct pubkey *id2, const struct node_id *id2,
struct amount_sat satoshis) struct amount_sat satoshis)
{ {
struct chan *chan = tal(rstate, struct chan); struct chan *chan = tal(rstate, struct chan);
int n1idx = pubkey_idx(id1, id2); int n1idx = node_id_idx(id1, id2);
struct node *n1, *n2; struct node *n1, *n2;
/* We should never add a channel twice */ /* We should never add a channel twice */
@ -537,7 +538,7 @@ static void bfg_one_edge(struct node *node,
if (amount_msat_less(this_total, curr_total)) { if (amount_msat_less(this_total, curr_total)) {
SUPERVERBOSE("...%s can reach here hoplen %zu" SUPERVERBOSE("...%s can reach here hoplen %zu"
" total %s risk %s", " total %s risk %s",
type_to_string(tmpctx, struct pubkey, type_to_string(tmpctx, struct node_id,
&src->id), &src->id),
h, h,
type_to_string(tmpctx, struct amount_msat, type_to_string(tmpctx, struct amount_msat,
@ -561,7 +562,7 @@ static bool hc_is_routable(const struct chan *chan, int idx)
/* riskfactor is already scaled to per-block amount */ /* riskfactor is already scaled to per-block amount */
static struct chan ** static struct chan **
find_route(const tal_t *ctx, struct routing_state *rstate, find_route(const tal_t *ctx, struct routing_state *rstate,
const struct pubkey *from, const struct pubkey *to, const struct node_id *from, const struct node_id *to,
struct amount_msat msat, struct amount_msat msat,
double riskfactor, double riskfactor,
double fuzz, const struct siphash_seed *base_seed, double fuzz, const struct siphash_seed *base_seed,
@ -581,15 +582,15 @@ find_route(const tal_t *ctx, struct routing_state *rstate,
if (!src) { if (!src) {
status_info("find_route: cannot find %s", status_info("find_route: cannot find %s",
type_to_string(tmpctx, struct pubkey, to)); type_to_string(tmpctx, struct node_id, to));
return NULL; return NULL;
} else if (!dst) { } else if (!dst) {
status_info("find_route: cannot find myself (%s)", status_info("find_route: cannot find myself (%s)",
type_to_string(tmpctx, struct pubkey, to)); type_to_string(tmpctx, struct node_id, to));
return NULL; return NULL;
} else if (dst == src) { } else if (dst == src) {
status_info("find_route: this is %s, refusing to create empty route", status_info("find_route: this is %s, refusing to create empty route",
type_to_string(tmpctx, struct pubkey, to)); type_to_string(tmpctx, struct node_id, to));
return NULL; return NULL;
} }
@ -622,7 +623,7 @@ find_route(const tal_t *ctx, struct routing_state *rstate,
int idx = half_chan_to(n, chan); int idx = half_chan_to(n, chan);
SUPERVERBOSE("Node %s edge %s", SUPERVERBOSE("Node %s edge %s",
type_to_string(tmpctx, struct pubkey, type_to_string(tmpctx, struct node_id,
&n->id), &n->id),
type_to_string(tmpctx, type_to_string(tmpctx,
struct short_channel_id, struct short_channel_id,
@ -666,7 +667,7 @@ find_route(const tal_t *ctx, struct routing_state *rstate,
/* No route? */ /* No route? */
if (amount_msat_greater_eq(best_total, INFINITE)) { if (amount_msat_greater_eq(best_total, INFINITE)) {
status_trace("find_route: No route to %s", status_trace("find_route: No route to %s",
type_to_string(tmpctx, struct pubkey, to)); type_to_string(tmpctx, struct node_id, to));
return NULL; return NULL;
} }
@ -692,9 +693,20 @@ find_route(const tal_t *ctx, struct routing_state *rstate,
return route; return route;
} }
/* Checks that key is valid, and signed this hash */
static bool check_signed_hash_nodeid(const struct sha256_double *hash,
const secp256k1_ecdsa_signature *signature,
const struct node_id *id)
{
struct pubkey key;
return pubkey_from_node_id(&key, id)
&& check_signed_hash(hash, signature, &key);
}
/* Verify the signature of a channel_update message */ /* Verify the signature of a channel_update message */
static u8 *check_channel_update(const tal_t *ctx, static u8 *check_channel_update(const tal_t *ctx,
const struct pubkey *node_key, const struct node_id *node_id,
const secp256k1_ecdsa_signature *node_sig, const secp256k1_ecdsa_signature *node_sig,
const u8 *update) const u8 *update)
{ {
@ -703,7 +715,7 @@ static u8 *check_channel_update(const tal_t *ctx,
struct sha256_double hash; struct sha256_double hash;
sha256_double(&hash, update + offset, tal_count(update) - offset); sha256_double(&hash, update + offset, tal_count(update) - offset);
if (!check_signed_hash(&hash, node_sig, node_key)) if (!check_signed_hash_nodeid(&hash, node_sig, node_id))
return towire_errorfmt(ctx, NULL, return towire_errorfmt(ctx, NULL,
"Bad signature for %s hash %s" "Bad signature for %s hash %s"
" on channel_update %s", " on channel_update %s",
@ -718,7 +730,7 @@ static u8 *check_channel_update(const tal_t *ctx,
} }
static u8 *check_channel_announcement(const tal_t *ctx, static u8 *check_channel_announcement(const tal_t *ctx,
const struct pubkey *node1_key, const struct pubkey *node2_key, const struct node_id *node1_id, const struct node_id *node2_id,
const struct pubkey *bitcoin1_key, const struct pubkey *bitcoin2_key, const struct pubkey *bitcoin1_key, const struct pubkey *bitcoin2_key,
const secp256k1_ecdsa_signature *node1_sig, const secp256k1_ecdsa_signature *node1_sig,
const secp256k1_ecdsa_signature *node2_sig, const secp256k1_ecdsa_signature *node2_sig,
@ -731,7 +743,7 @@ static u8 *check_channel_announcement(const tal_t *ctx,
sha256_double(&hash, announcement + offset, sha256_double(&hash, announcement + offset,
tal_count(announcement) - offset); tal_count(announcement) - offset);
if (!check_signed_hash(&hash, node1_sig, node1_key)) { if (!check_signed_hash_nodeid(&hash, node1_sig, node1_id)) {
return towire_errorfmt(ctx, NULL, return towire_errorfmt(ctx, NULL,
"Bad node_signature_1 %s hash %s" "Bad node_signature_1 %s hash %s"
" on node_announcement %s", " on node_announcement %s",
@ -743,7 +755,7 @@ static u8 *check_channel_announcement(const tal_t *ctx,
&hash), &hash),
tal_hex(ctx, announcement)); tal_hex(ctx, announcement));
} }
if (!check_signed_hash(&hash, node2_sig, node2_key)) { if (!check_signed_hash_nodeid(&hash, node2_sig, node2_id)) {
return towire_errorfmt(ctx, NULL, return towire_errorfmt(ctx, NULL,
"Bad node_signature_2 %s hash %s" "Bad node_signature_2 %s hash %s"
" on node_announcement %s", " on node_announcement %s",
@ -782,7 +794,7 @@ static u8 *check_channel_announcement(const tal_t *ctx,
return NULL; return NULL;
} }
static void add_pending_node_announcement(struct routing_state *rstate, struct pubkey *nodeid) static void add_pending_node_announcement(struct routing_state *rstate, struct node_id *nodeid)
{ {
struct pending_node_announce *pna = tal(rstate, struct pending_node_announce); struct pending_node_announce *pna = tal(rstate, struct pending_node_announce);
pna->nodeid = *nodeid; pna->nodeid = *nodeid;
@ -792,7 +804,7 @@ static void add_pending_node_announcement(struct routing_state *rstate, struct p
} }
static void process_pending_node_announcement(struct routing_state *rstate, static void process_pending_node_announcement(struct routing_state *rstate,
struct pubkey *nodeid) struct node_id *nodeid)
{ {
struct pending_node_announce *pna = pending_node_map_get(rstate->pending_node_map, nodeid); struct pending_node_announce *pna = pending_node_map_get(rstate->pending_node_map, nodeid);
if (!pna) if (!pna)
@ -802,7 +814,7 @@ static void process_pending_node_announcement(struct routing_state *rstate,
u8 *err; u8 *err;
SUPERVERBOSE( SUPERVERBOSE(
"Processing deferred node_announcement for node %s", "Processing deferred node_announcement for node %s",
type_to_string(pna, struct pubkey, nodeid)); type_to_string(pna, struct node_id, nodeid));
/* Should not error, since we processed it before */ /* Should not error, since we processed it before */
err = handle_node_announcement(rstate, pna->node_announcement); err = handle_node_announcement(rstate, pna->node_announcement);
@ -838,8 +850,8 @@ static void destroy_pending_cannouncement(struct pending_cannouncement *pending,
static bool is_local_channel(const struct routing_state *rstate, static bool is_local_channel(const struct routing_state *rstate,
const struct chan *chan) const struct chan *chan)
{ {
return pubkey_eq(&chan->nodes[0]->id, &rstate->local_id) return node_id_eq(&chan->nodes[0]->id, &rstate->local_id)
|| pubkey_eq(&chan->nodes[1]->id, &rstate->local_id); || node_id_eq(&chan->nodes[1]->id, &rstate->local_id);
} }
static void add_channel_announce_to_broadcast(struct routing_state *rstate, static void add_channel_announce_to_broadcast(struct routing_state *rstate,
@ -873,16 +885,20 @@ bool routing_add_channel_announcement(struct routing_state *rstate,
u8 *features; u8 *features;
struct bitcoin_blkid chain_hash; struct bitcoin_blkid chain_hash;
struct short_channel_id scid; struct short_channel_id scid;
struct pubkey node_id_1; struct node_id node_id_1;
struct pubkey node_id_2; struct node_id node_id_2;
struct pubkey bitcoin_key_1; struct pubkey bitcoin_key_1;
struct pubkey bitcoin_key_2; struct pubkey bitcoin_key_2;
/* FIXME */
struct pubkey pk1, pk2;
if (!fromwire_channel_announcement( if (!fromwire_channel_announcement(
tmpctx, msg, &node_signature_1, &node_signature_2, tmpctx, msg, &node_signature_1, &node_signature_2,
&bitcoin_signature_1, &bitcoin_signature_2, &features, &chain_hash, &bitcoin_signature_1, &bitcoin_signature_2, &features, &chain_hash,
&scid, &node_id_1, &node_id_2, &bitcoin_key_1, &bitcoin_key_2)) &scid, &pk1, &pk2, &bitcoin_key_1, &bitcoin_key_2))
return false; return false;
node_id_from_pubkey(&node_id_1, &pk1);
node_id_from_pubkey(&node_id_2, &pk2);
/* The channel may already exist if it was non-public from /* The channel may already exist if it was non-public from
* local_add_channel(); normally we don't accept new * local_add_channel(); normally we don't accept new
@ -926,6 +942,8 @@ u8 *handle_channel_announcement(struct routing_state *rstate,
announce, tal_count(announce), 0); announce, tal_count(announce), 0);
pending->update_timestamps[0] = pending->update_timestamps[1] = 0; pending->update_timestamps[0] = pending->update_timestamps[1] = 0;
/* FIXME */
struct pubkey pk1, pk2;
if (!fromwire_channel_announcement(pending, pending->announce, if (!fromwire_channel_announcement(pending, pending->announce,
&node_signature_1, &node_signature_1,
&node_signature_2, &node_signature_2,
@ -934,8 +952,7 @@ u8 *handle_channel_announcement(struct routing_state *rstate,
&features, &features,
&chain_hash, &chain_hash,
&pending->short_channel_id, &pending->short_channel_id,
&pending->node_id_1, &pk1, &pk2,
&pending->node_id_2,
&pending->bitcoin_key_1, &pending->bitcoin_key_1,
&pending->bitcoin_key_2)) { &pending->bitcoin_key_2)) {
err = towire_errorfmt(rstate, NULL, err = towire_errorfmt(rstate, NULL,
@ -943,6 +960,8 @@ u8 *handle_channel_announcement(struct routing_state *rstate,
tal_hex(pending, pending->announce)); tal_hex(pending, pending->announce));
goto malformed; goto malformed;
} }
node_id_from_pubkey(&pending->node_id_1, &pk1);
node_id_from_pubkey(&pending->node_id_2, &pk2);
/* If a prior txout lookup failed there is little point it trying /* If a prior txout lookup failed there is little point it trying
* again. Just drop the announcement and walk away whistling. Any non-0 * again. Just drop the announcement and walk away whistling. Any non-0
@ -1481,17 +1500,20 @@ bool routing_add_node_announcement(struct routing_state *rstate, const u8 *msg T
struct node *node; struct node *node;
secp256k1_ecdsa_signature signature; secp256k1_ecdsa_signature signature;
u32 timestamp; u32 timestamp;
struct pubkey node_id; struct node_id node_id;
u8 rgb_color[3]; u8 rgb_color[3];
u8 alias[32]; u8 alias[32];
u8 *features, *addresses; u8 *features, *addresses;
struct wireaddr *wireaddrs; struct wireaddr *wireaddrs;
/* FIXME */
struct pubkey pk;
if (!fromwire_node_announcement(tmpctx, msg, if (!fromwire_node_announcement(tmpctx, msg,
&signature, &features, &timestamp, &signature, &features, &timestamp,
&node_id, rgb_color, alias, &pk, rgb_color, alias,
&addresses)) &addresses))
return false; return false;
node_id_from_pubkey(&node_id, &pk);
node = get_node(rstate, &node_id); node = get_node(rstate, &node_id);
@ -1528,7 +1550,7 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
struct node *node; struct node *node;
secp256k1_ecdsa_signature signature; secp256k1_ecdsa_signature signature;
u32 timestamp; u32 timestamp;
struct pubkey node_id; struct node_id node_id;
u8 rgb_color[3]; u8 rgb_color[3];
u8 alias[32]; u8 alias[32];
u8 *features, *addresses; u8 *features, *addresses;
@ -1538,9 +1560,11 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
bool applied; bool applied;
serialized = tal_dup_arr(tmpctx, u8, node_ann, len, 0); serialized = tal_dup_arr(tmpctx, u8, node_ann, len, 0);
/* FIXME */
struct pubkey pk;
if (!fromwire_node_announcement(tmpctx, serialized, if (!fromwire_node_announcement(tmpctx, serialized,
&signature, &features, &timestamp, &signature, &features, &timestamp,
&node_id, rgb_color, alias, &pk, rgb_color, alias,
&addresses)) { &addresses)) {
/* BOLT #7: /* BOLT #7:
* *
@ -1553,6 +1577,7 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
tal_hex(tmpctx, node_ann)); tal_hex(tmpctx, node_ann));
return err; return err;
} }
node_id_from_pubkey(&node_id, &pk);
/* BOLT #7: /* BOLT #7:
* *
@ -1565,13 +1590,13 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
*/ */
if (!features_supported(features, NULL)) { if (!features_supported(features, NULL)) {
status_trace("Ignoring node announcement for node %s, unsupported features %s.", status_trace("Ignoring node announcement for node %s, unsupported features %s.",
type_to_string(tmpctx, struct pubkey, &node_id), type_to_string(tmpctx, struct node_id, &node_id),
tal_hex(tmpctx, features)); tal_hex(tmpctx, features));
return NULL; return NULL;
} }
sha256_double(&hash, serialized + 66, tal_count(serialized) - 66); sha256_double(&hash, serialized + 66, tal_count(serialized) - 66);
if (!check_signed_hash(&hash, &signature, &node_id)) { if (!check_signed_hash_nodeid(&hash, &signature, &node_id)) {
/* BOLT #7: /* BOLT #7:
* *
* - if `signature` is not a valid signature, using * - if `signature` is not a valid signature, using
@ -1628,12 +1653,12 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
&node_id); &node_id);
if (!pna) { if (!pna) {
bad_gossip_order(serialized, "node_announcement", bad_gossip_order(serialized, "node_announcement",
type_to_string(tmpctx, struct pubkey, type_to_string(tmpctx, struct node_id,
&node_id)); &node_id));
} else if (pna->timestamp < timestamp) { } else if (pna->timestamp < timestamp) {
SUPERVERBOSE( SUPERVERBOSE(
"Deferring node_announcement for node %s", "Deferring node_announcement for node %s",
type_to_string(tmpctx, struct pubkey, &node_id)); type_to_string(tmpctx, struct node_id, &node_id));
pna->timestamp = timestamp; pna->timestamp = timestamp;
tal_free(pna->node_announcement); tal_free(pna->node_announcement);
pna->node_announcement = tal_dup_arr(pna, u8, node_ann, pna->node_announcement = tal_dup_arr(pna, u8, node_ann,
@ -1649,7 +1674,7 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
} }
status_trace("Received node_announcement for node %s", status_trace("Received node_announcement for node %s",
type_to_string(tmpctx, struct pubkey, &node_id)); type_to_string(tmpctx, struct node_id, &node_id));
applied = routing_add_node_announcement(rstate, serialized); applied = routing_add_node_announcement(rstate, serialized);
assert(applied); assert(applied);
@ -1657,8 +1682,8 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
} }
struct route_hop *get_route(const tal_t *ctx, struct routing_state *rstate, struct route_hop *get_route(const tal_t *ctx, struct routing_state *rstate,
const struct pubkey *source, const struct node_id *source,
const struct pubkey *destination, const struct node_id *destination,
struct amount_msat msat, double riskfactor, struct amount_msat msat, double riskfactor,
u32 final_cltv, u32 final_cltv,
double fuzz, u64 seed, double fuzz, u64 seed,
@ -1733,13 +1758,13 @@ struct route_hop *get_route(const tal_t *ctx, struct routing_state *rstate,
total_delay += c->delay; total_delay += c->delay;
n = other_node(n, route[i]); n = other_node(n, route[i]);
} }
assert(pubkey_eq(&n->id, source)); assert(node_id_eq(&n->id, source));
return hops; return hops;
} }
void routing_failure(struct routing_state *rstate, void routing_failure(struct routing_state *rstate,
const struct pubkey *erring_node_pubkey, const struct node_id *erring_node_id,
const struct short_channel_id *scid, const struct short_channel_id *scid,
int erring_direction, int erring_direction,
enum onion_type failcode, enum onion_type failcode,
@ -1749,7 +1774,7 @@ void routing_failure(struct routing_state *rstate,
"erring node %s, " "erring node %s, "
"channel %s/%u", "channel %s/%u",
(int) failcode, onion_type_name(failcode), (int) failcode, onion_type_name(failcode),
type_to_string(tmpctx, struct pubkey, erring_node_pubkey), type_to_string(tmpctx, struct node_id, erring_node_id),
type_to_string(tmpctx, struct short_channel_id, scid), type_to_string(tmpctx, struct short_channel_id, scid),
erring_direction); erring_direction);
@ -1775,18 +1800,18 @@ void routing_failure(struct routing_state *rstate,
return; return;
if (failcode & NODE) { if (failcode & NODE) {
struct node *node = get_node(rstate, erring_node_pubkey); struct node *node = get_node(rstate, erring_node_id);
if (!node) { if (!node) {
status_unusual("routing_failure: Erring node %s not in map", status_unusual("routing_failure: Erring node %s not in map",
type_to_string(tmpctx, struct pubkey, type_to_string(tmpctx, struct node_id,
erring_node_pubkey)); erring_node_id));
} else { } else {
struct chan_map_iter i; struct chan_map_iter i;
struct chan *c; struct chan *c;
status_trace("Deleting node %s", status_trace("Deleting node %s",
type_to_string(tmpctx, type_to_string(tmpctx,
struct pubkey, struct node_id,
&node->id)); &node->id));
for (c = first_chan(node, &i); c; c = next_chan(node, &i)) { for (c = first_chan(node, &i); c; c = next_chan(node, &i)) {
/* Set it up to be pruned. */ /* Set it up to be pruned. */
@ -1806,8 +1831,8 @@ void routing_failure(struct routing_state *rstate,
/* This error can be triggered by sendpay if caller /* This error can be triggered by sendpay if caller
* uses the wrong key for dest. */ * uses the wrong key for dest. */
if (failcode == WIRE_INVALID_ONION_HMAC if (failcode == WIRE_INVALID_ONION_HMAC
&& !pubkey_eq(&chan->nodes[!erring_direction]->id, && !node_id_eq(&chan->nodes[!erring_direction]->id,
erring_node_pubkey)) erring_node_id))
return; return;
status_trace("Deleting channel %s", status_trace("Deleting channel %s",
@ -1879,7 +1904,7 @@ void memleak_remove_routing_tables(struct htable *memtable,
bool handle_local_add_channel(struct routing_state *rstate, const u8 *msg) bool handle_local_add_channel(struct routing_state *rstate, const u8 *msg)
{ {
struct short_channel_id scid; struct short_channel_id scid;
struct pubkey remote_node_id; struct node_id remote_node_id;
struct amount_sat sat; struct amount_sat sat;
if (!fromwire_gossipd_local_add_channel(msg, &scid, &remote_node_id, if (!fromwire_gossipd_local_add_channel(msg, &scid, &remote_node_id,

28
gossipd/routing.h

@ -6,6 +6,7 @@
#include <ccan/htable/htable_type.h> #include <ccan/htable/htable_type.h>
#include <ccan/time/time.h> #include <ccan/time/time.h>
#include <common/amount.h> #include <common/amount.h>
#include <common/node_id.h>
#include <gossipd/broadcast.h> #include <gossipd/broadcast.h>
#include <gossipd/gossip_constants.h> #include <gossipd/gossip_constants.h>
#include <gossipd/gossip_store.h> #include <gossipd/gossip_store.h>
@ -111,7 +112,7 @@ HTABLE_DEFINE_TYPE(struct chan, chan_map_scid, hash_scid, chan_eq_scid, chan_map
#define NUM_IMMEDIATE_CHANS (sizeof(struct chan_map) / sizeof(struct chan *) - 1) #define NUM_IMMEDIATE_CHANS (sizeof(struct chan_map) / sizeof(struct chan *) - 1)
struct node { struct node {
struct pubkey id; struct node_id id;
/* -1 means never; other fields undefined */ /* -1 means never; other fields undefined */
s64 last_timestamp; s64 last_timestamp;
@ -150,9 +151,9 @@ struct node {
u64 node_announcement_index; u64 node_announcement_index;
}; };
const struct pubkey *node_map_keyof_node(const struct node *n); const struct node_id *node_map_keyof_node(const struct node *n);
size_t node_map_hash_key(const struct pubkey *key); size_t node_map_hash_key(const struct node_id *pc);
bool node_map_node_eq(const struct node *n, const struct pubkey *key); bool node_map_node_eq(const struct node *n, const struct node_id *pc);
HTABLE_DEFINE_TYPE(struct node, node_map_keyof_node, node_map_hash_key, node_map_node_eq, node_map); HTABLE_DEFINE_TYPE(struct node, node_map_keyof_node, node_map_hash_key, node_map_node_eq, node_map);
struct pending_node_map; struct pending_node_map;
@ -204,7 +205,7 @@ struct routing_state {
struct broadcast_state *broadcasts; struct broadcast_state *broadcasts;
/* Our own ID so we can identify local channels */ /* Our own ID so we can identify local channels */
struct pubkey local_id; struct node_id local_id;
/* How old does a channel have to be before we prune it? */ /* How old does a channel have to be before we prune it? */
u32 prune_timeout; u32 prune_timeout;
@ -243,14 +244,14 @@ get_channel(const struct routing_state *rstate,
struct route_hop { struct route_hop {
struct short_channel_id channel_id; struct short_channel_id channel_id;
int direction; int direction;
struct pubkey nodeid; struct node_id nodeid;
struct amount_msat amount; struct amount_msat amount;
u32 delay; u32 delay;
}; };
struct routing_state *new_routing_state(const tal_t *ctx, struct routing_state *new_routing_state(const tal_t *ctx,
const struct chainparams *chainparams, const struct chainparams *chainparams,
const struct pubkey *local_id, const struct node_id *local_id,
u32 prune_timeout, u32 prune_timeout,
const u32 *dev_gossip_time, const u32 *dev_gossip_time,
const struct amount_sat *dev_unknown_channel_satoshis); const struct amount_sat *dev_unknown_channel_satoshis);
@ -263,8 +264,8 @@ struct routing_state *new_routing_state(const tal_t *ctx,
*/ */
struct chan *new_chan(struct routing_state *rstate, struct chan *new_chan(struct routing_state *rstate,
const struct short_channel_id *scid, const struct short_channel_id *scid,
const struct pubkey *id1, const struct node_id *id1,
const struct pubkey *id2, const struct node_id *id2,
struct amount_sat sat); struct amount_sat sat);
/* Handlers for incoming messages */ /* Handlers for incoming messages */
@ -300,12 +301,13 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update TAKES,
u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node); u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node);
/* Get a node: use this instead of node_map_get() */ /* Get a node: use this instead of node_map_get() */
struct node *get_node(struct routing_state *rstate, const struct pubkey *id); struct node *get_node(struct routing_state *rstate,
const struct node_id *id);
/* Compute a route to a destination, for a given amount and riskfactor. */ /* Compute a route to a destination, for a given amount and riskfactor. */
struct route_hop *get_route(const tal_t *ctx, struct routing_state *rstate, struct route_hop *get_route(const tal_t *ctx, struct routing_state *rstate,
const struct pubkey *source, const struct node_id *source,
const struct pubkey *destination, const struct node_id *destination,
const struct amount_msat msat, double riskfactor, const struct amount_msat msat, double riskfactor,
u32 final_cltv, u32 final_cltv,
double fuzz, double fuzz,
@ -314,7 +316,7 @@ struct route_hop *get_route(const tal_t *ctx, struct routing_state *rstate,
size_t max_hops); size_t max_hops);
/* Disable channel(s) based on the given routing failure. */ /* Disable channel(s) based on the given routing failure. */
void routing_failure(struct routing_state *rstate, void routing_failure(struct routing_state *rstate,
const struct pubkey *erring_node, const struct node_id *erring_node,
const struct short_channel_id *erring_channel, const struct short_channel_id *erring_channel,
int erring_direction, int erring_direction,
enum onion_type failcode, enum onion_type failcode,

1
gossipd/test/Makefile

@ -9,6 +9,7 @@ GOSSIPD_TEST_PROGRAMS := $(GOSSIPD_TEST_OBJS:.o=)
GOSSIPD_TEST_COMMON_OBJS := \ GOSSIPD_TEST_COMMON_OBJS := \
common/amount.o \ common/amount.o \
common/features.o \ common/features.o \
common/node_id.o \
common/pseudorand.o \ common/pseudorand.o \
common/type_to_string.o \ common/type_to_string.o \
common/utils.o common/utils.o

30
gossipd/test/run-bench-find_route.c

@ -44,7 +44,7 @@ bool fromwire_channel_update(const void *p UNNEEDED, secp256k1_ecdsa_signature *
bool fromwire_channel_update_option_channel_htlc_max(const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, u32 *timestamp UNNEEDED, u8 *message_flags UNNEEDED, u8 *channel_flags UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, struct amount_msat *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED, struct amount_msat *htlc_maximum_msat UNNEEDED) bool fromwire_channel_update_option_channel_htlc_max(const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, u32 *timestamp UNNEEDED, u8 *message_flags UNNEEDED, u8 *channel_flags UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, struct amount_msat *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED, struct amount_msat *htlc_maximum_msat UNNEEDED)
{ fprintf(stderr, "fromwire_channel_update_option_channel_htlc_max called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_update_option_channel_htlc_max called!\n"); abort(); }
/* Generated stub for fromwire_gossipd_local_add_channel */ /* Generated stub for fromwire_gossipd_local_add_channel */
bool fromwire_gossipd_local_add_channel(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *remote_node_id UNNEEDED, struct amount_sat *satoshis UNNEEDED) bool fromwire_gossipd_local_add_channel(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct node_id *remote_node_id UNNEEDED, struct amount_sat *satoshis UNNEEDED)
{ fprintf(stderr, "fromwire_gossipd_local_add_channel called!\n"); abort(); } { fprintf(stderr, "fromwire_gossipd_local_add_channel called!\n"); abort(); }
/* Generated stub for fromwire_gossip_store_channel_announcement */ /* Generated stub for fromwire_gossip_store_channel_announcement */
bool fromwire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED, struct amount_sat *satoshis UNNEEDED) bool fromwire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED, struct amount_sat *satoshis UNNEEDED)
@ -96,7 +96,7 @@ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED,
const char *fmt UNNEEDED, ...) const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); } { fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
/* Generated stub for towire_gossipd_local_add_channel */ /* Generated stub for towire_gossipd_local_add_channel */
u8 *towire_gossipd_local_add_channel(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED, const struct pubkey *remote_node_id UNNEEDED, struct amount_sat satoshis UNNEEDED) u8 *towire_gossipd_local_add_channel(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED, const struct node_id *remote_node_id UNNEEDED, struct amount_sat satoshis UNNEEDED)
{ fprintf(stderr, "towire_gossipd_local_add_channel called!\n"); abort(); } { fprintf(stderr, "towire_gossipd_local_add_channel called!\n"); abort(); }
/* Generated stub for towire_gossip_store_channel_announcement */ /* Generated stub for towire_gossip_store_channel_announcement */
u8 *towire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const u8 *announcement UNNEEDED, struct amount_sat satoshis UNNEEDED) u8 *towire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const u8 *announcement UNNEEDED, struct amount_sat satoshis UNNEEDED)
@ -129,7 +129,7 @@ void memleak_remove_intmap_(struct htable *memtable UNNEEDED, const struct intma
/* Updates existing route if required. */ /* Updates existing route if required. */
static void add_connection(struct routing_state *rstate, static void add_connection(struct routing_state *rstate,
const struct pubkey *nodes, const struct node_id *nodes,
u32 from, u32 to, u32 from, u32 to,
u32 base_fee, s32 proportional_fee, u32 base_fee, s32 proportional_fee,
u32 delay) u32 delay)
@ -137,7 +137,7 @@ static void add_connection(struct routing_state *rstate,
struct short_channel_id scid; struct short_channel_id scid;
struct half_chan *c; struct half_chan *c;
struct chan *chan; struct chan *chan;
int idx = pubkey_idx(&nodes[from], &nodes[to]); int idx = node_id_idx(&nodes[from], &nodes[to]);
/* Encode src and dst in scid. */ /* Encode src and dst in scid. */
memcpy((char *)&scid + idx * sizeof(from), &from, sizeof(from)); memcpy((char *)&scid + idx * sizeof(from), &from, sizeof(from));
@ -152,26 +152,28 @@ static void add_connection(struct routing_state *rstate,
c->base_fee = base_fee; c->base_fee = base_fee;
c->proportional_fee = proportional_fee; c->proportional_fee = proportional_fee;
c->delay = delay; c->delay = delay;
c->channel_flags = get_channel_direction(&nodes[from], &nodes[to]); c->channel_flags = node_id_idx(&nodes[from], &nodes[to]);
/* This must be non-NULL, otherwise we consider it disabled! */ /* This must be non-NULL, otherwise we consider it disabled! */
c->channel_update = tal(chan, u8); c->channel_update = tal(chan, u8);
c->htlc_maximum = AMOUNT_MSAT(-1ULL); c->htlc_maximum = AMOUNT_MSAT(-1ULL);
c->htlc_minimum = AMOUNT_MSAT(0); c->htlc_minimum = AMOUNT_MSAT(0);
} }
static struct pubkey nodeid(size_t n) static struct node_id nodeid(size_t n)
{ {
struct pubkey id; struct node_id id;
struct pubkey k;
struct secret s; struct secret s;
memset(&s, 0xFF, sizeof(s)); memset(&s, 0xFF, sizeof(s));
memcpy(&s, &n, sizeof(n)); memcpy(&s, &n, sizeof(n));
pubkey_from_secret(&s, &id); pubkey_from_secret(&s, &k);
node_id_from_pubkey(&id, &k);
return id; return id;
} }
static void populate_random_node(struct routing_state *rstate, static void populate_random_node(struct routing_state *rstate,
const struct pubkey *nodes, const struct node_id *nodes,
u32 n) u32 n)
{ {
/* Create 2 random channels. */ /* Create 2 random channels. */
@ -217,8 +219,8 @@ int main(int argc, char *argv[])
size_t num_nodes = 100, num_runs = 1; size_t num_nodes = 100, num_runs = 1;
struct timemono start, end; struct timemono start, end;
size_t num_success; size_t num_success;
struct pubkey me; struct node_id me;
struct pubkey *nodes; struct node_id *nodes;
bool perfme = false; bool perfme = false;
const double riskfactor = 0.01 / BLOCKS_PER_YEAR / 10000; const double riskfactor = 0.01 / BLOCKS_PER_YEAR / 10000;
struct siphash_seed base_seed; struct siphash_seed base_seed;
@ -241,7 +243,7 @@ int main(int argc, char *argv[])
if (argc > 3) if (argc > 3)
opt_usage_and_exit("[num_nodes [num_runs]]"); opt_usage_and_exit("[num_nodes [num_runs]]");
nodes = tal_arr(rstate, struct pubkey, num_nodes); nodes = tal_arr(rstate, struct node_id, num_nodes);
for (size_t i = 0; i < num_nodes; i++) for (size_t i = 0; i < num_nodes; i++)
nodes[i] = nodeid(i); nodes[i] = nodeid(i);
@ -255,8 +257,8 @@ int main(int argc, char *argv[])
start = time_mono(); start = time_mono();
num_success = 0; num_success = 0;
for (size_t i = 0; i < num_runs; i++) { for (size_t i = 0; i < num_runs; i++) {
const struct pubkey *from = &nodes[pseudorand(num_nodes)]; const struct node_id *from = &nodes[pseudorand(num_nodes)];
const struct pubkey *to = &nodes[pseudorand(num_nodes)]; const struct node_id *to = &nodes[pseudorand(num_nodes)];
struct amount_msat fee; struct amount_msat fee;
struct chan **route; struct chan **route;

30
gossipd/test/run-find_route-specific.c

@ -33,7 +33,7 @@ bool fromwire_channel_update(const void *p UNNEEDED, secp256k1_ecdsa_signature *
bool fromwire_channel_update_option_channel_htlc_max(const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, u32 *timestamp UNNEEDED, u8 *message_flags UNNEEDED, u8 *channel_flags UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, struct amount_msat *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED, struct amount_msat *htlc_maximum_msat UNNEEDED) bool fromwire_channel_update_option_channel_htlc_max(const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, u32 *timestamp UNNEEDED, u8 *message_flags UNNEEDED, u8 *channel_flags UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, struct amount_msat *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED, struct amount_msat *htlc_maximum_msat UNNEEDED)
{ fprintf(stderr, "fromwire_channel_update_option_channel_htlc_max called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_update_option_channel_htlc_max called!\n"); abort(); }
/* Generated stub for fromwire_gossipd_local_add_channel */ /* Generated stub for fromwire_gossipd_local_add_channel */
bool fromwire_gossipd_local_add_channel(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *remote_node_id UNNEEDED, struct amount_sat *satoshis UNNEEDED) bool fromwire_gossipd_local_add_channel(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct node_id *remote_node_id UNNEEDED, struct amount_sat *satoshis UNNEEDED)
{ fprintf(stderr, "fromwire_gossipd_local_add_channel called!\n"); abort(); } { fprintf(stderr, "fromwire_gossipd_local_add_channel called!\n"); abort(); }
/* Generated stub for fromwire_gossip_store_channel_announcement */ /* Generated stub for fromwire_gossip_store_channel_announcement */
bool fromwire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED, struct amount_sat *satoshis UNNEEDED) bool fromwire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED, struct amount_sat *satoshis UNNEEDED)
@ -85,7 +85,7 @@ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED,
const char *fmt UNNEEDED, ...) const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); } { fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
/* Generated stub for towire_gossipd_local_add_channel */ /* Generated stub for towire_gossipd_local_add_channel */
u8 *towire_gossipd_local_add_channel(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED, const struct pubkey *remote_node_id UNNEEDED, struct amount_sat satoshis UNNEEDED) u8 *towire_gossipd_local_add_channel(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED, const struct node_id *remote_node_id UNNEEDED, struct amount_sat satoshis UNNEEDED)
{ fprintf(stderr, "towire_gossipd_local_add_channel called!\n"); abort(); } { fprintf(stderr, "towire_gossipd_local_add_channel called!\n"); abort(); }
/* Generated stub for towire_gossip_store_channel_announcement */ /* Generated stub for towire_gossip_store_channel_announcement */
u8 *towire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const u8 *announcement UNNEEDED, struct amount_sat satoshis UNNEEDED) u8 *towire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const u8 *announcement UNNEEDED, struct amount_sat satoshis UNNEEDED)
@ -120,14 +120,14 @@ const void *trc;
static struct half_chan * static struct half_chan *
get_or_make_connection(struct routing_state *rstate, get_or_make_connection(struct routing_state *rstate,
const struct pubkey *from_id, const struct node_id *from_id,
const struct pubkey *to_id, const struct node_id *to_id,
const char *shortid, const char *shortid,
struct amount_sat satoshis) struct amount_sat satoshis)
{ {
struct short_channel_id scid; struct short_channel_id scid;
struct chan *chan; struct chan *chan;
const int idx = pubkey_idx(from_id, to_id); const int idx = node_id_idx(from_id, to_id);
if (!short_channel_id_from_str(shortid, strlen(shortid), &scid, if (!short_channel_id_from_str(shortid, strlen(shortid), &scid,
false)) false))
@ -146,14 +146,14 @@ get_or_make_connection(struct routing_state *rstate,
} }
static bool channel_is_between(const struct chan *chan, static bool channel_is_between(const struct chan *chan,
const struct pubkey *a, const struct pubkey *b) const struct node_id *a, const struct node_id *b)
{ {
if (pubkey_eq(&chan->nodes[0]->id, a) if (node_id_eq(&chan->nodes[0]->id, a)
&& pubkey_eq(&chan->nodes[1]->id, b)) && node_id_eq(&chan->nodes[1]->id, b))
return true; return true;
if (pubkey_eq(&chan->nodes[0]->id, b) if (node_id_eq(&chan->nodes[0]->id, b)
&& pubkey_eq(&chan->nodes[1]->id, a)) && node_id_eq(&chan->nodes[1]->id, a))
return true; return true;
return false; return false;
@ -165,7 +165,7 @@ int main(void)
struct half_chan *nc; struct half_chan *nc;
struct routing_state *rstate; struct routing_state *rstate;
struct pubkey a, b, c, d; struct node_id a, b, c, d;
struct amount_msat fee; struct amount_msat fee;
struct chan **route; struct chan **route;
const double riskfactor = 1.0 / BLOCKS_PER_YEAR / 10000; const double riskfactor = 1.0 / BLOCKS_PER_YEAR / 10000;
@ -174,16 +174,16 @@ int main(void)
| SECP256K1_CONTEXT_SIGN); | SECP256K1_CONTEXT_SIGN);
setup_tmpctx(); setup_tmpctx();
pubkey_from_hexstr("03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf", node_id_from_hexstr("03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf",
strlen("03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf"), strlen("03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf"),
&a); &a);
pubkey_from_hexstr("0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae", node_id_from_hexstr("0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae",
strlen("0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae"), strlen("0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae"),
&b); &b);
pubkey_from_hexstr("02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06", node_id_from_hexstr("02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06",
strlen("02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06"), strlen("02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06"),
&c); &c);
pubkey_from_hexstr("02cca6c5c966fcf61d121e3a70e03a1cd9eeeea024b26ea666ce974d43b242e636", node_id_from_hexstr("02cca6c5c966fcf61d121e3a70e03a1cd9eeeea024b26ea666ce974d43b242e636",
strlen("02cca6c5c966fcf61d121e3a70e03a1cd9eeeea024b26ea666ce974d43b242e636"), strlen("02cca6c5c966fcf61d121e3a70e03a1cd9eeeea024b26ea666ce974d43b242e636"),
&d); &d);

53
gossipd/test/run-find_route.c

@ -31,7 +31,7 @@ bool fromwire_channel_update(const void *p UNNEEDED, secp256k1_ecdsa_signature *
bool fromwire_channel_update_option_channel_htlc_max(const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, u32 *timestamp UNNEEDED, u8 *message_flags UNNEEDED, u8 *channel_flags UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, struct amount_msat *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED, struct amount_msat *htlc_maximum_msat UNNEEDED) bool fromwire_channel_update_option_channel_htlc_max(const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, u32 *timestamp UNNEEDED, u8 *message_flags UNNEEDED, u8 *channel_flags UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, struct amount_msat *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED, struct amount_msat *htlc_maximum_msat UNNEEDED)
{ fprintf(stderr, "fromwire_channel_update_option_channel_htlc_max called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_update_option_channel_htlc_max called!\n"); abort(); }
/* Generated stub for fromwire_gossipd_local_add_channel */ /* Generated stub for fromwire_gossipd_local_add_channel */
bool fromwire_gossipd_local_add_channel(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *remote_node_id UNNEEDED, struct amount_sat *satoshis UNNEEDED) bool fromwire_gossipd_local_add_channel(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct node_id *remote_node_id UNNEEDED, struct amount_sat *satoshis UNNEEDED)
{ fprintf(stderr, "fromwire_gossipd_local_add_channel called!\n"); abort(); } { fprintf(stderr, "fromwire_gossipd_local_add_channel called!\n"); abort(); }
/* Generated stub for fromwire_gossip_store_channel_announcement */ /* Generated stub for fromwire_gossip_store_channel_announcement */
bool fromwire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED, struct amount_sat *satoshis UNNEEDED) bool fromwire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED, struct amount_sat *satoshis UNNEEDED)
@ -83,7 +83,7 @@ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED,
const char *fmt UNNEEDED, ...) const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); } { fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
/* Generated stub for towire_gossipd_local_add_channel */ /* Generated stub for towire_gossipd_local_add_channel */
u8 *towire_gossipd_local_add_channel(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED, const struct pubkey *remote_node_id UNNEEDED, struct amount_sat satoshis UNNEEDED) u8 *towire_gossipd_local_add_channel(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED, const struct node_id *remote_node_id UNNEEDED, struct amount_sat satoshis UNNEEDED)
{ fprintf(stderr, "towire_gossipd_local_add_channel called!\n"); abort(); } { fprintf(stderr, "towire_gossipd_local_add_channel called!\n"); abort(); }
/* Generated stub for towire_gossip_store_channel_announcement */ /* Generated stub for towire_gossip_store_channel_announcement */
u8 *towire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const u8 *announcement UNNEEDED, struct amount_sat satoshis UNNEEDED) u8 *towire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const u8 *announcement UNNEEDED, struct amount_sat satoshis UNNEEDED)
@ -114,10 +114,17 @@ void memleak_remove_intmap_(struct htable *memtable UNNEEDED, const struct intma
{ fprintf(stderr, "memleak_remove_intmap_ called!\n"); abort(); } { fprintf(stderr, "memleak_remove_intmap_ called!\n"); abort(); }
#endif #endif
static void node_id_from_privkey(const struct privkey *p, struct node_id *id)
{
struct pubkey k;
pubkey_from_privkey(p, &k);
node_id_from_pubkey(id, &k);
}
/* Updates existing route if required. */ /* Updates existing route if required. */
static void add_connection(struct routing_state *rstate, static void add_connection(struct routing_state *rstate,
const struct pubkey *from, const struct node_id *from,
const struct pubkey *to, const struct node_id *to,
u32 base_fee, s32 proportional_fee, u32 base_fee, s32 proportional_fee,
u32 delay) u32 delay)
{ {
@ -134,13 +141,13 @@ static void add_connection(struct routing_state *rstate,
if (!chan) if (!chan)
chan = new_chan(rstate, &scid, from, to, satoshis); chan = new_chan(rstate, &scid, from, to, satoshis);
c = &chan->half[pubkey_idx(from, to)]; c = &chan->half[node_id_idx(from, to)];
/* Make sure it's seen as initialized (update non-NULL). */ /* Make sure it's seen as initialized (update non-NULL). */
c->channel_update = (void *)c; c->channel_update = (void *)c;
c->base_fee = base_fee; c->base_fee = base_fee;
c->proportional_fee = proportional_fee; c->proportional_fee = proportional_fee;
c->delay = delay; c->delay = delay;
c->channel_flags = get_channel_direction(from, to); c->channel_flags = node_id_idx(from, to);
c->htlc_minimum = AMOUNT_MSAT(0); c->htlc_minimum = AMOUNT_MSAT(0);
c->htlc_maximum = AMOUNT_MSAT(100000 * 1000); c->htlc_maximum = AMOUNT_MSAT(100000 * 1000);
} }
@ -155,7 +162,7 @@ static struct chan *find_channel(struct routing_state *rstate UNUSED,
struct chan_map_iter i; struct chan_map_iter i;
struct chan *c; struct chan *c;
*idx = pubkey_idx(&from->id, &to->id); *idx = node_id_idx(&from->id, &to->id);
for (c = first_chan(to, &i); c; c = next_chan(to, &i)) { for (c = first_chan(to, &i); c; c = next_chan(to, &i)) {
if (c->nodes[*idx] == from) if (c->nodes[*idx] == from)
@ -165,8 +172,8 @@ static struct chan *find_channel(struct routing_state *rstate UNUSED,
} }
static struct half_chan *get_connection(struct routing_state *rstate, static struct half_chan *get_connection(struct routing_state *rstate,
const struct pubkey *from_id, const struct node_id *from_id,
const struct pubkey *to_id) const struct node_id *to_id)
{ {
int idx; int idx;
struct node *from, *to; struct node *from, *to;
@ -184,14 +191,14 @@ static struct half_chan *get_connection(struct routing_state *rstate,
} }
static bool channel_is_between(const struct chan *chan, static bool channel_is_between(const struct chan *chan,
const struct pubkey *a, const struct pubkey *b) const struct node_id *a, const struct node_id *b)
{ {
if (pubkey_eq(&chan->nodes[0]->id, a) if (node_id_eq(&chan->nodes[0]->id, a)
&& pubkey_eq(&chan->nodes[1]->id, b)) && node_id_eq(&chan->nodes[1]->id, b))
return true; return true;
if (pubkey_eq(&chan->nodes[0]->id, b) if (node_id_eq(&chan->nodes[0]->id, b)
&& pubkey_eq(&chan->nodes[1]->id, a)) && node_id_eq(&chan->nodes[1]->id, a))
return true; return true;
return false; return false;
@ -202,7 +209,7 @@ int main(void)
setup_locale(); setup_locale();
struct routing_state *rstate; struct routing_state *rstate;
struct pubkey a, b, c, d; struct node_id a, b, c, d;
struct privkey tmp; struct privkey tmp;
struct amount_msat fee; struct amount_msat fee;
struct chan **route; struct chan **route;
@ -213,13 +220,13 @@ int main(void)
setup_tmpctx(); setup_tmpctx();
memset(&tmp, 'a', sizeof(tmp)); memset(&tmp, 'a', sizeof(tmp));
pubkey_from_privkey(&tmp, &a); node_id_from_privkey(&tmp, &a);
rstate = new_routing_state(tmpctx, NULL, &a, 0, NULL, NULL); rstate = new_routing_state(tmpctx, NULL, &a, 0, NULL, NULL);
new_node(rstate, &a); new_node(rstate, &a);
memset(&tmp, 'b', sizeof(tmp)); memset(&tmp, 'b', sizeof(tmp));
pubkey_from_privkey(&tmp, &b); node_id_from_privkey(&tmp, &b);
new_node(rstate, &b); new_node(rstate, &b);
/* A<->B */ /* A<->B */
@ -233,12 +240,12 @@ int main(void)
/* A<->B<->C */ /* A<->B<->C */
memset(&tmp, 'c', sizeof(tmp)); memset(&tmp, 'c', sizeof(tmp));
pubkey_from_privkey(&tmp, &c); node_id_from_privkey(&tmp, &c);
new_node(rstate, &c); new_node(rstate, &c);
status_trace("A = %s", type_to_string(tmpctx, struct pubkey, &a)); status_trace("A = %s", type_to_string(tmpctx, struct node_id, &a));
status_trace("B = %s", type_to_string(tmpctx, struct pubkey, &b)); status_trace("B = %s", type_to_string(tmpctx, struct node_id, &b));
status_trace("C = %s", type_to_string(tmpctx, struct pubkey, &c)); status_trace("C = %s", type_to_string(tmpctx, struct node_id, &c));
add_connection(rstate, &b, &c, 1, 1, 1); add_connection(rstate, &b, &c, 1, 1, 1);
route = find_route(tmpctx, rstate, &a, &c, AMOUNT_MSAT(1000), riskfactor, 0.0, NULL, route = find_route(tmpctx, rstate, &a, &c, AMOUNT_MSAT(1000), riskfactor, 0.0, NULL,
@ -249,9 +256,9 @@ int main(void)
/* A<->D<->C: Lower base, higher percentage. */ /* A<->D<->C: Lower base, higher percentage. */
memset(&tmp, 'd', sizeof(tmp)); memset(&tmp, 'd', sizeof(tmp));
pubkey_from_privkey(&tmp, &d); node_id_from_privkey(&tmp, &d);
new_node(rstate, &d); new_node(rstate, &d);
status_trace("D = %s", type_to_string(tmpctx, struct pubkey, &d)); status_trace("D = %s", type_to_string(tmpctx, struct node_id, &d));
add_connection(rstate, &a, &d, 0, 2, 1); add_connection(rstate, &a, &d, 0, 2, 1);
add_connection(rstate, &d, &c, 0, 2, 1); add_connection(rstate, &d, &c, 0, 2, 1);

1
hsmd/Makefile

@ -24,6 +24,7 @@ HSMD_COMMON_OBJS := \
common/key_derive.o \ common/key_derive.o \
common/memleak.o \ common/memleak.o \
common/msg_queue.o \ common/msg_queue.o \
common/node_id.o \
common/permute_tx.o \ common/permute_tx.o \
common/status.o \ common/status.o \
common/status_wire.o \ common/status_wire.o \

10
hsmd/hsm_wire.csv

@ -1,6 +1,6 @@
# Clients should not give a bad request but not the HSM's decision to crash. # Clients should not give a bad request but not the HSM's decision to crash.
hsmstatus_client_bad_request,1000 hsmstatus_client_bad_request,1000
hsmstatus_client_bad_request,,id,struct pubkey hsmstatus_client_bad_request,,id,struct node_id
hsmstatus_client_bad_request,,description,wirestring hsmstatus_client_bad_request,,description,wirestring
hsmstatus_client_bad_request,,len,u16 hsmstatus_client_bad_request,,len,u16
hsmstatus_client_bad_request,,msg,len*u8 hsmstatus_client_bad_request,,msg,len*u8
@ -12,12 +12,12 @@ hsm_init,,bip32_key_version,struct bip32_key_version
#include <common/bip32.h> #include <common/bip32.h>
hsm_init_reply,111 hsm_init_reply,111
hsm_init_reply,,node_id,struct pubkey hsm_init_reply,,node_id,struct node_id
hsm_init_reply,,bip32,struct ext_key hsm_init_reply,,bip32,struct ext_key
# Get a new HSM FD, with the specified capabilities # Get a new HSM FD, with the specified capabilities
hsm_client_hsmfd,9 hsm_client_hsmfd,9
hsm_client_hsmfd,,pubkey,struct pubkey # Which identity to use for requests hsm_client_hsmfd,,id,struct node_id # Which identity to use for requests
# Database id for this client, if any. # Database id for this client, if any.
hsm_client_hsmfd,,dbid,u64 hsm_client_hsmfd,,dbid,u64
hsm_client_hsmfd,,capabilities,u64 hsm_client_hsmfd,,capabilities,u64
@ -28,7 +28,7 @@ hsm_client_hsmfd_reply,109
#include <common/derive_basepoints.h> #include <common/derive_basepoints.h>
# Get the basepoints and funding key for this specific channel. # Get the basepoints and funding key for this specific channel.
hsm_get_channel_basepoints,10 hsm_get_channel_basepoints,10
hsm_get_channel_basepoints,,peerid,struct pubkey hsm_get_channel_basepoints,,peerid,struct node_id
hsm_get_channel_basepoints,,dbid,u64 hsm_get_channel_basepoints,,dbid,u64
hsm_get_channel_basepoints_reply,110 hsm_get_channel_basepoints_reply,110
@ -105,7 +105,7 @@ hsm_cupdate_sig_reply,,cu,culen*u8
# Master asks HSM to sign a commitment transaction. # Master asks HSM to sign a commitment transaction.
hsm_sign_commitment_tx,5 hsm_sign_commitment_tx,5
hsm_sign_commitment_tx,,peer_id,struct pubkey hsm_sign_commitment_tx,,peer_id,struct node_id
hsm_sign_commitment_tx,,channel_dbid,u64 hsm_sign_commitment_tx,,channel_dbid,u64
hsm_sign_commitment_tx,,tx,struct bitcoin_tx hsm_sign_commitment_tx,,tx,struct bitcoin_tx
hsm_sign_commitment_tx,,remote_funding_key,struct pubkey hsm_sign_commitment_tx,,remote_funding_key,struct pubkey

Can't render this file because it has a wrong number of fields in line 2.

30
hsmd/hsmd.c

@ -31,6 +31,7 @@
#include <common/hash_u5.h> #include <common/hash_u5.h>
#include <common/key_derive.h> #include <common/key_derive.h>
#include <common/memleak.h> #include <common/memleak.h>
#include <common/node_id.h>
#include <common/status.h> #include <common/status.h>
#include <common/subdaemon.h> #include <common/subdaemon.h>
#include <common/type_to_string.h> #include <common/type_to_string.h>
@ -81,7 +82,7 @@ struct client {
u8 *msg_in; u8 *msg_in;
/* ~Useful for logging, but also used to derive the per-channel seed. */ /* ~Useful for logging, but also used to derive the per-channel seed. */
struct pubkey id; struct node_id id;
/* ~This is a unique value handed to us from lightningd, used for /* ~This is a unique value handed to us from lightningd, used for
* per-channel seed generation (a single id may have multiple channels * per-channel seed generation (a single id may have multiple channels
@ -195,7 +196,7 @@ static void destroy_client(struct client *c)
} }
static struct client *new_client(const tal_t *ctx, static struct client *new_client(const tal_t *ctx,
const struct pubkey *id, const struct node_id *id,
u64 dbid, u64 dbid,
const u64 capabilities, const u64 capabilities,
int fd) int fd)
@ -205,6 +206,11 @@ static struct client *new_client(const tal_t *ctx,
/*~ All-zero pubkey is used for the initial master connection */ /*~ All-zero pubkey is used for the initial master connection */
if (id) { if (id) {
c->id = *id; c->id = *id;
if (!node_id_valid(id))
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Invalid node id %s",
type_to_string(tmpctx, struct node_id,
id));
} else { } else {
memset(&c->id, 0, sizeof(c->id)); memset(&c->id, 0, sizeof(c->id));
} }
@ -323,11 +329,11 @@ static void hsm_channel_secret_base(struct secret *channel_seed_base)
} }
/*~ This gets the seed for this particular channel. */ /*~ This gets the seed for this particular channel. */
static void get_channel_seed(const struct pubkey *peer_id, u64 dbid, static void get_channel_seed(const struct node_id *peer_id, u64 dbid,
struct secret *channel_seed) struct secret *channel_seed)
{ {
struct secret channel_base; struct secret channel_base;
u8 input[PUBKEY_CMPR_LEN + sizeof(dbid)]; u8 input[sizeof(peer_id->k) + sizeof(dbid)];
/*~ Again, "per-peer" should be "per-channel", but Hysterical Raisins */ /*~ Again, "per-peer" should be "per-channel", but Hysterical Raisins */
const char *info = "per-peer seed"; const char *info = "per-peer seed";
@ -337,7 +343,8 @@ static void get_channel_seed(const struct pubkey *peer_id, u64 dbid,
/* FIXME: lnd has a nicer BIP32 method for deriving secrets which we /* FIXME: lnd has a nicer BIP32 method for deriving secrets which we
* should migrate to. */ * should migrate to. */
hsm_channel_secret_base(&channel_base); hsm_channel_secret_base(&channel_base);
pubkey_to_der(input, peer_id); memcpy(input, peer_id->k, sizeof(peer_id->k));
BUILD_ASSERT(sizeof(peer_id->k) == PUBKEY_CMPR_LEN);
/*~ For all that talk about platform-independence, note that this /*~ For all that talk about platform-independence, note that this
* field is endian-dependent! But let's face it, little-endian won. * field is endian-dependent! But let's face it, little-endian won.
* In related news, we don't support EBCDIC or middle-endian. */ * In related news, we don't support EBCDIC or middle-endian. */
@ -528,7 +535,8 @@ static struct io_plan *init_hsm(struct io_conn *conn,
struct client *c, struct client *c,
const u8 *msg_in) const u8 *msg_in)
{ {
struct pubkey node_id; struct node_id node_id;
struct pubkey key;
/* This must be lightningd. */ /* This must be lightningd. */
assert(is_lightningd(c)); assert(is_lightningd(c));
@ -544,7 +552,8 @@ static struct io_plan *init_hsm(struct io_conn *conn,
load_hsm(); load_hsm();
/*~ We tell lightning our node id and (public) bip32 seed. */ /*~ We tell lightning our node id and (public) bip32 seed. */
node_key(NULL, &node_id); node_key(NULL, &key);
node_id_from_pubkey(&node_id, &key);
/*~ Note: marshalling a bip32 tree only marshals the public side, /*~ Note: marshalling a bip32 tree only marshals the public side,
* not the secrets! So we're not actually handing them out here! * not the secrets! So we're not actually handing them out here!
@ -712,7 +721,7 @@ static struct io_plan *handle_get_channel_basepoints(struct io_conn *conn,
struct client *c, struct client *c,
const u8 *msg_in) const u8 *msg_in)
{ {
struct pubkey peer_id; struct node_id peer_id;
u64 dbid; u64 dbid;
struct secret seed; struct secret seed;
struct basepoints basepoints; struct basepoints basepoints;
@ -741,7 +750,8 @@ static struct io_plan *handle_sign_commitment_tx(struct io_conn *conn,
struct client *c, struct client *c,
const u8 *msg_in) const u8 *msg_in)
{ {
struct pubkey peer_id, remote_funding_pubkey, local_funding_pubkey; struct pubkey remote_funding_pubkey, local_funding_pubkey;
struct node_id peer_id;
u64 dbid; u64 dbid;
struct amount_sat funding; struct amount_sat funding;
struct secret channel_seed; struct secret channel_seed;
@ -1255,7 +1265,7 @@ static struct io_plan *pass_client_hsmfd(struct io_conn *conn,
{ {
int fds[2]; int fds[2];
u64 dbid, capabilities; u64 dbid, capabilities;
struct pubkey id; struct node_id id;
/* This must be lightningd itself. */ /* This must be lightningd itself. */
assert(is_lightningd(c)); assert(is_lightningd(c));

8
lightningd/channel.c

@ -110,7 +110,7 @@ void delete_channel(struct channel *channel)
} }
void get_channel_basepoints(struct lightningd *ld, void get_channel_basepoints(struct lightningd *ld,
const struct pubkey *peer_id, const struct node_id *peer_id,
const u64 dbid, const u64 dbid,
struct basepoints *local_basepoints, struct basepoints *local_basepoints,
struct pubkey *local_funding_pubkey) struct pubkey *local_funding_pubkey)
@ -197,7 +197,9 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
if (!log) { if (!log) {
/* FIXME: update log prefix when we get scid */ /* FIXME: update log prefix when we get scid */
/* FIXME: Use minimal unique pubkey prefix for logs! */ /* FIXME: Use minimal unique pubkey prefix for logs! */
const char *idname = type_to_string(peer, struct pubkey, &peer->id); const char *idname = type_to_string(peer,
struct node_id,
&peer->id);
channel->log = new_log(channel, channel->log = new_log(channel,
peer->log_book, "%s chan #%"PRIu64":", peer->log_book, "%s chan #%"PRIu64":",
idname, dbid); idname, dbid);
@ -286,7 +288,7 @@ struct channel *peer_normal_channel(struct peer *peer)
} }
struct channel *active_channel_by_id(struct lightningd *ld, struct channel *active_channel_by_id(struct lightningd *ld,
const struct pubkey *id, const struct node_id *id,
struct uncommitted_channel **uc) struct uncommitted_channel **uc)
{ {
struct peer *peer = peer_by_id(ld, id); struct peer *peer = peer_by_id(ld, id);

4
lightningd/channel.h

@ -189,7 +189,7 @@ struct channel *peer_normal_channel(struct peer *peer);
/* Get active channel for peer, optionally any uncommitted_channel. */ /* Get active channel for peer, optionally any uncommitted_channel. */
struct channel *active_channel_by_id(struct lightningd *ld, struct channel *active_channel_by_id(struct lightningd *ld,
const struct pubkey *id, const struct node_id *id,
struct uncommitted_channel **uc); struct uncommitted_channel **uc);
struct channel *channel_by_dbid(struct lightningd *ld, const u64 dbid); struct channel *channel_by_dbid(struct lightningd *ld, const u64 dbid);
@ -227,7 +227,7 @@ static inline bool channel_active(const struct channel *channel)
} }
void get_channel_basepoints(struct lightningd *ld, void get_channel_basepoints(struct lightningd *ld,
const struct pubkey *peer_id, const struct node_id *peer_id,
const u64 dbid, const u64 dbid,
struct basepoints *local_basepoints, struct basepoints *local_basepoints,
struct pubkey *local_funding_pubkey); struct pubkey *local_funding_pubkey);

24
lightningd/connect_control.c

@ -1,4 +1,3 @@
#include <bitcoin/pubkey.h>
#include <ccan/err/err.h> #include <ccan/err/err.h>
#include <ccan/fdpass/fdpass.h> #include <ccan/fdpass/fdpass.h>
#include <ccan/list/list.h> #include <ccan/list/list.h>
@ -8,6 +7,7 @@
#include <common/json_helpers.h> #include <common/json_helpers.h>
#include <common/jsonrpc_errors.h> #include <common/jsonrpc_errors.h>
#include <common/memleak.h> #include <common/memleak.h>
#include <common/node_id.h>
#include <common/param.h> #include <common/param.h>
#include <common/pseudorand.h> #include <common/pseudorand.h>
#include <common/timeout.h> #include <common/timeout.h>
@ -32,7 +32,7 @@
struct connect { struct connect {
struct list_node list; struct list_node list;
struct pubkey id; struct node_id id;
struct command *cmd; struct command *cmd;
}; };
@ -42,7 +42,7 @@ static void destroy_connect(struct connect *c)
} }
static struct connect *new_connect(struct lightningd *ld, static struct connect *new_connect(struct lightningd *ld,
const struct pubkey *id, const struct node_id *id,
struct command *cmd) struct command *cmd)
{ {
struct connect *c = tal(cmd, struct connect); struct connect *c = tal(cmd, struct connect);
@ -55,23 +55,23 @@ static struct connect *new_connect(struct lightningd *ld,
/* Finds first command which matches. */ /* Finds first command which matches. */
static struct connect *find_connect(struct lightningd *ld, static struct connect *find_connect(struct lightningd *ld,
const struct pubkey *id) const struct node_id *id)
{ {
struct connect *i; struct connect *i;
list_for_each(&ld->connects, i, list) { list_for_each(&ld->connects, i, list) {
if (pubkey_eq(&i->id, id)) if (node_id_eq(&i->id, id))
return i; return i;
} }
return NULL; return NULL;
} }
static struct command_result *connect_cmd_succeed(struct command *cmd, static struct command_result *connect_cmd_succeed(struct command *cmd,
const struct pubkey *id) const struct node_id *id)
{ {
struct json_stream *response = json_stream_success(cmd); struct json_stream *response = json_stream_success(cmd);
json_object_start(response, NULL); json_object_start(response, NULL);
json_add_pubkey(response, "id", id); json_add_node_id(response, "id", id);
json_object_end(response); json_object_end(response);
return command_success(cmd, response); return command_success(cmd, response);
} }
@ -83,7 +83,7 @@ static struct command_result *json_connect(struct command *cmd,
{ {
u32 *port; u32 *port;
jsmntok_t *idtok; jsmntok_t *idtok;
struct pubkey id; struct node_id id;
char *id_str; char *id_str;
char *atptr; char *atptr;
char *ataddr = NULL; char *ataddr = NULL;
@ -110,7 +110,7 @@ static struct command_result *json_connect(struct command *cmd,
idtok->end = idtok->start + atidx; idtok->end = idtok->start + atidx;
} }
if (!json_to_pubkey(buffer, idtok, &id)) { if (!json_to_node_id(buffer, idtok, &id)) {
return command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"id %.*s not valid", "id %.*s not valid",
json_tok_full_len(idtok), json_tok_full_len(idtok),
@ -231,7 +231,7 @@ void delay_then_reconnect(struct channel *channel, u32 seconds_delay,
static void connect_failed(struct lightningd *ld, const u8 *msg) static void connect_failed(struct lightningd *ld, const u8 *msg)
{ {
struct pubkey id; struct node_id id;
char *err; char *err;
struct connect *c; struct connect *c;
u32 seconds_to_delay; u32 seconds_to_delay;
@ -255,7 +255,7 @@ static void connect_failed(struct lightningd *ld, const u8 *msg)
delay_then_reconnect(channel, seconds_to_delay, addrhint); delay_then_reconnect(channel, seconds_to_delay, addrhint);
} }
void connect_succeeded(struct lightningd *ld, const struct pubkey *id) void connect_succeeded(struct lightningd *ld, const struct node_id *id)
{ {
struct connect *c; struct connect *c;
@ -268,7 +268,7 @@ void connect_succeeded(struct lightningd *ld, const struct pubkey *id)
static void peer_please_disconnect(struct lightningd *ld, const u8 *msg) static void peer_please_disconnect(struct lightningd *ld, const u8 *msg)
{ {
struct pubkey id; struct node_id id;
struct channel *c; struct channel *c;
struct uncommitted_channel *uc; struct uncommitted_channel *uc;

2
lightningd/connect_control.h

@ -12,7 +12,7 @@ void connectd_activate(struct lightningd *ld);
void delay_then_reconnect(struct channel *channel, u32 seconds_delay, void delay_then_reconnect(struct channel *channel, u32 seconds_delay,
const struct wireaddr_internal *addrhint TAKES); const struct wireaddr_internal *addrhint TAKES);
void connect_succeeded(struct lightningd *ld, const struct pubkey *id); void connect_succeeded(struct lightningd *ld, const struct node_id *id);
void gossip_connect_result(struct lightningd *ld, const u8 *msg); void gossip_connect_result(struct lightningd *ld, const u8 *msg);
#endif /* LIGHTNING_LIGHTNINGD_CONNECT_CONTROL_H */ #endif /* LIGHTNING_LIGHTNINGD_CONNECT_CONTROL_H */

55
lightningd/gossip_control.c

@ -185,24 +185,6 @@ void gossipd_notify_spend(struct lightningd *ld,
subd_send_msg(ld->gossip, msg); subd_send_msg(ld->gossip, msg);
} }
/* Gossipd shouldn't give us bad pubkeys, but don't abort if they do */
static void json_add_raw_pubkey(struct json_stream *response,
const char *fieldname,
const u8 raw_pubkey[sizeof(struct pubkey)])
{
secp256k1_pubkey pubkey;
u8 der[PUBKEY_CMPR_LEN];
size_t outlen = PUBKEY_CMPR_LEN;
memcpy(&pubkey, raw_pubkey, sizeof(pubkey));
if (!secp256k1_ec_pubkey_serialize(secp256k1_ctx, der, &outlen,
&pubkey,
SECP256K1_EC_COMPRESSED))
json_add_string(response, fieldname, "INVALID PUBKEY");
else
json_add_hex(response, fieldname, der, sizeof(der));
}
static void json_getnodes_reply(struct subd *gossip UNUSED, const u8 *reply, static void json_getnodes_reply(struct subd *gossip UNUSED, const u8 *reply,
const int *fds UNUSED, const int *fds UNUSED,
struct command *cmd) struct command *cmd)
@ -225,7 +207,7 @@ static void json_getnodes_reply(struct subd *gossip UNUSED, const u8 *reply,
struct json_escaped *esc; struct json_escaped *esc;
json_object_start(response, NULL); json_object_start(response, NULL);
json_add_raw_pubkey(response, "nodeid", nodes[i]->nodeid); json_add_node_id(response, "nodeid", &nodes[i]->nodeid);
if (nodes[i]->last_timestamp < 0) { if (nodes[i]->last_timestamp < 0) {
json_object_end(response); json_object_end(response);
continue; continue;
@ -262,10 +244,10 @@ static struct command_result *json_listnodes(struct command *cmd,
const jsmntok_t *params) const jsmntok_t *params)
{ {
u8 *req; u8 *req;
struct pubkey *id; struct node_id *id;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_opt("id", param_pubkey, &id), p_opt("id", param_node_id, &id),
NULL)) NULL))
return command_param_failed(); return command_param_failed();
@ -308,8 +290,8 @@ static struct command_result *json_getroute(struct command *cmd,
const jsmntok_t *params) const jsmntok_t *params)
{ {
struct lightningd *ld = cmd->ld; struct lightningd *ld = cmd->ld;
struct pubkey *destination; struct node_id *destination;
struct pubkey *source; struct node_id *source;
const jsmntok_t *excludetok; const jsmntok_t *excludetok;
struct amount_msat *msat; struct amount_msat *msat;
unsigned *cltv; unsigned *cltv;
@ -325,11 +307,11 @@ static struct command_result *json_getroute(struct command *cmd,
double *fuzz; double *fuzz;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", param_pubkey, &destination), p_req("id", param_node_id, &destination),
p_req("msatoshi", param_msat, &msat), p_req("msatoshi", param_msat, &msat),
p_req("riskfactor", param_double, &riskfactor), p_req("riskfactor", param_double, &riskfactor),
p_opt_def("cltv", param_number, &cltv, 9), p_opt_def("cltv", param_number, &cltv, 9),
p_opt_def("fromid", param_pubkey, &source, ld->id), p_opt_def("fromid", param_node_id, &source, ld->id),
p_opt_def("fuzzpercent", param_percent, &fuzz, 5.0), p_opt_def("fuzzpercent", param_percent, &fuzz, 5.0),
p_opt("exclude", param_array, &excludetok), p_opt("exclude", param_array, &excludetok),
p_opt_def("maxhops", param_number, &max_hops, p_opt_def("maxhops", param_number, &max_hops,
@ -404,9 +386,10 @@ static void json_listchannels_reply(struct subd *gossip UNUSED, const u8 *reply,
json_array_start(response, "channels"); json_array_start(response, "channels");
for (i = 0; i < tal_count(entries); i++) { for (i = 0; i < tal_count(entries); i++) {
json_object_start(response, NULL); json_object_start(response, NULL);
json_add_raw_pubkey(response, "source", entries[i].source); json_add_node_id(response, "source",
json_add_raw_pubkey(response, "destination", &entries[i].source);
entries[i].destination); json_add_node_id(response, "destination",
&entries[i].destination);
json_add_string(response, "short_channel_id", json_add_string(response, "short_channel_id",
type_to_string(reply, struct short_channel_id, type_to_string(reply, struct short_channel_id,
&entries[i].short_channel_id)); &entries[i].short_channel_id));
@ -442,11 +425,11 @@ static struct command_result *json_listchannels(struct command *cmd,
{ {
u8 *req; u8 *req;
struct short_channel_id *id; struct short_channel_id *id;
struct pubkey *source; struct node_id *source;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_opt("short_channel_id", param_short_channel_id, &id), p_opt("short_channel_id", param_short_channel_id, &id),
p_opt("source", param_pubkey, &source), p_opt("source", param_node_id, &source),
NULL)) NULL))
return command_param_failed(); return command_param_failed();
@ -500,12 +483,12 @@ static struct command_result *json_dev_query_scids(struct command *cmd,
u8 *msg; u8 *msg;
const jsmntok_t *scidstok; const jsmntok_t *scidstok;
const jsmntok_t *t; const jsmntok_t *t;
struct pubkey *id; struct node_id *id;
struct short_channel_id *scids; struct short_channel_id *scids;
size_t i; size_t i;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", param_pubkey, &id), p_req("id", param_node_id, &id),
p_req("scids", param_array, &scidstok), p_req("scids", param_array, &scidstok),
NULL)) NULL))
return command_param_failed(); return command_param_failed();
@ -542,11 +525,11 @@ json_dev_send_timestamp_filter(struct command *cmd,
const jsmntok_t *params) const jsmntok_t *params)
{ {
u8 *msg; u8 *msg;
struct pubkey *id; struct node_id *id;
u32 *first, *range; u32 *first, *range;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", param_pubkey, &id), p_req("id", param_node_id, &id),
p_req("first", param_number, &first), p_req("first", param_number, &first),
p_req("range", param_number, &range), p_req("range", param_number, &range),
NULL)) NULL))
@ -612,11 +595,11 @@ static struct command_result *json_dev_query_channel_range(struct command *cmd,
const jsmntok_t *params) const jsmntok_t *params)
{ {
u8 *msg; u8 *msg;
struct pubkey *id; struct node_id *id;
u32 *first, *num; u32 *first, *num;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", param_pubkey, &id), p_req("id", param_node_id, &id),
p_req("first", param_number, &first), p_req("first", param_number, &first),
p_req("num", param_number, &num), p_req("num", param_number, &num),
NULL)) NULL))

20
lightningd/gossip_msg.c

@ -12,7 +12,7 @@ struct gossip_getnodes_entry *fromwire_gossip_getnodes_entry(const tal_t *ctx,
u16 flen; u16 flen;
entry = tal(ctx, struct gossip_getnodes_entry); entry = tal(ctx, struct gossip_getnodes_entry);
fromwire(pptr, max, entry->nodeid, sizeof(entry->nodeid)); fromwire_node_id(pptr, max, &entry->nodeid);
entry->last_timestamp = fromwire_u64(pptr, max); entry->last_timestamp = fromwire_u64(pptr, max);
if (entry->last_timestamp < 0) { if (entry->last_timestamp < 0) {
@ -43,7 +43,7 @@ struct gossip_getnodes_entry *fromwire_gossip_getnodes_entry(const tal_t *ctx,
void towire_gossip_getnodes_entry(u8 **pptr, void towire_gossip_getnodes_entry(u8 **pptr,
const struct gossip_getnodes_entry *entry) const struct gossip_getnodes_entry *entry)
{ {
towire(pptr, entry->nodeid, sizeof(entry->nodeid)); towire_node_id(pptr, &entry->nodeid);
towire_u64(pptr, entry->last_timestamp); towire_u64(pptr, entry->last_timestamp);
if (entry->last_timestamp < 0) if (entry->last_timestamp < 0)
@ -62,7 +62,7 @@ void towire_gossip_getnodes_entry(u8 **pptr,
void fromwire_route_hop(const u8 **pptr, size_t *max, struct route_hop *entry) void fromwire_route_hop(const u8 **pptr, size_t *max, struct route_hop *entry)
{ {
fromwire_pubkey(pptr, max, &entry->nodeid); fromwire_node_id(pptr, max, &entry->nodeid);
fromwire_short_channel_id(pptr, max, &entry->channel_id); fromwire_short_channel_id(pptr, max, &entry->channel_id);
entry->direction = fromwire_u8(pptr, max); entry->direction = fromwire_u8(pptr, max);
entry->amount = fromwire_amount_msat(pptr, max); entry->amount = fromwire_amount_msat(pptr, max);
@ -71,7 +71,7 @@ void fromwire_route_hop(const u8 **pptr, size_t *max, struct route_hop *entry)
void towire_route_hop(u8 **pptr, const struct route_hop *entry) void towire_route_hop(u8 **pptr, const struct route_hop *entry)
{ {
towire_pubkey(pptr, &entry->nodeid); towire_node_id(pptr, &entry->nodeid);
towire_short_channel_id(pptr, &entry->channel_id); towire_short_channel_id(pptr, &entry->channel_id);
towire_u8(pptr, entry->direction); towire_u8(pptr, entry->direction);
towire_amount_msat(pptr, entry->amount); towire_amount_msat(pptr, entry->amount);
@ -80,7 +80,7 @@ void towire_route_hop(u8 **pptr, const struct route_hop *entry)
void fromwire_route_info(const u8 **pptr, size_t *max, struct route_info *entry) void fromwire_route_info(const u8 **pptr, size_t *max, struct route_info *entry)
{ {
fromwire_pubkey(pptr, max, &entry->pubkey); fromwire_node_id(pptr, max, &entry->pubkey);
fromwire_short_channel_id(pptr, max, &entry->short_channel_id); fromwire_short_channel_id(pptr, max, &entry->short_channel_id);
entry->fee_base_msat = fromwire_u32(pptr, max); entry->fee_base_msat = fromwire_u32(pptr, max);
entry->fee_proportional_millionths = fromwire_u32(pptr, max); entry->fee_proportional_millionths = fromwire_u32(pptr, max);
@ -89,7 +89,7 @@ void fromwire_route_info(const u8 **pptr, size_t *max, struct route_info *entry)
void towire_route_info(u8 **pptr, const struct route_info *entry) void towire_route_info(u8 **pptr, const struct route_info *entry)
{ {
towire_pubkey(pptr, &entry->pubkey); towire_node_id(pptr, &entry->pubkey);
towire_short_channel_id(pptr, &entry->short_channel_id); towire_short_channel_id(pptr, &entry->short_channel_id);
towire_u32(pptr, entry->fee_base_msat); towire_u32(pptr, entry->fee_base_msat);
towire_u32(pptr, entry->fee_proportional_millionths); towire_u32(pptr, entry->fee_proportional_millionths);
@ -100,8 +100,8 @@ void fromwire_gossip_getchannels_entry(const u8 **pptr, size_t *max,
struct gossip_getchannels_entry *entry) struct gossip_getchannels_entry *entry)
{ {
fromwire_short_channel_id(pptr, max, &entry->short_channel_id); fromwire_short_channel_id(pptr, max, &entry->short_channel_id);
fromwire(pptr, max, entry->source, sizeof(entry->source)); fromwire_node_id(pptr, max, &entry->source);
fromwire(pptr, max, entry->destination, sizeof(entry->destination)); fromwire_node_id(pptr, max, &entry->destination);
entry->sat = fromwire_amount_sat(pptr, max); entry->sat = fromwire_amount_sat(pptr, max);
entry->message_flags = fromwire_u8(pptr, max); entry->message_flags = fromwire_u8(pptr, max);
entry->channel_flags = fromwire_u8(pptr, max); entry->channel_flags = fromwire_u8(pptr, max);
@ -117,8 +117,8 @@ void towire_gossip_getchannels_entry(u8 **pptr,
const struct gossip_getchannels_entry *entry) const struct gossip_getchannels_entry *entry)
{ {
towire_short_channel_id(pptr, &entry->short_channel_id); towire_short_channel_id(pptr, &entry->short_channel_id);
towire(pptr, entry->source, sizeof(entry->source)); towire_node_id(pptr, &entry->source);
towire(pptr, entry->destination, sizeof(entry->destination)); towire_node_id(pptr, &entry->destination);
towire_amount_sat(pptr, entry->sat); towire_amount_sat(pptr, entry->sat);
towire_u8(pptr, entry->message_flags); towire_u8(pptr, entry->message_flags);
towire_u8(pptr, entry->channel_flags); towire_u8(pptr, entry->channel_flags);

6
lightningd/gossip_msg.h

@ -12,8 +12,7 @@ struct peer_features {
}; };
struct gossip_getnodes_entry { struct gossip_getnodes_entry {
/* This is raw to optimize marshaling: be careful! */ struct node_id nodeid;
u8 nodeid[sizeof(struct pubkey)];
s64 last_timestamp; /* -1 means never: following fields ignored */ s64 last_timestamp; /* -1 means never: following fields ignored */
u8 *globalfeatures; u8 *globalfeatures;
struct wireaddr *addresses; struct wireaddr *addresses;
@ -22,8 +21,7 @@ struct gossip_getnodes_entry {
}; };
struct gossip_getchannels_entry { struct gossip_getchannels_entry {
/* These are raw to optimize marshaling: be careful! */ struct node_id source, destination;
u8 source[sizeof(struct pubkey)], destination[sizeof(struct pubkey)];
struct amount_sat sat; struct amount_sat sat;
struct short_channel_id short_channel_id; struct short_channel_id short_channel_id;
u8 message_flags; u8 message_flags;

8
lightningd/hsm_control.c

@ -21,7 +21,7 @@
#include <wire/wire_sync.h> #include <wire/wire_sync.h>
static int hsm_get_fd(struct lightningd *ld, static int hsm_get_fd(struct lightningd *ld,
const struct pubkey *id, const struct node_id *id,
u64 dbid, u64 dbid,
int capabilities) int capabilities)
{ {
@ -43,7 +43,7 @@ static int hsm_get_fd(struct lightningd *ld,
} }
int hsm_get_client_fd(struct lightningd *ld, int hsm_get_client_fd(struct lightningd *ld,
const struct pubkey *id, const struct node_id *id,
u64 dbid, u64 dbid,
int capabilities) int capabilities)
{ {
@ -61,7 +61,7 @@ static unsigned int hsm_msg(struct subd *hsmd,
const u8 *msg, const int *fds UNUSED) const u8 *msg, const int *fds UNUSED)
{ {
/* We only expect one thing from the HSM that's not a STATUS message */ /* We only expect one thing from the HSM that's not a STATUS message */
struct pubkey client_id; struct node_id client_id;
u8 *bad_msg; u8 *bad_msg;
char *desc; char *desc;
@ -71,7 +71,7 @@ static unsigned int hsm_msg(struct subd *hsmd,
/* This should, of course, never happen. */ /* This should, of course, never happen. */
log_broken(hsmd->log, "client %s %s (request %s)", log_broken(hsmd->log, "client %s %s (request %s)",
type_to_string(tmpctx, struct pubkey, &client_id), type_to_string(tmpctx, struct node_id, &client_id),
desc, tal_hex(tmpctx, bad_msg)); desc, tal_hex(tmpctx, bad_msg));
return 0; return 0;
} }

4
lightningd/hsm_control.h

@ -7,11 +7,11 @@
#include <stdbool.h> #include <stdbool.h>
struct lightningd; struct lightningd;
struct pubkey; struct node_id;
/* Ask HSM for a new fd for a subdaemon to use. */ /* Ask HSM for a new fd for a subdaemon to use. */
int hsm_get_client_fd(struct lightningd *ld, int hsm_get_client_fd(struct lightningd *ld,
const struct pubkey *id, const struct node_id *id,
u64 dbid, u64 dbid,
int capabilities); int capabilities);

8
lightningd/invoice.c

@ -334,7 +334,7 @@ static struct route_info *unpack_route(const tal_t *ctx,
"fee_proportional_millionths"); "fee_proportional_millionths");
cltv = json_get_member(buffer, t, "cltv_expiry_delta"); cltv = json_get_member(buffer, t, "cltv_expiry_delta");
if (!json_to_pubkey(buffer, pubkey, &r->pubkey) if (!json_to_node_id(buffer, pubkey, &r->pubkey)
|| !json_to_short_channel_id(buffer, scid, || !json_to_short_channel_id(buffer, scid,
&r->short_channel_id, &r->short_channel_id,
deprecated_apis) deprecated_apis)
@ -811,7 +811,7 @@ static struct command_result *json_decodepay(struct command *cmd,
json_add_string(response, "currency", b11->chain->bip173_name); json_add_string(response, "currency", b11->chain->bip173_name);
json_add_u64(response, "created_at", b11->timestamp); json_add_u64(response, "created_at", b11->timestamp);
json_add_u64(response, "expiry", b11->expiry); json_add_u64(response, "expiry", b11->expiry);
json_add_pubkey(response, "payee", &b11->receiver_id); json_add_node_id(response, "payee", &b11->receiver_id);
if (b11->msat) if (b11->msat)
json_add_amount_msat(response, *b11->msat, json_add_amount_msat(response, *b11->msat,
"msatoshi", "amount_msat"); "msatoshi", "amount_msat");
@ -841,8 +841,8 @@ static struct command_result *json_decodepay(struct command *cmd,
json_array_start(response, NULL); json_array_start(response, NULL);
for (n = 0; n < tal_count(b11->routes[i]); n++) { for (n = 0; n < tal_count(b11->routes[i]); n++) {
json_object_start(response, NULL); json_object_start(response, NULL);
json_add_pubkey(response, "pubkey", json_add_node_id(response, "pubkey",
&b11->routes[i][n].pubkey); &b11->routes[i][n].pubkey);
json_add_short_channel_id(response, json_add_short_channel_id(response,
"short_channel_id", "short_channel_id",
&b11->routes[i][n] &b11->routes[i][n]

2
lightningd/json.c

@ -29,7 +29,7 @@ json_add_route_hop(struct json_stream *r, char const *n,
{ {
/* Imitate what getroute/sendpay use */ /* Imitate what getroute/sendpay use */
json_object_start(r, n); json_object_start(r, n);
json_add_pubkey(r, "id", &h->nodeid); json_add_node_id(r, "id", &h->nodeid);
json_add_short_channel_id(r, "channel", json_add_short_channel_id(r, "channel",
&h->channel_id); &h->channel_id);
json_add_num(r, "direction", h->direction); json_add_num(r, "direction", h->direction);

2
lightningd/lightningd.c

@ -803,7 +803,7 @@ int main(int argc, char *argv[])
* so it can use tal_bytelen() to get the length. */ * so it can use tal_bytelen() to get the length. */
log_info(ld->log, "--------------------------------------------------"); log_info(ld->log, "--------------------------------------------------");
log_info(ld->log, "Server started with public key %s, alias %s (color #%s) and lightningd %s", log_info(ld->log, "Server started with public key %s, alias %s (color #%s) and lightningd %s",
type_to_string(tmpctx, struct pubkey, &ld->id), type_to_string(tmpctx, struct node_id, &ld->id),
json_escape(tmpctx, (const char *)ld->alias)->s, json_escape(tmpctx, (const char *)ld->alias)->s,
tal_hex(tmpctx, ld->rgb), version()); tal_hex(tmpctx, ld->rgb), version());

2
lightningd/lightningd.h

@ -105,7 +105,7 @@ struct lightningd {
const char *logfile; const char *logfile;
/* This is us. */ /* This is us. */
struct pubkey id; struct node_id id;
/* My name is... my favorite color is... */ /* My name is... my favorite color is... */
u8 *alias; /* At least 32 bytes (zero-filled) */ u8 *alias; /* At least 32 bytes (zero-filled) */

8
lightningd/notification.c

@ -14,22 +14,22 @@ bool notifications_have_topic(const char *topic)
return false; return false;
} }
void notify_connect(struct lightningd *ld, struct pubkey *nodeid, void notify_connect(struct lightningd *ld, struct node_id *nodeid,
struct wireaddr_internal *addr) struct wireaddr_internal *addr)
{ {
struct jsonrpc_notification *n = struct jsonrpc_notification *n =
jsonrpc_notification_start(NULL, notification_topics[0]); jsonrpc_notification_start(NULL, notification_topics[0]);
json_add_pubkey(n->stream, "id", nodeid); json_add_node_id(n->stream, "id", nodeid);
json_add_address_internal(n->stream, "address", addr); json_add_address_internal(n->stream, "address", addr);
jsonrpc_notification_end(n); jsonrpc_notification_end(n);
plugins_notify(ld->plugins, take(n)); plugins_notify(ld->plugins, take(n));
} }
void notify_disconnect(struct lightningd *ld, struct pubkey *nodeid) void notify_disconnect(struct lightningd *ld, struct node_id *nodeid)
{ {
struct jsonrpc_notification *n = struct jsonrpc_notification *n =
jsonrpc_notification_start(NULL, notification_topics[1]); jsonrpc_notification_start(NULL, notification_topics[1]);
json_add_pubkey(n->stream, "id", nodeid); json_add_node_id(n->stream, "id", nodeid);
jsonrpc_notification_end(n); jsonrpc_notification_end(n);
plugins_notify(ld->plugins, take(n)); plugins_notify(ld->plugins, take(n));
} }

4
lightningd/notification.h

@ -7,8 +7,8 @@
bool notifications_have_topic(const char *topic); bool notifications_have_topic(const char *topic);
void notify_connect(struct lightningd *ld, struct pubkey *nodeid, void notify_connect(struct lightningd *ld, struct node_id *nodeid,
struct wireaddr_internal *addr); struct wireaddr_internal *addr);
void notify_disconnect(struct lightningd *ld, struct pubkey *nodeid); void notify_disconnect(struct lightningd *ld, struct node_id *nodeid);
#endif /* LIGHTNING_LIGHTNINGD_NOTIFICATION_H */ #endif /* LIGHTNING_LIGHTNINGD_NOTIFICATION_H */

8
lightningd/opening_control.c

@ -638,7 +638,7 @@ new_uncommitted_channel(struct peer *peer)
uc->transient_billboard = NULL; uc->transient_billboard = NULL;
uc->dbid = wallet_get_channel_dbid(ld->wallet); uc->dbid = wallet_get_channel_dbid(ld->wallet);
idname = type_to_string(uc, struct pubkey, &uc->peer->id); idname = type_to_string(uc, struct node_id, &uc->peer->id);
uc->log = new_log(uc, uc->peer->log_book, "%s chan #%"PRIu64":", uc->log = new_log(uc, uc->peer->log_book, "%s chan #%"PRIu64":",
idname, uc->dbid); idname, uc->dbid);
tal_free(idname); tal_free(idname);
@ -833,7 +833,7 @@ static struct command_result *json_fund_channel(struct command *cmd,
{ {
struct command_result *res; struct command_result *res;
struct funding_channel * fc = tal(cmd, struct funding_channel); struct funding_channel * fc = tal(cmd, struct funding_channel);
struct pubkey *id; struct node_id *id;
struct peer *peer; struct peer *peer;
struct channel *channel; struct channel *channel;
u32 *feerate_per_kw, *minconf, maxheight; u32 *feerate_per_kw, *minconf, maxheight;
@ -847,7 +847,7 @@ static struct command_result *json_fund_channel(struct command *cmd,
fc->uc = NULL; fc->uc = NULL;
wtx_init(cmd, &fc->wtx, max_funding_satoshi); wtx_init(cmd, &fc->wtx, max_funding_satoshi);
if (!param(fc->cmd, buffer, params, if (!param(fc->cmd, buffer, params,
p_req("id", param_pubkey, &id), p_req("id", param_node_id, &id),
p_req("satoshi", param_wtx, &fc->wtx), p_req("satoshi", param_wtx, &fc->wtx),
p_opt("feerate", param_feerate, &feerate_per_kw), p_opt("feerate", param_feerate, &feerate_per_kw),
p_opt_def("announce", param_bool, &announce_channel, true), p_opt_def("announce", param_bool, &announce_channel, true),
@ -894,7 +894,7 @@ static struct command_result *json_fund_channel(struct command *cmd,
if (!*announce_channel) { if (!*announce_channel) {
fc->channel_flags &= ~CHANNEL_FLAGS_ANNOUNCE_CHANNEL; fc->channel_flags &= ~CHANNEL_FLAGS_ANNOUNCE_CHANNEL;
log_info(peer->ld->log, "Will open private channel with node %s", log_info(peer->ld->log, "Will open private channel with node %s",
type_to_string(fc, struct pubkey, id)); type_to_string(fc, struct node_id, id));
} }
maxheight = minconf_to_maxheight(*minconf, cmd->ld); maxheight = minconf_to_maxheight(*minconf, cmd->ld);

9
lightningd/options.c

@ -845,19 +845,16 @@ static const char *codename_noun[]
void setup_color_and_alias(struct lightningd *ld) void setup_color_and_alias(struct lightningd *ld)
{ {
u8 der[PUBKEY_CMPR_LEN];
pubkey_to_der(der, &ld->id);
if (!ld->rgb) if (!ld->rgb)
/* You can't get much red by default */ /* You can't get much red by default */
ld->rgb = tal_dup_arr(ld, u8, der, 3, 0); ld->rgb = tal_dup_arr(ld, u8, ld->id.k, 3, 0);
if (!ld->alias) { if (!ld->alias) {
u64 adjective, noun; u64 adjective, noun;
char *name; char *name;
memcpy(&adjective, der+3, sizeof(adjective)); memcpy(&adjective, ld->id.k+3, sizeof(adjective));
memcpy(&noun, der+3+sizeof(adjective), sizeof(noun)); memcpy(&noun, ld->id.k+3+sizeof(adjective), sizeof(noun));
noun %= ARRAY_SIZE(codename_noun); noun %= ARRAY_SIZE(codename_noun);
adjective %= ARRAY_SIZE(codename_adjective); adjective %= ARRAY_SIZE(codename_adjective);

63
lightningd/pay.c

@ -22,7 +22,7 @@
struct routing_failure { struct routing_failure {
unsigned int erring_index; unsigned int erring_index;
enum onion_type failcode; enum onion_type failcode;
struct pubkey erring_node; struct node_id erring_node;
struct short_channel_id erring_channel; struct short_channel_id erring_channel;
int channel_dir; int channel_dir;
}; };
@ -77,7 +77,7 @@ json_add_payment_fields(struct json_stream *response,
{ {
json_add_u64(response, "id", t->id); json_add_u64(response, "id", t->id);
json_add_hex(response, "payment_hash", &t->payment_hash, sizeof(t->payment_hash)); json_add_hex(response, "payment_hash", &t->payment_hash, sizeof(t->payment_hash));
json_add_pubkey(response, "destination", &t->destination); json_add_node_id(response, "destination", &t->destination);
json_add_amount_msat(response, t->msatoshi, json_add_amount_msat(response, t->msatoshi,
"msatoshi", "amount_msat"); "msatoshi", "amount_msat");
json_add_amount_msat(response, t->msatoshi_sent, json_add_amount_msat(response, t->msatoshi_sent,
@ -126,7 +126,7 @@ static void
json_add_routefail_info(struct json_stream *js, json_add_routefail_info(struct json_stream *js,
unsigned int erring_index, unsigned int erring_index,
enum onion_type failcode, enum onion_type failcode,
const struct pubkey *erring_node, const struct node_id *erring_node,
const struct short_channel_id *erring_channel, const struct short_channel_id *erring_channel,
int channel_dir) int channel_dir)
{ {
@ -138,7 +138,7 @@ json_add_routefail_info(struct json_stream *js,
/* FIXME: Better way to detect this? */ /* FIXME: Better way to detect this? */
if (!strstarts(failcodename, "INVALID ")) if (!strstarts(failcodename, "INVALID "))
json_add_string(js, "failcodename", failcodename); json_add_string(js, "failcodename", failcodename);
json_add_pubkey(js, "erring_node", erring_node); json_add_node_id(js, "erring_node", erring_node);
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); json_add_num(js, "erring_direction", channel_dir);
json_object_end(js); json_object_end(js);
@ -248,7 +248,7 @@ immediate_routing_failure(const tal_t *ctx,
const struct lightningd *ld, const struct lightningd *ld,
enum onion_type failcode, enum onion_type failcode,
const struct short_channel_id *channel0, const struct short_channel_id *channel0,
const struct pubkey *dstid) const struct node_id *dstid)
{ {
struct routing_failure *routing_failure; struct routing_failure *routing_failure;
@ -259,7 +259,7 @@ immediate_routing_failure(const tal_t *ctx,
routing_failure->failcode = failcode; routing_failure->failcode = failcode;
routing_failure->erring_node = ld->id; routing_failure->erring_node = ld->id;
routing_failure->erring_channel = *channel0; routing_failure->erring_channel = *channel0;
routing_failure->channel_dir = pubkey_idx(&ld->id, dstid); routing_failure->channel_dir = node_id_idx(&ld->id, dstid);
return routing_failure; return routing_failure;
} }
@ -281,8 +281,8 @@ local_routing_failure(const tal_t *ctx,
routing_failure->failcode = hout->failcode; routing_failure->failcode = hout->failcode;
routing_failure->erring_node = ld->id; routing_failure->erring_node = ld->id;
routing_failure->erring_channel = payment->route_channels[0]; routing_failure->erring_channel = payment->route_channels[0];
routing_failure->channel_dir = pubkey_idx(&ld->id, routing_failure->channel_dir = node_id_idx(&ld->id,
&payment->route_nodes[0]); &payment->route_nodes[0]);
log_debug(hout->key.channel->log, "local_routing_failure: %u (%s)", log_debug(hout->key.channel->log, "local_routing_failure: %u (%s)",
hout->failcode, onion_type_name(hout->failcode)); hout->failcode, onion_type_name(hout->failcode));
@ -300,8 +300,8 @@ remote_routing_failure(const tal_t *ctx,
{ {
enum onion_type failcode = fromwire_peektype(failure->msg); enum onion_type failcode = fromwire_peektype(failure->msg);
struct routing_failure *routing_failure; struct routing_failure *routing_failure;
const struct pubkey *route_nodes; const struct node_id *route_nodes;
const struct pubkey *erring_node; const struct node_id *erring_node;
const struct short_channel_id *route_channels; const struct short_channel_id *route_channels;
const struct short_channel_id *erring_channel; const struct short_channel_id *erring_channel;
int origin_index; int origin_index;
@ -320,11 +320,11 @@ remote_routing_failure(const tal_t *ctx,
erring_channel = &route_channels[origin_index]; erring_channel = &route_channels[origin_index];
/* Single hop? */ /* Single hop? */
if (origin_index == 0) if (origin_index == 0)
dir = pubkey_idx(&ld->id, dir = node_id_idx(&ld->id,
&route_nodes[origin_index]); &route_nodes[origin_index]);
else else
dir = pubkey_idx(&route_nodes[origin_index - 1], dir = node_id_idx(&route_nodes[origin_index - 1],
&route_nodes[origin_index]); &route_nodes[origin_index]);
/* BOLT #4: /* BOLT #4:
* *
@ -346,8 +346,8 @@ remote_routing_failure(const tal_t *ctx,
/* Report the *next* channel as failing. */ /* Report the *next* channel as failing. */
erring_channel = &route_channels[origin_index + 1]; erring_channel = &route_channels[origin_index + 1];
dir = pubkey_idx(&route_nodes[origin_index], dir = node_id_idx(&route_nodes[origin_index],
&route_nodes[origin_index+1]); &route_nodes[origin_index+1]);
/* If the error is a BADONION, then it's on behalf of the /* If the error is a BADONION, then it's on behalf of the
* following node. */ * following node. */
@ -511,7 +511,7 @@ static struct command_result *wait_payment(struct lightningd *ld,
bool faildestperm; bool faildestperm;
int failindex; int failindex;
enum onion_type failcode; enum onion_type failcode;
struct pubkey *failnode; struct node_id *failnode;
struct short_channel_id *failchannel; struct short_channel_id *failchannel;
u8 *failupdate; u8 *failupdate;
char *faildetail; char *faildetail;
@ -596,7 +596,8 @@ send_payment(struct lightningd *ld,
enum onion_type failcode; enum onion_type failcode;
size_t i, n_hops = tal_count(route); size_t i, n_hops = tal_count(route);
struct hop_data *hop_data = tal_arr(tmpctx, struct hop_data, n_hops); struct hop_data *hop_data = tal_arr(tmpctx, struct hop_data, n_hops);
struct pubkey *ids = tal_arr(tmpctx, struct pubkey, n_hops); struct pubkey *path = tal_arr(tmpctx, struct pubkey, n_hops);
struct node_id *ids = tal_arr(tmpctx, struct node_id, n_hops);
struct wallet_payment *payment = NULL; struct wallet_payment *payment = NULL;
struct htlc_out *hout; struct htlc_out *hout;
struct short_channel_id *channels; struct short_channel_id *channels;
@ -606,9 +607,19 @@ send_payment(struct lightningd *ld,
/* Expiry for HTLCs is absolute. And add one to give some margin. */ /* Expiry for HTLCs is absolute. And add one to give some margin. */
base_expiry = get_block_height(ld->topology) + 1; base_expiry = get_block_height(ld->topology) + 1;
/* Extract IDs for each hop: create_onionpacket wants array. */ /* Extract IDs for each hop: create_onionpacket wants array of *keys*,
for (i = 0; i < n_hops; i++) * and wallet wants continuous array of node_ids */
for (i = 0; i < n_hops; i++) {
ids[i] = route[i].nodeid; ids[i] = route[i].nodeid;
/* JSON parsing checked these were valid, so Shouldn't Happen */
if (!pubkey_from_node_id(&path[i], &ids[i])) {
return command_fail(cmd, PAY_RHASH_ALREADY_USED,
"Invalid nodeid %s",
type_to_string(tmpctx,
struct node_id,
&ids[i]));
}
}
/* Copy hop_data[n] from route[n+1] (ie. where it goes next) */ /* Copy hop_data[n] from route[n+1] (ie. where it goes next) */
for (i = 0; i < n_hops - 1; i++) { for (i = 0; i < n_hops - 1; i++) {
@ -645,11 +656,11 @@ send_payment(struct lightningd *ld,
struct amount_msat, struct amount_msat,
&payment->msatoshi)); &payment->msatoshi));
} }
if (!pubkey_eq(&payment->destination, &ids[n_hops-1])) { if (!node_id_eq(&payment->destination, &ids[n_hops-1])) {
return command_fail(cmd, PAY_RHASH_ALREADY_USED, return command_fail(cmd, PAY_RHASH_ALREADY_USED,
"Already succeeded to %s", "Already succeeded to %s",
type_to_string(tmpctx, type_to_string(tmpctx,
struct pubkey, struct node_id,
&payment->destination)); &payment->destination));
} }
return sendpay_success(cmd, payment); return sendpay_success(cmd, payment);
@ -666,14 +677,14 @@ send_payment(struct lightningd *ld,
json_add_routefail_info(data, 0, WIRE_UNKNOWN_NEXT_PEER, json_add_routefail_info(data, 0, WIRE_UNKNOWN_NEXT_PEER,
&ld->id, &route[0].channel_id, &ld->id, &route[0].channel_id,
pubkey_idx(&ld->id, &route[0].nodeid)); node_id_idx(&ld->id, &route[0].nodeid));
return command_failed(cmd, data); return command_failed(cmd, data);
} }
randombytes_buf(&sessionkey, sizeof(sessionkey)); randombytes_buf(&sessionkey, sizeof(sessionkey));
/* Onion will carry us from first peer onwards. */ /* Onion will carry us from first peer onwards. */
packet = create_onionpacket(tmpctx, ids, hop_data, sessionkey, rhash->u.u8, packet = create_onionpacket(tmpctx, path, hop_data, sessionkey, rhash->u.u8,
sizeof(struct sha256), &path_secrets); sizeof(struct sha256), &path_secrets);
onion = serialize_onionpacket(tmpctx, packet); onion = serialize_onionpacket(tmpctx, packet);
@ -799,7 +810,7 @@ static struct command_result *json_sendpay(struct command *cmd,
route = tal_arr(cmd, struct route_hop, routetok->size); route = tal_arr(cmd, struct route_hop, routetok->size);
json_for_each_arr(i, t, routetok) { json_for_each_arr(i, t, routetok) {
struct amount_msat *msat, *amount_msat; struct amount_msat *msat, *amount_msat;
struct pubkey *id; struct node_id *id;
struct short_channel_id *channel; struct short_channel_id *channel;
unsigned *delay, *direction; unsigned *delay, *direction;
@ -808,7 +819,7 @@ static struct command_result *json_sendpay(struct command *cmd,
p_opt("msatoshi", param_msat, &msat), p_opt("msatoshi", param_msat, &msat),
p_opt("amount_msat", param_msat, &amount_msat), p_opt("amount_msat", param_msat, &amount_msat),
/* These three actually required */ /* These three actually required */
p_opt("id", param_pubkey, &id), p_opt("id", param_node_id, &id),
p_opt("delay", param_number, &delay), p_opt("delay", param_number, &delay),
p_opt("channel", param_short_channel_id, &channel), p_opt("channel", param_short_channel_id, &channel),
p_opt("direction", param_number, &direction), p_opt("direction", param_number, &direction),

64
lightningd/peer_control.c

@ -98,7 +98,7 @@ static void peer_update_features(struct peer *peer,
} }
struct peer *new_peer(struct lightningd *ld, u64 dbid, struct peer *new_peer(struct lightningd *ld, u64 dbid,
const struct pubkey *id, const struct node_id *id,
const struct wireaddr_internal *addr) const struct wireaddr_internal *addr)
{ {
/* We are owned by our channels, and freed manually by destroy_channel */ /* We are owned by our channels, and freed manually by destroy_channel */
@ -111,7 +111,7 @@ struct peer *new_peer(struct lightningd *ld, u64 dbid,
peer->addr = *addr; peer->addr = *addr;
peer->globalfeatures = peer->localfeatures = NULL; peer->globalfeatures = peer->localfeatures = NULL;
list_head_init(&peer->channels); list_head_init(&peer->channels);
peer->direction = get_channel_direction(&peer->ld->id, &peer->id); peer->direction = node_id_idx(&peer->ld->id, &peer->id);
#if DEVELOPER #if DEVELOPER
peer->ignore_htlcs = false; peer->ignore_htlcs = false;
@ -162,12 +162,12 @@ struct peer *find_peer_by_dbid(struct lightningd *ld, u64 dbid)
return NULL; return NULL;
} }
struct peer *peer_by_id(struct lightningd *ld, const struct pubkey *id) struct peer *peer_by_id(struct lightningd *ld, const struct node_id *id)
{ {
struct peer *p; struct peer *p;
list_for_each(&ld->peers, p, list) list_for_each(&ld->peers, p, list)
if (pubkey_eq(&p->id, id)) if (node_id_eq(&p->id, id))
return p; return p;
return NULL; return NULL;
} }
@ -176,9 +176,9 @@ struct peer *peer_from_json(struct lightningd *ld,
const char *buffer, const char *buffer,
const jsmntok_t *peeridtok) const jsmntok_t *peeridtok)
{ {
struct pubkey peerid; struct node_id peerid;
if (!json_to_pubkey(buffer, peeridtok, &peerid)) if (!json_to_node_id(buffer, peeridtok, &peerid))
return NULL; return NULL;
return peer_by_id(ld, &peerid); return peer_by_id(ld, &peerid);
@ -526,7 +526,7 @@ static void json_add_channel(struct lightningd *ld,
json_add_short_channel_id(response, "short_channel_id", json_add_short_channel_id(response, "short_channel_id",
channel->scid); channel->scid);
json_add_num(response, "direction", json_add_num(response, "direction",
pubkey_idx(&ld->id, &channel->peer->id)); node_id_idx(&ld->id, &channel->peer->id));
} }
derive_channel_id(&cid, &channel->funding_txid, derive_channel_id(&cid, &channel->funding_txid,
@ -542,12 +542,12 @@ static void json_add_channel(struct lightningd *ld,
// are implemented // are implemented
json_object_start(response, "funding_allocation_msat"); json_object_start(response, "funding_allocation_msat");
if (channel->funder == LOCAL) { if (channel->funder == LOCAL) {
json_add_u64(response, pubkey_to_hexstr(tmpctx, &p->id), 0); json_add_u64(response, node_id_to_hexstr(tmpctx, &p->id), 0);
json_add_u64(response, pubkey_to_hexstr(tmpctx, &ld->id), json_add_u64(response, node_id_to_hexstr(tmpctx, &ld->id),
channel->funding.satoshis * 1000); /* Raw: raw JSON field */ channel->funding.satoshis * 1000); /* Raw: raw JSON field */
} else { } else {
json_add_u64(response, pubkey_to_hexstr(tmpctx, &ld->id), 0); json_add_u64(response, node_id_to_hexstr(tmpctx, &ld->id), 0);
json_add_u64(response, pubkey_to_hexstr(tmpctx, &p->id), json_add_u64(response, node_id_to_hexstr(tmpctx, &p->id),
channel->funding.satoshis * 1000); /* Raw: raw JSON field */ channel->funding.satoshis * 1000); /* Raw: raw JSON field */
} }
json_object_end(response); json_object_end(response);
@ -555,17 +555,17 @@ static void json_add_channel(struct lightningd *ld,
json_object_start(response, "funding_msat"); json_object_start(response, "funding_msat");
if (channel->funder == LOCAL) { if (channel->funder == LOCAL) {
json_add_sat_only(response, json_add_sat_only(response,
pubkey_to_hexstr(tmpctx, &p->id), node_id_to_hexstr(tmpctx, &p->id),
AMOUNT_SAT(0)); AMOUNT_SAT(0));
json_add_sat_only(response, json_add_sat_only(response,
pubkey_to_hexstr(tmpctx, &ld->id), node_id_to_hexstr(tmpctx, &ld->id),
channel->funding); channel->funding);
} else { } else {
json_add_sat_only(response, json_add_sat_only(response,
pubkey_to_hexstr(tmpctx, &ld->id), node_id_to_hexstr(tmpctx, &ld->id),
AMOUNT_SAT(0)); AMOUNT_SAT(0));
json_add_sat_only(response, json_add_sat_only(response,
pubkey_to_hexstr(tmpctx, &p->id), node_id_to_hexstr(tmpctx, &p->id),
channel->funding); channel->funding);
} }
json_object_end(response); json_object_end(response);
@ -682,7 +682,7 @@ peer_connected_serialize(struct peer_connected_hook_payload *payload,
{ {
const struct peer *p = payload->peer; const struct peer *p = payload->peer;
json_object_start(stream, "peer"); json_object_start(stream, "peer");
json_add_pubkey(stream, "id", &p->id); json_add_node_id(stream, "id", &p->id);
json_add_string( json_add_string(
stream, "addr", stream, "addr",
type_to_string(stream, struct wireaddr_internal, &payload->addr)); type_to_string(stream, struct wireaddr_internal, &payload->addr));
@ -819,7 +819,7 @@ REGISTER_PLUGIN_HOOK(peer_connected, peer_connected_hook_cb,
void peer_connected(struct lightningd *ld, const u8 *msg, void peer_connected(struct lightningd *ld, const u8 *msg,
int peer_fd, int gossip_fd) int peer_fd, int gossip_fd)
{ {
struct pubkey id; struct node_id id;
u8 *globalfeatures, *localfeatures; u8 *globalfeatures, *localfeatures;
struct peer *peer; struct peer *peer;
struct peer_connected_hook_payload *hook_payload; struct peer_connected_hook_payload *hook_payload;
@ -948,7 +948,7 @@ static void json_add_peer(struct lightningd *ld,
struct channel *channel; struct channel *channel;
json_object_start(response, NULL); json_object_start(response, NULL);
json_add_pubkey(response, "id", &p->id); json_add_node_id(response, "id", &p->id);
/* Channel is also connected if uncommitted channel */ /* Channel is also connected if uncommitted channel */
if (p->uncommitted_channel) if (p->uncommitted_channel)
@ -999,12 +999,12 @@ static struct command_result *json_listpeers(struct command *cmd,
const jsmntok_t *params) const jsmntok_t *params)
{ {
enum log_level *ll; enum log_level *ll;
struct pubkey *specific_id; struct node_id *specific_id;
struct peer *peer; struct peer *peer;
struct json_stream *response; struct json_stream *response;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_opt("id", param_pubkey, &specific_id), p_opt("id", param_node_id, &specific_id),
p_opt("level", param_loglevel, &ll), p_opt("level", param_loglevel, &ll),
NULL)) NULL))
return command_param_failed(); return command_param_failed();
@ -1229,13 +1229,13 @@ static struct command_result *json_disconnect(struct command *cmd,
const jsmntok_t *obj UNNEEDED, const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params) const jsmntok_t *params)
{ {
struct pubkey *id; struct node_id *id;
struct peer *peer; struct peer *peer;
struct channel *channel; struct channel *channel;
bool *force; bool *force;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", param_pubkey, &id), p_req("id", param_node_id, &id),
p_opt_def("force", param_bool, &force, false), p_opt_def("force", param_bool, &force, false),
NULL)) NULL))
return command_param_failed(); return command_param_failed();
@ -1285,7 +1285,7 @@ static struct command_result *json_getinfo(struct command *cmd,
response = json_stream_success(cmd); response = json_stream_success(cmd);
json_object_start(response, NULL); json_object_start(response, NULL);
json_add_pubkey(response, "id", &cmd->ld->id); json_add_node_id(response, "id", &cmd->ld->id);
json_add_string(response, "alias", (const char *)cmd->ld->alias); json_add_string(response, "alias", (const char *)cmd->ld->alias);
json_add_hex_talarr(response, "color", cmd->ld->rgb); json_add_hex_talarr(response, "color", cmd->ld->rgb);
@ -1425,7 +1425,7 @@ static void set_channel_fees(struct command *cmd, struct channel *channel,
/* write JSON response entry */ /* write JSON response entry */
derive_channel_id(&cid, &channel->funding_txid, channel->funding_outnum); derive_channel_id(&cid, &channel->funding_txid, channel->funding_outnum);
json_object_start(response, NULL); json_object_start(response, NULL);
json_add_pubkey(response, "peer_id", &channel->peer->id); json_add_node_id(response, "peer_id", &channel->peer->id);
json_add_string(response, "channel_id", json_add_string(response, "channel_id",
type_to_string(tmpctx, struct channel_id, &cid)); type_to_string(tmpctx, struct channel_id, &cid));
if (channel->scid) if (channel->scid)
@ -1508,14 +1508,14 @@ static struct command_result *json_sign_last_tx(struct command *cmd,
const jsmntok_t *obj UNNEEDED, const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params) const jsmntok_t *params)
{ {
struct pubkey *peerid; struct node_id *peerid;
struct peer *peer; struct peer *peer;
struct json_stream *response; struct json_stream *response;
u8 *linear; u8 *linear;
struct channel *channel; struct channel *channel;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", param_pubkey, &peerid), p_req("id", param_node_id, &peerid),
NULL)) NULL))
return command_param_failed(); return command_param_failed();
@ -1555,12 +1555,12 @@ static struct command_result *json_dev_fail(struct command *cmd,
const jsmntok_t *obj UNNEEDED, const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params) const jsmntok_t *params)
{ {
struct pubkey *peerid; struct node_id *peerid;
struct peer *peer; struct peer *peer;
struct channel *channel; struct channel *channel;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", param_pubkey, &peerid), p_req("id", param_node_id, &peerid),
NULL)) NULL))
return command_param_failed(); return command_param_failed();
@ -1600,13 +1600,13 @@ static struct command_result *json_dev_reenable_commit(struct command *cmd,
const jsmntok_t *obj UNNEEDED, const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params) const jsmntok_t *params)
{ {
struct pubkey *peerid; struct node_id *peerid;
struct peer *peer; struct peer *peer;
u8 *msg; u8 *msg;
struct channel *channel; struct channel *channel;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", param_pubkey, &peerid), p_req("id", param_node_id, &peerid),
NULL)) NULL))
return command_param_failed(); return command_param_failed();
@ -1688,7 +1688,7 @@ static struct command_result *json_dev_forget_channel(struct command *cmd,
const jsmntok_t *obj UNNEEDED, const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params) const jsmntok_t *params)
{ {
struct pubkey *peerid; struct node_id *peerid;
struct peer *peer; struct peer *peer;
struct channel *channel; struct channel *channel;
struct short_channel_id *scid; struct short_channel_id *scid;
@ -1697,7 +1697,7 @@ static struct command_result *json_dev_forget_channel(struct command *cmd,
bool *force; bool *force;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", param_pubkey, &peerid), p_req("id", param_node_id, &peerid),
p_opt("short_channel_id", param_short_channel_id, &scid), p_opt("short_channel_id", param_short_channel_id, &scid),
p_opt_def("force", param_bool, &force, false), p_opt_def("force", param_bool, &force, false),
NULL)) NULL))

7
lightningd/peer_control.h

@ -7,6 +7,7 @@
#include <common/channel_config.h> #include <common/channel_config.h>
#include <common/htlc.h> #include <common/htlc.h>
#include <common/json.h> #include <common/json.h>
#include <common/node_id.h>
#include <common/wireaddr.h> #include <common/wireaddr.h>
#include <lightningd/channel.h> #include <lightningd/channel.h>
#include <lightningd/channel_state.h> #include <lightningd/channel_state.h>
@ -27,7 +28,7 @@ struct peer {
u64 dbid; u64 dbid;
/* ID of peer */ /* ID of peer */
struct pubkey id; struct node_id id;
/* Our channels */ /* Our channels */
struct list_head channels; struct list_head channels;
@ -56,13 +57,13 @@ struct peer {
struct peer *find_peer_by_dbid(struct lightningd *ld, u64 dbid); struct peer *find_peer_by_dbid(struct lightningd *ld, u64 dbid);
struct peer *new_peer(struct lightningd *ld, u64 dbid, struct peer *new_peer(struct lightningd *ld, u64 dbid,
const struct pubkey *id, const struct node_id *id,
const struct wireaddr_internal *addr); const struct wireaddr_internal *addr);
/* Last one out deletes peer. Also removes from db. */ /* Last one out deletes peer. Also removes from db. */
void maybe_delete_peer(struct peer *peer); void maybe_delete_peer(struct peer *peer);
struct peer *peer_by_id(struct lightningd *ld, const struct pubkey *id); struct peer *peer_by_id(struct lightningd *ld, const struct node_id *id);
struct peer *peer_from_json(struct lightningd *ld, struct peer *peer_from_json(struct lightningd *ld,
const char *buffer, const char *buffer,
const jsmntok_t *peeridtok); const jsmntok_t *peeridtok);

10
lightningd/peer_htlcs.c

@ -493,7 +493,7 @@ static void forward_htlc(struct htlc_in *hin,
u32 cltv_expiry, u32 cltv_expiry,
struct amount_msat amt_to_forward, struct amount_msat amt_to_forward,
u32 outgoing_cltv_value, u32 outgoing_cltv_value,
const struct pubkey *next_hop, const struct node_id *next_hop,
const u8 next_onion[TOTAL_PACKET_SIZE]) const u8 next_onion[TOTAL_PACKET_SIZE])
{ {
enum onion_type failcode; enum onion_type failcode;
@ -591,7 +591,7 @@ struct gossip_resolve {
static void channel_resolve_reply(struct subd *gossip, const u8 *msg, static void channel_resolve_reply(struct subd *gossip, const u8 *msg,
const int *fds UNUSED, struct gossip_resolve *gr) const int *fds UNUSED, struct gossip_resolve *gr)
{ {
struct pubkey *peer_id; struct node_id *peer_id;
if (!fromwire_gossip_get_channel_peer_reply(msg, msg, &peer_id)) { if (!fromwire_gossip_get_channel_peer_reply(msg, msg, &peer_id)) {
log_broken(gossip->log, log_broken(gossip->log,
@ -1755,7 +1755,7 @@ static void fixup_hout(struct lightningd *ld, struct htlc_out *hout)
" is missing a resolution: %s.", " is missing a resolution: %s.",
hout->key.id, htlc_state_name(hout->hstate), hout->key.id, htlc_state_name(hout->hstate),
type_to_string(tmpctx, struct amount_msat, &hout->msat), type_to_string(tmpctx, struct amount_msat, &hout->msat),
type_to_string(tmpctx, struct pubkey, type_to_string(tmpctx, struct node_id,
&hout->key.channel->peer->id), &hout->key.channel->peer->id),
fix); fix);
} }
@ -1852,12 +1852,12 @@ static struct command_result *json_dev_ignore_htlcs(struct command *cmd,
const jsmntok_t *obj UNNEEDED, const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params) const jsmntok_t *params)
{ {
struct pubkey *peerid; struct node_id *peerid;
struct peer *peer; struct peer *peer;
bool *ignore; bool *ignore;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", param_pubkey, &peerid), p_req("id", param_node_id, &peerid),
p_req("ignore", param_bool, &ignore), p_req("ignore", param_bool, &ignore),
NULL)) NULL))
return command_param_failed(); return command_param_failed();

14
lightningd/ping.c

@ -16,17 +16,17 @@
struct ping_command { struct ping_command {
struct list_node list; struct list_node list;
struct pubkey id; struct node_id id;
struct command *cmd; struct command *cmd;
}; };
static struct ping_command *find_ping_cmd(struct lightningd *ld, static struct ping_command *find_ping_cmd(struct lightningd *ld,
const struct pubkey *id) const struct node_id *id)
{ {
struct ping_command *i; struct ping_command *i;
list_for_each(&ld->ping_commands, i, list) { list_for_each(&ld->ping_commands, i, list) {
if (pubkey_eq(id, &i->id)) if (node_id_eq(id, &i->id))
return i; return i;
} }
return NULL; return NULL;
@ -39,7 +39,7 @@ static void destroy_ping_command(struct ping_command *pc)
static struct ping_command *new_ping_command(const tal_t *ctx, static struct ping_command *new_ping_command(const tal_t *ctx,
struct lightningd *ld, struct lightningd *ld,
const struct pubkey *peer_id, const struct node_id *peer_id,
struct command *cmd) struct command *cmd)
{ {
struct ping_command *pc = tal(ctx, struct ping_command); struct ping_command *pc = tal(ctx, struct ping_command);
@ -56,7 +56,7 @@ void ping_reply(struct subd *subd, const u8 *msg)
{ {
u16 totlen; u16 totlen;
bool ok, sent = true; bool ok, sent = true;
struct pubkey id; struct node_id id;
struct ping_command *pc; struct ping_command *pc;
log_debug(subd->ld->log, "Got ping reply!"); log_debug(subd->ld->log, "Got ping reply!");
@ -87,10 +87,10 @@ static struct command_result *json_ping(struct command *cmd,
{ {
u8 *msg; u8 *msg;
unsigned int *len, *pongbytes; unsigned int *len, *pongbytes;
struct pubkey *id; struct node_id *id;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_req("id", param_pubkey, &id), p_req("id", param_node_id, &id),
p_opt_def("len", param_number, &len, 128), p_opt_def("len", param_number, &len, 128),
p_opt_def("pongbytes", param_number, &pongbytes, 128), p_opt_def("pongbytes", param_number, &pongbytes, 128),
NULL)) NULL))

61
lightningd/test/run-invoice-select-inchan.c

@ -67,7 +67,7 @@ struct command_result *command_success(struct command *cmd UNNEEDED,
{ fprintf(stderr, "command_success called!\n"); abort(); } { fprintf(stderr, "command_success called!\n"); abort(); }
/* Generated stub for connect_succeeded */ /* Generated stub for connect_succeeded */
void connect_succeeded(struct lightningd *ld UNNEEDED, const struct pubkey *id UNNEEDED) void connect_succeeded(struct lightningd *ld UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "connect_succeeded called!\n"); abort(); } { fprintf(stderr, "connect_succeeded called!\n"); abort(); }
/* Generated stub for delay_then_reconnect */ /* Generated stub for delay_then_reconnect */
void delay_then_reconnect(struct channel *channel UNNEEDED, u32 seconds_delay UNNEEDED, void delay_then_reconnect(struct channel *channel UNNEEDED, u32 seconds_delay UNNEEDED,
@ -80,7 +80,7 @@ void fatal(const char *fmt UNNEEDED, ...)
bool fromwire_channel_dev_memleak_reply(const void *p UNNEEDED, bool *leak UNNEEDED) bool fromwire_channel_dev_memleak_reply(const void *p UNNEEDED, bool *leak UNNEEDED)
{ fprintf(stderr, "fromwire_channel_dev_memleak_reply called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_dev_memleak_reply called!\n"); abort(); }
/* Generated stub for fromwire_connect_peer_connected */ /* Generated stub for fromwire_connect_peer_connected */
bool fromwire_connect_peer_connected(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct pubkey *id UNNEEDED, struct wireaddr_internal *addr UNNEEDED, struct crypto_state *crypto_state UNNEEDED, u8 **globalfeatures UNNEEDED, u8 **localfeatures UNNEEDED) bool fromwire_connect_peer_connected(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct node_id *id UNNEEDED, struct wireaddr_internal *addr UNNEEDED, struct crypto_state *crypto_state UNNEEDED, u8 **globalfeatures UNNEEDED, u8 **localfeatures UNNEEDED)
{ fprintf(stderr, "fromwire_connect_peer_connected called!\n"); abort(); } { fprintf(stderr, "fromwire_connect_peer_connected called!\n"); abort(); }
/* Generated stub for fromwire_gossip_get_incoming_channels_reply */ /* Generated stub for fromwire_gossip_get_incoming_channels_reply */
bool fromwire_gossip_get_incoming_channels_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct route_info **route_info UNNEEDED) bool fromwire_gossip_get_incoming_channels_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct route_info **route_info UNNEEDED)
@ -160,15 +160,15 @@ void json_add_log(struct json_stream *result UNNEEDED,
void json_add_member(struct json_stream *js UNNEEDED, const char *fieldname UNNEEDED, void json_add_member(struct json_stream *js UNNEEDED, const char *fieldname UNNEEDED,
const char *fmt UNNEEDED, ...) const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "json_add_member called!\n"); abort(); } { fprintf(stderr, "json_add_member called!\n"); abort(); }
/* Generated stub for json_add_node_id */
void json_add_node_id(struct json_stream *response UNNEEDED,
const char *fieldname UNNEEDED,
const struct node_id *id UNNEEDED)
{ fprintf(stderr, "json_add_node_id called!\n"); abort(); }
/* Generated stub for json_add_num */ /* Generated stub for json_add_num */
void json_add_num(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, void json_add_num(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
unsigned int value UNNEEDED) unsigned int value UNNEEDED)
{ fprintf(stderr, "json_add_num called!\n"); abort(); } { fprintf(stderr, "json_add_num called!\n"); abort(); }
/* Generated stub for json_add_pubkey */
void json_add_pubkey(struct json_stream *response UNNEEDED,
const char *fieldname UNNEEDED,
const struct pubkey *key UNNEEDED)
{ fprintf(stderr, "json_add_pubkey called!\n"); abort(); }
/* Generated stub for json_add_short_channel_id */ /* Generated stub for json_add_short_channel_id */
void json_add_short_channel_id(struct json_stream *response UNNEEDED, void json_add_short_channel_id(struct json_stream *response UNNEEDED,
const char *fieldname UNNEEDED, const char *fieldname UNNEEDED,
@ -219,10 +219,10 @@ enum address_parse_result json_tok_address_scriptpubkey(const tal_t *ctx UNNEEDE
bool json_tok_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, bool json_tok_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct channel_id *cid UNNEEDED) struct channel_id *cid UNNEEDED)
{ fprintf(stderr, "json_tok_channel_id called!\n"); abort(); } { fprintf(stderr, "json_tok_channel_id called!\n"); abort(); }
/* Generated stub for json_to_pubkey */ /* Generated stub for json_to_node_id */
bool json_to_pubkey(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, bool json_to_node_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct pubkey *pubkey UNNEEDED) struct node_id *id UNNEEDED)
{ fprintf(stderr, "json_to_pubkey called!\n"); abort(); } { fprintf(stderr, "json_to_node_id called!\n"); abort(); }
/* Generated stub for json_to_short_channel_id */ /* Generated stub for json_to_short_channel_id */
bool json_to_short_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, bool json_to_short_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct short_channel_id *scid UNNEEDED, struct short_channel_id *scid UNNEEDED,
@ -260,12 +260,18 @@ struct oneshot *new_reltimer_(struct timers *timers UNNEEDED,
struct timerel expire UNNEEDED, struct timerel expire UNNEEDED,
void (*cb)(void *) UNNEEDED, void *arg UNNEEDED) void (*cb)(void *) UNNEEDED, void *arg UNNEEDED)
{ fprintf(stderr, "new_reltimer_ called!\n"); abort(); } { fprintf(stderr, "new_reltimer_ called!\n"); abort(); }
/* Generated stub for node_id_cmp */
int node_id_cmp(const struct node_id *a UNNEEDED, const struct node_id *b UNNEEDED)
{ fprintf(stderr, "node_id_cmp called!\n"); abort(); }
/* Generated stub for node_id_to_hexstr */
char *node_id_to_hexstr(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "node_id_to_hexstr called!\n"); abort(); }
/* Generated stub for notify_connect */ /* Generated stub for notify_connect */
void notify_connect(struct lightningd *ld UNNEEDED, struct pubkey *nodeid UNNEEDED, void notify_connect(struct lightningd *ld UNNEEDED, struct node_id *nodeid UNNEEDED,
struct wireaddr_internal *addr UNNEEDED) struct wireaddr_internal *addr UNNEEDED)
{ fprintf(stderr, "notify_connect called!\n"); abort(); } { fprintf(stderr, "notify_connect called!\n"); abort(); }
/* Generated stub for notify_disconnect */ /* Generated stub for notify_disconnect */
void notify_disconnect(struct lightningd *ld UNNEEDED, struct pubkey *nodeid UNNEEDED) void notify_disconnect(struct lightningd *ld UNNEEDED, struct node_id *nodeid UNNEEDED)
{ fprintf(stderr, "notify_disconnect called!\n"); abort(); } { fprintf(stderr, "notify_disconnect called!\n"); abort(); }
/* Generated stub for null_response */ /* Generated stub for null_response */
struct json_stream *null_response(struct command *cmd UNNEEDED) struct json_stream *null_response(struct command *cmd UNNEEDED)
@ -316,16 +322,18 @@ struct command_result *param_msat(struct command *cmd UNNEEDED, const char *name
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct amount_msat **msat UNNEEDED) struct amount_msat **msat UNNEEDED)
{ fprintf(stderr, "param_msat called!\n"); abort(); } { fprintf(stderr, "param_msat called!\n"); abort(); }
/* Generated stub for param_node_id */
struct command_result *param_node_id(struct command *cmd UNNEEDED,
const char *name UNNEEDED,
const char *buffer UNNEEDED,
const jsmntok_t *tok UNNEEDED,
struct node_id **id UNNEEDED)
{ fprintf(stderr, "param_node_id called!\n"); abort(); }
/* Generated stub for param_number */ /* Generated stub for param_number */
struct command_result *param_number(struct command *cmd UNNEEDED, const char *name UNNEEDED, struct command_result *param_number(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
unsigned int **num UNNEEDED) unsigned int **num UNNEEDED)
{ fprintf(stderr, "param_number called!\n"); abort(); } { fprintf(stderr, "param_number called!\n"); abort(); }
/* Generated stub for param_pubkey */
struct command_result *param_pubkey(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct pubkey **pubkey UNNEEDED)
{ fprintf(stderr, "param_pubkey called!\n"); abort(); }
/* Generated stub for param_short_channel_id */ /* Generated stub for param_short_channel_id */
struct command_result *param_short_channel_id(struct command *cmd UNNEEDED, struct command_result *param_short_channel_id(struct command *cmd UNNEEDED,
const char *name UNNEEDED, const char *name UNNEEDED,
@ -413,10 +421,10 @@ u8 *towire_channel_send_shutdown(const tal_t *ctx UNNEEDED)
u8 *towire_channel_specific_feerates(const tal_t *ctx UNNEEDED, u32 feerate_base UNNEEDED, u32 feerate_ppm UNNEEDED) u8 *towire_channel_specific_feerates(const tal_t *ctx UNNEEDED, u32 feerate_base UNNEEDED, u32 feerate_ppm UNNEEDED)
{ fprintf(stderr, "towire_channel_specific_feerates called!\n"); abort(); } { fprintf(stderr, "towire_channel_specific_feerates called!\n"); abort(); }
/* Generated stub for towire_connectctl_connect_to_peer */ /* Generated stub for towire_connectctl_connect_to_peer */
u8 *towire_connectctl_connect_to_peer(const tal_t *ctx UNNEEDED, const struct pubkey *id UNNEEDED, u32 seconds_waited UNNEEDED, const struct wireaddr_internal *addrhint UNNEEDED) u8 *towire_connectctl_connect_to_peer(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED, u32 seconds_waited UNNEEDED, const struct wireaddr_internal *addrhint UNNEEDED)
{ fprintf(stderr, "towire_connectctl_connect_to_peer called!\n"); abort(); } { fprintf(stderr, "towire_connectctl_connect_to_peer called!\n"); abort(); }
/* Generated stub for towire_connectctl_peer_disconnected */ /* Generated stub for towire_connectctl_peer_disconnected */
u8 *towire_connectctl_peer_disconnected(const tal_t *ctx UNNEEDED, const struct pubkey *id UNNEEDED) u8 *towire_connectctl_peer_disconnected(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "towire_connectctl_peer_disconnected called!\n"); abort(); } { fprintf(stderr, "towire_connectctl_peer_disconnected called!\n"); abort(); }
/* Generated stub for towire_errorfmt */ /* Generated stub for towire_errorfmt */
u8 *towire_errorfmt(const tal_t *ctx UNNEEDED, u8 *towire_errorfmt(const tal_t *ctx UNNEEDED,
@ -427,10 +435,10 @@ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED,
u8 *towire_gossip_get_incoming_channels(const tal_t *ctx UNNEEDED, const bool *private_too UNNEEDED) u8 *towire_gossip_get_incoming_channels(const tal_t *ctx UNNEEDED, const bool *private_too UNNEEDED)
{ fprintf(stderr, "towire_gossip_get_incoming_channels called!\n"); abort(); } { fprintf(stderr, "towire_gossip_get_incoming_channels called!\n"); abort(); }
/* Generated stub for towire_hsm_get_channel_basepoints */ /* Generated stub for towire_hsm_get_channel_basepoints */
u8 *towire_hsm_get_channel_basepoints(const tal_t *ctx UNNEEDED, const struct pubkey *peerid UNNEEDED, u64 dbid UNNEEDED) u8 *towire_hsm_get_channel_basepoints(const tal_t *ctx UNNEEDED, const struct node_id *peerid UNNEEDED, u64 dbid UNNEEDED)
{ fprintf(stderr, "towire_hsm_get_channel_basepoints called!\n"); abort(); } { fprintf(stderr, "towire_hsm_get_channel_basepoints called!\n"); abort(); }
/* Generated stub for towire_hsm_sign_commitment_tx */ /* Generated stub for towire_hsm_sign_commitment_tx */
u8 *towire_hsm_sign_commitment_tx(const tal_t *ctx UNNEEDED, const struct pubkey *peer_id UNNEEDED, u64 channel_dbid UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const struct pubkey *remote_funding_key UNNEEDED, struct amount_sat funding_amount UNNEEDED) u8 *towire_hsm_sign_commitment_tx(const tal_t *ctx UNNEEDED, const struct node_id *peer_id UNNEEDED, u64 channel_dbid UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const struct pubkey *remote_funding_key UNNEEDED, struct amount_sat funding_amount UNNEEDED)
{ fprintf(stderr, "towire_hsm_sign_commitment_tx called!\n"); abort(); } { fprintf(stderr, "towire_hsm_sign_commitment_tx called!\n"); abort(); }
/* Generated stub for towire_hsm_sign_invoice */ /* Generated stub for towire_hsm_sign_invoice */
u8 *towire_hsm_sign_invoice(const tal_t *ctx UNNEEDED, const u8 *u5bytes UNNEEDED, const u8 *hrp UNNEEDED) u8 *towire_hsm_sign_invoice(const tal_t *ctx UNNEEDED, const u8 *u5bytes UNNEEDED, const u8 *hrp UNNEEDED)
@ -597,13 +605,14 @@ static void add_peer(struct lightningd *ld, int n, enum channel_state state,
list_add_tail(&peer->channels, &c->list); list_add_tail(&peer->channels, &c->list);
} }
/* There *is* padding in this structure, at the end. */ /* There *is* padding in this structure, after pubkey and after cltv_expiry_delta. */
STRUCTEQ_DEF(route_info, ALIGNOF(struct route_info) - sizeof(u16), STRUCTEQ_DEF(route_info,
ALIGNOF(struct short_channel_id) - 1 - sizeof(u16),
pubkey, pubkey,
cltv_expiry_delta,
short_channel_id, short_channel_id,
fee_base_msat, fee_base_msat,
fee_proportional_millionths, fee_proportional_millionths);
cltv_expiry_delta);
int main(void) int main(void)
{ {

14
plugins/pay.c

@ -12,7 +12,7 @@
#include <stdio.h> #include <stdio.h>
/* Public key of this node. */ /* Public key of this node. */
static struct pubkey my_id; static struct node_id my_id;
static unsigned int maxdelay_default; static unsigned int maxdelay_default;
static LIST_HEAD(pay_status); static LIST_HEAD(pay_status);
@ -310,7 +310,7 @@ static const char *route_pubkey(const tal_t *ctx,
{ {
if (n == tal_count(routehint)) if (n == tal_count(routehint))
return pc->dest; return pc->dest;
return type_to_string(ctx, struct pubkey, &routehint[n].pubkey); return type_to_string(ctx, struct node_id, &routehint[n].pubkey);
} }
static const char *join_routehint(const tal_t *ctx, static const char *join_routehint(const tal_t *ctx,
@ -604,7 +604,7 @@ static struct command_result *start_pay_attempt(struct command *cmd,
"{ 'message': 'Routehint absurd fee' }"); "{ 'message': 'Routehint absurd fee' }");
return next_routehint(cmd, pc); return next_routehint(cmd, pc);
} }
dest = type_to_string(tmpctx, struct pubkey, dest = type_to_string(tmpctx, struct node_id,
&attempt->routehint[0].pubkey); &attempt->routehint[0].pubkey);
max_hops -= tal_count(attempt->routehint); max_hops -= tal_count(attempt->routehint);
cltv = route_cltv(pc->final_cltv, cltv = route_cltv(pc->final_cltv,
@ -806,7 +806,7 @@ static struct route_info **filter_routehints(struct pay_command *pc,
/* If we are first hop, trim. */ /* If we are first hop, trim. */
if (tal_count(hints[i]) > 0 if (tal_count(hints[i]) > 0
&& pubkey_eq(&hints[i][0].pubkey, &my_id)) { && node_id_eq(&hints[i][0].pubkey, &my_id)) {
tal_append_fmt(&mods, tal_append_fmt(&mods,
"Removed ourselves from routehint %zu. ", "Removed ourselves from routehint %zu. ",
i); i);
@ -939,7 +939,7 @@ static struct command_result *json_pay(struct command *cmd,
pc->exemptfee = *exemptfee; pc->exemptfee = *exemptfee;
pc->riskfactor = *riskfactor; pc->riskfactor = *riskfactor;
pc->final_cltv = b11->min_final_cltv_expiry; pc->final_cltv = b11->min_final_cltv_expiry;
pc->dest = type_to_string(cmd, struct pubkey, &b11->receiver_id); pc->dest = type_to_string(cmd, struct node_id, &b11->receiver_id);
pc->shadow_dest = tal_strdup(pc, pc->dest); pc->shadow_dest = tal_strdup(pc, pc->dest);
pc->payment_hash = type_to_string(pc, struct sha256, pc->payment_hash = type_to_string(pc, struct sha256,
&b11->payment_hash); &b11->payment_hash);
@ -1001,7 +1001,7 @@ static void add_attempt(char **ret,
" 'fee_proportional_millionths': %u," " 'fee_proportional_millionths': %u,"
" 'cltv_expiry_delta': %u }", " 'cltv_expiry_delta': %u }",
i == 0 ? "" : ", ", i == 0 ? "" : ", ",
type_to_string(tmpctx, struct pubkey, type_to_string(tmpctx, struct node_id,
&attempt->routehint[i].pubkey), &attempt->routehint[i].pubkey),
type_to_string(tmpctx, type_to_string(tmpctx,
struct short_channel_id, struct short_channel_id,
@ -1183,7 +1183,7 @@ static void init(struct plugin_conn *rpc)
const char *field; const char *field;
field = rpc_delve(tmpctx, "getinfo", "", rpc, ".id"); field = rpc_delve(tmpctx, "getinfo", "", rpc, ".id");
if (!pubkey_from_hexstr(field, strlen(field), &my_id)) if (!node_id_from_hexstr(field, strlen(field), &my_id))
plugin_err("getinfo didn't contain valid id: '%s'", field); plugin_err("getinfo didn't contain valid id: '%s'", field);
field = rpc_delve(tmpctx, "listconfigs", field = rpc_delve(tmpctx, "listconfigs",

1
wallet/test/Makefile

@ -10,6 +10,7 @@ WALLET_TEST_COMMON_OBJS := \
common/htlc_wire.o \ common/htlc_wire.o \
common/type_to_string.o \ common/type_to_string.o \
common/memleak.o \ common/memleak.o \
common/node_id.o \
common/key_derive.o \ common/key_derive.o \
common/pseudorand.o \ common/pseudorand.o \
common/timeout.o \ common/timeout.o \

3
wallet/test/run-db.c

@ -22,9 +22,6 @@ static void db_log_(struct log *log UNUSED, enum log_level level UNUSED, const c
struct json_escaped *json_escaped_string_(const tal_t *ctx UNNEEDED, struct json_escaped *json_escaped_string_(const tal_t *ctx UNNEEDED,
const void *bytes UNNEEDED, size_t len UNNEEDED) const void *bytes UNNEEDED, size_t len UNNEEDED)
{ fprintf(stderr, "json_escaped_string_ called!\n"); abort(); } { fprintf(stderr, "json_escaped_string_ called!\n"); abort(); }
/* Generated stub for node_id_valid */
bool node_id_valid(const struct node_id *id UNNEEDED)
{ fprintf(stderr, "node_id_valid called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */ /* AUTOGENERATED MOCKS END */
static char *db_err; static char *db_err;

71
wallet/test/run-wallet.c

@ -70,7 +70,7 @@ struct command_result *command_success(struct command *cmd UNNEEDED,
{ fprintf(stderr, "command_success called!\n"); abort(); } { fprintf(stderr, "command_success called!\n"); abort(); }
/* Generated stub for connect_succeeded */ /* Generated stub for connect_succeeded */
void connect_succeeded(struct lightningd *ld UNNEEDED, const struct pubkey *id UNNEEDED) void connect_succeeded(struct lightningd *ld UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "connect_succeeded called!\n"); abort(); } { fprintf(stderr, "connect_succeeded called!\n"); abort(); }
/* Generated stub for delay_then_reconnect */ /* Generated stub for delay_then_reconnect */
void delay_then_reconnect(struct channel *channel UNNEEDED, u32 seconds_delay UNNEEDED, void delay_then_reconnect(struct channel *channel UNNEEDED, u32 seconds_delay UNNEEDED,
@ -95,10 +95,10 @@ bool fromwire_channel_offer_htlc_reply(const tal_t *ctx UNNEEDED, const void *p
bool fromwire_channel_sending_commitsig(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u64 *commitnum UNNEEDED, u32 *feerate UNNEEDED, struct changed_htlc **changed UNNEEDED, struct bitcoin_signature *commit_sig UNNEEDED, secp256k1_ecdsa_signature **htlc_sigs UNNEEDED) bool fromwire_channel_sending_commitsig(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u64 *commitnum UNNEEDED, u32 *feerate UNNEEDED, struct changed_htlc **changed UNNEEDED, struct bitcoin_signature *commit_sig UNNEEDED, secp256k1_ecdsa_signature **htlc_sigs UNNEEDED)
{ fprintf(stderr, "fromwire_channel_sending_commitsig called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_sending_commitsig called!\n"); abort(); }
/* Generated stub for fromwire_connect_peer_connected */ /* Generated stub for fromwire_connect_peer_connected */
bool fromwire_connect_peer_connected(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct pubkey *id UNNEEDED, struct wireaddr_internal *addr UNNEEDED, struct crypto_state *crypto_state UNNEEDED, u8 **globalfeatures UNNEEDED, u8 **localfeatures UNNEEDED) bool fromwire_connect_peer_connected(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct node_id *id UNNEEDED, struct wireaddr_internal *addr UNNEEDED, struct crypto_state *crypto_state UNNEEDED, u8 **globalfeatures UNNEEDED, u8 **localfeatures UNNEEDED)
{ fprintf(stderr, "fromwire_connect_peer_connected called!\n"); abort(); } { fprintf(stderr, "fromwire_connect_peer_connected called!\n"); abort(); }
/* Generated stub for fromwire_gossip_get_channel_peer_reply */ /* Generated stub for fromwire_gossip_get_channel_peer_reply */
bool fromwire_gossip_get_channel_peer_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct pubkey **peer_id UNNEEDED) bool fromwire_gossip_get_channel_peer_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct node_id **peer_id UNNEEDED)
{ fprintf(stderr, "fromwire_gossip_get_channel_peer_reply called!\n"); abort(); } { fprintf(stderr, "fromwire_gossip_get_channel_peer_reply called!\n"); abort(); }
/* Generated stub for fromwire_hsm_sign_commitment_tx_reply */ /* Generated stub for fromwire_hsm_sign_commitment_tx_reply */
bool fromwire_hsm_sign_commitment_tx_reply(const void *p UNNEEDED, struct bitcoin_signature *sig UNNEEDED) bool fromwire_hsm_sign_commitment_tx_reply(const void *p UNNEEDED, struct bitcoin_signature *sig UNNEEDED)
@ -234,15 +234,15 @@ void json_add_log(struct json_stream *result UNNEEDED,
void json_add_member(struct json_stream *js UNNEEDED, const char *fieldname UNNEEDED, void json_add_member(struct json_stream *js UNNEEDED, const char *fieldname UNNEEDED,
const char *fmt UNNEEDED, ...) const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "json_add_member called!\n"); abort(); } { fprintf(stderr, "json_add_member called!\n"); abort(); }
/* Generated stub for json_add_node_id */
void json_add_node_id(struct json_stream *response UNNEEDED,
const char *fieldname UNNEEDED,
const struct node_id *id UNNEEDED)
{ fprintf(stderr, "json_add_node_id called!\n"); abort(); }
/* Generated stub for json_add_num */ /* Generated stub for json_add_num */
void json_add_num(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, void json_add_num(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
unsigned int value UNNEEDED) unsigned int value UNNEEDED)
{ fprintf(stderr, "json_add_num called!\n"); abort(); } { fprintf(stderr, "json_add_num called!\n"); abort(); }
/* Generated stub for json_add_pubkey */
void json_add_pubkey(struct json_stream *response UNNEEDED,
const char *fieldname UNNEEDED,
const struct pubkey *key UNNEEDED)
{ fprintf(stderr, "json_add_pubkey called!\n"); abort(); }
/* Generated stub for json_add_short_channel_id */ /* Generated stub for json_add_short_channel_id */
void json_add_short_channel_id(struct json_stream *response UNNEEDED, void json_add_short_channel_id(struct json_stream *response UNNEEDED,
const char *fieldname UNNEEDED, const char *fieldname UNNEEDED,
@ -299,10 +299,10 @@ int json_tok_full_len(const jsmntok_t *t UNNEEDED)
/* Generated stub for json_tok_streq */ /* Generated stub for json_tok_streq */
bool json_tok_streq(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, const char *str UNNEEDED) bool json_tok_streq(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, const char *str UNNEEDED)
{ fprintf(stderr, "json_tok_streq called!\n"); abort(); } { fprintf(stderr, "json_tok_streq called!\n"); abort(); }
/* Generated stub for json_to_pubkey */ /* Generated stub for json_to_node_id */
bool json_to_pubkey(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, bool json_to_node_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct pubkey *pubkey UNNEEDED) struct node_id *id UNNEEDED)
{ fprintf(stderr, "json_to_pubkey called!\n"); abort(); } { fprintf(stderr, "json_to_node_id called!\n"); abort(); }
/* Generated stub for json_to_short_channel_id */ /* Generated stub for json_to_short_channel_id */
bool json_to_short_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, bool json_to_short_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct short_channel_id *scid UNNEEDED, struct short_channel_id *scid UNNEEDED,
@ -319,15 +319,12 @@ void log_add(struct log *log UNNEEDED, const char *fmt UNNEEDED, ...)
void log_io(struct log *log UNNEEDED, enum log_level dir UNNEEDED, const char *comment UNNEEDED, void log_io(struct log *log UNNEEDED, enum log_level dir UNNEEDED, const char *comment UNNEEDED,
const void *data UNNEEDED, size_t len UNNEEDED) const void *data UNNEEDED, size_t len UNNEEDED)
{ fprintf(stderr, "log_io called!\n"); abort(); } { fprintf(stderr, "log_io called!\n"); abort(); }
/* Generated stub for node_id_valid */
bool node_id_valid(const struct node_id *id UNNEEDED)
{ fprintf(stderr, "node_id_valid called!\n"); abort(); }
/* Generated stub for notify_connect */ /* Generated stub for notify_connect */
void notify_connect(struct lightningd *ld UNNEEDED, struct pubkey *nodeid UNNEEDED, void notify_connect(struct lightningd *ld UNNEEDED, struct node_id *nodeid UNNEEDED,
struct wireaddr_internal *addr UNNEEDED) struct wireaddr_internal *addr UNNEEDED)
{ fprintf(stderr, "notify_connect called!\n"); abort(); } { fprintf(stderr, "notify_connect called!\n"); abort(); }
/* Generated stub for notify_disconnect */ /* Generated stub for notify_disconnect */
void notify_disconnect(struct lightningd *ld UNNEEDED, struct pubkey *nodeid UNNEEDED) void notify_disconnect(struct lightningd *ld UNNEEDED, struct node_id *nodeid UNNEEDED)
{ fprintf(stderr, "notify_disconnect called!\n"); abort(); } { fprintf(stderr, "notify_disconnect called!\n"); abort(); }
/* Generated stub for null_response */ /* Generated stub for null_response */
struct json_stream *null_response(struct command *cmd UNNEEDED) struct json_stream *null_response(struct command *cmd UNNEEDED)
@ -379,16 +376,18 @@ struct command_result *param_msat(struct command *cmd UNNEEDED, const char *name
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct amount_msat **msat UNNEEDED) struct amount_msat **msat UNNEEDED)
{ fprintf(stderr, "param_msat called!\n"); abort(); } { fprintf(stderr, "param_msat called!\n"); abort(); }
/* Generated stub for param_node_id */
struct command_result *param_node_id(struct command *cmd UNNEEDED,
const char *name UNNEEDED,
const char *buffer UNNEEDED,
const jsmntok_t *tok UNNEEDED,
struct node_id **id UNNEEDED)
{ fprintf(stderr, "param_node_id called!\n"); abort(); }
/* Generated stub for param_number */ /* Generated stub for param_number */
struct command_result *param_number(struct command *cmd UNNEEDED, const char *name UNNEEDED, struct command_result *param_number(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
unsigned int **num UNNEEDED) unsigned int **num UNNEEDED)
{ fprintf(stderr, "param_number called!\n"); abort(); } { fprintf(stderr, "param_number called!\n"); abort(); }
/* Generated stub for param_pubkey */
struct command_result *param_pubkey(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct pubkey **pubkey UNNEEDED)
{ fprintf(stderr, "param_pubkey called!\n"); abort(); }
/* Generated stub for param_short_channel_id */ /* Generated stub for param_short_channel_id */
struct command_result *param_short_channel_id(struct command *cmd UNNEEDED, struct command_result *param_short_channel_id(struct command *cmd UNNEEDED,
const char *name UNNEEDED, const char *name UNNEEDED,
@ -504,10 +503,10 @@ u8 *towire_channel_send_shutdown(const tal_t *ctx UNNEEDED)
u8 *towire_channel_specific_feerates(const tal_t *ctx UNNEEDED, u32 feerate_base UNNEEDED, u32 feerate_ppm UNNEEDED) u8 *towire_channel_specific_feerates(const tal_t *ctx UNNEEDED, u32 feerate_base UNNEEDED, u32 feerate_ppm UNNEEDED)
{ fprintf(stderr, "towire_channel_specific_feerates called!\n"); abort(); } { fprintf(stderr, "towire_channel_specific_feerates called!\n"); abort(); }
/* Generated stub for towire_connectctl_connect_to_peer */ /* Generated stub for towire_connectctl_connect_to_peer */
u8 *towire_connectctl_connect_to_peer(const tal_t *ctx UNNEEDED, const struct pubkey *id UNNEEDED, u32 seconds_waited UNNEEDED, const struct wireaddr_internal *addrhint UNNEEDED) u8 *towire_connectctl_connect_to_peer(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED, u32 seconds_waited UNNEEDED, const struct wireaddr_internal *addrhint UNNEEDED)
{ fprintf(stderr, "towire_connectctl_connect_to_peer called!\n"); abort(); } { fprintf(stderr, "towire_connectctl_connect_to_peer called!\n"); abort(); }
/* Generated stub for towire_connectctl_peer_disconnected */ /* Generated stub for towire_connectctl_peer_disconnected */
u8 *towire_connectctl_peer_disconnected(const tal_t *ctx UNNEEDED, const struct pubkey *id UNNEEDED) u8 *towire_connectctl_peer_disconnected(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "towire_connectctl_peer_disconnected called!\n"); abort(); } { fprintf(stderr, "towire_connectctl_peer_disconnected called!\n"); abort(); }
/* Generated stub for towire_errorfmt */ /* Generated stub for towire_errorfmt */
u8 *towire_errorfmt(const tal_t *ctx UNNEEDED, u8 *towire_errorfmt(const tal_t *ctx UNNEEDED,
@ -518,7 +517,7 @@ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED,
u8 *towire_gossip_get_channel_peer(const tal_t *ctx UNNEEDED, const struct short_channel_id *channel_id UNNEEDED) u8 *towire_gossip_get_channel_peer(const tal_t *ctx UNNEEDED, const struct short_channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "towire_gossip_get_channel_peer called!\n"); abort(); } { fprintf(stderr, "towire_gossip_get_channel_peer called!\n"); abort(); }
/* Generated stub for towire_hsm_sign_commitment_tx */ /* Generated stub for towire_hsm_sign_commitment_tx */
u8 *towire_hsm_sign_commitment_tx(const tal_t *ctx UNNEEDED, const struct pubkey *peer_id UNNEEDED, u64 channel_dbid UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const struct pubkey *remote_funding_key UNNEEDED, struct amount_sat funding_amount UNNEEDED) u8 *towire_hsm_sign_commitment_tx(const tal_t *ctx UNNEEDED, const struct node_id *peer_id UNNEEDED, u64 channel_dbid UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const struct pubkey *remote_funding_key UNNEEDED, struct amount_sat funding_amount UNNEEDED)
{ fprintf(stderr, "towire_hsm_sign_commitment_tx called!\n"); abort(); } { fprintf(stderr, "towire_hsm_sign_commitment_tx called!\n"); abort(); }
/* Generated stub for towire_onchain_dev_memleak */ /* Generated stub for towire_onchain_dev_memleak */
u8 *towire_onchain_dev_memleak(const tal_t *ctx UNNEEDED) u8 *towire_onchain_dev_memleak(const tal_t *ctx UNNEEDED)
@ -555,7 +554,7 @@ bool dev_disconnect_permanent(struct lightningd *ld UNNEEDED)
#endif #endif
/* Fake stubs to talk to hsm */ /* Fake stubs to talk to hsm */
u8 *towire_hsm_get_channel_basepoints(const tal_t *ctx UNNEEDED, const struct pubkey *peerid UNNEEDED, u64 dbid UNNEEDED) u8 *towire_hsm_get_channel_basepoints(const tal_t *ctx UNNEEDED, const struct node_id *peerid UNNEEDED, u64 dbid UNNEEDED)
{ {
return NULL; return NULL;
} }
@ -698,6 +697,7 @@ static bool test_wallet_outputs(struct lightningd *ld, const tal_t *ctx)
struct wallet *w = create_test_wallet(ld, ctx); struct wallet *w = create_test_wallet(ld, ctx);
struct utxo u; struct utxo u;
struct pubkey pk; struct pubkey pk;
struct node_id id;
struct amount_sat fee_estimate, change_satoshis; struct amount_sat fee_estimate, change_satoshis;
const struct utxo **utxos; const struct utxo **utxos;
CHECK(w); CHECK(w);
@ -705,6 +705,7 @@ static bool test_wallet_outputs(struct lightningd *ld, const tal_t *ctx)
memset(&u, 0, sizeof(u)); memset(&u, 0, sizeof(u));
u.amount = AMOUNT_SAT(1); u.amount = AMOUNT_SAT(1);
pubkey_from_der(tal_hexdata(w, "02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc", 66), 33, &pk); pubkey_from_der(tal_hexdata(w, "02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc", 66), 33, &pk);
node_id_from_pubkey(&id, &pk);
db_begin_transaction(w->db); db_begin_transaction(w->db);
@ -720,7 +721,7 @@ static bool test_wallet_outputs(struct lightningd *ld, const tal_t *ctx)
memset(&u.txid, 1, sizeof(u.txid)); memset(&u.txid, 1, sizeof(u.txid));
u.close_info = tal(w, struct unilateral_close_info); u.close_info = tal(w, struct unilateral_close_info);
u.close_info->channel_id = 42; u.close_info->channel_id = 42;
u.close_info->peer_id = pk; u.close_info->peer_id = id;
u.close_info->commitment_point = pk; u.close_info->commitment_point = pk;
CHECK_MSG(wallet_add_utxo(w, &u, p2sh_wpkh), CHECK_MSG(wallet_add_utxo(w, &u, p2sh_wpkh),
"wallet_add_utxo with close_info"); "wallet_add_utxo with close_info");
@ -734,7 +735,7 @@ static bool test_wallet_outputs(struct lightningd *ld, const tal_t *ctx)
u = *utxos[1]; u = *utxos[1];
CHECK(u.close_info->channel_id == 42 && CHECK(u.close_info->channel_id == 42 &&
pubkey_eq(&u.close_info->commitment_point, &pk) && pubkey_eq(&u.close_info->commitment_point, &pk) &&
pubkey_eq(&u.close_info->peer_id, &pk)); node_id_eq(&u.close_info->peer_id, &id));
/* Now un-reserve them for the tests below */ /* Now un-reserve them for the tests below */
tal_free(utxos); tal_free(utxos);
@ -826,7 +827,7 @@ static bool channelseq(struct channel *c1, struct channel *c2)
CHECK(c1->peer->dbid == c2->peer->dbid); CHECK(c1->peer->dbid == c2->peer->dbid);
CHECK(c1->peer == c2->peer); CHECK(c1->peer == c2->peer);
CHECK(c1->their_shachain.id == c2->their_shachain.id); CHECK(c1->their_shachain.id == c2->their_shachain.id);
CHECK_MSG(pubkey_eq(&p1->id, &p2->id), "NodeIDs do not match"); CHECK_MSG(node_id_eq(&p1->id, &p2->id), "NodeIDs do not match");
CHECK((c1->scid == NULL && c2->scid == NULL) 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(amount_msat_eq(c1->our_msat, c2->our_msat));
@ -900,6 +901,7 @@ static bool test_channel_crud(struct lightningd *ld, const tal_t *ctx)
struct channel_info *ci = &c1.channel_info; struct channel_info *ci = &c1.channel_info;
struct bitcoin_txid *hash = tal(w, struct bitcoin_txid); struct bitcoin_txid *hash = tal(w, struct bitcoin_txid);
struct pubkey pk; struct pubkey pk;
struct node_id id;
struct changed_htlc *last_commit; struct changed_htlc *last_commit;
secp256k1_ecdsa_signature *sig = tal(w, secp256k1_ecdsa_signature); secp256k1_ecdsa_signature *sig = tal(w, secp256k1_ecdsa_signature);
u8 *scriptpubkey = tal_arr(ctx, u8, 100); u8 *scriptpubkey = tal_arr(ctx, u8, 100);
@ -912,13 +914,14 @@ static bool test_channel_crud(struct lightningd *ld, const tal_t *ctx)
last_commit = tal_arr(w, struct changed_htlc, 2); last_commit = tal_arr(w, struct changed_htlc, 2);
mempat(last_commit, tal_bytelen(last_commit)); mempat(last_commit, tal_bytelen(last_commit));
pubkey_from_der(tal_hexdata(w, "02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc", 66), 33, &pk); pubkey_from_der(tal_hexdata(w, "02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc", 66), 33, &pk);
node_id_from_pubkey(&id, &pk);
ci->feerate_per_kw[LOCAL] = ci->feerate_per_kw[REMOTE] = 31337; ci->feerate_per_kw[LOCAL] = ci->feerate_per_kw[REMOTE] = 31337;
mempat(scriptpubkey, tal_count(scriptpubkey)); mempat(scriptpubkey, tal_count(scriptpubkey));
c1.first_blocknum = 1; c1.first_blocknum = 1;
parse_wireaddr_internal("localhost:1234", &addr, 0, false, false, false, parse_wireaddr_internal("localhost:1234", &addr, 0, false, false, false,
NULL); NULL);
c1.final_key_idx = 1337; c1.final_key_idx = 1337;
p = new_peer(ld, 0, &pk, &addr); p = new_peer(ld, 0, &id, &addr);
c1.peer = p; c1.peer = p;
c1.dbid = wallet_get_channel_dbid(w); c1.dbid = wallet_get_channel_dbid(w);
c1.state = CHANNELD_NORMAL; c1.state = CHANNELD_NORMAL;
@ -1120,7 +1123,7 @@ static bool test_payment_crud(struct lightningd *ld, const tal_t *ctx)
struct wallet *w = create_test_wallet(ld, ctx); struct wallet *w = create_test_wallet(ld, ctx);
mempat(t, sizeof(*t)); mempat(t, sizeof(*t));
memset(&t->destination, 1, sizeof(t->destination)); memset(&t->destination, 2, sizeof(t->destination));
t->id = 0; t->id = 0;
t->msatoshi = AMOUNT_MSAT(100); t->msatoshi = AMOUNT_MSAT(100);
@ -1135,7 +1138,7 @@ static bool test_payment_crud(struct lightningd *ld, const tal_t *ctx)
t2 = wallet_payment_by_hash(ctx, w, &t->payment_hash); t2 = wallet_payment_by_hash(ctx, w, &t->payment_hash);
CHECK(t2 != NULL); CHECK(t2 != NULL);
CHECK(t2->status == t->status); CHECK(t2->status == t->status);
CHECK(pubkey_cmp(&t2->destination, &t->destination) == 0); CHECK(node_id_cmp(&t2->destination, &t->destination) == 0);
CHECK(amount_msat_eq(t2->msatoshi, t->msatoshi)); CHECK(amount_msat_eq(t2->msatoshi, t->msatoshi));
CHECK(amount_msat_eq(t2->msatoshi_sent, t->msatoshi_sent)); CHECK(amount_msat_eq(t2->msatoshi_sent, t->msatoshi_sent));
CHECK(!t2->payment_preimage); CHECK(!t2->payment_preimage);
@ -1148,7 +1151,7 @@ static bool test_payment_crud(struct lightningd *ld, const tal_t *ctx)
t2 = wallet_payment_by_hash(ctx, w, &t->payment_hash); t2 = wallet_payment_by_hash(ctx, w, &t->payment_hash);
CHECK(t2 != NULL); CHECK(t2 != NULL);
CHECK(t2->status == t->status); CHECK(t2->status == t->status);
CHECK(pubkey_cmp(&t2->destination, &t->destination) == 0); CHECK(node_id_eq(&t2->destination, &t->destination));
CHECK(amount_msat_eq(t2->msatoshi, t->msatoshi)); CHECK(amount_msat_eq(t2->msatoshi, t->msatoshi));
CHECK(amount_msat_eq(t2->msatoshi_sent, t->msatoshi_sent)); CHECK(amount_msat_eq(t2->msatoshi_sent, t->msatoshi_sent));
CHECK(preimage_eq(t->payment_preimage, t2->payment_preimage)); CHECK(preimage_eq(t->payment_preimage, t2->payment_preimage));
@ -1180,7 +1183,7 @@ int main(void)
/* Only elements in ld we should access */ /* Only elements in ld we should access */
list_head_init(&ld->peers); list_head_init(&ld->peers);
pubkey_from_der(tal_hexdata(tmpctx, "02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc", 66), 33, &ld->id); node_id_from_hexstr("02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc", 66, &ld->id);
/* Accessed in peer destructor sanity check */ /* Accessed in peer destructor sanity check */
htlc_in_map_init(&ld->htlcs_in); htlc_in_map_init(&ld->htlcs_in);
htlc_out_map_init(&ld->htlcs_out); htlc_out_map_init(&ld->htlcs_out);

30
wallet/wallet.c

@ -93,7 +93,7 @@ bool wallet_add_utxo(struct wallet *w, struct utxo *utxo,
sqlite3_bind_int(stmt, 6, utxo->keyindex); sqlite3_bind_int(stmt, 6, utxo->keyindex);
if (utxo->close_info) { if (utxo->close_info) {
sqlite3_bind_int64(stmt, 7, utxo->close_info->channel_id); sqlite3_bind_int64(stmt, 7, utxo->close_info->channel_id);
sqlite3_bind_pubkey(stmt, 8, &utxo->close_info->peer_id); sqlite3_bind_node_id(stmt, 8, &utxo->close_info->peer_id);
sqlite3_bind_pubkey(stmt, 9, &utxo->close_info->commitment_point); sqlite3_bind_pubkey(stmt, 9, &utxo->close_info->commitment_point);
} else { } else {
sqlite3_bind_null(stmt, 7); sqlite3_bind_null(stmt, 7);
@ -138,7 +138,7 @@ static struct utxo *wallet_stmt2output(const tal_t *ctx, sqlite3_stmt *stmt)
if (sqlite3_column_type(stmt, 6) != SQLITE_NULL) { if (sqlite3_column_type(stmt, 6) != SQLITE_NULL) {
utxo->close_info = tal(utxo, struct unilateral_close_info); utxo->close_info = tal(utxo, struct unilateral_close_info);
utxo->close_info->channel_id = sqlite3_column_int64(stmt, 6); utxo->close_info->channel_id = sqlite3_column_int64(stmt, 6);
sqlite3_column_pubkey(stmt, 7, &utxo->close_info->peer_id); sqlite3_column_node_id(stmt, 7, &utxo->close_info->peer_id);
sqlite3_column_pubkey(stmt, 8, &utxo->close_info->commitment_point); sqlite3_column_pubkey(stmt, 8, &utxo->close_info->commitment_point);
} else { } else {
utxo->close_info = NULL; utxo->close_info = NULL;
@ -550,7 +550,7 @@ static struct peer *wallet_peer_load(struct wallet *w, const u64 dbid)
{ {
const unsigned char *addrstr; const unsigned char *addrstr;
struct peer *peer; struct peer *peer;
struct pubkey id; struct node_id id;
struct wireaddr_internal addr; struct wireaddr_internal addr;
sqlite3_stmt *stmt = sqlite3_stmt *stmt =
@ -560,7 +560,7 @@ static struct peer *wallet_peer_load(struct wallet *w, const u64 dbid)
if (!db_select_step(w->db, stmt)) if (!db_select_step(w->db, stmt))
return NULL; return NULL;
if (!sqlite3_column_pubkey(stmt, 1, &id)) { if (!sqlite3_column_node_id(stmt, 1, &id)) {
db_stmt_done(stmt); db_stmt_done(stmt);
return NULL; return NULL;
} }
@ -1087,7 +1087,7 @@ void wallet_channel_insert(struct wallet *w, struct channel *chan)
if (chan->peer->dbid == 0) { if (chan->peer->dbid == 0) {
/* Need to create the peer first */ /* Need to create the peer first */
stmt = db_prepare(w->db, "INSERT INTO peers (node_id, address) VALUES (?, ?);"); stmt = db_prepare(w->db, "INSERT INTO peers (node_id, address) VALUES (?, ?);");
sqlite3_bind_pubkey(stmt, 1, &chan->peer->id); sqlite3_bind_node_id(stmt, 1, &chan->peer->id);
sqlite3_bind_text(stmt, 2, sqlite3_bind_text(stmt, 2,
type_to_string(tmpctx, struct wireaddr_internal, &chan->peer->addr), type_to_string(tmpctx, struct wireaddr_internal, &chan->peer->addr),
-1, SQLITE_TRANSIENT); -1, SQLITE_TRANSIENT);
@ -1469,7 +1469,7 @@ static void fixup_hin(struct wallet *wallet, struct htlc_in *hin)
" subsituting temporary node failure", " subsituting temporary node failure",
hin->key.id, htlc_state_name(hin->hstate), hin->key.id, htlc_state_name(hin->hstate),
type_to_string(tmpctx, struct amount_msat, &hin->msat), type_to_string(tmpctx, struct amount_msat, &hin->msat),
type_to_string(tmpctx, struct pubkey, type_to_string(tmpctx, struct node_id,
&hin->key.channel->peer->id)); &hin->key.channel->peer->id));
#endif #endif
} }
@ -1721,13 +1721,13 @@ void wallet_payment_store(struct wallet *wallet,
sqlite3_bind_int(stmt, 1, payment->status); sqlite3_bind_int(stmt, 1, payment->status);
sqlite3_bind_sha256(stmt, 2, &payment->payment_hash); sqlite3_bind_sha256(stmt, 2, &payment->payment_hash);
sqlite3_bind_pubkey(stmt, 3, &payment->destination); sqlite3_bind_node_id(stmt, 3, &payment->destination);
sqlite3_bind_amount_msat(stmt, 4, payment->msatoshi); sqlite3_bind_amount_msat(stmt, 4, payment->msatoshi);
sqlite3_bind_int(stmt, 5, payment->timestamp); sqlite3_bind_int(stmt, 5, payment->timestamp);
sqlite3_bind_blob(stmt, 6, payment->path_secrets, sqlite3_bind_blob(stmt, 6, payment->path_secrets,
tal_bytelen(payment->path_secrets), tal_bytelen(payment->path_secrets),
SQLITE_TRANSIENT); SQLITE_TRANSIENT);
sqlite3_bind_pubkey_array(stmt, 7, payment->route_nodes); sqlite3_bind_node_id_array(stmt, 7, payment->route_nodes);
sqlite3_bind_short_channel_id_array(stmt, 8, sqlite3_bind_short_channel_id_array(stmt, 8,
payment->route_channels); payment->route_channels);
sqlite3_bind_amount_msat(stmt, 9, payment->msatoshi_sent); sqlite3_bind_amount_msat(stmt, 9, payment->msatoshi_sent);
@ -1779,7 +1779,7 @@ static struct wallet_payment *wallet_stmt2payment(const tal_t *ctx,
payment->id = sqlite3_column_int64(stmt, 0); payment->id = sqlite3_column_int64(stmt, 0);
payment->status = sqlite3_column_int(stmt, 1); payment->status = sqlite3_column_int(stmt, 1);
sqlite3_column_pubkey(stmt, 2, &payment->destination); sqlite3_column_node_id(stmt, 2, &payment->destination);
payment->msatoshi = sqlite3_column_amount_msat(stmt, 3); payment->msatoshi = sqlite3_column_amount_msat(stmt, 3);
sqlite3_column_sha256(stmt, 4, &payment->payment_hash); sqlite3_column_sha256(stmt, 4, &payment->payment_hash);
@ -1793,7 +1793,7 @@ static struct wallet_payment *wallet_stmt2payment(const tal_t *ctx,
/* Can be NULL for old db! */ /* Can be NULL for old db! */
payment->path_secrets = sqlite3_column_secrets(payment, stmt, 7); payment->path_secrets = sqlite3_column_secrets(payment, stmt, 7);
payment->route_nodes = sqlite3_column_pubkey_array(payment, stmt, 8); payment->route_nodes = sqlite3_column_node_id_array(payment, stmt, 8);
payment->route_channels payment->route_channels
= sqlite3_column_short_channel_id_array(payment, stmt, 9); = sqlite3_column_short_channel_id_array(payment, stmt, 9);
@ -1896,7 +1896,7 @@ void wallet_payment_get_failinfo(const tal_t *ctx,
bool *faildestperm, bool *faildestperm,
int *failindex, int *failindex,
enum onion_type *failcode, enum onion_type *failcode,
struct pubkey **failnode, struct node_id **failnode,
struct short_channel_id **failchannel, struct short_channel_id **failchannel,
u8 **failupdate, u8 **failupdate,
char **faildetail, char **faildetail,
@ -1929,8 +1929,8 @@ void wallet_payment_get_failinfo(const tal_t *ctx,
if (sqlite3_column_type(stmt, 4) == SQLITE_NULL) if (sqlite3_column_type(stmt, 4) == SQLITE_NULL)
*failnode = NULL; *failnode = NULL;
else { else {
*failnode = tal(ctx, struct pubkey); *failnode = tal(ctx, struct node_id);
resb = sqlite3_column_pubkey(stmt, 4, *failnode); resb = sqlite3_column_node_id(stmt, 4, *failnode);
assert(resb); assert(resb);
} }
if (sqlite3_column_type(stmt, 5) == SQLITE_NULL) if (sqlite3_column_type(stmt, 5) == SQLITE_NULL)
@ -1962,7 +1962,7 @@ void wallet_payment_set_failinfo(struct wallet *wallet,
bool faildestperm, bool faildestperm,
int failindex, int failindex,
enum onion_type failcode, enum onion_type failcode,
const struct pubkey *failnode, const struct node_id *failnode,
const struct short_channel_id *failchannel, const struct short_channel_id *failchannel,
const u8 *failupdate /*tal_arr*/, const u8 *failupdate /*tal_arr*/,
const char *faildetail, const char *faildetail,
@ -1992,7 +1992,7 @@ void wallet_payment_set_failinfo(struct wallet *wallet,
sqlite3_bind_int(stmt, 3, failindex); sqlite3_bind_int(stmt, 3, failindex);
sqlite3_bind_int(stmt, 4, (int) failcode); sqlite3_bind_int(stmt, 4, (int) failcode);
if (failnode) if (failnode)
sqlite3_bind_pubkey(stmt, 5, failnode); sqlite3_bind_node_id(stmt, 5, failnode);
else else
sqlite3_bind_null(stmt, 5); sqlite3_bind_null(stmt, 5);
if (failchannel) { if (failchannel) {

10
wallet/wallet.h

@ -23,9 +23,9 @@ struct amount_msat;
struct invoices; struct invoices;
struct channel; struct channel;
struct lightningd; struct lightningd;
struct node_id;
struct oneshot; struct oneshot;
struct peer; struct peer;
struct pubkey;
struct timers; struct timers;
struct wallet { struct wallet {
@ -215,14 +215,14 @@ struct wallet_payment {
u32 timestamp; u32 timestamp;
struct sha256 payment_hash; struct sha256 payment_hash;
enum wallet_payment_status status; enum wallet_payment_status status;
struct pubkey destination; struct node_id destination;
struct amount_msat msatoshi; struct amount_msat msatoshi;
struct amount_msat msatoshi_sent; struct amount_msat msatoshi_sent;
/* If and only if PAYMENT_COMPLETE */ /* If and only if PAYMENT_COMPLETE */
struct preimage *payment_preimage; struct preimage *payment_preimage;
/* Needed for recovering from routing failures. */ /* Needed for recovering from routing failures. */
struct secret *path_secrets; struct secret *path_secrets;
struct pubkey *route_nodes; struct node_id *route_nodes;
struct short_channel_id *route_channels; struct short_channel_id *route_channels;
/* bolt11 string; NULL for old payments. */ /* bolt11 string; NULL for old payments. */
const char *bolt11; const char *bolt11;
@ -900,7 +900,7 @@ void wallet_payment_get_failinfo(const tal_t *ctx,
bool *faildestperm, bool *faildestperm,
int *failindex, int *failindex,
enum onion_type *failcode, enum onion_type *failcode,
struct pubkey **failnode, struct node_id **failnode,
struct short_channel_id **failchannel, struct short_channel_id **failchannel,
u8 **failupdate, u8 **failupdate,
char **faildetail, char **faildetail,
@ -915,7 +915,7 @@ void wallet_payment_set_failinfo(struct wallet *wallet,
bool faildestperm, bool faildestperm,
int failindex, int failindex,
enum onion_type failcode, enum onion_type failcode,
const struct pubkey *failnode, const struct node_id *failnode,
const struct short_channel_id *failchannel, const struct short_channel_id *failchannel,
const u8 *failupdate, const u8 *failupdate,
const char *faildetail, const char *faildetail,

2
wallet/walletrpc.c

@ -500,7 +500,7 @@ static struct command_result *json_listfunds(struct command *cmd,
struct channel *c; struct channel *c;
list_for_each(&p->channels, c, list) { list_for_each(&p->channels, c, list) {
json_object_start(response, NULL); json_object_start(response, NULL);
json_add_pubkey(response, "peer_id", &p->id); json_add_node_id(response, "peer_id", &p->id);
if (c->scid) if (c->scid)
json_add_short_channel_id(response, json_add_short_channel_id(response,
"short_channel_id", "short_channel_id",

2
wire/towire.c

@ -85,6 +85,8 @@ void towire_pubkey(u8 **pptr, const struct pubkey *pubkey)
void towire_node_id(u8 **pptr, const struct node_id *id) void towire_node_id(u8 **pptr, const struct node_id *id)
{ {
/* Cheap sanity check */
assert(id->k[0] == 0x2 || id->k[0] == 0x3);
towire(pptr, id->k, sizeof(id->k)); towire(pptr, id->k, sizeof(id->k));
} }

Loading…
Cancel
Save