@@ -1874,6 +1874,52 @@ impl<Signer: ChannelSigner> ChannelContext<Signer> {
1874
1874
None
1875
1875
}
1876
1876
}
1877
+
1878
+ /// Gets the latest commitment transaction and any dependent transactions for relay (forcing
1879
+ /// shutdown of this channel - no more calls into this Channel may be made afterwards except
1880
+ /// those explicitly stated to be allowed after shutdown completes, eg some simple getters).
1881
+ /// Also returns the list of payment_hashes for channels which we can safely fail backwards
1882
+ /// immediately (others we will have to allow to time out).
1883
+ pub fn force_shutdown ( & mut self , should_broadcast : bool ) -> ShutdownResult {
1884
+ // Note that we MUST only generate a monitor update that indicates force-closure - we're
1885
+ // called during initialization prior to the chain_monitor in the encompassing ChannelManager
1886
+ // being fully configured in some cases. Thus, its likely any monitor events we generate will
1887
+ // be delayed in being processed! See the docs for `ChannelManagerReadArgs` for more.
1888
+ assert ! ( self . channel_state != ChannelState :: ShutdownComplete as u32 ) ;
1889
+
1890
+ // We go ahead and "free" any holding cell HTLCs or HTLCs we haven't yet committed to and
1891
+ // return them to fail the payment.
1892
+ let mut dropped_outbound_htlcs = Vec :: with_capacity ( self . holding_cell_htlc_updates . len ( ) ) ;
1893
+ let counterparty_node_id = self . get_counterparty_node_id ( ) ;
1894
+ for htlc_update in self . holding_cell_htlc_updates . drain ( ..) {
1895
+ match htlc_update {
1896
+ HTLCUpdateAwaitingACK :: AddHTLC { source, payment_hash, .. } => {
1897
+ dropped_outbound_htlcs. push ( ( source, payment_hash, counterparty_node_id, self . channel_id ) ) ;
1898
+ } ,
1899
+ _ => { }
1900
+ }
1901
+ }
1902
+ let monitor_update = if let Some ( funding_txo) = self . get_funding_txo ( ) {
1903
+ // If we haven't yet exchanged funding signatures (ie channel_state < FundingSent),
1904
+ // returning a channel monitor update here would imply a channel monitor update before
1905
+ // we even registered the channel monitor to begin with, which is invalid.
1906
+ // Thus, if we aren't actually at a point where we could conceivably broadcast the
1907
+ // funding transaction, don't return a funding txo (which prevents providing the
1908
+ // monitor update to the user, even if we return one).
1909
+ // See test_duplicate_chan_id and test_pre_lockin_no_chan_closed_update for more.
1910
+ if self . channel_state & ( ChannelState :: FundingSent as u32 | ChannelState :: ChannelReady as u32 | ChannelState :: ShutdownComplete as u32 ) != 0 {
1911
+ self . latest_monitor_update_id = CLOSED_CHANNEL_UPDATE_ID ;
1912
+ Some ( ( self . get_counterparty_node_id ( ) , funding_txo, ChannelMonitorUpdate {
1913
+ update_id : self . latest_monitor_update_id ,
1914
+ updates : vec ! [ ChannelMonitorUpdateStep :: ChannelForceClosed { should_broadcast } ] ,
1915
+ } ) )
1916
+ } else { None }
1917
+ } else { None } ;
1918
+
1919
+ self . channel_state = ChannelState :: ShutdownComplete as u32 ;
1920
+ self . update_time_counter += 1 ;
1921
+ ( monitor_update, dropped_outbound_htlcs)
1922
+ }
1877
1923
}
1878
1924
1879
1925
// Internal utility functions for channels
@@ -5823,52 +5869,6 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5823
5869
Ok ( ( shutdown, monitor_update, dropped_outbound_htlcs) )
5824
5870
}
5825
5871
5826
- /// Gets the latest commitment transaction and any dependent transactions for relay (forcing
5827
- /// shutdown of this channel - no more calls into this Channel may be made afterwards except
5828
- /// those explicitly stated to be allowed after shutdown completes, eg some simple getters).
5829
- /// Also returns the list of payment_hashes for channels which we can safely fail backwards
5830
- /// immediately (others we will have to allow to time out).
5831
- pub fn force_shutdown ( & mut self , should_broadcast : bool ) -> ShutdownResult {
5832
- // Note that we MUST only generate a monitor update that indicates force-closure - we're
5833
- // called during initialization prior to the chain_monitor in the encompassing ChannelManager
5834
- // being fully configured in some cases. Thus, its likely any monitor events we generate will
5835
- // be delayed in being processed! See the docs for `ChannelManagerReadArgs` for more.
5836
- assert ! ( self . context. channel_state != ChannelState :: ShutdownComplete as u32 ) ;
5837
-
5838
- // We go ahead and "free" any holding cell HTLCs or HTLCs we haven't yet committed to and
5839
- // return them to fail the payment.
5840
- let mut dropped_outbound_htlcs = Vec :: with_capacity ( self . context . holding_cell_htlc_updates . len ( ) ) ;
5841
- let counterparty_node_id = self . context . get_counterparty_node_id ( ) ;
5842
- for htlc_update in self . context . holding_cell_htlc_updates . drain ( ..) {
5843
- match htlc_update {
5844
- HTLCUpdateAwaitingACK :: AddHTLC { source, payment_hash, .. } => {
5845
- dropped_outbound_htlcs. push ( ( source, payment_hash, counterparty_node_id, self . context . channel_id ) ) ;
5846
- } ,
5847
- _ => { }
5848
- }
5849
- }
5850
- let monitor_update = if let Some ( funding_txo) = self . context . get_funding_txo ( ) {
5851
- // If we haven't yet exchanged funding signatures (ie channel_state < FundingSent),
5852
- // returning a channel monitor update here would imply a channel monitor update before
5853
- // we even registered the channel monitor to begin with, which is invalid.
5854
- // Thus, if we aren't actually at a point where we could conceivably broadcast the
5855
- // funding transaction, don't return a funding txo (which prevents providing the
5856
- // monitor update to the user, even if we return one).
5857
- // See test_duplicate_chan_id and test_pre_lockin_no_chan_closed_update for more.
5858
- if self . context . channel_state & ( ChannelState :: FundingSent as u32 | ChannelState :: ChannelReady as u32 | ChannelState :: ShutdownComplete as u32 ) != 0 {
5859
- self . context . latest_monitor_update_id = CLOSED_CHANNEL_UPDATE_ID ;
5860
- Some ( ( self . context . get_counterparty_node_id ( ) , funding_txo, ChannelMonitorUpdate {
5861
- update_id : self . context . latest_monitor_update_id ,
5862
- updates : vec ! [ ChannelMonitorUpdateStep :: ChannelForceClosed { should_broadcast } ] ,
5863
- } ) )
5864
- } else { None }
5865
- } else { None } ;
5866
-
5867
- self . context . channel_state = ChannelState :: ShutdownComplete as u32 ;
5868
- self . context . update_time_counter += 1 ;
5869
- ( monitor_update, dropped_outbound_htlcs)
5870
- }
5871
-
5872
5872
pub fn inflight_htlc_sources ( & self ) -> impl Iterator < Item =( & HTLCSource , & PaymentHash ) > {
5873
5873
self . context . holding_cell_htlc_updates . iter ( )
5874
5874
. flat_map ( |htlc_update| {
0 commit comments