Skip to content

Commit bbfe29c

Browse files
committed
splice: Add call to hsmd_{check,lock}_outpoint on mutual channel_ready
1 parent 324268f commit bbfe29c

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

channeld/channeld.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,44 @@ static bool channel_announcement_negotiate(struct peer *peer)
681681
return sent_announcement;
682682
}
683683

684+
static void lock_signer_outpoint(const struct bitcoin_outpoint *outpoint) {
685+
const u8 *msg;
686+
bool is_buried = false;
687+
688+
do {
689+
/* Make sure the hsmd agrees that this outpoint is
690+
* sufficiently buried. */
691+
msg = towire_hsmd_check_outpoint(NULL, &outpoint->txid, outpoint->n);
692+
msg = hsm_req(tmpctx, take(msg));
693+
if (!fromwire_hsmd_check_outpoint_reply(msg, &is_buried))
694+
status_failed(STATUS_FAIL_HSM_IO,
695+
"Bad hsmd_check_outpoint_reply: %s",
696+
tal_hex(tmpctx, msg));
697+
698+
/* the signer should have a shorter buried height requirement so
699+
* it almost always will be ready ahead of us.*/
700+
if (!is_buried) {
701+
sleep(10);
702+
}
703+
} while (!is_buried);
704+
705+
/* tell the signer that we are now locked */
706+
msg = towire_hsmd_lock_outpoint(NULL, &outpoint->txid, outpoint->n);
707+
msg = hsm_req(tmpctx, take(msg));
708+
if (!fromwire_hsmd_lock_outpoint_reply(msg))
709+
status_failed(STATUS_FAIL_HSM_IO,
710+
"Bad hsmd_lock_outpoint_reply: %s",
711+
tal_hex(tmpctx, msg));
712+
}
713+
714+
/* Call this method when channel_ready status are changed. */
715+
static void check_mutual_channel_ready(const struct peer *peer)
716+
{
717+
if (peer->channel_ready[LOCAL] && peer->channel_ready[REMOTE]) {
718+
lock_signer_outpoint(&peer->channel->funding);
719+
}
720+
}
721+
684722
/* Call this method when splice_locked status are changed. If both sides have
685723
* splice_locked'ed than this function consumes the `splice_locked_ready` values
686724
* 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)
831869

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

52305269
peer->channel_ready[LOCAL] = true;
5270+
check_mutual_channel_ready(peer);
52315271
}
52325272
else if(splicing && !peer->splice_state->locked_ready[LOCAL]) {
52335273
assert(scid);

openingd/dualopend.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,46 @@ static void billboard_update(struct state *state)
424424
peer_billboard(false, update);
425425
}
426426

427+
static void lock_signer_outpoint(const struct bitcoin_outpoint *outpoint) {
428+
const u8 *msg;
429+
bool is_buried = false;
430+
431+
do {
432+
/* Make sure the hsmd agrees that this outpoint is
433+
* sufficiently buried. */
434+
msg = towire_hsmd_check_outpoint(NULL, &outpoint->txid, outpoint->n);
435+
wire_sync_write(HSM_FD, take(msg));
436+
msg = wire_sync_read(tmpctx, HSM_FD);
437+
if (!fromwire_hsmd_check_outpoint_reply(msg, &is_buried))
438+
status_failed(STATUS_FAIL_HSM_IO,
439+
"Bad hsmd_check_outpoint_reply: %s",
440+
tal_hex(tmpctx, msg));
441+
442+
/* the signer should have a shorter buried height requirement so
443+
* it almost always will be ready ahead of us.*/
444+
if (!is_buried) {
445+
sleep(10);
446+
}
447+
} while (!is_buried);
448+
449+
/* tell the signer that we are now locked */
450+
msg = towire_hsmd_lock_outpoint(NULL, &outpoint->txid, outpoint->n);
451+
wire_sync_write(HSM_FD, take(msg));
452+
msg = wire_sync_read(tmpctx, HSM_FD);
453+
if (!fromwire_hsmd_lock_outpoint_reply(msg))
454+
status_failed(STATUS_FAIL_HSM_IO,
455+
"Bad hsmd_lock_outpoint_reply: %s",
456+
tal_hex(tmpctx, msg));
457+
}
458+
459+
/* Call this method when channel_ready status are changed. */
460+
static void check_mutual_channel_ready(const struct state *state)
461+
{
462+
if (state->channel_ready[LOCAL] && state->channel_ready[REMOTE]) {
463+
lock_signer_outpoint(&state->channel->funding);
464+
}
465+
}
466+
427467
static void send_shutdown(struct state *state, const u8 *final_scriptpubkey)
428468
{
429469
u8 *msg;
@@ -1273,6 +1313,7 @@ static u8 *handle_channel_ready(struct state *state, u8 *msg)
12731313
}
12741314

12751315
state->channel_ready[REMOTE] = true;
1316+
check_mutual_channel_ready(state);
12761317
billboard_update(state);
12771318

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

38263867
state->channel_ready[LOCAL] = true;
3868+
check_mutual_channel_ready(state);
38273869
billboard_update(state);
38283870
}
38293871

0 commit comments

Comments
 (0)