mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-23 15:04:19 +01:00
common: use bitcoin_outpoint.
I started pulling this thread, and the entire codebase got unravelled. Oh well, it's done now! Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
e7a8a0d291
commit
c503232cde
@@ -543,7 +543,7 @@ clean:
|
||||
}
|
||||
|
||||
void bitcoind_getutxout_(struct bitcoind *bitcoind,
|
||||
const struct bitcoin_txid *txid, const u32 outnum,
|
||||
const struct bitcoin_outpoint *outpoint,
|
||||
void (*cb)(struct bitcoind *bitcoind,
|
||||
const struct bitcoin_tx_output *txout,
|
||||
void *arg),
|
||||
@@ -558,8 +558,8 @@ void bitcoind_getutxout_(struct bitcoind *bitcoind,
|
||||
|
||||
req = jsonrpc_request_start(bitcoind, "getutxout", bitcoind->log,
|
||||
NULL, getutxout_callback, call);
|
||||
json_add_txid(req->stream, "txid", txid);
|
||||
json_add_num(req->stream, "vout", outnum);
|
||||
json_add_txid(req->stream, "txid", &outpoint->txid);
|
||||
json_add_num(req->stream, "vout", outpoint->n);
|
||||
jsonrpc_request_end(req);
|
||||
bitcoin_plugin_send(bitcoind, req);
|
||||
}
|
||||
@@ -599,7 +599,7 @@ process_getfilteredblock_step2(struct bitcoind *bitcoind,
|
||||
call->current_outpoint++;
|
||||
if (call->current_outpoint < tal_count(call->outpoints)) {
|
||||
o = call->outpoints[call->current_outpoint];
|
||||
bitcoind_getutxout(bitcoind, &o->txid, o->outnum,
|
||||
bitcoind_getutxout(bitcoind, &o->outpoint,
|
||||
process_getfilteredblock_step2, call);
|
||||
} else {
|
||||
/* If there were no more outpoints to check, we call the callback. */
|
||||
@@ -645,10 +645,10 @@ static void process_getfilteredblock_step1(struct bitcoind *bitcoind,
|
||||
if (amount_asset_is_main(&amount) && is_p2wsh(script, NULL)) {
|
||||
/* This is an interesting output, remember it. */
|
||||
o = tal(call->outpoints, struct filteredblock_outpoint);
|
||||
bitcoin_txid(tx, &o->txid);
|
||||
bitcoin_txid(tx, &o->outpoint.txid);
|
||||
o->outpoint.n = j;
|
||||
o->amount = amount_asset_to_sat(&amount);
|
||||
o->txindex = i;
|
||||
o->outnum = j;
|
||||
o->scriptPubKey = tal_steal(o, script);
|
||||
tal_arr_expand(&call->outpoints, o);
|
||||
} else {
|
||||
@@ -667,7 +667,7 @@ static void process_getfilteredblock_step1(struct bitcoind *bitcoind,
|
||||
* store the one's that are unspent in
|
||||
* call->result->outpoints. */
|
||||
o = call->outpoints[call->current_outpoint];
|
||||
bitcoind_getutxout(bitcoind, &o->txid, o->outnum,
|
||||
bitcoind_getutxout(bitcoind, &o->outpoint,
|
||||
process_getfilteredblock_step2, call);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,8 +39,7 @@ struct bitcoind {
|
||||
|
||||
/* A single outpoint in a filtered block */
|
||||
struct filteredblock_outpoint {
|
||||
struct bitcoin_txid txid;
|
||||
u32 outnum;
|
||||
struct bitcoin_outpoint outpoint;
|
||||
u32 txindex;
|
||||
const u8 *scriptPubKey;
|
||||
struct amount_sat amount;
|
||||
@@ -150,13 +149,13 @@ void bitcoind_getrawblockbyheight_(struct bitcoind *bitcoind,
|
||||
(arg))
|
||||
|
||||
void bitcoind_getutxout_(struct bitcoind *bitcoind,
|
||||
const struct bitcoin_txid *txid, const u32 outnum,
|
||||
const struct bitcoin_outpoint *outpoint,
|
||||
void (*cb)(struct bitcoind *bitcoind,
|
||||
const struct bitcoin_tx_output *txout,
|
||||
void *arg),
|
||||
void *arg);
|
||||
#define bitcoind_getutxout(bitcoind_, txid_, vout_, cb, arg) \
|
||||
bitcoind_getutxout_((bitcoind_), (txid_), (vout_), \
|
||||
#define bitcoind_getutxout(bitcoind_, outpoint_, cb, arg) \
|
||||
bitcoind_getutxout_((bitcoind_), (outpoint_), \
|
||||
typesafe_cb_preargs(void, void *, \
|
||||
(cb), (arg), \
|
||||
struct bitcoind *, \
|
||||
|
||||
@@ -299,10 +299,11 @@ static void watch_for_utxo_reconfirmation(struct chain_topology *topo,
|
||||
assert(unconfirmed[i]->close_info != NULL);
|
||||
assert(unconfirmed[i]->blockheight == NULL);
|
||||
|
||||
if (find_txwatch(topo, &unconfirmed[i]->txid, NULL))
|
||||
if (find_txwatch(topo, &unconfirmed[i]->outpoint.txid, NULL))
|
||||
continue;
|
||||
|
||||
notleak(watch_txid(topo, topo, NULL, &unconfirmed[i]->txid,
|
||||
notleak(watch_txid(topo, topo, NULL,
|
||||
&unconfirmed[i]->outpoint.txid,
|
||||
closeinfo_txid_confirmed));
|
||||
}
|
||||
}
|
||||
@@ -654,25 +655,24 @@ static void updates_complete(struct chain_topology *topo)
|
||||
|
||||
static void record_utxo_spent(struct lightningd *ld,
|
||||
const struct bitcoin_txid *txid,
|
||||
const struct bitcoin_txid *utxo_txid,
|
||||
u32 vout, u32 blockheight,
|
||||
const struct bitcoin_outpoint *outpoint,
|
||||
u32 blockheight,
|
||||
struct amount_sat *input_amt)
|
||||
{
|
||||
struct utxo *utxo;
|
||||
struct chain_coin_mvt *mvt;
|
||||
u8 *ctx = tal(NULL, u8);
|
||||
|
||||
utxo = wallet_utxo_get(ctx, ld->wallet, utxo_txid, vout);
|
||||
utxo = wallet_utxo_get(ctx, ld->wallet, outpoint);
|
||||
if (!utxo) {
|
||||
log_broken(ld->log, "No record of utxo %s:%d",
|
||||
type_to_string(tmpctx, struct bitcoin_txid,
|
||||
utxo_txid),
|
||||
vout);
|
||||
log_broken(ld->log, "No record of utxo %s",
|
||||
type_to_string(tmpctx, struct bitcoin_outpoint,
|
||||
outpoint));
|
||||
return;
|
||||
}
|
||||
|
||||
*input_amt = utxo->amount;
|
||||
mvt = new_coin_spend_track(ctx, txid, utxo_txid, vout, blockheight);
|
||||
mvt = new_coin_spend_track(ctx, txid, outpoint, blockheight);
|
||||
notify_chain_mvt(ld, mvt);
|
||||
tal_free(ctx);
|
||||
}
|
||||
@@ -680,20 +680,23 @@ static void record_utxo_spent(struct lightningd *ld,
|
||||
static void record_outputs_as_withdraws(const tal_t *ctx,
|
||||
struct lightningd *ld,
|
||||
const struct bitcoin_tx *tx,
|
||||
struct bitcoin_txid *txid,
|
||||
const struct bitcoin_txid *txid,
|
||||
u32 blockheight)
|
||||
{
|
||||
struct chain_coin_mvt *mvt;
|
||||
for (size_t i = 0; i < tx->wtx->num_outputs; i++) {
|
||||
struct bitcoin_outpoint outpoint;
|
||||
|
||||
outpoint.txid = *txid;
|
||||
for (outpoint.n = 0; outpoint.n < tx->wtx->num_outputs; outpoint.n++) {
|
||||
struct amount_asset asset;
|
||||
struct amount_sat outval;
|
||||
if (elements_tx_output_is_fee(tx, i))
|
||||
if (elements_tx_output_is_fee(tx, outpoint.n))
|
||||
continue;
|
||||
asset = bitcoin_tx_output_get_amount(tx, i);
|
||||
asset = bitcoin_tx_output_get_amount(tx, outpoint.n);
|
||||
assert(amount_asset_is_main(&asset));
|
||||
outval = amount_asset_to_sat(&asset);
|
||||
mvt = new_coin_withdrawal_sat(ctx, "wallet", txid,
|
||||
txid, i, blockheight,
|
||||
&outpoint, blockheight,
|
||||
outval);
|
||||
notify_chain_mvt(ld, mvt);
|
||||
}
|
||||
@@ -701,7 +704,7 @@ static void record_outputs_as_withdraws(const tal_t *ctx,
|
||||
|
||||
static void record_tx_outs_and_fees(struct lightningd *ld,
|
||||
const struct bitcoin_tx *tx,
|
||||
struct bitcoin_txid *txid,
|
||||
const struct bitcoin_txid *txid,
|
||||
u32 blockheight,
|
||||
struct amount_sat inputs_total,
|
||||
bool our_tx)
|
||||
@@ -728,7 +731,7 @@ static void record_tx_outs_and_fees(struct lightningd *ld,
|
||||
/* We don't have detailed withdrawal info for this tx,
|
||||
* so we log the wallet withdrawal as a single entry */
|
||||
mvt = new_coin_withdrawal_sat(ctx, "wallet", txid, NULL,
|
||||
0, blockheight, out_val);
|
||||
blockheight, out_val);
|
||||
notify_chain_mvt(ld, mvt);
|
||||
goto log_fee;
|
||||
}
|
||||
@@ -763,23 +766,21 @@ static void topo_update_spends(struct chain_topology *topo, struct block *b)
|
||||
txid = b->txids[i];
|
||||
|
||||
for (size_t j = 0; j < tx->wtx->num_inputs; j++) {
|
||||
const struct wally_tx_input *input = &tx->wtx->inputs[j];
|
||||
struct bitcoin_txid outpoint_txid;
|
||||
struct bitcoin_outpoint outpoint;
|
||||
bool our_spend;
|
||||
|
||||
bitcoin_tx_input_get_txid(tx, j, &outpoint_txid);
|
||||
bitcoin_tx_input_get_outpoint(tx, j, &outpoint);
|
||||
|
||||
our_spend = wallet_outpoint_spend(
|
||||
topo->ld->wallet, tmpctx, b->height, &outpoint_txid,
|
||||
input->index);
|
||||
topo->ld->wallet, tmpctx, b->height, &outpoint);
|
||||
our_tx &= our_spend;
|
||||
includes_our_spend |= our_spend;
|
||||
if (our_spend) {
|
||||
struct amount_sat input_amt;
|
||||
bool ok;
|
||||
|
||||
record_utxo_spent(topo->ld, &txid, &outpoint_txid,
|
||||
input->index, b->height, &input_amt);
|
||||
record_utxo_spent(topo->ld, &txid, &outpoint,
|
||||
b->height, &input_amt);
|
||||
ok = amount_sat_add(&inputs_total, inputs_total, input_amt);
|
||||
assert(ok);
|
||||
}
|
||||
@@ -804,15 +805,21 @@ static void topo_add_utxos(struct chain_topology *topo, struct block *b)
|
||||
{
|
||||
for (size_t i = 0; i < tal_count(b->full_txs); i++) {
|
||||
const struct bitcoin_tx *tx = b->full_txs[i];
|
||||
for (size_t j = 0; j < tx->wtx->num_outputs; j++) {
|
||||
if (tx->wtx->outputs[j].features & WALLY_TX_IS_COINBASE)
|
||||
struct bitcoin_outpoint outpoint;
|
||||
|
||||
bitcoin_txid(tx, &outpoint.txid);
|
||||
for (outpoint.n = 0;
|
||||
outpoint.n < tx->wtx->num_outputs;
|
||||
outpoint.n++) {
|
||||
if (tx->wtx->outputs[outpoint.n].features
|
||||
& WALLY_TX_IS_COINBASE)
|
||||
continue;
|
||||
|
||||
const u8 *script = bitcoin_tx_output_get_script(tmpctx, tx, j);
|
||||
struct amount_asset amt = bitcoin_tx_output_get_amount(tx, j);
|
||||
const u8 *script = bitcoin_tx_output_get_script(tmpctx, tx, outpoint.n);
|
||||
struct amount_asset amt = bitcoin_tx_output_get_amount(tx, outpoint.n);
|
||||
|
||||
if (amount_asset_is_main(&amt) && is_p2wsh(script, NULL)) {
|
||||
wallet_utxoset_add(topo->ld->wallet, tx, j,
|
||||
wallet_utxoset_add(topo->ld->wallet, &outpoint,
|
||||
b->height, i, script,
|
||||
amount_asset_to_sat(&amt));
|
||||
}
|
||||
|
||||
@@ -144,8 +144,7 @@ static void destroy_inflight(struct channel_inflight *inflight)
|
||||
|
||||
struct channel_inflight *
|
||||
new_inflight(struct channel *channel,
|
||||
const struct bitcoin_txid funding_txid,
|
||||
u16 funding_outnum,
|
||||
const struct bitcoin_outpoint *funding_outpoint,
|
||||
u32 funding_feerate,
|
||||
struct amount_sat total_funds,
|
||||
struct amount_sat our_funds,
|
||||
@@ -163,9 +162,8 @@ new_inflight(struct channel *channel,
|
||||
struct funding_info *funding
|
||||
= tal(inflight, struct funding_info);
|
||||
|
||||
funding->txid = funding_txid;
|
||||
funding->outpoint = *funding_outpoint;
|
||||
funding->total_funds = total_funds;
|
||||
funding->outnum = funding_outnum;
|
||||
funding->feerate = funding_feerate;
|
||||
funding->our_funds = our_funds;
|
||||
|
||||
@@ -312,9 +310,8 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
||||
u64 next_index_local,
|
||||
u64 next_index_remote,
|
||||
u64 next_htlc_id,
|
||||
const struct bitcoin_txid *funding_txid,
|
||||
u16 funding_outnum,
|
||||
struct amount_sat funding,
|
||||
const struct bitcoin_outpoint *funding,
|
||||
struct amount_sat funding_sats,
|
||||
struct amount_msat push,
|
||||
struct amount_sat our_funds,
|
||||
bool remote_funding_locked,
|
||||
@@ -396,9 +393,8 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
||||
channel->next_index[LOCAL] = next_index_local;
|
||||
channel->next_index[REMOTE] = next_index_remote;
|
||||
channel->next_htlc_id = next_htlc_id;
|
||||
channel->funding_txid = *funding_txid;
|
||||
channel->funding_outnum = funding_outnum;
|
||||
channel->funding = funding;
|
||||
channel->funding = *funding;
|
||||
channel->funding_sats = funding_sats;
|
||||
channel->push = push;
|
||||
channel->our_funds = our_funds;
|
||||
channel->remote_funding_locked = remote_funding_locked;
|
||||
@@ -514,7 +510,7 @@ struct channel_inflight *channel_inflight_find(struct channel *channel,
|
||||
{
|
||||
struct channel_inflight *inflight;
|
||||
list_for_each(&channel->inflights, inflight, list) {
|
||||
if (bitcoin_txid_eq(txid, &inflight->funding->txid))
|
||||
if (bitcoin_txid_eq(txid, &inflight->funding->outpoint.txid))
|
||||
return inflight;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,7 @@ struct billboard {
|
||||
};
|
||||
|
||||
struct funding_info {
|
||||
struct bitcoin_txid txid;
|
||||
u16 outnum;
|
||||
struct bitcoin_outpoint outpoint;
|
||||
u32 feerate;
|
||||
struct amount_sat total_funds;
|
||||
|
||||
@@ -117,10 +116,9 @@ struct channel {
|
||||
u64 next_index[NUM_SIDES];
|
||||
u64 next_htlc_id;
|
||||
|
||||
/* Funding txid and amounts */
|
||||
struct bitcoin_txid funding_txid;
|
||||
u16 funding_outnum;
|
||||
struct amount_sat funding;
|
||||
/* Funding outpoint and amount */
|
||||
struct bitcoin_outpoint funding;
|
||||
struct amount_sat funding_sats;
|
||||
|
||||
/* Our original funds, in funding amount */
|
||||
struct amount_sat our_funds;
|
||||
@@ -258,9 +256,8 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
||||
u64 next_index_local,
|
||||
u64 next_index_remote,
|
||||
u64 next_htlc_id,
|
||||
const struct bitcoin_txid *funding_txid,
|
||||
u16 funding_outnum,
|
||||
struct amount_sat funding,
|
||||
const struct bitcoin_outpoint *funding,
|
||||
struct amount_sat funding_sats,
|
||||
struct amount_msat push,
|
||||
struct amount_sat our_funds,
|
||||
bool remote_funding_locked,
|
||||
@@ -310,10 +307,9 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
||||
/* new_inflight - Create a new channel_inflight for a channel */
|
||||
struct channel_inflight *
|
||||
new_inflight(struct channel *channel,
|
||||
const struct bitcoin_txid funding_txid,
|
||||
u16 funding_outnum,
|
||||
const struct bitcoin_outpoint *funding_outpoint,
|
||||
u32 funding_feerate,
|
||||
struct amount_sat funding,
|
||||
struct amount_sat funding_sat,
|
||||
struct amount_sat our_funds,
|
||||
struct wally_psbt *funding_psbt STEALS,
|
||||
struct bitcoin_tx *last_tx STEALS,
|
||||
|
||||
@@ -138,10 +138,11 @@ void channel_record_open(struct channel *channel)
|
||||
|
||||
/* FIXME: logic here will change for dual funded channels */
|
||||
if (channel->opener == LOCAL) {
|
||||
if (!amount_sat_to_msat(&channel_open_amt, channel->funding))
|
||||
if (!amount_sat_to_msat(&channel_open_amt,
|
||||
channel->funding_sats))
|
||||
fatal("Unable to convert funding %s to msat",
|
||||
type_to_string(tmpctx, struct amount_sat,
|
||||
&channel->funding));
|
||||
&channel->funding_sats));
|
||||
|
||||
/* if we pushed sats, we should decrement that
|
||||
* from the channel balance */
|
||||
@@ -150,7 +151,7 @@ void channel_record_open(struct channel *channel)
|
||||
type_to_string(tmpctx,
|
||||
struct channel_id,
|
||||
&channel->cid),
|
||||
&channel->funding_txid,
|
||||
&channel->funding.txid,
|
||||
blockheight, channel->push);
|
||||
notify_chain_mvt(channel->peer->ld, mvt);
|
||||
}
|
||||
@@ -164,8 +165,7 @@ void channel_record_open(struct channel *channel)
|
||||
mvt = new_coin_deposit(ctx,
|
||||
type_to_string(tmpctx, struct channel_id,
|
||||
&channel->cid),
|
||||
&channel->funding_txid,
|
||||
channel->funding_outnum,
|
||||
&channel->funding,
|
||||
blockheight, channel_open_amt);
|
||||
notify_chain_mvt(channel->peer->ld, mvt);
|
||||
tal_free(ctx);
|
||||
@@ -648,9 +648,8 @@ void peer_start_channeld(struct channel *channel,
|
||||
chainparams,
|
||||
ld->our_features,
|
||||
&channel->cid,
|
||||
&channel->funding_txid,
|
||||
channel->funding_outnum,
|
||||
channel->funding,
|
||||
&channel->funding,
|
||||
channel->funding_sats,
|
||||
channel->minimum_depth,
|
||||
get_block_height(ld->topology),
|
||||
channel->blockheight_states,
|
||||
@@ -858,7 +857,7 @@ void channel_notify_new_block(struct lightningd *ld,
|
||||
"loss of funds.",
|
||||
block_height - channel->first_blocknum,
|
||||
type_to_string(tmpctx, struct bitcoin_txid,
|
||||
&channel->funding_txid));
|
||||
&channel->funding.txid));
|
||||
/* FIXME: Send an error packet for this case! */
|
||||
/* And forget it. */
|
||||
delete_channel(channel);
|
||||
@@ -967,7 +966,7 @@ struct command_result *cancel_channel_before_broadcast(struct command *cmd,
|
||||
* type into DB before broadcast). */
|
||||
enum wallet_tx_type type;
|
||||
if (wallet_transaction_type(cmd->ld->wallet,
|
||||
&cancel_channel->funding_txid,
|
||||
&cancel_channel->funding.txid,
|
||||
&type))
|
||||
return command_fail(cmd, FUNDING_CANCEL_NOT_SAFE,
|
||||
"Has the funding transaction been"
|
||||
@@ -991,8 +990,7 @@ struct command_result *cancel_channel_before_broadcast(struct command *cmd,
|
||||
* is broadcast by external wallet and the transaction hasn't
|
||||
* been onchain. */
|
||||
bitcoind_getutxout(cmd->ld->topology->bitcoind,
|
||||
&cancel_channel->funding_txid,
|
||||
cancel_channel->funding_outnum,
|
||||
&cancel_channel->funding,
|
||||
process_check_funding_broadcast,
|
||||
notleak(tal_steal(NULL, cc)));
|
||||
return command_still_pending(cmd);
|
||||
|
||||
@@ -197,8 +197,8 @@ static bool closing_fee_is_acceptable(struct lightningd *ld,
|
||||
bool feerate_unknown;
|
||||
|
||||
/* Calculate actual fee (adds in eliminated outputs) */
|
||||
fee = calc_tx_fee(channel->funding, tx);
|
||||
last_fee = calc_tx_fee(channel->funding, channel->last_tx);
|
||||
fee = calc_tx_fee(channel->funding_sats, tx);
|
||||
last_fee = calc_tx_fee(channel->funding_sats, channel->last_tx);
|
||||
|
||||
log_debug(channel->log, "Their actual closing tx fee is %s"
|
||||
" vs previous %s",
|
||||
@@ -421,7 +421,7 @@ void peer_start_closingd(struct channel *channel,
|
||||
if (!*max_feerate)
|
||||
*max_feerate = final_commit_feerate;
|
||||
/* No other limit on fees */
|
||||
feelimit = channel->funding;
|
||||
feelimit = channel->funding_sats;
|
||||
} else
|
||||
max_feerate = NULL;
|
||||
|
||||
@@ -440,10 +440,10 @@ void peer_start_closingd(struct channel *channel,
|
||||
*/
|
||||
/* What is not ours is theirs */
|
||||
if (!amount_sat_sub_msat(&their_msat,
|
||||
channel->funding, channel->our_msat)) {
|
||||
channel->funding_sats, channel->our_msat)) {
|
||||
log_broken(channel->log, "our_msat overflow funding %s minus %s",
|
||||
type_to_string(tmpctx, struct amount_sat,
|
||||
&channel->funding),
|
||||
&channel->funding_sats),
|
||||
type_to_string(tmpctx, struct amount_msat,
|
||||
&channel->our_msat));
|
||||
channel_fail_permanent(channel,
|
||||
@@ -456,9 +456,8 @@ void peer_start_closingd(struct channel *channel,
|
||||
chainparams,
|
||||
pps,
|
||||
&channel->cid,
|
||||
&channel->funding_txid,
|
||||
channel->funding_outnum,
|
||||
channel->funding,
|
||||
&channel->funding,
|
||||
channel->funding_sats,
|
||||
&channel->local_funding_pubkey,
|
||||
&channel->channel_info.remote_fundingkey,
|
||||
channel->opener,
|
||||
|
||||
@@ -932,13 +932,13 @@ openchannel2_sign_hook_cb(struct openchannel2_psbt_payload *payload STEALS)
|
||||
|
||||
/* Check that we've got the same / correct PSBT */
|
||||
psbt_txid(NULL, payload->psbt, &txid, NULL);
|
||||
if (!bitcoin_txid_eq(&inflight->funding->txid, &txid)) {
|
||||
if (!bitcoin_txid_eq(&inflight->funding->outpoint.txid, &txid)) {
|
||||
log_broken(channel->log,
|
||||
"PSBT's txid does not match. %s != %s",
|
||||
type_to_string(tmpctx, struct bitcoin_txid,
|
||||
&txid),
|
||||
type_to_string(tmpctx, struct bitcoin_txid,
|
||||
&inflight->funding->txid));
|
||||
&inflight->funding->outpoint.txid));
|
||||
msg = towire_dualopend_fail(NULL, "Peer error with PSBT"
|
||||
" signatures.");
|
||||
goto send_msg;
|
||||
@@ -1057,8 +1057,7 @@ wallet_update_channel(struct lightningd *ld,
|
||||
struct channel *channel,
|
||||
struct bitcoin_tx *remote_commit STEALS,
|
||||
struct bitcoin_signature *remote_commit_sig,
|
||||
const struct bitcoin_txid *funding_txid,
|
||||
u16 funding_outnum,
|
||||
const struct bitcoin_outpoint *funding,
|
||||
struct amount_sat total_funding,
|
||||
struct amount_sat our_funding,
|
||||
u32 funding_feerate,
|
||||
@@ -1080,9 +1079,8 @@ wallet_update_channel(struct lightningd *ld,
|
||||
assert(channel->unsaved_dbid == 0);
|
||||
assert(channel->dbid != 0);
|
||||
|
||||
channel->funding_txid = *funding_txid;
|
||||
channel->funding_outnum = funding_outnum;
|
||||
channel->funding = total_funding;
|
||||
channel->funding = *funding;
|
||||
channel->funding_sats = total_funding;
|
||||
channel->our_funds = our_funding;
|
||||
channel->our_msat = our_msat;
|
||||
channel->msat_to_us_min = our_msat;
|
||||
@@ -1109,10 +1107,9 @@ wallet_update_channel(struct lightningd *ld,
|
||||
|
||||
/* Add open attempt to channel's inflights */
|
||||
inflight = new_inflight(channel,
|
||||
channel->funding_txid,
|
||||
channel->funding_outnum,
|
||||
&channel->funding,
|
||||
funding_feerate,
|
||||
channel->funding,
|
||||
channel->funding_sats,
|
||||
channel->our_funds,
|
||||
psbt,
|
||||
channel->last_tx,
|
||||
@@ -1133,8 +1130,7 @@ wallet_commit_channel(struct lightningd *ld,
|
||||
struct channel *channel,
|
||||
struct bitcoin_tx *remote_commit,
|
||||
struct bitcoin_signature *remote_commit_sig,
|
||||
const struct bitcoin_txid *funding_txid,
|
||||
u16 funding_outnum,
|
||||
const struct bitcoin_outpoint *funding,
|
||||
struct amount_sat total_funding,
|
||||
struct amount_sat our_funding,
|
||||
struct channel_info *channel_info,
|
||||
@@ -1174,9 +1170,8 @@ wallet_commit_channel(struct lightningd *ld,
|
||||
channel->dbid = channel->unsaved_dbid;
|
||||
channel->unsaved_dbid = 0;
|
||||
|
||||
channel->funding_txid = *funding_txid;
|
||||
channel->funding_outnum = funding_outnum;
|
||||
channel->funding = total_funding;
|
||||
channel->funding = *funding;
|
||||
channel->funding_sats = total_funding;
|
||||
channel->our_funds = our_funding;
|
||||
channel->our_msat = our_msat;
|
||||
channel->msat_to_us_min = our_msat;
|
||||
@@ -1231,10 +1226,9 @@ wallet_commit_channel(struct lightningd *ld,
|
||||
|
||||
/* Open attempt to channel's inflights */
|
||||
inflight = new_inflight(channel,
|
||||
channel->funding_txid,
|
||||
channel->funding_outnum,
|
||||
&channel->funding,
|
||||
funding_feerate,
|
||||
channel->funding,
|
||||
channel->funding_sats,
|
||||
channel->our_funds,
|
||||
psbt,
|
||||
channel->last_tx,
|
||||
@@ -1505,8 +1499,8 @@ static void handle_peer_tx_sigs_sent(struct subd *dualopend,
|
||||
/* Tell plugins about the success */
|
||||
notify_channel_opened(dualopend->ld,
|
||||
&channel->peer->id,
|
||||
&channel->funding,
|
||||
&channel->funding_txid,
|
||||
&channel->funding_sats,
|
||||
&channel->funding.txid,
|
||||
&channel->remote_funding_locked);
|
||||
|
||||
/* BOLT-f53ca2301232db780843e894f55d95d512f297f9 #2
|
||||
@@ -1651,7 +1645,7 @@ void dualopen_tell_depth(struct subd *dualopend,
|
||||
/* Are we there yet? */
|
||||
if (to_go == 0) {
|
||||
assert(channel->scid);
|
||||
assert(bitcoin_txid_eq(&channel->funding_txid, txid));
|
||||
assert(bitcoin_txid_eq(&channel->funding.txid, txid));
|
||||
|
||||
channel_set_billboard(channel, false,
|
||||
tal_fmt(tmpctx, "Funding depth reached"
|
||||
@@ -1876,8 +1870,8 @@ static void handle_peer_tx_sigs_msg(struct subd *dualopend,
|
||||
/* Tell plugins about the success */
|
||||
notify_channel_opened(dualopend->ld,
|
||||
&channel->peer->id,
|
||||
&channel->funding,
|
||||
&channel->funding_txid,
|
||||
&channel->funding_sats,
|
||||
&channel->funding.txid,
|
||||
&channel->remote_funding_locked);
|
||||
|
||||
/* BOLT-f53ca2301232db780843e894f55d95d512f297f9 #2
|
||||
@@ -2007,12 +2001,12 @@ static void handle_validate_rbf(struct subd *dualopend,
|
||||
for (size_t i = 0; i < candidate_psbt->num_inputs; i++) {
|
||||
struct wally_tx_input *input =
|
||||
&candidate_psbt->tx->inputs[i];
|
||||
struct bitcoin_txid in_txid;
|
||||
struct bitcoin_outpoint outpoint;
|
||||
|
||||
wally_tx_input_get_txid(input, &in_txid);
|
||||
wally_tx_input_get_outpoint(input, &outpoint);
|
||||
|
||||
if (!psbt_has_input(inflight->funding_psbt,
|
||||
&in_txid, input->index))
|
||||
&outpoint))
|
||||
inputs_present[i] = false;
|
||||
}
|
||||
}
|
||||
@@ -2308,13 +2302,13 @@ json_openchannel_signed(struct command *cmd,
|
||||
/* Verify that the psbt's txid matches that of the
|
||||
* funding txid for this channel */
|
||||
psbt_txid(NULL, psbt, &txid, NULL);
|
||||
if (!bitcoin_txid_eq(&txid, &channel->funding_txid))
|
||||
if (!bitcoin_txid_eq(&txid, &channel->funding.txid))
|
||||
return command_fail(cmd, FUNDING_PSBT_INVALID,
|
||||
"Txid for passed in PSBT does not match"
|
||||
" funding txid for channel. Expected %s, "
|
||||
"received %s",
|
||||
type_to_string(tmpctx, struct bitcoin_txid,
|
||||
&channel->funding_txid),
|
||||
&channel->funding.txid),
|
||||
type_to_string(tmpctx, struct bitcoin_txid,
|
||||
&txid));
|
||||
|
||||
@@ -2325,14 +2319,15 @@ json_openchannel_signed(struct command *cmd,
|
||||
return command_fail(cmd, LIGHTNINGD,
|
||||
"Open attempt for channel not found");
|
||||
|
||||
if (!bitcoin_txid_eq(&txid, &inflight->funding->txid))
|
||||
if (!bitcoin_txid_eq(&txid, &inflight->funding->outpoint.txid))
|
||||
return command_fail(cmd, LIGHTNINGD,
|
||||
"Current inflight transaction is %s,"
|
||||
" not %s",
|
||||
type_to_string(tmpctx, struct bitcoin_txid,
|
||||
&txid),
|
||||
type_to_string(tmpctx, struct bitcoin_txid,
|
||||
&inflight->funding->txid));
|
||||
&inflight->funding
|
||||
->outpoint.txid));
|
||||
|
||||
if (inflight->funding_psbt && psbt_is_finalized(inflight->funding_psbt))
|
||||
return command_fail(cmd, FUNDING_STATE_INVALID,
|
||||
@@ -2709,8 +2704,8 @@ static void handle_commit_received(struct subd *dualopend,
|
||||
struct channel_info channel_info;
|
||||
struct bitcoin_tx *remote_commit;
|
||||
struct bitcoin_signature remote_commit_sig;
|
||||
struct bitcoin_txid funding_txid;
|
||||
u16 funding_outnum, lease_chan_max_ppt;
|
||||
struct bitcoin_outpoint funding;
|
||||
u16 lease_chan_max_ppt;
|
||||
u32 feerate_funding, feerate_commitment, lease_expiry,
|
||||
lease_chan_max_msat, lease_blockheight_start;
|
||||
struct amount_sat total_funding, funding_ours;
|
||||
@@ -2736,8 +2731,7 @@ static void handle_commit_received(struct subd *dualopend,
|
||||
&channel_info.theirbase.delayed_payment,
|
||||
&channel_info.remote_per_commit,
|
||||
&channel_info.remote_fundingkey,
|
||||
&funding_txid,
|
||||
&funding_outnum,
|
||||
&funding,
|
||||
&total_funding,
|
||||
&funding_ours,
|
||||
&channel->channel_flags,
|
||||
@@ -2779,8 +2773,7 @@ static void handle_commit_received(struct subd *dualopend,
|
||||
if (!(inflight = wallet_commit_channel(ld, channel,
|
||||
remote_commit,
|
||||
&remote_commit_sig,
|
||||
&funding_txid,
|
||||
funding_outnum,
|
||||
&funding,
|
||||
total_funding,
|
||||
funding_ours,
|
||||
&channel_info,
|
||||
@@ -2819,8 +2812,7 @@ static void handle_commit_received(struct subd *dualopend,
|
||||
if (!(inflight = wallet_update_channel(ld, channel,
|
||||
remote_commit,
|
||||
&remote_commit_sig,
|
||||
&funding_txid,
|
||||
funding_outnum,
|
||||
&funding,
|
||||
total_funding,
|
||||
funding_ours,
|
||||
feerate_funding,
|
||||
@@ -2861,7 +2853,7 @@ static void handle_commit_received(struct subd *dualopend,
|
||||
json_add_psbt(response, "psbt", psbt);
|
||||
json_add_bool(response, "commitments_secured", true);
|
||||
/* For convenience sake, we include the funding outnum */
|
||||
json_add_num(response, "funding_outnum", funding_outnum);
|
||||
json_add_num(response, "funding_outnum", funding.n);
|
||||
if (oa->our_upfront_shutdown_script) {
|
||||
json_add_hex_talarr(response, "close_to",
|
||||
oa->our_upfront_shutdown_script);
|
||||
@@ -3264,10 +3256,9 @@ void peer_restart_dualopend(struct peer *peer,
|
||||
&channel->local_funding_pubkey,
|
||||
&channel->channel_info.remote_fundingkey,
|
||||
channel->minimum_depth,
|
||||
&inflight->funding->txid,
|
||||
inflight->funding->outnum,
|
||||
&inflight->funding->outpoint,
|
||||
inflight->funding->feerate,
|
||||
channel->funding,
|
||||
channel->funding_sats,
|
||||
channel->our_msat,
|
||||
&channel->channel_info.theirbase,
|
||||
&channel->channel_info.remote_per_commit,
|
||||
|
||||
@@ -57,7 +57,7 @@ static void got_filteredblock(struct bitcoind *bitcoind,
|
||||
u32 txindex = short_channel_id_txnum(scid);
|
||||
for (size_t i=0; i<tal_count(fb->outpoints); i++) {
|
||||
o = fb->outpoints[i];
|
||||
if (o->txindex == txindex && o->outnum == outnum) {
|
||||
if (o->txindex == txindex && o->outpoint.n == outnum) {
|
||||
fbo = o;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -585,7 +585,7 @@ static struct route_info **select_inchan(const tal_t *ctx,
|
||||
if (!amount_sat_add(&cumulative_reserve,
|
||||
candidates[i].c->our_config.channel_reserve,
|
||||
candidates[i].c->channel_info.their_config.channel_reserve)
|
||||
|| !amount_sat_to_msat(&capacity, candidates[i].c->funding)
|
||||
|| !amount_sat_to_msat(&capacity, candidates[i].c->funding_sats)
|
||||
|| !amount_msat_sub_sat(&capacity, capacity, cumulative_reserve)) {
|
||||
log_broken(ld->log, "Channel %s capacity overflow!",
|
||||
type_to_string(tmpctx, struct short_channel_id, candidates[i].c->scid));
|
||||
|
||||
@@ -194,6 +194,7 @@ void notify_invoice_creation(struct lightningd *ld, struct amount_msat *amount,
|
||||
plugins_notify(ld->plugins, take(n));
|
||||
}
|
||||
|
||||
/* FIXME: Use outpoint here! */
|
||||
static void channel_opened_notification_serialize(struct json_stream *stream,
|
||||
struct node_id *node_id,
|
||||
struct amount_sat *funding_sat,
|
||||
@@ -437,11 +438,11 @@ static void json_mvt_id(struct json_stream *stream, enum mvt_type mvt_type,
|
||||
/* some chain ledger entries aren't associated with a utxo
|
||||
* e.g. journal updates (due to penalty/state loss) and
|
||||
* chain_fee entries */
|
||||
if (id->output_txid) {
|
||||
if (id->outpoint) {
|
||||
json_add_string(stream, "utxo_txid",
|
||||
type_to_string(tmpctx, struct bitcoin_txid,
|
||||
id->output_txid));
|
||||
json_add_u32(stream, "vout", id->vout);
|
||||
&id->outpoint->txid));
|
||||
json_add_u32(stream, "vout", id->outpoint->n);
|
||||
}
|
||||
|
||||
/* on-chain htlcs include a payment hash */
|
||||
|
||||
@@ -185,18 +185,18 @@ static enum watch_result onchain_txo_watched(struct channel *channel,
|
||||
static void watch_tx_and_outputs(struct channel *channel,
|
||||
const struct bitcoin_tx *tx)
|
||||
{
|
||||
struct bitcoin_txid txid;
|
||||
struct bitcoin_outpoint outpoint;
|
||||
struct txwatch *txw;
|
||||
struct lightningd *ld = channel->peer->ld;
|
||||
|
||||
bitcoin_txid(tx, &txid);
|
||||
bitcoin_txid(tx, &outpoint.txid);
|
||||
|
||||
/* Make txwatch a parent of txo watches, so we can unwatch together. */
|
||||
txw = watch_tx(channel->owner, ld->topology, channel, tx,
|
||||
onchain_tx_watched);
|
||||
|
||||
for (size_t i = 0; i < tx->wtx->num_outputs; i++)
|
||||
watch_txo(txw, ld->topology, channel, &txid, i,
|
||||
for (outpoint.n = 0; outpoint.n < tx->wtx->num_outputs; outpoint.n++)
|
||||
watch_txo(txw, ld->topology, channel, &outpoint,
|
||||
onchain_txo_watched);
|
||||
}
|
||||
|
||||
@@ -381,14 +381,14 @@ static void onchain_add_utxo(struct channel *channel, const u8 *msg)
|
||||
{
|
||||
struct chain_coin_mvt *mvt;
|
||||
u32 blockheight;
|
||||
struct bitcoin_txid txid;
|
||||
u32 outnum, csv_lock;
|
||||
struct bitcoin_outpoint outpoint;
|
||||
u32 csv_lock;
|
||||
struct amount_sat amount;
|
||||
struct pubkey *commitment_point;
|
||||
u8 *scriptPubkey;
|
||||
|
||||
if (!fromwire_onchaind_add_utxo(
|
||||
tmpctx, msg, &txid, &outnum, &commitment_point,
|
||||
tmpctx, msg, &outpoint, &commitment_point,
|
||||
&amount, &blockheight, &scriptPubkey,
|
||||
&csv_lock)) {
|
||||
log_broken(channel->log,
|
||||
@@ -399,32 +399,30 @@ static void onchain_add_utxo(struct channel *channel, const u8 *msg)
|
||||
|
||||
assert(blockheight);
|
||||
outpointfilter_add(channel->peer->ld->wallet->owned_outpoints,
|
||||
&txid, outnum);
|
||||
log_debug(channel->log, "adding utxo to watch %s:%u, csv %u",
|
||||
type_to_string(tmpctx, struct bitcoin_txid, &txid),
|
||||
outnum, csv_lock);
|
||||
&outpoint);
|
||||
log_debug(channel->log, "adding utxo to watch %s, csv %u",
|
||||
type_to_string(tmpctx, struct bitcoin_outpoint, &outpoint),
|
||||
csv_lock);
|
||||
|
||||
wallet_add_onchaind_utxo(channel->peer->ld->wallet,
|
||||
&txid, outnum, scriptPubkey,
|
||||
&outpoint, scriptPubkey,
|
||||
blockheight, amount, channel,
|
||||
commitment_point,
|
||||
csv_lock);
|
||||
|
||||
mvt = new_coin_deposit_sat(msg, "wallet", &txid,
|
||||
outnum, blockheight, amount);
|
||||
mvt = new_coin_deposit_sat(msg, "wallet", &outpoint, blockheight, amount);
|
||||
notify_chain_mvt(channel->peer->ld, mvt);
|
||||
}
|
||||
|
||||
static void onchain_annotate_txout(struct channel *channel, const u8 *msg)
|
||||
{
|
||||
struct bitcoin_txid txid;
|
||||
struct bitcoin_outpoint outpoint;
|
||||
enum wallet_tx_type type;
|
||||
u32 outnum;
|
||||
if (!fromwire_onchaind_annotate_txout(msg, &txid, &outnum, &type))
|
||||
if (!fromwire_onchaind_annotate_txout(msg, &outpoint, &type))
|
||||
fatal("onchaind gave invalid onchain_annotate_txout "
|
||||
"message: %s",
|
||||
tal_hex(msg, msg));
|
||||
wallet_annotate_txout(channel->peer->ld->wallet, &txid, outnum, type,
|
||||
wallet_annotate_txout(channel->peer->ld->wallet, &outpoint, type,
|
||||
channel->dbid);
|
||||
}
|
||||
|
||||
@@ -636,7 +634,7 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
if (!feerates[i]) {
|
||||
/* We have at least one data point: the last tx's feerate. */
|
||||
struct amount_sat fee = channel->funding;
|
||||
struct amount_sat fee = channel->funding_sats;
|
||||
for (size_t i = 0;
|
||||
i < channel->last_tx->wtx->num_outputs; i++) {
|
||||
struct amount_asset asset =
|
||||
@@ -649,7 +647,7 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
|
||||
" funding %s tx %s",
|
||||
type_to_string(tmpctx,
|
||||
struct amount_sat,
|
||||
&channel->funding),
|
||||
&channel->funding_sats),
|
||||
type_to_string(tmpctx,
|
||||
struct bitcoin_tx,
|
||||
channel->last_tx));
|
||||
@@ -669,7 +667,7 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
|
||||
msg = towire_onchaind_init(channel,
|
||||
&channel->their_shachain.chain,
|
||||
chainparams,
|
||||
channel->funding,
|
||||
channel->funding_sats,
|
||||
channel->our_msat,
|
||||
&channel->channel_info.old_remote_per_commit,
|
||||
&channel->channel_info.remote_per_commit,
|
||||
|
||||
@@ -65,7 +65,7 @@ struct funding_channel {
|
||||
|
||||
struct wallet_tx *wtx;
|
||||
struct amount_msat push;
|
||||
struct amount_sat funding;
|
||||
struct amount_sat funding_sats;
|
||||
u8 channel_flags;
|
||||
const u8 *our_upfront_shutdown_script;
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ void json_add_uncommitted_channel(struct json_stream *response,
|
||||
}
|
||||
|
||||
/* These should never fail. */
|
||||
if (amount_sat_to_msat(&total, uc->fc->funding)
|
||||
if (amount_sat_to_msat(&total, uc->fc->funding_sats)
|
||||
&& amount_msat_sub(&ours, total, uc->fc->push)) {
|
||||
json_add_amount_msat_compat(response, ours,
|
||||
"msatoshi_to_us", "to_us_msat");
|
||||
@@ -80,9 +80,8 @@ wallet_commit_channel(struct lightningd *ld,
|
||||
struct channel_id *cid,
|
||||
struct bitcoin_tx *remote_commit,
|
||||
struct bitcoin_signature *remote_commit_sig,
|
||||
const struct bitcoin_txid *funding_txid,
|
||||
u16 funding_outnum,
|
||||
struct amount_sat funding,
|
||||
const struct bitcoin_outpoint *funding,
|
||||
struct amount_sat funding_sats,
|
||||
struct amount_msat push,
|
||||
u8 channel_flags,
|
||||
struct channel_info *channel_info,
|
||||
@@ -111,15 +110,15 @@ wallet_commit_channel(struct lightningd *ld,
|
||||
}
|
||||
|
||||
if (uc->fc) {
|
||||
if (!amount_sat_sub_msat(&our_msat, funding, push)) {
|
||||
if (!amount_sat_sub_msat(&our_msat, funding_sats, push)) {
|
||||
log_broken(uc->log, "push %s exceeds funding %s",
|
||||
type_to_string(tmpctx, struct amount_msat,
|
||||
&push),
|
||||
type_to_string(tmpctx, struct amount_sat,
|
||||
&funding));
|
||||
&funding_sats));
|
||||
return NULL;
|
||||
}
|
||||
local_funding = funding;
|
||||
local_funding = funding_sats;
|
||||
} else {
|
||||
our_msat = push;
|
||||
local_funding = AMOUNT_SAT(0);
|
||||
@@ -166,9 +165,8 @@ wallet_commit_channel(struct lightningd *ld,
|
||||
&uc->our_config,
|
||||
uc->minimum_depth,
|
||||
1, 1, 0,
|
||||
funding_txid,
|
||||
funding_outnum,
|
||||
funding,
|
||||
funding_sats,
|
||||
push,
|
||||
local_funding,
|
||||
false, /* !remote_funding_locked */
|
||||
@@ -332,8 +330,7 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
|
||||
{
|
||||
struct channel_info channel_info;
|
||||
struct channel_id cid;
|
||||
struct bitcoin_txid funding_txid;
|
||||
u16 funding_txout;
|
||||
struct bitcoin_outpoint funding;
|
||||
struct bitcoin_signature remote_commit_sig;
|
||||
struct bitcoin_tx *remote_commit;
|
||||
u32 feerate;
|
||||
@@ -360,8 +357,7 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
|
||||
&channel_info.remote_per_commit,
|
||||
&fc->uc->minimum_depth,
|
||||
&channel_info.remote_fundingkey,
|
||||
&funding_txid,
|
||||
&funding_txout,
|
||||
&funding,
|
||||
&feerate,
|
||||
&fc->uc->our_config.channel_reserve,
|
||||
&remote_upfront_shutdown_script,
|
||||
@@ -382,7 +378,7 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
|
||||
&channel_info.remote_per_commit));
|
||||
|
||||
/* Saved with channel to disk */
|
||||
derive_channel_id(&cid, &funding_txid, funding_txout);
|
||||
derive_channel_id(&cid, &funding);
|
||||
|
||||
/* old_remote_per_commit not valid yet, copy valid one. */
|
||||
channel_info.old_remote_per_commit = channel_info.remote_per_commit;
|
||||
@@ -392,9 +388,8 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
|
||||
&cid,
|
||||
remote_commit,
|
||||
&remote_commit_sig,
|
||||
&funding_txid,
|
||||
funding_txout,
|
||||
fc->funding,
|
||||
&funding,
|
||||
fc->funding_sats,
|
||||
fc->push,
|
||||
fc->channel_flags,
|
||||
&channel_info,
|
||||
@@ -435,9 +430,8 @@ static void opening_fundee_finished(struct subd *openingd,
|
||||
struct bitcoin_tx *remote_commit;
|
||||
struct channel_id cid;
|
||||
struct lightningd *ld = openingd->ld;
|
||||
struct bitcoin_txid funding_txid;
|
||||
u16 funding_outnum;
|
||||
struct amount_sat funding;
|
||||
struct bitcoin_outpoint funding;
|
||||
struct amount_sat funding_sats;
|
||||
struct amount_msat push;
|
||||
u32 feerate;
|
||||
u8 channel_flags;
|
||||
@@ -464,9 +458,8 @@ static void opening_fundee_finished(struct subd *openingd,
|
||||
&channel_info.theirbase.delayed_payment,
|
||||
&channel_info.remote_per_commit,
|
||||
&channel_info.remote_fundingkey,
|
||||
&funding_txid,
|
||||
&funding_outnum,
|
||||
&funding,
|
||||
&funding_sats,
|
||||
&push,
|
||||
&channel_flags,
|
||||
&feerate,
|
||||
@@ -493,7 +486,7 @@ static void opening_fundee_finished(struct subd *openingd,
|
||||
goto failed;
|
||||
}
|
||||
|
||||
derive_channel_id(&cid, &funding_txid, funding_outnum);
|
||||
derive_channel_id(&cid, &funding);
|
||||
|
||||
/* old_remote_per_commit not valid yet, copy valid one. */
|
||||
channel_info.old_remote_per_commit = channel_info.remote_per_commit;
|
||||
@@ -503,9 +496,8 @@ static void opening_fundee_finished(struct subd *openingd,
|
||||
&cid,
|
||||
remote_commit,
|
||||
&remote_commit_sig,
|
||||
&funding_txid,
|
||||
funding_outnum,
|
||||
funding,
|
||||
&funding,
|
||||
funding_sats,
|
||||
push,
|
||||
channel_flags,
|
||||
&channel_info,
|
||||
@@ -521,13 +513,13 @@ static void opening_fundee_finished(struct subd *openingd,
|
||||
|
||||
log_debug(channel->log, "Watching funding tx %s",
|
||||
type_to_string(reply, struct bitcoin_txid,
|
||||
&channel->funding_txid));
|
||||
&channel->funding.txid));
|
||||
|
||||
channel_watch_funding(ld, channel);
|
||||
|
||||
/* Tell plugins about the success */
|
||||
notify_channel_opened(ld, &channel->peer->id, &channel->funding,
|
||||
&channel->funding_txid, &channel->remote_funding_locked);
|
||||
notify_channel_opened(ld, &channel->peer->id, &channel->funding_sats,
|
||||
&channel->funding.txid, &channel->remote_funding_locked);
|
||||
|
||||
if (pbase)
|
||||
wallet_penalty_base_add(ld->wallet, channel->dbid, pbase);
|
||||
@@ -1054,14 +1046,14 @@ static struct command_result *json_fundchannel_complete(struct command *cmd,
|
||||
if (!chainparams->is_elements
|
||||
&& !amount_sat_eq(amount_sat(funding_psbt->tx->outputs
|
||||
[*funding_txout_num].satoshi),
|
||||
fc->funding))
|
||||
fc->funding_sats))
|
||||
return command_fail(cmd, FUNDING_PSBT_INVALID,
|
||||
"Output to open channel is %"PRIu64"sat,"
|
||||
" should be %s",
|
||||
funding_psbt->tx->outputs
|
||||
[*funding_txout_num].satoshi,
|
||||
type_to_string(tmpctx, struct amount_sat,
|
||||
&fc->funding));
|
||||
&fc->funding_sats));
|
||||
|
||||
funding_txid = tal(cmd, struct bitcoin_txid);
|
||||
psbt_txid(NULL, funding_psbt, funding_txid, NULL);
|
||||
@@ -1165,7 +1157,7 @@ static struct command_result *json_fundchannel_start(struct command *cmd,
|
||||
type_to_string(tmpctx, struct amount_msat, push_msat),
|
||||
type_to_string(tmpctx, struct amount_sat, amount));
|
||||
|
||||
fc->funding = *amount;
|
||||
fc->funding_sats = *amount;
|
||||
if (!feerate_per_kw) {
|
||||
feerate_per_kw = tal(cmd, u32);
|
||||
*feerate_per_kw = opening_feerate(cmd->ld->topology);
|
||||
|
||||
@@ -579,7 +579,8 @@ struct amount_msat channel_amount_receivable(const struct channel *channel)
|
||||
struct amount_msat their_msat, receivable;
|
||||
|
||||
/* Compute how much we can receive via this channel in one payment */
|
||||
if (!amount_sat_sub_msat(&their_msat, channel->funding, channel->our_msat))
|
||||
if (!amount_sat_sub_msat(&their_msat,
|
||||
channel->funding_sats, channel->our_msat))
|
||||
their_msat = AMOUNT_MSAT(0);
|
||||
|
||||
if (!amount_msat_sub_sat(&receivable,
|
||||
@@ -653,7 +654,7 @@ static void json_add_channel(struct lightningd *ld,
|
||||
|
||||
json_add_string(response, "channel_id",
|
||||
type_to_string(tmpctx, struct channel_id, &channel->cid));
|
||||
json_add_txid(response, "funding_txid", &channel->funding_txid);
|
||||
json_add_txid(response, "funding_txid", &channel->funding.txid);
|
||||
|
||||
if (!list_empty(&channel->inflights)) {
|
||||
struct channel_inflight *initial, *inflight;
|
||||
@@ -690,9 +691,9 @@ static void json_add_channel(struct lightningd *ld,
|
||||
|
||||
json_object_start(response, NULL);
|
||||
json_add_txid(response, "funding_txid",
|
||||
&inflight->funding->txid);
|
||||
&inflight->funding->outpoint.txid);
|
||||
json_add_num(response, "funding_outnum",
|
||||
inflight->funding->outnum);
|
||||
inflight->funding->outpoint.n);
|
||||
json_add_string(response, "feerate",
|
||||
tal_fmt(tmpctx, "%d%s",
|
||||
inflight->funding->feerate,
|
||||
@@ -743,12 +744,12 @@ static void json_add_channel(struct lightningd *ld,
|
||||
json_add_string(response, NULL, "option_anchor_outputs");
|
||||
json_array_end(response);
|
||||
|
||||
if (!amount_sat_sub(&peer_funded_sats, channel->funding,
|
||||
if (!amount_sat_sub(&peer_funded_sats, channel->funding_sats,
|
||||
channel->our_funds)) {
|
||||
log_broken(channel->log,
|
||||
"Overflow subtracing funding %s, our funds %s",
|
||||
type_to_string(tmpctx, struct amount_sat,
|
||||
&channel->funding),
|
||||
&channel->funding_sats),
|
||||
type_to_string(tmpctx, struct amount_sat,
|
||||
&channel->our_funds));
|
||||
peer_funded_sats = AMOUNT_SAT(0);
|
||||
@@ -791,11 +792,11 @@ static void json_add_channel(struct lightningd *ld,
|
||||
json_add_sat_only(response, "remote_msat", peer_funded_sats);
|
||||
json_object_end(response);
|
||||
|
||||
if (!amount_sat_to_msat(&funding_msat, channel->funding)) {
|
||||
if (!amount_sat_to_msat(&funding_msat, channel->funding_sats)) {
|
||||
log_broken(channel->log,
|
||||
"Overflow converting funding %s",
|
||||
type_to_string(tmpctx, struct amount_sat,
|
||||
&channel->funding));
|
||||
&channel->funding_sats));
|
||||
funding_msat = AMOUNT_MSAT(0);
|
||||
}
|
||||
json_add_amount_msat_compat(response, channel->our_msat,
|
||||
@@ -1203,14 +1204,14 @@ static bool check_funding_tx(const struct bitcoin_tx *tx,
|
||||
* actually contain the funding output). As of v2 (where
|
||||
* RBF is introduced), this isn't a problem so much as
|
||||
* both sides have full access to the funding transaction */
|
||||
if (check_funding_details(tx, wscript, channel->funding,
|
||||
channel->funding_outnum))
|
||||
if (check_funding_details(tx, wscript, channel->funding_sats,
|
||||
channel->funding.n))
|
||||
return true;
|
||||
|
||||
list_for_each(&channel->inflights, inflight, list) {
|
||||
if (check_funding_details(tx, wscript,
|
||||
inflight->funding->total_funds,
|
||||
inflight->funding->outnum))
|
||||
inflight->funding->outpoint.n))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -1222,9 +1223,8 @@ static void update_channel_from_inflight(struct lightningd *ld,
|
||||
{
|
||||
struct wally_psbt *psbt_copy;
|
||||
|
||||
channel->funding_txid = inflight->funding->txid;
|
||||
channel->funding_outnum = inflight->funding->outnum;
|
||||
channel->funding = inflight->funding->total_funds;
|
||||
channel->funding = inflight->funding->outpoint;
|
||||
channel->funding_sats = inflight->funding->total_funds;
|
||||
channel->our_funds = inflight->funding->our_funds;
|
||||
|
||||
/* Lease infos ! */
|
||||
@@ -1306,17 +1306,17 @@ static enum watch_result funding_depth_cb(struct lightningd *ld,
|
||||
update_channel_from_inflight(ld, channel, inf);
|
||||
}
|
||||
|
||||
wallet_annotate_txout(ld->wallet, txid, channel->funding_outnum,
|
||||
wallet_annotate_txout(ld->wallet, &channel->funding,
|
||||
TX_CHANNEL_FUNDING, channel->dbid);
|
||||
loc = wallet_transaction_locate(tmpctx, ld->wallet, txid);
|
||||
if (!mk_short_channel_id(&scid,
|
||||
loc->blkheight, loc->index,
|
||||
channel->funding_outnum)) {
|
||||
channel->funding.n)) {
|
||||
channel_fail_permanent(channel,
|
||||
REASON_LOCAL,
|
||||
"Invalid funding scid %u:%u:%u",
|
||||
loc->blkheight, loc->index,
|
||||
channel->funding_outnum);
|
||||
channel->funding.n);
|
||||
return DELETE_WATCH;
|
||||
}
|
||||
|
||||
@@ -1373,8 +1373,7 @@ void channel_watch_wrong_funding(struct lightningd *ld, struct channel *channel)
|
||||
if (channel->shutdown_wrong_funding) {
|
||||
/* FIXME: Remove arg from cb? */
|
||||
watch_txo(channel, ld->topology, channel,
|
||||
&channel->shutdown_wrong_funding->txid,
|
||||
channel->shutdown_wrong_funding->n,
|
||||
channel->shutdown_wrong_funding,
|
||||
funding_spent);
|
||||
}
|
||||
}
|
||||
@@ -1383,9 +1382,9 @@ void channel_watch_funding(struct lightningd *ld, struct channel *channel)
|
||||
{
|
||||
/* FIXME: Remove arg from cb? */
|
||||
watch_txid(channel, ld->topology, channel,
|
||||
&channel->funding_txid, funding_depth_cb);
|
||||
&channel->funding.txid, funding_depth_cb);
|
||||
watch_txo(channel, ld->topology, channel,
|
||||
&channel->funding_txid, channel->funding_outnum,
|
||||
&channel->funding,
|
||||
funding_spent);
|
||||
channel_watch_wrong_funding(ld, channel);
|
||||
}
|
||||
@@ -1396,10 +1395,9 @@ static void channel_watch_inflight(struct lightningd *ld,
|
||||
{
|
||||
/* FIXME: Remove arg from cb? */
|
||||
watch_txid(channel, ld->topology, channel,
|
||||
&inflight->funding->txid, funding_depth_cb);
|
||||
&inflight->funding->outpoint.txid, funding_depth_cb);
|
||||
watch_txo(channel, ld->topology, channel,
|
||||
&inflight->funding->txid,
|
||||
inflight->funding->outnum,
|
||||
&inflight->funding->outpoint,
|
||||
funding_spent);
|
||||
}
|
||||
|
||||
@@ -1574,8 +1572,8 @@ static void activate_peer(struct peer *peer, u32 delay)
|
||||
list_for_each(&channel->inflights, inflight, list) {
|
||||
/* Don't double watch the txid that's also in
|
||||
* channel->funding_txid */
|
||||
if (bitcoin_txid_eq(&channel->funding_txid,
|
||||
&inflight->funding->txid))
|
||||
if (bitcoin_txid_eq(&channel->funding.txid,
|
||||
&inflight->funding->outpoint.txid))
|
||||
continue;
|
||||
|
||||
channel_watch_inflight(ld, channel, inflight);
|
||||
@@ -2096,7 +2094,7 @@ static struct command_result *json_sign_last_tx(struct command *cmd,
|
||||
&inflight->last_sig);
|
||||
json_object_start(response, NULL);
|
||||
json_add_txid(response, "funding_txid",
|
||||
&inflight->funding->txid);
|
||||
&inflight->funding->outpoint.txid);
|
||||
remove_sig(inflight->last_tx);
|
||||
json_add_tx(response, "tx", channel->last_tx);
|
||||
json_object_end(response);
|
||||
@@ -2240,7 +2238,7 @@ static void process_dev_forget_channel(struct bitcoind *bitcoind UNUSED,
|
||||
response = json_stream_success(forget->cmd);
|
||||
json_add_bool(response, "forced", forget->force);
|
||||
json_add_bool(response, "funding_unspent", txout != NULL);
|
||||
json_add_txid(response, "funding_txid", &forget->channel->funding_txid);
|
||||
json_add_txid(response, "funding_txid", &forget->channel->funding.txid);
|
||||
|
||||
/* Set error so we don't try to reconnect. */
|
||||
forget->channel->error = towire_errorfmt(forget->channel,
|
||||
@@ -2316,8 +2314,7 @@ static struct command_result *json_dev_forget_channel(struct command *cmd,
|
||||
|
||||
if (!channel_unsaved(forget->channel))
|
||||
bitcoind_getutxout(cmd->ld->topology->bitcoind,
|
||||
&forget->channel->funding_txid,
|
||||
forget->channel->funding_outnum,
|
||||
&forget->channel->funding,
|
||||
process_dev_forget_channel, forget);
|
||||
return command_still_pending(cmd);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ struct channel *active_channel_by_scid(struct lightningd *ld UNNEEDED,
|
||||
{ fprintf(stderr, "active_channel_by_scid called!\n"); abort(); }
|
||||
/* Generated stub for bitcoind_getutxout_ */
|
||||
void bitcoind_getutxout_(struct bitcoind *bitcoind UNNEEDED,
|
||||
const struct bitcoin_txid *txid UNNEEDED, const u32 outnum UNNEEDED,
|
||||
const struct bitcoin_outpoint *outpoint UNNEEDED,
|
||||
void (*cb)(struct bitcoind *bitcoind UNNEEDED,
|
||||
const struct bitcoin_tx_output *txout UNNEEDED,
|
||||
void *arg) UNNEEDED,
|
||||
@@ -676,8 +676,9 @@ u8 *towire_warningfmt(const tal_t *ctx UNNEEDED,
|
||||
const char *version(void)
|
||||
{ fprintf(stderr, "version called!\n"); abort(); }
|
||||
/* Generated stub for wallet_annotate_txout */
|
||||
void wallet_annotate_txout(struct wallet *w UNNEEDED, const struct bitcoin_txid *txid UNNEEDED,
|
||||
int outnum UNNEEDED, enum wallet_tx_type type UNNEEDED, u64 channel UNNEEDED)
|
||||
void wallet_annotate_txout(struct wallet *w UNNEEDED,
|
||||
const struct bitcoin_outpoint *outpoint UNNEEDED,
|
||||
enum wallet_tx_type type UNNEEDED, u64 channel UNNEEDED)
|
||||
{ fprintf(stderr, "wallet_annotate_txout called!\n"); abort(); }
|
||||
/* Generated stub for wallet_channel_save */
|
||||
void wallet_channel_save(struct wallet *w UNNEEDED, struct channel *chan UNNEEDED)
|
||||
@@ -820,8 +821,7 @@ struct txwatch *watch_txid(const tal_t *ctx UNNEEDED,
|
||||
struct txowatch *watch_txo(const tal_t *ctx UNNEEDED,
|
||||
struct chain_topology *topo UNNEEDED,
|
||||
struct channel *channel UNNEEDED,
|
||||
const struct bitcoin_txid *txid UNNEEDED,
|
||||
unsigned int output UNNEEDED,
|
||||
const struct bitcoin_outpoint *outpoint UNNEEDED,
|
||||
enum watch_result (*cb)(struct channel *channel UNNEEDED,
|
||||
const struct bitcoin_tx *tx UNNEEDED,
|
||||
size_t input_num UNNEEDED,
|
||||
@@ -870,7 +870,7 @@ static struct channel *add_peer(struct lightningd *ld, int n,
|
||||
c->opener = LOCAL;
|
||||
c->peer = peer;
|
||||
/* Channel has incoming capacity n*1000 - 1 millisatoshi */
|
||||
c->funding.satoshis = n+1;
|
||||
c->funding_sats.satoshis = n+1;
|
||||
c->our_msat = AMOUNT_MSAT(1);
|
||||
c->our_config.channel_reserve = AMOUNT_SAT(1);
|
||||
c->our_config.htlc_minimum = AMOUNT_MSAT(0);
|
||||
|
||||
@@ -187,8 +187,7 @@ struct txwatch *watch_tx(const tal_t *ctx,
|
||||
struct txowatch *watch_txo(const tal_t *ctx,
|
||||
struct chain_topology *topo,
|
||||
struct channel *channel,
|
||||
const struct bitcoin_txid *txid,
|
||||
unsigned int output,
|
||||
const struct bitcoin_outpoint *outpoint,
|
||||
enum watch_result (*cb)(struct channel *channel,
|
||||
const struct bitcoin_tx *tx,
|
||||
size_t input_num,
|
||||
@@ -197,8 +196,7 @@ struct txowatch *watch_txo(const tal_t *ctx,
|
||||
struct txowatch *w = tal(ctx, struct txowatch);
|
||||
|
||||
w->topo = topo;
|
||||
w->out.txid = *txid;
|
||||
w->out.n = output;
|
||||
w->out = *outpoint;
|
||||
w->channel = channel;
|
||||
w->cb = cb;
|
||||
|
||||
|
||||
@@ -53,8 +53,7 @@ struct txwatch *watch_tx(const tal_t *ctx,
|
||||
struct txowatch *watch_txo(const tal_t *ctx,
|
||||
struct chain_topology *topo,
|
||||
struct channel *channel,
|
||||
const struct bitcoin_txid *txid,
|
||||
unsigned int output,
|
||||
const struct bitcoin_outpoint *outpoint,
|
||||
enum watch_result (*cb)(struct channel *channel,
|
||||
const struct bitcoin_tx *tx,
|
||||
size_t input_num,
|
||||
|
||||
Reference in New Issue
Block a user