Skip to content

Commit fe3d706

Browse files
committed
Remove MsgHandleErrInternal::from_chan_maybe_close as it's useless
Technically funding_transaction_generated was fine using it, but calling force_shutdown on an empty Channel inside the channel_state lock isn't a big deal and almost any other use of it would be unsafe.
1 parent 032f202 commit fe3d706

File tree

2 files changed

+6
-23
lines changed

2 files changed

+6
-23
lines changed

src/ln/channel.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,7 @@ impl Channel {
10041004
#[inline]
10051005
/// Creates a set of keys for build_commitment_transaction to generate a transaction which we
10061006
/// will sign and send to our counterparty.
1007+
/// If an Err is returned, it is a ChannelError::Close (for get_outbound_funding_created)
10071008
fn build_remote_transaction_keys(&self) -> Result<TxCreationKeys, ChannelError> {
10081009
//TODO: Ensure that the payment_key derived here ends up in the library users' wallet as we
10091010
//may see payments to it!
@@ -2949,6 +2950,7 @@ impl Channel {
29492950
}
29502951
}
29512952

2953+
/// If an Err is returned, it is a ChannelError::Close (for get_outbound_funding_created)
29522954
fn get_outbound_funding_created_signature(&mut self) -> Result<(Signature, Transaction), ChannelError> {
29532955
let funding_script = self.get_funding_redeemscript();
29542956

@@ -2966,6 +2968,7 @@ impl Channel {
29662968
/// or if called on an inbound channel.
29672969
/// Note that channel_id changes during this call!
29682970
/// Do NOT broadcast the funding transaction until after a successful funding_signed call!
2971+
/// If an Err is returned, it is a ChannelError::Close.
29692972
pub fn get_outbound_funding_created(&mut self, funding_txo: OutPoint) -> Result<(msgs::FundingCreated, ChannelMonitor), ChannelError> {
29702973
if !self.channel_outbound {
29712974
panic!("Tried to create outbound funding_created message on an inbound channel!");

src/ln/channelmanager.rs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -215,28 +215,6 @@ impl MsgHandleErrInternal {
215215
shutdown_finish: None,
216216
}
217217
}
218-
#[inline]
219-
fn from_chan_maybe_close(err: ChannelError, channel_id: [u8; 32]) -> Self {
220-
Self {
221-
err: match err {
222-
ChannelError::Ignore(msg) => HandleError {
223-
err: msg,
224-
action: Some(msgs::ErrorAction::IgnoreError),
225-
},
226-
ChannelError::Close(msg) => HandleError {
227-
err: msg,
228-
action: Some(msgs::ErrorAction::SendErrorMessage {
229-
msg: msgs::ErrorMessage {
230-
channel_id,
231-
data: msg.to_string()
232-
},
233-
}),
234-
},
235-
},
236-
needs_channel_force_close: true,
237-
shutdown_finish: None,
238-
}
239-
}
240218
}
241219

242220
/// Pass to fail_htlc_backwwards to indicate the reason to fail the payment
@@ -1363,7 +1341,9 @@ impl ChannelManager {
13631341
match channel_state.by_id.remove(temporary_channel_id) {
13641342
Some(mut chan) => {
13651343
(chan.get_outbound_funding_created(funding_txo)
1366-
.map_err(|e| MsgHandleErrInternal::from_chan_maybe_close(e, chan.channel_id()))
1344+
.map_err(|e| if let ChannelError::Close(msg) = e {
1345+
MsgHandleErrInternal::from_finish_shutdown(msg, chan.channel_id(), chan.force_shutdown(), None)
1346+
} else { unreachable!(); })
13671347
, chan)
13681348
},
13691349
None => return

0 commit comments

Comments
 (0)