Skip to content

Commit ec6b161

Browse files
committed
added workaround to dispatch calls to handle_sign_commitment_tx to handle_sign_mutual_close_tx if appropriate
1 parent 48ed900 commit ec6b161

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

contrib/remote_hsmd/hsmd.c

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -770,17 +770,39 @@ static struct io_plan *handle_sign_commitment_tx(struct io_conn *conn,
770770
if (tx->wtx->num_outputs == 0)
771771
return bad_req_fmt(conn, c, msg_in, "tx must have > 0 outputs");
772772

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+
}
784806

785807
return req_reply(conn, c,
786808
take(towire_hsmd_sign_commitment_tx_reply(NULL, &sig)));

contrib/remote_hsmd/scripts/run-one-test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ SUBDAEMON='hsmd:remote_hsmd' \
1414
REMOTE_SIGNER_CMD=$(pwd)/../rust-lightning-signer/target/debug/server \
1515
pytest \
1616
$THETEST \
17-
-v --timeout=300 --timeout_method=thread -x
17+
-v --timeout=300 --timeout_method=thread -x -s

0 commit comments

Comments
 (0)