Skip to content

Commit 461947a

Browse files
committed
test_lightningd.py: fix obscure corner case in gossip.
I actually hit this very hard to reproduce race: if we haven't process the channeld message when block #6 comes in, we won't send the gossip message. We wait for logs, but don't generate new blocks, and timeout on l1.daemon.wait_for_log('peer_out WIRE_ANNOUNCEMENT_SIGNATURES'). The solution, which also tests that we don't send announcement signatures immediately, is to generate a single block, wait for CHANNELD_NORMAL, then (in gossip tests), generate 5 more. Signed-off-by: Rusty Russell <[email protected]>
1 parent 3404509 commit 461947a

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

lightningd/gossip/gossip.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,16 +612,19 @@ static struct io_plan *resolve_channel_req(struct io_conn *conn,
612612
status_failed(WIRE_GOSSIPSTATUS_BAD_REQUEST,
613613
"Unable to parse resolver request");
614614

615-
status_trace("Attempting to resolve channel %s",
616-
type_to_string(trc, struct short_channel_id, &scid));
617-
618615
nc = get_connection_by_scid(daemon->rstate, &scid, 0);
619616
if (!nc) {
617+
status_trace("Failed to resolve channel %s",
618+
type_to_string(trc, struct short_channel_id, &scid));
620619
keys = NULL;
621620
} else {
622621
keys = tal_arr(msg, struct pubkey, 2);
623622
keys[0] = nc->src->id;
624623
keys[1] = nc->dst->id;
624+
status_trace("Resolved channel %s %s<->%s",
625+
type_to_string(trc, struct short_channel_id, &scid),
626+
type_to_string(trc, struct pubkey, &keys[0]),
627+
type_to_string(trc, struct pubkey, &keys[1]));
625628
}
626629
daemon_conn_send(&daemon->master,
627630
take(towire_gossip_resolve_channel_reply(msg, keys)));

lightningd/peer_control.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,10 @@ static enum watch_result funding_announce_cb(struct peer *peer,
662662
return KEEP_WATCHING;
663663
}
664664
if (peer->state != CHANNELD_NORMAL || !peer->owner) {
665+
log_debug(peer->ld->log,
666+
"Funding tx announce ready, but peer state %s %s",
667+
peer_state_name(peer->state),
668+
peer->owner ? peer->owner->name : "unowned");
665669
return KEEP_WATCHING;
666670
}
667671
subd_send_msg(peer->owner,

tests/test_lightningd.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def fund_channel(self,l1,l2,amount):
183183
# Technically, this is async to fundchannel.
184184
l1.daemon.wait_for_log('sendrawtx exit 0')
185185

186-
l1.bitcoin.rpc.generate(6)
186+
l1.bitcoin.rpc.generate(1)
187187

188188
l1.daemon.wait_for_log('-> CHANNELD_NORMAL')
189189
l2.daemon.wait_for_log('-> CHANNELD_NORMAL')
@@ -307,6 +307,10 @@ def test_gossip_jsonrpc(self):
307307

308308
self.fund_channel(l1,l2,10**5)
309309

310+
# Shouldn't send announce signatures until 6 deep.
311+
assert not l1.daemon.is_in_log('peer_out WIRE_ANNOUNCEMENT_SIGNATURES')
312+
313+
l1.bitcoin.rpc.generate(5)
310314
l1.daemon.wait_for_log('peer_out WIRE_ANNOUNCEMENT_SIGNATURES')
311315
l1.daemon.wait_for_log('peer_in WIRE_ANNOUNCEMENT_SIGNATURES')
312316

@@ -366,6 +370,9 @@ def test_routing_gossip(self):
366370
src.rpc.connect('localhost', dst.info['port'], dst.info['id'])
367371
src.openchannel(dst, 20000)
368372

373+
# Allow announce messages.
374+
l1.bitcoin.rpc.generate(5)
375+
369376
def settle_gossip(n):
370377
"""Wait for gossip to settle at the node
371378
"""
@@ -407,6 +414,9 @@ def test_forward(self):
407414
self.fund_channel(l1, l2, 10**6)
408415
self.fund_channel(l2, l3, 10**6)
409416

417+
# Allow announce messages.
418+
l1.bitcoin.rpc.generate(5)
419+
410420
# If they're at different block heights we can get spurious errors.
411421
sync_blockheight(l1, l2, l3)
412422

0 commit comments

Comments
 (0)