@@ -2756,12 +2756,24 @@ impl Channel {
2756
2756
}
2757
2757
2758
2758
/// Called by channelmanager based on chain blocks being connected.
2759
- /// Note that we only need to use this to detect funding_signed, anything else is handled by
2760
- /// the channel_monitor.
2759
+ /// We need to use this to detect funding_signed and outgoing HTLC timed out before we were able
2760
+ /// to commit them on remote commitment tx, anything else is handled by the channel_monitor.
2761
2761
/// In case of Err, the channel may have been closed, at which point the standard requirements
2762
2762
/// apply - no calls may be made except those explicitly stated to be allowed post-shutdown.
2763
2763
/// Only returns an ErrorAction of DisconnectPeer, if Err.
2764
- pub fn block_connected ( & mut self , header : & BlockHeader , height : u32 , txn_matched : & [ & Transaction ] , indexes_of_txn_matched : & [ u32 ] ) -> Result < Option < msgs:: FundingLocked > , HandleError > {
2764
+ pub fn block_connected ( & mut self , header : & BlockHeader , height : u32 , txn_matched : & [ & Transaction ] , indexes_of_txn_matched : & [ u32 ] ) -> Result < ( Option < msgs:: FundingLocked > , Vec < ( HTLCSource , [ u8 ; 32 ] ) > ) , HandleError > {
2765
+ let mut timed_out_htlcs = Vec :: new ( ) ;
2766
+ self . holding_cell_htlc_updates . retain ( |htlc_update| {
2767
+ match htlc_update {
2768
+ & HTLCUpdateAwaitingACK :: AddHTLC { ref payment_hash, ref source, ref cltv_expiry, .. } => {
2769
+ if cltv_expiry <= & height { // XXX follow 0a4821b
2770
+ timed_out_htlcs. push ( ( source. clone ( ) , payment_hash. clone ( ) ) ) ;
2771
+ false
2772
+ } else { true }
2773
+ } ,
2774
+ _ => true
2775
+ }
2776
+ } ) ;
2765
2777
let non_shutdown_state = self . channel_state & ( !MULTI_STATE_FLAGS ) ;
2766
2778
if header. bitcoin_hash ( ) != self . last_block_connected {
2767
2779
self . last_block_connected = header. bitcoin_hash ( ) ;
@@ -2796,10 +2808,10 @@ impl Channel {
2796
2808
if need_commitment_update {
2797
2809
let next_per_commitment_secret = self . build_local_commitment_secret ( self . cur_local_commitment_transaction_number ) ;
2798
2810
let next_per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & next_per_commitment_secret) ;
2799
- return Ok ( Some ( msgs:: FundingLocked {
2811
+ return Ok ( ( Some ( msgs:: FundingLocked {
2800
2812
channel_id : self . channel_id ,
2801
2813
next_per_commitment_point : next_per_commitment_point,
2802
- } ) ) ;
2814
+ } ) , timed_out_htlcs ) ) ;
2803
2815
}
2804
2816
}
2805
2817
}
@@ -2831,7 +2843,7 @@ impl Channel {
2831
2843
}
2832
2844
}
2833
2845
}
2834
- Ok ( None )
2846
+ Ok ( ( None , timed_out_htlcs ) )
2835
2847
}
2836
2848
2837
2849
/// Called by channelmanager based on chain blocks being disconnected.
0 commit comments