@@ -55,7 +55,7 @@ use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError};
55
55
use crate::ln::outbound_payment;
56
56
use crate::ln::outbound_payment::{OutboundPayments, PaymentAttempts, PendingOutboundPayment, SendAlongPathArgs};
57
57
use 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};
59
59
use crate::util::config::{UserConfig, ChannelConfig, ChannelConfigUpdate};
60
60
use crate::util::wakers::{Future, Notifier};
61
61
use crate::util::scid_utils::fake_scid;
@@ -643,23 +643,23 @@ impl_writeable_tlv_based_enum!(RAAMonitorUpdateBlockingAction,
643
643
644
644
645
645
/// State we hold per-peer.
646
- pub(super) struct PeerState<Signer: ChannelSigner> {
646
+ pub(super) struct PeerState<SP: Deref> where SP::Target: SignerProvider {
647
647
/// `channel_id` -> `Channel`.
648
648
///
649
649
/// Holds all funded channels where the peer is the counterparty.
650
- pub(super) channel_by_id: HashMap<[u8; 32], Channel<Signer >>,
650
+ pub(super) channel_by_id: HashMap<[u8; 32], Channel<SP >>,
651
651
/// `temporary_channel_id` -> `OutboundV1Channel`.
652
652
///
653
653
/// Holds all outbound V1 channels where the peer is the counterparty. Once an outbound channel has
654
654
/// been assigned a `channel_id`, the entry in this map is removed and one is created in
655
655
/// `channel_by_id`.
656
- pub(super) outbound_v1_channel_by_id: HashMap<[u8; 32], OutboundV1Channel<Signer >>,
656
+ pub(super) outbound_v1_channel_by_id: HashMap<[u8; 32], OutboundV1Channel<SP >>,
657
657
/// `temporary_channel_id` -> `InboundV1Channel`.
658
658
///
659
659
/// Holds all inbound V1 channels where the peer is the counterparty. Once an inbound channel has
660
660
/// been assigned a `channel_id`, the entry in this map is removed and one is created in
661
661
/// `channel_by_id`.
662
- pub(super) inbound_v1_channel_by_id: HashMap<[u8; 32], InboundV1Channel<Signer >>,
662
+ pub(super) inbound_v1_channel_by_id: HashMap<[u8; 32], InboundV1Channel<SP >>,
663
663
/// `temporary_channel_id` -> `InboundChannelRequest`.
664
664
///
665
665
/// When manual channel acceptance is enabled, this holds all unaccepted inbound channels where
@@ -705,7 +705,7 @@ pub(super) struct PeerState<Signer: ChannelSigner> {
705
705
is_connected: bool,
706
706
}
707
707
708
- impl <Signer: ChannelSigner > PeerState<Signer> {
708
+ impl <SP: Deref > PeerState<SP> where SP::Target: SignerProvider {
709
709
/// Indicates that a peer meets the criteria where we're ok to remove it from our storage.
710
710
/// If true is passed for `require_disconnected`, the function will return false if we haven't
711
711
/// disconnected from the node already, ie. `PeerState::is_connected` is set to `true`.
@@ -1130,9 +1130,9 @@ where
1130
1130
///
1131
1131
/// See `ChannelManager` struct-level documentation for lock order requirements.
1132
1132
#[cfg(not(any(test, feature = "_test_utils")))]
1133
- per_peer_state: FairRwLock<HashMap<PublicKey, Mutex<PeerState<<SP::Target as SignerProvider>::Signer >>>>,
1133
+ per_peer_state: FairRwLock<HashMap<PublicKey, Mutex<PeerState<SP >>>>,
1134
1134
#[cfg(any(test, feature = "_test_utils"))]
1135
- pub(super) per_peer_state: FairRwLock<HashMap<PublicKey, Mutex<PeerState<<SP::Target as SignerProvider>::Signer >>>>,
1135
+ pub(super) per_peer_state: FairRwLock<HashMap<PublicKey, Mutex<PeerState<SP >>>>,
1136
1136
1137
1137
/// The set of events which we need to give to the user to handle. In some cases an event may
1138
1138
/// require some further action after the user handles it (currently only blocking a monitor
@@ -1574,11 +1574,13 @@ impl ChannelDetails {
1574
1574
self.short_channel_id.or(self.outbound_scid_alias)
1575
1575
}
1576
1576
1577
- fn from_channel_context<Signer: WriteableEcdsaChannelSigner , F: Deref>(
1578
- context: &ChannelContext<Signer >, best_block_height: u32, latest_features: InitFeatures,
1577
+ fn from_channel_context<SP: Deref , F: Deref>(
1578
+ context: &ChannelContext<SP >, best_block_height: u32, latest_features: InitFeatures,
1579
1579
fee_estimator: &LowerBoundedFeeEstimator<F>
1580
1580
) -> Self
1581
- where F::Target: FeeEstimator
1581
+ where
1582
+ SP::Target: SignerProvider,
1583
+ F::Target: FeeEstimator
1582
1584
{
1583
1585
let balance = context.get_available_balances(fee_estimator);
1584
1586
let (to_remote_reserve_satoshis, to_self_reserve_satoshis) =
@@ -2279,7 +2281,7 @@ where
2279
2281
Ok(temporary_channel_id)
2280
2282
}
2281
2283
2282
- fn list_funded_channels_with_filter<Fn: FnMut(&(&[u8; 32], &Channel<<SP::Target as SignerProvider>::Signer >)) -> bool + Copy>(&self, f: Fn) -> Vec<ChannelDetails> {
2284
+ fn list_funded_channels_with_filter<Fn: FnMut(&(&[u8; 32], &Channel<SP >)) -> bool + Copy>(&self, f: Fn) -> Vec<ChannelDetails> {
2283
2285
// Allocate our best estimate of the number of channels we have in the `res`
2284
2286
// Vec. Sadly the `short_to_chan_info` map doesn't cover channels without
2285
2287
// a scid or a scid alias, and the `id_to_peer` shouldn't be used outside
@@ -2405,7 +2407,7 @@ where
2405
2407
}
2406
2408
2407
2409
/// Helper function that issues the channel close events
2408
- fn issue_channel_close_events(&self, context: &ChannelContext<<SP::Target as SignerProvider>::Signer >, closure_reason: ClosureReason) {
2410
+ fn issue_channel_close_events(&self, context: &ChannelContext<SP >, closure_reason: ClosureReason) {
2409
2411
let mut pending_events_lock = self.pending_events.lock().unwrap();
2410
2412
match context.unbroadcasted_funding() {
2411
2413
Some(transaction) => {
@@ -3095,7 +3097,7 @@ where
3095
3097
///
3096
3098
/// [`channel_update`]: msgs::ChannelUpdate
3097
3099
/// [`internal_closing_signed`]: Self::internal_closing_signed
3098
- fn get_channel_update_for_broadcast(&self, chan: &Channel<<SP::Target as SignerProvider>::Signer >) -> Result<msgs::ChannelUpdate, LightningError> {
3100
+ fn get_channel_update_for_broadcast(&self, chan: &Channel<SP >) -> Result<msgs::ChannelUpdate, LightningError> {
3099
3101
if !chan.context.should_announce() {
3100
3102
return Err(LightningError {
3101
3103
err: "Cannot broadcast a channel_update for a private channel".to_owned(),
@@ -3120,7 +3122,7 @@ where
3120
3122
///
3121
3123
/// [`channel_update`]: msgs::ChannelUpdate
3122
3124
/// [`internal_closing_signed`]: Self::internal_closing_signed
3123
- fn get_channel_update_for_unicast(&self, chan: &Channel<<SP::Target as SignerProvider>::Signer >) -> Result<msgs::ChannelUpdate, LightningError> {
3125
+ fn get_channel_update_for_unicast(&self, chan: &Channel<SP >) -> Result<msgs::ChannelUpdate, LightningError> {
3124
3126
log_trace!(self.logger, "Attempting to generate channel update for channel {}", log_bytes!(chan.context.channel_id()));
3125
3127
let short_channel_id = match chan.context.get_short_channel_id().or(chan.context.latest_inbound_scid_alias()) {
3126
3128
None => return Err(LightningError{err: "Channel not yet established".to_owned(), action: msgs::ErrorAction::IgnoreError}),
@@ -3130,7 +3132,7 @@ where
3130
3132
self.get_channel_update_for_onion(short_channel_id, chan)
3131
3133
}
3132
3134
3133
- fn get_channel_update_for_onion(&self, short_channel_id: u64, chan: &Channel<<SP::Target as SignerProvider>::Signer >) -> Result<msgs::ChannelUpdate, LightningError> {
3135
+ fn get_channel_update_for_onion(&self, short_channel_id: u64, chan: &Channel<SP >) -> Result<msgs::ChannelUpdate, LightningError> {
3134
3136
log_trace!(self.logger, "Generating channel update for channel {}", log_bytes!(chan.context.channel_id()));
3135
3137
let were_node_one = self.our_network_pubkey.serialize()[..] < chan.context.get_counterparty_node_id().serialize()[..];
3136
3138
@@ -3424,7 +3426,7 @@ where
3424
3426
3425
3427
/// Handles the generation of a funding transaction, optionally (for tests) with a function
3426
3428
/// which checks the correctness of the funding transaction given the associated channel.
3427
- fn funding_transaction_generated_intern<FundingOutput: Fn(&OutboundV1Channel<<SP::Target as SignerProvider>::Signer >, &Transaction) -> Result<OutPoint, APIError>>(
3429
+ fn funding_transaction_generated_intern<FundingOutput: Fn(&OutboundV1Channel<SP >, &Transaction) -> Result<OutPoint, APIError>>(
3428
3430
&self, temporary_channel_id: &[u8; 32], counterparty_node_id: &PublicKey, funding_transaction: Transaction, find_funding_output: FundingOutput
3429
3431
) -> Result<(), APIError> {
3430
3432
let per_peer_state = self.per_peer_state.read().unwrap();
@@ -4337,7 +4339,7 @@ where
4337
4339
let _ = self.process_background_events();
4338
4340
}
4339
4341
4340
- fn update_channel_fee(&self, chan_id: &[u8; 32], chan: &mut Channel<<SP::Target as SignerProvider>::Signer >, new_feerate: u32) -> NotifyOption {
4342
+ fn update_channel_fee(&self, chan_id: &[u8; 32], chan: &mut Channel<SP >, new_feerate: u32) -> NotifyOption {
4341
4343
if !chan.context.is_outbound() { return NotifyOption::SkipPersist; }
4342
4344
// If the feerate has decreased by less than half, don't bother
4343
4345
if new_feerate <= chan.context.get_feerate_sat_per_1000_weight() && new_feerate * 2 > chan.context.get_feerate_sat_per_1000_weight() {
@@ -4496,7 +4498,7 @@ where
4496
4498
4497
4499
let process_unfunded_channel_tick = |
4498
4500
chan_id: &[u8; 32],
4499
- chan_context: &mut ChannelContext<<SP::Target as SignerProvider>::Signer >,
4501
+ chan_context: &mut ChannelContext<SP >,
4500
4502
unfunded_chan_context: &mut UnfundedChannelContext,
4501
4503
pending_msg_events: &mut Vec<MessageSendEvent>,
4502
4504
| {
@@ -4686,7 +4688,7 @@ where
4686
4688
///
4687
4689
/// This is for failures on the channel on which the HTLC was *received*, not failures
4688
4690
/// forwarding
4689
- fn get_htlc_inbound_temp_fail_err_and_data(&self, desired_err_code: u16, chan: &Channel<<SP::Target as SignerProvider>::Signer >) -> (u16, Vec<u8>) {
4691
+ fn get_htlc_inbound_temp_fail_err_and_data(&self, desired_err_code: u16, chan: &Channel<SP >) -> (u16, Vec<u8>) {
4690
4692
// We can't be sure what SCID was used when relaying inbound towards us, so we have to
4691
4693
// guess somewhat. If its a public channel, we figure best to just use the real SCID (as
4692
4694
// we're not leaking that we have a channel with the counterparty), otherwise we try to use
@@ -4706,7 +4708,7 @@ where
4706
4708
4707
4709
/// Gets an HTLC onion failure code and error data for an `UPDATE` error, given the error code
4708
4710
/// that we want to return and a channel.
4709
- 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>) {
4711
+ fn get_htlc_temp_fail_err_and_data(&self, desired_err_code: u16, scid: u64, chan: &Channel<SP >) -> (u16, Vec<u8>) {
4710
4712
debug_assert_eq!(desired_err_code & 0x1000, 0x1000);
4711
4713
if let Ok(upd) = self.get_channel_update_for_onion(scid, chan) {
4712
4714
let mut enc = VecWriter(Vec::with_capacity(upd.serialized_length() + 6));
@@ -5150,7 +5152,7 @@ where
5150
5152
/// Handles a channel reentering a functional state, either due to reconnect or a monitor
5151
5153
/// update completion.
5152
5154
fn handle_channel_resumption(&self, pending_msg_events: &mut Vec<MessageSendEvent>,
5153
- channel: &mut Channel<<SP::Target as SignerProvider>::Signer >, raa: Option<msgs::RevokeAndACK>,
5155
+ channel: &mut Channel<SP >, raa: Option<msgs::RevokeAndACK>,
5154
5156
commitment_update: Option<msgs::CommitmentUpdate>, order: RAACommitmentOrder,
5155
5157
pending_forwards: Vec<(PendingHTLCInfo, u64)>, funding_broadcastable: Option<Transaction>,
5156
5158
channel_ready: Option<msgs::ChannelReady>, announcement_sigs: Option<msgs::AnnouncementSignatures>)
@@ -5385,7 +5387,7 @@ where
5385
5387
/// The filter is called for each peer and provided with the number of unfunded, inbound, and
5386
5388
/// non-0-conf channels we have with the peer.
5387
5389
fn peers_without_funded_channels<Filter>(&self, maybe_count_peer: Filter) -> usize
5388
- where Filter: Fn(&PeerState<<SP::Target as SignerProvider>::Signer >) -> bool {
5390
+ where Filter: Fn(&PeerState<SP >) -> bool {
5389
5391
let mut peers_without_funded_channels = 0;
5390
5392
let best_block_height = self.best_block.read().unwrap().height();
5391
5393
{
@@ -5403,7 +5405,7 @@ where
5403
5405
}
5404
5406
5405
5407
fn unfunded_channel_count(
5406
- peer: &PeerState<<SP::Target as SignerProvider>::Signer >, best_block_height: u32
5408
+ peer: &PeerState<SP >, best_block_height: u32
5407
5409
) -> usize {
5408
5410
let mut num_unfunded_channels = 0;
5409
5411
for (_, chan) in peer.channel_by_id.iter() {
@@ -5849,7 +5851,7 @@ where
5849
5851
chan.get().context.config().accept_underpaying_htlcs, next_packet_pk_opt),
5850
5852
Err(e) => PendingHTLCStatus::Fail(e)
5851
5853
};
5852
- let create_pending_htlc_status = |chan: &Channel<<SP::Target as SignerProvider>::Signer >, pending_forward_info: PendingHTLCStatus, error_code: u16| {
5854
+ let create_pending_htlc_status = |chan: &Channel<SP >, pending_forward_info: PendingHTLCStatus, error_code: u16| {
5853
5855
// If the update_add is completely bogus, the call will Err and we will close,
5854
5856
// but if we've sent a shutdown and they haven't acknowledged it yet, we just
5855
5857
// want to reject the new HTLC and fail it backwards instead of forwarding.
@@ -6999,7 +7001,7 @@ where
6999
7001
/// Calls a function which handles an on-chain event (blocks dis/connected, transactions
7000
7002
/// un/confirmed, etc) on each channel, handling any resulting errors or messages generated by
7001
7003
/// the function.
7002
- fn do_chain_event<FN: Fn(&mut Channel<<SP::Target as SignerProvider>::Signer >) -> Result<(Option<msgs::ChannelReady>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>>
7004
+ fn do_chain_event<FN: Fn(&mut Channel<SP >) -> Result<(Option<msgs::ChannelReady>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>>
7003
7005
(&self, height_opt: Option<u32>, f: FN) {
7004
7006
// Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
7005
7007
// during initialization prior to the chain_monitor being fully configured in some cases.
@@ -8503,13 +8505,13 @@ where
8503
8505
8504
8506
let channel_count: u64 = Readable::read(reader)?;
8505
8507
let mut funding_txo_set = HashSet::with_capacity(cmp::min(channel_count as usize, 128));
8506
- 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));
8508
+ let mut peer_channels: HashMap<PublicKey, HashMap<[u8; 32], Channel<SP >>> = HashMap::with_capacity(cmp::min(channel_count as usize, 128));
8507
8509
let mut id_to_peer = HashMap::with_capacity(cmp::min(channel_count as usize, 128));
8508
8510
let mut short_to_chan_info = HashMap::with_capacity(cmp::min(channel_count as usize, 128));
8509
8511
let mut channel_closures = VecDeque::new();
8510
8512
let mut close_background_events = Vec::new();
8511
8513
for _ in 0..channel_count {
8512
- let mut channel: Channel<<SP::Target as SignerProvider>::Signer > = Channel::read(reader, (
8514
+ let mut channel: Channel<SP > = Channel::read(reader, (
8513
8515
&args.entropy_source, &args.signer_provider, best_block_height, &provided_channel_type_features(&args.default_config)
8514
8516
))?;
8515
8517
let funding_txo = channel.context.get_funding_txo().ok_or(DecodeError::InvalidValue)?;
@@ -8654,7 +8656,7 @@ where
8654
8656
};
8655
8657
8656
8658
let peer_count: u64 = Readable::read(reader)?;
8657
- 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 >>)>()));
8659
+ let mut per_peer_state = HashMap::with_capacity(cmp::min(peer_count as usize, MAX_ALLOC_SIZE/mem::size_of::<(PublicKey, Mutex<PeerState<SP >>)>()));
8658
8660
for _ in 0..peer_count {
8659
8661
let peer_pubkey = Readable::read(reader)?;
8660
8662
let peer_chans = peer_channels.remove(&peer_pubkey).unwrap_or(HashMap::new());
0 commit comments