@@ -29,7 +29,7 @@ use bitcoin::hash_types::{Txid, BlockHash};
2929use crate :: chain;
3030use crate :: chain:: { ChannelMonitorUpdateStatus , Filter , WatchedOutput } ;
3131use crate :: chain:: chaininterface:: { BroadcasterInterface , FeeEstimator } ;
32- use crate :: chain:: channelmonitor:: { ChannelMonitor , ChannelMonitorUpdate , Balance , MonitorEvent , TransactionOutputs , WithChannelMonitor , LATENCY_GRACE_PERIOD_BLOCKS } ;
32+ use crate :: chain:: channelmonitor:: { ChannelMonitor , ChannelMonitorUpdate , Balance , MonitorEvent , TransactionOutputs , WithChannelMonitor } ;
3333use crate :: chain:: transaction:: { OutPoint , TransactionData } ;
3434use crate :: ln:: ChannelId ;
3535use crate :: sign:: ecdsa:: WriteableEcdsaChannelSigner ;
@@ -851,21 +851,12 @@ where C::Target: chain::Filter,
851851 fn release_pending_monitor_events ( & self ) -> Vec < ( OutPoint , ChannelId , Vec < MonitorEvent > , Option < PublicKey > ) > {
852852 let mut pending_monitor_events = self . pending_monitor_events . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
853853 for monitor_state in self . monitors . read ( ) . unwrap ( ) . values ( ) {
854- let logger = WithChannelMonitor :: from ( & self . logger , & monitor_state. monitor ) ;
855- let is_pending_monitor_update = monitor_state. has_pending_chainsync_updates ( & monitor_state. pending_monitor_updates . lock ( ) . unwrap ( ) ) ;
856- if !is_pending_monitor_update || monitor_state. last_chain_persist_height . load ( Ordering :: Acquire ) + LATENCY_GRACE_PERIOD_BLOCKS as usize <= self . highest_chain_height . load ( Ordering :: Acquire ) {
857- if is_pending_monitor_update {
858- log_error ! ( logger, "A ChannelMonitor sync took longer than {} blocks to complete." , LATENCY_GRACE_PERIOD_BLOCKS ) ;
859- log_error ! ( logger, " To avoid funds-loss, we are allowing monitor updates to be released." ) ;
860- log_error ! ( logger, " This may cause duplicate payment events to be generated." ) ;
861- }
862- let monitor_events = monitor_state. monitor . get_and_clear_pending_monitor_events ( ) ;
863- if monitor_events. len ( ) > 0 {
864- let monitor_outpoint = monitor_state. monitor . get_funding_txo ( ) . 0 ;
865- let monitor_channel_id = monitor_state. monitor . channel_id ( ) ;
866- let counterparty_node_id = monitor_state. monitor . get_counterparty_node_id ( ) ;
867- pending_monitor_events. push ( ( monitor_outpoint, monitor_channel_id, monitor_events, counterparty_node_id) ) ;
868- }
854+ let monitor_events = monitor_state. monitor . get_and_clear_pending_monitor_events ( ) ;
855+ if monitor_events. len ( ) > 0 {
856+ let monitor_outpoint = monitor_state. monitor . get_funding_txo ( ) . 0 ;
857+ let monitor_channel_id = monitor_state. monitor . channel_id ( ) ;
858+ let counterparty_node_id = monitor_state. monitor . get_counterparty_node_id ( ) ;
859+ pending_monitor_events. push ( ( monitor_outpoint, monitor_channel_id, monitor_events, counterparty_node_id) ) ;
869860 }
870861 }
871862 pending_monitor_events
@@ -902,15 +893,12 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L
902893#[ cfg( test) ]
903894mod tests {
904895 use crate :: check_added_monitors;
905- use crate :: { expect_payment_claimed, expect_payment_path_successful, get_event_msg} ;
906- use crate :: { get_htlc_update_msgs, get_local_commitment_txn, get_revoke_commit_msgs, get_route_and_payment_hash, unwrap_send_err} ;
907- use crate :: chain:: { ChannelMonitorUpdateStatus , Confirm , Watch } ;
908- use crate :: chain:: channelmonitor:: LATENCY_GRACE_PERIOD_BLOCKS ;
896+ use crate :: { expect_payment_path_successful, get_event_msg} ;
897+ use crate :: { get_htlc_update_msgs, get_revoke_commit_msgs} ;
898+ use crate :: chain:: { ChannelMonitorUpdateStatus , Watch } ;
909899 use crate :: events:: { Event , MessageSendEvent , MessageSendEventsProvider } ;
910- use crate :: ln:: channelmanager:: { PaymentSendFailure , PaymentId , RecipientOnionFields } ;
911900 use crate :: ln:: functional_test_utils:: * ;
912901 use crate :: ln:: msgs:: ChannelMessageHandler ;
913- use crate :: util:: errors:: APIError ;
914902
915903 #[ test]
916904 fn test_async_ooo_offchain_updates ( ) {
@@ -1017,76 +1005,6 @@ mod tests {
10171005 check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
10181006 }
10191007
1020- fn do_chainsync_pauses_events ( block_timeout : bool ) {
1021- // When a chainsync monitor update occurs, any MonitorUpdates should be held before being
1022- // passed upstream to a `ChannelManager` via `Watch::release_pending_monitor_events`. This
1023- // tests that behavior, as well as some ways it might go wrong.
1024- let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
1025- let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
1026- let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
1027- let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1028- let channel = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
1029-
1030- // Get a route for later and rebalance the channel somewhat
1031- send_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 10_000_000 ) ;
1032- let ( route, second_payment_hash, _, second_payment_secret) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 1 ] , 100_000 ) ;
1033-
1034- // First route a payment that we will claim on chain and give the recipient the preimage.
1035- let ( payment_preimage, payment_hash, ..) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 1_000_000 ) ;
1036- nodes[ 1 ] . node . claim_funds ( payment_preimage) ;
1037- expect_payment_claimed ! ( nodes[ 1 ] , payment_hash, 1_000_000 ) ;
1038- nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
1039- check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
1040- let remote_txn = get_local_commitment_txn ! ( nodes[ 1 ] , channel. 2 ) ;
1041- assert_eq ! ( remote_txn. len( ) , 2 ) ;
1042-
1043- // Temp-fail the block connection which will hold the channel-closed event
1044- chanmon_cfgs[ 0 ] . persister . chain_sync_monitor_persistences . lock ( ) . unwrap ( ) . clear ( ) ;
1045- chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: InProgress ) ;
1046-
1047- // Connect B's commitment transaction, but only to the ChainMonitor/ChannelMonitor. The
1048- // channel is now closed, but the ChannelManager doesn't know that yet.
1049- let new_header = create_dummy_header ( nodes[ 0 ] . best_block_info ( ) . 0 , 0 ) ;
1050- nodes[ 0 ] . chain_monitor . chain_monitor . transactions_confirmed ( & new_header,
1051- & [ ( 0 , & remote_txn[ 0 ] ) , ( 1 , & remote_txn[ 1 ] ) ] , nodes[ 0 ] . best_block_info ( ) . 1 + 1 ) ;
1052- assert ! ( nodes[ 0 ] . chain_monitor. release_pending_monitor_events( ) . is_empty( ) ) ;
1053- nodes[ 0 ] . chain_monitor . chain_monitor . best_block_updated ( & new_header, nodes[ 0 ] . best_block_info ( ) . 1 + 1 ) ;
1054- assert ! ( nodes[ 0 ] . chain_monitor. release_pending_monitor_events( ) . is_empty( ) ) ;
1055-
1056- // If the ChannelManager tries to update the channel, however, the ChainMonitor will pass
1057- // the update through to the ChannelMonitor which will refuse it (as the channel is closed).
1058- chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
1059- unwrap_send_err ! ( nodes[ 0 ] . node. send_payment_with_route( & route, second_payment_hash,
1060- RecipientOnionFields :: secret_only( second_payment_secret) , PaymentId ( second_payment_hash. 0 )
1061- ) , false , APIError :: MonitorUpdateInProgress , { } ) ;
1062- check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
1063-
1064- // However, as the ChainMonitor is still waiting for the original persistence to complete,
1065- // it won't yet release the MonitorEvents.
1066- assert ! ( nodes[ 0 ] . chain_monitor. release_pending_monitor_events( ) . is_empty( ) ) ;
1067-
1068- if block_timeout {
1069- // After three blocks, pending MontiorEvents should be released either way.
1070- let latest_header = create_dummy_header ( nodes[ 0 ] . best_block_info ( ) . 0 , 0 ) ;
1071- nodes[ 0 ] . chain_monitor . chain_monitor . best_block_updated ( & latest_header, nodes[ 0 ] . best_block_info ( ) . 1 + LATENCY_GRACE_PERIOD_BLOCKS ) ;
1072- } else {
1073- let persistences = chanmon_cfgs[ 0 ] . persister . chain_sync_monitor_persistences . lock ( ) . unwrap ( ) . clone ( ) ;
1074- for ( funding_outpoint, update_ids) in persistences {
1075- for update_id in update_ids {
1076- nodes[ 0 ] . chain_monitor . chain_monitor . channel_monitor_updated ( funding_outpoint, update_id) . unwrap ( ) ;
1077- }
1078- }
1079- }
1080-
1081- expect_payment_sent ( & nodes[ 0 ] , payment_preimage, None , true , false ) ;
1082- }
1083-
1084- #[ test]
1085- fn chainsync_pauses_events ( ) {
1086- do_chainsync_pauses_events ( false ) ;
1087- do_chainsync_pauses_events ( true ) ;
1088- }
1089-
10901008 #[ test]
10911009 #[ cfg( feature = "std" ) ]
10921010 fn update_during_chainsync_poisons_channel ( ) {
@@ -1109,3 +1027,4 @@ mod tests {
11091027 } ) . is_err( ) ) ;
11101028 }
11111029}
1030+
0 commit comments