onchaind: fix all_irrevocably_resolved test.

I was examining a test_onchain_timeout failure, and realized that we
were forgetting a peer even though we'd just spent the HTLC_TIMEOUT_TX!

This reveals that we weren't resolving an output when we stole the preimage
from it, like we should.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2018-01-04 13:40:37 +10:30 committed by Christian Decker
parent 05a3db886b
commit 824f8517ac
2 changed files with 22 additions and 4 deletions

View File

@ -496,7 +496,7 @@ static bool all_irrevocably_resolved(struct tracked_output **outs)
size_t i;
for (i = 0; i < tal_count(outs); i++) {
if (outs[i]->resolved && outs[i]->resolved->depth < 100)
if (!outs[i]->resolved || outs[i]->resolved->depth < 100)
return false;
}
return true;
@ -721,6 +721,17 @@ static void output_spent(struct tracked_output ***outs,
handle_htlc_onchain_fulfill(out, tx);
if (out->tx_type == THEIR_REVOKED_UNILATERAL)
steal_htlc_tx(out);
else {
/* BOLT #5:
*
* If the HTLC output is spent using the
* payment preimage, the HTLC output is
* considered *irrevocably resolved*, and the
* node MUST extract the payment preimage from
* the transaction input witness.
*/
ignore_output(out);
}
break;
case FUNDING_OUTPUT:

View File

@ -960,12 +960,19 @@ class LightningDTests(BaseLightningDTests):
l1.daemon.wait_for_log('WIRE_PERMANENT_CHANNEL_FAILURE: timed out')
# 91 later, l2 is done.
bitcoind.generate_block(91)
# 2 later, l1 spends HTLC (5 blocks total).
bitcoind.generate_block(2)
l1.daemon.wait_for_log('Broadcasting OUR_DELAYED_RETURN_TO_WALLET .* to resolve OUR_HTLC_TIMEOUT_TX/DELAYED_OUTPUT_TO_US')
l1.daemon.wait_for_log('sendrawtx exit 0')
# 89 later, l2 is done.
bitcoind.generate_block(89)
l2.daemon.wait_for_log('onchaind complete, forgetting peer')
# Now, 100 blocks and l1 should be done.
bitcoind.generate_block(6)
bitcoind.generate_block(10)
assert not l1.daemon.is_in_log('onchaind complete, forgetting peer')
bitcoind.generate_block(1)
l1.daemon.wait_for_log('onchaind complete, forgetting peer')
# Payment failed, BTW