Skip to content

Commit e0bbdde

Browse files
committed
Make ChannelManager::issue_channel_close_events take a ChannelContext
1 parent fdf3f65 commit e0bbdde

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

lightning/src/ln/channel.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,6 +1786,15 @@ impl<Signer: ChannelSigner> ChannelContext<Signer> {
17861786
}
17871787
res
17881788
}
1789+
1790+
/// Returns transaction if there is pending funding transaction that is yet to broadcast
1791+
pub fn unbroadcasted_funding(&self) -> Option<Transaction> {
1792+
if self.channel_state & (ChannelState::FundingCreated as u32) != 0 {
1793+
self.funding_transaction.clone()
1794+
} else {
1795+
None
1796+
}
1797+
}
17891798
}
17901799

17911800
// Internal utility functions for channels
@@ -3350,15 +3359,6 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
33503359
Ok(self.get_announcement_sigs(node_signer, genesis_block_hash, user_config, best_block.height(), logger))
33513360
}
33523361

3353-
/// Returns transaction if there is pending funding transaction that is yet to broadcast
3354-
pub fn unbroadcasted_funding(&self) -> Option<Transaction> {
3355-
if self.context.channel_state & (ChannelState::FundingCreated as u32) != 0 {
3356-
self.context.funding_transaction.clone()
3357-
} else {
3358-
None
3359-
}
3360-
}
3361-
33623362
pub fn update_add_htlc<F, L: Deref>(&mut self, msg: &msgs::UpdateAddHTLC, mut pending_forward_status: PendingHTLCStatus, create_pending_htlc_status: F, logger: &L) -> Result<(), ChannelError>
33633363
where F: for<'a> Fn(&'a Self, PendingHTLCStatus, u16) -> PendingHTLCStatus, L::Target: Logger {
33643364
// We can't accept HTLCs sent after we've sent a shutdown.

lightning/src/ln/channelmanager.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use crate::events::{Event, EventHandler, EventsProvider, MessageSendEvent, Messa
4040
// Since this struct is returned in `list_channels` methods, expose it here in case users want to
4141
// construct one themselves.
4242
use crate::ln::{inbound_payment, PaymentHash, PaymentPreimage, PaymentSecret};
43-
use crate::ln::channel::{Channel, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch};
43+
use crate::ln::channel::{Channel, ChannelContext, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch};
4444
use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
4545
#[cfg(any(feature = "_test_utils", test))]
4646
use crate::ln::features::InvoiceFeatures;
@@ -2166,19 +2166,19 @@ where
21662166
}
21672167

21682168
/// Helper function that issues the channel close events
2169-
fn issue_channel_close_events(&self, channel: &Channel<<SP::Target as SignerProvider>::Signer>, closure_reason: ClosureReason) {
2169+
fn issue_channel_close_events(&self, context: &ChannelContext<<SP::Target as SignerProvider>::Signer>, closure_reason: ClosureReason) {
21702170
let mut pending_events_lock = self.pending_events.lock().unwrap();
2171-
match channel.unbroadcasted_funding() {
2171+
match context.unbroadcasted_funding() {
21722172
Some(transaction) => {
21732173
pending_events_lock.push_back((events::Event::DiscardFunding {
2174-
channel_id: channel.context.channel_id(), transaction
2174+
channel_id: context.channel_id(), transaction
21752175
}, None));
21762176
},
21772177
None => {},
21782178
}
21792179
pending_events_lock.push_back((events::Event::ChannelClosed {
2180-
channel_id: channel.context.channel_id(),
2181-
user_channel_id: channel.context.get_user_id(),
2180+
channel_id: context.channel_id(),
2181+
user_channel_id: context.get_user_id(),
21822182
reason: closure_reason
21832183
}, None));
21842184
}
@@ -2225,7 +2225,7 @@ where
22252225
msg: channel_update
22262226
});
22272227
}
2228-
self.issue_channel_close_events(&channel, ClosureReason::HolderForceClosed);
2228+
self.issue_channel_close_events(&channel.context, ClosureReason::HolderForceClosed);
22292229
}
22302230
break Ok(());
22312231
},
@@ -2335,9 +2335,9 @@ where
23352335
let peer_state = &mut *peer_state_lock;
23362336
if let hash_map::Entry::Occupied(chan) = peer_state.channel_by_id.entry(channel_id.clone()) {
23372337
if let Some(peer_msg) = peer_msg {
2338-
self.issue_channel_close_events(chan.get(),ClosureReason::CounterpartyForceClosed { peer_msg: UntrustedString(peer_msg.to_string()) });
2338+
self.issue_channel_close_events(&chan.get().context, ClosureReason::CounterpartyForceClosed { peer_msg: UntrustedString(peer_msg.to_string()) });
23392339
} else {
2340-
self.issue_channel_close_events(chan.get(),ClosureReason::HolderForceClosed);
2340+
self.issue_channel_close_events(&chan.get().context, ClosureReason::HolderForceClosed);
23412341
}
23422342
remove_channel!(self, chan)
23432343
} else {
@@ -5212,7 +5212,7 @@ where
52125212
msg: update
52135213
});
52145214
}
5215-
self.issue_channel_close_events(&chan, ClosureReason::CooperativeClosure);
5215+
self.issue_channel_close_events(&chan.context, ClosureReason::CooperativeClosure);
52165216
}
52175217
Ok(())
52185218
}
@@ -5697,7 +5697,7 @@ where
56975697
} else {
56985698
ClosureReason::CommitmentTxConfirmed
56995699
};
5700-
self.issue_channel_close_events(&chan, reason);
5700+
self.issue_channel_close_events(&chan.context, reason);
57015701
pending_msg_events.push(events::MessageSendEvent::HandleError {
57025702
node_id: chan.context.get_counterparty_node_id(),
57035703
action: msgs::ErrorAction::SendErrorMessage {
@@ -5822,7 +5822,7 @@ where
58225822
});
58235823
}
58245824

5825-
self.issue_channel_close_events(chan, ClosureReason::CooperativeClosure);
5825+
self.issue_channel_close_events(&chan.context, ClosureReason::CooperativeClosure);
58265826

58275827
log_info!(self.logger, "Broadcasting {}", log_tx!(tx));
58285828
self.tx_broadcaster.broadcast_transactions(&[&tx]);
@@ -6540,7 +6540,7 @@ where
65406540
});
65416541
}
65426542
let reason_message = format!("{}", reason);
6543-
self.issue_channel_close_events(channel, reason);
6543+
self.issue_channel_close_events(&channel.context, reason);
65446544
pending_msg_events.push(events::MessageSendEvent::HandleError {
65456545
node_id: channel.context.get_counterparty_node_id(),
65466546
action: msgs::ErrorAction::SendErrorMessage { msg: msgs::ErrorMessage {
@@ -6791,7 +6791,7 @@ where
67916791
chan.remove_uncommitted_htlcs_and_mark_paused(&self.logger);
67926792
if chan.is_shutdown() {
67936793
update_maps_on_chan_removal!(self, chan);
6794-
self.issue_channel_close_events(chan, ClosureReason::DisconnectedPeer);
6794+
self.issue_channel_close_events(&chan.context, ClosureReason::DisconnectedPeer);
67956795
return false;
67966796
}
67976797
true

0 commit comments

Comments
 (0)