@@ -2961,12 +2961,24 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
2961
2961
}
2962
2962
2963
2963
/// Called by channelmanager based on chain blocks being connected.
2964
- /// Note that we only need to use this to detect funding_signed, anything else is handled by
2965
- /// the channel_monitor.
2964
+ /// We need to use this to detect funding_signed and outgoing HTLC timed out before we were able
2965
+ /// to commit them on remote commitment tx, anything else is handled by the channel_monitor.
2966
2966
/// In case of Err, the channel may have been closed, at which point the standard requirements
2967
2967
/// apply - no calls may be made except those explicitly stated to be allowed post-shutdown.
2968
2968
/// Only returns an ErrorAction of DisconnectPeer, if Err.
2969
- pub fn block_connected ( & mut self , header : & BlockHeader , height : u32 , txn_matched : & [ & Transaction ] , indexes_of_txn_matched : & [ u32 ] ) -> Result < Option < msgs:: FundingLocked > , msgs:: ErrorMessage > {
2969
+ pub fn block_connected ( & mut self , header : & BlockHeader , height : u32 , txn_matched : & [ & Transaction ] , indexes_of_txn_matched : & [ u32 ] ) -> Result < ( Option < msgs:: FundingLocked > , Vec < ( HTLCSource , PaymentHash , u64 ) > ) , msgs:: ErrorMessage > {
2970
+ let mut timed_out_htlcs = Vec :: new ( ) ;
2971
+ self . holding_cell_htlc_updates . retain ( |htlc_update| {
2972
+ match htlc_update {
2973
+ & HTLCUpdateAwaitingACK :: AddHTLC { ref payment_hash, ref source, ref cltv_expiry, ref amount_msat, .. } => {
2974
+ if cltv_expiry <= & height { // XXX follow 0a4821b
2975
+ timed_out_htlcs. push ( ( source. clone ( ) , payment_hash. clone ( ) , * amount_msat) ) ;
2976
+ false
2977
+ } else { true }
2978
+ } ,
2979
+ _ => true
2980
+ }
2981
+ } ) ;
2970
2982
let non_shutdown_state = self . channel_state & ( !MULTI_STATE_FLAGS ) ;
2971
2983
if header. bitcoin_hash ( ) != self . last_block_connected {
2972
2984
self . last_block_connected = header. bitcoin_hash ( ) ;
@@ -3002,13 +3014,13 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
3002
3014
if self . channel_state & ( ChannelState :: MonitorUpdateFailed as u32 ) == 0 {
3003
3015
let next_per_commitment_secret = self . build_local_commitment_secret ( self . cur_local_commitment_transaction_number ) ;
3004
3016
let next_per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & next_per_commitment_secret) ;
3005
- return Ok ( Some ( msgs:: FundingLocked {
3017
+ return Ok ( ( Some ( msgs:: FundingLocked {
3006
3018
channel_id : self . channel_id ,
3007
3019
next_per_commitment_point : next_per_commitment_point,
3008
- } ) ) ;
3020
+ } ) , timed_out_htlcs ) ) ;
3009
3021
} else {
3010
3022
self . monitor_pending_funding_locked = true ;
3011
- return Ok ( None ) ;
3023
+ return Ok ( ( None , timed_out_htlcs ) ) ;
3012
3024
}
3013
3025
}
3014
3026
}
@@ -3054,7 +3066,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
3054
3066
}
3055
3067
}
3056
3068
}
3057
- Ok ( None )
3069
+ Ok ( ( None , timed_out_htlcs ) )
3058
3070
}
3059
3071
3060
3072
/// Called by channelmanager based on chain blocks being disconnected.
0 commit comments