diff --git a/onchaind/onchain.c b/onchaind/onchain.c index 7ca33711d..36ffd81ab 100644 --- a/onchaind/onchain.c +++ b/onchaind/onchain.c @@ -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: diff --git a/tests/test_lightningd.py b/tests/test_lightningd.py index a420b4385..231333fe1 100644 --- a/tests/test_lightningd.py +++ b/tests/test_lightningd.py @@ -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