mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
htlc_tx: use keyset abstraction.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
4bfaaef408
commit
04db39558d
@ -214,11 +214,11 @@ static void add_htlcs(struct bitcoin_tx ***txs,
|
|||||||
|
|
||||||
if (htlc_owner(htlc) == side) {
|
if (htlc_owner(htlc) == side) {
|
||||||
tx = htlc_timeout_tx(*txs, &txid, i,
|
tx = htlc_timeout_tx(*txs, &txid, i,
|
||||||
htlc,
|
htlc->msatoshi,
|
||||||
|
htlc->expiry.locktime,
|
||||||
to_self_delay(channel, side),
|
to_self_delay(channel, side),
|
||||||
&keyset->self_revocation_key,
|
feerate_per_kw,
|
||||||
&keyset->self_delayed_payment_key,
|
keyset);
|
||||||
feerate_per_kw);
|
|
||||||
wscript = bitcoin_wscript_htlc_offer(*wscripts,
|
wscript = bitcoin_wscript_htlc_offer(*wscripts,
|
||||||
&keyset->self_payment_key,
|
&keyset->self_payment_key,
|
||||||
&keyset->other_payment_key,
|
&keyset->other_payment_key,
|
||||||
@ -226,11 +226,10 @@ static void add_htlcs(struct bitcoin_tx ***txs,
|
|||||||
&keyset->self_revocation_key);
|
&keyset->self_revocation_key);
|
||||||
} else {
|
} else {
|
||||||
tx = htlc_success_tx(*txs, &txid, i,
|
tx = htlc_success_tx(*txs, &txid, i,
|
||||||
htlc,
|
htlc->msatoshi,
|
||||||
to_self_delay(channel, side),
|
to_self_delay(channel, side),
|
||||||
&keyset->self_revocation_key,
|
feerate_per_kw,
|
||||||
&keyset->self_delayed_payment_key,
|
keyset);
|
||||||
feerate_per_kw);
|
|
||||||
wscript = bitcoin_wscript_htlc_receive(*wscripts,
|
wscript = bitcoin_wscript_htlc_receive(*wscripts,
|
||||||
&htlc->expiry,
|
&htlc->expiry,
|
||||||
&keyset->self_payment_key,
|
&keyset->self_payment_key,
|
||||||
|
@ -3,11 +3,12 @@
|
|||||||
#include <bitcoin/tx.h>
|
#include <bitcoin/tx.h>
|
||||||
#include <lightningd/commit_tx.h>
|
#include <lightningd/commit_tx.h>
|
||||||
#include <lightningd/htlc_tx.h>
|
#include <lightningd/htlc_tx.h>
|
||||||
|
#include <lightningd/keyset.h>
|
||||||
|
|
||||||
static struct bitcoin_tx *htlc_tx(const tal_t *ctx,
|
static struct bitcoin_tx *htlc_tx(const tal_t *ctx,
|
||||||
const struct sha256_double *commit_txid,
|
const struct sha256_double *commit_txid,
|
||||||
unsigned int commit_output_number,
|
unsigned int commit_output_number,
|
||||||
const struct htlc *htlc,
|
u64 msatoshi,
|
||||||
u16 to_self_delay,
|
u16 to_self_delay,
|
||||||
const struct pubkey *revocation_pubkey,
|
const struct pubkey *revocation_pubkey,
|
||||||
const struct pubkey *local_delayedkey,
|
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;
|
tx->input[0].index = commit_output_number;
|
||||||
|
|
||||||
/* We need amount for signing. */
|
/* We need amount for signing. */
|
||||||
amount = htlc->msatoshi / 1000;
|
amount = msatoshi / 1000;
|
||||||
tx->input[0].amount = tal_dup(tx, u64, &amount);
|
tx->input[0].amount = tal_dup(tx, u64, &amount);
|
||||||
|
|
||||||
/* BOLT #3:
|
/* 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,
|
struct bitcoin_tx *htlc_success_tx(const tal_t *ctx,
|
||||||
const struct sha256_double *commit_txid,
|
const struct sha256_double *commit_txid,
|
||||||
unsigned int commit_output_number,
|
unsigned int commit_output_number,
|
||||||
const struct htlc *received_htlc,
|
u64 htlc_msatoshi,
|
||||||
u16 to_self_delay,
|
u16 to_self_delay,
|
||||||
const struct pubkey *revocation_pubkey,
|
u64 feerate_per_kw,
|
||||||
const struct pubkey *local_delayedkey,
|
const struct keyset *keyset)
|
||||||
u64 feerate_per_kw)
|
|
||||||
{
|
{
|
||||||
/* BOLT #3:
|
/* BOLT #3:
|
||||||
* * locktime: `0` for HTLC-Success, `cltv_expiry` for HTLC-Timeout.
|
* * locktime: `0` for HTLC-Success, `cltv_expiry` for HTLC-Timeout.
|
||||||
*/
|
*/
|
||||||
return htlc_tx(ctx, commit_txid, commit_output_number, received_htlc,
|
return htlc_tx(ctx, commit_txid, commit_output_number, htlc_msatoshi,
|
||||||
to_self_delay, revocation_pubkey, local_delayedkey,
|
to_self_delay,
|
||||||
|
&keyset->self_revocation_key,
|
||||||
|
&keyset->self_delayed_payment_key,
|
||||||
htlc_success_fee(feerate_per_kw), 0);
|
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,
|
struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx,
|
||||||
const struct sha256_double *commit_txid,
|
const struct sha256_double *commit_txid,
|
||||||
unsigned int commit_output_number,
|
unsigned int commit_output_number,
|
||||||
const struct htlc *offered_htlc,
|
u64 htlc_msatoshi,
|
||||||
|
u32 cltv_expiry,
|
||||||
u16 to_self_delay,
|
u16 to_self_delay,
|
||||||
const struct pubkey *revocation_pubkey,
|
u64 feerate_per_kw,
|
||||||
const struct pubkey *local_delayedkey,
|
const struct keyset *keyset)
|
||||||
u64 feerate_per_kw)
|
|
||||||
{
|
{
|
||||||
/* BOLT #3:
|
/* BOLT #3:
|
||||||
* * locktime: `0` for HTLC-Success, `cltv_expiry` for HTLC-Timeout.
|
* * locktime: `0` for HTLC-Success, `cltv_expiry` for HTLC-Timeout.
|
||||||
*/
|
*/
|
||||||
return htlc_tx(ctx, commit_txid, commit_output_number, offered_htlc,
|
return htlc_tx(ctx, commit_txid, commit_output_number, htlc_msatoshi,
|
||||||
to_self_delay, revocation_pubkey, local_delayedkey,
|
to_self_delay,
|
||||||
|
&keyset->self_revocation_key,
|
||||||
|
&keyset->self_delayed_payment_key,
|
||||||
htlc_timeout_fee(feerate_per_kw),
|
htlc_timeout_fee(feerate_per_kw),
|
||||||
offered_htlc->expiry.locktime);
|
cltv_expiry);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fill in the witness for HTLC-timeout tx produced above. */
|
/* Fill in the witness for HTLC-timeout tx produced above. */
|
||||||
|
@ -12,11 +12,10 @@ struct sha256_double;
|
|||||||
struct bitcoin_tx *htlc_success_tx(const tal_t *ctx,
|
struct bitcoin_tx *htlc_success_tx(const tal_t *ctx,
|
||||||
const struct sha256_double *commit_txid,
|
const struct sha256_double *commit_txid,
|
||||||
unsigned int commit_output_number,
|
unsigned int commit_output_number,
|
||||||
const struct htlc *received_htlc,
|
u64 htlc_msatoshi,
|
||||||
u16 to_self_delay,
|
u16 to_self_delay,
|
||||||
const struct pubkey *revocation_pubkey,
|
u64 feerate_per_kw,
|
||||||
const struct pubkey *local_delayedkey,
|
const struct keyset *keyset);
|
||||||
u64 feerate_per_kw);
|
|
||||||
|
|
||||||
/* Fill in the witness for HTLC-success tx produced above. */
|
/* Fill in the witness for HTLC-success tx produced above. */
|
||||||
void htlc_success_tx_add_witness(struct bitcoin_tx *htlc_success,
|
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,
|
struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx,
|
||||||
const struct sha256_double *commit_txid,
|
const struct sha256_double *commit_txid,
|
||||||
unsigned int commit_output_number,
|
unsigned int commit_output_number,
|
||||||
const struct htlc *offered_htlc,
|
u64 htlc_msatoshi,
|
||||||
|
u32 cltv_expiry,
|
||||||
u16 to_self_delay,
|
u16 to_self_delay,
|
||||||
const struct pubkey *revocation_pubkey,
|
u64 feerate_per_kw,
|
||||||
const struct pubkey *local_delayedkey,
|
const struct keyset *keyset);
|
||||||
u64 feerate_per_kw);
|
|
||||||
|
|
||||||
/* Fill in the witness for HTLC-timeout tx produced above. */
|
/* Fill in the witness for HTLC-timeout tx produced above. */
|
||||||
void htlc_timeout_tx_add_witness(struct bitcoin_tx *htlc_timeout,
|
void htlc_timeout_tx_add_witness(struct bitcoin_tx *htlc_timeout,
|
||||||
|
@ -208,6 +208,7 @@ static void report_htlcs(const struct bitcoin_tx *tx,
|
|||||||
struct sha256_double txid;
|
struct sha256_double txid;
|
||||||
struct bitcoin_tx **htlc_tx;
|
struct bitcoin_tx **htlc_tx;
|
||||||
secp256k1_ecdsa_signature *remotesig;
|
secp256k1_ecdsa_signature *remotesig;
|
||||||
|
struct keyset keyset;
|
||||||
u8 **wscript;
|
u8 **wscript;
|
||||||
|
|
||||||
htlc_tx = tal_arrz(tmpctx, struct bitcoin_tx *, tal_count(htlc_map));
|
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);
|
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++) {
|
for (i = 0; i < tal_count(htlc_map); i++) {
|
||||||
const struct htlc *htlc = 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) {
|
if (htlc_owner(htlc) == LOCAL) {
|
||||||
htlc_tx[i] = htlc_timeout_tx(htlc_tx, &txid, i,
|
htlc_tx[i] = htlc_timeout_tx(htlc_tx, &txid, i,
|
||||||
htlc, to_self_delay,
|
htlc->msatoshi,
|
||||||
remote_revocation_key,
|
htlc->expiry.locktime,
|
||||||
local_delayedkey,
|
to_self_delay,
|
||||||
feerate_per_kw);
|
feerate_per_kw,
|
||||||
|
&keyset);
|
||||||
wscript[i] = bitcoin_wscript_htlc_offer(tmpctx,
|
wscript[i] = bitcoin_wscript_htlc_offer(tmpctx,
|
||||||
localkey,
|
localkey,
|
||||||
remotekey,
|
remotekey,
|
||||||
@ -243,10 +252,10 @@ static void report_htlcs(const struct bitcoin_tx *tx,
|
|||||||
remote_revocation_key);
|
remote_revocation_key);
|
||||||
} else {
|
} else {
|
||||||
htlc_tx[i] = htlc_success_tx(htlc_tx, &txid, i,
|
htlc_tx[i] = htlc_success_tx(htlc_tx, &txid, i,
|
||||||
htlc, to_self_delay,
|
htlc->msatoshi,
|
||||||
remote_revocation_key,
|
to_self_delay,
|
||||||
local_delayedkey,
|
feerate_per_kw,
|
||||||
feerate_per_kw);
|
&keyset);
|
||||||
wscript[i] = bitcoin_wscript_htlc_receive(tmpctx,
|
wscript[i] = bitcoin_wscript_htlc_receive(tmpctx,
|
||||||
&htlc->expiry,
|
&htlc->expiry,
|
||||||
localkey,
|
localkey,
|
||||||
|
Loading…
Reference in New Issue
Block a user