Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Splicing support #95

Draft
wants to merge 13 commits into
base: 2023-08-remote-hsmd-v23.08
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
splice: Add call to hsmd_{check,lock}_outpoint on mutual channel_ready
ksedgwic committed Oct 6, 2023

Verified

This commit was signed with the committer’s verified signature.
WengerK Kevin Wenger
commit 9064b140ceefaf28b4c632139cd6d642780168ae
40 changes: 40 additions & 0 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
@@ -681,6 +681,44 @@ static bool channel_announcement_negotiate(struct peer *peer)
return sent_announcement;
}

static void lock_signer_outpoint(const struct bitcoin_outpoint *outpoint) {
const u8 *msg;
bool is_buried = false;

do {
/* Make sure the hsmd agrees that this outpoint is
* sufficiently buried. */
msg = towire_hsmd_check_outpoint(NULL, &outpoint->txid, outpoint->n);
msg = hsm_req(tmpctx, take(msg));
if (!fromwire_hsmd_check_outpoint_reply(msg, &is_buried))
status_failed(STATUS_FAIL_HSM_IO,
"Bad hsmd_check_outpoint_reply: %s",
tal_hex(tmpctx, msg));

/* the signer should have a shorter buried height requirement so
* it almost always will be ready ahead of us.*/
if (!is_buried) {
sleep(10);
}
} while (!is_buried);

/* tell the signer that we are now locked */
msg = towire_hsmd_lock_outpoint(NULL, &outpoint->txid, outpoint->n);
msg = hsm_req(tmpctx, take(msg));
if (!fromwire_hsmd_lock_outpoint_reply(msg))
status_failed(STATUS_FAIL_HSM_IO,
"Bad hsmd_lock_outpoint_reply: %s",
tal_hex(tmpctx, msg));
}

/* Call this method when channel_ready status are changed. */
static void check_mutual_channel_ready(const struct peer *peer)
{
if (peer->channel_ready[LOCAL] && peer->channel_ready[REMOTE]) {
lock_signer_outpoint(&peer->channel->funding);
}
}

/* Call this method when splice_locked status are changed. If both sides have
* splice_locked'ed than this function consumes the `splice_locked_ready` values
* and considers the channel funding to be switched to the splice tx. */
@@ -831,6 +869,7 @@ static void handle_peer_channel_ready(struct peer *peer, const u8 *msg)

peer->tx_sigs_allowed = false;
peer->channel_ready[REMOTE] = true;
check_mutual_channel_ready(peer);
if (tlvs->short_channel_id != NULL) {
status_debug(
"Peer told us that they'll use alias=%s for this channel",
@@ -5252,6 +5291,7 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)
peer_write(peer->pps, take(msg));

peer->channel_ready[LOCAL] = true;
check_mutual_channel_ready(peer);
}
else if(splicing && !peer->splice_state->locked_ready[LOCAL]) {
assert(scid);
6 changes: 4 additions & 2 deletions lightningd/dual_open_control.c
Original file line number Diff line number Diff line change
@@ -3698,7 +3698,8 @@ bool peer_start_dualopend(struct peer *peer,
hsmfd = hsm_get_client_fd(peer->ld, &peer->id, channel->unsaved_dbid,
HSM_PERM_COMMITMENT_POINT
| HSM_PERM_SIGN_REMOTE_TX
| HSM_PERM_SIGN_WILL_FUND_OFFER);
| HSM_PERM_SIGN_WILL_FUND_OFFER
| HSM_PERM_LOCK_OUTPOINT);

channel->owner = new_channel_subd(channel,
peer->ld,
@@ -3770,7 +3771,8 @@ bool peer_restart_dualopend(struct peer *peer,
hsmfd = hsm_get_client_fd(peer->ld, &peer->id, channel->dbid,
HSM_PERM_COMMITMENT_POINT
| HSM_PERM_SIGN_REMOTE_TX
| HSM_PERM_SIGN_WILL_FUND_OFFER);
| HSM_PERM_SIGN_WILL_FUND_OFFER
| HSM_PERM_LOCK_OUTPOINT);

channel_set_owner(channel,
new_channel_subd(channel, peer->ld,
42 changes: 42 additions & 0 deletions openingd/dualopend.c
Original file line number Diff line number Diff line change
@@ -424,6 +424,46 @@ static void billboard_update(struct state *state)
peer_billboard(false, update);
}

static void lock_signer_outpoint(const struct bitcoin_outpoint *outpoint) {
const u8 *msg;
bool is_buried = false;

do {
/* Make sure the hsmd agrees that this outpoint is
* sufficiently buried. */
msg = towire_hsmd_check_outpoint(NULL, &outpoint->txid, outpoint->n);
wire_sync_write(HSM_FD, take(msg));
msg = wire_sync_read(tmpctx, HSM_FD);
if (!fromwire_hsmd_check_outpoint_reply(msg, &is_buried))
status_failed(STATUS_FAIL_HSM_IO,
"Bad hsmd_check_outpoint_reply: %s",
tal_hex(tmpctx, msg));

/* the signer should have a shorter buried height requirement so
* it almost always will be ready ahead of us.*/
if (!is_buried) {
sleep(10);
}
} while (!is_buried);

/* tell the signer that we are now locked */
msg = towire_hsmd_lock_outpoint(NULL, &outpoint->txid, outpoint->n);
wire_sync_write(HSM_FD, take(msg));
msg = wire_sync_read(tmpctx, HSM_FD);
if (!fromwire_hsmd_lock_outpoint_reply(msg))
status_failed(STATUS_FAIL_HSM_IO,
"Bad hsmd_lock_outpoint_reply: %s",
tal_hex(tmpctx, msg));
}

/* Call this method when channel_ready status are changed. */
static void check_mutual_channel_ready(const struct state *state)
{
if (state->channel_ready[LOCAL] && state->channel_ready[REMOTE]) {
lock_signer_outpoint(&state->channel->funding);
}
}

static void send_shutdown(struct state *state, const u8 *final_scriptpubkey)
{
u8 *msg;
@@ -1273,6 +1313,7 @@ static u8 *handle_channel_ready(struct state *state, u8 *msg)
}

state->channel_ready[REMOTE] = true;
check_mutual_channel_ready(state);
billboard_update(state);

if (state->channel_ready[LOCAL])
@@ -3824,6 +3865,7 @@ static void send_channel_ready(struct state *state)
peer_write(state->pps, take(msg));

state->channel_ready[LOCAL] = true;
check_mutual_channel_ready(state);
billboard_update(state);
}