diff --git a/gossipd/routing.c b/gossipd/routing.c index f86344c74..74392bad2 100644 --- a/gossipd/routing.c +++ b/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, ×tamp, &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; diff --git a/tests/test_lightningd.py b/tests/test_lightningd.py index 8b55b1287..1717b93a6 100644 --- a/tests/test_lightningd.py +++ b/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