Skip to content

Commit

Permalink
splice: signer must be informed of splice params
Browse files Browse the repository at this point in the history
The signer needs to know when the splice operation starts and the
splice parameters for each splice transaction candidate.

The channel establishment v2 (dual funding) code path already
notifies the signer via the hsmd API hsmd_ready_channel calls
However, the splicing code path does not.

Link: ElementsProject#6723
Suggested-by: @devrandom
Co-Developed-by: Ken Sedgwick <[email protected]>
Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
ksedgwic authored and vincenzopalazzo committed Sep 29, 2023
1 parent 77e3c3a commit 7b76ddf
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -3441,6 +3441,42 @@ static struct inflight *inflights_new(struct peer *peer)
return inf;
}

static void update_hsmd_with_splice(struct peer *peer, struct inflight *inflight)
{
u8 *msg;
struct amount_msat push_value;
/* These aren't allowed to change, so we
* don't need to gather them */
u8 *local_upfront_shutdown_script = NULL;
u8 *remote_upfront_shutdown_script = NULL;
u32 *local_upfront_shutdown_wallet_index = NULL;

// FIXME: handle the error
assert(amount_sat_to_msat(&push_value, inflight->amnt));

This comment has been minimized.

Copy link
@ksedgwic

ksedgwic Sep 29, 2023

Author

I'm not sure this is the right amount value for push_value. devrandom suggested:
lightning-signer#95 (comment)


msg = towire_hsmd_ready_channel(
NULL,
peer->channel->opener == LOCAL,
inflight->amnt,
push_value,
&inflight->outpoint.txid,
inflight->outpoint.n,
peer->channel->config[LOCAL].to_self_delay,
local_upfront_shutdown_script,
local_upfront_shutdown_wallet_index,
&peer->channel->basepoints[REMOTE],
&peer->channel->funding_pubkey[REMOTE],
peer->channel->config[REMOTE].to_self_delay,
remote_upfront_shutdown_script,
peer->channel->type);

wire_sync_write(HSM_FD, take(msg));
msg = wire_sync_read(tmpctx, HSM_FD);

This comment has been minimized.

Copy link
@vincenzopalazzo

vincenzopalazzo Sep 29, 2023

Owner

I changed this from your previous code, I do not know if there was any reason to sue hsm_req(tmpctx, take(msg))

This comment has been minimized.

Copy link
@ksedgwic

ksedgwic Sep 29, 2023

Author

I've noticed that there are several different ways to do this, I usually mimic whichever technique is prevalent in the file that I'm in. channeld.c seems to use hsm_req ... not sure which version is the best ...

if (!fromwire_hsmd_ready_channel_reply(msg))
status_failed(STATUS_FAIL_HSM_IO, "Bad ready_channel_reply %s",
tal_hex(tmpctx, msg));
}

/* ACCEPTER side of the splice. Here we handle all the accepter's steps for the
* splice. Since the channel must be in STFU mode we block the daemon here until
* the splice is finished or aborted. */
Expand Down Expand Up @@ -3577,6 +3613,8 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
new_inflight->last_tx = NULL;
new_inflight->i_am_initiator = false;

update_hsmd_with_splice(peer, new_inflight);

update_view_from_inflights(peer);

peer->splice_state->count++;
Expand Down Expand Up @@ -3811,6 +3849,8 @@ static void splice_initiator_user_finalized(struct peer *peer)
new_inflight->last_tx = NULL;
new_inflight->i_am_initiator = true;

update_hsmd_with_splice(peer, new_inflight);

update_view_from_inflights(peer);

peer->splice_state->count++;
Expand Down Expand Up @@ -5160,8 +5200,7 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)

if (depth < peer->channel->minimum_depth) {
peer->depth_togo = peer->channel->minimum_depth - depth;
}
else {
} else {
peer->depth_togo = 0;

/* For splicing we only update the short channel id on mutual
Expand Down Expand Up @@ -5206,8 +5245,7 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)
peer_write(peer->pps, take(msg));

peer->channel_ready[LOCAL] = true;
}
else if(splicing && !peer->splice_state->locked_ready[LOCAL]) {
} else if(splicing && !peer->splice_state->locked_ready[LOCAL]) {
assert(scid);

msg = towire_splice_locked(NULL, &peer->channel_id);
Expand Down

1 comment on commit 7b76ddf

@ksedgwic
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise looks good

Please sign in to comment.