Browse Source

gossipd: only broadcast channel_announcement once we have a channel_update.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
c2189229ca
  1. 18
      gossipd/routing.c
  2. 1
      tests/test_lightningd.py

18
gossipd/routing.c

@ -635,10 +635,8 @@ bool routing_add_channel_announcement(struct routing_state *rstate,
/* Channel is now public. */
chan->channel_announce = tal_dup_arr(chan, u8, msg, tal_len(msg), 0);
/* Now we can broadcast channel announce */
insert_broadcast(rstate->broadcasts, chan->channel_announce);
/* Clear any private updates. */
/* Clear any private updates: new updates will trigger broadcast of
* this channel_announce. */
for (size_t i = 0; i < ARRAY_SIZE(chan->half); i++)
chan->half[i].channel_update
= tal_free(chan->half[i].channel_update);
@ -934,6 +932,7 @@ bool routing_add_channel_update(struct routing_state *rstate,
struct bitcoin_blkid chain_hash;
struct chan *chan;
u8 direction;
bool have_broadcast_announce;
if (!fromwire_channel_update(update, &signature, &chain_hash,
&short_channel_id, &timestamp, &flags,
@ -944,6 +943,10 @@ bool routing_add_channel_update(struct routing_state *rstate,
if (!chan)
return false;
/* We broadcast announce once we have one update */
have_broadcast_announce = is_halfchan_defined(&chan->half[0])
|| is_halfchan_defined(&chan->half[1]);
direction = flags & 0x1;
set_connection_values(chan, direction, fee_base_msat,
fee_proportional_millionths, expiry,
@ -959,6 +962,13 @@ bool routing_add_channel_update(struct routing_state *rstate,
if (!chan->channel_announce)
return true;
/* BOLT #7:
* - MUST consider whether to send the `channel_announcement` after
* receiving the first corresponding `channel_update`.
*/
if (!have_broadcast_announce)
insert_broadcast(rstate->broadcasts, chan->channel_announce);
insert_broadcast(rstate->broadcasts,
chan->half[direction].channel_update);
return true;

1
tests/test_lightningd.py

@ -2642,7 +2642,6 @@ class LightningDTests(BaseLightningDTests):
for n in [l1, l2, l3]:
wait_for(lambda: len(n.rpc.listchannels()['channels']) == 4)
@unittest.expectedFailure
@unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1")
def test_gossip_no_empty_announcements(self):
# Need full IO logging so we can see gossip

Loading…
Cancel
Save