dualopend: tell lightningd about new channel as soon as it's locked in.

Once we send funding_locked, gossipd could start seeing channel_updates
from the peer (which get sent so we can use the channel in routehints
even before it's announcable).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-01-25 06:35:52 +10:30
parent 88a4502a51
commit 4dc72dd829
3 changed files with 64 additions and 1 deletions

View File

@ -22,6 +22,7 @@
#include <lightningd/channel_control.h>
#include <lightningd/closing_control.h>
#include <lightningd/dual_open_control.h>
#include <lightningd/gossip_control.h>
#include <lightningd/hsm_control.h>
#include <lightningd/json.h>
#include <lightningd/notification.h>
@ -1368,6 +1369,24 @@ static void handle_channel_closed(struct subd *dualopend,
"Start closingd");
}
static void handle_local_private_channel(struct subd *dualopend,
const u8 *msg)
{
struct amount_sat capacity;
u8 *features;
if (!fromwire_dualopend_local_private_channel(msg, msg, &capacity,
&features)) {
channel_internal_error(dualopend->channel,
"bad dualopend_local_private_channel %s",
tal_hex(msg, msg));
return;
}
tell_gossipd_local_private_channel(dualopend->ld, dualopend->channel,
capacity, features);
}
struct channel_send {
const struct wally_tx *wtx;
struct channel *channel;
@ -2991,7 +3010,9 @@ static unsigned int dual_opend_msg(struct subd *dualopend,
case WIRE_DUALOPEND_FAIL_FALLEN_BEHIND:
channel_fail_fallen_behind(dualopend, msg);
return 0;
case WIRE_DUALOPEND_LOCAL_PRIVATE_CHANNEL:
handle_local_private_channel(dualopend, msg);
return 0;
/* Messages we send */
case WIRE_DUALOPEND_INIT:
case WIRE_DUALOPEND_REINIT:

View File

@ -3396,6 +3396,38 @@ static void send_funding_locked(struct state *state)
billboard_update(state);
}
/* FIXME: Maybe cache this? */
static struct amount_sat channel_size(struct state *state)
{
u32 funding_outnum;
const u8 *funding_wscript =
bitcoin_redeem_2of2(tmpctx,
&state->our_funding_pubkey,
&state->their_funding_pubkey);
if (!find_txout(state->tx_state->psbt,
scriptpubkey_p2wsh(tmpctx, funding_wscript),
&funding_outnum)) {
open_err_fatal(state, "Cannot fund txout");
}
return psbt_output_get_amount(state->tx_state->psbt, funding_outnum);
}
static void tell_gossipd_new_channel(struct state *state)
{
u8 *msg;
const u8 *annfeatures = get_agreed_channelfeatures(tmpctx,
state->our_features,
state->their_features);
/* Tell lightningd about local channel. */
msg = towire_dualopend_local_private_channel(NULL,
channel_size(state),
annfeatures);
wire_sync_write(REQ_FD, take(msg));
}
static u8 *handle_funding_depth(struct state *state, u8 *msg)
{
u32 depth;
@ -3410,6 +3442,9 @@ static u8 *handle_funding_depth(struct state *state, u8 *msg)
/* We check this before we arrive here, but for sanity */
assert(state->minimum_depth <= depth);
/* Tell gossipd the new channel exists before we tell peer. */
tell_gossipd_new_channel(state);
send_funding_locked(state);
if (state->funding_locked[REMOTE])
return towire_dualopend_channel_locked(state);
@ -3665,6 +3700,7 @@ static u8 *handle_master_in(struct state *state)
case WIRE_DUALOPEND_FAIL_FALLEN_BEHIND:
case WIRE_DUALOPEND_DRY_RUN:
case WIRE_DUALOPEND_VALIDATE_LEASE:
case WIRE_DUALOPEND_LOCAL_PRIVATE_CHANNEL:
break;
}

View File

@ -238,3 +238,9 @@ msgdata,dualopend_validate_lease,their_pubkey,pubkey,
msgtype,dualopend_validate_lease_reply,7127
msgdata,dualopend_validate_lease_reply,err_msg,?wirestring,
# Tell gossipd about this (as-yet) unannounced channel
msgtype,dualopend_local_private_channel,7015
msgdata,dualopend_local_private_channel,capacity,amount_sat,
msgdata,dualopend_local_private_channel,len,u16,
msgdata,dualopend_local_private_channel,features,u8,len

Can't render this file because it has a wrong number of fields in line 14.