wally: Migrate main daemon to use wally transactions

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker
2019-03-25 11:35:56 +01:00
committed by Rusty Russell
parent c39963b8b7
commit d651ce6f3b
13 changed files with 73 additions and 69 deletions

View File

@@ -69,11 +69,11 @@ static void filter_block_txs(struct chain_topology *topo, struct block *b)
size_t j;
/* Tell them if it spends a txo we care about. */
for (j = 0; j < tal_count(tx->input); j++) {
for (j = 0; j < tx->wtx->num_inputs; j++) {
struct txwatch_output out;
struct txowatch *txo;
out.txid = tx->input[j].txid;
out.index = tx->input[j].index;
bitcoin_tx_input_get_txid(tx, j, &out.txid);
out.index = tx->wtx->inputs[j].index;
txo = txowatch_hash_get(&topo->txowatches, &out);
if (txo) {
@@ -571,10 +571,13 @@ static void topo_update_spends(struct chain_topology *topo, struct block *b)
const struct short_channel_id *scid;
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 < tal_count(tx->input); j++) {
const struct bitcoin_tx_input *input = &tx->input[j];
for (size_t j = 0; j < tx->wtx->num_inputs; j++) {
const struct wally_tx_input *input = &tx->wtx->inputs[j];
struct bitcoin_txid txid;
bitcoin_tx_input_get_txid(tx, j, &txid);
scid = wallet_outpoint_spend(topo->ld->wallet, tmpctx,
b->height, &input->txid,
b->height, &txid,
input->index);
if (scid) {
gossipd_notify_spend(topo->bitcoind->ld, scid);
@@ -588,12 +591,14 @@ 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 < tal_count(tx->output); j++) {
const struct bitcoin_tx_output *output = &tx->output[j];
if (is_p2wsh(output->script, NULL)) {
for (size_t j = 0; j < tx->wtx->num_outputs; j++) {
const u8 *script = bitcoin_tx_output_get_script(tmpctx, tx, j);
struct amount_sat amt = bitcoin_tx_output_get_amount(tx, j);
if (is_p2wsh(script, NULL)) {
wallet_utxoset_add(topo->ld->wallet, tx, j,
b->height, i, output->script,
output->amount);
b->height, i, script,
amt);
}
}
}

View File

@@ -20,9 +20,10 @@
static struct amount_sat calc_tx_fee(struct amount_sat sat_in,
const struct bitcoin_tx *tx)
{
struct amount_sat fee = sat_in;
for (size_t i = 0; i < tal_count(tx->output); i++) {
if (!amount_sat_sub(&fee, fee, tx->output[i].amount))
struct amount_sat amt, fee = sat_in;
for (size_t i = 0; i < tx->wtx->num_outputs; i++) {
amt = bitcoin_tx_output_get_amount(tx, i);
if (!amount_sat_sub(&fee, fee, amt))
fatal("Tx spends more than input %s? %s",
type_to_string(tmpctx, struct amount_sat, &sat_in),
type_to_string(tmpctx, struct bitcoin_tx, tx));

View File

@@ -157,7 +157,7 @@ static void watch_tx_and_outputs(struct channel *channel,
txw = watch_tx(channel->owner, ld->topology, channel, tx,
onchain_tx_watched);
for (size_t i = 0; i < tal_count(tx->output); i++)
for (size_t i = 0; i < tx->wtx->num_outputs; i++)
watch_txo(txw, ld->topology, channel, &txid, i,
onchain_txo_watched);
}
@@ -450,9 +450,10 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
if (!feerate) {
/* We have at least one data point: the last tx's feerate. */
struct amount_sat fee = channel->funding;
for (size_t i = 0; i < tal_count(channel->last_tx->output); i++)
for (size_t i = 0; i < channel->last_tx->wtx->num_outputs; i++)
if (!amount_sat_sub(&fee, fee,
channel->last_tx->output[i].amount)) {
bitcoin_tx_output_get_amount(
channel->last_tx, i))) {
log_broken(channel->log, "Could not get fee"
" funding %s tx %s",
type_to_string(tmpctx,

View File

@@ -343,17 +343,19 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
ld->wallet->bip32_base);
log_debug(fc->uc->log, "Funding tx has %zi inputs, %zu outputs:",
tal_count(fundingtx->input),
tal_count(fundingtx->output));
fundingtx->wtx->num_inputs,
fundingtx->wtx->num_outputs);
for (size_t i = 0; i < tal_count(fundingtx->input); i++) {
for (size_t i = 0; i < fundingtx->wtx->num_inputs; i++) {
struct bitcoin_txid tmptxid;
bitcoin_tx_input_get_txid(fundingtx, i, &tmptxid);
log_debug(fc->uc->log, "%zi: %s (%s) %s\n",
i,
type_to_string(tmpctx, struct amount_sat,
&fc->wtx.utxos[i]->amount),
fc->wtx.utxos[i]->is_p2sh ? "P2SH" : "SEGWIT",
type_to_string(tmpctx, struct bitcoin_txid,
&fundingtx->input[i].txid));
&tmptxid));
}
bitcoin_txid(fundingtx, &funding_txid);
@@ -433,8 +435,8 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
/* Make sure we recognize our change output by its scriptpubkey in
* future. This assumes that we have only two outputs, may not be true
* if we add support for multifundchannel */
if (tal_count(fundingtx->output) == 2)
txfilter_add_scriptpubkey(ld->owned_txfilter, fundingtx->output[!funding_outnum].script);
if (fundingtx->wtx->num_outputs == 2)
txfilter_add_scriptpubkey(ld->owned_txfilter, bitcoin_tx_output_get_script(tmpctx, fundingtx, !funding_outnum));
/* We need these to compose cmd's response in funding_broadcast_success */
fc->hextx = tal_hex(fc, linearize_tx(fc->cmd, fundingtx));

View File

@@ -200,7 +200,7 @@ static void sign_last_tx(struct channel *channel)
struct bitcoin_signature sig;
u8 *msg, **witness;
assert(!channel->last_tx->input[0].witness);
assert(!channel->last_tx->wtx->inputs[0].witness);
msg = towire_hsm_sign_commitment_tx(tmpctx,
&channel->peer->id,
@@ -219,7 +219,7 @@ static void sign_last_tx(struct channel *channel)
tal_hex(tmpctx, msg));
witness =
bitcoin_witness_2of2(channel->last_tx->input, &channel->last_sig,
bitcoin_witness_2of2(channel->last_tx, &channel->last_sig,
&sig, &channel->channel_info.remote_fundingkey,
&channel->local_funding_pubkey);
@@ -1532,7 +1532,7 @@ static struct command_result *json_sign_last_tx(struct command *cmd,
response = json_stream_success(cmd);
log_debug(channel->log, "dev-sign-last-tx: signing tx with %zu outputs",
tal_count(channel->last_tx->output));
channel->last_tx->wtx->num_outputs);
sign_last_tx(channel);
linear = linearize_tx(cmd, channel->last_tx);
remove_sig(channel->last_tx);