Browse Source

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 <decker.christian@gmail.com>
ppa-0.6.1
Christian Decker 7 years ago
parent
commit
59128a86ee
  1. 20
      common/utxo.c
  2. 2
      common/utxo.h
  3. 3
      tools/generate-wire.py

20
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;
}
}

2
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 */

3
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))

Loading…
Cancel
Save