@@ -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;
@@ -659,23 +659,23 @@ impl_writeable_tlv_based_enum!(RAAMonitorUpdateBlockingAction,
659
659
660
660
661
661
/// State we hold per-peer.
662
- pub(super) struct PeerState<Signer: ChannelSigner> {
662
+ pub(super) struct PeerState<SP: Deref> where SP::Target: SignerProvider {
663
663
/// `channel_id` -> `Channel`.
664
664
///
665
665
/// 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 >>,
667
667
/// `temporary_channel_id` -> `OutboundV1Channel`.
668
668
///
669
669
/// Holds all outbound V1 channels where the peer is the counterparty. Once an outbound channel has
670
670
/// been assigned a `channel_id`, the entry in this map is removed and one is created in
671
671
/// `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 >>,
673
673
/// `temporary_channel_id` -> `InboundV1Channel`.
674
674
///
675
675
/// Holds all inbound V1 channels where the peer is the counterparty. Once an inbound channel has
676
676
/// been assigned a `channel_id`, the entry in this map is removed and one is created in
677
677
/// `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 >>,
679
679
/// `temporary_channel_id` -> `InboundChannelRequest`.
680
680
///
681
681
/// When manual channel acceptance is enabled, this holds all unaccepted inbound channels where
@@ -721,7 +721,7 @@ pub(super) struct PeerState<Signer: ChannelSigner> {
721
721
is_connected: bool,
722
722
}
723
723
724
- impl <Signer: ChannelSigner > PeerState<Signer> {
724
+ impl <SP: Deref > PeerState<SP> where SP::Target: SignerProvider {
725
725
/// Indicates that a peer meets the criteria where we're ok to remove it from our storage.
726
726
/// If true is passed for `require_disconnected`, the function will return false if we haven't
727
727
/// disconnected from the node already, ie. `PeerState::is_connected` is set to `true`.
@@ -1146,9 +1146,9 @@ where
1146
1146
///
1147
1147
/// See `ChannelManager` struct-level documentation for lock order requirements.
1148
1148
#[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 >>>>,
1150
1150
#[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 >>>>,
1152
1152
1153
1153
/// The set of events which we need to give to the user to handle. In some cases an event may
1154
1154
/// require some further action after the user handles it (currently only blocking a monitor
@@ -1594,11 +1594,13 @@ impl ChannelDetails {
1594
1594
self.short_channel_id.or(self.outbound_scid_alias)
1595
1595
}
1596
1596
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,
1599
1599
fee_estimator: &LowerBoundedFeeEstimator<F>
1600
1600
) -> Self
1601
- where F::Target: FeeEstimator
1601
+ where
1602
+ SP::Target: SignerProvider,
1603
+ F::Target: FeeEstimator
1602
1604
{
1603
1605
let balance = context.get_available_balances(fee_estimator);
1604
1606
let (to_remote_reserve_satoshis, to_self_reserve_satoshis) =
@@ -2299,7 +2301,7 @@ where
2299
2301
Ok(temporary_channel_id)
2300
2302
}
2301
2303
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> {
2303
2305
// Allocate our best estimate of the number of channels we have in the `res`
2304
2306
// Vec. Sadly the `short_to_chan_info` map doesn't cover channels without
2305
2307
// a scid or a scid alias, and the `id_to_peer` shouldn't be used outside
@@ -2425,7 +2427,7 @@ where
2425
2427
}
2426
2428
2427
2429
/// 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) {
2429
2431
let mut pending_events_lock = self.pending_events.lock().unwrap();
2430
2432
match context.unbroadcasted_funding() {
2431
2433
Some(transaction) => {
@@ -3115,7 +3117,7 @@ where
3115
3117
///
3116
3118
/// [`channel_update`]: msgs::ChannelUpdate
3117
3119
/// [`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> {
3119
3121
if !chan.context.should_announce() {
3120
3122
return Err(LightningError {
3121
3123
err: "Cannot broadcast a channel_update for a private channel".to_owned(),
@@ -3140,7 +3142,7 @@ where
3140
3142
///
3141
3143
/// [`channel_update`]: msgs::ChannelUpdate
3142
3144
/// [`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> {
3144
3146
log_trace!(self.logger, "Attempting to generate channel update for channel {}", log_bytes!(chan.context.channel_id()));
3145
3147
let short_channel_id = match chan.context.get_short_channel_id().or(chan.context.latest_inbound_scid_alias()) {
3146
3148
None => return Err(LightningError{err: "Channel not yet established".to_owned(), action: msgs::ErrorAction::IgnoreError}),
@@ -3150,7 +3152,7 @@ where
3150
3152
self.get_channel_update_for_onion(short_channel_id, chan)
3151
3153
}
3152
3154
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> {
3154
3156
log_trace!(self.logger, "Generating channel update for channel {}", log_bytes!(chan.context.channel_id()));
3155
3157
let were_node_one = self.our_network_pubkey.serialize()[..] < chan.context.get_counterparty_node_id().serialize()[..];
3156
3158
@@ -3444,7 +3446,7 @@ where
3444
3446
3445
3447
/// Handles the generation of a funding transaction, optionally (for tests) with a function
3446
3448
/// 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>>(
3448
3450
&self, temporary_channel_id: &[u8; 32], counterparty_node_id: &PublicKey, funding_transaction: Transaction, find_funding_output: FundingOutput
3449
3451
) -> Result<(), APIError> {
3450
3452
let per_peer_state = self.per_peer_state.read().unwrap();
@@ -4362,7 +4364,7 @@ where
4362
4364
let _ = self.process_background_events();
4363
4365
}
4364
4366
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 {
4366
4368
if !chan.context.is_outbound() { return NotifyOption::SkipPersist; }
4367
4369
// If the feerate has decreased by less than half, don't bother
4368
4370
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
4521
4523
4522
4524
let process_unfunded_channel_tick = |
4523
4525
chan_id: &[u8; 32],
4524
- chan_context: &mut ChannelContext<<SP::Target as SignerProvider>::Signer >,
4526
+ chan_context: &mut ChannelContext<SP >,
4525
4527
unfunded_chan_context: &mut UnfundedChannelContext,
4526
4528
pending_msg_events: &mut Vec<MessageSendEvent>,
4527
4529
| {
@@ -4711,7 +4713,7 @@ where
4711
4713
///
4712
4714
/// This is for failures on the channel on which the HTLC was *received*, not failures
4713
4715
/// 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>) {
4715
4717
// We can't be sure what SCID was used when relaying inbound towards us, so we have to
4716
4718
// guess somewhat. If its a public channel, we figure best to just use the real SCID (as
4717
4719
// we're not leaking that we have a channel with the counterparty), otherwise we try to use
@@ -4731,7 +4733,7 @@ where
4731
4733
4732
4734
/// Gets an HTLC onion failure code and error data for an `UPDATE` error, given the error code
4733
4735
/// 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>) {
4735
4737
debug_assert_eq!(desired_err_code & 0x1000, 0x1000);
4736
4738
if let Ok(upd) = self.get_channel_update_for_onion(scid, chan) {
4737
4739
let mut enc = VecWriter(Vec::with_capacity(upd.serialized_length() + 6));
@@ -5194,7 +5196,7 @@ where
5194
5196
/// Handles a channel reentering a functional state, either due to reconnect or a monitor
5195
5197
/// update completion.
5196
5198
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>,
5198
5200
commitment_update: Option<msgs::CommitmentUpdate>, order: RAACommitmentOrder,
5199
5201
pending_forwards: Vec<(PendingHTLCInfo, u64)>, funding_broadcastable: Option<Transaction>,
5200
5202
channel_ready: Option<msgs::ChannelReady>, announcement_sigs: Option<msgs::AnnouncementSignatures>)
@@ -5429,7 +5431,7 @@ where
5429
5431
/// The filter is called for each peer and provided with the number of unfunded, inbound, and
5430
5432
/// non-0-conf channels we have with the peer.
5431
5433
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 {
5433
5435
let mut peers_without_funded_channels = 0;
5434
5436
let best_block_height = self.best_block.read().unwrap().height();
5435
5437
{
@@ -5447,7 +5449,7 @@ where
5447
5449
}
5448
5450
5449
5451
fn unfunded_channel_count(
5450
- peer: &PeerState<<SP::Target as SignerProvider>::Signer >, best_block_height: u32
5452
+ peer: &PeerState<SP >, best_block_height: u32
5451
5453
) -> usize {
5452
5454
let mut num_unfunded_channels = 0;
5453
5455
for (_, chan) in peer.channel_by_id.iter() {
@@ -5893,7 +5895,7 @@ where
5893
5895
chan.get().context.config().accept_underpaying_htlcs, next_packet_pk_opt),
5894
5896
Err(e) => PendingHTLCStatus::Fail(e)
5895
5897
};
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| {
5897
5899
// If the update_add is completely bogus, the call will Err and we will close,
5898
5900
// but if we've sent a shutdown and they haven't acknowledged it yet, we just
5899
5901
// want to reject the new HTLC and fail it backwards instead of forwarding.
@@ -7055,7 +7057,7 @@ where
7055
7057
/// Calls a function which handles an on-chain event (blocks dis/connected, transactions
7056
7058
/// un/confirmed, etc) on each channel, handling any resulting errors or messages generated by
7057
7059
/// 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>>
7059
7061
(&self, height_opt: Option<u32>, f: FN) {
7060
7062
// Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
7061
7063
// during initialization prior to the chain_monitor being fully configured in some cases.
@@ -8601,13 +8603,13 @@ where
8601
8603
8602
8604
let channel_count: u64 = Readable::read(reader)?;
8603
8605
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));
8605
8607
let mut id_to_peer = HashMap::with_capacity(cmp::min(channel_count as usize, 128));
8606
8608
let mut short_to_chan_info = HashMap::with_capacity(cmp::min(channel_count as usize, 128));
8607
8609
let mut channel_closures = VecDeque::new();
8608
8610
let mut close_background_events = Vec::new();
8609
8611
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, (
8611
8613
&args.entropy_source, &args.signer_provider, best_block_height, &provided_channel_type_features(&args.default_config)
8612
8614
))?;
8613
8615
let funding_txo = channel.context.get_funding_txo().ok_or(DecodeError::InvalidValue)?;
@@ -8752,7 +8754,7 @@ where
8752
8754
};
8753
8755
8754
8756
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 >>)>()));
8756
8758
for _ in 0..peer_count {
8757
8759
let peer_pubkey = Readable::read(reader)?;
8758
8760
let peer_chans = peer_channels.remove(&peer_pubkey).unwrap_or(HashMap::new());
@@ -10574,13 +10576,13 @@ pub mod bench {
10574
10576
&'a test_utils::TestFeeEstimator, &'a test_utils::TestRouter<'a>,
10575
10577
&'a test_utils::TestLogger>;
10576
10578
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>,
10579
10581
}
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>;
10582
10584
#[inline]
10583
- fn node(&self) -> &Manager<'a , P> { self.node }
10585
+ fn node(&self) -> &Manager<'chan_mon_cfg , P> { self.node }
10584
10586
#[inline]
10585
10587
fn chain_monitor(&self) -> Option<&test_utils::TestChainMonitor> { None }
10586
10588
}
0 commit comments