@@ -2067,31 +2067,56 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2067
2067
claimable_outpoints. append ( & mut new_outpoints) ;
2068
2068
}
2069
2069
2070
+ // Find which on-chain events have reached their confirmation threshold.
2070
2071
let onchain_events_waiting_threshold_conf =
2071
2072
self . onchain_events_waiting_threshold_conf . drain ( ..) . collect :: < Vec < _ > > ( ) ;
2073
+ let mut onchain_events_reaching_threshold_conf = Vec :: new ( ) ;
2072
2074
for entry in onchain_events_waiting_threshold_conf {
2073
2075
if entry. has_reached_confirmation_threshold ( height) {
2074
- match entry. event {
2075
- OnchainEvent :: HTLCUpdate { htlc_update } => {
2076
- log_trace ! ( logger, "HTLC {} failure update has got enough confirmations to be passed upstream" , log_bytes!( ( htlc_update. 1 ) . 0 ) ) ;
2077
- self . pending_monitor_events . push ( MonitorEvent :: HTLCEvent ( HTLCUpdate {
2078
- payment_hash : htlc_update. 1 ,
2079
- payment_preimage : None ,
2080
- source : htlc_update. 0 ,
2081
- } ) ) ;
2082
- } ,
2083
- OnchainEvent :: MaturingOutput { descriptor } => {
2084
- log_trace ! ( logger, "Descriptor {} has got enough confirmations to be passed upstream" , log_spendable!( descriptor) ) ;
2085
- self . pending_events . push ( Event :: SpendableOutputs {
2086
- outputs : vec ! [ descriptor]
2087
- } ) ;
2088
- }
2089
- }
2076
+ onchain_events_reaching_threshold_conf. push ( entry) ;
2090
2077
} else {
2091
2078
self . onchain_events_waiting_threshold_conf . push ( entry) ;
2092
2079
}
2093
2080
}
2094
2081
2082
+ // Used to check for duplicate HTLC resolutions.
2083
+ #[ cfg( debug_assertions) ]
2084
+ let unconfirmed_htlcs: Vec < _ > = self . onchain_events_waiting_threshold_conf
2085
+ . iter ( )
2086
+ . filter_map ( |entry| match & entry. event {
2087
+ OnchainEvent :: HTLCUpdate { htlc_update } => Some ( htlc_update. 0 . clone ( ) ) ,
2088
+ OnchainEvent :: MaturingOutput { .. } => None ,
2089
+ } )
2090
+ . collect ( ) ;
2091
+ #[ cfg( debug_assertions) ]
2092
+ let mut confirmed_htlcs = Vec :: new ( ) ;
2093
+
2094
+ // Produce actionable events from on-chain events having reached their threshold.
2095
+ for entry in onchain_events_reaching_threshold_conf. drain ( ..) {
2096
+ match entry. event {
2097
+ OnchainEvent :: HTLCUpdate { htlc_update } => {
2098
+ // Check for duplicate HTLC resolutions.
2099
+ debug_assert ! ( unconfirmed_htlcs. iter( ) . find( |& htlc| htlc == & htlc_update. 0 ) . is_none( ) ) ;
2100
+ debug_assert ! ( confirmed_htlcs. iter( ) . find( |& htlc| htlc == & htlc_update. 0 ) . is_none( ) ) ;
2101
+ #[ cfg( debug_assertions) ]
2102
+ confirmed_htlcs. push ( htlc_update. 0 . clone ( ) ) ;
2103
+
2104
+ log_trace ! ( logger, "HTLC {} failure update has got enough confirmations to be passed upstream" , log_bytes!( ( htlc_update. 1 ) . 0 ) ) ;
2105
+ self . pending_monitor_events . push ( MonitorEvent :: HTLCEvent ( HTLCUpdate {
2106
+ payment_hash : htlc_update. 1 ,
2107
+ payment_preimage : None ,
2108
+ source : htlc_update. 0 ,
2109
+ } ) ) ;
2110
+ } ,
2111
+ OnchainEvent :: MaturingOutput { descriptor } => {
2112
+ log_trace ! ( logger, "Descriptor {} has got enough confirmations to be passed upstream" , log_spendable!( descriptor) ) ;
2113
+ self . pending_events . push ( Event :: SpendableOutputs {
2114
+ outputs : vec ! [ descriptor]
2115
+ } ) ;
2116
+ }
2117
+ }
2118
+ }
2119
+
2095
2120
self . onchain_tx_handler . update_claims_view ( & txn_matched, claimable_outpoints, Some ( height) , & & * broadcaster, & & * fee_estimator, & & * logger) ;
2096
2121
self . last_block_hash = block_hash;
2097
2122
0 commit comments