Skip to content

Commit 7138643

Browse files
committed
Added sign-channel-announcement.
1 parent 8f637d5 commit 7138643

File tree

4 files changed

+11
-27
lines changed

4 files changed

+11
-27
lines changed

contrib/remote_hsmd/NOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ Some popular tests:
7171
# sign-message
7272
export THETEST=tests/test_misc.py::test_signmessage
7373

74+
# sign-channel-announcement
75+
export THETEST=tests/test_closing.py::test_closing_different_fees
76+
7477
rust-lightning-signer
7578
----------------------------------------------------------------
7679

contrib/remote_hsmd/TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ COMPLETE proxy_stat proxy_handle_sign_penalty_to_us
2727
COMPLETE proxy_stat proxy_handle_sign_commitment_tx
2828
COMPLETE proxy_stat proxy_handle_sign_mutual_close_tx
2929
COMPLETE proxy_stat proxy_handle_check_future_secret
30+
COMPLETE proxy_stat proxy_handle_cannouncement_sig
3031
COMPLETE proxy_stat proxy_handle_sign_message
3132
3233
PARTIAL (-P2SH) proxy_stat proxy_handle_sign_withdrawal_tx
3334
3435
MARSHALED proxy_stat proxy_init_hsm
35-
MARSHALED proxy_stat proxy_handle_cannouncement_sig
3636
```
3737

3838
Improvements

contrib/remote_hsmd/hsmd.c

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -833,14 +833,9 @@ static struct io_plan *handle_cannouncement_sig(struct io_conn *conn,
833833
*/
834834
/* First type bytes are the msg type */
835835
size_t offset = 2 + 256;
836-
struct privkey node_pkey;
837836
secp256k1_ecdsa_signature node_sig, bitcoin_sig;
838-
struct sha256_double hash;
839837
u8 *reply;
840838
u8 *ca;
841-
struct pubkey funding_pubkey;
842-
struct privkey funding_privkey;
843-
struct secret channel_seed;
844839

845840
/*~ You'll find FIXMEs like this scattered through the code.
846841
* Sometimes they suggest simple improvements which someone like
@@ -850,10 +845,6 @@ static struct io_plan *handle_cannouncement_sig(struct io_conn *conn,
850845
/*~ Christian uses TODO(cdecker) or FIXME(cdecker), but I'm sure he won't
851846
* mind if you fix this for him! */
852847

853-
/* FIXME: We should cache these. */
854-
get_channel_seed(&c->id, c->dbid, &channel_seed);
855-
derive_funding_key(&channel_seed, &funding_pubkey, &funding_privkey);
856-
857848
/*~ fromwire_ routines which need to do allocation take a tal context
858849
* as their first field; tmpctx is good here since we won't need it
859850
* after this function. */
@@ -881,15 +872,7 @@ static struct io_plan *handle_cannouncement_sig(struct io_conn *conn,
881872
return bad_req_fmt(conn, c, msg_in,
882873
"proxy_%s error: %s", __FUNCTION__,
883874
proxy_last_message());
884-
g_proxy_impl = PROXY_IMPL_MARSHALED;
885-
886-
/* FIXME - REPLACE BELOW W/ REMOTE RETURN */
887-
888-
node_key(&node_pkey, NULL);
889-
sha256_double(&hash, ca + offset, tal_count(ca) - offset);
890-
891-
sign_hash(&node_pkey, &hash, &node_sig);
892-
sign_hash(&funding_privkey, &hash, &bitcoin_sig);
875+
g_proxy_impl = PROXY_IMPL_COMPLETE;
893876

894877
reply = towire_hsm_cannouncement_sig_reply(NULL, &node_sig,
895878
&bitcoin_sig);

contrib/remote_hsmd/proxy.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -867,25 +867,23 @@ proxy_stat proxy_handle_cannouncement_sig(
867867
tal_count(channel_announcement)).c_str()
868868
);
869869

870+
/* Skip the portion of the channel_update that we don't sign */
871+
size_t offset = 2 + 256; /* sizeof(type) + 4*sizeof(signature) */
872+
size_t annsz = tal_count(channel_announcement);
873+
870874
last_message = "";
871875
SignChannelAnnouncementRequest req;
872876
marshal_node_id(&self_id, req.mutable_node_id());
873877
marshal_channel_nonce(peer_id, dbid, req.mutable_channel_nonce());
874-
req.set_channel_announcement(channel_announcement,
875-
tal_count(channel_announcement));
878+
req.set_channel_announcement(channel_announcement + offset,
879+
annsz - offset);
876880

877881
ClientContext context;
878882
SignChannelAnnouncementReply rsp;
879883
Status status = stub->SignChannelAnnouncement(&context, req, &rsp);
880884
if (status.ok()) {
881-
// FIXME - UNCOMMENT WHEN SERVER IMPLEMENTS:
882-
#if 0
883885
unmarshal_ecdsa_signature(rsp.node_signature(), o_node_sig);
884886
unmarshal_ecdsa_signature(rsp.bitcoin_signature(), o_bitcoin_sig);
885-
#else
886-
memset(o_node_sig->data, '\0', sizeof(o_node_sig->data));
887-
memset(o_bitcoin_sig->data, '\0', sizeof(o_bitcoin_sig->data));
888-
#endif
889887
status_debug("%s:%d %s self_id=%s node_sig=%s bitcoin_sig=%s",
890888
__FILE__, __LINE__, __FUNCTION__,
891889
dump_node_id(&self_id).c_str(),

0 commit comments

Comments
 (0)