@@ -1517,10 +1517,10 @@ where
1517
1517
return false;
1518
1518
}
1519
1519
}
1520
- !self
1521
- .channel_by_id
1522
- .iter()
1523
- .any(|(_, channel)| channel.is_funded() || channel.funding().is_outbound() )
1520
+ let chan_is_funded_or_outbound = |(_, channel): (_, &Channel<SP>)| {
1521
+ channel.is_funded() || channel.funding().is_outbound()
1522
+ };
1523
+ !self.channel_by_id.iter().any(chan_is_funded_or_outbound )
1524
1524
&& self.monitor_update_blocked_actions.is_empty()
1525
1525
&& self.closed_channel_monitor_update_ids.is_empty()
1526
1526
}
@@ -3322,17 +3322,14 @@ macro_rules! emit_funding_tx_broadcast_safe_event {
3322
3322
macro_rules! emit_channel_pending_event {
3323
3323
($locked_events: expr, $channel: expr) => {
3324
3324
if $channel.context.should_emit_channel_pending_event() {
3325
+ let funding_txo = $channel.funding.get_funding_txo().unwrap();
3325
3326
$locked_events.push_back((
3326
3327
events::Event::ChannelPending {
3327
3328
channel_id: $channel.context.channel_id(),
3328
3329
former_temporary_channel_id: $channel.context.temporary_channel_id(),
3329
3330
counterparty_node_id: $channel.context.get_counterparty_node_id(),
3330
3331
user_channel_id: $channel.context.get_user_id(),
3331
- funding_txo: $channel
3332
- .funding
3333
- .get_funding_txo()
3334
- .unwrap()
3335
- .into_bitcoin_outpoint(),
3332
+ funding_txo: funding_txo.into_bitcoin_outpoint(),
3336
3333
channel_type: Some($channel.funding.get_channel_type().clone()),
3337
3334
},
3338
3335
None,
@@ -3807,8 +3804,8 @@ where
3807
3804
let mut outbound_scid_alias = 0;
3808
3805
let mut i = 0;
3809
3806
loop {
3807
+ // fuzzing chacha20 doesn't use the key at all so we always get the same alias
3810
3808
if cfg!(fuzzing) {
3811
- // fuzzing chacha20 doesn't use the key at all so we always get the same alias
3812
3809
outbound_scid_alias += 1;
3813
3810
} else {
3814
3811
outbound_scid_alias = fake_scid::Namespace::OutboundAlias.get_fake_scid(
@@ -3940,22 +3937,17 @@ where
3940
3937
for (_cp_id, peer_state_mutex) in per_peer_state.iter() {
3941
3938
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
3942
3939
let peer_state = &mut *peer_state_lock;
3943
- res.extend(
3944
- peer_state
3945
- .channel_by_id
3946
- .iter()
3947
- // Only `Channels` in the `Channel::Funded` phase can be considered funded.
3948
- .filter(|(_, chan)| chan.is_funded())
3949
- .filter(f)
3950
- .map(|(_channel_id, channel)| {
3951
- ChannelDetails::from_channel(
3952
- channel,
3953
- best_block_height,
3954
- peer_state.latest_features.clone(),
3955
- &self.fee_estimator,
3956
- )
3957
- }),
3958
- );
3940
+ // Only `Channels` in the `Channel::Funded` phase can be considered funded.
3941
+ let filtered_chan_by_id =
3942
+ peer_state.channel_by_id.iter().filter(|(_, chan)| chan.is_funded()).filter(f);
3943
+ res.extend(filtered_chan_by_id.map(|(_channel_id, channel)| {
3944
+ ChannelDetails::from_channel(
3945
+ channel,
3946
+ best_block_height,
3947
+ peer_state.latest_features.clone(),
3948
+ &self.fee_estimator,
3949
+ )
3950
+ }));
3959
3951
}
3960
3952
}
3961
3953
res
@@ -4022,12 +4014,8 @@ where
4022
4014
&self.fee_estimator,
4023
4015
)
4024
4016
};
4025
- return peer_state
4026
- .channel_by_id
4027
- .iter()
4028
- .map(|(_, chan)| (chan))
4029
- .map(channel_to_details)
4030
- .collect();
4017
+ let chan_by_id = peer_state.channel_by_id.iter();
4018
+ return chan_by_id.map(|(_, chan)| (chan)).map(channel_to_details).collect();
4031
4019
}
4032
4020
vec![]
4033
4021
}
@@ -8928,9 +8916,12 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8928
8916
) -> Result<(), MsgHandleErrInternal> {
8929
8917
self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel: &mut Channel<SP>| {
8930
8918
match channel.as_unfunded_v2_mut() {
8931
- Some(unfunded_channel) => Ok(unfunded_channel
8932
- .tx_add_output(msg)
8933
- .into_msg_send_event(counterparty_node_id)),
8919
+ Some(unfunded_channel) => {
8920
+ let msg_send_event = unfunded_channel
8921
+ .tx_add_output(msg)
8922
+ .into_msg_send_event(counterparty_node_id);
8923
+ Ok(msg_send_event)
8924
+ },
8934
8925
None => Err("tx_add_output"),
8935
8926
}
8936
8927
})
@@ -8941,9 +8932,12 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8941
8932
) -> Result<(), MsgHandleErrInternal> {
8942
8933
self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel: &mut Channel<SP>| {
8943
8934
match channel.as_unfunded_v2_mut() {
8944
- Some(unfunded_channel) => Ok(unfunded_channel
8945
- .tx_remove_input(msg)
8946
- .into_msg_send_event(counterparty_node_id)),
8935
+ Some(unfunded_channel) => {
8936
+ let msg_send_event = unfunded_channel
8937
+ .tx_remove_input(msg)
8938
+ .into_msg_send_event(counterparty_node_id);
8939
+ Ok(msg_send_event)
8940
+ },
8947
8941
None => Err("tx_remove_input"),
8948
8942
}
8949
8943
})
@@ -8954,9 +8948,12 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8954
8948
) -> Result<(), MsgHandleErrInternal> {
8955
8949
self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel: &mut Channel<SP>| {
8956
8950
match channel.as_unfunded_v2_mut() {
8957
- Some(unfunded_channel) => Ok(unfunded_channel
8958
- .tx_remove_output(msg)
8959
- .into_msg_send_event(counterparty_node_id)),
8951
+ Some(unfunded_channel) => {
8952
+ let msg_send_event = unfunded_channel
8953
+ .tx_remove_output(msg)
8954
+ .into_msg_send_event(counterparty_node_id);
8955
+ Ok(msg_send_event)
8956
+ },
8960
8957
None => Err("tx_remove_output"),
8961
8958
}
8962
8959
})
@@ -9666,13 +9663,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9666
9663
let is_processing_events = self.pending_events_processor.load(Ordering::Acquire);
9667
9664
let num_forward_events = pending_events
9668
9665
.iter()
9669
- .filter(|(ev, _)| {
9670
- if let events::Event::PendingHTLCsForwardable { .. } = ev {
9671
- true
9672
- } else {
9673
- false
9674
- }
9675
- })
9666
+ .filter(|(ev, _)| matches!(ev, events::Event::PendingHTLCsForwardable { .. }))
9676
9667
.count();
9677
9668
// We only want to push a PendingHTLCsForwardable event if no others are queued. Processing
9678
9669
// events is done in batches and they are not removed until we're done processing each
@@ -10963,30 +10954,32 @@ where
10963
10954
payer_note: Option<String>, payment_id: PaymentId, retry_strategy: Retry,
10964
10955
route_params_config: RouteParametersConfig,
10965
10956
) -> Result<(), Bolt12SemanticError> {
10957
+ let create_pending_payment_fn = |invoice_request: &InvoiceRequest, nonce| {
10958
+ let expiration = StaleExpiration::TimerTicks(1);
10959
+ let retryable_invoice_request = RetryableInvoiceRequest {
10960
+ invoice_request: invoice_request.clone(),
10961
+ nonce,
10962
+ needs_retry: true,
10963
+ };
10964
+ self.pending_outbound_payments
10965
+ .add_new_awaiting_invoice(
10966
+ payment_id,
10967
+ expiration,
10968
+ retry_strategy,
10969
+ route_params_config,
10970
+ Some(retryable_invoice_request),
10971
+ )
10972
+ .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)
10973
+ };
10974
+
10966
10975
self.pay_for_offer_intern(
10967
10976
offer,
10968
10977
quantity,
10969
10978
amount_msats,
10970
10979
payer_note,
10971
10980
payment_id,
10972
10981
None,
10973
- |invoice_request, nonce| {
10974
- let expiration = StaleExpiration::TimerTicks(1);
10975
- let retryable_invoice_request = RetryableInvoiceRequest {
10976
- invoice_request: invoice_request.clone(),
10977
- nonce,
10978
- needs_retry: true,
10979
- };
10980
- self.pending_outbound_payments
10981
- .add_new_awaiting_invoice(
10982
- payment_id,
10983
- expiration,
10984
- retry_strategy,
10985
- route_params_config,
10986
- Some(retryable_invoice_request),
10987
- )
10988
- .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)
10989
- },
10982
+ create_pending_payment_fn,
10990
10983
)
10991
10984
}
10992
10985
@@ -11290,9 +11283,8 @@ where
11290
11283
}
11291
11284
11292
11285
fn get_peers_for_blinded_path(&self) -> Vec<MessageForwardNode> {
11293
- self.per_peer_state
11294
- .read()
11295
- .unwrap()
11286
+ let per_peer_state = self.per_peer_state.read().unwrap();
11287
+ per_peer_state
11296
11288
.iter()
11297
11289
.map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
11298
11290
.filter(|(_, peer)| peer.is_connected)
@@ -12112,13 +12104,10 @@ where
12112
12104
self.do_chain_event(None, |channel| {
12113
12105
if let Some(funding_txo) = channel.funding.get_funding_txo() {
12114
12106
if funding_txo.txid == *txid {
12115
- channel
12116
- .funding_transaction_unconfirmed(&&WithChannelContext::from(
12117
- &self.logger,
12118
- &channel.context,
12119
- None,
12120
- ))
12121
- .map(|()| (None, Vec::new(), None))
12107
+ let chan_context =
12108
+ WithChannelContext::from(&self.logger, &channel.context, None);
12109
+ let res = channel.funding_transaction_unconfirmed(&&chan_context);
12110
+ res.map(|()| (None, Vec::new(), None))
12122
12111
} else {
12123
12112
Ok((None, Vec::new(), None))
12124
12113
}
@@ -12445,13 +12434,13 @@ where
12445
12434
MR::Target: MessageRouter,
12446
12435
L::Target: Logger,
12447
12436
{
12448
- fn handle_open_channel(&self, counterparty_node_id: PublicKey, msg : &msgs::OpenChannel) {
12437
+ fn handle_open_channel(&self, counterparty_node_id: PublicKey, message : &msgs::OpenChannel) {
12449
12438
// Note that we never need to persist the updated ChannelManager for an inbound
12450
12439
// open_channel message - pre-funded channels are never written so there should be no
12451
12440
// change to the contents.
12452
12441
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || {
12453
- let res =
12454
- self.internal_open_channel(&counterparty_node_id, OpenChannelMessageRef::V1( msg) );
12442
+ let msg = OpenChannelMessageRef::V1(message);
12443
+ let res = self.internal_open_channel(&counterparty_node_id, msg);
12455
12444
let persist = match &res {
12456
12445
Err(e) if e.closes_channel() => {
12457
12446
debug_assert!(false, "We shouldn't close a new channel");
@@ -12960,16 +12949,10 @@ where
12960
12949
{
12961
12950
let RetryableInvoiceRequest { invoice_request, nonce, .. } = retryable_invoice_request;
12962
12951
12963
- if self
12964
- .flow
12965
- .enqueue_invoice_request(
12966
- invoice_request,
12967
- payment_id,
12968
- nonce,
12969
- self.get_peers_for_blinded_path(),
12970
- )
12971
- .is_err()
12972
- {
12952
+ let peers = self.get_peers_for_blinded_path();
12953
+ let enqueue_invreq_res =
12954
+ self.flow.enqueue_invoice_request(invoice_request, payment_id, nonce, peers);
12955
+ if enqueue_invreq_res.is_err() {
12973
12956
log_warn!(
12974
12957
self.logger,
12975
12958
"Retry failed for invoice request with payment_id {}",
@@ -14078,11 +14061,9 @@ impl Readable for VecDeque<(Event, Option<EventCompletionAction>)> {
14078
14061
fn read<R: Read>(reader: &mut R) -> Result<Self, DecodeError> {
14079
14062
let len: u64 = Readable::read(reader)?;
14080
14063
const MAX_ALLOC_SIZE: u64 = 1024 * 16;
14081
- let mut events: Self = VecDeque::with_capacity(cmp::min(
14082
- MAX_ALLOC_SIZE
14083
- / mem::size_of::<(events::Event, Option<EventCompletionAction>)>() as u64,
14084
- len,
14085
- ) as usize);
14064
+ let event_size = mem::size_of::<(events::Event, Option<EventCompletionAction>)>();
14065
+ let mut events: Self =
14066
+ VecDeque::with_capacity(cmp::min(MAX_ALLOC_SIZE / event_size as u64, len) as usize);
14086
14067
for _ in 0..len {
14087
14068
let ev_opt = MaybeReadable::read(reader)?;
14088
14069
let action = Readable::read(reader)?;
0 commit comments