@@ -4654,7 +4654,7 @@ where
4654
4654
for htlc in sources. drain ( ..) {
4655
4655
if let Err ( ( pk, err) ) = self . claim_funds_from_hop (
4656
4656
htlc. prev_hop , payment_preimage,
4657
- |_| Some ( MonitorUpdateCompletionAction :: PaymentClaimed { payment_hash } ) , false )
4657
+ |_| Some ( MonitorUpdateCompletionAction :: PaymentClaimed { payment_hash } ) )
4658
4658
{
4659
4659
if let msgs:: ErrorAction :: IgnoreError = err. err . action {
4660
4660
// We got a temporary failure updating monitor, but will claim the
@@ -4684,10 +4684,15 @@ where
4684
4684
}
4685
4685
4686
4686
fn claim_funds_from_hop < ComplFunc : FnOnce ( Option < u64 > ) -> Option < MonitorUpdateCompletionAction > > ( & self ,
4687
- prev_hop : HTLCPreviousHopData , payment_preimage : PaymentPreimage , completion_action : ComplFunc , during_init : bool )
4687
+ prev_hop : HTLCPreviousHopData , payment_preimage : PaymentPreimage , completion_action : ComplFunc )
4688
4688
-> Result < ( ) , ( PublicKey , MsgHandleErrInternal ) > {
4689
4689
//TODO: Delay the claimed_funds relaying just like we do outbound relay!
4690
4690
4691
+ // If we haven't yet run background events assume we're still deserializing and shouldn't
4692
+ // actually pass `ChannelMonitorUpdate`s to users yet. Instead, queue them up as
4693
+ // `BackgroundEvent`s.
4694
+ let during_init = !self . background_events_processed_since_startup . load ( Ordering :: Acquire ) ;
4695
+
4691
4696
{
4692
4697
let per_peer_state = self . per_peer_state . read ( ) . unwrap ( ) ;
4693
4698
let chan_id = prev_hop. outpoint . to_channel_id ( ) ;
@@ -4788,10 +4793,11 @@ where
4788
4793
self . pending_outbound_payments . finalize_claims ( sources, & self . pending_events ) ;
4789
4794
}
4790
4795
4791
- fn claim_funds_internal ( & self , source : HTLCSource , payment_preimage : PaymentPreimage , forwarded_htlc_value_msat : Option < u64 > , from_onchain : bool , next_channel_id : [ u8 ; 32 ] , during_init : bool ) {
4796
+ fn claim_funds_internal ( & self , source : HTLCSource , payment_preimage : PaymentPreimage , forwarded_htlc_value_msat : Option < u64 > , from_onchain : bool , next_channel_id : [ u8 ; 32 ] ) {
4792
4797
match source {
4793
4798
HTLCSource :: OutboundRoute { session_priv, payment_id, path, .. } => {
4794
- debug_assert ! ( !during_init) ;
4799
+ debug_assert ! ( self . background_events_processed_since_startup. load( Ordering :: Acquire ) ,
4800
+ "We don't support claim_htlc claims during startup - monitors may not be available yet" ) ;
4795
4801
self . pending_outbound_payments . claim_htlc ( payment_id, payment_preimage, session_priv, path, from_onchain, & self . pending_events , & self . logger ) ;
4796
4802
} ,
4797
4803
HTLCSource :: PreviousHopData ( hop_data) => {
@@ -4814,7 +4820,7 @@ where
4814
4820
downstream_counterparty_and_funding_outpoint : None ,
4815
4821
} )
4816
4822
} else { None }
4817
- } , during_init ) ;
4823
+ } ) ;
4818
4824
if let Err ( ( pk, err) ) = res {
4819
4825
let result: Result < ( ) , _ > = Err ( err) ;
4820
4826
let _ = handle_error ! ( self , result, pk) ;
@@ -5562,7 +5568,7 @@ where
5562
5568
hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( format ! ( "Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}" , counterparty_node_id) , msg. channel_id ) )
5563
5569
}
5564
5570
} ;
5565
- self . claim_funds_internal ( htlc_source, msg. payment_preimage . clone ( ) , Some ( forwarded_htlc_value) , false , msg. channel_id , false ) ;
5571
+ self . claim_funds_internal ( htlc_source, msg. payment_preimage . clone ( ) , Some ( forwarded_htlc_value) , false , msg. channel_id ) ;
5566
5572
Ok ( ( ) )
5567
5573
}
5568
5574
@@ -5932,7 +5938,7 @@ where
5932
5938
MonitorEvent :: HTLCEvent ( htlc_update) => {
5933
5939
if let Some ( preimage) = htlc_update. payment_preimage {
5934
5940
log_trace ! ( self . logger, "Claiming HTLC with preimage {} from our monitor" , log_bytes!( preimage. 0 ) ) ;
5935
- self . claim_funds_internal ( htlc_update. source , preimage, htlc_update. htlc_value_satoshis . map ( |v| v * 1000 ) , true , funding_outpoint. to_channel_id ( ) , false ) ;
5941
+ self . claim_funds_internal ( htlc_update. source , preimage, htlc_update. htlc_value_satoshis . map ( |v| v * 1000 ) , true , funding_outpoint. to_channel_id ( ) ) ;
5936
5942
} else {
5937
5943
log_trace ! ( self . logger, "Failing HTLC with hash {} from our monitor" , log_bytes!( htlc_update. payment_hash. 0 ) ) ;
5938
5944
let receiver = HTLCDestination :: NextHopChannel { node_id : counterparty_node_id, channel_id : funding_outpoint. to_channel_id ( ) } ;
@@ -8906,7 +8912,7 @@ where
8906
8912
// don't remember in the `ChannelMonitor` where we got a preimage from, but if the
8907
8913
// channel is closed we just assume that it probably came from an on-chain claim.
8908
8914
channel_manager. claim_funds_internal ( source, preimage, Some ( downstream_value) ,
8909
- downstream_closed, downstream_chan_id, true ) ;
8915
+ downstream_closed, downstream_chan_id) ;
8910
8916
}
8911
8917
8912
8918
//TODO: Broadcast channel update for closed channels, but only after we've made a
0 commit comments