From a5c65e2c9b4f215a161de671d5b11f1fb519782e Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 3 Jan 2018 15:56:44 +1030 Subject: [PATCH] lightningd: reactivate peers. This is surprisingly simple. We set up the watches for funding tx depth and the funding output, then if it's not onchain we ask gossipd to reconnect. Signed-off-by: Rusty Russell --- lightningd/peer_control.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 5da5fee2c..51930333e 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -2718,23 +2718,23 @@ static void activate_peer(struct peer *peer) { assert(!peer->owner); - switch (peer->state) { - case UNINITIALIZED: - abort(); - - case OPENINGD: - case CHANNELD_AWAITING_LOCKIN: - case CHANNELD_NORMAL: - case CHANNELD_SHUTTING_DOWN: - case CLOSINGD_SIGEXCHANGE: - case CLOSINGD_COMPLETE: - case FUNDING_SPEND_SEEN: - case ONCHAIND_CHEATED: - case ONCHAIND_THEIR_UNILATERAL: - case ONCHAIND_OUR_UNILATERAL: - case ONCHAIND_MUTUAL: - log_broken(peer->log, "FIXME: Implement activate_peer(%s)", + /* FIXME: We should never have these in the database! */ + if (!peer->funding_txid) { + log_broken(peer->log, "activate_peer(%s) with no funding txid?", peer_state_name(peer->state)); + return; + } + + /* This may be unnecessary, but it's harmless. */ + watch_txid(peer, peer->ld->topology, peer, peer->funding_txid, + funding_lockin_cb, NULL); + + watch_txo(peer, peer->ld->topology, peer, peer->funding_txid, peer->funding_outnum, + funding_spent, NULL); + + if (peer_wants_reconnect(peer)) { + u8 *msg = towire_gossipctl_reach_peer(peer, &peer->id); + subd_send_msg(peer->ld->gossip, take(msg)); } }