wire: use struct node_id for node ids.

Don't turn them to/from pubkeys implicitly.  This means nodeids in the store
don't get converted, but bitcoin keys still do.

MCP results from 5 runs, min-max(mean +/- stddev):
	store_load_msec:33934-35251(34531.4+/-5e+02)
	vsz_kb:2637488
	store_rewrite_sec:34.720000-35.130000(34.94+/-0.14)
	listnodes_sec:1.020000-1.290000(1.146+/-0.086)
	listchannels_sec:51.110000-58.240000(54.826+/-2.5)
	routing_sec:30.000000-33.320000(30.726+/-1.3)
	peer_write_all_sec:50.370000-52.970000(51.646+/-1.1)

MCP notable changes from previous patch (>1 stddev):
	-store_load_msec:46184-47474(46673.4+/-4.5e+02)
	+store_load_msec:33934-35251(34531.4+/-5e+02)
	-vsz_kb:2638880
	+vsz_kb:2637488
	-store_rewrite_sec:46.750000-48.280000(47.512+/-0.51)
	+store_rewrite_sec:34.720000-35.130000(34.94+/-0.14)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2019-04-08 19:28:44 +09:30 committed by neil saitug
parent 4c9d9b2e05
commit 91849dddc4
9 changed files with 40 additions and 47 deletions

View File

@ -406,12 +406,6 @@ static u8 *create_channel_announcement(const tal_t *ctx, struct peer *peer)
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(
ctx, &peer->announcement_node_sigs[first],
&peer->announcement_node_sigs[second],
@ -419,8 +413,10 @@ static u8 *create_channel_announcement(const tal_t *ctx, struct peer *peer)
&peer->announcement_bitcoin_sigs[second],
features,
&peer->chain_hash,
&peer->short_channel_ids[LOCAL], &pk1,
&pk2, &peer->channel->funding_pubkey[first],
&peer->short_channel_ids[LOCAL],
&peer->node_ids[first],
&peer->node_ids[second],
&peer->channel->funding_pubkey[first],
&peer->channel->funding_pubkey[second]);
tal_free(features);
return cannounce;

View File

@ -89,8 +89,8 @@ static u8 *gossip_store_wrap_channel_announcement(const tal_t *ctx,
u8 *features;
struct bitcoin_blkid chain_hash;
struct short_channel_id scid;
struct pubkey node_id_1;
struct pubkey node_id_2;
struct node_id node_id_1;
struct node_id node_id_2;
struct pubkey bitcoin_key_1;
struct pubkey bitcoin_key_2;

View File

@ -372,13 +372,9 @@ static u8 *create_node_announcement(const tal_t *ctx, struct daemon *daemon,
for (i = 0; i < tal_count(daemon->announcable); i++)
towire_wireaddr(&addresses, &daemon->announcable[i]);
/* FIXME */
struct pubkey me;
if (!pubkey_from_node_id(&me, &daemon->id))
abort();
announcement =
towire_node_announcement(ctx, sig, daemon->globalfeatures, timestamp,
&me, daemon->rgb, daemon->alias,
&daemon->id, daemon->rgb, daemon->alias,
addresses);
return announcement;
}

View File

@ -890,15 +890,11 @@ bool routing_add_channel_announcement(struct routing_state *rstate,
struct pubkey bitcoin_key_1;
struct pubkey bitcoin_key_2;
/* FIXME */
struct pubkey pk1, pk2;
if (!fromwire_channel_announcement(
tmpctx, msg, &node_signature_1, &node_signature_2,
&bitcoin_signature_1, &bitcoin_signature_2, &features, &chain_hash,
&scid, &pk1, &pk2, &bitcoin_key_1, &bitcoin_key_2))
&scid, &node_id_1, &node_id_2, &bitcoin_key_1, &bitcoin_key_2))
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
* local_add_channel(); normally we don't accept new
@ -942,8 +938,6 @@ u8 *handle_channel_announcement(struct routing_state *rstate,
announce, tal_count(announce), 0);
pending->update_timestamps[0] = pending->update_timestamps[1] = 0;
/* FIXME */
struct pubkey pk1, pk2;
if (!fromwire_channel_announcement(pending, pending->announce,
&node_signature_1,
&node_signature_2,
@ -952,7 +946,8 @@ u8 *handle_channel_announcement(struct routing_state *rstate,
&features,
&chain_hash,
&pending->short_channel_id,
&pk1, &pk2,
&pending->node_id_1,
&pending->node_id_2,
&pending->bitcoin_key_1,
&pending->bitcoin_key_2)) {
err = towire_errorfmt(rstate, NULL,
@ -960,8 +955,6 @@ u8 *handle_channel_announcement(struct routing_state *rstate,
tal_hex(pending, pending->announce));
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
* again. Just drop the announcement and walk away whistling. Any non-0
@ -1030,6 +1023,7 @@ u8 *handle_channel_announcement(struct routing_state *rstate,
goto ignored;
}
/* Note that if node_id_1 or node_id_2 are malformed, it's caught here */
err = check_channel_announcement(rstate,
&pending->node_id_1,
&pending->node_id_2,
@ -1506,14 +1500,12 @@ bool routing_add_node_announcement(struct routing_state *rstate, const u8 *msg T
u8 *features, *addresses;
struct wireaddr *wireaddrs;
/* FIXME */
struct pubkey pk;
/* Note: validity of node_id is already checked. */
if (!fromwire_node_announcement(tmpctx, msg,
&signature, &features, &timestamp,
&pk, rgb_color, alias,
&node_id, rgb_color, alias,
&addresses))
return false;
node_id_from_pubkey(&node_id, &pk);
node = get_node(rstate, &node_id);
@ -1560,11 +1552,9 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
bool applied;
serialized = tal_dup_arr(tmpctx, u8, node_ann, len, 0);
/* FIXME */
struct pubkey pk;
if (!fromwire_node_announcement(tmpctx, serialized,
&signature, &features, &timestamp,
&pk, rgb_color, alias,
&node_id, rgb_color, alias,
&addresses)) {
/* BOLT #7:
*
@ -1577,7 +1567,6 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
tal_hex(tmpctx, node_ann));
return err;
}
node_id_from_pubkey(&node_id, &pk);
/* BOLT #7:
*
@ -1596,6 +1585,7 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
}
sha256_double(&hash, serialized + 66, tal_count(serialized) - 66);
/* If node_id is invalid, it fails here */
if (!check_signed_hash_nodeid(&hash, &signature, &node_id)) {
/* BOLT #7:
*

View File

@ -35,7 +35,7 @@ struct broadcast_state *new_broadcast_state(tal_t *ctx UNNEEDED)
void broadcast_del(struct broadcast_state *bstate UNNEEDED, u64 index UNNEEDED, const u8 *payload UNNEEDED)
{ fprintf(stderr, "broadcast_del called!\n"); abort(); }
/* Generated stub for fromwire_channel_announcement */
bool fromwire_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *node_signature_1 UNNEEDED, secp256k1_ecdsa_signature *node_signature_2 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_1 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_2 UNNEEDED, u8 **features UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *node_id_1 UNNEEDED, struct pubkey *node_id_2 UNNEEDED, struct pubkey *bitcoin_key_1 UNNEEDED, struct pubkey *bitcoin_key_2 UNNEEDED)
bool fromwire_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *node_signature_1 UNNEEDED, secp256k1_ecdsa_signature *node_signature_2 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_1 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_2 UNNEEDED, u8 **features UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct node_id *node_id_1 UNNEEDED, struct node_id *node_id_2 UNNEEDED, struct pubkey *bitcoin_key_1 UNNEEDED, struct pubkey *bitcoin_key_2 UNNEEDED)
{ fprintf(stderr, "fromwire_channel_announcement called!\n"); abort(); }
/* Generated stub for fromwire_channel_update */
bool fromwire_channel_update(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)
@ -62,7 +62,7 @@ bool fromwire_gossip_store_local_add_channel(const tal_t *ctx UNNEEDED, const vo
bool fromwire_gossip_store_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED)
{ fprintf(stderr, "fromwire_gossip_store_node_announcement called!\n"); abort(); }
/* Generated stub for fromwire_node_announcement */
bool fromwire_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, u8 **features UNNEEDED, u32 *timestamp UNNEEDED, struct pubkey *node_id UNNEEDED, u8 rgb_color[3] UNNEEDED, u8 alias[32] UNNEEDED, u8 **addresses UNNEEDED)
bool fromwire_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, u8 **features UNNEEDED, u32 *timestamp UNNEEDED, struct node_id *node_id UNNEEDED, u8 rgb_color[3] UNNEEDED, u8 alias[32] UNNEEDED, u8 **addresses UNNEEDED)
{ fprintf(stderr, "fromwire_node_announcement called!\n"); abort(); }
/* Generated stub for fromwire_peektype */
int fromwire_peektype(const u8 *cursor UNNEEDED)

View File

@ -24,7 +24,7 @@ struct broadcast_state *new_broadcast_state(tal_t *ctx UNNEEDED)
void broadcast_del(struct broadcast_state *bstate UNNEEDED, u64 index UNNEEDED, const u8 *payload UNNEEDED)
{ fprintf(stderr, "broadcast_del called!\n"); abort(); }
/* Generated stub for fromwire_channel_announcement */
bool fromwire_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *node_signature_1 UNNEEDED, secp256k1_ecdsa_signature *node_signature_2 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_1 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_2 UNNEEDED, u8 **features UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *node_id_1 UNNEEDED, struct pubkey *node_id_2 UNNEEDED, struct pubkey *bitcoin_key_1 UNNEEDED, struct pubkey *bitcoin_key_2 UNNEEDED)
bool fromwire_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *node_signature_1 UNNEEDED, secp256k1_ecdsa_signature *node_signature_2 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_1 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_2 UNNEEDED, u8 **features UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct node_id *node_id_1 UNNEEDED, struct node_id *node_id_2 UNNEEDED, struct pubkey *bitcoin_key_1 UNNEEDED, struct pubkey *bitcoin_key_2 UNNEEDED)
{ fprintf(stderr, "fromwire_channel_announcement called!\n"); abort(); }
/* Generated stub for fromwire_channel_update */
bool fromwire_channel_update(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)
@ -51,7 +51,7 @@ bool fromwire_gossip_store_local_add_channel(const tal_t *ctx UNNEEDED, const vo
bool fromwire_gossip_store_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED)
{ fprintf(stderr, "fromwire_gossip_store_node_announcement called!\n"); abort(); }
/* Generated stub for fromwire_node_announcement */
bool fromwire_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, u8 **features UNNEEDED, u32 *timestamp UNNEEDED, struct pubkey *node_id UNNEEDED, u8 rgb_color[3] UNNEEDED, u8 alias[32] UNNEEDED, u8 **addresses UNNEEDED)
bool fromwire_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, u8 **features UNNEEDED, u32 *timestamp UNNEEDED, struct node_id *node_id UNNEEDED, u8 rgb_color[3] UNNEEDED, u8 alias[32] UNNEEDED, u8 **addresses UNNEEDED)
{ fprintf(stderr, "fromwire_node_announcement called!\n"); abort(); }
/* Generated stub for fromwire_peektype */
int fromwire_peektype(const u8 *cursor UNNEEDED)

View File

@ -22,7 +22,7 @@ void status_fmt(enum log_level level UNUSED, const char *fmt, ...)
void broadcast_del(struct broadcast_state *bstate UNNEEDED, u64 index UNNEEDED, const u8 *payload UNNEEDED)
{ fprintf(stderr, "broadcast_del called!\n"); abort(); }
/* Generated stub for fromwire_channel_announcement */
bool fromwire_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *node_signature_1 UNNEEDED, secp256k1_ecdsa_signature *node_signature_2 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_1 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_2 UNNEEDED, u8 **features UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *node_id_1 UNNEEDED, struct pubkey *node_id_2 UNNEEDED, struct pubkey *bitcoin_key_1 UNNEEDED, struct pubkey *bitcoin_key_2 UNNEEDED)
bool fromwire_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *node_signature_1 UNNEEDED, secp256k1_ecdsa_signature *node_signature_2 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_1 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_2 UNNEEDED, u8 **features UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct node_id *node_id_1 UNNEEDED, struct node_id *node_id_2 UNNEEDED, struct pubkey *bitcoin_key_1 UNNEEDED, struct pubkey *bitcoin_key_2 UNNEEDED)
{ fprintf(stderr, "fromwire_channel_announcement called!\n"); abort(); }
/* Generated stub for fromwire_channel_update */
bool fromwire_channel_update(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)
@ -49,7 +49,7 @@ bool fromwire_gossip_store_local_add_channel(const tal_t *ctx UNNEEDED, const vo
bool fromwire_gossip_store_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED)
{ fprintf(stderr, "fromwire_gossip_store_node_announcement called!\n"); abort(); }
/* Generated stub for fromwire_node_announcement */
bool fromwire_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, u8 **features UNNEEDED, u32 *timestamp UNNEEDED, struct pubkey *node_id UNNEEDED, u8 rgb_color[3] UNNEEDED, u8 alias[32] UNNEEDED, u8 **addresses UNNEEDED)
bool fromwire_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, u8 **features UNNEEDED, u32 *timestamp UNNEEDED, struct node_id *node_id UNNEEDED, u8 rgb_color[3] UNNEEDED, u8 alias[32] UNNEEDED, u8 **addresses UNNEEDED)
{ fprintf(stderr, "fromwire_node_announcement called!\n"); abort(); }
/* Generated stub for fromwire_peektype */
int fromwire_peektype(const u8 *cursor UNNEEDED)

View File

@ -18,6 +18,7 @@ type2size = {
'secp256k1_ecdsa_signature': 64,
'struct preimage': 32,
'struct pubkey': 33,
'struct node_id': 33,
'struct sha256': 32,
'struct bitcoin_blkid': 32,
'struct bitcoin_txid': 32,
@ -110,6 +111,7 @@ partialtypemap = {
'pad': FieldType('pad'),
'msat': FieldType('struct amount_msat'),
'satoshis': FieldType('struct amount_sat'),
'node_id': FieldType('struct node_id'),
}
# Size to typename match

View File

@ -42,6 +42,11 @@ static void set_pubkey(struct pubkey *key)
assert(pubkey_from_der(der, sizeof(der), key));
}
static void set_node_id(struct node_id *id)
{
memset(id->k, 2, sizeof(id->k));
}
/* Size up to field. */
#define upto_field(p, field) \
((char *)&(p)->field - (char *)(p))
@ -167,7 +172,7 @@ struct msg_commitment_signed {
struct msg_node_announcement {
secp256k1_ecdsa_signature signature;
u32 timestamp;
struct pubkey node_id;
struct node_id node_id;
u8 rgb_color[3];
u8 alias[32];
u8 *features;
@ -206,8 +211,8 @@ struct msg_channel_announcement {
u8 *features;
struct bitcoin_blkid chain_hash;
struct short_channel_id short_channel_id;
struct pubkey node_id_1;
struct pubkey node_id_2;
struct node_id node_id_1;
struct node_id node_id_2;
struct pubkey bitcoin_key_1;
struct pubkey bitcoin_key_2;
};
@ -762,7 +767,9 @@ static bool channel_announcement_eq(const struct msg_channel_announcement *a,
&& eq_field(a, b, chain_hash)
&& short_channel_id_eq(&a->short_channel_id,
&b->short_channel_id)
&& eq_between(a, b, node_id_1, bitcoin_key_2);
&& eq_field(a, b, node_id_1)
&& eq_field(a, b, node_id_2)
&& eq_between(a, b, bitcoin_key_1, bitcoin_key_2);
}
static bool funding_locked_eq(const struct msg_funding_locked *a,
@ -887,7 +894,9 @@ static bool update_add_htlc_eq(const struct msg_update_add_htlc *a,
static bool node_announcement_eq(const struct msg_node_announcement *a,
const struct msg_node_announcement *b)
{
return eq_with(a, b, alias)
return eq_with(a, b, node_id)
&& eq_field(a, b, rgb_color)
&& eq_field(a, b, alias)
&& eq_var(a, b, features)
&& eq_var(a, b, addresses);
}
@ -938,8 +947,8 @@ int main(void)
| SECP256K1_CONTEXT_SIGN);
memset(&ca, 2, sizeof(ca));
set_pubkey(&ca.node_id_1);
set_pubkey(&ca.node_id_2);
set_node_id(&ca.node_id_1);
set_node_id(&ca.node_id_2);
set_pubkey(&ca.bitcoin_key_1);
set_pubkey(&ca.bitcoin_key_2);
ca.features = tal_arr(ctx, u8, 2);
@ -1103,7 +1112,7 @@ int main(void)
test_corruption(&uah, uah2, update_add_htlc);
memset(&na, 2, sizeof(na));
set_pubkey(&na.node_id);
set_node_id(&na.node_id);
na.features = tal_arr(ctx, u8, 2);
memset(na.features, 2, 2);
na.addresses = tal_arr(ctx, u8, 2);