mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-21 16:14:23 +01:00
protocol: add output script to close_clearing message.
We just use a p2sh to a single address for the moment, but that's simply for non-segwit wallets; we'll pay to whatever the other side specifies. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
16
close_tx.c
16
close_tx.c
@@ -1,6 +1,4 @@
|
|||||||
#include "bitcoin/pubkey.h"
|
|
||||||
#include "bitcoin/script.h"
|
#include "bitcoin/script.h"
|
||||||
#include "bitcoin/shadouble.h"
|
|
||||||
#include "bitcoin/tx.h"
|
#include "bitcoin/tx.h"
|
||||||
#include "close_tx.h"
|
#include "close_tx.h"
|
||||||
#include "permute_tx.h"
|
#include "permute_tx.h"
|
||||||
@@ -8,15 +6,14 @@
|
|||||||
|
|
||||||
struct bitcoin_tx *create_close_tx(secp256k1_context *secpctx,
|
struct bitcoin_tx *create_close_tx(secp256k1_context *secpctx,
|
||||||
const tal_t *ctx,
|
const tal_t *ctx,
|
||||||
const struct pubkey *our_final,
|
const u8 *our_script,
|
||||||
const struct pubkey *their_final,
|
const u8 *their_script,
|
||||||
const struct sha256_double *anchor_txid,
|
const struct sha256_double *anchor_txid,
|
||||||
unsigned int anchor_index,
|
unsigned int anchor_index,
|
||||||
u64 anchor_satoshis,
|
u64 anchor_satoshis,
|
||||||
uint64_t to_us, uint64_t to_them)
|
uint64_t to_us, uint64_t to_them)
|
||||||
{
|
{
|
||||||
struct bitcoin_tx *tx;
|
struct bitcoin_tx *tx;
|
||||||
const u8 *redeemscript;
|
|
||||||
|
|
||||||
/* Now create close tx: one input, two outputs. */
|
/* Now create close tx: one input, two outputs. */
|
||||||
tx = bitcoin_tx(ctx, 1, 2);
|
tx = bitcoin_tx(ctx, 1, 2);
|
||||||
@@ -28,14 +25,15 @@ struct bitcoin_tx *create_close_tx(secp256k1_context *secpctx,
|
|||||||
|
|
||||||
/* One output is to us. */
|
/* One output is to us. */
|
||||||
tx->output[0].amount = to_us;
|
tx->output[0].amount = to_us;
|
||||||
redeemscript = bitcoin_redeem_single(tx, our_final);
|
tx->output[0].script = tal_dup_arr(tx, u8,
|
||||||
tx->output[0].script = scriptpubkey_p2sh(tx, redeemscript);
|
our_script, tal_count(our_script), 0);
|
||||||
tx->output[0].script_length = tal_count(tx->output[0].script);
|
tx->output[0].script_length = tal_count(tx->output[0].script);
|
||||||
|
|
||||||
/* Other output is to them. */
|
/* Other output is to them. */
|
||||||
tx->output[1].amount = to_them;
|
tx->output[1].amount = to_them;
|
||||||
redeemscript = bitcoin_redeem_single(tx, their_final);
|
tx->output[1].script = tal_dup_arr(tx, u8,
|
||||||
tx->output[1].script = scriptpubkey_p2sh(tx, redeemscript);
|
their_script, tal_count(their_script),
|
||||||
|
0);
|
||||||
tx->output[1].script_length = tal_count(tx->output[1].script);
|
tx->output[1].script_length = tal_count(tx->output[1].script);
|
||||||
|
|
||||||
assert(tx->output[0].amount + tx->output[1].amount <= anchor_satoshis);
|
assert(tx->output[0].amount + tx->output[1].amount <= anchor_satoshis);
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ struct pubkey;
|
|||||||
* input scriptsig. */
|
* input scriptsig. */
|
||||||
struct bitcoin_tx *create_close_tx(secp256k1_context *secpctx,
|
struct bitcoin_tx *create_close_tx(secp256k1_context *secpctx,
|
||||||
const tal_t *ctx,
|
const tal_t *ctx,
|
||||||
const struct pubkey *our_final,
|
const u8 *our_script,
|
||||||
const struct pubkey *their_final,
|
const u8 *their_script,
|
||||||
const struct sha256_double *anchor_txid,
|
const struct sha256_double *anchor_txid,
|
||||||
unsigned int anchor_index,
|
unsigned int anchor_index,
|
||||||
u64 anchor_satoshis,
|
u64 anchor_satoshis,
|
||||||
|
|||||||
@@ -388,9 +388,18 @@ void queue_pkt_err(struct peer *peer, Pkt *err)
|
|||||||
|
|
||||||
void queue_pkt_close_clearing(struct peer *peer)
|
void queue_pkt_close_clearing(struct peer *peer)
|
||||||
{
|
{
|
||||||
|
u8 *redeemscript;
|
||||||
CloseClearing *c = tal(peer, CloseClearing);
|
CloseClearing *c = tal(peer, CloseClearing);
|
||||||
|
|
||||||
close_clearing__init(c);
|
close_clearing__init(c);
|
||||||
|
redeemscript = bitcoin_redeem_single(c, &peer->us.finalkey);
|
||||||
|
peer->closing.our_script = scriptpubkey_p2sh(peer, redeemscript);
|
||||||
|
|
||||||
|
c->scriptpubkey.data = tal_dup_arr(c, u8,
|
||||||
|
peer->closing.our_script,
|
||||||
|
tal_count(peer->closing.our_script),
|
||||||
|
0);
|
||||||
|
c->scriptpubkey.len = tal_count(c->scriptpubkey.data);
|
||||||
|
|
||||||
queue_pkt(peer, PKT__PKT_CLOSE_CLEARING, c);
|
queue_pkt(peer, PKT__PKT_CLOSE_CLEARING, c);
|
||||||
}
|
}
|
||||||
@@ -748,7 +757,13 @@ Pkt *accept_pkt_revocation(struct peer *peer, const Pkt *pkt)
|
|||||||
|
|
||||||
Pkt *accept_pkt_close_clearing(struct peer *peer, const Pkt *pkt)
|
Pkt *accept_pkt_close_clearing(struct peer *peer, const Pkt *pkt)
|
||||||
{
|
{
|
||||||
/* FIXME: Reject unknown odd fields? */
|
const CloseClearing *c = pkt->close_clearing;
|
||||||
|
|
||||||
|
/* FIXME: Filter for non-standardness? */
|
||||||
|
peer->closing.their_script = tal_dup_arr(peer, u8,
|
||||||
|
c->scriptpubkey.data,
|
||||||
|
c->scriptpubkey.len, 0);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -948,8 +948,8 @@ struct bitcoin_tx *peer_create_close_tx(struct peer *peer, u64 fee)
|
|||||||
cstate.b.pay_msat / 1000);
|
cstate.b.pay_msat / 1000);
|
||||||
|
|
||||||
return create_close_tx(peer->dstate->secpctx, peer,
|
return create_close_tx(peer->dstate->secpctx, peer,
|
||||||
&peer->us.finalkey,
|
peer->closing.our_script,
|
||||||
&peer->them.finalkey,
|
peer->closing.their_script,
|
||||||
&peer->anchor.txid,
|
&peer->anchor.txid,
|
||||||
peer->anchor.index,
|
peer->anchor.index,
|
||||||
peer->anchor.satoshis,
|
peer->anchor.satoshis,
|
||||||
|
|||||||
@@ -170,6 +170,8 @@ struct peer {
|
|||||||
struct bitcoin_signature *their_sig;
|
struct bitcoin_signature *their_sig;
|
||||||
/* If their_sig is non-NULL, this is the fee. */
|
/* If their_sig is non-NULL, this is the fee. */
|
||||||
u64 their_fee;
|
u64 their_fee;
|
||||||
|
/* scriptPubKey we/they want for closing. */
|
||||||
|
u8 *our_script, *their_script;
|
||||||
} closing;
|
} closing;
|
||||||
|
|
||||||
/* If not INPUT_NONE, send this when we have no more HTLCs. */
|
/* If not INPUT_NONE, send this when we have no more HTLCs. */
|
||||||
|
|||||||
@@ -2017,9 +2017,29 @@ const ProtobufCMessageDescriptor update_revocation__descriptor =
|
|||||||
(ProtobufCMessageInit) update_revocation__init,
|
(ProtobufCMessageInit) update_revocation__init,
|
||||||
NULL,NULL,NULL /* reserved[123] */
|
NULL,NULL,NULL /* reserved[123] */
|
||||||
};
|
};
|
||||||
#define close_clearing__field_descriptors NULL
|
static const ProtobufCFieldDescriptor close_clearing__field_descriptors[1] =
|
||||||
#define close_clearing__field_indices_by_name NULL
|
{
|
||||||
#define close_clearing__number_ranges NULL
|
{
|
||||||
|
"scriptPubkey",
|
||||||
|
1,
|
||||||
|
PROTOBUF_C_LABEL_REQUIRED,
|
||||||
|
PROTOBUF_C_TYPE_BYTES,
|
||||||
|
0, /* quantifier_offset */
|
||||||
|
offsetof(CloseClearing, scriptpubkey),
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
0, /* flags */
|
||||||
|
0,NULL,NULL /* reserved1,reserved2, etc */
|
||||||
|
},
|
||||||
|
};
|
||||||
|
static const unsigned close_clearing__field_indices_by_name[] = {
|
||||||
|
0, /* field[0] = scriptPubkey */
|
||||||
|
};
|
||||||
|
static const ProtobufCIntRange close_clearing__number_ranges[1 + 1] =
|
||||||
|
{
|
||||||
|
{ 1, 0 },
|
||||||
|
{ 0, 1 }
|
||||||
|
};
|
||||||
const ProtobufCMessageDescriptor close_clearing__descriptor =
|
const ProtobufCMessageDescriptor close_clearing__descriptor =
|
||||||
{
|
{
|
||||||
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
|
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
|
||||||
@@ -2028,10 +2048,10 @@ const ProtobufCMessageDescriptor close_clearing__descriptor =
|
|||||||
"CloseClearing",
|
"CloseClearing",
|
||||||
"",
|
"",
|
||||||
sizeof(CloseClearing),
|
sizeof(CloseClearing),
|
||||||
0,
|
1,
|
||||||
close_clearing__field_descriptors,
|
close_clearing__field_descriptors,
|
||||||
close_clearing__field_indices_by_name,
|
close_clearing__field_indices_by_name,
|
||||||
0, close_clearing__number_ranges,
|
1, close_clearing__number_ranges,
|
||||||
(ProtobufCMessageInit) close_clearing__init,
|
(ProtobufCMessageInit) close_clearing__init,
|
||||||
NULL,NULL,NULL /* reserved[123] */
|
NULL,NULL,NULL /* reserved[123] */
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -417,10 +417,14 @@ struct _UpdateRevocation
|
|||||||
struct _CloseClearing
|
struct _CloseClearing
|
||||||
{
|
{
|
||||||
ProtobufCMessage base;
|
ProtobufCMessage base;
|
||||||
|
/*
|
||||||
|
* Output script for mutual close tx.
|
||||||
|
*/
|
||||||
|
ProtobufCBinaryData scriptpubkey;
|
||||||
};
|
};
|
||||||
#define CLOSE_CLEARING__INIT \
|
#define CLOSE_CLEARING__INIT \
|
||||||
{ PROTOBUF_C_MESSAGE_INIT (&close_clearing__descriptor) \
|
{ PROTOBUF_C_MESSAGE_INIT (&close_clearing__descriptor) \
|
||||||
}
|
, {0,NULL} }
|
||||||
|
|
||||||
|
|
||||||
struct _CloseSignature
|
struct _CloseSignature
|
||||||
|
|||||||
@@ -173,6 +173,8 @@ message update_revocation {
|
|||||||
|
|
||||||
// Start clearing out the channel HTLCs so we can close it
|
// Start clearing out the channel HTLCs so we can close it
|
||||||
message close_clearing {
|
message close_clearing {
|
||||||
|
// Output script for mutual close tx.
|
||||||
|
required bytes scriptPubkey = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message close_signature {
|
message close_signature {
|
||||||
|
|||||||
Reference in New Issue
Block a user