Skip to content

Commit

Permalink
gossipd: Add a new msgtype so that we can tell master that we've foun…
Browse files Browse the repository at this point in the history
…d our ownchannel through gossip, this would be used to publish a notification to the recovery plugin so that we can reconnect to that particular peer and see if they have our peer_storage.
  • Loading branch information
adi2011 committed Nov 13, 2023
1 parent b71532b commit 89cb877
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
9 changes: 8 additions & 1 deletion gossipd/gossipd.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,15 @@ static const u8 *handle_channel_announcement_msg(struct daemon *daemon,
{
const struct short_channel_id *scid;
const u8 *err;
bool our_channel;

/* If it's OK, tells us the short_channel_id to lookup; it notes
* if this is the unknown channel the peer was looking for (in
* which case, it frees and NULLs that ptr) */
err = handle_channel_announcement(daemon->rstate, msg,
daemon->current_blockheight,
&scid, source_peer);
&scid, source_peer, &our_channel,
&daemon->id);
if (err)
return err;
else if (scid) {
Expand All @@ -269,6 +271,10 @@ static const u8 *handle_channel_announcement_msg(struct daemon *daemon,
daemon_conn_send(daemon->master,
take(towire_gossipd_get_txout(NULL,
scid)));

/* TODO: Send to master that we've found a channel which is ours */
// daemon_conn_send(daemon->master,
// );
}
}
return NULL;
Expand Down Expand Up @@ -1206,6 +1212,7 @@ static struct io_plan *recv_req(struct io_conn *conn,
case WIRE_GOSSIPD_NEW_BLOCKHEIGHT_REPLY:
case WIRE_GOSSIPD_GET_ADDRS_REPLY:
case WIRE_GOSSIPD_GOT_LOCAL_CHANNEL_UPDATE:
case WIRE_GOSSIPD_DISCOVERED_CHANNEL:
break;
}

Expand Down
5 changes: 5 additions & 0 deletions gossipd/gossipd_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ msgdata,gossipd_local_channel_close,short_channel_id,short_channel_id,
msgtype,gossipd_get_txout,3018
msgdata,gossipd_get_txout,short_channel_id,short_channel_id,

#Gossipd->master we've found our channel through gossip
msgtype,gossipd_discovered_channel,3019
msgdata,gossipd_discovered_channel,peer_id,node_id,
msgdata,gossipd_discovered_channel,short_channel_id,short_channel_id,

# master->gossipd here is the output, or empty if none.
msgtype,gossipd_get_txout_reply,3118
msgdata,gossipd_get_txout_reply,short_channel_id,short_channel_id,
Expand Down
10 changes: 9 additions & 1 deletion gossipd/routing.c
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,9 @@ u8 *handle_channel_announcement(struct routing_state *rstate,
const u8 *announce TAKES,
u32 current_blockheight,
const struct short_channel_id **scid,
const struct node_id *source_peer TAKES)
const struct node_id *source_peer TAKES,
bool *our_channel,
const struct node_id *local_node_id)
{
struct pending_cannouncement *pending;
struct bitcoin_blkid chain_hash;
Expand Down Expand Up @@ -1052,6 +1054,12 @@ u8 *handle_channel_announcement(struct routing_state *rstate,

/* We don't use features */
tal_free(features);
*our_channel = false;

if (node_id_cmp(&pending->node_id_1, local_node_id) == 0 ||
node_id_cmp(&pending->node_id_2, local_node_id) == 0) {
*our_channel = true;
}

/* If we know the blockheight, and it's in the future, reject
* out-of-hand. Remember, it should be 6 deep before they tell us
Expand Down
5 changes: 4 additions & 1 deletion gossipd/routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,15 @@ struct chan *new_chan(struct routing_state *rstate,
*
* Returns error message if we should fail channel. Make *scid non-NULL
* (for checking) if we extracted a short_channel_id, otherwise ignore.
* Makes our_channel `true` if one of the endpoint is local_node_id.
*/
u8 *handle_channel_announcement(struct routing_state *rstate,
const u8 *announce TAKES,
u32 current_blockheight,
const struct short_channel_id **scid,
const struct node_id *source_peer TAKES);
const struct node_id *source_peer TAKES,
bool *our_channel,
const struct node_id *local_node_id);

/**
* handle_pending_cannouncement -- handle channel_announce once we've
Expand Down
9 changes: 9 additions & 0 deletions lightningd/gossip_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ static void handle_local_channel_update(struct lightningd *ld, const u8 *msg)
channel_replace_update(channel, take(update));
}

static void handle_discovered_channel(struct lightningd *ld, const u8 *msg)
{
// Publish a notification from here to the plugins!
return;
}

const u8 *get_channel_update(struct channel *channel)
{
/* Tell gossipd we're using it (if shutting down, might be NULL) */
Expand Down Expand Up @@ -213,6 +219,9 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
case WIRE_GOSSIPD_GOT_LOCAL_CHANNEL_UPDATE:
handle_local_channel_update(gossip->ld, msg);
break;
case WIRE_GOSSIPD_DISCOVERED_CHANNEL:
handle_discovered_channel(gossip->ld, msg);
break;
}
return 0;
}
Expand Down

0 comments on commit 89cb877

Please sign in to comment.