@@ -1648,14 +1648,32 @@ impl ChannelMonitor {
1648
1648
/// Attempts to claim any claimable HTLCs in a commitment transaction which was not (yet)
1649
1649
/// revoked using data in local_claimable_outpoints.
1650
1650
/// Should not be used if check_spend_revoked_transaction succeeds.
1651
- fn check_spend_local_transaction ( & self , tx : & Transaction , _height : u32 ) -> ( Vec < Transaction > , Vec < SpendableOutputDescriptor > , ( Sha256dHash , Vec < TxOut > ) ) {
1651
+ fn check_spend_local_transaction ( & mut self , tx : & Transaction , height : u32 ) -> ( Vec < Transaction > , Vec < SpendableOutputDescriptor > , ( Sha256dHash , Vec < TxOut > ) ) {
1652
1652
let commitment_txid = tx. txid ( ) ;
1653
- // TODO: If we find a match here we need to fail back HTLCs that weren't included in the
1654
- // broadcast commitment transaction, either because they didn't meet dust or because they
1655
- // weren't yet included in our commitment transaction(s).
1653
+
1654
+ macro_rules! wait_threshold_conf {
1655
+ ( $height: expr, $update: expr) => {
1656
+ match self . htlc_updated_waiting_threshold_conf. entry( $height + HTLC_FAIL_ANTI_REORG_DELAY - 1 ) {
1657
+ hash_map:: Entry :: Occupied ( mut entry) => {
1658
+ entry. get_mut( ) . push( $update) ;
1659
+ }
1660
+ hash_map:: Entry :: Vacant ( entry) => {
1661
+ entry. insert( vec![ ( $update) ] ) ;
1662
+ }
1663
+ }
1664
+ }
1665
+ }
1666
+
1656
1667
if let & Some ( ref local_tx) = & self . current_local_signed_commitment_tx {
1657
1668
if local_tx. txid == commitment_txid {
1658
1669
log_trace ! ( self , "Got latest local commitment tx broadcast, searching for available HTLCs to claim" ) ;
1670
+ for ( ref htlc, _, ref source) in & local_tx. htlc_outputs {
1671
+ if htlc. transaction_output_index . is_none ( ) {
1672
+ if let Some ( source) = source {
1673
+ wait_threshold_conf ! ( height, ( source. clone( ) , None , htlc. payment_hash. clone( ) ) ) ;
1674
+ }
1675
+ }
1676
+ }
1659
1677
match self . key_storage {
1660
1678
Storage :: Local { ref delayed_payment_base_key, ref latest_per_commitment_point, .. } => {
1661
1679
let ( local_txn, spendable_outputs, watch_outputs) = self . broadcast_by_local_state ( local_tx, latest_per_commitment_point, & Some ( * delayed_payment_base_key) ) ;
@@ -1671,6 +1689,13 @@ impl ChannelMonitor {
1671
1689
if let & Some ( ref local_tx) = & self . prev_local_signed_commitment_tx {
1672
1690
if local_tx. txid == commitment_txid {
1673
1691
log_trace ! ( self , "Got previous local commitment tx broadcast, searching for available HTLCs to claim" ) ;
1692
+ for ( ref htlc, _, ref source) in & local_tx. htlc_outputs {
1693
+ if htlc. transaction_output_index . is_none ( ) {
1694
+ if let Some ( source) = source {
1695
+ wait_threshold_conf ! ( height, ( source. clone( ) , None , htlc. payment_hash. clone( ) ) ) ;
1696
+ }
1697
+ }
1698
+ }
1674
1699
match self . key_storage {
1675
1700
Storage :: Local { ref delayed_payment_base_key, ref prev_latest_per_commitment_point, .. } => {
1676
1701
let ( local_txn, spendable_outputs, watch_outputs) = self . broadcast_by_local_state ( local_tx, prev_latest_per_commitment_point, & Some ( * delayed_payment_base_key) ) ;
0 commit comments