Skip to content

Commit b2f6f4e

Browse files
committed
f - fix WithChannelContext::from (etc.)
1 parent 4eedd82 commit b2f6f4e

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

lightning/src/ln/channel.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,13 +764,13 @@ impl<'a, L: Deref> WithChannelContext<'a, L>
764764
where L::Target: Logger {
765765
pub(super) fn from<C, S: Deref>(logger: &'a L, context: C, payment_hash: Option<PaymentHash>) -> Self
766766
where
767-
C: Deref<Target = ChannelContext<S>>,
767+
C: AsRef<ChannelContext<S>>,
768768
S::Target: SignerProvider,
769769
{
770770
WithChannelContext {
771771
logger,
772-
peer_id: Some(context.counterparty_node_id),
773-
channel_id: Some(context.channel_id),
772+
peer_id: Some(context.as_ref().counterparty_node_id),
773+
channel_id: Some(context.as_ref().channel_id),
774774
payment_hash
775775
}
776776
}
@@ -1596,6 +1596,26 @@ where
15961596
}
15971597
}
15981598

1599+
impl<C, F, SP: Deref> AsRef<ChannelContext<SP>> for ScopedChannelContext<C, F, SP>
1600+
where
1601+
C: Deref<Target = ChannelContext<SP>>,
1602+
F: Deref<Target = FundingScope>,
1603+
SP::Target: SignerProvider,
1604+
{
1605+
fn as_ref(&self) -> &ChannelContext<SP> {
1606+
self.context.deref()
1607+
}
1608+
}
1609+
1610+
impl<SP: Deref> AsRef<ChannelContext<SP>> for ChannelContext<SP>
1611+
where
1612+
SP::Target: SignerProvider,
1613+
{
1614+
fn as_ref(&self) -> &ChannelContext<SP> {
1615+
self
1616+
}
1617+
}
1618+
15991619
impl<C, F, SP: Deref> ScopedChannelContext<C, F, SP>
16001620
where
16011621
C: Deref<Target = ChannelContext<SP>>,

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3728,7 +3728,7 @@ where
37283728
.filter_map(|(chan_id, chan)| chan.as_funded().map(|chan| (chan_id, chan)))
37293729
.filter(f)
37303730
.map(|(_channel_id, channel)| {
3731-
ChannelDetails::from_channel_context(&channel.context, best_block_height,
3731+
ChannelDetails::from_channel_context(channel.context(), best_block_height,
37323732
peer_state.latest_features.clone(), &self.fee_estimator)
37333733
})
37343734
);
@@ -6541,8 +6541,8 @@ where
65416541
chan.context_mut().maybe_expire_prev_config();
65426542
let unfunded_context = chan.unfunded_context_mut().expect("channel should be unfunded");
65436543
if unfunded_context.should_expire_unfunded_channel() {
6544-
let context = chan.context_mut();
6545-
let logger = WithChannelContext::from(&self.logger, context, None);
6544+
let mut context = chan.context_mut();
6545+
let logger = WithChannelContext::from(&self.logger, &context, None);
65466546
log_error!(logger,
65476547
"Force-closing pending channel with ID {} for not establishing in a timely manner",
65486548
context.channel_id());
@@ -8551,8 +8551,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
85518551
}
85528552
},
85538553
None => {
8554-
let context = chan_entry.get_mut().context_mut();
8555-
let logger = WithChannelContext::from(&self.logger, context, None);
8554+
let mut context = chan_entry.get_mut().context_mut();
8555+
let logger = WithChannelContext::from(&self.logger, &context, None);
85568556
log_error!(logger, "Immediately closing unfunded channel {} as peer asked to cooperatively shut it down (which is unnecessary)", &msg.channel_id);
85578557
let mut close_res = context.force_shutdown(false, ClosureReason::CounterpartyCoopClosedUnfundedChannel);
85588558
remove_channel_entry!(self, peer_state, chan_entry, close_res);
@@ -9497,8 +9497,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
94979497
_ => unblock_chan(chan, &mut peer_state.pending_msg_events),
94989498
};
94999499
if let Some(mut shutdown_result) = shutdown_result {
9500-
let context = &chan.context();
9501-
let logger = WithChannelContext::from(&self.logger, context, None);
9500+
let context = chan.context();
9501+
let logger = WithChannelContext::from(&self.logger, &context, None);
95029502
log_trace!(logger, "Removing channel {} now that the signer is unblocked", context.channel_id());
95039503
locked_close_channel!(self, peer_state, context, shutdown_result);
95049504
shutdown_results.push(shutdown_result);
@@ -11534,7 +11534,7 @@ where
1153411534
return true;
1153511535
}
1153611536
// Clean up for removal.
11537-
let context = chan.context_mut();
11537+
let mut context = chan.context_mut();
1153811538
let mut close_res = context.force_shutdown(false, ClosureReason::DisconnectedPeer);
1153911539
locked_close_channel!(self, peer_state, &context, close_res);
1154011540
failed_channels.push(close_res);

0 commit comments

Comments
 (0)