@@ -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 );
0 commit comments