Browse Source

channeld: change to_remote for option_anchor_outputs.

It's now a P2WSH to incorporate a CSV 1 delay.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
bump-pyln-proto
Rusty Russell 4 years ago
parent
commit
3ff8311b40
  1. 22
      bitcoin/script.c
  2. 4
      bitcoin/script.h
  3. 27
      channeld/commit_tx.c
  4. 25
      common/initial_commit_tx.c

22
bitcoin/script.c

@ -34,6 +34,7 @@
#define OP_1SUB 0x8C #define OP_1SUB 0x8C
#define OP_ADD 0x93 #define OP_ADD 0x93
#define OP_CHECKSIG 0xAC #define OP_CHECKSIG 0xAC
#define OP_CHECKSIGVERIFY 0xAD
#define OP_CHECKMULTISIG 0xAE #define OP_CHECKMULTISIG 0xAE
#define OP_HASH160 0xA9 #define OP_HASH160 0xA9
#define OP_CHECKSEQUENCEVERIFY 0xB2 #define OP_CHECKSEQUENCEVERIFY 0xB2
@ -321,6 +322,27 @@ u8 *scriptpubkey_witness_raw(const tal_t *ctx, u8 version,
return script; return script;
} }
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3:
*
* #### `to_remote` Output
*
* If `option_anchor_outputs` applies to the commitment
* transaction, the `to_remote` output is encumbered by a one
* block csv lock.
* <remote_pubkey> OP_CHECKSIGVERIFY 1 OP_CHECKSEQUENCEVERIFY
*/
u8 *anchor_to_remote_redeem(const tal_t *ctx,
const struct pubkey *remote_key)
{
u8 *script = tal_arr(ctx, u8, 0);
add_push_key(&script, remote_key);
add_op(&script, OP_CHECKSIGVERIFY);
add_number(&script, 1);
add_op(&script, OP_CHECKSEQUENCEVERIFY);
return script;
}
/* Create a witness which spends the 2of2. */ /* Create a witness which spends the 2of2. */
u8 **bitcoin_witness_2of2(const tal_t *ctx, u8 **bitcoin_witness_2of2(const tal_t *ctx,
const struct bitcoin_signature *sig1, const struct bitcoin_signature *sig1,

4
bitcoin/script.h

@ -57,6 +57,10 @@ u8 *scriptpubkey_p2wpkh_derkey(const tal_t *ctx, const u8 der[33]);
u8 *scriptpubkey_witness_raw(const tal_t *ctx, u8 version, u8 *scriptpubkey_witness_raw(const tal_t *ctx, u8 version,
const u8 *wprog, size_t wprog_size); const u8 *wprog, size_t wprog_size);
/* To-remotekey with csv 1 delay. */
u8 *anchor_to_remote_redeem(const tal_t *ctx,
const struct pubkey *remote_key);
/* Create a witness which spends the 2of2. */ /* Create a witness which spends the 2of2. */
u8 **bitcoin_witness_2of2(const tal_t *ctx, u8 **bitcoin_witness_2of2(const tal_t *ctx,
const struct bitcoin_signature *sig1, const struct bitcoin_signature *sig1,

27
channeld/commit_tx.c

@ -260,21 +260,34 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
*/ */
if (amount_msat_greater_eq_sat(other_pay, dust_limit)) { if (amount_msat_greater_eq_sat(other_pay, dust_limit)) {
struct amount_sat amount = amount_msat_to_sat_round_down(other_pay); struct amount_sat amount = amount_msat_to_sat_round_down(other_pay);
u8 *p2wpkh = u8 *scriptpubkey;
scriptpubkey_p2wpkh(tx, &keyset->other_payment_key); int pos;
/* BOLT #3:
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3:
* *
* #### `to_remote` Output * #### `to_remote` Output
* *
* This output sends funds to the other peer and thus is a simple * If `option_anchor_outputs` applies to the commitment
* P2WPKH to `remotepubkey`. * transaction, the `to_remote` output is encumbered by a one
* block csv lock.
* <remote_pubkey> OP_CHECKSIGVERIFY 1 OP_CHECKSEQUENCEVERIFY
*
*...
* Otherwise, this output is a simple P2WPKH to `remotepubkey`.
*/ */
int pos = bitcoin_tx_add_output(tx, p2wpkh, NULL, amount); if (option_anchor_outputs) {
scriptpubkey = scriptpubkey_p2wsh(tmpctx,
anchor_to_remote_redeem(tmpctx, &keyset->other_payment_key));
} else {
scriptpubkey = scriptpubkey_p2wpkh(tmpctx,
&keyset->other_payment_key);
}
pos = bitcoin_tx_add_output(tx, scriptpubkey, NULL, amount);
assert(pos == n); assert(pos == n);
(*htlcmap)[n] = direct_outputs ? dummy_to_remote : NULL; (*htlcmap)[n] = direct_outputs ? dummy_to_remote : NULL;
/* We don't assign cltvs[n]: if we use it, order doesn't matter. /* We don't assign cltvs[n]: if we use it, order doesn't matter.
* However, valgrind will warn us something wierd is happening */ * However, valgrind will warn us something wierd is happening */
SUPERVERBOSE("# to-remote amount %s P2WPKH(%s)\n", SUPERVERBOSE("# to-remote amount %s key %s\n",
type_to_string(tmpctx, struct amount_sat, type_to_string(tmpctx, struct amount_sat,
&amount), &amount),
type_to_string(tmpctx, struct pubkey, type_to_string(tmpctx, struct pubkey,

25
common/initial_commit_tx.c

@ -223,17 +223,28 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
* output](#to_remote-output). * output](#to_remote-output).
*/ */
if (amount_msat_greater_eq_sat(other_pay, dust_limit)) { if (amount_msat_greater_eq_sat(other_pay, dust_limit)) {
/* BOLT #3: /* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3:
* *
* #### `to_remote` Output * If `option_anchor_outputs` applies to the commitment
* transaction, the `to_remote` output is encumbered by a one
* block csv lock.
* <remote_pubkey> OP_CHECKSIGVERIFY 1 OP_CHECKSEQUENCEVERIFY
* *
* This output sends funds to the other peer and thus is a simple *...
* P2WPKH to `remotepubkey`. * Otherwise, this output is a simple P2WPKH to `remotepubkey`.
*/ */
u8 *scriptpubkey;
int pos;
amount = amount_msat_to_sat_round_down(other_pay); amount = amount_msat_to_sat_round_down(other_pay);
int pos = bitcoin_tx_add_output( if (option_anchor_outputs) {
tx, scriptpubkey_p2wpkh(tx, &keyset->other_payment_key), scriptpubkey = scriptpubkey_p2wsh(tmpctx,
NULL, amount); anchor_to_remote_redeem(tmpctx, &keyset->other_payment_key));
} else {
scriptpubkey = scriptpubkey_p2wpkh(tmpctx,
&keyset->other_payment_key);
}
pos = bitcoin_tx_add_output(tx, scriptpubkey, NULL, amount);
assert(pos == n); assert(pos == n);
output_order[n] = dummy_remote; output_order[n] = dummy_remote;
n++; n++;

Loading…
Cancel
Save