@@ -618,6 +618,61 @@ pub type SimpleArcChannelManager<M, T, F, L> = ChannelManager<
618618/// This is not exported to bindings users as Arcs don't make sense in bindings 
619619pub  type  SimpleRefChannelManager < ' a ,  ' b ,  ' c ,  ' d ,  ' e ,  ' f ,  ' g ,  ' h ,  M ,  T ,  F ,  L >  = ChannelManager < & ' a  M ,  & ' b  T ,  & ' c  KeysManager ,  & ' c  KeysManager ,  & ' c  KeysManager ,  & ' d  F ,  & ' e  DefaultRouter < & ' f  NetworkGraph < & ' g  L > ,  & ' g  L ,  & ' h  Mutex < ProbabilisticScorer < & ' f  NetworkGraph < & ' g  L > ,  & ' g  L > > > ,  & ' g  L > ; 
620620
621+ /// A trivial trait which describes any [`ChannelManager`] used in testing. 
622+ #[ cfg( any( test,  feature = "_test_utils" ) ) ]  
623+ pub  trait  AChannelManager  { 
624+ 	type  Watch :  chain:: Watch < Self :: Signer > ; 
625+ 	type  M :  Deref < Target  = Self :: Watch > ; 
626+ 	type  Broadcaster :  BroadcasterInterface ; 
627+ 	type  T :  Deref < Target  = Self :: Broadcaster > ; 
628+ 	type  EntropySource :  EntropySource ; 
629+ 	type  ES :  Deref < Target  = Self :: EntropySource > ; 
630+ 	type  NodeSigner :  NodeSigner ; 
631+ 	type  NS :  Deref < Target  = Self :: NodeSigner > ; 
632+ 	type  Signer :  WriteableEcdsaChannelSigner ; 
633+ 	type  SignerProvider :  SignerProvider < Signer  = Self :: Signer > ; 
634+ 	type  SP :  Deref < Target  = Self :: SignerProvider > ; 
635+ 	type  FeeEstimator :  FeeEstimator ; 
636+ 	type  F :  Deref < Target  = Self :: FeeEstimator > ; 
637+ 	type  Router :  Router ; 
638+ 	type  R :  Deref < Target  = Self :: Router > ; 
639+ 	type  Logger :  Logger ; 
640+ 	type  L :  Deref < Target  = Self :: Logger > ; 
641+ 	fn  get_cm ( & self )  -> & ChannelManager < Self :: M ,  Self :: T ,  Self :: ES ,  Self :: NS ,  Self :: SP ,  Self :: F ,  Self :: R ,  Self :: L > ; 
642+ } 
643+ #[ cfg( any( test,  feature = "_test_utils" ) ) ]  
644+ impl < M :  Deref ,  T :  Deref ,  ES :  Deref ,  NS :  Deref ,  SP :  Deref ,  F :  Deref ,  R :  Deref ,  L :  Deref >  AChannelManager 
645+ for  ChannelManager < M ,  T ,  ES ,  NS ,  SP ,  F ,  R ,  L > 
646+ where 
647+ 	M :: Target :  chain:: Watch < <SP :: Target  as  SignerProvider >:: Signer >  + Sized , 
648+ 	T :: Target :  BroadcasterInterface  + Sized , 
649+ 	ES :: Target :  EntropySource  + Sized , 
650+ 	NS :: Target :  NodeSigner  + Sized , 
651+ 	SP :: Target :  SignerProvider  + Sized , 
652+ 	F :: Target :  FeeEstimator  + Sized , 
653+ 	R :: Target :  Router  + Sized , 
654+ 	L :: Target :  Logger  + Sized , 
655+ { 
656+ 	type  Watch  = M :: Target ; 
657+ 	type  M  = M ; 
658+ 	type  Broadcaster  = T :: Target ; 
659+ 	type  T  = T ; 
660+ 	type  EntropySource  = ES :: Target ; 
661+ 	type  ES  = ES ; 
662+ 	type  NodeSigner  = NS :: Target ; 
663+ 	type  NS  = NS ; 
664+ 	type  Signer  = <SP :: Target  as  SignerProvider >:: Signer ; 
665+ 	type  SignerProvider  = SP :: Target ; 
666+ 	type  SP  = SP ; 
667+ 	type  FeeEstimator  = F :: Target ; 
668+ 	type  F  = F ; 
669+ 	type  Router  = R :: Target ; 
670+ 	type  R  = R ; 
671+ 	type  Logger  = L :: Target ; 
672+ 	type  L  = L ; 
673+ 	fn  get_cm ( & self )  -> & ChannelManager < M ,  T ,  ES ,  NS ,  SP ,  F ,  R ,  L >  {  self  } 
674+ } 
675+ 
621676/// Manager which keeps track of a number of channels and sends messages to the appropriate 
622677/// channel, also tracking HTLC preimages and forwarding onion packets appropriately. 
623678/// 
@@ -1623,6 +1678,36 @@ macro_rules! handle_new_monitor_update {
16231678	} 
16241679} 
16251680
1681+ macro_rules!  process_events_body { 
1682+ 	( $self:  expr,  $event_to_handle:  expr,  $handle_event:  expr)  => { 
1683+ 		// We'll acquire our total consistency lock until the returned future completes so that 
1684+ 		// we can be sure no other persists happen while processing events. 
1685+ 		let  _read_guard = $self. total_consistency_lock. read( ) . unwrap( ) ; 
1686+ 
1687+ 		let  mut  result = NotifyOption :: SkipPersist ; 
1688+ 
1689+ 		// TODO: This behavior should be documented. It's unintuitive that we query 
1690+ 		// ChannelMonitors when clearing other events. 
1691+ 		if  $self. process_pending_monitor_events( )  { 
1692+ 			result = NotifyOption :: DoPersist ; 
1693+ 		} 
1694+ 
1695+ 		let  pending_events = mem:: replace( & mut  * $self. pending_events. lock( ) . unwrap( ) ,  vec![ ] ) ; 
1696+ 		if  !pending_events. is_empty( )  { 
1697+ 			result = NotifyOption :: DoPersist ; 
1698+ 		} 
1699+ 
1700+ 		for  event in pending_events { 
1701+ 			$event_to_handle = event; 
1702+ 			$handle_event; 
1703+ 		} 
1704+ 
1705+ 		if  result == NotifyOption :: DoPersist  { 
1706+ 			$self. persistence_notifier. notify( ) ; 
1707+ 		} 
1708+ 	} 
1709+ } 
1710+ 
16261711impl < M :  Deref ,  T :  Deref ,  ES :  Deref ,  NS :  Deref ,  SP :  Deref ,  F :  Deref ,  R :  Deref ,  L :  Deref >  ChannelManager < M ,  T ,  ES ,  NS ,  SP ,  F ,  R ,  L > 
16271712where 
16281713	M :: Target :  chain:: Watch < <SP :: Target  as  SignerProvider >:: Signer > , 
@@ -5720,30 +5805,8 @@ where
57205805 	pub  async  fn  process_pending_events_async < Future :  core:: future:: Future ,  H :  Fn ( Event )  -> Future > ( 
57215806		& self ,  handler :  H 
57225807	)  { 
5723- 		// We'll acquire our total consistency lock until the returned future completes so that 
5724- 		// we can be sure no other persists happen while processing events. 
5725- 		let  _read_guard = self . total_consistency_lock . read ( ) . unwrap ( ) ; 
5726- 
5727- 		let  mut  result = NotifyOption :: SkipPersist ; 
5728- 
5729- 		// TODO: This behavior should be documented. It's unintuitive that we query 
5730- 		// ChannelMonitors when clearing other events. 
5731- 		if  self . process_pending_monitor_events ( )  { 
5732- 			result = NotifyOption :: DoPersist ; 
5733- 		} 
5734- 
5735- 		let  pending_events = mem:: replace ( & mut  * self . pending_events . lock ( ) . unwrap ( ) ,  vec ! [ ] ) ; 
5736- 		if  !pending_events. is_empty ( )  { 
5737- 			result = NotifyOption :: DoPersist ; 
5738- 		} 
5739- 
5740- 		for  event in  pending_events { 
5741- 			handler ( event) . await ; 
5742- 		} 
5743- 
5744- 		if  result == NotifyOption :: DoPersist  { 
5745- 			self . persistence_notifier . notify ( ) ; 
5746- 		} 
5808+ 		let  mut  ev; 
5809+ 		process_events_body ! ( self ,  ev,  {  handler( ev) . await  } ) ; 
57475810	} 
57485811} 
57495812
@@ -5825,26 +5888,8 @@ where
58255888 	/// An [`EventHandler`] may safely call back to the provider in order to handle an event. 
58265889 	/// However, it must not call [`Writeable::write`] as doing so would result in a deadlock. 
58275890 	fn  process_pending_events < H :  Deref > ( & self ,  handler :  H )  where  H :: Target :  EventHandler  { 
5828- 		PersistenceNotifierGuard :: optionally_notify ( & self . total_consistency_lock ,  & self . persistence_notifier ,  || { 
5829- 			let  mut  result = NotifyOption :: SkipPersist ; 
5830- 
5831- 			// TODO: This behavior should be documented. It's unintuitive that we query 
5832- 			// ChannelMonitors when clearing other events. 
5833- 			if  self . process_pending_monitor_events ( )  { 
5834- 				result = NotifyOption :: DoPersist ; 
5835- 			} 
5836- 
5837- 			let  pending_events = mem:: replace ( & mut  * self . pending_events . lock ( ) . unwrap ( ) ,  vec ! [ ] ) ; 
5838- 			if  !pending_events. is_empty ( )  { 
5839- 				result = NotifyOption :: DoPersist ; 
5840- 			} 
5841- 
5842- 			for  event in  pending_events { 
5843- 				handler. handle_event ( event) ; 
5844- 			} 
5845- 
5846- 			result
5847- 		} ) ; 
5891+ 		let  mut  ev; 
5892+ 		process_events_body ! ( self ,  ev,  handler. handle_event( ev) ) ; 
58485893	} 
58495894} 
58505895
@@ -8849,14 +8894,23 @@ pub mod bench {
88498894
88508895	use  test:: Bencher ; 
88518896
8852- 	struct  NodeHolder < ' a ,  P :  Persist < InMemorySigner > >  { 
8853- 		node :  & ' a  ChannelManager < 
8854- 			& ' a  ChainMonitor < InMemorySigner ,  & ' a  test_utils:: TestChainSource , 
8855- 				& ' a  test_utils:: TestBroadcaster ,  & ' a  test_utils:: TestFeeEstimator , 
8856- 				& ' a  test_utils:: TestLogger ,  & ' a  P > , 
8857- 			& ' a  test_utils:: TestBroadcaster ,  & ' a  KeysManager ,  & ' a  KeysManager ,  & ' a  KeysManager , 
8858- 			& ' a  test_utils:: TestFeeEstimator ,  & ' a  test_utils:: TestRouter < ' a > , 
8859- 			& ' a  test_utils:: TestLogger > , 
8897+ 	type  Manager < ' a ,  P >  = ChannelManager < 
8898+ 		& ' a  ChainMonitor < InMemorySigner ,  & ' a  test_utils:: TestChainSource , 
8899+ 			& ' a  test_utils:: TestBroadcaster ,  & ' a  test_utils:: TestFeeEstimator , 
8900+ 			& ' a  test_utils:: TestLogger ,  & ' a  P > , 
8901+ 		& ' a  test_utils:: TestBroadcaster ,  & ' a  KeysManager ,  & ' a  KeysManager ,  & ' a  KeysManager , 
8902+ 		& ' a  test_utils:: TestFeeEstimator ,  & ' a  test_utils:: TestRouter < ' a > , 
8903+ 		& ' a  test_utils:: TestLogger > ; 
8904+ 
8905+ 	struct  ANodeHolder < ' a ,  P :  Persist < InMemorySigner > >  { 
8906+ 		node :  & ' a  Manager < ' a ,  P > , 
8907+ 	} 
8908+ 	impl < ' a ,  P :  Persist < InMemorySigner > >  NodeHolder  for  ANodeHolder < ' a ,  P >  { 
8909+ 		type  CM  = Manager < ' a ,  P > ; 
8910+ 		#[ inline]  
8911+ 		fn  node ( & self )  -> & Manager < ' a ,  P >  {  self . node  } 
8912+ 		#[ inline]  
8913+ 		fn  chain_monitor ( & self )  -> Option < & test_utils:: TestChainMonitor >  {  None  } 
88608914	} 
88618915
88628916	#[ cfg( test) ]  
@@ -8887,7 +8941,7 @@ pub mod bench {
88878941			network, 
88888942			best_block :  BestBlock :: from_network ( network) , 
88898943		} ) ; 
8890- 		let  node_a_holder = NodeHolder  {  node :  & node_a } ; 
8944+ 		let  node_a_holder = ANodeHolder  {  node :  & node_a } ; 
88918945
88928946		let  logger_b = test_utils:: TestLogger :: with_id ( "node a" . to_owned ( ) ) ; 
88938947		let  chain_monitor_b = ChainMonitor :: new ( None ,  & tx_broadcaster,  & logger_a,  & fee_estimator,  & persister_b) ; 
@@ -8897,7 +8951,7 @@ pub mod bench {
88978951			network, 
88988952			best_block :  BestBlock :: from_network ( network) , 
88998953		} ) ; 
8900- 		let  node_b_holder = NodeHolder  {  node :  & node_b } ; 
8954+ 		let  node_b_holder = ANodeHolder  {  node :  & node_b } ; 
89018955
89028956		node_a. peer_connected ( & node_b. get_our_node_id ( ) ,  & Init  {  features :  node_b. init_features ( ) ,  remote_network_address :  None  } ,  true ) . unwrap ( ) ; 
89038957		node_b. peer_connected ( & node_a. get_our_node_id ( ) ,  & Init  {  features :  node_a. init_features ( ) ,  remote_network_address :  None  } ,  false ) . unwrap ( ) ; 
@@ -8993,15 +9047,15 @@ pub mod bench {
89939047				let  payment_event = SendEvent :: from_event( $node_a. get_and_clear_pending_msg_events( ) . pop( ) . unwrap( ) ) ; 
89949048				$node_b. handle_update_add_htlc( & $node_a. get_our_node_id( ) ,  & payment_event. msgs[ 0 ] ) ; 
89959049				$node_b. handle_commitment_signed( & $node_a. get_our_node_id( ) ,  & payment_event. commitment_msg) ; 
8996- 				let  ( raa,  cs)  = do_get_revoke_commit_msgs! ( NodeHolder  {  node:  & $node_b } ,  & $node_a. get_our_node_id( ) ) ; 
9050+ 				let  ( raa,  cs)  = get_revoke_commit_msgs ( & ANodeHolder  {  node:  & $node_b } ,  & $node_a. get_our_node_id( ) ) ; 
89979051				$node_a. handle_revoke_and_ack( & $node_b. get_our_node_id( ) ,  & raa) ; 
89989052				$node_a. handle_commitment_signed( & $node_b. get_our_node_id( ) ,  & cs) ; 
8999- 				$node_b. handle_revoke_and_ack( & $node_a. get_our_node_id( ) ,  & get_event_msg!( NodeHolder  {  node:  & $node_a } ,  MessageSendEvent :: SendRevokeAndACK ,  $node_b. get_our_node_id( ) ) ) ; 
9053+ 				$node_b. handle_revoke_and_ack( & $node_a. get_our_node_id( ) ,  & get_event_msg!( ANodeHolder  {  node:  & $node_a } ,  MessageSendEvent :: SendRevokeAndACK ,  $node_b. get_our_node_id( ) ) ) ; 
90009054
9001- 				expect_pending_htlcs_forwardable!( NodeHolder  {  node:  & $node_b } ) ; 
9002- 				expect_payment_claimable!( NodeHolder  {  node:  & $node_b } ,  payment_hash,  payment_secret,  10_000 ) ; 
9055+ 				expect_pending_htlcs_forwardable!( ANodeHolder  {  node:  & $node_b } ) ; 
9056+ 				expect_payment_claimable!( ANodeHolder  {  node:  & $node_b } ,  payment_hash,  payment_secret,  10_000 ) ; 
90039057				$node_b. claim_funds( payment_preimage) ; 
9004- 				expect_payment_claimed!( NodeHolder  {  node:  & $node_b } ,  payment_hash,  10_000 ) ; 
9058+ 				expect_payment_claimed!( ANodeHolder  {  node:  & $node_b } ,  payment_hash,  10_000 ) ; 
90059059
90069060				match  $node_b. get_and_clear_pending_msg_events( ) . pop( ) . unwrap( )  { 
90079061					MessageSendEvent :: UpdateHTLCs  {  node_id,  updates }  => { 
@@ -9012,12 +9066,12 @@ pub mod bench {
90129066					_ => panic!( "Failed to generate claim event" ) , 
90139067				} 
90149068
9015- 				let  ( raa,  cs)  = do_get_revoke_commit_msgs! ( NodeHolder  {  node:  & $node_a } ,  & $node_b. get_our_node_id( ) ) ; 
9069+ 				let  ( raa,  cs)  = get_revoke_commit_msgs ( & ANodeHolder  {  node:  & $node_a } ,  & $node_b. get_our_node_id( ) ) ; 
90169070				$node_b. handle_revoke_and_ack( & $node_a. get_our_node_id( ) ,  & raa) ; 
90179071				$node_b. handle_commitment_signed( & $node_a. get_our_node_id( ) ,  & cs) ; 
9018- 				$node_a. handle_revoke_and_ack( & $node_b. get_our_node_id( ) ,  & get_event_msg!( NodeHolder  {  node:  & $node_b } ,  MessageSendEvent :: SendRevokeAndACK ,  $node_a. get_our_node_id( ) ) ) ; 
9072+ 				$node_a. handle_revoke_and_ack( & $node_b. get_our_node_id( ) ,  & get_event_msg!( ANodeHolder  {  node:  & $node_b } ,  MessageSendEvent :: SendRevokeAndACK ,  $node_a. get_our_node_id( ) ) ) ; 
90199073
9020- 				expect_payment_sent!( NodeHolder  {  node:  & $node_a } ,  payment_preimage) ; 
9074+ 				expect_payment_sent!( ANodeHolder  {  node:  & $node_a } ,  payment_preimage) ; 
90219075			} 
90229076		} 
90239077
0 commit comments