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>
This commit is contained in:
Rusty Russell
2019-04-08 19:28:32 +09:30
committed by neil saitug
parent b4455d517c
commit a2fa699e0e
63 changed files with 685 additions and 578 deletions

View File

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

View File

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

View File

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

View File

@@ -28,6 +28,9 @@ void fromwire_bitcoin_txid(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
/* Generated stub for fromwire_bool */
bool fromwire_bool(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ 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 */
void fromwire_pubkey(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct pubkey *pubkey UNNEEDED)
{ 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 */
void towire_bool(u8 **pptr UNNEEDED, bool v UNNEEDED)
{ 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 */
void towire_pubkey(u8 **pptr UNNEEDED, const struct pubkey *pubkey UNNEEDED)
{ fprintf(stderr, "towire_pubkey called!\n"); abort(); }

View File

@@ -17,7 +17,7 @@ void towire_utxo(u8 **pptr, const struct utxo *utxo)
towire_bool(pptr, is_unilateral_close);
if (is_unilateral_close) {
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);
}
}
@@ -39,7 +39,7 @@ struct utxo *fromwire_utxo(const tal_t *ctx, const u8 **ptr, size_t *max)
if (fromwire_bool(ptr, max)) {
utxo->close_info = tal(utxo, struct unilateral_close_info);
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);
} else {
utxo->close_info = NULL;

View File

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