mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-07 08:04:23 +01:00
df: reinitialize dual-funding
Prior to this, all reconnect logic lived in channeld. If you disconnected before we finished building a funding transaction, that was no big deal. Now, however, we're waiting for the funding to lock in in dualopend, instead of handing straight to channeld to wait. So we need a way to restart dualopend.
This commit is contained in:
committed by
Christian Decker
parent
1b6deaffc8
commit
9fdf1ea32a
@@ -1803,6 +1803,7 @@ static unsigned int dual_opend_msg(struct subd *dualopend,
|
||||
|
||||
/* Messages we send */
|
||||
case WIRE_DUALOPEND_INIT:
|
||||
case WIRE_DUALOPEND_REINIT:
|
||||
case WIRE_DUALOPEND_OPENER_INIT:
|
||||
case WIRE_DUALOPEND_GOT_OFFER_REPLY:
|
||||
case WIRE_DUALOPEND_FAIL:
|
||||
@@ -1863,6 +1864,85 @@ AUTODATA(json_command, &openchannel_update_command);
|
||||
AUTODATA(json_command, &openchannel_signed_command);
|
||||
#endif /* EXPERIMENTAL_FEATURES */
|
||||
|
||||
void peer_restart_dualopend(struct peer *peer,
|
||||
struct per_peer_state *pps,
|
||||
struct channel *channel,
|
||||
const u8 *send_msg)
|
||||
{
|
||||
u32 max_to_self_delay;
|
||||
struct amount_msat min_effective_htlc_capacity;
|
||||
struct channel_config unused_config;
|
||||
int hsmfd;
|
||||
u8 *msg;
|
||||
|
||||
hsmfd = hsm_get_client_fd(peer->ld, &peer->id, channel->dbid,
|
||||
HSM_CAP_COMMITMENT_POINT
|
||||
| HSM_CAP_SIGN_REMOTE_TX);
|
||||
|
||||
channel_set_owner(channel,
|
||||
new_channel_subd(peer->ld, "lightning_dualopend",
|
||||
channel, CHANNEL,
|
||||
&peer->id,
|
||||
channel->log, true,
|
||||
dualopend_wire_name,
|
||||
dual_opend_msg,
|
||||
channel_errmsg,
|
||||
channel_set_billboard,
|
||||
take(&pps->peer_fd),
|
||||
take(&pps->gossip_fd),
|
||||
take(&pps->gossip_store_fd),
|
||||
take(&hsmfd), NULL));
|
||||
if (!channel->owner) {
|
||||
log_broken(channel->log, "Could not subdaemon channel: %s",
|
||||
strerror(errno));
|
||||
channel_fail_reconnect_later(channel,
|
||||
"Failed to subdaemon channel");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Find the max self delay and min htlc capacity */
|
||||
channel_config(peer->ld, &unused_config,
|
||||
&max_to_self_delay,
|
||||
&min_effective_htlc_capacity);
|
||||
|
||||
msg = towire_dualopend_reinit(NULL,
|
||||
chainparams,
|
||||
peer->ld->our_features,
|
||||
peer->their_features,
|
||||
&channel->our_config,
|
||||
&channel->channel_info.their_config,
|
||||
&channel->cid,
|
||||
max_to_self_delay,
|
||||
min_effective_htlc_capacity,
|
||||
pps,
|
||||
&channel->local_basepoints,
|
||||
&channel->local_funding_pubkey,
|
||||
&channel->channel_info.remote_fundingkey,
|
||||
channel->minimum_depth,
|
||||
feerate_min(peer->ld, NULL),
|
||||
feerate_max(peer->ld, NULL),
|
||||
&channel->funding_txid,
|
||||
channel->funding_outnum,
|
||||
channel->funding,
|
||||
channel->our_msat,
|
||||
&channel->channel_info.theirbase,
|
||||
&channel->channel_info.remote_per_commit,
|
||||
channel->psbt,
|
||||
channel->opener,
|
||||
channel->scid != NULL,
|
||||
channel->remote_funding_locked,
|
||||
channel->state == CHANNELD_SHUTTING_DOWN,
|
||||
channel->shutdown_scriptpubkey[REMOTE] != NULL,
|
||||
channel->shutdown_scriptpubkey[LOCAL],
|
||||
channel->remote_upfront_shutdown_script,
|
||||
channel->remote_tx_sigs,
|
||||
channel->fee_states,
|
||||
send_msg);
|
||||
|
||||
|
||||
subd_send_msg(channel->owner, take(msg));
|
||||
}
|
||||
|
||||
void peer_start_dualopend(struct peer *peer,
|
||||
struct per_peer_state *pps,
|
||||
const u8 *send_msg)
|
||||
|
||||
@@ -10,6 +10,11 @@ void peer_start_dualopend(struct peer *peer,
|
||||
struct per_peer_state *pps,
|
||||
const u8 *send_msg);
|
||||
|
||||
void peer_restart_dualopend(struct peer *peer,
|
||||
struct per_peer_state *pps,
|
||||
struct channel *channel,
|
||||
const u8 *send_msg);
|
||||
|
||||
void dualopen_tell_depth(struct subd *dualopend,
|
||||
struct channel *channel,
|
||||
u32 depth);
|
||||
|
||||
@@ -1024,9 +1024,18 @@ peer_connected_hook_cb(struct peer_connected_hook_payload *payload STEALS,
|
||||
}
|
||||
case DUALOPEND_OPEN_INIT:
|
||||
case DUALOPEND_AWAITING_LOCKIN:
|
||||
/* FIXME: open dualopend */
|
||||
abort();
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
assert(!channel->owner);
|
||||
|
||||
channel->peer->addr = addr;
|
||||
peer_restart_dualopend(peer, payload->pps,
|
||||
channel, NULL);
|
||||
|
||||
tal_free(payload);
|
||||
return;
|
||||
#else
|
||||
abort();
|
||||
#endif /* EXPERIMENTAL_FEATURES */
|
||||
case CHANNELD_AWAITING_LOCKIN:
|
||||
case CHANNELD_NORMAL:
|
||||
case CHANNELD_SHUTTING_DOWN:
|
||||
@@ -1060,7 +1069,18 @@ send_error:
|
||||
if (feature_negotiated(ld->our_features,
|
||||
peer->their_features,
|
||||
OPT_DUAL_FUND)) {
|
||||
peer_start_dualopend(peer, payload->pps, error);
|
||||
/* if we have a channel, we're actually restarting
|
||||
* dualopend. we only get here if there's an error */
|
||||
if (channel) {
|
||||
assert(!channel->owner);
|
||||
|
||||
assert(channel->state == DUALOPEND_OPEN_INIT
|
||||
|| channel->state == DUALOPEND_AWAITING_LOCKIN);
|
||||
channel->peer->addr = addr;
|
||||
peer_restart_dualopend(peer, payload->pps,
|
||||
channel, error);
|
||||
} else
|
||||
peer_start_dualopend(peer, payload->pps, error);
|
||||
} else
|
||||
#endif /* EXPERIMENTAL_FEATURES */
|
||||
peer_start_openingd(peer, payload->pps, error);
|
||||
|
||||
@@ -501,6 +501,12 @@ void peer_memleak_done(struct command *cmd UNNEEDED, struct subd *leaker UNNEEDE
|
||||
/* Generated stub for peer_normal_channel */
|
||||
struct channel *peer_normal_channel(struct peer *peer UNNEEDED)
|
||||
{ fprintf(stderr, "peer_normal_channel called!\n"); abort(); }
|
||||
/* Generated stub for peer_restart_dualopend */
|
||||
void peer_restart_dualopend(struct peer *peer UNNEEDED,
|
||||
struct per_peer_state *pps UNNEEDED,
|
||||
struct channel *channel UNNEEDED,
|
||||
const u8 *send_msg UNNEEDED)
|
||||
{ fprintf(stderr, "peer_restart_dualopend called!\n"); abort(); }
|
||||
/* Generated stub for peer_start_channeld */
|
||||
void peer_start_channeld(struct channel *channel UNNEEDED,
|
||||
struct per_peer_state *pps UNNEEDED,
|
||||
|
||||
Reference in New Issue
Block a user