mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-26 20:30:59 +01:00
psbt: remove input_amounts from bitcoin tx
Instead we will stash them into the PSBT as a utxo/witness record (which includes the amount)
This commit is contained in:
parent
85f395f7d4
commit
a04f0fe250
22 changed files with 153 additions and 155 deletions
|
@ -1,6 +1,9 @@
|
|||
#include <assert.h>
|
||||
#include <bitcoin/psbt.h>
|
||||
#include <bitcoin/script.h>
|
||||
#include <ccan/cast/cast.h>
|
||||
#include <common/amount.h>
|
||||
#include <common/utils.h>
|
||||
#include <string.h>
|
||||
#include <wally_psbt.h>
|
||||
#include <wally_transaction.h>
|
||||
|
@ -72,6 +75,7 @@ struct wally_psbt_input *psbt_add_input(struct wally_psbt *psbt,
|
|||
tx = psbt->tx;
|
||||
assert(insert_at <= tx->num_inputs);
|
||||
wally_tx_add_input(tx, input);
|
||||
|
||||
tmp_in = tx->inputs[tx->num_inputs - 1];
|
||||
MAKE_ROOM(tx->inputs, insert_at, tx->num_inputs);
|
||||
tx->inputs[insert_at] = tmp_in;
|
||||
|
@ -137,6 +141,71 @@ void psbt_rm_output(struct wally_psbt *psbt,
|
|||
REMOVE_ELEM(psbt->outputs, remove_at, psbt->num_outputs);
|
||||
psbt->num_outputs -= 1;
|
||||
}
|
||||
void psbt_input_set_prev_utxo(struct wally_psbt *psbt, size_t in,
|
||||
const u8 *scriptPubkey, struct amount_sat amt)
|
||||
{
|
||||
struct wally_tx_output *prev_out;
|
||||
int wally_err;
|
||||
u8 *scriptpk;
|
||||
|
||||
assert(psbt->num_inputs > in);
|
||||
if (scriptPubkey) {
|
||||
assert(is_p2wsh(scriptPubkey, NULL) || is_p2wpkh(scriptPubkey, NULL)
|
||||
|| is_p2sh(scriptPubkey, NULL));
|
||||
scriptpk = cast_const(u8 *, scriptPubkey);
|
||||
} else {
|
||||
/* Adding a NULL scriptpubkey is an error, *however* there is the
|
||||
* possiblity we're spending a UTXO that we didn't save the
|
||||
* scriptpubkey data for. in this case we set it to an 'empty'
|
||||
* or zero-len script */
|
||||
scriptpk = tal_arr(psbt, u8, 1);
|
||||
scriptpk[0] = 0x00;
|
||||
}
|
||||
|
||||
wally_err = wally_tx_output_init_alloc(amt.satoshis, /* Raw: type conv */
|
||||
scriptpk,
|
||||
tal_bytelen(scriptpk),
|
||||
&prev_out);
|
||||
assert(wally_err == WALLY_OK);
|
||||
wally_err = wally_psbt_input_set_witness_utxo(&psbt->inputs[in],
|
||||
prev_out);
|
||||
assert(wally_err == WALLY_OK);
|
||||
tal_steal(psbt, psbt->inputs[in].witness_utxo);
|
||||
}
|
||||
|
||||
void psbt_input_set_prev_utxo_wscript(struct wally_psbt *psbt, size_t in,
|
||||
const u8 *wscript, struct amount_sat amt)
|
||||
{
|
||||
int wally_err;
|
||||
const u8 *scriptPubkey;
|
||||
|
||||
if (wscript) {
|
||||
scriptPubkey = scriptpubkey_p2wsh(psbt, wscript);
|
||||
wally_err = wally_psbt_input_set_witness_script(&psbt->inputs[in],
|
||||
cast_const(u8 *, wscript),
|
||||
tal_bytelen(wscript));
|
||||
assert(wally_err == WALLY_OK);
|
||||
} else
|
||||
scriptPubkey = NULL;
|
||||
psbt_input_set_prev_utxo(psbt, in, scriptPubkey, amt);
|
||||
}
|
||||
|
||||
struct amount_sat psbt_input_get_amount(struct wally_psbt *psbt,
|
||||
size_t in)
|
||||
{
|
||||
struct amount_sat val;
|
||||
assert(in < psbt->num_inputs);
|
||||
if (psbt->inputs[in].witness_utxo) {
|
||||
val.satoshis = psbt->inputs[in].witness_utxo->satoshi; /* Raw: type conversion */
|
||||
} else if (psbt->inputs[in].non_witness_utxo) {
|
||||
int idx = psbt->tx->inputs[in].index;
|
||||
struct wally_tx *prev_tx = psbt->inputs[in].non_witness_utxo;
|
||||
val.satoshis = prev_tx->outputs[idx].satoshi; /* Raw: type conversion */
|
||||
} else
|
||||
abort();
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
void towire_psbt(u8 **pptr, const struct wally_psbt *psbt)
|
||||
{
|
||||
|
|
|
@ -10,6 +10,7 @@ struct wally_tx_output;
|
|||
struct wally_psbt;
|
||||
struct wally_psbt_input;
|
||||
struct wally_tx;
|
||||
struct amount_sat;
|
||||
|
||||
void psbt_destroy(struct wally_psbt *psbt);
|
||||
|
||||
|
@ -30,6 +31,13 @@ struct wally_psbt_output *psbt_add_output(struct wally_psbt *psbt,
|
|||
void psbt_rm_output(struct wally_psbt *psbt,
|
||||
size_t remove_at);
|
||||
|
||||
void psbt_input_set_prev_utxo(struct wally_psbt *psbt, size_t in,
|
||||
const u8 *wscript, struct amount_sat amt);
|
||||
void psbt_input_set_prev_utxo_wscript(struct wally_psbt *psbt, size_t in,
|
||||
const u8 *wscript, struct amount_sat amt);
|
||||
struct amount_sat psbt_input_get_amount(struct wally_psbt *psbt,
|
||||
size_t in);
|
||||
|
||||
void towire_psbt(u8 **pptr, const struct wally_psbt *psbt);
|
||||
struct wally_psbt *fromwire_psbt(const tal_t *ctx,
|
||||
const u8 **curosr, size_t *max);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "signature.h"
|
||||
#include "tx.h"
|
||||
#include <assert.h>
|
||||
#include <bitcoin/psbt.h>
|
||||
#include <ccan/cast/cast.h>
|
||||
#include <ccan/mem/mem.h>
|
||||
#include <common/type_to_string.h>
|
||||
|
@ -119,11 +120,15 @@ void bitcoin_tx_hash_for_sig(const struct bitcoin_tx *tx, unsigned int in,
|
|||
{
|
||||
int ret;
|
||||
u8 value[9];
|
||||
u64 satoshis = tx->input_amounts[in]->satoshis /* Raw: sig-helper */;
|
||||
u64 input_val_sats;
|
||||
struct amount_sat input_amt;
|
||||
int flags = WALLY_TX_FLAG_USE_WITNESS;
|
||||
|
||||
input_amt = psbt_input_get_amount(tx->psbt, in);
|
||||
input_val_sats = input_amt.satoshis; /* Raw: type conversion */
|
||||
|
||||
if (is_elements(chainparams)) {
|
||||
ret = wally_tx_confidential_value_from_satoshi(satoshis, value, sizeof(value));
|
||||
ret = wally_tx_confidential_value_from_satoshi(input_val_sats, value, sizeof(value));
|
||||
assert(ret == WALLY_OK);
|
||||
ret = wally_tx_get_elements_signature_hash(
|
||||
tx->wtx, in, script, tal_bytelen(script), value,
|
||||
|
@ -132,7 +137,7 @@ void bitcoin_tx_hash_for_sig(const struct bitcoin_tx *tx, unsigned int in,
|
|||
assert(ret == WALLY_OK);
|
||||
} else {
|
||||
ret = wally_tx_get_btc_signature_hash(
|
||||
tx->wtx, in, script, tal_bytelen(script), satoshis,
|
||||
tx->wtx, in, script, tal_bytelen(script), input_val_sats,
|
||||
sighash_type, flags, dest->sha.u.u8, sizeof(*dest));
|
||||
assert(ret == WALLY_OK);
|
||||
}
|
||||
|
|
|
@ -49,6 +49,18 @@ u16 fromwire_u16(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
|||
/* Generated stub for fromwire_u32 */
|
||||
u32 fromwire_u32(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_u32 called!\n"); abort(); }
|
||||
/* Generated stub for is_p2sh */
|
||||
bool is_p2sh(const u8 *script UNNEEDED, struct ripemd160 *addr UNNEEDED)
|
||||
{ fprintf(stderr, "is_p2sh called!\n"); abort(); }
|
||||
/* Generated stub for is_p2wpkh */
|
||||
bool is_p2wpkh(const u8 *script UNNEEDED, struct bitcoin_address *addr UNNEEDED)
|
||||
{ fprintf(stderr, "is_p2wpkh called!\n"); abort(); }
|
||||
/* Generated stub for is_p2wsh */
|
||||
bool is_p2wsh(const u8 *script UNNEEDED, struct sha256 *addr UNNEEDED)
|
||||
{ fprintf(stderr, "is_p2wsh called!\n"); abort(); }
|
||||
/* Generated stub for scriptpubkey_p2wsh */
|
||||
u8 *scriptpubkey_p2wsh(const tal_t *ctx UNNEEDED, const u8 *witnessscript UNNEEDED)
|
||||
{ fprintf(stderr, "scriptpubkey_p2wsh called!\n"); abort(); }
|
||||
/* Generated stub for towire_amount_sat */
|
||||
void towire_amount_sat(u8 **pptr UNNEEDED, const struct amount_sat sat UNNEEDED)
|
||||
{ fprintf(stderr, "towire_amount_sat called!\n"); abort(); }
|
||||
|
|
|
@ -50,6 +50,18 @@ u16 fromwire_u16(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
|||
/* Generated stub for fromwire_u32 */
|
||||
u32 fromwire_u32(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_u32 called!\n"); abort(); }
|
||||
/* Generated stub for is_p2sh */
|
||||
bool is_p2sh(const u8 *script UNNEEDED, struct ripemd160 *addr UNNEEDED)
|
||||
{ fprintf(stderr, "is_p2sh called!\n"); abort(); }
|
||||
/* Generated stub for is_p2wpkh */
|
||||
bool is_p2wpkh(const u8 *script UNNEEDED, struct bitcoin_address *addr UNNEEDED)
|
||||
{ fprintf(stderr, "is_p2wpkh called!\n"); abort(); }
|
||||
/* Generated stub for is_p2wsh */
|
||||
bool is_p2wsh(const u8 *script UNNEEDED, struct sha256 *addr UNNEEDED)
|
||||
{ fprintf(stderr, "is_p2wsh called!\n"); abort(); }
|
||||
/* Generated stub for scriptpubkey_p2wsh */
|
||||
u8 *scriptpubkey_p2wsh(const tal_t *ctx UNNEEDED, const u8 *witnessscript UNNEEDED)
|
||||
{ fprintf(stderr, "scriptpubkey_p2wsh called!\n"); abort(); }
|
||||
/* Generated stub for towire_amount_sat */
|
||||
void towire_amount_sat(u8 **pptr UNNEEDED, const struct amount_sat sat UNNEEDED)
|
||||
{ fprintf(stderr, "towire_amount_sat called!\n"); abort(); }
|
||||
|
|
46
bitcoin/tx.c
46
bitcoin/tx.c
|
@ -3,6 +3,7 @@
|
|||
#include <bitcoin/chainparams.h>
|
||||
#include <bitcoin/psbt.h>
|
||||
#include <bitcoin/pullpush.h>
|
||||
#include <bitcoin/script.h>
|
||||
#include <bitcoin/tx.h>
|
||||
#include <ccan/cast/cast.h>
|
||||
#include <ccan/crypto/sha256/sha256.h>
|
||||
|
@ -102,18 +103,15 @@ struct amount_sat bitcoin_tx_compute_fee_w_inputs(const struct bitcoin_tx *tx,
|
|||
|
||||
/**
|
||||
* Compute how much fee we are actually sending with this transaction.
|
||||
* Note that using this with a transaction without the input_amounts
|
||||
* initialized/populated is an error.
|
||||
*/
|
||||
struct amount_sat bitcoin_tx_compute_fee(const struct bitcoin_tx *tx)
|
||||
{
|
||||
struct amount_sat input_total = AMOUNT_SAT(0);
|
||||
struct amount_sat input_total = AMOUNT_SAT(0), input_amt;
|
||||
bool ok;
|
||||
|
||||
for (size_t i = 0; i < tal_count(tx->input_amounts); i++) {
|
||||
assert(tx->input_amounts[i]);
|
||||
ok = amount_sat_add(&input_total, input_total,
|
||||
*tx->input_amounts[i]);
|
||||
for (size_t i = 0; i < tx->psbt->num_inputs; i++) {
|
||||
input_amt = psbt_input_get_amount(tx->psbt, i);
|
||||
ok = amount_sat_add(&input_total, input_total, input_amt);
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
|
@ -173,16 +171,11 @@ int bitcoin_tx_add_input(struct bitcoin_tx *tx, const struct bitcoin_txid *txid,
|
|||
input->features = chainparams->is_elements ? WALLY_TX_IS_ELEMENTS : 0;
|
||||
wally_tx_add_input(tx->wtx, input);
|
||||
psbt_add_input(tx->psbt, input, i);
|
||||
|
||||
|
||||
|
||||
wally_tx_input_free(input);
|
||||
|
||||
/* Now store the input amount if we know it, so we can sign later */
|
||||
if (tal_count(tx->input_amounts) < tx->wtx->num_inputs)
|
||||
tal_resize(&tx->input_amounts, tx->wtx->num_inputs);
|
||||
|
||||
tx->input_amounts[i] = tal_free(tx->input_amounts[i]);
|
||||
tx->input_amounts[i] = tal_dup(tx, struct amount_sat, &amount);
|
||||
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
@ -192,9 +185,6 @@ bool bitcoin_tx_check(const struct bitcoin_tx *tx)
|
|||
size_t written;
|
||||
int flags = WALLY_TX_FLAG_USE_WITNESS;
|
||||
|
||||
if (tal_count(tx->input_amounts) != tx->wtx->num_inputs)
|
||||
return false;
|
||||
|
||||
if (wally_tx_get_length(tx->wtx, flags, &written) != WALLY_OK)
|
||||
return false;
|
||||
|
||||
|
@ -440,7 +430,6 @@ struct bitcoin_tx *bitcoin_tx(const tal_t *ctx,
|
|||
&tx->wtx);
|
||||
tal_add_destructor(tx, bitcoin_tx_destroy);
|
||||
|
||||
tx->input_amounts = tal_arrz(tx, struct amount_sat*, input_count);
|
||||
tx->wtx->locktime = nlocktime;
|
||||
tx->wtx->version = 2;
|
||||
tx->chainparams = chainparams;
|
||||
|
@ -451,11 +440,7 @@ struct bitcoin_tx *bitcoin_tx(const tal_t *ctx,
|
|||
|
||||
void bitcoin_tx_finalize(struct bitcoin_tx *tx)
|
||||
{
|
||||
size_t num_inputs;
|
||||
elements_tx_add_fee_output(tx);
|
||||
|
||||
num_inputs = tx->wtx->num_inputs;
|
||||
tal_resize(&tx->input_amounts, num_inputs);
|
||||
assert(bitcoin_tx_check(tx));
|
||||
}
|
||||
|
||||
|
@ -498,9 +483,6 @@ struct bitcoin_tx *pull_bitcoin_tx(const tal_t *ctx, const u8 **cursor,
|
|||
wally_tx_get_length(tx->wtx, flags & ~WALLY_TX_FLAG_USE_ELEMENTS,
|
||||
&wsize);
|
||||
|
||||
/* We don't know the input amounts yet, so set them all to NULL */
|
||||
tx->input_amounts =
|
||||
tal_arrz(tx, struct amount_sat *, tx->wtx->inputs_allocation_len);
|
||||
tx->chainparams = chainparams;
|
||||
|
||||
tx->psbt = new_psbt(tx, tx->wtx);
|
||||
|
@ -537,9 +519,6 @@ struct bitcoin_tx *bitcoin_tx_from_hex(const tal_t *ctx, const char *hex,
|
|||
|
||||
tal_free(linear_tx);
|
||||
|
||||
tx->input_amounts =
|
||||
tal_arrz(tx, struct amount_sat *, tx->wtx->num_inputs);
|
||||
|
||||
return tx;
|
||||
|
||||
fail_free_tx:
|
||||
|
@ -616,13 +595,6 @@ struct bitcoin_tx *fromwire_bitcoin_tx(const tal_t *ctx,
|
|||
tal_free(tx->psbt);
|
||||
tx->psbt = fromwire_psbt(tx, cursor, max);
|
||||
|
||||
for (size_t i = 0; i < tal_count(tx->input_amounts); i++) {
|
||||
struct amount_sat sat;
|
||||
sat = fromwire_amount_sat(cursor, max);
|
||||
tx->input_amounts[i] =
|
||||
tal_dup(tx, struct amount_sat, &sat);
|
||||
}
|
||||
|
||||
return tx;
|
||||
}
|
||||
|
||||
|
@ -637,8 +609,6 @@ void towire_bitcoin_tx(u8 **pptr, const struct bitcoin_tx *tx)
|
|||
towire_u8_array(pptr, lin, tal_count(lin));
|
||||
|
||||
towire_psbt(pptr, tx->psbt);
|
||||
for (size_t i = 0; i < tal_count(tx->input_amounts); i++)
|
||||
towire_amount_sat(pptr, *tx->input_amounts[i]);
|
||||
}
|
||||
|
||||
struct bitcoin_tx_output *fromwire_bitcoin_tx_output(const tal_t *ctx,
|
||||
|
|
|
@ -21,9 +21,6 @@ struct bitcoin_txid {
|
|||
STRUCTEQ_DEF(bitcoin_txid, 0, shad.sha.u);
|
||||
|
||||
struct bitcoin_tx {
|
||||
/* Keep track of input amounts, this is needed for signatures (NULL if
|
||||
* unknown) */
|
||||
struct amount_sat **input_amounts;
|
||||
struct wally_tx *wtx;
|
||||
|
||||
/* Keep a reference to the ruleset we have to abide by */
|
||||
|
|
|
@ -841,7 +841,6 @@ static secp256k1_ecdsa_signature *calc_commitsigs(const tal_t *ctx,
|
|||
|
||||
msg = towire_hsm_sign_remote_commitment_tx(NULL, txs[0],
|
||||
&peer->channel->funding_pubkey[REMOTE],
|
||||
*txs[0]->input_amounts[0],
|
||||
&peer->remote_per_commit,
|
||||
peer->channel->option_static_remotekey);
|
||||
|
||||
|
@ -883,7 +882,6 @@ static secp256k1_ecdsa_signature *calc_commitsigs(const tal_t *ctx,
|
|||
wscript = bitcoin_tx_output_get_witscript(tmpctx, txs[0],
|
||||
txs[i+1]->wtx->inputs[0].index);
|
||||
msg = towire_hsm_sign_remote_htlc_tx(NULL, txs[i + 1], wscript,
|
||||
*txs[i+1]->input_amounts[0],
|
||||
&peer->remote_per_commit);
|
||||
|
||||
msg = hsm_req(tmpctx, take(msg));
|
||||
|
|
|
@ -102,8 +102,8 @@ penalty_tx_create(const tal_t *ctx,
|
|||
bitcoin_tx_finalize(tx);
|
||||
|
||||
u8 *hsm_sign_msg =
|
||||
towire_hsm_sign_penalty_to_us(ctx, &remote_per_commitment_secret, tx,
|
||||
wscript, *tx->input_amounts[0]);
|
||||
towire_hsm_sign_penalty_to_us(ctx, &remote_per_commitment_secret,
|
||||
tx, wscript);
|
||||
|
||||
if (!wire_sync_write(hsm_fd, take(hsm_sign_msg)))
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
|
|
|
@ -276,8 +276,7 @@ static void send_offer(struct per_peer_state *pps,
|
|||
wire_sync_write(HSM_FD,
|
||||
take(towire_hsm_sign_mutual_close_tx(NULL,
|
||||
tx,
|
||||
&funding_pubkey[REMOTE],
|
||||
funding)));
|
||||
&funding_pubkey[REMOTE])));
|
||||
msg = wire_sync_read(tmpctx, HSM_FD);
|
||||
if (!fromwire_hsm_sign_tx_reply(msg, &our_sig))
|
||||
status_failed(STATUS_FAIL_HSM_IO,
|
||||
|
|
|
@ -69,14 +69,6 @@ static void swap_wally_inputs(struct wally_tx_input *inputs,
|
|||
}
|
||||
}
|
||||
|
||||
static void swap_input_amounts(struct amount_sat **amounts, size_t i1,
|
||||
size_t i2)
|
||||
{
|
||||
struct amount_sat *tmp = amounts[i1];
|
||||
amounts[i1] = amounts[i2];
|
||||
amounts[i2] = tmp;
|
||||
}
|
||||
|
||||
void permute_inputs(struct bitcoin_tx *tx, const void **map)
|
||||
{
|
||||
size_t i, best_pos;
|
||||
|
@ -95,7 +87,6 @@ void permute_inputs(struct bitcoin_tx *tx, const void **map)
|
|||
tx->psbt->tx->inputs,
|
||||
tx->psbt->inputs,
|
||||
map, i, best_pos);
|
||||
swap_input_amounts(tx->input_amounts, i, best_pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -165,8 +165,6 @@ int main(int argc, char *argv[])
|
|||
printf("# funding witness script = %s\n",
|
||||
tal_hex(NULL, funding_wscript));
|
||||
|
||||
/* Need input amount for signing */
|
||||
tx->input_amounts[0] = tal_dup(tx, struct amount_sat, &funding_amount);
|
||||
sign_tx_input(tx, 0, NULL, funding_wscript,
|
||||
&funding_privkey[LOCAL],
|
||||
&funding_pubkey[LOCAL],
|
||||
|
|
|
@ -464,7 +464,6 @@ int main(int argc, char *argv[])
|
|||
|
||||
for (size_t i = 0; i < tal_count(htlcmap); i++) {
|
||||
struct bitcoin_signature local_htlc_sig, remote_htlc_sig;
|
||||
struct amount_sat amt;
|
||||
u8 *wscript;
|
||||
|
||||
if (!htlcmap[i])
|
||||
|
@ -473,9 +472,6 @@ int main(int argc, char *argv[])
|
|||
i, side_to_str(htlc_owner(htlcmap[i])), htlcmap[i]->id);
|
||||
printf("# unsigned htlc tx for output %zu: %s\n",
|
||||
i, tal_hex(NULL, linearize_tx(NULL, local_txs[1+i])));
|
||||
amt = amount_msat_to_sat_round_down(htlcmap[i]->amount);
|
||||
local_txs[1+i]->input_amounts[0]
|
||||
= tal_dup(local_txs[1+i], struct amount_sat, &amt);
|
||||
|
||||
wscript = bitcoin_tx_output_get_witscript(NULL, local_txs[1+i], 1+i);
|
||||
printf("# wscript: %s\n", tal_hex(NULL, wscript));
|
||||
|
@ -516,8 +512,6 @@ int main(int argc, char *argv[])
|
|||
remote_txs = channel_txs(NULL, &htlcmap, NULL, &funding_wscript, channel,
|
||||
&remote_per_commit_point, commitnum,
|
||||
REMOTE);
|
||||
remote_txs[0]->input_amounts[0]
|
||||
= tal_dup(remote_txs[0], struct amount_sat, &funding_amount);
|
||||
|
||||
printf("## remote_commitment\n"
|
||||
"# input amount %s, funding_wscript %s, key %s\n",
|
||||
|
@ -579,7 +573,6 @@ int main(int argc, char *argv[])
|
|||
|
||||
for (size_t i = 0; i < tal_count(htlcmap); i++) {
|
||||
struct bitcoin_signature local_htlc_sig, remote_htlc_sig;
|
||||
struct amount_sat amt;
|
||||
u8 *wscript;
|
||||
|
||||
if (!htlcmap[i])
|
||||
|
@ -588,9 +581,6 @@ int main(int argc, char *argv[])
|
|||
i, side_to_str(htlc_owner(htlcmap[i])), htlcmap[i]->id);
|
||||
printf("# unsigned htlc tx for output %zu: %s\n",
|
||||
i, tal_hex(NULL, linearize_tx(NULL, remote_txs[1+i])));
|
||||
amt = amount_msat_to_sat_round_down(htlcmap[i]->amount);
|
||||
remote_txs[1+i]->input_amounts[0]
|
||||
= tal_dup(remote_txs[1+i], struct amount_sat, &amt);
|
||||
|
||||
wscript = bitcoin_tx_output_get_witscript(NULL, remote_txs[1+i], 1+i);
|
||||
printf("# wscript: %s\n", tal_hex(NULL, wscript));
|
||||
|
|
|
@ -105,7 +105,6 @@ msgdata,hsm_sign_commitment_tx,peer_id,node_id,
|
|||
msgdata,hsm_sign_commitment_tx,channel_dbid,u64,
|
||||
msgdata,hsm_sign_commitment_tx,tx,bitcoin_tx,
|
||||
msgdata,hsm_sign_commitment_tx,remote_funding_key,pubkey,
|
||||
msgdata,hsm_sign_commitment_tx,funding_amount,amount_sat,
|
||||
|
||||
msgtype,hsm_sign_commitment_tx_reply,105
|
||||
msgdata,hsm_sign_commitment_tx_reply,sig,bitcoin_signature,
|
||||
|
@ -118,21 +117,18 @@ msgdata,hsm_sign_delayed_payment_to_us,commit_num,u64,
|
|||
msgdata,hsm_sign_delayed_payment_to_us,tx,bitcoin_tx,
|
||||
msgdata,hsm_sign_delayed_payment_to_us,wscript_len,u16,
|
||||
msgdata,hsm_sign_delayed_payment_to_us,wscript,u8,wscript_len
|
||||
msgdata,hsm_sign_delayed_payment_to_us,input_amount,amount_sat,
|
||||
|
||||
msgtype,hsm_sign_remote_htlc_to_us,13
|
||||
msgdata,hsm_sign_remote_htlc_to_us,remote_per_commitment_point,pubkey,
|
||||
msgdata,hsm_sign_remote_htlc_to_us,tx,bitcoin_tx,
|
||||
msgdata,hsm_sign_remote_htlc_to_us,wscript_len,u16,
|
||||
msgdata,hsm_sign_remote_htlc_to_us,wscript,u8,wscript_len
|
||||
msgdata,hsm_sign_remote_htlc_to_us,input_amount,amount_sat,
|
||||
|
||||
msgtype,hsm_sign_penalty_to_us,14
|
||||
msgdata,hsm_sign_penalty_to_us,revocation_secret,secret,
|
||||
msgdata,hsm_sign_penalty_to_us,tx,bitcoin_tx,
|
||||
msgdata,hsm_sign_penalty_to_us,wscript_len,u16,
|
||||
msgdata,hsm_sign_penalty_to_us,wscript,u8,wscript_len
|
||||
msgdata,hsm_sign_penalty_to_us,input_amount,amount_sat,
|
||||
|
||||
# Onchaind asks HSM to sign a local HTLC success or HTLC timeout tx.
|
||||
msgtype,hsm_sign_local_htlc_tx,16
|
||||
|
@ -140,13 +136,11 @@ msgdata,hsm_sign_local_htlc_tx,commit_num,u64,
|
|||
msgdata,hsm_sign_local_htlc_tx,tx,bitcoin_tx,
|
||||
msgdata,hsm_sign_local_htlc_tx,wscript_len,u16,
|
||||
msgdata,hsm_sign_local_htlc_tx,wscript,u8,wscript_len
|
||||
msgdata,hsm_sign_local_htlc_tx,input_amount,amount_sat,
|
||||
|
||||
# Openingd/channeld asks HSM to sign the other sides' commitment tx.
|
||||
msgtype,hsm_sign_remote_commitment_tx,19
|
||||
msgdata,hsm_sign_remote_commitment_tx,tx,bitcoin_tx,
|
||||
msgdata,hsm_sign_remote_commitment_tx,remote_funding_key,pubkey,
|
||||
msgdata,hsm_sign_remote_commitment_tx,funding_amount,amount_sat,
|
||||
msgdata,hsm_sign_remote_commitment_tx,remote_per_commit,pubkey,
|
||||
msgdata,hsm_sign_remote_commitment_tx,option_static_remotekey,bool,
|
||||
|
||||
|
@ -155,14 +149,12 @@ msgtype,hsm_sign_remote_htlc_tx,20
|
|||
msgdata,hsm_sign_remote_htlc_tx,tx,bitcoin_tx,
|
||||
msgdata,hsm_sign_remote_htlc_tx,len,u16,
|
||||
msgdata,hsm_sign_remote_htlc_tx,wscript,u8,len
|
||||
msgdata,hsm_sign_remote_htlc_tx,amounts_satoshi,amount_sat,
|
||||
msgdata,hsm_sign_remote_htlc_tx,remote_per_commit_point,pubkey,
|
||||
|
||||
# closingd asks HSM to sign mutual close tx.
|
||||
msgtype,hsm_sign_mutual_close_tx,21
|
||||
msgdata,hsm_sign_mutual_close_tx,tx,bitcoin_tx,
|
||||
msgdata,hsm_sign_mutual_close_tx,remote_funding_key,pubkey,
|
||||
msgdata,hsm_sign_mutual_close_tx,funding,amount_sat,
|
||||
|
||||
# Reply for all the above requests.
|
||||
msgtype,hsm_sign_tx_reply,112
|
||||
|
|
|
53
hsmd/hsmd.c
53
hsmd/hsmd.c
|
@ -928,7 +928,6 @@ static struct io_plan *handle_sign_commitment_tx(struct io_conn *conn,
|
|||
struct pubkey remote_funding_pubkey, local_funding_pubkey;
|
||||
struct node_id peer_id;
|
||||
u64 dbid;
|
||||
struct amount_sat funding;
|
||||
struct secret channel_seed;
|
||||
struct bitcoin_tx *tx;
|
||||
struct bitcoin_signature sig;
|
||||
|
@ -938,8 +937,7 @@ static struct io_plan *handle_sign_commitment_tx(struct io_conn *conn,
|
|||
if (!fromwire_hsm_sign_commitment_tx(tmpctx, msg_in,
|
||||
&peer_id, &dbid,
|
||||
&tx,
|
||||
&remote_funding_pubkey,
|
||||
&funding))
|
||||
&remote_funding_pubkey))
|
||||
return bad_req(conn, c, msg_in);
|
||||
|
||||
tx->chainparams = c->chainparams;
|
||||
|
@ -960,13 +958,6 @@ static struct io_plan *handle_sign_commitment_tx(struct io_conn *conn,
|
|||
funding_wscript = bitcoin_redeem_2of2(tmpctx,
|
||||
&local_funding_pubkey,
|
||||
&remote_funding_pubkey);
|
||||
/*~ Segregated Witness also added the input amount to the signing
|
||||
* algorithm; it's only part of the input implicitly (it's part of the
|
||||
* output it's spending), so in our 'bitcoin_tx' structure it's a
|
||||
* pointer, as we don't always know it (and zero is a valid amount, so
|
||||
* NULL is better to mean 'unknown' and has the nice property that
|
||||
* you'll crash if you assume it's there and you're wrong.) */
|
||||
tx->input_amounts[0] = tal_dup(tx, struct amount_sat, &funding);
|
||||
sign_tx_input(tx, 0, NULL, funding_wscript,
|
||||
&secrets.funding_privkey,
|
||||
&local_funding_pubkey,
|
||||
|
@ -990,7 +981,6 @@ static struct io_plan *handle_sign_remote_commitment_tx(struct io_conn *conn,
|
|||
const u8 *msg_in)
|
||||
{
|
||||
struct pubkey remote_funding_pubkey, local_funding_pubkey;
|
||||
struct amount_sat funding;
|
||||
struct secret channel_seed;
|
||||
struct bitcoin_tx *tx;
|
||||
struct bitcoin_signature sig;
|
||||
|
@ -1002,7 +992,6 @@ static struct io_plan *handle_sign_remote_commitment_tx(struct io_conn *conn,
|
|||
if (!fromwire_hsm_sign_remote_commitment_tx(tmpctx, msg_in,
|
||||
&tx,
|
||||
&remote_funding_pubkey,
|
||||
&funding,
|
||||
&remote_per_commit,
|
||||
&option_static_remotekey))
|
||||
return bad_req(conn, c, msg_in);
|
||||
|
@ -1021,8 +1010,6 @@ static struct io_plan *handle_sign_remote_commitment_tx(struct io_conn *conn,
|
|||
funding_wscript = bitcoin_redeem_2of2(tmpctx,
|
||||
&local_funding_pubkey,
|
||||
&remote_funding_pubkey);
|
||||
/* Need input amount for signing */
|
||||
tx->input_amounts[0] = tal_dup(tx, struct amount_sat, &funding);
|
||||
sign_tx_input(tx, 0, NULL, funding_wscript,
|
||||
&secrets.funding_privkey,
|
||||
&local_funding_pubkey,
|
||||
|
@ -1044,13 +1031,12 @@ static struct io_plan *handle_sign_remote_htlc_tx(struct io_conn *conn,
|
|||
struct secrets secrets;
|
||||
struct basepoints basepoints;
|
||||
struct pubkey remote_per_commit_point;
|
||||
struct amount_sat amount;
|
||||
u8 *wscript;
|
||||
struct privkey htlc_privkey;
|
||||
struct pubkey htlc_pubkey;
|
||||
|
||||
if (!fromwire_hsm_sign_remote_htlc_tx(tmpctx, msg_in,
|
||||
&tx, &wscript, &amount,
|
||||
&tx, &wscript,
|
||||
&remote_per_commit_point))
|
||||
return bad_req(conn, c, msg_in);
|
||||
tx->chainparams = c->chainparams;
|
||||
|
@ -1070,8 +1056,6 @@ static struct io_plan *handle_sign_remote_htlc_tx(struct io_conn *conn,
|
|||
return bad_req_fmt(conn, c, msg_in,
|
||||
"Failed deriving htlc pubkey");
|
||||
|
||||
/* Need input amount for signing */
|
||||
tx->input_amounts[0] = tal_dup(tx, struct amount_sat, &amount);
|
||||
sign_tx_input(tx, 0, NULL, wscript, &htlc_privkey, &htlc_pubkey,
|
||||
SIGHASH_ALL, &sig);
|
||||
|
||||
|
@ -1086,8 +1070,7 @@ static struct io_plan *handle_sign_to_us_tx(struct io_conn *conn,
|
|||
const u8 *msg_in,
|
||||
struct bitcoin_tx *tx,
|
||||
const struct privkey *privkey,
|
||||
const u8 *wscript,
|
||||
struct amount_sat input_sat)
|
||||
const u8 *wscript)
|
||||
{
|
||||
struct bitcoin_signature sig;
|
||||
struct pubkey pubkey;
|
||||
|
@ -1098,7 +1081,6 @@ static struct io_plan *handle_sign_to_us_tx(struct io_conn *conn,
|
|||
if (tx->wtx->num_inputs != 1)
|
||||
return bad_req_fmt(conn, c, msg_in, "bad txinput count");
|
||||
|
||||
tx->input_amounts[0] = tal_dup(tx, struct amount_sat, &input_sat);
|
||||
sign_tx_input(tx, 0, NULL, wscript, privkey, &pubkey, SIGHASH_ALL, &sig);
|
||||
|
||||
return req_reply(conn, c, take(towire_hsm_sign_tx_reply(NULL, &sig)));
|
||||
|
@ -1113,7 +1095,6 @@ static struct io_plan *handle_sign_delayed_payment_to_us(struct io_conn *conn,
|
|||
const u8 *msg_in)
|
||||
{
|
||||
u64 commit_num;
|
||||
struct amount_sat input_sat;
|
||||
struct secret channel_seed, basepoint_secret;
|
||||
struct pubkey basepoint;
|
||||
struct bitcoin_tx *tx;
|
||||
|
@ -1125,8 +1106,7 @@ static struct io_plan *handle_sign_delayed_payment_to_us(struct io_conn *conn,
|
|||
/*~ We don't derive the wscript ourselves, but perhaps we should? */
|
||||
if (!fromwire_hsm_sign_delayed_payment_to_us(tmpctx, msg_in,
|
||||
&commit_num,
|
||||
&tx, &wscript,
|
||||
&input_sat))
|
||||
&tx, &wscript))
|
||||
return bad_req(conn, c, msg_in);
|
||||
tx->chainparams = c->chainparams;
|
||||
get_channel_seed(&c->id, c->dbid, &channel_seed);
|
||||
|
@ -1159,7 +1139,7 @@ static struct io_plan *handle_sign_delayed_payment_to_us(struct io_conn *conn,
|
|||
return bad_req_fmt(conn, c, msg_in, "failed deriving privkey");
|
||||
|
||||
return handle_sign_to_us_tx(conn, c, msg_in,
|
||||
tx, &privkey, wscript, input_sat);
|
||||
tx, &privkey, wscript);
|
||||
}
|
||||
|
||||
/*~ This is used when a commitment transaction is onchain, and has an HTLC
|
||||
|
@ -1169,7 +1149,6 @@ static struct io_plan *handle_sign_remote_htlc_to_us(struct io_conn *conn,
|
|||
struct client *c,
|
||||
const u8 *msg_in)
|
||||
{
|
||||
struct amount_sat input_sat;
|
||||
struct secret channel_seed, htlc_basepoint_secret;
|
||||
struct pubkey htlc_basepoint;
|
||||
struct bitcoin_tx *tx;
|
||||
|
@ -1179,8 +1158,7 @@ static struct io_plan *handle_sign_remote_htlc_to_us(struct io_conn *conn,
|
|||
|
||||
if (!fromwire_hsm_sign_remote_htlc_to_us(tmpctx, msg_in,
|
||||
&remote_per_commitment_point,
|
||||
&tx, &wscript,
|
||||
&input_sat))
|
||||
&tx, &wscript))
|
||||
return bad_req(conn, c, msg_in);
|
||||
|
||||
tx->chainparams = c->chainparams;
|
||||
|
@ -1199,7 +1177,7 @@ static struct io_plan *handle_sign_remote_htlc_to_us(struct io_conn *conn,
|
|||
"Failed deriving htlc privkey");
|
||||
|
||||
return handle_sign_to_us_tx(conn, c, msg_in,
|
||||
tx, &privkey, wscript, input_sat);
|
||||
tx, &privkey, wscript);
|
||||
}
|
||||
|
||||
/*~ This is used when the remote peer's commitment transaction is revoked;
|
||||
|
@ -1209,7 +1187,6 @@ static struct io_plan *handle_sign_penalty_to_us(struct io_conn *conn,
|
|||
struct client *c,
|
||||
const u8 *msg_in)
|
||||
{
|
||||
struct amount_sat input_sat;
|
||||
struct secret channel_seed, revocation_secret, revocation_basepoint_secret;
|
||||
struct pubkey revocation_basepoint;
|
||||
struct bitcoin_tx *tx;
|
||||
|
@ -1219,8 +1196,7 @@ static struct io_plan *handle_sign_penalty_to_us(struct io_conn *conn,
|
|||
|
||||
if (!fromwire_hsm_sign_penalty_to_us(tmpctx, msg_in,
|
||||
&revocation_secret,
|
||||
&tx, &wscript,
|
||||
&input_sat))
|
||||
&tx, &wscript))
|
||||
return bad_req(conn, c, msg_in);
|
||||
tx->chainparams = c->chainparams;
|
||||
|
||||
|
@ -1243,7 +1219,7 @@ static struct io_plan *handle_sign_penalty_to_us(struct io_conn *conn,
|
|||
"Failed deriving revocation privkey");
|
||||
|
||||
return handle_sign_to_us_tx(conn, c, msg_in,
|
||||
tx, &privkey, wscript, input_sat);
|
||||
tx, &privkey, wscript);
|
||||
}
|
||||
|
||||
/*~ This is used when a commitment transaction is onchain, and has an HTLC
|
||||
|
@ -1254,7 +1230,6 @@ static struct io_plan *handle_sign_local_htlc_tx(struct io_conn *conn,
|
|||
const u8 *msg_in)
|
||||
{
|
||||
u64 commit_num;
|
||||
struct amount_sat input_sat;
|
||||
struct secret channel_seed, htlc_basepoint_secret;
|
||||
struct sha256 shaseed;
|
||||
struct pubkey per_commitment_point, htlc_basepoint;
|
||||
|
@ -1265,8 +1240,7 @@ static struct io_plan *handle_sign_local_htlc_tx(struct io_conn *conn,
|
|||
struct pubkey htlc_pubkey;
|
||||
|
||||
if (!fromwire_hsm_sign_local_htlc_tx(tmpctx, msg_in,
|
||||
&commit_num, &tx, &wscript,
|
||||
&input_sat))
|
||||
&commit_num, &tx, &wscript))
|
||||
return bad_req(conn, c, msg_in);
|
||||
|
||||
tx->chainparams = c->chainparams;
|
||||
|
@ -1300,7 +1274,6 @@ static struct io_plan *handle_sign_local_htlc_tx(struct io_conn *conn,
|
|||
return bad_req_fmt(conn, c, msg_in, "bad txinput count");
|
||||
|
||||
/* FIXME: Check that output script is correct! */
|
||||
tx->input_amounts[0] = tal_dup(tx, struct amount_sat, &input_sat);
|
||||
sign_tx_input(tx, 0, NULL, wscript, &htlc_privkey, &htlc_pubkey,
|
||||
SIGHASH_ALL, &sig);
|
||||
|
||||
|
@ -1395,13 +1368,11 @@ static struct io_plan *handle_sign_mutual_close_tx(struct io_conn *conn,
|
|||
struct pubkey remote_funding_pubkey, local_funding_pubkey;
|
||||
struct bitcoin_signature sig;
|
||||
struct secrets secrets;
|
||||
struct amount_sat funding;
|
||||
const u8 *funding_wscript;
|
||||
|
||||
if (!fromwire_hsm_sign_mutual_close_tx(tmpctx, msg_in,
|
||||
&tx,
|
||||
&remote_funding_pubkey,
|
||||
&funding))
|
||||
&remote_funding_pubkey))
|
||||
return bad_req(conn, c, msg_in);
|
||||
|
||||
tx->chainparams = c->chainparams;
|
||||
|
@ -1415,8 +1386,6 @@ static struct io_plan *handle_sign_mutual_close_tx(struct io_conn *conn,
|
|||
funding_wscript = bitcoin_redeem_2of2(tmpctx,
|
||||
&local_funding_pubkey,
|
||||
&remote_funding_pubkey);
|
||||
/* Need input amount for signing */
|
||||
tx->input_amounts[0] = tal_dup(tx, struct amount_sat, &funding);
|
||||
sign_tx_input(tx, 0, NULL, funding_wscript,
|
||||
&secrets.funding_privkey,
|
||||
&local_funding_pubkey,
|
||||
|
|
|
@ -184,20 +184,12 @@ static void sign_last_tx(struct channel *channel)
|
|||
u8 *msg, **witness;
|
||||
|
||||
assert(!channel->last_tx->wtx->inputs[0].witness);
|
||||
/* Attach input amount, to complete transaction for marshaling */
|
||||
if (!channel->last_tx->input_amounts[0]) {
|
||||
channel->last_tx->input_amounts[0]
|
||||
= tal_dup(channel->last_tx->input_amounts,
|
||||
struct amount_sat,
|
||||
&channel->funding);
|
||||
}
|
||||
msg = towire_hsm_sign_commitment_tx(tmpctx,
|
||||
&channel->peer->id,
|
||||
channel->dbid,
|
||||
channel->last_tx,
|
||||
&channel->channel_info
|
||||
.remote_fundingkey,
|
||||
channel->funding);
|
||||
.remote_fundingkey);
|
||||
|
||||
if (!wire_sync_write(ld->hsm_fd, take(msg)))
|
||||
fatal("Could not write to HSM: %s", strerror(errno));
|
||||
|
|
|
@ -492,7 +492,7 @@ u8 *towire_gossip_get_incoming_channels(const tal_t *ctx UNNEEDED)
|
|||
u8 *towire_hsm_get_channel_basepoints(const tal_t *ctx UNNEEDED, const struct node_id *peerid UNNEEDED, u64 dbid UNNEEDED)
|
||||
{ fprintf(stderr, "towire_hsm_get_channel_basepoints called!\n"); abort(); }
|
||||
/* Generated stub for towire_hsm_sign_commitment_tx */
|
||||
u8 *towire_hsm_sign_commitment_tx(const tal_t *ctx UNNEEDED, const struct node_id *peer_id UNNEEDED, u64 channel_dbid UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const struct pubkey *remote_funding_key UNNEEDED, struct amount_sat funding_amount UNNEEDED)
|
||||
u8 *towire_hsm_sign_commitment_tx(const tal_t *ctx UNNEEDED, const struct node_id *peer_id UNNEEDED, u64 channel_dbid UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const struct pubkey *remote_funding_key UNNEEDED)
|
||||
{ fprintf(stderr, "towire_hsm_sign_commitment_tx called!\n"); abort(); }
|
||||
/* Generated stub for towire_hsm_sign_invoice */
|
||||
u8 *towire_hsm_sign_invoice(const tal_t *ctx UNNEEDED, const u8 *u5bytes UNNEEDED, const u8 *hrp UNNEEDED)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <bitcoin/feerate.h>
|
||||
#include <bitcoin/psbt.h>
|
||||
#include <bitcoin/script.h>
|
||||
#include <ccan/crypto/shachain/shachain.h>
|
||||
#include <ccan/mem/mem.h>
|
||||
|
@ -193,7 +194,7 @@ static void update_ledger_chain_fees(const struct bitcoin_txid *txid,
|
|||
|
||||
/* Log the fees paid on this transaction as 'chain fees'. note that
|
||||
* you *cannot* pass a chaintopology-originated tx to this method,
|
||||
* as they don't have the input_amounts populated */
|
||||
* as they don't have input amounts populated */
|
||||
static struct amount_sat record_chain_fees_tx(const struct bitcoin_txid *txid,
|
||||
const struct bitcoin_tx *tx,
|
||||
u32 blockheight)
|
||||
|
@ -400,7 +401,8 @@ static bool grind_htlc_tx_fee(struct amount_sat *fee,
|
|||
const u8 *wscript,
|
||||
u64 weight)
|
||||
{
|
||||
struct amount_sat prev_fee = AMOUNT_SAT(UINT64_MAX);
|
||||
struct amount_sat prev_fee = AMOUNT_SAT(UINT64_MAX), input_amt;
|
||||
input_amt = psbt_input_get_amount(tx->psbt, 0);
|
||||
|
||||
for (u64 i = min_possible_feerate; i <= max_possible_feerate; i++) {
|
||||
/* BOLT #3:
|
||||
|
@ -424,7 +426,7 @@ static bool grind_htlc_tx_fee(struct amount_sat *fee,
|
|||
continue;
|
||||
|
||||
prev_fee = *fee;
|
||||
if (!amount_sat_sub(&out, *tx->input_amounts[0], *fee))
|
||||
if (!amount_sat_sub(&out, input_amt, *fee))
|
||||
break;
|
||||
|
||||
bitcoin_tx_output_set_amount(tx, 0, out);
|
||||
|
@ -560,8 +562,7 @@ static u8 *delayed_payment_to_us(const tal_t *ctx,
|
|||
const u8 *wscript)
|
||||
{
|
||||
return towire_hsm_sign_delayed_payment_to_us(ctx, commit_num,
|
||||
tx, wscript,
|
||||
*tx->input_amounts[0]);
|
||||
tx, wscript);
|
||||
}
|
||||
|
||||
static u8 *remote_htlc_to_us(const tal_t *ctx,
|
||||
|
@ -570,8 +571,7 @@ static u8 *remote_htlc_to_us(const tal_t *ctx,
|
|||
{
|
||||
return towire_hsm_sign_remote_htlc_to_us(ctx,
|
||||
remote_per_commitment_point,
|
||||
tx, wscript,
|
||||
*tx->input_amounts[0]);
|
||||
tx, wscript);
|
||||
}
|
||||
|
||||
static u8 *penalty_to_us(const tal_t *ctx,
|
||||
|
@ -579,7 +579,7 @@ static u8 *penalty_to_us(const tal_t *ctx,
|
|||
const u8 *wscript)
|
||||
{
|
||||
return towire_hsm_sign_penalty_to_us(ctx, remote_per_commitment_secret,
|
||||
tx, wscript, *tx->input_amounts[0]);
|
||||
tx, wscript);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -675,8 +675,7 @@ static void hsm_sign_local_htlc_tx(struct bitcoin_tx *tx,
|
|||
struct bitcoin_signature *sig)
|
||||
{
|
||||
u8 *msg = towire_hsm_sign_local_htlc_tx(NULL, commit_num,
|
||||
tx, wscript,
|
||||
*tx->input_amounts[0]);
|
||||
tx, wscript);
|
||||
|
||||
if (!wire_sync_write(HSM_FD, take(msg)))
|
||||
status_failed(STATUS_FAIL_HSM_IO,
|
||||
|
|
|
@ -221,13 +221,13 @@ void towire_bool(u8 **pptr UNNEEDED, bool v UNNEEDED)
|
|||
u8 *towire_hsm_get_per_commitment_point(const tal_t *ctx UNNEEDED, u64 n UNNEEDED)
|
||||
{ fprintf(stderr, "towire_hsm_get_per_commitment_point called!\n"); abort(); }
|
||||
/* Generated stub for towire_hsm_sign_delayed_payment_to_us */
|
||||
u8 *towire_hsm_sign_delayed_payment_to_us(const tal_t *ctx UNNEEDED, u64 commit_num UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const u8 *wscript UNNEEDED, struct amount_sat input_amount UNNEEDED)
|
||||
u8 *towire_hsm_sign_delayed_payment_to_us(const tal_t *ctx UNNEEDED, u64 commit_num UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const u8 *wscript UNNEEDED)
|
||||
{ fprintf(stderr, "towire_hsm_sign_delayed_payment_to_us called!\n"); abort(); }
|
||||
/* Generated stub for towire_hsm_sign_penalty_to_us */
|
||||
u8 *towire_hsm_sign_penalty_to_us(const tal_t *ctx UNNEEDED, const struct secret *revocation_secret UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const u8 *wscript UNNEEDED, struct amount_sat input_amount UNNEEDED)
|
||||
u8 *towire_hsm_sign_penalty_to_us(const tal_t *ctx UNNEEDED, const struct secret *revocation_secret UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const u8 *wscript UNNEEDED)
|
||||
{ fprintf(stderr, "towire_hsm_sign_penalty_to_us called!\n"); abort(); }
|
||||
/* Generated stub for towire_hsm_sign_remote_htlc_to_us */
|
||||
u8 *towire_hsm_sign_remote_htlc_to_us(const tal_t *ctx UNNEEDED, const struct pubkey *remote_per_commitment_point UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const u8 *wscript UNNEEDED, struct amount_sat input_amount UNNEEDED)
|
||||
u8 *towire_hsm_sign_remote_htlc_to_us(const tal_t *ctx UNNEEDED, const struct pubkey *remote_per_commitment_point UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const u8 *wscript UNNEEDED)
|
||||
{ fprintf(stderr, "towire_hsm_sign_remote_htlc_to_us called!\n"); abort(); }
|
||||
/* Generated stub for towire_onchain_add_utxo */
|
||||
u8 *towire_onchain_add_utxo(const tal_t *ctx UNNEEDED, const struct bitcoin_txid *prev_out_tx UNNEEDED, u32 prev_out_index UNNEEDED, const struct pubkey *per_commit_point UNNEEDED, struct amount_sat value UNNEEDED, u32 blockheight UNNEEDED, const u8 *scriptpubkey UNNEEDED)
|
||||
|
@ -290,7 +290,7 @@ void towire_u8_array(u8 **pptr UNNEEDED, const u8 *arr UNNEEDED, size_t num UNNE
|
|||
/* AUTOGENERATED MOCKS END */
|
||||
|
||||
/* Stubs which do get called. */
|
||||
u8 *towire_hsm_sign_local_htlc_tx(const tal_t *ctx UNNEEDED, u64 commit_num UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const u8 *wscript UNNEEDED, struct amount_sat input_amount UNNEEDED)
|
||||
u8 *towire_hsm_sign_local_htlc_tx(const tal_t *ctx UNNEEDED, u64 commit_num UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const u8 *wscript UNNEEDED)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
@ -352,7 +352,7 @@ struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx,
|
|||
assert(tx);
|
||||
|
||||
in_amount = amount_msat_to_sat_round_down(htlc_msatoshi);
|
||||
tx->input_amounts[0] = tal_dup(tx, struct amount_sat, &in_amount);
|
||||
psbt_input_set_prev_utxo_wscript(tx->psbt, 0, NULL, in_amount);
|
||||
tx->chainparams = chainparams;
|
||||
|
||||
tx->wtx->locktime = cltv_expiry;
|
||||
|
|
|
@ -236,16 +236,16 @@ void towire_bool(u8 **pptr UNNEEDED, bool v UNNEEDED)
|
|||
u8 *towire_hsm_get_per_commitment_point(const tal_t *ctx UNNEEDED, u64 n UNNEEDED)
|
||||
{ fprintf(stderr, "towire_hsm_get_per_commitment_point called!\n"); abort(); }
|
||||
/* Generated stub for towire_hsm_sign_delayed_payment_to_us */
|
||||
u8 *towire_hsm_sign_delayed_payment_to_us(const tal_t *ctx UNNEEDED, u64 commit_num UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const u8 *wscript UNNEEDED, struct amount_sat input_amount UNNEEDED)
|
||||
u8 *towire_hsm_sign_delayed_payment_to_us(const tal_t *ctx UNNEEDED, u64 commit_num UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const u8 *wscript UNNEEDED)
|
||||
{ fprintf(stderr, "towire_hsm_sign_delayed_payment_to_us called!\n"); abort(); }
|
||||
/* Generated stub for towire_hsm_sign_local_htlc_tx */
|
||||
u8 *towire_hsm_sign_local_htlc_tx(const tal_t *ctx UNNEEDED, u64 commit_num UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const u8 *wscript UNNEEDED, struct amount_sat input_amount UNNEEDED)
|
||||
u8 *towire_hsm_sign_local_htlc_tx(const tal_t *ctx UNNEEDED, u64 commit_num UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const u8 *wscript UNNEEDED)
|
||||
{ fprintf(stderr, "towire_hsm_sign_local_htlc_tx called!\n"); abort(); }
|
||||
/* Generated stub for towire_hsm_sign_penalty_to_us */
|
||||
u8 *towire_hsm_sign_penalty_to_us(const tal_t *ctx UNNEEDED, const struct secret *revocation_secret UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const u8 *wscript UNNEEDED, struct amount_sat input_amount UNNEEDED)
|
||||
u8 *towire_hsm_sign_penalty_to_us(const tal_t *ctx UNNEEDED, const struct secret *revocation_secret UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const u8 *wscript UNNEEDED)
|
||||
{ fprintf(stderr, "towire_hsm_sign_penalty_to_us called!\n"); abort(); }
|
||||
/* Generated stub for towire_hsm_sign_remote_htlc_to_us */
|
||||
u8 *towire_hsm_sign_remote_htlc_to_us(const tal_t *ctx UNNEEDED, const struct pubkey *remote_per_commitment_point UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const u8 *wscript UNNEEDED, struct amount_sat input_amount UNNEEDED)
|
||||
u8 *towire_hsm_sign_remote_htlc_to_us(const tal_t *ctx UNNEEDED, const struct pubkey *remote_per_commitment_point UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const u8 *wscript UNNEEDED)
|
||||
{ fprintf(stderr, "towire_hsm_sign_remote_htlc_to_us called!\n"); abort(); }
|
||||
/* Generated stub for towire_onchain_add_utxo */
|
||||
u8 *towire_onchain_add_utxo(const tal_t *ctx UNNEEDED, const struct bitcoin_txid *prev_out_tx UNNEEDED, u32 prev_out_index UNNEEDED, const struct pubkey *per_commit_point UNNEEDED, struct amount_sat value UNNEEDED, u32 blockheight UNNEEDED, const u8 *scriptpubkey UNNEEDED)
|
||||
|
@ -330,8 +330,7 @@ int main(int argc, char *argv[])
|
|||
tx = bitcoin_tx_from_hex(tmpctx, "0200000001e1ebca08cf1c301ac563580a1126d5c8fcb0e5e2043230b852c726553caf1e1d0000000000000000000160ae0a000000000022002082e03c5a9cb79c82cd5a0572dc175290bc044609aabe9cc852d61927436041796d000000",
|
||||
strlen("0200000001e1ebca08cf1c301ac563580a1126d5c8fcb0e5e2043230b852c726553caf1e1d0000000000000000000160ae0a000000000022002082e03c5a9cb79c82cd5a0572dc175290bc044609aabe9cc852d61927436041796d000000"));
|
||||
tx->chainparams = chainparams_for_network("regtest");
|
||||
tx->input_amounts[0] = tal(tx, struct amount_sat);
|
||||
*tx->input_amounts[0] = AMOUNT_SAT(700000);
|
||||
psbt_input_set_prev_utxo(tx->psbt, 0, NULL, AMOUNT_SAT(700000));
|
||||
tx->chainparams = chainparams_for_network("bitcoin");
|
||||
der = tal_hexdata(tmpctx, "30450221009b2e0eef267b94c3899fb0dc7375012e2cee4c10348a068fe78d1b82b4b14036022077c3fad3adac2ddf33f415e45f0daf6658b7a0b09647de4443938ae2dbafe2b9" "01",
|
||||
strlen("30450221009b2e0eef267b94c3899fb0dc7375012e2cee4c10348a068fe78d1b82b4b14036022077c3fad3adac2ddf33f415e45f0daf6658b7a0b09647de4443938ae2dbafe2b9" "01"));
|
||||
|
|
|
@ -735,7 +735,6 @@ static bool funder_finalize_channel_setup(struct state *state,
|
|||
msg = towire_hsm_sign_remote_commitment_tx(NULL,
|
||||
*tx,
|
||||
&state->channel->funding_pubkey[REMOTE],
|
||||
state->channel->funding,
|
||||
&state->first_per_commitment_point[REMOTE],
|
||||
state->channel->option_static_remotekey);
|
||||
|
||||
|
@ -1269,7 +1268,6 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
|
|||
msg = towire_hsm_sign_remote_commitment_tx(NULL,
|
||||
remote_commit,
|
||||
&state->channel->funding_pubkey[REMOTE],
|
||||
state->channel->funding,
|
||||
&state->first_per_commitment_point[REMOTE],
|
||||
state->channel->option_static_remotekey);
|
||||
|
||||
|
|
|
@ -693,7 +693,7 @@ u8 *towire_final_incorrect_htlc_amount(const tal_t *ctx UNNEEDED, struct amount_
|
|||
u8 *towire_gossip_get_stripped_cupdate(const tal_t *ctx UNNEEDED, const struct short_channel_id *channel_id UNNEEDED)
|
||||
{ fprintf(stderr, "towire_gossip_get_stripped_cupdate called!\n"); abort(); }
|
||||
/* Generated stub for towire_hsm_sign_commitment_tx */
|
||||
u8 *towire_hsm_sign_commitment_tx(const tal_t *ctx UNNEEDED, const struct node_id *peer_id UNNEEDED, u64 channel_dbid UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const struct pubkey *remote_funding_key UNNEEDED, struct amount_sat funding_amount UNNEEDED)
|
||||
u8 *towire_hsm_sign_commitment_tx(const tal_t *ctx UNNEEDED, const struct node_id *peer_id UNNEEDED, u64 channel_dbid UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const struct pubkey *remote_funding_key UNNEEDED)
|
||||
{ fprintf(stderr, "towire_hsm_sign_commitment_tx called!\n"); abort(); }
|
||||
/* Generated stub for towire_incorrect_cltv_expiry */
|
||||
u8 *towire_incorrect_cltv_expiry(const tal_t *ctx UNNEEDED, u32 cltv_expiry UNNEEDED, const u8 *channel_update UNNEEDED)
|
||||
|
|
Loading…
Add table
Reference in a new issue