mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +01:00
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>
This commit is contained in:
parent
37c2873c88
commit
59128a86ee
3 changed files with 22 additions and 3 deletions
|
@ -3,20 +3,38 @@
|
||||||
|
|
||||||
void towire_utxo(u8 **pptr, const struct utxo *utxo)
|
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_bitcoin_txid(pptr, &utxo->txid);
|
||||||
towire_u32(pptr, utxo->outnum);
|
towire_u32(pptr, utxo->outnum);
|
||||||
towire_u64(pptr, utxo->amount);
|
towire_u64(pptr, utxo->amount);
|
||||||
towire_u32(pptr, utxo->keyindex);
|
towire_u32(pptr, utxo->keyindex);
|
||||||
towire_bool(pptr, utxo->is_p2sh);
|
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);
|
fromwire_bitcoin_txid(ptr, max, &utxo->txid);
|
||||||
utxo->outnum = fromwire_u32(ptr, max);
|
utxo->outnum = fromwire_u32(ptr, max);
|
||||||
utxo->amount = fromwire_u64(ptr, max);
|
utxo->amount = fromwire_u64(ptr, max);
|
||||||
utxo->keyindex = fromwire_u32(ptr, max);
|
utxo->keyindex = fromwire_u32(ptr, max);
|
||||||
utxo->is_p2sh = fromwire_bool(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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ struct utxo {
|
||||||
};
|
};
|
||||||
|
|
||||||
void towire_utxo(u8 **pptr, const struct utxo *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
|
/* build_utxos/funding_tx use array of pointers, but marshall code
|
||||||
* wants arr of structs */
|
* wants arr of structs */
|
||||||
|
|
|
@ -31,6 +31,7 @@ type2size = {
|
||||||
varlen_structs = [
|
varlen_structs = [
|
||||||
'gossip_getnodes_entry',
|
'gossip_getnodes_entry',
|
||||||
'failed_htlc',
|
'failed_htlc',
|
||||||
|
'utxo',
|
||||||
]
|
]
|
||||||
|
|
||||||
class FieldType(object):
|
class FieldType(object):
|
||||||
|
@ -297,7 +298,7 @@ class Message(object):
|
||||||
self.print_fromwire_array(subcalls, basetype, f, f.name,
|
self.print_fromwire_array(subcalls, basetype, f, f.name,
|
||||||
f.num_elems)
|
f.num_elems)
|
||||||
elif f.is_variable_size():
|
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;'
|
subcalls.append('\t*{} = {} ? tal_arr(ctx, {}, {}) : NULL;'
|
||||||
.format(f.name, f.lenvar, f.fieldtype.name, f.lenvar))
|
.format(f.name, f.lenvar, f.fieldtype.name, f.lenvar))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue