@@ -55,7 +55,7 @@ use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError};
5555use crate::ln::outbound_payment;
5656use crate::ln::outbound_payment::{OutboundPayments, PaymentAttempts, PendingOutboundPayment, SendAlongPathArgs};
5757use crate::ln::wire::Encode;
58- use crate::sign::{EntropySource, KeysManager, NodeSigner, Recipient, SignerProvider, ChannelSigner,  WriteableEcdsaChannelSigner};
58+ use crate::sign::{EntropySource, KeysManager, NodeSigner, Recipient, SignerProvider, WriteableEcdsaChannelSigner};
5959use crate::util::config::{UserConfig, ChannelConfig, ChannelConfigUpdate};
6060use crate::util::wakers::{Future, Notifier};
6161use crate::util::scid_utils::fake_scid;
@@ -659,23 +659,23 @@ impl_writeable_tlv_based_enum!(RAAMonitorUpdateBlockingAction,
659659
660660
661661/// State we hold per-peer.
662- pub(super) struct PeerState<Signer: ChannelSigner>  {
662+ pub(super) struct PeerState<SP: Deref> where SP::Target: SignerProvider  {
663663	/// `channel_id` -> `Channel`.
664664	///
665665	/// Holds all funded channels where the peer is the counterparty.
666- 	pub(super) channel_by_id: HashMap<[u8; 32], Channel<Signer >>,
666+ 	pub(super) channel_by_id: HashMap<[u8; 32], Channel<SP >>,
667667	/// `temporary_channel_id` -> `OutboundV1Channel`.
668668	///
669669	/// Holds all outbound V1 channels where the peer is the counterparty. Once an outbound channel has
670670	/// been assigned a `channel_id`, the entry in this map is removed and one is created in
671671	/// `channel_by_id`.
672- 	pub(super) outbound_v1_channel_by_id: HashMap<[u8; 32], OutboundV1Channel<Signer >>,
672+ 	pub(super) outbound_v1_channel_by_id: HashMap<[u8; 32], OutboundV1Channel<SP >>,
673673	/// `temporary_channel_id` -> `InboundV1Channel`.
674674	///
675675	/// Holds all inbound V1 channels where the peer is the counterparty. Once an inbound channel has
676676	/// been assigned a `channel_id`, the entry in this map is removed and one is created in
677677	/// `channel_by_id`.
678- 	pub(super) inbound_v1_channel_by_id: HashMap<[u8; 32], InboundV1Channel<Signer >>,
678+ 	pub(super) inbound_v1_channel_by_id: HashMap<[u8; 32], InboundV1Channel<SP >>,
679679	/// `temporary_channel_id` -> `InboundChannelRequest`.
680680	///
681681	/// When manual channel acceptance is enabled, this holds all unaccepted inbound channels where
@@ -721,7 +721,7 @@ pub(super) struct PeerState<Signer: ChannelSigner> {
721721	is_connected: bool,
722722}
723723
724- impl <Signer: ChannelSigner > PeerState<Signer>  {
724+ impl <SP: Deref > PeerState<SP> where SP::Target: SignerProvider  {
725725	/// Indicates that a peer meets the criteria where we're ok to remove it from our storage.
726726	/// If true is passed for `require_disconnected`, the function will return false if we haven't
727727	/// disconnected from the node already, ie. `PeerState::is_connected` is set to `true`.
@@ -1146,9 +1146,9 @@ where
11461146	///
11471147	/// See `ChannelManager` struct-level documentation for lock order requirements.
11481148	#[cfg(not(any(test, feature = "_test_utils")))]
1149- 	per_peer_state: FairRwLock<HashMap<PublicKey, Mutex<PeerState<<SP::Target as SignerProvider>::Signer >>>>,
1149+ 	per_peer_state: FairRwLock<HashMap<PublicKey, Mutex<PeerState<SP >>>>,
11501150	#[cfg(any(test, feature = "_test_utils"))]
1151- 	pub(super) per_peer_state: FairRwLock<HashMap<PublicKey, Mutex<PeerState<<SP::Target as SignerProvider>::Signer >>>>,
1151+ 	pub(super) per_peer_state: FairRwLock<HashMap<PublicKey, Mutex<PeerState<SP >>>>,
11521152
11531153	/// The set of events which we need to give to the user to handle. In some cases an event may
11541154	/// require some further action after the user handles it (currently only blocking a monitor
@@ -1594,11 +1594,13 @@ impl ChannelDetails {
15941594		self.short_channel_id.or(self.outbound_scid_alias)
15951595	}
15961596
1597- 	fn from_channel_context<Signer: WriteableEcdsaChannelSigner , F: Deref>(
1598- 		context: &ChannelContext<Signer >, best_block_height: u32, latest_features: InitFeatures,
1597+ 	fn from_channel_context<SP: Deref , F: Deref>(
1598+ 		context: &ChannelContext<SP >, best_block_height: u32, latest_features: InitFeatures,
15991599		fee_estimator: &LowerBoundedFeeEstimator<F>
16001600	) -> Self
1601- 	where F::Target: FeeEstimator
1601+ 	where
1602+ 		SP::Target: SignerProvider,
1603+ 		F::Target: FeeEstimator
16021604	{
16031605		let balance = context.get_available_balances(fee_estimator);
16041606		let (to_remote_reserve_satoshis, to_self_reserve_satoshis) =
@@ -2299,7 +2301,7 @@ where
22992301		Ok(temporary_channel_id)
23002302	}
23012303
2302- 	fn list_funded_channels_with_filter<Fn: FnMut(&(&[u8; 32], &Channel<<SP::Target as SignerProvider>::Signer >)) -> bool + Copy>(&self, f: Fn) -> Vec<ChannelDetails> {
2304+ 	fn list_funded_channels_with_filter<Fn: FnMut(&(&[u8; 32], &Channel<SP >)) -> bool + Copy>(&self, f: Fn) -> Vec<ChannelDetails> {
23032305		// Allocate our best estimate of the number of channels we have in the `res`
23042306		// Vec. Sadly the `short_to_chan_info` map doesn't cover channels without
23052307		// a scid or a scid alias, and the `id_to_peer` shouldn't be used outside
@@ -2425,7 +2427,7 @@ where
24252427	}
24262428
24272429	/// Helper function that issues the channel close events
2428- 	fn issue_channel_close_events(&self, context: &ChannelContext<<SP::Target as SignerProvider>::Signer >, closure_reason: ClosureReason) {
2430+ 	fn issue_channel_close_events(&self, context: &ChannelContext<SP >, closure_reason: ClosureReason) {
24292431		let mut pending_events_lock = self.pending_events.lock().unwrap();
24302432		match context.unbroadcasted_funding() {
24312433			Some(transaction) => {
@@ -3115,7 +3117,7 @@ where
31153117	///
31163118	/// [`channel_update`]: msgs::ChannelUpdate
31173119	/// [`internal_closing_signed`]: Self::internal_closing_signed
3118- 	fn get_channel_update_for_broadcast(&self, chan: &Channel<<SP::Target as SignerProvider>::Signer >) -> Result<msgs::ChannelUpdate, LightningError> {
3120+ 	fn get_channel_update_for_broadcast(&self, chan: &Channel<SP >) -> Result<msgs::ChannelUpdate, LightningError> {
31193121		if !chan.context.should_announce() {
31203122			return Err(LightningError {
31213123				err: "Cannot broadcast a channel_update for a private channel".to_owned(),
@@ -3140,7 +3142,7 @@ where
31403142	///
31413143	/// [`channel_update`]: msgs::ChannelUpdate
31423144	/// [`internal_closing_signed`]: Self::internal_closing_signed
3143- 	fn get_channel_update_for_unicast(&self, chan: &Channel<<SP::Target as SignerProvider>::Signer >) -> Result<msgs::ChannelUpdate, LightningError> {
3145+ 	fn get_channel_update_for_unicast(&self, chan: &Channel<SP >) -> Result<msgs::ChannelUpdate, LightningError> {
31443146		log_trace!(self.logger, "Attempting to generate channel update for channel {}", log_bytes!(chan.context.channel_id()));
31453147		let short_channel_id = match chan.context.get_short_channel_id().or(chan.context.latest_inbound_scid_alias()) {
31463148			None => return Err(LightningError{err: "Channel not yet established".to_owned(), action: msgs::ErrorAction::IgnoreError}),
@@ -3150,7 +3152,7 @@ where
31503152		self.get_channel_update_for_onion(short_channel_id, chan)
31513153	}
31523154
3153- 	fn get_channel_update_for_onion(&self, short_channel_id: u64, chan: &Channel<<SP::Target as SignerProvider>::Signer >) -> Result<msgs::ChannelUpdate, LightningError> {
3155+ 	fn get_channel_update_for_onion(&self, short_channel_id: u64, chan: &Channel<SP >) -> Result<msgs::ChannelUpdate, LightningError> {
31543156		log_trace!(self.logger, "Generating channel update for channel {}", log_bytes!(chan.context.channel_id()));
31553157		let were_node_one = self.our_network_pubkey.serialize()[..] < chan.context.get_counterparty_node_id().serialize()[..];
31563158
@@ -3444,7 +3446,7 @@ where
34443446
34453447	/// Handles the generation of a funding transaction, optionally (for tests) with a function
34463448	/// which checks the correctness of the funding transaction given the associated channel.
3447- 	fn funding_transaction_generated_intern<FundingOutput: Fn(&OutboundV1Channel<<SP::Target as SignerProvider>::Signer >, &Transaction) -> Result<OutPoint, APIError>>(
3449+ 	fn funding_transaction_generated_intern<FundingOutput: Fn(&OutboundV1Channel<SP >, &Transaction) -> Result<OutPoint, APIError>>(
34483450		&self, temporary_channel_id: &[u8; 32], counterparty_node_id: &PublicKey, funding_transaction: Transaction, find_funding_output: FundingOutput
34493451	) -> Result<(), APIError> {
34503452		let per_peer_state = self.per_peer_state.read().unwrap();
@@ -4362,7 +4364,7 @@ where
43624364		let _ = self.process_background_events();
43634365	}
43644366
4365- 	fn update_channel_fee(&self, chan_id: &[u8; 32], chan: &mut Channel<<SP::Target as SignerProvider>::Signer >, new_feerate: u32) -> NotifyOption {
4367+ 	fn update_channel_fee(&self, chan_id: &[u8; 32], chan: &mut Channel<SP >, new_feerate: u32) -> NotifyOption {
43664368		if !chan.context.is_outbound() { return NotifyOption::SkipPersist; }
43674369		// If the feerate has decreased by less than half, don't bother
43684370		if new_feerate <= chan.context.get_feerate_sat_per_1000_weight() && new_feerate * 2 > chan.context.get_feerate_sat_per_1000_weight() {
@@ -4521,7 +4523,7 @@ where
45214523
45224524					let process_unfunded_channel_tick = |
45234525						chan_id: &[u8; 32],
4524- 						chan_context: &mut ChannelContext<<SP::Target as SignerProvider>::Signer >,
4526+ 						chan_context: &mut ChannelContext<SP >,
45254527						unfunded_chan_context: &mut UnfundedChannelContext,
45264528						pending_msg_events: &mut Vec<MessageSendEvent>,
45274529					| {
@@ -4711,7 +4713,7 @@ where
47114713	///
47124714	/// This is for failures on the channel on which the HTLC was *received*, not failures
47134715	/// forwarding
4714- 	fn get_htlc_inbound_temp_fail_err_and_data(&self, desired_err_code: u16, chan: &Channel<<SP::Target as SignerProvider>::Signer >) -> (u16, Vec<u8>) {
4716+ 	fn get_htlc_inbound_temp_fail_err_and_data(&self, desired_err_code: u16, chan: &Channel<SP >) -> (u16, Vec<u8>) {
47154717		// We can't be sure what SCID was used when relaying inbound towards us, so we have to
47164718		// guess somewhat. If its a public channel, we figure best to just use the real SCID (as
47174719		// we're not leaking that we have a channel with the counterparty), otherwise we try to use
@@ -4731,7 +4733,7 @@ where
47314733
47324734	/// Gets an HTLC onion failure code and error data for an `UPDATE` error, given the error code
47334735	/// that we want to return and a channel.
4734- 	fn get_htlc_temp_fail_err_and_data(&self, desired_err_code: u16, scid: u64, chan: &Channel<<SP::Target as SignerProvider>::Signer >) -> (u16, Vec<u8>) {
4736+ 	fn get_htlc_temp_fail_err_and_data(&self, desired_err_code: u16, scid: u64, chan: &Channel<SP >) -> (u16, Vec<u8>) {
47354737		debug_assert_eq!(desired_err_code & 0x1000, 0x1000);
47364738		if let Ok(upd) = self.get_channel_update_for_onion(scid, chan) {
47374739			let mut enc = VecWriter(Vec::with_capacity(upd.serialized_length() + 6));
@@ -5194,7 +5196,7 @@ where
51945196	/// Handles a channel reentering a functional state, either due to reconnect or a monitor
51955197	/// update completion.
51965198	fn handle_channel_resumption(&self, pending_msg_events: &mut Vec<MessageSendEvent>,
5197- 		channel: &mut Channel<<SP::Target as SignerProvider>::Signer >, raa: Option<msgs::RevokeAndACK>,
5199+ 		channel: &mut Channel<SP >, raa: Option<msgs::RevokeAndACK>,
51985200		commitment_update: Option<msgs::CommitmentUpdate>, order: RAACommitmentOrder,
51995201		pending_forwards: Vec<(PendingHTLCInfo, u64)>, funding_broadcastable: Option<Transaction>,
52005202		channel_ready: Option<msgs::ChannelReady>, announcement_sigs: Option<msgs::AnnouncementSignatures>)
@@ -5429,7 +5431,7 @@ where
54295431	/// The filter is called for each peer and provided with the number of unfunded, inbound, and
54305432	/// non-0-conf channels we have with the peer.
54315433	fn peers_without_funded_channels<Filter>(&self, maybe_count_peer: Filter) -> usize
5432- 	where Filter: Fn(&PeerState<<SP::Target as SignerProvider>::Signer >) -> bool {
5434+ 	where Filter: Fn(&PeerState<SP >) -> bool {
54335435		let mut peers_without_funded_channels = 0;
54345436		let best_block_height = self.best_block.read().unwrap().height();
54355437		{
@@ -5447,7 +5449,7 @@ where
54475449	}
54485450
54495451	fn unfunded_channel_count(
5450- 		peer: &PeerState<<SP::Target as SignerProvider>::Signer >, best_block_height: u32
5452+ 		peer: &PeerState<SP >, best_block_height: u32
54515453	) -> usize {
54525454		let mut num_unfunded_channels = 0;
54535455		for (_, chan) in peer.channel_by_id.iter() {
@@ -5893,7 +5895,7 @@ where
58935895							chan.get().context.config().accept_underpaying_htlcs, next_packet_pk_opt),
58945896					Err(e) => PendingHTLCStatus::Fail(e)
58955897				};
5896- 				let create_pending_htlc_status = |chan: &Channel<<SP::Target as SignerProvider>::Signer >, pending_forward_info: PendingHTLCStatus, error_code: u16| {
5898+ 				let create_pending_htlc_status = |chan: &Channel<SP >, pending_forward_info: PendingHTLCStatus, error_code: u16| {
58975899					// If the update_add is completely bogus, the call will Err and we will close,
58985900					// but if we've sent a shutdown and they haven't acknowledged it yet, we just
58995901					// want to reject the new HTLC and fail it backwards instead of forwarding.
@@ -7055,7 +7057,7 @@ where
70557057	/// Calls a function which handles an on-chain event (blocks dis/connected, transactions
70567058	/// un/confirmed, etc) on each channel, handling any resulting errors or messages generated by
70577059	/// the function.
7058- 	fn do_chain_event<FN: Fn(&mut Channel<<SP::Target as SignerProvider>::Signer >) -> Result<(Option<msgs::ChannelReady>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>>
7060+ 	fn do_chain_event<FN: Fn(&mut Channel<SP >) -> Result<(Option<msgs::ChannelReady>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>>
70597061			(&self, height_opt: Option<u32>, f: FN) {
70607062		// Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
70617063		// during initialization prior to the chain_monitor being fully configured in some cases.
@@ -8601,13 +8603,13 @@ where
86018603
86028604		let channel_count: u64 = Readable::read(reader)?;
86038605		let mut funding_txo_set = HashSet::with_capacity(cmp::min(channel_count as usize, 128));
8604- 		let mut peer_channels: HashMap<PublicKey, HashMap<[u8; 32], Channel<<SP::Target as SignerProvider>::Signer >>> = HashMap::with_capacity(cmp::min(channel_count as usize, 128));
8606+ 		let mut peer_channels: HashMap<PublicKey, HashMap<[u8; 32], Channel<SP >>> = HashMap::with_capacity(cmp::min(channel_count as usize, 128));
86058607		let mut id_to_peer = HashMap::with_capacity(cmp::min(channel_count as usize, 128));
86068608		let mut short_to_chan_info = HashMap::with_capacity(cmp::min(channel_count as usize, 128));
86078609		let mut channel_closures = VecDeque::new();
86088610		let mut close_background_events = Vec::new();
86098611		for _ in 0..channel_count {
8610- 			let mut channel: Channel<<SP::Target as SignerProvider>::Signer > = Channel::read(reader, (
8612+ 			let mut channel: Channel<SP > = Channel::read(reader, (
86118613				&args.entropy_source, &args.signer_provider, best_block_height, &provided_channel_type_features(&args.default_config)
86128614			))?;
86138615			let funding_txo = channel.context.get_funding_txo().ok_or(DecodeError::InvalidValue)?;
@@ -8752,7 +8754,7 @@ where
87528754		};
87538755
87548756		let peer_count: u64 = Readable::read(reader)?;
8755- 		let mut per_peer_state = HashMap::with_capacity(cmp::min(peer_count as usize, MAX_ALLOC_SIZE/mem::size_of::<(PublicKey, Mutex<PeerState<<SP::Target as SignerProvider>::Signer >>)>()));
8757+ 		let mut per_peer_state = HashMap::with_capacity(cmp::min(peer_count as usize, MAX_ALLOC_SIZE/mem::size_of::<(PublicKey, Mutex<PeerState<SP >>)>()));
87568758		for _ in 0..peer_count {
87578759			let peer_pubkey = Readable::read(reader)?;
87588760			let peer_chans = peer_channels.remove(&peer_pubkey).unwrap_or(HashMap::new());
@@ -10574,13 +10576,13 @@ pub mod bench {
1057410576		&'a test_utils::TestFeeEstimator, &'a test_utils::TestRouter<'a>,
1057510577		&'a test_utils::TestLogger>;
1057610578
10577- 	struct ANodeHolder<'a , P: Persist<InMemorySigner>> {
10578- 		node: &'a  Manager<'a , P>,
10579+ 	struct ANodeHolder<'node_cfg, 'chan_mon_cfg: 'node_cfg , P: Persist<InMemorySigner>> {
10580+ 		node: &'node_cfg  Manager<'chan_mon_cfg , P>,
1057910581	}
10580- 	impl<'a,  P: Persist<InMemorySigner>> NodeHolder for ANodeHolder<'a , P> {
10581- 		type CM = Manager<'a , P>;
10582+ 	impl<'node_cfg, 'chan_mon_cfg: 'node_cfg,  P: Persist<InMemorySigner>> NodeHolder for ANodeHolder<'node_cfg, 'chan_mon_cfg , P> {
10583+ 		type CM = Manager<'chan_mon_cfg , P>;
1058210584		#[inline]
10583- 		fn node(&self) -> &Manager<'a , P> { self.node }
10585+ 		fn node(&self) -> &Manager<'chan_mon_cfg , P> { self.node }
1058410586		#[inline]
1058510587		fn chain_monitor(&self) -> Option<&test_utils::TestChainMonitor> { None }
1058610588	}
0 commit comments