Browse Source

closingd: use hsmfd to get signatures, don't use seed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
429aad8ac7
  1. 4
      closingd/Makefile
  2. 30
      closingd/closing.c
  3. 2
      closingd/closing_wire.csv
  4. 8
      lightningd/closing_control.c

4
closingd/Makefile

@ -43,6 +43,7 @@ $(LIGHTNINGD_CLOSING_OBJS): $(LIGHTNINGD_HEADERS)
# Common source we use. # Common source we use.
CLOSINGD_COMMON_OBJS := \ CLOSINGD_COMMON_OBJS := \
common/base32.o \ common/base32.o \
common/bip32.o \
common/close_tx.o \ common/close_tx.o \
common/crypto_state.o \ common/crypto_state.o \
common/crypto_sync.o \ common/crypto_sync.o \
@ -67,6 +68,7 @@ CLOSINGD_COMMON_OBJS := \
common/subdaemon.o \ common/subdaemon.o \
common/type_to_string.o \ common/type_to_string.o \
common/utils.o \ common/utils.o \
common/utxo.o \
common/version.o \ common/version.o \
common/wire_error.o \ common/wire_error.o \
common/wireaddr.o \ common/wireaddr.o \
@ -81,7 +83,7 @@ closingd/gen_closing_wire.c: $(WIRE_GEN) closingd/closing_wire.csv
LIGHTNINGD_CLOSING_OBJS := $(LIGHTNINGD_CLOSING_SRC:.c=.o) $(LIGHTNINGD_CLOSING_GEN_SRC:.c=.o) LIGHTNINGD_CLOSING_OBJS := $(LIGHTNINGD_CLOSING_SRC:.c=.o) $(LIGHTNINGD_CLOSING_GEN_SRC:.c=.o)
lightningd/lightning_closingd: $(LIGHTNINGD_CLOSING_OBJS) $(WIRE_ONION_OBJS) $(CLOSINGD_COMMON_OBJS) $(WIRE_OBJS) $(BITCOIN_OBJS) lightningd/lightning_closingd: $(LIGHTNINGD_CLOSING_OBJS) $(WIRE_ONION_OBJS) $(CLOSINGD_COMMON_OBJS) $(WIRE_OBJS) $(BITCOIN_OBJS) $(LIGHTNINGD_HSM_CLIENT_OBJS)
check-source: $(LIGHTNINGD_CLOSING_SRC_NOGEN:%=check-src-include-order/%) check-source: $(LIGHTNINGD_CLOSING_SRC_NOGEN:%=check-src-include-order/%)
check-source-bolt: $(LIGHTNINGD_CLOSING_SRC:%=bolt-check/%) $(LIGHTNINGD_CLOSING_HEADERS:%=bolt-check/%) check-source-bolt: $(LIGHTNINGD_CLOSING_SRC:%=bolt-check/%) $(LIGHTNINGD_CLOSING_HEADERS:%=bolt-check/%)

30
closingd/closing.c

@ -16,6 +16,7 @@
#include <common/version.h> #include <common/version.h>
#include <common/wire_error.h> #include <common/wire_error.h>
#include <errno.h> #include <errno.h>
#include <hsmd/gen_hsm_client_wire.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
@ -26,6 +27,7 @@
#define REQ_FD STDIN_FILENO #define REQ_FD STDIN_FILENO
#define PEER_FD 3 #define PEER_FD 3
#define GOSSIP_FD 4 #define GOSSIP_FD 4
#define HSM_FD 5
static struct bitcoin_tx *close_tx(const tal_t *ctx, static struct bitcoin_tx *close_tx(const tal_t *ctx,
struct crypto_state *cs, struct crypto_state *cs,
@ -147,7 +149,6 @@ static void send_offer(struct crypto_state *cs,
const u64 satoshi_out[NUM_SIDES], const u64 satoshi_out[NUM_SIDES],
enum side funder, enum side funder,
uint64_t our_dust_limit, uint64_t our_dust_limit,
const struct secrets *secrets,
uint64_t fee_to_offer) uint64_t fee_to_offer)
{ {
struct bitcoin_tx *tx; struct bitcoin_tx *tx;
@ -176,10 +177,16 @@ static void send_offer(struct crypto_state *cs,
* own output. * own output.
*/ */
/* (We don't do this). */ /* (We don't do this). */
sign_tx_input(tx, 0, NULL, funding_wscript, wire_sync_write(HSM_FD,
&secrets->funding_privkey, take(towire_hsm_sign_mutual_close_tx(NULL,
&funding_pubkey[LOCAL], tx,
&our_sig); &funding_pubkey[REMOTE],
funding_satoshi)));
msg = wire_sync_read(tmpctx, HSM_FD);
if (!fromwire_hsm_sign_tx_reply(msg, &our_sig))
status_failed(STATUS_FAIL_HSM_IO,
"Bad hsm_sign_mutual_close_tx reply %s",
tal_hex(tmpctx, msg));
status_trace("sending fee offer %"PRIu64, fee_to_offer); status_trace("sending fee offer %"PRIu64, fee_to_offer);
@ -424,7 +431,6 @@ int main(int argc, char *argv[])
struct crypto_state cs; struct crypto_state cs;
const tal_t *ctx = tal(NULL, char); const tal_t *ctx = tal(NULL, char);
u8 *msg; u8 *msg;
struct secret seed;
struct pubkey funding_pubkey[NUM_SIDES]; struct pubkey funding_pubkey[NUM_SIDES];
struct bitcoin_txid funding_txid; struct bitcoin_txid funding_txid;
u16 funding_txout; u16 funding_txout;
@ -435,7 +441,6 @@ int main(int argc, char *argv[])
enum side funder; enum side funder;
u8 *scriptpubkey[NUM_SIDES], *funding_wscript; u8 *scriptpubkey[NUM_SIDES], *funding_wscript;
struct channel_id channel_id; struct channel_id channel_id;
struct secrets secrets;
bool reconnected; bool reconnected;
u64 next_index[NUM_SIDES], revocations_received; u64 next_index[NUM_SIDES], revocations_received;
enum side whose_turn; enum side whose_turn;
@ -448,9 +453,10 @@ int main(int argc, char *argv[])
msg = wire_sync_read(tmpctx, REQ_FD); msg = wire_sync_read(tmpctx, REQ_FD);
if (!fromwire_closing_init(ctx, msg, if (!fromwire_closing_init(ctx, msg,
&cs, &seed, &cs,
&funding_txid, &funding_txout, &funding_txid, &funding_txout,
&funding_satoshi, &funding_satoshi,
&funding_pubkey[LOCAL],
&funding_pubkey[REMOTE], &funding_pubkey[REMOTE],
&funder, &funder,
&satoshi_out[LOCAL], &satoshi_out[LOCAL],
@ -473,8 +479,6 @@ int main(int argc, char *argv[])
status_trace("dustlimit = %"PRIu64, our_dust_limit); status_trace("dustlimit = %"PRIu64, our_dust_limit);
status_trace("fee = %"PRIu64, offer[LOCAL]); status_trace("fee = %"PRIu64, offer[LOCAL]);
derive_channel_id(&channel_id, &funding_txid, funding_txout); derive_channel_id(&channel_id, &funding_txid, funding_txout);
derive_basepoints(&seed, &funding_pubkey[LOCAL], NULL,
&secrets, NULL);
funding_wscript = bitcoin_redeem_2of2(ctx, funding_wscript = bitcoin_redeem_2of2(ctx,
&funding_pubkey[LOCAL], &funding_pubkey[LOCAL],
@ -504,7 +508,8 @@ int main(int argc, char *argv[])
funding_wscript, funding_wscript,
scriptpubkey, &funding_txid, funding_txout, scriptpubkey, &funding_txid, funding_txout,
funding_satoshi, satoshi_out, funder, funding_satoshi, satoshi_out, funder,
our_dust_limit, &secrets, offer[LOCAL]); our_dust_limit,
offer[LOCAL]);
} else { } else {
if (i == 0) if (i == 0)
peer_billboard(false, "Waiting for their initial" peer_billboard(false, "Waiting for their initial"
@ -552,7 +557,8 @@ int main(int argc, char *argv[])
funding_wscript, funding_wscript,
scriptpubkey, &funding_txid, funding_txout, scriptpubkey, &funding_txid, funding_txout,
funding_satoshi, satoshi_out, funder, funding_satoshi, satoshi_out, funder,
our_dust_limit, &secrets, offer[LOCAL]); our_dust_limit,
offer[LOCAL]);
} else { } else {
peer_billboard(false, "Waiting for another" peer_billboard(false, "Waiting for another"
" closing fee offer:" " closing fee offer:"

2
closingd/closing_wire.csv

@ -3,10 +3,10 @@
# Begin! (passes peer fd, gossipd-client fd) # Begin! (passes peer fd, gossipd-client fd)
closing_init,2001 closing_init,2001
closing_init,,crypto_state,struct crypto_state closing_init,,crypto_state,struct crypto_state
closing_init,,seed,struct secret
closing_init,,funding_txid,struct bitcoin_txid closing_init,,funding_txid,struct bitcoin_txid
closing_init,,funding_txout,u16 closing_init,,funding_txout,u16
closing_init,,funding_satoshi,u64 closing_init,,funding_satoshi,u64
closing_init,,local_fundingkey,struct pubkey
closing_init,,remote_fundingkey,struct pubkey closing_init,,remote_fundingkey,struct pubkey
closing_init,,funder,enum side closing_init,,funder,enum side
closing_init,,local_msatoshi,u64 closing_init,,local_msatoshi,u64

Can't render this file because it has a wrong number of fields in line 3.

8
lightningd/closing_control.c

@ -9,6 +9,7 @@
#include <lightningd/chaintopology.h> #include <lightningd/chaintopology.h>
#include <lightningd/channel.h> #include <lightningd/channel.h>
#include <lightningd/closing_control.h> #include <lightningd/closing_control.h>
#include <lightningd/hsm_control.h>
#include <lightningd/lightningd.h> #include <lightningd/lightningd.h>
#include <lightningd/log.h> #include <lightningd/log.h>
#include <lightningd/options.h> #include <lightningd/options.h>
@ -133,6 +134,7 @@ void peer_start_closingd(struct channel *channel,
u64 minfee, startfee, feelimit; u64 minfee, startfee, feelimit;
u64 num_revocations; u64 num_revocations;
u64 funding_msatoshi, our_msatoshi, their_msatoshi; u64 funding_msatoshi, our_msatoshi, their_msatoshi;
int hsmfd;
struct lightningd *ld = channel->peer->ld; struct lightningd *ld = channel->peer->ld;
if (!channel->remote_shutdown_scriptpubkey) { if (!channel->remote_shutdown_scriptpubkey) {
@ -141,6 +143,9 @@ void peer_start_closingd(struct channel *channel,
return; return;
} }
hsmfd = hsm_get_client_fd(ld, &channel->peer->id, channel->dbid,
HSM_CAP_SIGN_CLOSING_TX);
channel_set_owner(channel, channel_set_owner(channel,
new_channel_subd(ld, new_channel_subd(ld,
"lightning_closingd", "lightning_closingd",
@ -149,6 +154,7 @@ void peer_start_closingd(struct channel *channel,
channel_errmsg, channel_errmsg,
channel_set_billboard, channel_set_billboard,
take(&peer_fd), take(&gossip_fd), take(&peer_fd), take(&gossip_fd),
take(&hsmfd),
NULL)); NULL));
if (!channel->owner) { if (!channel->owner) {
log_unusual(channel->log, "Could not subdaemon closing: %s", log_unusual(channel->log, "Could not subdaemon closing: %s",
@ -191,10 +197,10 @@ void peer_start_closingd(struct channel *channel,
their_msatoshi = funding_msatoshi - our_msatoshi; their_msatoshi = funding_msatoshi - our_msatoshi;
initmsg = towire_closing_init(tmpctx, initmsg = towire_closing_init(tmpctx,
cs, cs,
&channel->seed,
&channel->funding_txid, &channel->funding_txid,
channel->funding_outnum, channel->funding_outnum,
channel->funding_satoshi, channel->funding_satoshi,
&channel->local_funding_pubkey,
&channel->channel_info.remote_fundingkey, &channel->channel_info.remote_fundingkey,
channel->funder, channel->funder,
our_msatoshi / 1000, /* Rounds down */ our_msatoshi / 1000, /* Rounds down */

Loading…
Cancel
Save