wallet: fix spending of change.

We recorded our own change as P2SH; it's not.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2017-09-12 21:20:47 +09:30 committed by Christian Decker
parent be90364f7f
commit f219955dc6
4 changed files with 30 additions and 2 deletions

View file

@ -2132,6 +2132,17 @@ static bool opening_funder_finished(struct subd *opening, const u8 *resp,
&channel_info->remote_fundingkey,
fc->change, &changekey,
fc->peer->ld->wallet->bip32_base);
log_debug(fc->peer->log, "Funding tx has %zi inputs, %zu outputs:",
tal_count(fc->funding_tx->input),
tal_count(fc->funding_tx->output));
for (size_t i = 0; i < tal_count(fc->funding_tx->input); i++) {
log_debug(fc->peer->log, "%zi: %"PRIu64" satoshi (%s) %s\n",
i, fc->utxomap[i]->amount,
fc->utxomap[i]->is_p2sh ? "P2SH" : "SEGWIT",
type_to_string(ltmp, struct sha256_double,
&fc->funding_tx->input[i].txid));
}
fc->peer->funding_txid = tal(fc->peer, struct sha256_double);
bitcoin_txid(fc->funding_tx, fc->peer->funding_txid);

View file

@ -611,6 +611,16 @@ class LightningDTests(BaseLightningDTests):
for n in [l1, l2, l3]:
wait_for(lambda: len(n.rpc.getchannels()['channels']) == 4)
def test_second_channel(self):
l1 = self.node_factory.get_node()
l2 = self.node_factory.get_node()
l3 = self.node_factory.get_node()
l1.rpc.connect('localhost', l2.info['port'], l2.info['id'])
l1.rpc.connect('localhost', l3.info['port'], l3.info['id'])
self.fund_channel(l1, l2, 10**6)
self.fund_channel(l1, l3, 10**6)
def test_routing_gossip(self):
nodes = [self.node_factory.get_node() for _ in range(5)]
l1 = nodes[0]

View file

@ -829,7 +829,13 @@ int wallet_extract_owned_outputs(struct wallet *w, const struct bitcoin_tx *tx,
utxo->status = output_state_available;
bitcoin_txid(tx, &utxo->txid);
utxo->outnum = output;
if (!wallet_add_utxo(w, utxo, p2sh_wpkh)) {
log_debug(w->log, "Owning output %zu %"PRIu64" (%s) txid %s",
output, tx->output[output].amount,
is_p2sh ? "P2SH" : "SEGWIT",
type_to_string(ltmp, struct sha256_double,
&utxo->txid));
if (!wallet_add_utxo(w, utxo, is_p2sh ? p2sh_wpkh : our_change)) {
tal_free(utxo);
return -1;
}

View file

@ -40,7 +40,8 @@ enum wallet_output_type {
p2sh_wpkh = 0,
to_local = 1,
htlc_offer = 3,
htlc_recv = 4
htlc_recv = 4,
our_change = 5
};
/* A database backed shachain struct. The datastructure is