Create SpendableOutputs events no matter the chain::Confirm order
authorMatt Corallo <git@bluematt.me>
Fri, 25 Jun 2021 04:16:35 +0000 (04:16 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 2 Jul 2021 17:16:12 +0000 (17:16 +0000)
commit496eb4526bd64e7d41d0b238b834923ca00c8ff6
treedb1d8f4e7c6dffcd802515f4226d2ee585373f09
parent599c74cd427592c318f90bf0cc91ad88dc14bc06
Create SpendableOutputs events no matter the chain::Confirm order

We had a user who pointed out that we weren't creating
`SpendableOutputs` events when we should have been after they
called `ChannelMonitor::best_block_updated` with a block well
after a CSV locktime and then called
`ChannelMonitor::transactions_confirmed` with the transaction which
we should have been spending (with a block height/hash a ways in
the past).

This was due to `ChannelMonitor::transactions_confirmed` only
calling `ChannelMonitor::block_confirmed` with the height at which
the transactions were confirmed, resulting in all checks being done
against that, not the current height.

Further, in the same scenario, we also would not fail-back and HTLC
where the HTLC-Timeout transaction was confirmed more than
ANTI_REORG_DELAY blocks ago.

To address this, we use the best block height for confirmation
threshold checks in `ChannelMonitor::block_confirmed` and pass both
the confirmation and current heights through to
`OnchainTx::update_claims_view`, using each as appropriate.

Fixes #962.
lightning/src/chain/channelmonitor.rs
lightning/src/chain/onchaintx.rs
lightning/src/ln/functional_test_utils.rs
lightning/src/ln/functional_tests.rs