From 59128a86ee58bbf113bfbcf0f9b7531c5ee16605 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 2 Jan 2018 14:54:32 +0100 Subject: [PATCH] hsm: Make sure to pass close_info along with the UTXO The close_info is needed to re-derive the secret key that is supposed to be used to sign the input spending the output. Signed-off-by: Christian Decker --- common/utxo.c | 20 +++++++++++++++++++- common/utxo.h | 2 +- tools/generate-wire.py | 3 ++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/common/utxo.c b/common/utxo.c index edd86741f..b3f7fb049 100644 --- a/common/utxo.c +++ b/common/utxo.c @@ -3,20 +3,38 @@ void towire_utxo(u8 **pptr, const struct utxo *utxo) { + /* Is this a unilateral close output and needs the + * close_info? */ + bool is_unilateral_close = utxo->close_info != NULL; towire_bitcoin_txid(pptr, &utxo->txid); towire_u32(pptr, utxo->outnum); towire_u64(pptr, utxo->amount); towire_u32(pptr, utxo->keyindex); towire_bool(pptr, utxo->is_p2sh); + + towire_bool(pptr, is_unilateral_close); + if (is_unilateral_close) { + towire_u64(pptr, utxo->close_info->channel_id); + towire_pubkey(pptr, &utxo->close_info->peer_id); + towire_pubkey(pptr, &utxo->close_info->commitment_point); + } } -void fromwire_utxo(const u8 **ptr, size_t *max, struct utxo *utxo) +void fromwire_utxo(const tal_t *ctx, const u8 **ptr, size_t *max, struct utxo *utxo) { fromwire_bitcoin_txid(ptr, max, &utxo->txid); utxo->outnum = fromwire_u32(ptr, max); utxo->amount = fromwire_u64(ptr, max); utxo->keyindex = fromwire_u32(ptr, max); utxo->is_p2sh = fromwire_bool(ptr, max); + if (fromwire_bool(ptr, max)) { + utxo->close_info = tal(ctx, struct unilateral_close_info); + utxo->close_info->channel_id = fromwire_u64(ptr, max); + fromwire_pubkey(ptr, max, &utxo->close_info->peer_id); + fromwire_pubkey(ptr, max, &utxo->close_info->commitment_point); + } else { + utxo->close_info = NULL; + } } diff --git a/common/utxo.h b/common/utxo.h index 7ed145cb9..1f7e93b68 100644 --- a/common/utxo.h +++ b/common/utxo.h @@ -29,7 +29,7 @@ struct utxo { }; void towire_utxo(u8 **pptr, const struct utxo *utxo); -void fromwire_utxo(const u8 **ptr, size_t *max, struct utxo *utxo); +void fromwire_utxo(const tal_t *ctx, const u8 **ptr, size_t *max, struct utxo *utxo); /* build_utxos/funding_tx use array of pointers, but marshall code * wants arr of structs */ diff --git a/tools/generate-wire.py b/tools/generate-wire.py index 8784b1cfd..3307f9bdc 100755 --- a/tools/generate-wire.py +++ b/tools/generate-wire.py @@ -31,6 +31,7 @@ type2size = { varlen_structs = [ 'gossip_getnodes_entry', 'failed_htlc', + 'utxo', ] class FieldType(object): @@ -297,7 +298,7 @@ class Message(object): self.print_fromwire_array(subcalls, basetype, f, f.name, f.num_elems) elif f.is_variable_size(): - subcalls.append("\t//2th case {name}".format(name=f.name)) + subcalls.append("\t//2nd case {name}".format(name=f.name)) subcalls.append('\t*{} = {} ? tal_arr(ctx, {}, {}) : NULL;' .format(f.name, f.lenvar, f.fieldtype.name, f.lenvar))