@@ -770,17 +770,39 @@ static struct io_plan *handle_sign_commitment_tx(struct io_conn *conn,
770
770
if (tx -> wtx -> num_outputs == 0 )
771
771
return bad_req_fmt (conn , c , msg_in , "tx must have > 0 outputs" );
772
772
773
- proxy_stat rv = proxy_handle_sign_commitment_tx (
774
- tx , & remote_funding_pubkey , & peer_id , dbid ,
775
- rhashes , commit_num , & sig );
776
- if (PROXY_PERMANENT (rv ))
777
- status_failed (STATUS_FAIL_INTERNAL_ERROR ,
778
- "proxy_%s failed: %s" , __FUNCTION__ ,
779
- proxy_last_message ());
780
- else if (!PROXY_SUCCESS (rv ))
781
- return bad_req_fmt (conn , c , msg_in ,
782
- "proxy_%s error: %s" , __FUNCTION__ ,
783
- proxy_last_message ());
773
+ // WORKAROUND - sometimes c-lightning calls handle_sign_commitment_tx
774
+ // with mutual close transactions. We can tell the difference because
775
+ // the locktime field will be set to 0 for a mutual close.
776
+ if (tx -> wtx -> locktime == 0 ) {
777
+ // This is really a mutual close.
778
+ fprintf (stderr ,
779
+ "handle_sign_commitment_tx called with locktime==0; "
780
+ "dispatching to proxy_handle_sign_mutual_close_tx instead\n" );
781
+ proxy_stat rv = proxy_handle_sign_mutual_close_tx (
782
+ tx , & remote_funding_pubkey , & peer_id , dbid , & sig );
783
+ if (PROXY_PERMANENT (rv ))
784
+ status_failed (STATUS_FAIL_INTERNAL_ERROR ,
785
+ "proxy_%s failed: %s" , __FUNCTION__ ,
786
+ proxy_last_message ());
787
+ else if (!PROXY_SUCCESS (rv ))
788
+ return bad_req_fmt (conn , c , msg_in ,
789
+ "proxy_%s error: %s" , __FUNCTION__ ,
790
+ proxy_last_message ());
791
+
792
+ } else {
793
+ // This is a unilateral close from our side.
794
+ proxy_stat rv = proxy_handle_sign_commitment_tx (
795
+ tx , & remote_funding_pubkey , & peer_id , dbid ,
796
+ rhashes , commit_num , & sig );
797
+ if (PROXY_PERMANENT (rv ))
798
+ status_failed (STATUS_FAIL_INTERNAL_ERROR ,
799
+ "proxy_%s failed: %s" , __FUNCTION__ ,
800
+ proxy_last_message ());
801
+ else if (!PROXY_SUCCESS (rv ))
802
+ return bad_req_fmt (conn , c , msg_in ,
803
+ "proxy_%s error: %s" , __FUNCTION__ ,
804
+ proxy_last_message ());
805
+ }
784
806
785
807
return req_reply (conn , c ,
786
808
take (towire_hsmd_sign_commitment_tx_reply (NULL , & sig )));
0 commit comments