Skip to content

Commit 9cf9bd3

Browse files
committed
Added sign-commitment-tx and sign-mutual-close-tx.
1 parent bfecc5a commit 9cf9bd3

File tree

5 files changed

+22
-79
lines changed

5 files changed

+22
-79
lines changed

contrib/remote_hsmd/NOTES.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,32 @@ $THETEST \
3838

3939
Some popular tests:
4040

41+
# sign-invoice, handle-sign-remote-htlc-tx
4142
export THETEST=tests/test_connection.py::test_balance
4243
export THETEST=tests/test_pay.py::test_sendpay
4344
export THETEST=tests/test_pay.py::test_pay
45+
46+
# sign-local-htlc-tx
4447
export THETEST=tests/test_closing.py::test_onchain_different_fees
48+
49+
# sign-remote-htlc-to-us
4550
export THETEST=tests/test_closing.py::test_onchain_feechange
4651
export THETEST=tests/test_closing.py::test_onchain_all_dust
4752
export THETEST=tests/test_closing.py::test_permfail_new_commit
53+
54+
# sign-delayed-payment-to-us
4855
export THETEST=tests/test_closing.py::test_onchain_multihtlc_our_unilateral
4956
export THETEST=tests/test_closing.py::test_onchain_multihtlc_their_unilateral
5057
export THETEST=tests/test_closing.py::test_permfail_htlc_in
5158
export THETEST=tests/test_closing.py::test_permfail_htlc_out
52-
export THETEST=tests/test_closing.py::test_penalty_inhtlc
53-
export THETEST=tests/test_closing.py::test_penalty_outhtlc
54-
5559

56-
Tests remote_commitment:
60+
# sign-penalty-to-us
61+
export THETEST=tests/test_closing.py::test_penalty_inhtlc
62+
export THETEST=tests/test_closing.py::test_penalty_outhtlc
63+
export THETEST=tests/test_closing.py::test_closing
5764

65+
# sign-mutual-close
66+
export THETEST=tests/test_closing.py::test_closing
5867

5968
rust-lightning-signer
6069
----------------------------------------------------------------

contrib/remote_hsmd/TODO.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ COMPLETE proxy_stat proxy_handle_sign_local_htlc_tx
2424
COMPLETE proxy_stat proxy_handle_sign_remote_htlc_to_us
2525
COMPLETE proxy_stat proxy_handle_sign_delayed_payment_to_us
2626
COMPLETE proxy_stat proxy_handle_sign_penalty_to_us
27+
COMPLETE proxy_stat proxy_handle_sign_commitment_tx
28+
COMPLETE proxy_stat proxy_handle_sign_mutual_close_tx
2729
2830
PARTIAL (-P2SH) proxy_stat proxy_handle_sign_withdrawal_tx
2931
3032
MARSHALED proxy_stat proxy_init_hsm
3133
MARSHALED proxy_stat proxy_handle_sign_message
32-
MARSHALED proxy_stat proxy_handle_sign_mutual_close_tx
33-
MARSHALED proxy_stat proxy_handle_sign_commitment_tx
3434
MARSHALED proxy_stat proxy_handle_cannouncement_sig
3535
MARSHALED proxy_stat proxy_handle_check_future_secret
3636
```

contrib/remote_hsmd/hsmd.c

Lines changed: 5 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -998,15 +998,12 @@ static struct io_plan *handle_sign_commitment_tx(struct io_conn *conn,
998998
struct client *c,
999999
const u8 *msg_in)
10001000
{
1001-
struct pubkey remote_funding_pubkey, local_funding_pubkey;
1001+
struct pubkey remote_funding_pubkey;
10021002
struct node_id peer_id;
10031003
u64 dbid;
10041004
struct amount_sat funding;
1005-
struct secret channel_seed;
10061005
struct bitcoin_tx *tx;
10071006
struct bitcoin_signature sig;
1008-
struct secrets secrets;
1009-
const u8 *funding_wscript;
10101007

10111008
if (!fromwire_hsm_sign_commitment_tx(tmpctx, msg_in,
10121009
&peer_id, &dbid,
@@ -1032,9 +1029,7 @@ static struct io_plan *handle_sign_commitment_tx(struct io_conn *conn,
10321029
tx->input_amounts[0] = tal_dup(tx, struct amount_sat, &funding);
10331030

10341031
proxy_stat rv = proxy_handle_sign_commitment_tx(
1035-
tx, &remote_funding_pubkey, &funding,
1036-
&c->id, c->dbid,
1037-
&sig);
1032+
tx, &remote_funding_pubkey, &peer_id, dbid, &sig);
10381033
if (PROXY_PERMANENT(rv))
10391034
status_failed(STATUS_FAIL_INTERNAL_ERROR,
10401035
"proxy_%s failed: %s", __FUNCTION__,
@@ -1045,28 +1040,6 @@ static struct io_plan *handle_sign_commitment_tx(struct io_conn *conn,
10451040
proxy_last_message());
10461041
g_proxy_impl = PROXY_IMPL_MARSHALED;
10471042

1048-
#if 0
1049-
status_debug("%s:%d %s: signature: %s",
1050-
__FILE__, __LINE__, __FUNCTION__,
1051-
type_to_string(tmpctx, struct bitcoin_signature, &sig));
1052-
#else
1053-
get_channel_seed(&peer_id, dbid, &channel_seed);
1054-
derive_basepoints(&channel_seed,
1055-
&local_funding_pubkey, NULL, &secrets, NULL);
1056-
1057-
/*~ Bitcoin signatures cover the (part of) the script they're
1058-
* executing; the rules are a bit complex in general, but for
1059-
* Segregated Witness it's simply the current script. */
1060-
funding_wscript = bitcoin_redeem_2of2(tmpctx,
1061-
&local_funding_pubkey,
1062-
&remote_funding_pubkey);
1063-
sign_tx_input(tx, 0, NULL, funding_wscript,
1064-
&secrets.funding_privkey,
1065-
&local_funding_pubkey,
1066-
SIGHASH_ALL,
1067-
&sig);
1068-
#endif
1069-
10701043
return req_reply(conn, c,
10711044
take(towire_hsm_sign_commitment_tx_reply(NULL, &sig)));
10721045
}
@@ -1436,13 +1409,10 @@ static struct io_plan *handle_sign_mutual_close_tx(struct io_conn *conn,
14361409
struct client *c,
14371410
const u8 *msg_in)
14381411
{
1439-
struct secret channel_seed;
14401412
struct bitcoin_tx *tx;
1441-
struct pubkey remote_funding_pubkey, local_funding_pubkey;
1413+
struct pubkey remote_funding_pubkey;
14421414
struct bitcoin_signature sig;
1443-
struct secrets secrets;
14441415
struct amount_sat funding;
1445-
const u8 *funding_wscript;
14461416

14471417
if (!fromwire_hsm_sign_mutual_close_tx(tmpctx, msg_in,
14481418
&tx,
@@ -1456,9 +1426,7 @@ static struct io_plan *handle_sign_mutual_close_tx(struct io_conn *conn,
14561426
tx->input_amounts[0] = tal_dup(tx, struct amount_sat, &funding);
14571427

14581428
proxy_stat rv = proxy_handle_sign_mutual_close_tx(
1459-
tx, &remote_funding_pubkey, &funding,
1460-
&c->id, c->dbid,
1461-
&sig);
1429+
tx, &remote_funding_pubkey, &c->id, c->dbid, &sig);
14621430
if (PROXY_PERMANENT(rv))
14631431
status_failed(STATUS_FAIL_INTERNAL_ERROR,
14641432
"proxy_%s failed: %s", __FUNCTION__,
@@ -1467,25 +1435,7 @@ static struct io_plan *handle_sign_mutual_close_tx(struct io_conn *conn,
14671435
return bad_req_fmt(conn, c, msg_in,
14681436
"proxy_%s error: %s", __FUNCTION__,
14691437
proxy_last_message());
1470-
/* FIXME - uncomment this: assert(tal_count(sigs) == 1); */
1471-
g_proxy_impl = PROXY_IMPL_MARSHALED;
1472-
1473-
/* FIXME - USE SERVER RESULT AND REMOVE BELOW */
1474-
1475-
/* FIXME: We should know dust level, decent fee range and
1476-
* balances, and final_keyindex, and thus be able to check tx
1477-
* outputs! */
1478-
get_channel_seed(&c->id, c->dbid, &channel_seed);
1479-
derive_basepoints(&channel_seed,
1480-
&local_funding_pubkey, NULL, &secrets, NULL);
1481-
1482-
funding_wscript = bitcoin_redeem_2of2(tmpctx,
1483-
&local_funding_pubkey,
1484-
&remote_funding_pubkey);
1485-
sign_tx_input(tx, 0, NULL, funding_wscript,
1486-
&secrets.funding_privkey,
1487-
&local_funding_pubkey,
1488-
SIGHASH_ALL, &sig);
1438+
g_proxy_impl = PROXY_IMPL_COMPLETE;
14891439

14901440
return req_reply(conn, c, take(towire_hsm_sign_tx_reply(NULL, &sig)));
14911441
}

contrib/remote_hsmd/proxy.cc

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -763,19 +763,17 @@ proxy_stat proxy_handle_get_channel_basepoints(
763763
proxy_stat proxy_handle_sign_mutual_close_tx(
764764
struct bitcoin_tx *tx,
765765
const struct pubkey *remote_funding_pubkey,
766-
struct amount_sat *funding,
767766
struct node_id *peer_id,
768767
u64 dbid,
769768
struct bitcoin_signature *o_sig)
770769
{
771770
status_debug(
772771
"%s:%d %s self_id=%s peer_id=%s dbid=%" PRIu64 " "
773-
"funding=%" PRIu64 " remote_funding_pubkey=%s tx=%s",
772+
"remote_funding_pubkey=%s tx=%s",
774773
__FILE__, __LINE__, __FUNCTION__,
775774
dump_node_id(&self_id).c_str(),
776775
dump_node_id(peer_id).c_str(),
777776
dbid,
778-
funding->satoshis,
779777
dump_pubkey(remote_funding_pubkey).c_str(),
780778
dump_tx(tx).c_str()
781779
);
@@ -792,12 +790,7 @@ proxy_stat proxy_handle_sign_mutual_close_tx(
792790
SignatureReply rsp;
793791
Status status = stub->SignMutualCloseTx(&context, req, &rsp);
794792
if (status.ok()) {
795-
// FIXME - UNCOMMENT WHEN SERVER IMPLEMENTS:
796-
#if 0
797793
unmarshal_bitcoin_signature(rsp.signature(), o_sig);
798-
#else
799-
memset(o_sig, '\0', sizeof(*o_sig));
800-
#endif
801794
status_debug("%s:%d %s self_id=%s sig=%s",
802795
__FILE__, __LINE__, __FUNCTION__,
803796
dump_node_id(&self_id).c_str(),
@@ -817,19 +810,17 @@ proxy_stat proxy_handle_sign_mutual_close_tx(
817810
proxy_stat proxy_handle_sign_commitment_tx(
818811
struct bitcoin_tx *tx,
819812
const struct pubkey *remote_funding_pubkey,
820-
struct amount_sat *funding,
821813
struct node_id *peer_id,
822814
u64 dbid,
823815
struct bitcoin_signature *o_sig)
824816
{
825817
status_debug(
826818
"%s:%d %s self_id=%s peer_id=%s dbid=%" PRIu64 " "
827-
"funding=%" PRIu64 " remote_funding_pubkey=%s tx=%s",
819+
"remote_funding_pubkey=%s tx=%s",
828820
__FILE__, __LINE__, __FUNCTION__,
829821
dump_node_id(&self_id).c_str(),
830822
dump_node_id(peer_id).c_str(),
831823
dbid,
832-
funding->satoshis,
833824
dump_pubkey(remote_funding_pubkey).c_str(),
834825
dump_tx(tx).c_str()
835826
);
@@ -846,12 +837,7 @@ proxy_stat proxy_handle_sign_commitment_tx(
846837
SignatureReply rsp;
847838
Status status = stub->SignCommitmentTx(&context, req, &rsp);
848839
if (status.ok()) {
849-
// FIXME - UNCOMMENT WHEN SERVER IMPLEMENTS:
850-
#if 0
851840
unmarshal_bitcoin_signature(rsp.signature(), o_sig);
852-
#else
853-
memset(o_sig, '\0', sizeof(*o_sig));
854-
#endif
855841
status_debug("%s:%d %s self_id=%s sig=%s",
856842
__FILE__, __LINE__, __FUNCTION__,
857843
dump_node_id(&self_id).c_str(),

contrib/remote_hsmd/proxy.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,13 @@ proxy_stat proxy_handle_get_channel_basepoints(
9393
proxy_stat proxy_handle_sign_mutual_close_tx(
9494
struct bitcoin_tx *tx,
9595
const struct pubkey *remote_funding_pubkey,
96-
struct amount_sat *funding,
9796
struct node_id *peer_id,
9897
u64 dbid,
9998
struct bitcoin_signature *o_sig);
10099

101100
proxy_stat proxy_handle_sign_commitment_tx(
102101
struct bitcoin_tx *tx,
103102
const struct pubkey *remote_funding_pubkey,
104-
struct amount_sat *funding,
105103
struct node_id *peer_id,
106104
u64 dbid,
107105
struct bitcoin_signature *o_sig);

0 commit comments

Comments
 (0)