Browse Source

htlc_tx: use keyset abstraction.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
04db39558d
  1. 15
      lightningd/channel.c
  2. 34
      lightningd/htlc_tx.c
  3. 15
      lightningd/htlc_tx.h
  4. 25
      lightningd/test/run-commit_tx.c

15
lightningd/channel.c

@ -214,11 +214,11 @@ static void add_htlcs(struct bitcoin_tx ***txs,
if (htlc_owner(htlc) == side) {
tx = htlc_timeout_tx(*txs, &txid, i,
htlc,
htlc->msatoshi,
htlc->expiry.locktime,
to_self_delay(channel, side),
&keyset->self_revocation_key,
&keyset->self_delayed_payment_key,
feerate_per_kw);
feerate_per_kw,
keyset);
wscript = bitcoin_wscript_htlc_offer(*wscripts,
&keyset->self_payment_key,
&keyset->other_payment_key,
@ -226,11 +226,10 @@ static void add_htlcs(struct bitcoin_tx ***txs,
&keyset->self_revocation_key);
} else {
tx = htlc_success_tx(*txs, &txid, i,
htlc,
htlc->msatoshi,
to_self_delay(channel, side),
&keyset->self_revocation_key,
&keyset->self_delayed_payment_key,
feerate_per_kw);
feerate_per_kw,
keyset);
wscript = bitcoin_wscript_htlc_receive(*wscripts,
&htlc->expiry,
&keyset->self_payment_key,

34
lightningd/htlc_tx.c

@ -3,11 +3,12 @@
#include <bitcoin/tx.h>
#include <lightningd/commit_tx.h>
#include <lightningd/htlc_tx.h>
#include <lightningd/keyset.h>
static struct bitcoin_tx *htlc_tx(const tal_t *ctx,
const struct sha256_double *commit_txid,
unsigned int commit_output_number,
const struct htlc *htlc,
u64 msatoshi,
u16 to_self_delay,
const struct pubkey *revocation_pubkey,
const struct pubkey *local_delayedkey,
@ -47,7 +48,7 @@ static struct bitcoin_tx *htlc_tx(const tal_t *ctx,
tx->input[0].index = commit_output_number;
/* We need amount for signing. */
amount = htlc->msatoshi / 1000;
amount = msatoshi / 1000;
tx->input[0].amount = tal_dup(tx, u64, &amount);
/* BOLT #3:
@ -74,17 +75,18 @@ static struct bitcoin_tx *htlc_tx(const tal_t *ctx,
struct bitcoin_tx *htlc_success_tx(const tal_t *ctx,
const struct sha256_double *commit_txid,
unsigned int commit_output_number,
const struct htlc *received_htlc,
u64 htlc_msatoshi,
u16 to_self_delay,
const struct pubkey *revocation_pubkey,
const struct pubkey *local_delayedkey,
u64 feerate_per_kw)
u64 feerate_per_kw,
const struct keyset *keyset)
{
/* BOLT #3:
* * locktime: `0` for HTLC-Success, `cltv_expiry` for HTLC-Timeout.
*/
return htlc_tx(ctx, commit_txid, commit_output_number, received_htlc,
to_self_delay, revocation_pubkey, local_delayedkey,
return htlc_tx(ctx, commit_txid, commit_output_number, htlc_msatoshi,
to_self_delay,
&keyset->self_revocation_key,
&keyset->self_delayed_payment_key,
htlc_success_fee(feerate_per_kw), 0);
}
@ -118,19 +120,21 @@ void htlc_success_tx_add_witness(struct bitcoin_tx *htlc_success,
struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx,
const struct sha256_double *commit_txid,
unsigned int commit_output_number,
const struct htlc *offered_htlc,
u64 htlc_msatoshi,
u32 cltv_expiry,
u16 to_self_delay,
const struct pubkey *revocation_pubkey,
const struct pubkey *local_delayedkey,
u64 feerate_per_kw)
u64 feerate_per_kw,
const struct keyset *keyset)
{
/* BOLT #3:
* * locktime: `0` for HTLC-Success, `cltv_expiry` for HTLC-Timeout.
*/
return htlc_tx(ctx, commit_txid, commit_output_number, offered_htlc,
to_self_delay, revocation_pubkey, local_delayedkey,
return htlc_tx(ctx, commit_txid, commit_output_number, htlc_msatoshi,
to_self_delay,
&keyset->self_revocation_key,
&keyset->self_delayed_payment_key,
htlc_timeout_fee(feerate_per_kw),
offered_htlc->expiry.locktime);
cltv_expiry);
}
/* Fill in the witness for HTLC-timeout tx produced above. */

15
lightningd/htlc_tx.h

@ -12,11 +12,10 @@ struct sha256_double;
struct bitcoin_tx *htlc_success_tx(const tal_t *ctx,
const struct sha256_double *commit_txid,
unsigned int commit_output_number,
const struct htlc *received_htlc,
u64 htlc_msatoshi,
u16 to_self_delay,
const struct pubkey *revocation_pubkey,
const struct pubkey *local_delayedkey,
u64 feerate_per_kw);
u64 feerate_per_kw,
const struct keyset *keyset);
/* Fill in the witness for HTLC-success tx produced above. */
void htlc_success_tx_add_witness(struct bitcoin_tx *htlc_success,
@ -33,11 +32,11 @@ void htlc_success_tx_add_witness(struct bitcoin_tx *htlc_success,
struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx,
const struct sha256_double *commit_txid,
unsigned int commit_output_number,
const struct htlc *offered_htlc,
u64 htlc_msatoshi,
u32 cltv_expiry,
u16 to_self_delay,
const struct pubkey *revocation_pubkey,
const struct pubkey *local_delayedkey,
u64 feerate_per_kw);
u64 feerate_per_kw,
const struct keyset *keyset);
/* Fill in the witness for HTLC-timeout tx produced above. */
void htlc_timeout_tx_add_witness(struct bitcoin_tx *htlc_timeout,

25
lightningd/test/run-commit_tx.c

@ -208,6 +208,7 @@ static void report_htlcs(const struct bitcoin_tx *tx,
struct sha256_double txid;
struct bitcoin_tx **htlc_tx;
secp256k1_ecdsa_signature *remotesig;
struct keyset keyset;
u8 **wscript;
htlc_tx = tal_arrz(tmpctx, struct bitcoin_tx *, tal_count(htlc_map));
@ -224,6 +225,13 @@ static void report_htlcs(const struct bitcoin_tx *tx,
printf("num_htlcs: %zu\n", n);
/* FIXME: naming here is kind of backwards: local revocation key
* is derived from remote revocation basepoint, but it's local */
keyset.self_revocation_key = *remote_revocation_key;
keyset.self_delayed_payment_key = *local_delayedkey;
keyset.self_payment_key = *localkey;
keyset.other_payment_key = *remotekey;
for (i = 0; i < tal_count(htlc_map); i++) {
const struct htlc *htlc = htlc_map[i];
@ -232,10 +240,11 @@ static void report_htlcs(const struct bitcoin_tx *tx,
if (htlc_owner(htlc) == LOCAL) {
htlc_tx[i] = htlc_timeout_tx(htlc_tx, &txid, i,
htlc, to_self_delay,
remote_revocation_key,
local_delayedkey,
feerate_per_kw);
htlc->msatoshi,
htlc->expiry.locktime,
to_self_delay,
feerate_per_kw,
&keyset);
wscript[i] = bitcoin_wscript_htlc_offer(tmpctx,
localkey,
remotekey,
@ -243,10 +252,10 @@ static void report_htlcs(const struct bitcoin_tx *tx,
remote_revocation_key);
} else {
htlc_tx[i] = htlc_success_tx(htlc_tx, &txid, i,
htlc, to_self_delay,
remote_revocation_key,
local_delayedkey,
feerate_per_kw);
htlc->msatoshi,
to_self_delay,
feerate_per_kw,
&keyset);
wscript[i] = bitcoin_wscript_htlc_receive(tmpctx,
&htlc->expiry,
localkey,

Loading…
Cancel
Save