Browse Source

routing: use marshalled short_channel_id, not string as tag for channel_announce

We use this technique for the other tags, so use it here too.

This was drawn to my attention when I made more than 10 channels in a
block, and the string changed length:

 Valgrind error file: valgrind-errors.31415
==31415== Conditional jump or move depends on uninitialised value(s)
==31415==    at 0x4C35E20: bcmp (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==31415==    by 0x11A624: queue_broadcast (broadcast.c:40)
==31415==    by 0x118D93: handle_pending_cannouncement (routing.c:704)
==31415==    by 0x1109E3: handle_txout_reply (gossip.c:1796)
==31415==    by 0x111177: recv_req (gossip.c:1955)
==31415==    by 0x136723: next_plan (io.c:59)
==31415==    by 0x137220: do_plan (io.c:387)
==31415==    by 0x13725E: io_ready (io.c:397)
==31415==    by 0x138B97: io_loop (poll.c:305)
==31415==    by 0x111352: main (gossip.c:2022)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
8fcb45c1b2
  1. 33
      gossipd/routing.c

33
gossipd/routing.c

@ -549,7 +549,6 @@ const struct short_channel_id *handle_channel_announcement(
struct pending_cannouncement *pending;
struct bitcoin_blkid chain_hash;
u8 *features;
const char *tag;
secp256k1_ecdsa_signature node_signature_1, node_signature_2;
secp256k1_ecdsa_signature bitcoin_signature_1, bitcoin_signature_2;
struct node_connection *c0, *c1;
@ -576,10 +575,6 @@ const struct short_channel_id *handle_channel_announcement(
return NULL;
}
tag = type_to_string(pending, struct short_channel_id,
&pending->short_channel_id);
tal_resize(&tag, strlen(tag));
/* BOLT #7:
*
* If there is an unknown even bit in the `features` field the
@ -602,7 +597,8 @@ const struct short_channel_id *handle_channel_announcement(
if (!structeq(&chain_hash, &rstate->chain_hash)) {
status_trace(
"Received channel_announcement %s for unknown chain %s",
tag,
type_to_string(pending, struct short_channel_id,
&pending->short_channel_id),
type_to_string(pending, struct bitcoin_blkid, &chain_hash));
tal_free(pending);
return NULL;
@ -617,13 +613,16 @@ const struct short_channel_id *handle_channel_announcement(
&bitcoin_signature_2,
pending->announce)) {
status_trace("Signature verification of channel_announcement"
" for %s failed", tag);
" for %s failed",
type_to_string(pending, struct short_channel_id,
&pending->short_channel_id));
tal_free(pending);
return NULL;
}
status_trace("Received channel_announcement for channel %s", tag);
tal_free(tag);
status_trace("Received channel_announcement for channel %s",
type_to_string(pending, struct short_channel_id,
&pending->short_channel_id));
/* FIXME: Handle duplicates as per BOLT #7 */
@ -647,7 +646,7 @@ bool handle_pending_cannouncement(struct routing_state *rstate,
{
bool forward, local;
struct node_connection *c0, *c1;
const char *tag;
u8 *tag;
const u8 *s;
struct pending_cannouncement *pending;
@ -655,15 +654,17 @@ bool handle_pending_cannouncement(struct routing_state *rstate,
assert(pending);
list_del_from(&rstate->pending_cannouncement, &pending->list);
tag = type_to_string(pending, struct short_channel_id, scid);
tal_resize(&tag, strlen(tag));
tag = tal_arr(pending, u8, 0);
towire_short_channel_id(&tag, scid);
/* BOLT #7:
*
* The receiving node MUST ignore the message if this output is spent.
*/
if (tal_len(outscript) == 0) {
status_trace("channel_announcement: no unspent txout %s", tag);
status_trace("channel_announcement: no unspent txout %s",
type_to_string(pending, struct short_channel_id,
scid));
tal_free(pending);
return false;
}
@ -683,7 +684,9 @@ bool handle_pending_cannouncement(struct routing_state *rstate,
if (!scripteq(s, outscript)) {
status_trace("channel_announcement: txout %s expectes %s, got %s",
tag, tal_hex(trc, s), tal_hex(trc, outscript));
type_to_string(pending, struct short_channel_id,
scid),
tal_hex(trc, s), tal_hex(trc, outscript));
tal_free(pending);
return false;
}
@ -703,7 +706,7 @@ bool handle_pending_cannouncement(struct routing_state *rstate,
if (forward) {
if (queue_broadcast(rstate->broadcasts,
WIRE_CHANNEL_ANNOUNCEMENT,
(u8*)tag, pending->announce))
tag, pending->announce))
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Announcement %s was replaced?",
tal_hex(trc, pending->announce));

Loading…
Cancel
Save