mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-18 22:54:25 +01:00
gossipd: have master explicitly tell us when peer is disconnected.
Currently we intuit it from the fd being closed, but that may happen out of order with when the master thinks it's dead. So now if the gossip fd closes we just ignore it, and we'll get a notification from the master when the peer is disconnected. The notification is slightly ugly in that we have to disable it for a channel when we manually hand the channel back to gossipd. Note: as stands, this is racy with reconnects. See the next patch. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -12,13 +12,26 @@
|
||||
#include <lightningd/peer_control.h>
|
||||
#include <lightningd/subd.h>
|
||||
|
||||
static bool connects_to_peer(struct subd *owner)
|
||||
{
|
||||
return owner && owner->talks_to_peer;
|
||||
}
|
||||
|
||||
void channel_set_owner(struct channel *channel, struct subd *owner)
|
||||
{
|
||||
struct subd *old_owner = channel->owner;
|
||||
channel->owner = owner;
|
||||
|
||||
if (old_owner)
|
||||
if (old_owner) {
|
||||
subd_release_channel(old_owner, channel);
|
||||
if (channel->connected && !connects_to_peer(owner)) {
|
||||
u8 *msg = towire_gossipctl_peer_disconnected(NULL,
|
||||
&channel->peer->id);
|
||||
subd_send_msg(channel->peer->ld->gossip, take(msg));
|
||||
channel->connected = false;
|
||||
}
|
||||
}
|
||||
channel->connected = connects_to_peer(owner);
|
||||
}
|
||||
|
||||
struct htlc_out *channel_has_htlc_out(struct channel *channel)
|
||||
@@ -155,7 +168,8 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
||||
struct changed_htlc *last_sent_commit,
|
||||
u32 first_blocknum,
|
||||
u32 min_possible_feerate,
|
||||
u32 max_possible_feerate)
|
||||
u32 max_possible_feerate,
|
||||
bool connected)
|
||||
{
|
||||
struct channel *channel = tal(peer->ld, struct channel);
|
||||
|
||||
@@ -212,6 +226,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
||||
channel->first_blocknum = first_blocknum;
|
||||
channel->min_possible_feerate = min_possible_feerate;
|
||||
channel->max_possible_feerate = max_possible_feerate;
|
||||
channel->connected = connected;
|
||||
derive_channel_seed(peer->ld, &channel->seed, &peer->id, channel->dbid);
|
||||
|
||||
list_add_tail(&peer->channels, &channel->list);
|
||||
|
||||
Reference in New Issue
Block a user