mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +01:00
script: make "sig_and_empty" more generic, make htlc tx witness fns clearer.
For non-delayed HTLC success spends, we have a similar pattern ("<sig> <preimage> <wscript>") so a we want to use the same function. The other routines don't say "witness" in them, and should. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
86ecc6a058
commit
6ef64cd52b
4 changed files with 43 additions and 40 deletions
|
@ -422,14 +422,15 @@ bool is_p2wpkh(const u8 *script)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 **bitcoin_witness_sig_and_empty(const tal_t *ctx,
|
u8 **bitcoin_witness_sig_and_element(const tal_t *ctx,
|
||||||
const secp256k1_ecdsa_signature *sig,
|
const secp256k1_ecdsa_signature *sig,
|
||||||
const u8 *witnessscript)
|
const void *elem, size_t elemsize,
|
||||||
|
const u8 *witnessscript)
|
||||||
{
|
{
|
||||||
u8 **witness = tal_arr(ctx, u8 *, 3);
|
u8 **witness = tal_arr(ctx, u8 *, 3);
|
||||||
|
|
||||||
witness[0] = stack_sig(witness, sig);
|
witness[0] = stack_sig(witness, sig);
|
||||||
witness[1] = NULL;
|
witness[1] = tal_dup_arr(witness, u8, elem, elemsize, 0);
|
||||||
witness[2] = tal_dup_arr(witness, u8,
|
witness[2] = tal_dup_arr(witness, u8,
|
||||||
witnessscript, tal_count(witnessscript), 0);
|
witnessscript, tal_count(witnessscript), 0);
|
||||||
|
|
||||||
|
@ -662,10 +663,10 @@ u8 *bitcoin_wscript_htlc_receive(const tal_t *ctx,
|
||||||
*...
|
*...
|
||||||
* * `txin[0]` witness stack: `0 <remotesig> <localsig> <payment_preimage>` for HTLC-Success, `0 <remotesig> <localsig> 0` for HTLC-Timeout.
|
* * `txin[0]` witness stack: `0 <remotesig> <localsig> <payment_preimage>` for HTLC-Success, `0 <remotesig> <localsig> 0` for HTLC-Timeout.
|
||||||
*/
|
*/
|
||||||
u8 **bitcoin_htlc_offer_spend_timeout(const tal_t *ctx,
|
u8 **bitcoin_witness_htlc_timeout_tx(const tal_t *ctx,
|
||||||
const secp256k1_ecdsa_signature *localsig,
|
const secp256k1_ecdsa_signature *localsig,
|
||||||
const secp256k1_ecdsa_signature *remotesig,
|
const secp256k1_ecdsa_signature *remotesig,
|
||||||
const u8 *wscript)
|
const u8 *wscript)
|
||||||
{
|
{
|
||||||
u8 **witness = tal_arr(ctx, u8 *, 5);
|
u8 **witness = tal_arr(ctx, u8 *, 5);
|
||||||
|
|
||||||
|
@ -678,11 +679,11 @@ u8 **bitcoin_htlc_offer_spend_timeout(const tal_t *ctx,
|
||||||
return witness;
|
return witness;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 **bitcoin_htlc_receive_spend_preimage(const tal_t *ctx,
|
u8 **bitcoin_witness_htlc_success_tx(const tal_t *ctx,
|
||||||
const secp256k1_ecdsa_signature *localsig,
|
const secp256k1_ecdsa_signature *localsig,
|
||||||
const secp256k1_ecdsa_signature *remotesig,
|
const secp256k1_ecdsa_signature *remotesig,
|
||||||
const struct preimage *preimage,
|
const struct preimage *preimage,
|
||||||
const u8 *wscript)
|
const u8 *wscript)
|
||||||
{
|
{
|
||||||
u8 **witness = tal_arr(ctx, u8 *, 5);
|
u8 **witness = tal_arr(ctx, u8 *, 5);
|
||||||
|
|
||||||
|
@ -694,7 +695,6 @@ u8 **bitcoin_htlc_receive_spend_preimage(const tal_t *ctx,
|
||||||
|
|
||||||
return witness;
|
return witness;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 *bitcoin_wscript_htlc_tx(const tal_t *ctx,
|
u8 *bitcoin_wscript_htlc_tx(const tal_t *ctx,
|
||||||
u16 to_self_delay,
|
u16 to_self_delay,
|
||||||
const struct pubkey *revocation_pubkey,
|
const struct pubkey *revocation_pubkey,
|
||||||
|
|
|
@ -66,10 +66,11 @@ u8 **bitcoin_witness_p2wpkh(const tal_t *ctx,
|
||||||
const secp256k1_ecdsa_signature *sig,
|
const secp256k1_ecdsa_signature *sig,
|
||||||
const struct pubkey *key);
|
const struct pubkey *key);
|
||||||
|
|
||||||
/* Create a witness which contains sig, an empty entry, and the witnessscript */
|
/* Create a witness which contains sig, another entry, and the witnessscript */
|
||||||
u8 **bitcoin_witness_sig_and_empty(const tal_t *ctx,
|
u8 **bitcoin_witness_sig_and_element(const tal_t *ctx,
|
||||||
const secp256k1_ecdsa_signature *sig,
|
const secp256k1_ecdsa_signature *sig,
|
||||||
const u8 *witnessscript);
|
const void *elem, size_t elemsize,
|
||||||
|
const u8 *witnessscript);
|
||||||
|
|
||||||
/* BOLT #3 to-local output */
|
/* BOLT #3 to-local output */
|
||||||
u8 *bitcoin_wscript_to_local(const tal_t *ctx,
|
u8 *bitcoin_wscript_to_local(const tal_t *ctx,
|
||||||
|
@ -86,21 +87,21 @@ u8 *bitcoin_wscript_htlc_offer(const tal_t *ctx,
|
||||||
const struct pubkey *remotekey,
|
const struct pubkey *remotekey,
|
||||||
const struct sha256 *payment_hash,
|
const struct sha256 *payment_hash,
|
||||||
const struct pubkey *revocationkey);
|
const struct pubkey *revocationkey);
|
||||||
u8 **bitcoin_htlc_offer_spend_timeout(const tal_t *ctx,
|
u8 **bitcoin_witness_htlc_timeout_tx(const tal_t *ctx,
|
||||||
const secp256k1_ecdsa_signature *localsig,
|
const secp256k1_ecdsa_signature *localsig,
|
||||||
const secp256k1_ecdsa_signature *remotesig,
|
const secp256k1_ecdsa_signature *remotesig,
|
||||||
const u8 *wscript);
|
const u8 *wscript);
|
||||||
u8 *bitcoin_wscript_htlc_receive(const tal_t *ctx,
|
u8 *bitcoin_wscript_htlc_receive(const tal_t *ctx,
|
||||||
const struct abs_locktime *htlc_abstimeout,
|
const struct abs_locktime *htlc_abstimeout,
|
||||||
const struct pubkey *localkey,
|
const struct pubkey *localkey,
|
||||||
const struct pubkey *remotekey,
|
const struct pubkey *remotekey,
|
||||||
const struct sha256 *payment_hash,
|
const struct sha256 *payment_hash,
|
||||||
const struct pubkey *revocationkey);
|
const struct pubkey *revocationkey);
|
||||||
u8 **bitcoin_htlc_receive_spend_preimage(const tal_t *ctx,
|
u8 **bitcoin_witness_htlc_success_tx(const tal_t *ctx,
|
||||||
const secp256k1_ecdsa_signature *localsig,
|
const secp256k1_ecdsa_signature *localsig,
|
||||||
const secp256k1_ecdsa_signature *remotesig,
|
const secp256k1_ecdsa_signature *remotesig,
|
||||||
const struct preimage *preimage,
|
const struct preimage *preimage,
|
||||||
const u8 *wscript);
|
const u8 *wscript);
|
||||||
|
|
||||||
/* Underlying functions for penalties, where we only keep ripemd160 */
|
/* Underlying functions for penalties, where we only keep ripemd160 */
|
||||||
u8 *bitcoin_wscript_htlc_offer_ripemd160(const tal_t *ctx,
|
u8 *bitcoin_wscript_htlc_offer_ripemd160(const tal_t *ctx,
|
||||||
|
|
|
@ -109,10 +109,10 @@ void htlc_success_tx_add_witness(struct bitcoin_tx *htlc_success,
|
||||||
&hash, revocationkey);
|
&hash, revocationkey);
|
||||||
|
|
||||||
htlc_success->input[0].witness
|
htlc_success->input[0].witness
|
||||||
= bitcoin_htlc_receive_spend_preimage(htlc_success->input,
|
= bitcoin_witness_htlc_success_tx(htlc_success->input,
|
||||||
localsig, remotesig,
|
localsig, remotesig,
|
||||||
payment_preimage,
|
payment_preimage,
|
||||||
wscript);
|
wscript);
|
||||||
tal_free(wscript);
|
tal_free(wscript);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,9 +150,9 @@ void htlc_timeout_tx_add_witness(struct bitcoin_tx *htlc_timeout,
|
||||||
payment_hash, revocationkey);
|
payment_hash, revocationkey);
|
||||||
|
|
||||||
htlc_timeout->input[0].witness
|
htlc_timeout->input[0].witness
|
||||||
= bitcoin_htlc_offer_spend_timeout(htlc_timeout->input,
|
= bitcoin_witness_htlc_timeout_tx(htlc_timeout->input,
|
||||||
localsig, remotesig,
|
localsig, remotesig,
|
||||||
wscript);
|
wscript);
|
||||||
tal_free(wscript);
|
tal_free(wscript);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -659,8 +659,10 @@ static struct bitcoin_tx *tx_to_us(const tal_t *ctx,
|
||||||
tx->output[0].amount -= fee;
|
tx->output[0].amount -= fee;
|
||||||
|
|
||||||
sign_tx_input(tx, 0, NULL, wscript, privkey, pubkey, &sig);
|
sign_tx_input(tx, 0, NULL, wscript, privkey, pubkey, &sig);
|
||||||
tx->input[0].witness = bitcoin_witness_sig_and_empty(tx->input,
|
tx->input[0].witness = bitcoin_witness_sig_and_element(tx->input,
|
||||||
&sig, wscript);
|
&sig,
|
||||||
|
NULL, 0,
|
||||||
|
wscript);
|
||||||
return tx;
|
return tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -711,10 +713,10 @@ static void resolve_our_htlc_ourcommit(struct tracked_output *out,
|
||||||
&keyset->self_payment_key, &localsig);
|
&keyset->self_payment_key, &localsig);
|
||||||
|
|
||||||
tx->input[0].witness
|
tx->input[0].witness
|
||||||
= bitcoin_htlc_offer_spend_timeout(tx->input,
|
= bitcoin_witness_htlc_timeout_tx(tx->input,
|
||||||
&localsig,
|
&localsig,
|
||||||
remotesig,
|
remotesig,
|
||||||
wscript);
|
wscript);
|
||||||
|
|
||||||
propose_resolution_at_block(out, tx, htlc->cltv_expiry,
|
propose_resolution_at_block(out, tx, htlc->cltv_expiry,
|
||||||
OUR_HTLC_TIMEOUT_TO_US);
|
OUR_HTLC_TIMEOUT_TO_US);
|
||||||
|
|
Loading…
Add table
Reference in a new issue